kate Library API Documentation

kateconfigdialog.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "kateconfigdialog.h"
00021 #include "kateconfigdialog.moc"
00022 
00023 #include "katemainwindow.h"
00024 
00025 #include "kateconsole.h"
00026 #include "katedocmanager.h"
00027 #include "katepluginmanager.h"
00028 #include "kateconfigplugindialogpage.h"
00029 #include "kateviewmanager.h"
00030 #include "kateapp.h"
00031 #include "katefileselector.h"
00032 #include "katefilelist.h"
00033 #include "kateexternaltools.h"
00034 
00035 #include <qbuttongroup.h>
00036 #include <qcheckbox.h>
00037 #include <qhbox.h>
00038 #include <qlabel.h>
00039 #include <qlayout.h>
00040 #include <qpushbutton.h>
00041 #include <qradiobutton.h>
00042 #include <qspinbox.h>
00043 #include <qvbox.h>
00044 #include <qwhatsthis.h>
00045 #include <qcombobox.h>
00046 
00047 #include <kinstance.h>
00048 #include <kdebug.h>
00049 #include <kdialogbase.h>
00050 #include <kglobalaccel.h>
00051 #include <kglobal.h>
00052 #include <kglobalsettings.h>
00053 #include <kiconloader.h>
00054 #include <kkeydialog.h>
00055 #include <klistbox.h>
00056 #include <klocale.h>
00057 #include <ksimpleconfig.h>
00058 #include <kstdaction.h>
00059 #include <kstandarddirs.h>
00060 #include <kwin.h>
00061 #include <kseparator.h>
00062 
00063 KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view )
00064  : KDialogBase ( KDialogBase::TreeList,
00065                  i18n("Configure"),
00066                  KDialogBase::Ok | KDialogBase::Apply|KDialogBase::Cancel | KDialogBase::Help,
00067                  KDialogBase::Ok,
00068                  parent,
00069                  "configdialog" )
00070 {
00071   KConfig *config = kapp->config();
00072 
00073   KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );
00074 
00075   actionButton( KDialogBase::Apply)->setEnabled( false );
00076 
00077   mainWindow = parent;
00078 
00079   setMinimumSize(600,400);
00080 
00081   v = view;
00082 
00083   pluginPages.setAutoDelete (false);
00084   editorPages.setAutoDelete (false);
00085 
00086   QStringList path;
00087 
00088   setShowIconsInTreeList(true);
00089 
00090   path.clear();
00091   path << i18n("Application");
00092   setFolderIcon (path, SmallIcon("kate", KIcon::SizeSmall));
00093 
00094   path.clear();
00095 
00096   //BEGIN General page
00097   path << i18n("Application") << i18n("General");
00098   QFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("gohome", KIcon::SizeSmall));
00099 
00100   QVBoxLayout *lo = new QVBoxLayout( frGeneral );
00101   lo->setSpacing(KDialog::spacingHint());
00102   config->setGroup("General");
00103 
00104   // GROUP with the one below: "Startup"
00105   QButtonGroup *bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Start&up"), frGeneral );
00106   lo->addWidget( bgStartup );
00107 
00108   // reopen projects
00109   cb_reopenProjects = new QCheckBox( bgStartup );
00110   cb_reopenProjects->setText(i18n("Reopen &projects at startup"));
00111   //config->setGroup("General");
00112   cb_reopenProjects->setChecked( config->readBoolEntry("Restore Projects", false) );
00113   connect( cb_reopenProjects, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00114 
00115 
00116   // reopen files
00117   cb_reopenFiles = new QCheckBox( bgStartup );
00118   cb_reopenFiles->setText(i18n("R&eopen files at startup"));
00119   //config->setGroup("General");
00120   cb_reopenFiles->setChecked( config->readBoolEntry("Restore Documents", false) );
00121   QWhatsThis::add(cb_reopenFiles, i18n(
00122         "If this is enabled Kate will attempt to reopen files that were open when you closed "
00123         "last time. Cursor position will be recovered if possible. Non-existent files will "
00124         "not be opened."));
00125   connect( cb_reopenFiles, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00126 
00127   //config->setGroup("General");
00128   // restore view  config
00129   cb_restoreVC = new QCheckBox( bgStartup );
00130   cb_restoreVC->setText(i18n("Restore &window configuration"));
00131   cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", false) );
00132   QWhatsThis::add(cb_restoreVC, i18n(
00133         "Check this if you want all your views and frames restored each time you open Kate"));
00134   connect( cb_restoreVC, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00135 
00136   // GROUP with the one below: "Appearance"
00137   bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("&Appearance"), frGeneral );
00138   lo->addWidget( bgStartup );
00139 
00140   // show full path in title
00141   config->setGroup("General");
00142   cb_fullPath = new QCheckBox( i18n("&Show full path in title"), bgStartup);
00143   cb_fullPath->setChecked( mainWindow->kateViewManager()->getShowFullPath() );
00144   QWhatsThis::add(cb_fullPath,i18n("If this option is checked, the full document path will be shown in the window caption."));
00145   connect( cb_fullPath, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00146 
00147 
00148   // GROUP with the one below: "Behavior"
00149   bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("&Behavior"), frGeneral );
00150   lo->addWidget( bgStartup );
00151 
00152   // How instances should be handled
00153   cb_singleInstance = new QCheckBox(bgStartup);
00154   cb_singleInstance->setText(i18n("Allow Kate to use more than one UN&IX process"));
00155   config->setGroup("KDE");
00156   cb_singleInstance->setChecked(config->readBoolEntry("MultipleInstances",false));
00157   QWhatsThis::add( cb_singleInstance, i18n(
00158         "If this is unchecked, Kate will only use one UNIX process. If you try running it again, the current "
00159         "process will get the focus, and open any files you requested to be opened. If it is checked, each time "
00160         "you start Kate, a new UNIX process will be started.") );
00161   connect( cb_singleInstance, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00162 
00163   // sync the konsole ?
00164   cb_syncKonsole = new QCheckBox(bgStartup);
00165   cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document"));
00166   cb_syncKonsole->setChecked(parent->syncKonsole);
00167   QWhatsThis::add( cb_syncKonsole, i18n(
00168         "If this is checked, the built in Konsole will <code>cd</code> to the directory "
00169         "of the active document when started and whenever the active document changes, "
00170         "if the document is a local file.") );
00171   connect( cb_syncKonsole, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00172 
00173   // modified files notification
00174   cb_modNotifications = new QCheckBox(
00175       i18n("Wa&rn about files modified by foreign processes"), bgStartup );
00176   cb_modNotifications->setChecked( parent->modNotification );
00177   QWhatsThis::add( cb_modNotifications, i18n(
00178       "If enabled, when Kate receives focus you will be asked what to do with "
00179       "files that have been modified on the hard disk. If not enabled, you will "
00180       "be asked what to do with a file that has been modified on the hard disk only "
00181       "when that file gains focus inside Kate.") );
00182   connect( cb_modNotifications, SIGNAL( toggled( bool ) ),
00183            this, SLOT( slotChanged() ) );
00184 
00185   // GROUP with the one below: "Meta-informations"
00186   bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Meta-Information"), frGeneral );
00187   lo->addWidget( bgStartup );
00188 
00189   // save meta infos
00190   cb_saveMetaInfos = new QCheckBox( bgStartup );
00191   cb_saveMetaInfos->setText(i18n("Keep &meta-information past sessions"));
00192   cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos());
00193   QWhatsThis::add(cb_saveMetaInfos, i18n(
00194         "Check this if you want document configuration like for example "
00195         "bookmarks to be saved past editor sessions. The configuration will be "
00196         "restored if the document has not changed when reopened."));
00197   connect( cb_saveMetaInfos, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00198 
00199   // meta infos days
00200   QHBox *hbDmf = new QHBox( bgStartup );
00201   hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos());
00202   QLabel *lDmf = new QLabel( i18n("&Delete unused meta-information after:"), hbDmf );
00203   sb_daysMetaInfos = new QSpinBox( 0, 180, 1, hbDmf );
00204   sb_daysMetaInfos->setSpecialValueText(i18n("(never)"));
00205   sb_daysMetaInfos->setSuffix(i18n(" day(s)"));
00206   sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() );
00207   lDmf->setBuddy( sb_daysMetaInfos );
00208   connect( cb_saveMetaInfos, SIGNAL( toggled( bool ) ), hbDmf, SLOT( setEnabled( bool ) ) );
00209   connect( sb_daysMetaInfos, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
00210 
00211   lo->addStretch(1); // :-] works correct without autoadd
00212   //END General page
00213 
00214   path.clear();
00215 
00216   // file selector page
00217   path << i18n("Application") << i18n("File Selector");
00218 
00219   QVBox *page = addVBoxPage( path, i18n("File Selector Settings"),
00220                               BarIcon("fileopen", KIcon::SizeSmall) );
00221   fileSelConfigPage = new KFSConfigPage( page, "file selector config page",
00222                                          mainWindow->fileselector );
00223   connect( fileSelConfigPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00224   path.clear();
00225 
00226   path << i18n("Application") << i18n("Document List");
00227   page = addVBoxPage( path, i18n("Document List Settings"),
00228   BarIcon("documents", KIcon::SizeSmall) );
00229   filelistConfigPage = new KFLConfigPage( page, "file list config page",
00230                       mainWindow->filelist );
00231   connect( filelistConfigPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00232   path.clear();
00233 
00234   path << i18n("Application") << i18n("Plugins");
00235   /*QVBox **/page=addVBoxPage(path,i18n("Plugin Manager"),
00236                           BarIcon("connect_established",KIcon::SizeSmall));
00237   KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this);
00238   connect( configPluginPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00239 
00240   // Tools->External Tools menu
00241   path.clear();
00242   path << i18n("Application") << i18n("External Tools");
00243   page = addVBoxPage( path, i18n("External Tools"),
00244       BarIcon("configure", KIcon::SizeSmall) );
00245   configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page");
00246   connect( configExternalToolsPage, SIGNAL(changed()), this, SLOT(slotChanged()) );
00247 
00248   // editor widgets from kwrite/kwdialog
00249   path.clear();
00250   path << i18n("Editor");
00251   setFolderIcon (path, SmallIcon("edit", KIcon::SizeSmall));
00252 
00253   for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
00254   {
00255     path.clear();
00256     path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
00257     /*QVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
00258                               KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, KIcon::SizeSmall) );
00259 
00260     KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
00261     connect( cPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00262     editorPages.append (cPage);
00263   }
00264 
00265   for (uint i=0; i<KatePluginManager::self()->pluginList().count(); i++)
00266   {
00267     if  ( KatePluginManager::self()->pluginList().at(i)->load
00268           && Kate::pluginConfigInterfaceExtension(KatePluginManager::self()->pluginList().at(i)->plugin) )
00269       addPluginPage (KatePluginManager::self()->pluginList().at(i)->plugin);
00270   }
00271 
00272   enableButtonSeparator(true);
00273   dataChanged = false;
00274   unfoldTreeList ();
00275 }
00276 
00277 KateConfigDialog::~KateConfigDialog()
00278 {
00279 }
00280 
00281 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
00282 {
00283   if (!Kate::pluginConfigInterfaceExtension(plugin))
00284     return;
00285 
00286   for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
00287   {
00288     QStringList path;
00289     path.clear();
00290     path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i);
00291     QVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, KIcon::SizeSmall));
00292 
00293     PluginPageListItem *info=new PluginPageListItem;
00294     info->plugin = plugin;
00295     info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page);
00296     connect( info->page, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00297     pluginPages.append(info);
00298   }
00299 }
00300 
00301 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
00302 {
00303    if (!Kate::pluginConfigInterfaceExtension(plugin))
00304     return;
00305 
00306   for (uint i=0; i<pluginPages.count(); i++)
00307   {
00308     if  ( pluginPages.at(i)->plugin == plugin )
00309     {
00310       QWidget *w = pluginPages.at(i)->page->parentWidget();
00311       delete pluginPages.at(i)->page;
00312       delete w;
00313       pluginPages.remove(pluginPages.at(i));
00314       i--;
00315     }
00316   }
00317 }
00318 
00319 void KateConfigDialog::slotOk()
00320 {
00321   slotApply();
00322   accept();
00323 }
00324 
00325 void KateConfigDialog::slotApply()
00326 {
00327   KConfig *config = kapp->config();
00328 
00329   // if data changed apply the kate app stuff
00330   if( dataChanged )
00331   {
00332     config->setGroup("KDE");
00333     config->writeEntry("MultipleInstances",cb_singleInstance->isChecked());
00334     config->setGroup("General");
00335     config->writeEntry("Restore Projects", cb_reopenProjects->isChecked());
00336     config->writeEntry("Restore Documents", cb_reopenFiles->isChecked());
00337     config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked());
00338 
00339     config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked());
00340     KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
00341 
00342     config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() );
00343     KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value());
00344 
00345     config->writeEntry("Modified Notification", cb_modNotifications->isChecked());
00346     mainWindow->modNotification = cb_modNotifications->isChecked();
00347 
00348     mainWindow->syncKonsole = cb_syncKonsole->isChecked();
00349 
00350     fileSelConfigPage->apply();
00351 
00352     filelistConfigPage->apply();
00353 
00354     configExternalToolsPage->apply();
00355     for (uint i=0; i < ((KateApp *)kapp)->mainWindows(); i++)
00356     {
00357       KateMainWindow *win = ((KateApp *)kapp)->kateMainWindow (i);
00358       win->externalTools->reload();
00359     }
00360     KateExternalToolsCommand::self()->reload();
00361     //mainWindow->externalTools->reload();
00362 
00363     mainWindow->kateViewManager()->setShowFullPath( cb_fullPath->isChecked() ); // hm, stored 2 places :(
00364 
00365     mainWindow->saveOptions (config);
00366 
00367     // save plugin config !!
00368     ((KateApp *)kapp)->katePluginManager()->writeConfig ();
00369   }
00370 
00371   //
00372   // editor config ! (the apply() methode will check the changed state internally)
00373   //
00374   for (uint i=0; i<editorPages.count(); i++)
00375   {
00376     editorPages.at(i)->apply();
00377   }
00378 
00379   v->getDoc()->writeConfig(config);
00380 
00381   //
00382   // plugins config ! (the apply() methode SHOULD check the changed state internally)
00383   //
00384   for (uint i=0; i<pluginPages.count(); i++)
00385   {
00386     pluginPages.at(i)->page->apply();
00387   }
00388 
00389   config->sync();
00390 
00391   dataChanged = false;
00392   actionButton( KDialogBase::Apply)->setEnabled( false );
00393 }
00394 
00395 void KateConfigDialog::slotChanged()
00396 {
00397   dataChanged = true;
00398   actionButton( KDialogBase::Apply)->setEnabled( true );
00399 }
KDE Logo
This file is part of the documentation for kate Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jun 14 01:19:50 2006 by doxygen 1.4.0 written by Dimitri van Heesch, © 1997-2003