• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • app
kateconfigdialog.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kateconfigdialog.h"
21 #include "kateconfigdialog.moc"
22 
23 #include "katemainwindow.h"
24 
25 #include "kateconsole.h"
26 #include "katedocmanager.h"
27 #include "katepluginmanager.h"
28 #include "kateconfigplugindialogpage.h"
29 #include "kateviewmanager.h"
30 #include "kateapp.h"
31 #include "katefileselector.h"
32 #include "katefilelist.h"
33 #include "kateexternaltools.h"
34 
35 #include <tqbuttongroup.h>
36 #include <tqcheckbox.h>
37 #include <tqhbox.h>
38 #include <tqlabel.h>
39 #include <tqlayout.h>
40 #include <tqpushbutton.h>
41 #include <tqradiobutton.h>
42 #include <tqspinbox.h>
43 #include <tqvbox.h>
44 #include <tqwhatsthis.h>
45 #include <tqcombobox.h>
46 
47 #include <kinstance.h>
48 #include <kdebug.h>
49 #include <kdialogbase.h>
50 #include <kglobalaccel.h>
51 #include <kglobal.h>
52 #include <kglobalsettings.h>
53 #include <kiconloader.h>
54 #include <kkeydialog.h>
55 #include <klistbox.h>
56 #include <klocale.h>
57 #include <ksimpleconfig.h>
58 #include <kstdaction.h>
59 #include <kstandarddirs.h>
60 #include <kwin.h>
61 #include <kseparator.h>
62 
63 KateConfigDialog::KateConfigDialog ( KateMainWindow *parent, Kate::View *view )
64  : KDialogBase ( KDialogBase::TreeList,
65  i18n("Configure"),
66  KDialogBase::Ok | KDialogBase::Apply|KDialogBase::Cancel | KDialogBase::Help,
67  KDialogBase::Ok,
68  parent,
69  "configdialog" )
70 {
71  KConfig *config = KateApp::self()->config();
72 
73  KWin::setIcons( winId(), KateApp::self()->icon(), KateApp::self()->miniIcon() );
74 
75  actionButton( KDialogBase::Apply)->setEnabled( false );
76 
77  mainWindow = parent;
78 
79  setMinimumSize(600,400);
80 
81  v = view;
82 
83  pluginPages.setAutoDelete (false);
84  editorPages.setAutoDelete (false);
85 
86  TQStringList path;
87 
88  setShowIconsInTreeList(true);
89 
90  path.clear();
91  path << i18n("Application");
92  setFolderIcon (path, SmallIcon("kate", KIcon::SizeSmall));
93 
94  path.clear();
95 
96  //BEGIN General page
97  path << i18n("Application") << i18n("General");
98  TQFrame* frGeneral = addPage(path, i18n("General Options"), BarIcon("gohome", KIcon::SizeSmall));
99 
100  TQVBoxLayout *lo = new TQVBoxLayout( frGeneral );
101  lo->setSpacing(KDialog::spacingHint());
102  config->setGroup("General");
103 
104  // GROUP with the one below: "Appearance"
105  TQButtonGroup *bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Appearance"), frGeneral );
106  lo->addWidget( bgStartup );
107 
108  // show full path in title
109  config->setGroup("General");
110  cb_fullPath = new TQCheckBox( i18n("&Show full path in title"), bgStartup);
111  cb_fullPath->setChecked( mainWindow->viewManager()->getShowFullPath() );
112  TQWhatsThis::add(cb_fullPath,i18n("If this option is checked, the full document path will be shown in the window caption."));
113  connect( cb_fullPath, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) );
114 
115  // sort filelist if desired
116  cb_sortFiles = new TQCheckBox(bgStartup);
117  cb_sortFiles->setText(i18n("Sort &files alphabetically in the file list"));
118  cb_sortFiles->setChecked(parent->filelist->sortType() == KateFileList::sortByName);
119  TQWhatsThis::add( cb_sortFiles, i18n(
120  "If this is checked, the files in the file list will be sorted alphabetically.") );
121  connect( cb_sortFiles, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) );
122 
123  // GROUP with the one below: "Behavior"
124  bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("&Behavior"), frGeneral );
125  lo->addWidget( bgStartup );
126 
127  // number of recent files
128  TQHBox *hbNrf = new TQHBox( bgStartup );
129  TQLabel *lNrf = new TQLabel( i18n("&Number of recent files:"), hbNrf );
130  sb_numRecentFiles = new TQSpinBox( 0, 1000, 1, hbNrf );
131  sb_numRecentFiles->setValue( mainWindow->fileOpenRecent->maxItems() );
132  lNrf->setBuddy( sb_numRecentFiles );
133  TQString numRecentFileHelpString ( i18n(
134  "<qt>Sets the number of recent files remembered by Kate.<p><strong>NOTE: </strong>"
135  "If you set this lower than the current value, the list will be truncated and "
136  "some items forgotten.</qt>") );
137  TQWhatsThis::add( lNrf, numRecentFileHelpString );
138  TQWhatsThis::add( sb_numRecentFiles, numRecentFileHelpString );
139  connect( sb_numRecentFiles, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) );
140 
141  // sync the konsole ?
142  cb_syncKonsole = new TQCheckBox(bgStartup);
143  cb_syncKonsole->setText(i18n("Sync &terminal emulator with active document"));
144  cb_syncKonsole->setChecked(parent->syncKonsole);
145  TQWhatsThis::add( cb_syncKonsole, i18n(
146  "If this is checked, the built in Konsole will <code>cd</code> to the directory "
147  "of the active document when started and whenever the active document changes, "
148  "if the document is a local file.") );
149  connect( cb_syncKonsole, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) );
150 
151  // modified files notification
152  cb_modNotifications = new TQCheckBox(
153  i18n("Wa&rn about files modified by foreign processes"), bgStartup );
154  cb_modNotifications->setChecked( parent->modNotification );
155  TQWhatsThis::add( cb_modNotifications, i18n(
156  "If enabled, when Kate receives focus you will be asked what to do with "
157  "files that have been modified on the hard disk. If not enabled, you will "
158  "be asked what to do with a file that has been modified on the hard disk only "
159  "when that file gains focus inside Kate.") );
160  connect( cb_modNotifications, TQT_SIGNAL( toggled( bool ) ),
161  this, TQT_SLOT( slotChanged() ) );
162 
163  // GROUP with the one below: "Meta-informations"
164  bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Meta-Information"), frGeneral );
165  lo->addWidget( bgStartup );
166 
167  // save meta infos
168  cb_saveMetaInfos = new TQCheckBox( bgStartup );
169  cb_saveMetaInfos->setText(i18n("Keep &meta-information past sessions"));
170  cb_saveMetaInfos->setChecked(KateDocManager::self()->getSaveMetaInfos());
171  TQWhatsThis::add(cb_saveMetaInfos, i18n(
172  "Check this if you want document configuration like for example "
173  "bookmarks to be saved past editor sessions. The configuration will be "
174  "restored if the document has not changed when reopened."));
175  connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) );
176 
177  // meta infos days
178  TQHBox *hbDmf = new TQHBox( bgStartup );
179  hbDmf->setEnabled(KateDocManager::self()->getSaveMetaInfos());
180  TQLabel *lDmf = new TQLabel( i18n("&Delete unused meta-information after:"), hbDmf );
181  sb_daysMetaInfos = new TQSpinBox( 0, 180, 1, hbDmf );
182  sb_daysMetaInfos->setSpecialValueText(i18n("(never)"));
183  sb_daysMetaInfos->setSuffix(i18n(" day(s)"));
184  sb_daysMetaInfos->setValue( KateDocManager::self()->getDaysMetaInfos() );
185  lDmf->setBuddy( sb_daysMetaInfos );
186  connect( cb_saveMetaInfos, TQT_SIGNAL( toggled( bool ) ), hbDmf, TQT_SLOT( setEnabled( bool ) ) );
187  connect( sb_daysMetaInfos, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( slotChanged() ) );
188 
189  lo->addStretch(1); // :-] works correct without autoadd
190  //END General page
191 
192  path.clear();
193 
194  //BEGIN Session page
195  path << i18n("Application") << i18n("Sessions");
196  TQFrame* frSessions = addPage(path, i18n("Session Management"), BarIcon("history", KIcon::SizeSmall));
197 
198  lo = new TQVBoxLayout( frSessions );
199  lo->setSpacing(KDialog::spacingHint());
200 
201  // GROUP with the one below: "Startup"
202  bgStartup = new TQButtonGroup( 1, Qt::Horizontal, i18n("Elements of Sessions"), frSessions );
203  lo->addWidget( bgStartup );
204 
205  // restore view config
206  cb_restoreVC = new TQCheckBox( bgStartup );
207  cb_restoreVC->setText(i18n("Include &window configuration"));
208  config->setGroup("General");
209  cb_restoreVC->setChecked( config->readBoolEntry("Restore Window Configuration", true) );
210  TQWhatsThis::add(cb_restoreVC, i18n(
211  "Check this if you want all your views and frames restored each time you open Kate"));
212  connect( cb_restoreVC, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotChanged() ) );
213 
214  TQRadioButton *rb1, *rb2, *rb3;
215 
216  sessions_start = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Startup"), frSessions );
217  lo->add (sessions_start);
218 
219  sessions_start->setRadioButtonExclusive( true );
220  sessions_start->insert( rb1=new TQRadioButton( i18n("&Start new session"), sessions_start ), 0 );
221  sessions_start->insert( rb2=new TQRadioButton( i18n("&Load last-used session"), sessions_start ), 1 );
222  sessions_start->insert( rb3=new TQRadioButton( i18n("&Manually choose a session"), sessions_start ), 2 );
223 
224  config->setGroup("General");
225  TQString sesStart (config->readEntry ("Startup Session", "manual"));
226  if (sesStart == "new")
227  sessions_start->setButton (0);
228  else if (sesStart == "last")
229  sessions_start->setButton (1);
230  else
231  sessions_start->setButton (2);
232 
233  connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
234  connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
235  connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
236 
237  sessions_exit = new TQButtonGroup( 1, Qt::Horizontal, i18n("Behavior on Application Exit or Session Switch"), frSessions );
238  lo->add (sessions_exit);
239 
240  sessions_exit->setRadioButtonExclusive( true );
241  sessions_exit->insert( rb1=new TQRadioButton( i18n("&Do not save session"), sessions_exit ), 0 );
242  sessions_exit->insert( rb2=new TQRadioButton( i18n("&Save session"), sessions_exit ), 1 );
243  sessions_exit->insert( rb3=new TQRadioButton( i18n("&Ask user"), sessions_exit ), 2 );
244 
245  config->setGroup("General");
246  TQString sesExit (config->readEntry ("Session Exit", "save"));
247  if (sesExit == "discard")
248  sessions_exit->setButton (0);
249  else if (sesExit == "save")
250  sessions_exit->setButton (1);
251  else
252  sessions_exit->setButton (2);
253 
254  connect(rb1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
255  connect(rb2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
256  connect(rb3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged()));
257 
258  lo->addStretch(1); // :-] works correct without autoadd
259  //END Session page
260 
261  path.clear();
262 
263  // file selector page
264  path << i18n("Application") << i18n("File Selector");
265 
266  TQVBox *page = addVBoxPage( path, i18n("File Selector Settings"),
267  BarIcon("fileopen", KIcon::SizeSmall) );
268  fileSelConfigPage = new KFSConfigPage( page, "file selector config page",
269  mainWindow->fileselector );
270  connect( fileSelConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) );
271  path.clear();
272 
273  path << i18n("Application") << i18n("Document List");
274  page = addVBoxPage( path, i18n("Document List Settings"),
275  BarIcon("view_text", KIcon::SizeSmall) );
276  filelistConfigPage = new KFLConfigPage( page, "file list config page",
277  mainWindow->filelist );
278  connect( filelistConfigPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) );
279  path.clear();
280 
281  path << i18n("Application") << i18n("Plugins");
282  /*TQVBox **/page=addVBoxPage(path,i18n("Plugin Manager"),
283  BarIcon("connect_established",KIcon::SizeSmall));
284  KateConfigPluginPage *configPluginPage = new KateConfigPluginPage(page, this);
285  connect( configPluginPage, TQT_SIGNAL( changed() ), TQT_TQOBJECT(this), TQT_SLOT( slotChanged() ) );
286 
287  // Tools->External Tools menu
288  path.clear();
289  path << i18n("Application") << i18n("External Tools");
290  page = addVBoxPage( path, i18n("External Tools"),
291  BarIcon("configure", KIcon::SizeSmall) );
292  configExternalToolsPage = new KateExternalToolsConfigWidget(page, "external tools config page");
293  connect( configExternalToolsPage, TQT_SIGNAL(changed()), TQT_TQOBJECT(this), TQT_SLOT(slotChanged()) );
294 
295  // editor widgets from kwrite/kwdialog
296  path.clear();
297  path << i18n("Editor");
298  setFolderIcon (path, SmallIcon("edit", KIcon::SizeSmall));
299 
300  for (uint i = 0; i < KTextEditor::configInterfaceExtension (v->document())->configPages (); i++)
301  {
302  path.clear();
303  path << i18n("Editor") << KTextEditor::configInterfaceExtension (v->document())->configPageName (i);
304  /*TQVBox **/page = addVBoxPage(path, KTextEditor::configInterfaceExtension (v->document())->configPageFullName (i),
305  KTextEditor::configInterfaceExtension (v->document())->configPagePixmap(i, KIcon::SizeSmall) );
306 
307  KTextEditor::ConfigPage *cPage = KTextEditor::configInterfaceExtension (v->document())->configPage(i, page);
308  connect( cPage, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) );
309  editorPages.append (cPage);
310  }
311 
312  KatePluginList &pluginList (KatePluginManager::self()->pluginList());
313  for (unsigned int i=0; i < pluginList.size(); ++i)
314  {
315  if ( pluginList[i].load
316  && Kate::pluginConfigInterfaceExtension(pluginList[i].plugin) )
317  addPluginPage (pluginList[i].plugin);
318  }
319 
320  enableButtonSeparator(true);
321  dataChanged = false;
322  unfoldTreeList ();
323 }
324 
325 KateConfigDialog::~KateConfigDialog()
326 {
327 }
328 
329 void KateConfigDialog::addPluginPage (Kate::Plugin *plugin)
330 {
331  if (!Kate::pluginConfigInterfaceExtension(plugin))
332  return;
333 
334  for (uint i=0; i<Kate::pluginConfigInterfaceExtension(plugin)->configPages(); i++)
335  {
336  TQStringList path;
337  path.clear();
338  path << i18n("Application")<<i18n("Plugins") << Kate::pluginConfigInterfaceExtension(plugin)->configPageName(i);
339  TQVBox *page=addVBoxPage(path, Kate::pluginConfigInterfaceExtension(plugin)->configPageFullName(i), Kate::pluginConfigInterfaceExtension(plugin)->configPagePixmap(i, KIcon::SizeSmall));
340 
341  PluginPageListItem *info=new PluginPageListItem;
342  info->plugin = plugin;
343  info->page = Kate::pluginConfigInterfaceExtension(plugin)->configPage (i, page);
344  connect( info->page, TQT_SIGNAL( changed() ), this, TQT_SLOT( slotChanged() ) );
345  pluginPages.append(info);
346  }
347 }
348 
349 void KateConfigDialog::removePluginPage (Kate::Plugin *plugin)
350 {
351  if (!Kate::pluginConfigInterfaceExtension(plugin))
352  return;
353 
354  for (uint i=0; i<pluginPages.count(); i++)
355  {
356  if ( pluginPages.at(i)->plugin == plugin )
357  {
358  TQWidget *w = pluginPages.at(i)->page->parentWidget();
359  delete pluginPages.at(i)->page;
360  delete w;
361  pluginPages.remove(pluginPages.at(i));
362  i--;
363  }
364  }
365 }
366 
367 void KateConfigDialog::slotOk()
368 {
369  slotApply();
370  accept();
371 }
372 
373 void KateConfigDialog::slotApply()
374 {
375  KConfig *config = KateApp::self()->config();
376 
377  // if data changed apply the kate app stuff
378  if( dataChanged )
379  {
380  config->setGroup("General");
381 
382  config->writeEntry("Restore Window Configuration", cb_restoreVC->isChecked());
383 
384  int bu = sessions_start->id (sessions_start->selected());
385 
386  if (bu == 0)
387  config->writeEntry ("Startup Session", "new");
388  else if (bu == 1)
389  config->writeEntry ("Startup Session", "last");
390  else
391  config->writeEntry ("Startup Session", "manual");
392 
393  bu = sessions_exit->id (sessions_exit->selected());
394 
395  if (bu == 0)
396  config->writeEntry ("Session Exit", "discard");
397  else if (bu == 1)
398  config->writeEntry ("Session Exit", "save");
399  else
400  config->writeEntry ("Session Exit", "ask");
401 
402  config->writeEntry("Save Meta Infos", cb_saveMetaInfos->isChecked());
403  KateDocManager::self()->setSaveMetaInfos(cb_saveMetaInfos->isChecked());
404 
405  config->writeEntry("Days Meta Infos", sb_daysMetaInfos->value() );
406  KateDocManager::self()->setDaysMetaInfos(sb_daysMetaInfos->value());
407 
408  config->writeEntry("Modified Notification", cb_modNotifications->isChecked());
409  mainWindow->modNotification = cb_modNotifications->isChecked();
410 
411  mainWindow->syncKonsole = cb_syncKonsole->isChecked();
412  mainWindow->filelist->setSortType(cb_sortFiles->isChecked() ? KateFileList::sortByName : KateFileList::sortByID);
413 
414  config->writeEntry( "Number of recent files", sb_numRecentFiles->value() );
415  mainWindow->fileOpenRecent->setMaxItems( sb_numRecentFiles->value() );
416 
417  fileSelConfigPage->apply();
418 
419  filelistConfigPage->apply();
420 
421  configExternalToolsPage->apply();
422  KateExternalToolsCommand::self()->reload();
423  for (uint i=0; i < KateApp::self()->mainWindows(); i++)
424  {
425  KateMainWindow *win = KateApp::self()->mainWindow (i);
426  win->externalTools->reload();
427  }
428  //mainWindow->externalTools->reload();
429 
430  mainWindow->viewManager()->setShowFullPath( cb_fullPath->isChecked() ); // hm, stored 2 places :(
431 
432  mainWindow->saveOptions ();
433 
434  // save plugin config !!
435  KateApp::self()->pluginManager()->writeConfig ();
436  }
437 
438  //
439  // editor config ! (the apply() methode will check the changed state internally)
440  //
441  for (uint i=0; i<editorPages.count(); i++)
442  {
443  editorPages.at(i)->apply();
444  }
445 
446  v->getDoc()->writeConfig(config);
447 
448  //
449  // plugins config ! (the apply() methode SHOULD check the changed state internally)
450  //
451  for (uint i=0; i<pluginPages.count(); i++)
452  {
453  pluginPages.at(i)->page->apply();
454  }
455 
456  config->sync();
457 
458  dataChanged = false;
459  actionButton( KDialogBase::Apply)->setEnabled( false );
460 }
461 
462 void KateConfigDialog::slotChanged()
463 {
464  dataChanged = true;
465  actionButton( KDialogBase::Apply)->setEnabled( true );
466 }

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for kate by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |