00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 <qradiobutton.h>
00041 #include <qspinbox.h>
00042 #include <qvbox.h>
00043 #include <qwhatsthis.h>
00044
00045 #include <kinstance.h>
00046 #include <kdebug.h>
00047 #include <kdialogbase.h>
00048 #include <kglobalaccel.h>
00049 #include <kglobal.h>
00050 #include <kglobalsettings.h>
00051 #include <kiconloader.h>
00052 #include <kio/netaccess.h>
00053 #include <kkeydialog.h>
00054 #include <klistbox.h>
00055 #include <klocale.h>
00056 #include <ksimpleconfig.h>
00057 #include <kstdaction.h>
00058 #include <kstandarddirs.h>
00059 #include <kwin.h>
00060 #include <kseparator.h>
00061 #include <qcombobox.h>
00062 #include <kmdidefines.h>
00063
00064 KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view )
00065 : KDialogBase ( KDialogBase::TreeList,
00066 i18n("Configure"),
00067 KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Help,
00068 KDialogBase::Ok,
00069 parent,
00070 "configdialog" )
00071 {
00072 KConfig *config = kapp->config();
00073
00074 KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );
00075
00076 docManager = ((KateApp *)kapp)->kateDocumentManager();
00077 viewManager = parent->kateViewManager();
00078 pluginManager = ((KateApp *)kapp)->katePluginManager();
00079 mainWindow = parent;
00080
00081 setMinimumSize(600,400);
00082
00083 v = view;
00084
00085 pluginPages.setAutoDelete (false);
00086 editorPages.setAutoDelete (false);
00087
00088 QStringList path;
00089
00090 setShowIconsInTreeList(true);
00091
00092 path.clear();
00093 path << i18n("Application");
00094 setFolderIcon (path, SmallIcon("kate", KIcon::SizeSmall));
00095
00096 path.clear();
00097
00098
00099 path << i18n("Application") << i18n("General");
00100 QFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("gohome", KIcon::SizeSmall));
00101
00102 QVBoxLayout *lo = new QVBoxLayout( frGeneral );
00103 lo->setSpacing(KDialog::spacingHint());
00104 config->setGroup("General");
00105
00106
00107 QButtonGroup *bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Startup"), frGeneral );
00108 lo->addWidget( bgStartup );
00109
00110
00111 cb_reopenProjects = new QCheckBox( bgStartup );
00112 cb_reopenProjects->setText(i18n("Reopen &projects at startup"));
00113
00114 cb_reopenProjects->setChecked( config->readBoolEntry("Restore Projects", false) );
00115 connect( cb_reopenProjects, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00116
00117
00118
00119 cb_reopenFiles = new QCheckBox( bgStartup );
00120 cb_reopenFiles->setText(i18n("Reopen &files at startup"));
00121
00122 cb_reopenFiles->setChecked( config->readBoolEntry("Restore Documents", false) );
00123 QWhatsThis::add(cb_reopenFiles, i18n(
00124 "If this is enabled Kate will attempt to reopen files that were open when you closed "
00125 "last time. Cursor position will be recovered if possible. Non-existent files will "
00126 "not be opened."));
00127 connect( cb_reopenFiles, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00128
00129
00130
00131 cb_restoreVC = new QCheckBox( bgStartup );
00132 cb_restoreVC->setText(i18n("Restore &window configuration"));
00133 cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", false) );
00134 QWhatsThis::add(cb_restoreVC, i18n(
00135 "Check this if you want all your views and frames restored each time you open Kate"));
00136 connect( cb_restoreVC, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00137
00138
00139 bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Appearance"), frGeneral );
00140 lo->addWidget( bgStartup );
00141
00142 QHBox *hbGM=new QHBox(bgStartup);
00143 QLabel *lGM=new QLabel(i18n("Default GUI mode for new windows:"),hbGM);
00144 combo_guiMode = new QComboBox(hbGM);
00145
00146 QStringList allgml;
00147 allgml<<i18n("Toplevel Mode")<<i18n("Childframe Mode")<<i18n("Tab Page Mode")<<i18n("IDEAL Mode");
00148
00149 QStringList gml;
00150 gml<<i18n("IDEAL Mode")<<i18n("Tab Page Mode");
00151
00152 combo_guiMode->insertStringList(gml);
00153 lGM->setBuddy(combo_guiMode);
00154 switch (KateMainWindow::defaultMode)
00155 {
00156 case KMdi::TabPageMode:
00157 combo_guiMode->setCurrentItem(1);
00158 break;
00159 case KMdi::IDEAlMode:
00160 default:
00161 combo_guiMode->setCurrentItem(0);
00162 }
00163 connect(combo_guiMode,SIGNAL(activated(int)),this,SLOT(slotChanged()));
00164
00165
00166 config->setGroup("General");
00167 cb_fullPath = new QCheckBox( i18n("Show full &path in title"), bgStartup);
00168 cb_fullPath->setChecked( viewManager->getShowFullPath() );
00169 QWhatsThis::add(cb_fullPath,i18n("If this option is checked, the full document path will be shown in the window caption."));
00170 connect( cb_fullPath, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00171
00172
00173 cb_sortFiles = new QCheckBox(bgStartup);
00174 cb_sortFiles->setText(i18n("Sort &files alphabetically in the file list"));
00175 cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName);
00176 QWhatsThis::add( cb_sortFiles, i18n(
00177 "If this is checked, the files in the file list will be sorted alphabetically.") );
00178 connect( cb_sortFiles, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00179
00180
00181 bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Behavior"), frGeneral );
00182 lo->addWidget( bgStartup );
00183
00184
00185 QHBox *hbNrf = new QHBox( bgStartup );
00186 QLabel *lNrf = new QLabel( i18n("&Number of recent files:"), hbNrf );
00187 sb_numRecentFiles = new QSpinBox( 0, 1000, 1, hbNrf );
00188 sb_numRecentFiles->setValue( mainWindow->fileOpenRecent->maxItems() );
00189 lNrf->setBuddy( sb_numRecentFiles );
00190 QString youwouldnotbelieveit ( i18n(
00191 "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>"
00192 "If you set this lower than the current value, the list will be truncated and "
00193 "some items forgotten.</qt>") );
00194 QWhatsThis::add( lNrf, youwouldnotbelieveit );
00195 QWhatsThis::add( sb_numRecentFiles, youwouldnotbelieveit );
00196 connect( sb_numRecentFiles, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
00197
00198
00199 cb_singleInstance = new QCheckBox(bgStartup);
00200 cb_singleInstance->setText(i18n("Allow Kate to use more than one UN&IX process"));
00201 config->setGroup("KDE");
00202 cb_singleInstance->setChecked(config->readBoolEntry("MultipleInstances",false));
00203 QWhatsThis::add( cb_singleInstance, i18n(
00204 "If this is unchecked, Kate will only use one UNIX process. If you try running it again, the current "
00205 "process will get the focus, and open any files you requested to be opened. If it is checked, each time "
00206 "you start Kate, a new UNIX process will be started.") );
00207 connect( cb_singleInstance, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00208
00209
00210 cb_syncKonsole = new QCheckBox(bgStartup);
00211 cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document"));
00212 cb_syncKonsole->setChecked(parent->syncKonsole);
00213 QWhatsThis::add( cb_syncKonsole, i18n(
00214 "If this is checked, the built in Konsole will <code>cd</code> to the directory "
00215 "of the active document when started and whenever the active document changes, "
00216 "if the document is a local file.") );
00217 connect( cb_syncKonsole, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00218
00219
00220 cb_modNotifications = new QCheckBox(
00221 i18n("Wa&rn about files modified by foreign processes"), bgStartup );
00222 cb_modNotifications->setChecked( parent->modNotification );
00223 QWhatsThis::add( cb_modNotifications, i18n(
00224 "If enabled, a passive popup message will be displayed whenever a local "
00225 "file is modified, created or deleted by another process.") );
00226 connect( cb_modNotifications, SIGNAL( toggled( bool ) ),
00227 this, SLOT( slotChanged() ) );
00228
00229
00230 bgStartup = new QButtonGroup( 1, Qt::Horizontal, i18n("Meta-Information"), frGeneral );
00231 lo->addWidget( bgStartup );
00232
00233
00234 cb_saveMetaInfos = new QCheckBox( bgStartup );
00235 cb_saveMetaInfos->setText(i18n("Keep &meta-information past sessions"));
00236 cb_saveMetaInfos->setChecked(docManager->getSaveMetaInfos());
00237 QWhatsThis::add(cb_saveMetaInfos, i18n(
00238 "Check this if you want document configuration like for example "
00239 "bookmarks to be saved past editor sessions. The configuration will be "
00240 "restored if the document has not changed when reopened."));
00241 connect( cb_saveMetaInfos, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00242
00243
00244 QHBox *hbDmf = new QHBox( bgStartup );
00245 hbDmf->setEnabled(docManager->getSaveMetaInfos());
00246 QLabel *lDmf = new QLabel( i18n("&Delete unused meta-information after:"), hbDmf );
00247 sb_daysMetaInfos = new QSpinBox( 0, 180, 1, hbDmf );
00248 sb_daysMetaInfos->setSpecialValueText(i18n("(never)"));
00249 sb_daysMetaInfos->setSuffix(i18n(" day(s)"));
00250 sb_daysMetaInfos->setValue( docManager->getDaysMetaInfos() );
00251 lDmf->setBuddy( sb_daysMetaInfos );
00252 connect( cb_saveMetaInfos, SIGNAL( toggled( bool ) ), hbDmf, SLOT( setEnabled( bool ) ) );
00253 connect( sb_daysMetaInfos, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
00254
00255 lo->addStretch(1);
00256
00257
00258 path.clear();
00259
00260
00261 path << i18n("Application") << i18n("File Selector");
00262
00263 QVBox *page = addVBoxPage( path, i18n("File Selector Settings"),
00264 BarIcon("fileopen", KIcon::SizeSmall) );
00265 fileSelConfigPage = new KFSConfigPage( page, "file selector config page",
00266 mainWindow->fileselector );
00267 connect( fileSelConfigPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00268
00269 path.clear();
00270 path << i18n("Application") << i18n("Plugins");
00271 page=addVBoxPage(path,i18n("Plugin Manager"),
00272 BarIcon("connect_established",KIcon::SizeSmall));
00273 KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this);
00274 connect( configPluginPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00275
00276
00277 path.clear();
00278 path << i18n("Application") << i18n("External Tools");
00279 page = addVBoxPage( path, i18n("External Tools"),
00280 BarIcon("configure", KIcon::SizeSmall) );
00281 configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page");
00282 connect( configExternalToolsPage, SIGNAL(changed()), this, SLOT(slotChanged()) );
00283
00284
00285 path.clear();
00286 path << i18n("Editor");
00287 setFolderIcon (path, SmallIcon("edit", KIcon::SizeSmall));
00288
00289 for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
00290 {
00291 path.clear();
00292 path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
00293 page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
00294 KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, KIcon::SizeSmall) );
00295
00296 KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
00297 connect( cPage, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00298 editorPages.append (cPage);
00299 }
00300
00301 for (uint i=0; i<pluginManager->pluginList().count(); i++)
00302 {
00303 if ( pluginManager->pluginList().at(i)->load && Kate::pluginConfigInterfaceExtension(pluginManager->pluginList().at(i)->plugin) )
00304 addPluginPage (pluginManager->pluginList().at(i)->plugin);
00305 }
00306
00307 enableButtonSeparator(true);
00308 dataChanged = false;
00309 unfoldTreeList ();
00310 }
00311
00312 KateConfigDialog::~KateConfigDialog()
00313 {
00314 }
00315
00316 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
00317 {
00318 if (!Kate::pluginConfigInterfaceExtension(plugin))
00319 return;
00320
00321 for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
00322 {
00323 QStringList path;
00324 path.clear();
00325 path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i);
00326 QVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, KIcon::SizeSmall));
00327
00328 PluginPageListItem *info=new PluginPageListItem;
00329 info->plugin = plugin;
00330 info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page);
00331 connect( info->page, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00332 pluginPages.append(info);
00333 }
00334 }
00335
00336 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
00337 {
00338 if (!Kate::pluginConfigInterfaceExtension(plugin))
00339 return;
00340
00341 for (uint i=0; i<pluginPages.count(); i++)
00342 {
00343 if ( pluginPages.at(i)->plugin == plugin )
00344 {
00345 QWidget *w = pluginPages.at(i)->page->parentWidget();
00346 delete pluginPages.at(i)->page;
00347 delete w;
00348 pluginPages.remove(pluginPages.at(i));
00349 i--;
00350 }
00351 }
00352 }
00353
00354 void KateConfigDialog::slotOk()
00355 {
00356 KConfig *config = kapp->config();
00357
00358
00359 if( dataChanged )
00360 {
00361 config->setGroup("KDE");
00362 config->writeEntry("MultipleInstances",cb_singleInstance->isChecked());
00363 config->setGroup("General");
00364 config->writeEntry("Restore Projects", cb_reopenProjects->isChecked());
00365 config->writeEntry("Restore Documents", cb_reopenFiles->isChecked());
00366 config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked());
00367
00368 config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked());
00369 docManager->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
00370
00371 config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() );
00372 docManager->setDaysMetaInfos(sb_daysMetaInfos->value());
00373
00374 config->writeEntry("Modified Notification", cb_modNotifications->isChecked());
00375 mainWindow->modNotification = cb_modNotifications->isChecked();
00376
00377 KMdi::MdiMode tmpMode;
00378 switch (combo_guiMode->currentItem()) {
00379 case 1:
00380 tmpMode=KMdi::TabPageMode;
00381 break;
00382 case 0:
00383 default:
00384 tmpMode=KMdi::IDEAlMode;
00385 break;
00386 }
00387 config->writeEntry("DefaultGUIMode",tmpMode);
00388 mainWindow->defaultMode=tmpMode;
00389
00390 for (uint i=0; i < ((KateApp *)kapp)->mainWindows(); i++)
00391 {
00392 KateMainWindow *win = ((KateApp *)kapp)->kateMainWindow (i);
00393
00394 if (tmpMode != win->mdiMode())
00395 {
00396 if (tmpMode == KMdi::TabPageMode)
00397 win->switchToTabPageMode();
00398 else
00399 win->switchToIDEAlMode();
00400 }
00401 }
00402
00403 mainWindow->syncKonsole = cb_syncKonsole->isChecked();
00404
00405 mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID);
00406
00407 config->writeEntry( "Number of recent files", sb_numRecentFiles->value() );
00408 mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() );
00409
00410 fileSelConfigPage->apply();
00411
00412 configExternalToolsPage->apply();
00413 mainWindow->externalTools->reload();
00414
00415 viewManager->setShowFullPath( cb_fullPath->isChecked() );
00416
00417 mainWindow->saveOptions (config);
00418
00419
00420 ((KateApp *)kapp)->katePluginManager()->writeConfig ();
00421 }
00422
00423
00424
00425
00426 for (uint i=0; i<editorPages.count(); i++)
00427 {
00428 editorPages.at(i)->apply();
00429 }
00430
00431 v->getDoc()->writeConfig(config);
00432
00433
00434
00435
00436 for (uint i=0; i<pluginPages.count(); i++)
00437 {
00438 pluginPages.at(i)->page->apply();
00439 }
00440
00441 config->sync();
00442
00443 dataChanged = false;
00444 accept();
00445 }
00446
00447 void KateConfigDialog::slotChanged()
00448 {
00449 dataChanged = true;
00450 }