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 
00034 #include <qbuttongroup.h>
00035 #include <qcheckbox.h>
00036 #include <qhbox.h>
00037 #include <qlabel.h>
00038 #include <qlayout.h>
00039 #include <qradiobutton.h>
00040 #include <qspinbox.h>
00041 #include <qvbox.h>
00042 #include <qwhatsthis.h>
00043 
00044 #include <kinstance.h>
00045 #include <kdebug.h>
00046 #include <kdialogbase.h>
00047 #include <kglobalaccel.h>
00048 #include <kglobal.h>
00049 #include <kglobalsettings.h>
00050 #include <kiconloader.h>
00051 #include <kio/netaccess.h>
00052 #include <kkeydialog.h>
00053 #include <klistbox.h>
00054 #include <klocale.h>
00055 #include <ksimpleconfig.h>
00056 #include <kstdaction.h>
00057 #include <kstandarddirs.h>
00058 #include <kwin.h>
00059 #include <kseparator.h>
00060 #include <qcombobox.h>
00061 #include <kmdidefines.h>
00062 
00063 KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view )
00064  : KDialogBase ( KDialogBase::TreeList,
00065                  i18n("Configure"),
00066                  KDialogBase::Ok | 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   docManager = ((KateApp *)kapp)->kateDocumentManager();
00076   viewManager = parent->kateViewManager();
00077   pluginManager = ((KateApp *)kapp)->katePluginManager();
00078   mainWindow = parent;
00079 
00080   setMinimumSize(600,400);
00081 
00082   v = view;
00083 
00084   pluginPages.setAutoDelete (false);
00085   editorPages.setAutoDelete (false);
00086 
00087   QStringList path;
00088 
00089   setShowIconsInTreeList(true);
00090 
00091   path.clear();
00092   path << i18n("Application");
00093   setFolderIcon (path, SmallIcon("kate", KIcon::SizeSmall));
00094 
00095   path.clear();
00096 
00097   // General page
00098   path << i18n("Application") << i18n("General");
00099   QFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("gohome", KIcon::SizeSmall));
00100 
00101   QVBoxLayout *lo = new QVBoxLayout( frGeneral );
00102   lo->setSpacing(KDialog::spacingHint());
00103   config->setGroup("General");
00104 
00105   // GROUP with the one below: "Startup"
00106   QButtonGroup *bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Startup"), frGeneral );
00107   lo->addWidget( bgStartup );
00108 
00109   // reopen projects
00110   cb_reopenProjects = new QCheckBox( bgStartup );
00111   cb_reopenProjects->setText(i18n("Reopen &projects at startup"));
00112   //config->setGroup("General");
00113   cb_reopenProjects->setChecked( config->readBoolEntry("Restore Projects", false) );
00114   connect( cb_reopenProjects, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00115 
00116 
00117   // reopen files
00118   cb_reopenFiles = new QCheckBox( bgStartup );
00119   cb_reopenFiles->setText(i18n("Reopen &files at startup"));
00120   //config->setGroup("General");
00121   cb_reopenFiles->setChecked( config->readBoolEntry("Restore Documents", false) );
00122   QWhatsThis::add(cb_reopenFiles, i18n(
00123         "If this is enabled Kate will attempt to reopen files that were open when you closed "
00124         "last time. Cursor position will be recovered if possible. Non-existent files will "
00125         "not be opened."));
00126   connect( cb_reopenFiles, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00127 
00128   //config->setGroup("General");
00129   // restore view  config
00130   cb_restoreVC = new QCheckBox( bgStartup );
00131   cb_restoreVC->setText(i18n("Restore &window configuration"));
00132   cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", false) );
00133   QWhatsThis::add(cb_restoreVC, i18n(
00134         "Check this if you want all your views and frames restored each time you open Kate"));
00135   connect( cb_restoreVC, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00136 
00137   // GROUP with the one below: "Appearance"
00138   bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Appearance"), frGeneral );
00139   lo->addWidget( bgStartup );
00140   
00141   QHBox *hbGM=new QHBox(bgStartup);
00142     QLabel *lGM=new QLabel(i18n("Default GUI mode for new windows:"),hbGM);
00143     combo_guiMode = new QComboBox(hbGM);
00144     
00145         QStringList allgml;
00146     allgml<<i18n("Toplevel Mode")<<i18n("Childframe Mode")<<i18n("Tab Page Mode")<<i18n("IDEAL Mode");
00147     
00148         QStringList gml;
00149         gml<<i18n("IDEAL Mode")<<i18n("Tab Page Mode");
00150     
00151         combo_guiMode->insertStringList(gml);
00152     lGM->setBuddy(combo_guiMode);
00153     switch (KateMainWindow::defaultMode)
00154         {
00155         case KMdi::TabPageMode:
00156             combo_guiMode->setCurrentItem(1);
00157             break;
00158         case KMdi::IDEAlMode:
00159         default:
00160             combo_guiMode->setCurrentItem(0);
00161     }
00162         connect(combo_guiMode,SIGNAL(activated(int)),this,SLOT(slotChanged()));
00163 
00164   // show full path in title
00165   config->setGroup("General");
00166   cb_fullPath = new QCheckBox( i18n("Show full &path in title"), bgStartup);
00167   cb_fullPath->setChecked( viewManager->getShowFullPath() );
00168   QWhatsThis::add(cb_fullPath,i18n("If this option is checked, the full document path will be shown in the window caption."));
00169   connect( cb_fullPath, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00170   
00171   // sort filelist ?
00172   cb_sortFiles = new QCheckBox(bgStartup);
00173   cb_sortFiles->setText(i18n("Sort &files alphabetically in the file list."));
00174   cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName);
00175   QWhatsThis::add( cb_sortFiles, i18n(
00176         "If this is checked, the files in the file list will be sorted alphabetically.") );
00177   connect( cb_sortFiles, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00178   
00179   // GROUP with the one below: "Behavior"
00180   bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Behavior"), frGeneral );
00181   lo->addWidget( bgStartup );
00182   
00183   // number of recent files
00184   QHBox *hbNrf = new QHBox( bgStartup );
00185   QLabel *lNrf = new QLabel( i18n("&Number of recent files:"), hbNrf );
00186   sb_numRecentFiles = new QSpinBox( 0, 1000, 1, hbNrf );
00187   sb_numRecentFiles->setValue( mainWindow->fileOpenRecent->maxItems() );
00188   lNrf->setBuddy( sb_numRecentFiles );
00189   QString youwouldnotbelieveit ( i18n(
00190         "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>"
00191         "If you set this lower than the current value, the list will be truncated and "
00192         "some items forgotten.</qt>") );
00193   QWhatsThis::add( lNrf, youwouldnotbelieveit );
00194   QWhatsThis::add( sb_numRecentFiles, youwouldnotbelieveit );
00195   connect( sb_numRecentFiles, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
00196   
00197   // How instances should be handled
00198   cb_singleInstance = new QCheckBox(bgStartup);
00199   cb_singleInstance->setText(i18n("Allow Kate to use more than one UN&IX process"));
00200   config->setGroup("KDE");
00201   cb_singleInstance->setChecked(config->readBoolEntry("MultipleInstances",false));
00202   QWhatsThis::add( cb_singleInstance, i18n(
00203         "If this is unchecked, Kate will only use one UNIX process. If you try running it again, the current "
00204         "process will get the focus, and open any files you requested to be opened. If it is checked, each time "
00205         "you start Kate, a new UNIX process will be started.") );
00206   connect( cb_singleInstance, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00207 
00208   // sync the konsole ?
00209   cb_syncKonsole = new QCheckBox(bgStartup);
00210   cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document"));
00211   cb_syncKonsole->setChecked(parent->syncKonsole);
00212   QWhatsThis::add( cb_syncKonsole, i18n(
00213         "If this is checked, the built in Konsole will <code>cd</code> to the directory "
00214         "of the active document when started and whenever the active document changes, "
00215         "if the document is a local file.") );
00216   connect( cb_syncKonsole, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00217 
00218   // modified files notification
00219   cb_modNotifications = new QCheckBox(
00220       i18n("Wa&rn about files modified by foreign processes"), bgStartup );
00221   cb_modNotifications->setChecked( parent->modNotification );
00222   QWhatsThis::add( cb_modNotifications, i18n(
00223       "If enabled, a passive popup message will be displayed whenever a local "
00224       "file is modified, created or deleted by another process.") );
00225   connect( cb_modNotifications, SIGNAL( toggled( bool ) ),
00226            this, SLOT( slotChanged() ) );
00227 
00228   lo->addStretch(1); // :-] works correct without autoadd
00229   // END General page
00230 
00231   path.clear();
00232 
00233   // file selector page
00234   path << i18n("Application") << i18n("File Selector");
00235 
00236   QVBox *page = addVBoxPage( path, i18n("File Selector Settings"),
00237                               BarIcon("fileopen", KIcon::SizeSmall) );
00238   fileSelConfigPage = new KFSConfigPage( page, "file selector config page",
00239                                          mainWindow->fileselector );
00240   connect( fileSelConfigPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00241 
00242   path.clear();
00243   path << i18n("Application") << i18n("Plugins");
00244   /*QVBox **/page=addVBoxPage(path,i18n("Plugin Manager"),
00245                           BarIcon("connect_established",KIcon::SizeSmall));
00246   KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this);
00247   connect( configPluginPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00248 
00249   // editor widgets from kwrite/kwdialog
00250   path.clear();
00251   path << i18n("Editor");
00252   setFolderIcon (path, SmallIcon("edit", KIcon::SizeSmall));
00253 
00254   for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
00255   {
00256     path.clear();
00257     path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
00258     /*QVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
00259                               KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, KIcon::SizeSmall) );
00260 
00261     KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
00262     connect( cPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00263     editorPages.append (cPage);
00264   }
00265 
00266   for (uint i=0; i<pluginManager->pluginList().count(); i++)
00267   {
00268     if  ( pluginManager->pluginList().at(i)->load && Kate::pluginConfigInterfaceExtension(pluginManager->pluginList().at(i)->plugin) )
00269       addPluginPage (pluginManager->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     }
00315   }
00316 }
00317 
00318 void KateConfigDialog::slotOk()
00319 {
00320   KConfig *config = kapp->config();
00321 
00322   // if data changed apply the kate app stuff
00323   if( dataChanged )
00324   {
00325     config->setGroup("KDE");
00326     config->writeEntry("MultipleInstances",cb_singleInstance->isChecked());
00327     config->setGroup("General");
00328     config->writeEntry("Restore Projects", cb_reopenProjects->isChecked());
00329     config->writeEntry("Restore Documents", cb_reopenFiles->isChecked());
00330     config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked());
00331   
00332     config->writeEntry("Modified Notification", cb_modNotifications->isChecked());
00333     mainWindow->modNotification = cb_modNotifications->isChecked();
00334   
00335     KMdi::MdiMode tmpMode;
00336     switch (combo_guiMode->currentItem()) {
00337           case 1: 
00338                   tmpMode=KMdi::TabPageMode;
00339                   break;
00340           case 0:
00341           default:
00342                   tmpMode=KMdi::IDEAlMode;
00343                   break;
00344     }
00345     config->writeEntry("DefaultGUIMode",tmpMode);
00346     mainWindow->defaultMode=tmpMode;
00347     
00348     for (uint i=0; i < ((KateApp *)kapp)->mainWindows(); i++)
00349     {
00350       KateMainWindow *win = ((KateApp *)kapp)->kateMainWindow (i);
00351       
00352       if (tmpMode != win->mdiMode())
00353       {
00354         if (tmpMode == KMdi::TabPageMode)
00355           win->switchToTabPageMode();
00356         else
00357           win->switchToIDEAlMode();      
00358       }
00359     }
00360     
00361     mainWindow->syncKonsole = cb_syncKonsole->isChecked();
00362   
00363     mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID);
00364   
00365     config->writeEntry( "Number of recent files", sb_numRecentFiles->value() );
00366     mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() );
00367   
00368     fileSelConfigPage->apply();
00369     
00370     viewManager->setShowFullPath( cb_fullPath->isChecked() ); // hm, stored 2 places :(
00371 
00372     mainWindow->saveOptions (config);
00373   }
00374   
00375   //
00376   // editor config ! (the apply() methode will check the changed state internally)
00377   //
00378   for (uint i=0; i<editorPages.count(); i++)
00379   {
00380     editorPages.at(i)->apply();
00381   }
00382 
00383   v->getDoc()->writeConfig(config);
00384 
00385   //
00386   // plugins config ! (the apply() methode SHOULD check the changed state internally)
00387   //
00388   for (uint i=0; i<pluginPages.count(); i++)
00389   {
00390     pluginPages.at(i)->page->apply();
00391   }
00392   
00393   config->sync();
00394   
00395   dataChanged = false;
00396   accept();
00397 }
00398 
00399 void KateConfigDialog::slotChanged()
00400 {
00401   dataChanged = true;
00402 }
KDE Logo
This file is part of the documentation for kate Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 5 04:41:10 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003