• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

katedialogs.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
00003    Copyright (C) 2003 Christoph Cullmann <cullmann@kde.org>
00004    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00005    Copyright (C) 2006 Dominik Haumann <dhdev@gmx.de>
00006    Copyright (C) 2007 Mirko Stocker <me@misto.ch>
00007 
00008    Based on work of:
00009      Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
00010 
00011    This library is free software; you can redistribute it and/or
00012    modify it under the terms of the GNU Library General Public
00013    License version 2 as published by the Free Software Foundation.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Library General Public License for more details.
00019 
00020    You should have received a copy of the GNU Library General Public License
00021    along with this library; see the file COPYING.LIB.  If not, write to
00022    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023    Boston, MA 02110-1301, USA.
00024 */
00025 
00026 //BEGIN Includes
00027 #include "katedialogs.h"
00028 #include "katedialogs.moc"
00029 
00030 #include "kateautoindent.h"
00031 #include "katebuffer.h"
00032 #include "kateconfig.h"
00033 #include "katedocument.h"
00034 #include "kateglobal.h"
00035 #include "kateschema.h"
00036 #include "katesyntaxdocument.h"
00037 #include "katemodeconfigpage.h"
00038 #include "kateview.h"
00039 #include "katepartpluginmanager.h"
00040 #include "kpluginselector.h"
00041 
00042 // auto generated ui files
00043 #include "ui_modonhdwidget.h"
00044 #include "ui_appearanceconfigwidget.h"
00045 #include "ui_cursorconfigwidget.h"
00046 #include "ui_editconfigwidget.h"
00047 #include "ui_indentationconfigwidget.h"
00048 #include "ui_completionconfigtab.h"
00049 #include "ui_opensaveconfigwidget.h"
00050 #include "ui_opensaveconfigadvwidget.h"
00051 #include "ui_viinputmodeconfigwidget.h"
00052 
00053 #include <ktexteditor/plugin.h>
00054 
00055 #include <kio/job.h>
00056 #include <kio/jobclasses.h>
00057 #include <kio/netaccess.h>
00058 
00059 #include <kapplication.h>
00060 #include <kcharsets.h>
00061 #include <kcolorbutton.h>
00062 #include <kcolorcombo.h>
00063 #include <kcolordialog.h>
00064 #include <kcombobox.h>
00065 #include <kconfig.h>
00066 #include <kdebug.h>
00067 #include <kfontdialog.h>
00068 #include <kglobal.h>
00069 #include <kglobalsettings.h>
00070 #include <kiconloader.h>
00071 #include <kshortcutsdialog.h>
00072 #include <klineedit.h>
00073 #include <klocale.h>
00074 #include <kmessagebox.h>
00075 #include <kmimetypechooser.h>
00076 #include <knuminput.h>
00077 #include <kmenu.h>
00078 #include <kprocess.h>
00079 #include <krun.h>
00080 #include <kseparator.h>
00081 #include <kstandarddirs.h>
00082 #include <ktemporaryfile.h>
00083 #include <kpushbutton.h>
00084 #include <kvbox.h>
00085 #include <kactioncollection.h>
00086 #include <kplugininfo.h>
00087 
00088 #include <ktabwidget.h>
00089 //#include <knewstuff/knewstuff.h>
00090 #include <QtGui/QCheckBox>
00091 #include <QtGui/QComboBox>
00092 #include <QtGui/QDialog>
00093 #include <QtCore/QFile>
00094 #include <QtGui/QGroupBox>
00095 #include <QtGui/QLabel>
00096 #include <QtGui/QLayout>
00097 #include <QtCore/QMap>
00098 #include <QtCore/QObject>
00099 #include <QtGui/QPainter>
00100 #include <QtGui/QRadioButton>
00101 #include <QtGui/QSlider>
00102 #include <QtGui/QSpinBox>
00103 #include <QtCore/QStringList>
00104 #include <QtGui/QTabWidget>
00105 #include <QtCore/QTextCodec>
00106 #include <QtCore/QTextStream>
00107 #include <QtGui/QToolButton>
00108 #include <QtGui/QWhatsThis>
00109 #include <QtGui/QKeyEvent>
00110 #include <QtXml/QDomDocument>
00111 
00112 // trailing slash is important
00113 #define HLDOWNLOADPATH "http://kate.kde.org/syntax/"
00114 
00115 //END
00116 
00117 //BEGIN KateConfigPage
00118 KateConfigPage::KateConfigPage ( QWidget *parent, const char * )
00119   : KTextEditor::ConfigPage (parent)
00120   , m_changed (false)
00121 {
00122   connect (this, SIGNAL(changed()), this, SLOT(somethingHasChanged ()));
00123 }
00124 
00125 KateConfigPage::~KateConfigPage ()
00126 {
00127 }
00128 
00129 void KateConfigPage::slotChanged()
00130 {
00131   emit changed();
00132 }
00133 
00134 void KateConfigPage::somethingHasChanged ()
00135 {
00136   m_changed = true;
00137   kDebug (13000) << "TEST: something changed on the config page: " << this;
00138 }
00139 //END KateConfigPage
00140 
00141 //BEGIN KateIndentConfigTab
00142 KateIndentConfigTab::KateIndentConfigTab(QWidget *parent)
00143   : KateConfigPage(parent)
00144 {
00145   // This will let us have more separation between this page and
00146   // the KTabWidget edge (ereslibre)
00147   QVBoxLayout *layout = new QVBoxLayout;
00148   QWidget *newWidget = new QWidget(this);
00149 
00150   ui = new Ui::IndentationConfigWidget();
00151   ui->setupUi( newWidget );
00152 
00153   ui->cmbMode->addItems (KateAutoIndent::listModes());
00154 
00155   ui->label->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
00156   connect(ui->label, SIGNAL(linkActivated(const QString&)), this, SLOT(showWhatsThis(const QString&)));
00157 
00158   // What's This? help can be found in the ui file
00159 
00160   reload ();
00161 
00162   //
00163   // after initial reload, connect the stuff for the changed () signal
00164   //
00165 
00166   connect(ui->cmbMode, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00167 
00168   connect(ui->chkKeepExtraSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00169   connect(ui->chkIndentPaste, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00170   connect(ui->chkBackspaceUnindents, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00171 
00172   connect(ui->sbIndentWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00173 
00174   connect(ui->rbTabAdvances, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00175   connect(ui->rbTabIndents, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00176   connect(ui->rbTabSmart, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00177 
00178   layout->addWidget(newWidget);
00179   setLayout(layout);
00180 }
00181 
00182 KateIndentConfigTab::~KateIndentConfigTab()
00183 {
00184   delete ui;
00185 }
00186 
00187 void KateIndentConfigTab::showWhatsThis(const QString& text)
00188 {
00189   QWhatsThis::showText(QCursor::pos(), text);
00190 }
00191 
00192 void KateIndentConfigTab::apply ()
00193 {
00194   // nothing changed, no need to apply stuff
00195   if (!hasChanged())
00196     return;
00197   m_changed = false;
00198 
00199   KateDocumentConfig::global()->configStart ();
00200 
00201   uint configFlags = KateDocumentConfig::global()->configFlags();
00202 
00203   configFlags &= ~KateDocumentConfig::cfKeepExtraSpaces;
00204   configFlags &= ~KateDocumentConfig::cfIndentPastedText;
00205   configFlags &= ~KateDocumentConfig::cfBackspaceIndents;
00206 
00207   if (ui->chkKeepExtraSpaces->isChecked()) configFlags |= KateDocumentConfig::cfKeepExtraSpaces;
00208   if (ui->chkIndentPaste->isChecked()) configFlags |= KateDocumentConfig::cfIndentPastedText;
00209   if (ui->chkBackspaceUnindents->isChecked()) configFlags |= KateDocumentConfig::cfBackspaceIndents;
00210 
00211   KateDocumentConfig::global()->setConfigFlags(configFlags);
00212   KateDocumentConfig::global()->setIndentationWidth(ui->sbIndentWidth->value());
00213   KateDocumentConfig::global()->setIndentationMode(KateAutoIndent::modeName(ui->cmbMode->currentIndex()));
00214 
00215   if (ui->rbTabAdvances->isChecked())
00216     KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabInsertsTab );
00217   else if (ui->rbTabIndents->isChecked())
00218     KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabIndents );
00219   else
00220     KateDocumentConfig::global()->setTabHandling( KateDocumentConfig::tabSmart );
00221 
00222   KateDocumentConfig::global()->configEnd ();
00223 }
00224 
00225 void KateIndentConfigTab::reload ()
00226 {
00227   uint configFlags = KateDocumentConfig::global()->configFlags();
00228 
00229   ui->sbIndentWidth->setValue(KateDocumentConfig::global()->indentationWidth());
00230   ui->chkKeepExtraSpaces->setChecked(configFlags & KateDocumentConfig::cfKeepExtraSpaces);
00231   ui->chkIndentPaste->setChecked(configFlags & KateDocumentConfig::cfIndentPastedText);
00232   ui->chkBackspaceUnindents->setChecked(configFlags & KateDocumentConfig::cfBackspaceIndents);
00233 
00234   ui->rbTabAdvances->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabInsertsTab );
00235   ui->rbTabIndents->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabIndents );
00236   ui->rbTabSmart->setChecked( KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabSmart );
00237 
00238   ui->cmbMode->setCurrentIndex (KateAutoIndent::modeNumber (KateDocumentConfig::global()->indentationMode()));
00239 }
00240 //END KateIndentConfigTab
00241 
00242 //BEGIN KateCompletionConfigTab
00243 KateCompletionConfigTab::KateCompletionConfigTab(QWidget *parent)
00244   : KateConfigPage(parent)
00245 {
00246   // This will let us have more separation between this page and
00247   // the KTabWidget edge (ereslibre)
00248   QVBoxLayout *layout = new QVBoxLayout;
00249   QWidget *newWidget = new QWidget(this);
00250 
00251   ui = new Ui::CompletionConfigTab ();
00252   ui->setupUi( newWidget );
00253 
00254   // What's This? help can be found in the ui file
00255 
00256   reload ();
00257 
00258   //
00259   // after initial reload, connect the stuff for the changed () signal
00260   //
00261 
00262   connect(ui->chkAutoCompletionEnabled, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00263 
00264   layout->addWidget(newWidget);
00265   setLayout(layout);
00266 }
00267 
00268 KateCompletionConfigTab::~KateCompletionConfigTab()
00269 {
00270   delete ui;
00271 }
00272 
00273 void KateCompletionConfigTab::showWhatsThis(const QString& text)
00274 {
00275   QWhatsThis::showText(QCursor::pos(), text);
00276 }
00277 
00278 void KateCompletionConfigTab::apply ()
00279 {
00280   // nothing changed, no need to apply stuff
00281   if (!hasChanged())
00282     return;
00283   m_changed = false;
00284 
00285   KateViewConfig::global()->configStart ();
00286   KateViewConfig::global()->setAutomaticCompletionInvocation (ui->chkAutoCompletionEnabled->isChecked());
00287   KateViewConfig::global()->configEnd ();
00288 }
00289 
00290 void KateCompletionConfigTab::reload ()
00291 {
00292   ui->chkAutoCompletionEnabled->setChecked( KateViewConfig::global()->automaticCompletionInvocation () );
00293 }
00294 //END KateCompletionConfigTab
00295 
00296 //BEGIN KateViInputModeConfigTab
00297 KateViInputModeConfigTab::KateViInputModeConfigTab(QWidget *parent)
00298   : KateConfigPage(parent)
00299 {
00300   // This will let us have more separation between this page and
00301   // the KTabWidget edge (ereslibre)
00302   QVBoxLayout *layout = new QVBoxLayout;
00303   QWidget *newWidget = new QWidget(this);
00304 
00305   ui = new Ui::ViInputModeConfigWidget ();
00306   ui->setupUi( newWidget );
00307 
00308   // What's This? help can be found in the ui file
00309 
00310   reload ();
00311 
00312   //
00313   // after initial reload, connect the stuff for the changed () signal
00314   //
00315 
00316   connect(ui->chkViInputModeDefault, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00317   connect(ui->chkViCommandsOverride, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00318   connect(ui->chkViStatusBarHide, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00319 
00320   layout->addWidget(newWidget);
00321   setLayout(layout);
00322 }
00323 
00324 KateViInputModeConfigTab::~KateViInputModeConfigTab()
00325 {
00326   delete ui;
00327 }
00328 
00329 void KateViInputModeConfigTab::showWhatsThis(const QString& text)
00330 {
00331   QWhatsThis::showText(QCursor::pos(), text);
00332 }
00333 
00334 void KateViInputModeConfigTab::apply ()
00335 {
00336   // nothing changed, no need to apply stuff
00337   if (!hasChanged())
00338     return;
00339   m_changed = false;
00340 
00341   KateViewConfig::global()->configStart ();
00342   KateViewConfig::global()->setViInputMode (ui->chkViInputModeDefault->isChecked());
00343   KateViewConfig::global()->setViInputModeStealKeys (ui->chkViCommandsOverride->isChecked());
00344   KateViewConfig::global()->setViInputModeHideStatusBar (ui->chkViStatusBarHide->isChecked());
00345   KateViewConfig::global()->configEnd ();
00346 }
00347 
00348 void KateViInputModeConfigTab::reload ()
00349 {
00350   ui->chkViInputModeDefault->setChecked( KateViewConfig::global()->viInputMode () );
00351   ui->chkViCommandsOverride->setChecked( KateViewConfig::global()->viInputModeStealKeys () );
00352   ui->chkViStatusBarHide->setChecked( KateViewConfig::global()->viInputModeHideStatusBar () );
00353 }
00354 //END KateViInputModeConfigTab
00355 
00356 
00357 //BEGIN KateSelectConfigTab
00358 KateSelectConfigTab::KateSelectConfigTab(QWidget *parent)
00359   : KateConfigPage(parent)
00360 {
00361   // This will let us having more separation between this page and
00362   // the KTabWidget edge (ereslibre)
00363   QVBoxLayout *layout = new QVBoxLayout;
00364   QWidget *newWidget = new QWidget(this);
00365 
00366   uint configFlags = KateDocumentConfig::global()->configFlags();
00367 
00368   ui = new Ui::CursorConfigWidget();
00369   ui->setupUi( newWidget );
00370 
00371   ui->chkSmartHome->setChecked(configFlags & KateDocumentConfig::cfSmartHome);
00372   connect(ui->chkSmartHome, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00373 
00374   ui->chkWrapCursor->setChecked(configFlags & KateDocumentConfig::cfWrapCursor);
00375   connect(ui->chkWrapCursor, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00376 
00377   ui->chkPagingMovesCursor->setChecked(KateDocumentConfig::global()->pageUpDownMovesCursor());
00378   connect(ui->chkPagingMovesCursor, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00379 
00380   ui->sbAutoCenterCursor->setValue(KateViewConfig::global()->autoCenterLines());
00381   connect(ui->sbAutoCenterCursor, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00382 
00383   // What's This? Help is in the ui-files
00384 
00385   reload ();
00386 
00387   //
00388   // after initial reload, connect the stuff for the changed () signal
00389   //
00390 
00391   connect(ui->rbNormal, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00392   connect(ui->rbPersistent, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00393 
00394   layout->addWidget(newWidget);
00395   setLayout(layout);
00396 }
00397 
00398 KateSelectConfigTab::~KateSelectConfigTab()
00399 {
00400   delete ui;
00401 }
00402 
00403 void KateSelectConfigTab::apply ()
00404 {
00405   // nothing changed, no need to apply stuff
00406   if (!hasChanged())
00407     return;
00408   m_changed = false;
00409 
00410   KateViewConfig::global()->configStart ();
00411   KateDocumentConfig::global()->configStart ();
00412 
00413   uint configFlags = KateDocumentConfig::global()->configFlags();
00414 
00415   configFlags &= ~KateDocumentConfig::cfSmartHome;
00416   configFlags &= ~KateDocumentConfig::cfWrapCursor;
00417 
00418   if (ui->chkSmartHome->isChecked()) configFlags |= KateDocumentConfig::cfSmartHome;
00419   if (ui->chkWrapCursor->isChecked()) configFlags |= KateDocumentConfig::cfWrapCursor;
00420 
00421   KateDocumentConfig::global()->setConfigFlags(configFlags);
00422 
00423   KateViewConfig::global()->setAutoCenterLines(qMax(0, ui->sbAutoCenterCursor->value()));
00424   KateDocumentConfig::global()->setPageUpDownMovesCursor(ui->chkPagingMovesCursor->isChecked());
00425 
00426   KateViewConfig::global()->setPersistentSelection (ui->rbPersistent->isChecked());
00427 
00428   KateDocumentConfig::global()->configEnd ();
00429   KateViewConfig::global()->configEnd ();
00430 }
00431 
00432 void KateSelectConfigTab::reload ()
00433 {
00434   ui->rbNormal->setChecked( ! KateViewConfig::global()->persistentSelection() );
00435   ui->rbPersistent->setChecked( KateViewConfig::global()->persistentSelection() );
00436 }
00437 //END KateSelectConfigTab
00438 
00439 //BEGIN KateEditConfigTab
00440 KateEditConfigTab::KateEditConfigTab(QWidget *parent)
00441   : KateConfigPage(parent)
00442   , selectConfigTab(new KateSelectConfigTab(this))
00443   , indentConfigTab(new KateIndentConfigTab(this))
00444   , completionConfigTab (new KateCompletionConfigTab(this))
00445   , viInputModeConfigTab(new KateViInputModeConfigTab(this))
00446 {
00447   // FIXME: Is really needed to move all this code below to another class,
00448   // since it is another tab itself on the config dialog. This means we should
00449   // initialize, add and work with as we do with selectConfigTab and
00450   // indentConfigTab (ereslibre)
00451   QVBoxLayout *layout = new QVBoxLayout;
00452   layout->setMargin(0);
00453   KTabWidget *tabWidget = new KTabWidget(this);
00454   uint configFlags = KateDocumentConfig::global()->configFlags();
00455 
00456   QWidget *tmpWidget = new QWidget(tabWidget);
00457   QVBoxLayout *internalLayout = new QVBoxLayout;
00458   QWidget *newWidget = new QWidget(tabWidget);
00459   ui = new Ui::EditConfigWidget();
00460   ui->setupUi( newWidget );
00461 
00462   ui->chkReplaceTabs->setChecked( configFlags & KateDocumentConfig::cfReplaceTabsDyn );
00463   connect( ui->chkReplaceTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
00464 
00465   ui->chkShowTabs->setChecked( configFlags & KateDocumentConfig::cfShowTabs );
00466   connect(ui->chkShowTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00467 
00468   ui->chkShowSpaces->setChecked( configFlags & KateDocumentConfig::cfShowSpaces );
00469   connect(ui->chkShowSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00470 
00471   ui->sbTabWidth->setValue( KateDocumentConfig::global()->tabWidth() );
00472   connect(ui->sbTabWidth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00473 
00474 
00475   ui->chkStaticWordWrap->setChecked(KateDocumentConfig::global()->wordWrap());
00476   connect(ui->chkStaticWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00477 
00478   ui->chkShowStaticWordWrapMarker->setChecked( KateRendererConfig::global()->wordWrapMarker() );
00479   connect(ui->chkShowStaticWordWrapMarker, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00480 
00481   ui->sbWordWrap->setValue( KateDocumentConfig::global()->wordWrapAt() );
00482   connect(ui->sbWordWrap, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00483 
00484 
00485   ui->chkRemoveTrailingSpaces->setChecked( configFlags & KateDocumentConfig::cfRemoveTrailingDyn );
00486   connect( ui->chkRemoveTrailingSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()) );
00487 
00488   ui->chkAutoBrackets->setChecked( configFlags & KateDocumentConfig::cfAutoBrackets );
00489   connect(ui->chkAutoBrackets, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00490 
00491   // What is this? help is in the ui-file
00492 
00493   internalLayout->addWidget(newWidget);
00494   tmpWidget->setLayout(internalLayout);
00495 
00496   // add all tabs
00497   tabWidget->insertTab(0, tmpWidget, i18n("General"));
00498   tabWidget->insertTab(1, selectConfigTab, i18n("Cursor & Selection"));
00499   tabWidget->insertTab(2, indentConfigTab, i18n("Indentation"));
00500   tabWidget->insertTab(3, completionConfigTab, i18n("Auto Completion"));
00501   tabWidget->insertTab(4, viInputModeConfigTab, i18n("Vi Input Mode"));
00502 
00503   connect(selectConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
00504   connect(indentConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
00505   connect(completionConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
00506   connect(viInputModeConfigTab, SIGNAL(changed()), this, SLOT(slotChanged()));
00507 
00508   layout->addWidget(tabWidget);
00509   setLayout(layout);
00510 }
00511 
00512 KateEditConfigTab::~KateEditConfigTab()
00513 {
00514   delete ui;
00515 }
00516 
00517 void KateEditConfigTab::apply ()
00518 {
00519   // try to update the rest of tabs
00520   selectConfigTab->apply();
00521   indentConfigTab->apply();
00522   completionConfigTab->apply();
00523   viInputModeConfigTab->apply();
00524 
00525   // nothing changed, no need to apply stuff
00526   if (!hasChanged())
00527     return;
00528   m_changed = false;
00529 
00530   KateViewConfig::global()->configStart ();
00531   KateDocumentConfig::global()->configStart ();
00532 
00533   uint configFlags = KateDocumentConfig::global()->configFlags();
00534 
00535   configFlags &= ~KateDocumentConfig::cfAutoBrackets;
00536   configFlags &= ~KateDocumentConfig::cfShowTabs;
00537   configFlags &= ~KateDocumentConfig::cfShowSpaces;
00538   configFlags &= ~KateDocumentConfig::cfReplaceTabsDyn;
00539   configFlags &= ~KateDocumentConfig::cfRemoveTrailingDyn;
00540 
00541   if (ui->chkAutoBrackets->isChecked()) configFlags |= KateDocumentConfig::cfAutoBrackets;
00542   if (ui->chkShowTabs->isChecked()) configFlags |= KateDocumentConfig::cfShowTabs;
00543   if (ui->chkShowSpaces->isChecked()) configFlags |= KateDocumentConfig::cfShowSpaces;
00544   if (ui->chkReplaceTabs->isChecked()) configFlags |= KateDocumentConfig::cfReplaceTabsDyn;
00545   if (ui->chkRemoveTrailingSpaces->isChecked()) configFlags |= KateDocumentConfig::cfRemoveTrailingDyn;
00546 
00547   KateDocumentConfig::global()->setConfigFlags(configFlags);
00548 
00549   KateDocumentConfig::global()->setWordWrapAt(ui->sbWordWrap->value());
00550   KateDocumentConfig::global()->setWordWrap(ui->chkStaticWordWrap->isChecked());
00551   KateDocumentConfig::global()->setTabWidth(ui->sbTabWidth->value());
00552 
00553   KateRendererConfig::global()->setWordWrapMarker (ui->chkShowStaticWordWrapMarker->isChecked());
00554 
00555   KateDocumentConfig::global()->configEnd ();
00556   KateViewConfig::global()->configEnd ();
00557 }
00558 
00559 void KateEditConfigTab::reload ()
00560 {
00561   selectConfigTab->reload();
00562   indentConfigTab->reload();
00563   completionConfigTab->reload();
00564   viInputModeConfigTab->reload();
00565 }
00566 
00567 void KateEditConfigTab::reset ()
00568 {
00569   selectConfigTab->reset();
00570   indentConfigTab->reset();
00571   completionConfigTab->reset();
00572   viInputModeConfigTab->reset();
00573 }
00574 
00575 void KateEditConfigTab::defaults ()
00576 {
00577   selectConfigTab->defaults();
00578   indentConfigTab->defaults();
00579   completionConfigTab->defaults();
00580   viInputModeConfigTab->defaults();
00581 }
00582 //END KateEditConfigTab
00583 
00584 //BEGIN KateViewDefaultsConfig
00585 KateViewDefaultsConfig::KateViewDefaultsConfig(QWidget *parent)
00586   :KateConfigPage(parent)
00587 {
00588   ui = new Ui::AppearanceConfigWidget();
00589   ui->setupUi( this );
00590 
00591   if (KateDocument::simpleMode ())
00592     ui->gbSortBookmarks->hide ();
00593 
00594   ui->cmbDynamicWordWrapIndicator->addItem( i18n("Off") );
00595   ui->cmbDynamicWordWrapIndicator->addItem( i18n("Follow Line Numbers") );
00596   ui->cmbDynamicWordWrapIndicator->addItem( i18n("Always On") );
00597 
00598   ui->chkShowIndentationLines->setChecked(KateRendererConfig::global()->showIndentationLines());
00599   ui->chkShowWholeBracketExpression->setChecked(KateRendererConfig::global()->showWholeBracketExpression());
00600 
00601   // What's This? help is in the ui-file
00602 
00603   reload();
00604 
00605   //
00606   // after initial reload, connect the stuff for the changed () signal
00607   //
00608 
00609   connect(ui->gbWordWrap, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00610   connect(ui->cmbDynamicWordWrapIndicator, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00611   connect(ui->sbDynamicWordWrapDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00612   connect(ui->chkIconBorder, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00613   connect(ui->chkScrollbarMarks, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00614   connect(ui->chkLineNumbers, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00615   connect(ui->chkShowFoldingMarkers, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00616   connect(ui->rbSortBookmarksByPosition, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00617   connect(ui->rbSortBookmarksByCreation, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00618   connect(ui->chkShowIndentationLines, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00619   connect(ui->chkShowWholeBracketExpression, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00620   connect(ui->chkDeveloperMode, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00621 }
00622 
00623 KateViewDefaultsConfig::~KateViewDefaultsConfig()
00624 {
00625   delete ui;
00626 }
00627 
00628 void KateViewDefaultsConfig::apply ()
00629 {
00630   // nothing changed, no need to apply stuff
00631   if (!hasChanged())
00632     return;
00633   m_changed = false;
00634 
00635   KateViewConfig::global()->configStart ();
00636   KateRendererConfig::global()->configStart ();
00637 
00638   KateViewConfig::global()->setDynWordWrap (ui->gbWordWrap->isChecked());
00639   KateViewConfig::global()->setDynWordWrapIndicators (ui->cmbDynamicWordWrapIndicator->currentIndex ());
00640   KateViewConfig::global()->setDynWordWrapAlignIndent(ui->sbDynamicWordWrapDepth->value());
00641   KateViewConfig::global()->setLineNumbers (ui->chkLineNumbers->isChecked());
00642   KateViewConfig::global()->setIconBar (ui->chkIconBorder->isChecked());
00643   KateViewConfig::global()->setScrollBarMarks (ui->chkScrollbarMarks->isChecked());
00644   KateViewConfig::global()->setFoldingBar (ui->chkShowFoldingMarkers->isChecked());
00645 
00646   KateViewConfig::global()->setBookmarkSort (ui->rbSortBookmarksByPosition->isChecked()?0:1);
00647   KateRendererConfig::global()->setShowIndentationLines(ui->chkShowIndentationLines->isChecked());
00648   KateRendererConfig::global()->setShowWholeBracketExpression(ui->chkShowWholeBracketExpression->isChecked());
00649 
00650   KateDocumentConfig::global()->setAllowSimpleMode (!ui->chkDeveloperMode->isChecked());
00651 
00652   KateRendererConfig::global()->configEnd ();
00653   KateViewConfig::global()->configEnd ();
00654 }
00655 
00656 void KateViewDefaultsConfig::reload ()
00657 {
00658   ui->gbWordWrap->setChecked(KateViewConfig::global()->dynWordWrap());
00659   ui->cmbDynamicWordWrapIndicator->setCurrentIndex( KateViewConfig::global()->dynWordWrapIndicators() );
00660   ui->sbDynamicWordWrapDepth->setValue(KateViewConfig::global()->dynWordWrapAlignIndent());
00661   ui->chkLineNumbers->setChecked(KateViewConfig::global()->lineNumbers());
00662   ui->chkIconBorder->setChecked(KateViewConfig::global()->iconBar());
00663   ui->chkScrollbarMarks->setChecked(KateViewConfig::global()->scrollBarMarks());
00664   ui->chkShowFoldingMarkers->setChecked(KateViewConfig::global()->foldingBar());
00665   ui->rbSortBookmarksByPosition->setChecked(KateViewConfig::global()->bookmarkSort()==0);
00666   ui->rbSortBookmarksByCreation->setChecked(KateViewConfig::global()->bookmarkSort()==1);
00667   ui->chkShowIndentationLines->setChecked(KateRendererConfig::global()->showIndentationLines());
00668   ui->chkShowWholeBracketExpression->setChecked(KateRendererConfig::global()->showWholeBracketExpression());
00669   ui->chkDeveloperMode->setChecked(!KateDocumentConfig::global()->allowSimpleMode());
00670 }
00671 
00672 void KateViewDefaultsConfig::reset () {;}
00673 
00674 void KateViewDefaultsConfig::defaults (){;}
00675 //END KateViewDefaultsConfig
00676 
00677 //BEGIN KateSaveConfigTab
00678 KateSaveConfigTab::KateSaveConfigTab( QWidget *parent )
00679   : KateConfigPage( parent )
00680   , modeConfigPage( new ModeConfigPage( this ) )
00681 {
00682   // FIXME: Is really needed to move all this code below to another class,
00683   // since it is another tab itself on the config dialog. This means we should
00684   // initialize, add and work with as we do with modeConfigPage (ereslibre)
00685   QVBoxLayout *layout = new QVBoxLayout;
00686   layout->setMargin(0);
00687   KTabWidget *tabWidget = new KTabWidget(this);
00688 
00689   QWidget *tmpWidget = new QWidget(tabWidget);
00690   QVBoxLayout *internalLayout = new QVBoxLayout;
00691   QWidget *newWidget = new QWidget(tabWidget);
00692   ui = new Ui::OpenSaveConfigWidget();
00693   ui->setupUi( newWidget );
00694 
00695   QWidget *tmpWidget2 = new QWidget(tabWidget);
00696   QVBoxLayout *internalLayout2 = new QVBoxLayout;
00697   QWidget *newWidget2 = new QWidget(tabWidget);
00698   uiadv = new Ui::OpenSaveConfigAdvWidget();
00699   uiadv->setupUi( newWidget2 );
00700 
00701   // What's this help is added in ui/opensaveconfigwidget.ui
00702   reload();
00703 
00704   //
00705   // after initial reload, connect the stuff for the changed () signal
00706   //
00707 
00708   connect( ui->cmbEncoding, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00709   connect( ui->cmbEncodingDetection, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00710   connect( ui->cmbEOL, SIGNAL(activated(int)), this, SLOT(slotChanged()));
00711   connect( ui->chkDetectEOL, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00712   connect( ui->chkRemoveTrailingSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged()));
00713   connect( uiadv->chkBackupLocalFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00714   connect( uiadv->chkBackupRemoteFiles, SIGNAL( toggled(bool) ), this, SLOT( slotChanged() ) );
00715   connect( uiadv->sbConfigFileSearchDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged()));
00716   connect( uiadv->edtBackupPrefix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00717   connect( uiadv->edtBackupSuffix, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00718 
00719   internalLayout->addWidget(newWidget);
00720   tmpWidget->setLayout(internalLayout);
00721   internalLayout2->addWidget(newWidget2);
00722   tmpWidget2->setLayout(internalLayout2);
00723 
00724   // add all tabs
00725   tabWidget->insertTab(0, tmpWidget, i18n("General"));
00726   tabWidget->insertTab(1, tmpWidget2, i18n("Advanced"));
00727   tabWidget->insertTab(2, modeConfigPage, i18n("Modes & Filetypes"));
00728 
00729   connect(modeConfigPage, SIGNAL(changed()), this, SLOT(slotChanged()));
00730 
00731   layout->addWidget(tabWidget);
00732   setLayout(layout);
00733 }
00734 
00735 KateSaveConfigTab::~KateSaveConfigTab()
00736 {
00737   delete ui;
00738 }
00739 
00740 void KateSaveConfigTab::apply()
00741 {
00742   modeConfigPage->apply();
00743 
00744   // nothing changed, no need to apply stuff
00745   if (!hasChanged())
00746     return;
00747   m_changed = false;
00748 
00749   KateDocumentConfig::global()->configStart ();
00750 
00751   if ( uiadv->edtBackupSuffix->text().isEmpty() && uiadv->edtBackupPrefix->text().isEmpty() ) {
00752     KMessageBox::information(
00753                 this,
00754                 i18n("You did not provide a backup suffix or prefix. Using default suffix: '~'"),
00755                 i18n("No Backup Suffix or Prefix")
00756                         );
00757     uiadv->edtBackupSuffix->setText( "~" );
00758   }
00759 
00760   uint f( 0 );
00761   if ( uiadv->chkBackupLocalFiles->isChecked() )
00762     f |= KateDocumentConfig::LocalFiles;
00763   if ( uiadv->chkBackupRemoteFiles->isChecked() )
00764     f |= KateDocumentConfig::RemoteFiles;
00765 
00766   KateDocumentConfig::global()->setBackupFlags(f);
00767   KateDocumentConfig::global()->setBackupPrefix(uiadv->edtBackupPrefix->text());
00768   KateDocumentConfig::global()->setBackupSuffix(uiadv->edtBackupSuffix->text());
00769 
00770   KateDocumentConfig::global()->setSearchDirConfigDepth(uiadv->sbConfigFileSearchDepth->value());
00771 
00772   uint configFlags = KateDocumentConfig::global()->configFlags();
00773 
00774   configFlags &= ~KateDocumentConfig::cfRemoveSpaces; // clear flag
00775   if (ui->chkRemoveTrailingSpaces->isChecked()) configFlags |= KateDocumentConfig::cfRemoveSpaces; // set flag if checked
00776 
00777   KateDocumentConfig::global()->setConfigFlags(configFlags);
00778 
00779   KateDocumentConfig::global()->setEncoding((ui->cmbEncoding->currentIndex() == 0) ? "" : KGlobal::charsets()->encodingForName(ui->cmbEncoding->currentText()));
00780   KateDocumentConfig::global()->setEncodingProberType(
00781       (KEncodingProber::ProberType)ui->cmbEncodingDetection->itemData(ui->cmbEncodingDetection->currentIndex()).toUInt());
00782 
00783   KateDocumentConfig::global()->setEol(ui->cmbEOL->currentIndex());
00784   KateDocumentConfig::global()->setAllowEolDetection(ui->chkDetectEOL->isChecked());
00785 
00786   KateDocumentConfig::global()->configEnd ();
00787 }
00788 
00789 void KateSaveConfigTab::reload()
00790 {
00791   modeConfigPage->reload();
00792 
00793   // encoding
00794   ui->cmbEncoding->clear ();
00795   ui->cmbEncoding->addItem (i18n("KDE Default"));
00796   ui->cmbEncoding->setCurrentIndex(0);
00797   QStringList encodings (KGlobal::charsets()->descriptiveEncodingNames());
00798   int insert = 1;
00799   for (int i=0; i < encodings.count(); i++)
00800   {
00801     bool found = false;
00802     QTextCodec *codecForEnc = KGlobal::charsets()->codecForName(KGlobal::charsets()->encodingForName(encodings[i]), found);
00803 
00804     if (found)
00805     {
00806       ui->cmbEncoding->addItem (encodings[i]);
00807 
00808       if ( codecForEnc->name() == KateDocumentConfig::global()->encoding() )
00809       {
00810         ui->cmbEncoding->setCurrentIndex(insert);
00811       }
00812 
00813       insert++;
00814     }
00815   }
00816 
00817   // encoding detection
00818   ui->cmbEncodingDetection->clear ();
00819 
00820   ui->cmbEncodingDetection->addItem (i18n("Disabled"), QVariant((uint)KEncodingProber::None));
00821   ui->cmbEncodingDetection->setCurrentIndex(0);
00822 
00823   ui->cmbEncodingDetection->addItem (i18n("Universal"), QVariant((uint)KEncodingProber::Universal));
00824 
00825   QStringList items;
00826   foreach (const QStringList &encodingsForScript, KGlobal::charsets()->encodingsByScript())
00827     items << encodingsForScript.at(0);
00828   items.sort();
00829   foreach (const QString &item, items) {
00830     KEncodingProber::ProberType scri=KEncodingProber::proberTypeForName(item);
00831     ui->cmbEncodingDetection->addItem (item, QVariant((uint)scri));
00832     if (scri==KateDocumentConfig::global()->encodingProberType())
00833       ui->cmbEncodingDetection->setCurrentIndex(ui->cmbEncodingDetection->count()-1);
00834   }
00835 
00836   // eol
00837   ui->cmbEOL->setCurrentIndex(KateDocumentConfig::global()->eol());
00838   ui->chkDetectEOL->setChecked(KateDocumentConfig::global()->allowEolDetection());
00839 
00840   const uint configFlags = KateDocumentConfig::global()->configFlags();
00841   ui->chkRemoveTrailingSpaces->setChecked(configFlags & KateDocumentConfig::cfRemoveSpaces);
00842   uiadv->sbConfigFileSearchDepth->setValue(KateDocumentConfig::global()->searchDirConfigDepth());
00843 
00844   // other stuff
00845   uint f ( KateDocumentConfig::global()->backupFlags() );
00846   uiadv->chkBackupLocalFiles->setChecked( f & KateDocumentConfig::LocalFiles );
00847   uiadv->chkBackupRemoteFiles->setChecked( f & KateDocumentConfig::RemoteFiles );
00848   uiadv->edtBackupPrefix->setText( KateDocumentConfig::global()->backupPrefix() );
00849   uiadv->edtBackupSuffix->setText( KateDocumentConfig::global()->backupSuffix() );
00850 }
00851 
00852 void KateSaveConfigTab::reset()
00853 {
00854   modeConfigPage->reset();
00855 }
00856 
00857 void KateSaveConfigTab::defaults()
00858 {
00859   modeConfigPage->defaults();
00860 
00861   uiadv->chkBackupLocalFiles->setChecked( true );
00862   uiadv->chkBackupRemoteFiles->setChecked( false );
00863   uiadv->edtBackupPrefix->setText( "" );
00864   uiadv->edtBackupSuffix->setText( "~" );
00865 }
00866 
00867 //END KateSaveConfigTab
00868 
00869 //BEGIN KatePartPluginConfigPage
00870 KatePartPluginConfigPage::KatePartPluginConfigPage (QWidget *parent)
00871   : KateConfigPage (parent, "")
00872   , scriptConfigPage (new KateScriptConfigPage(this))
00873 {
00874   // FIXME: Is really needed to move all this code below to another class,
00875   // since it is another tab itself on the config dialog. This means we should
00876   // initialize, add and work with as we do with scriptConfigPage (ereslibre)
00877   QVBoxLayout *generalLayout = new QVBoxLayout;
00878   generalLayout->setMargin(0);
00879   KTabWidget *tabWidget = new KTabWidget(this);
00880 
00881   QWidget *tmpWidget = new QWidget(tabWidget);
00882   QVBoxLayout *internalLayout = new QVBoxLayout;
00883   QWidget *newWidget = new QWidget(tabWidget);
00884   QVBoxLayout *layout = new QVBoxLayout;
00885   newWidget->setLayout(layout);
00886   layout->setMargin(0);
00887 
00888   plugins.clear();
00889 
00890   int i = 0;
00891   foreach (const KatePartPluginInfo &info, KatePartPluginManager::self()->pluginList())
00892   {
00893     KPluginInfo it(info.service);
00894     it.setPluginEnabled(info.load);
00895     plugins.append(it);
00896     i++;
00897   }
00898 
00899   selector = new KPluginSelector(0);
00900 
00901   connect(selector, SIGNAL(changed(bool)), this, SLOT(slotChanged()));
00902   connect(selector, SIGNAL(configCommitted(QByteArray)), this, SLOT(slotChanged()));
00903 
00904   selector->addPlugins(plugins, KPluginSelector::IgnoreConfigFile, i18n("Editor Plugins"), "Editor");
00905   layout->addWidget(selector);
00906 
00907   internalLayout->addWidget(newWidget);
00908   tmpWidget->setLayout(internalLayout);
00909 
00910   // add all tabs
00911   tabWidget->insertTab(0, tmpWidget, i18n("Plugins"));
00912   tabWidget->insertTab(1, scriptConfigPage, i18n("Scripts"));
00913 
00914   generalLayout->addWidget(tabWidget);
00915   setLayout(generalLayout);
00916 }
00917 
00918 KatePartPluginConfigPage::~KatePartPluginConfigPage ()
00919 {
00920 }
00921 
00922 void KatePartPluginConfigPage::apply ()
00923 {
00924   scriptConfigPage->apply();
00925 
00926   selector->updatePluginsState();
00927 
00928   KatePartPluginList &katePluginList = KatePartPluginManager::self()->pluginList();
00929   for (int i=0; i < plugins.count(); i++) {
00930     if (plugins[i].isPluginEnabled()) {
00931       if (!katePluginList[i].load) {
00932         KatePartPluginManager::self()->loadPlugin(katePluginList[i]);
00933         KatePartPluginManager::self()->enablePlugin(katePluginList[i]);
00934       }
00935     } else {
00936       if (katePluginList[i].load) {
00937         KatePartPluginManager::self()->disablePlugin(katePluginList[i]);
00938         KatePartPluginManager::self()->unloadPlugin(katePluginList[i]);
00939       }
00940     }
00941   }
00942 }
00943 
00944 void KatePartPluginConfigPage::reload ()
00945 {
00946   scriptConfigPage->reload();
00947 
00948   selector->load();
00949 }
00950 
00951 void KatePartPluginConfigPage::reset ()
00952 {
00953   scriptConfigPage->reset();
00954 
00955   selector->load();
00956 }
00957 
00958 void KatePartPluginConfigPage::defaults ()
00959 {
00960   scriptConfigPage->defaults();
00961 
00962   selector->defaults();
00963 }
00964 //END KatePartPluginConfigPage
00965 
00966 class KateScriptNewStuff {};
00967 
00968 /*
00969 class KateScriptNewStuff: public KNewStuff {
00970   public:
00971     KateScriptNewStuff(QWidget *parent):KNewStuff("kate/scripts",parent) {}
00972     virtual ~KateScriptNewStuff() {}
00973     virtual bool install( const QString &fileName ) {return false;}
00974     virtual bool createUploadFile( const QString &fileName ) {return false;}
00975 };
00976 */
00977 //BEGIN KateScriptConfigPage
00978 KateScriptConfigPage::KateScriptConfigPage(QWidget *parent): KateConfigPage(parent,""), m_newStuff(new KateScriptNewStuff())
00979 {
00980   // TODO: Please look at KateSelectConfigTab or ModeConfigPage to add
00981   // a layout like we do there, to be consistent and have on all config
00982   // pages the same distance to the KTabWidget edge (ereslibre)
00983 
00984   //m_newStuff->download();
00985 }
00986 
00987 KateScriptConfigPage::~KateScriptConfigPage()
00988 {
00989   delete m_newStuff;
00990   m_newStuff=0;
00991 }
00992 
00993 void KateScriptConfigPage::apply () {
00994 }
00995 void KateScriptConfigPage::reload () {
00996 }
00997 
00998 //END KateScriptConfigPage
00999 
01000 //BEGIN KateHlDownloadDialog
01001 KateHlDownloadDialog::KateHlDownloadDialog(QWidget *parent, const char *name, bool modal)
01002   : KDialog( parent )
01003 {
01004   setCaption( i18n("Highlight Download") );
01005   setButtons( User1 | Close );
01006   setButtonGuiItem( User1, KGuiItem(i18n("&Install")) );
01007   setDefaultButton( User1 );
01008   setObjectName( name );
01009   setModal( modal );
01010   showButtonSeparator( true );
01011 
01012   KVBox* vbox = new KVBox(this);
01013   setMainWidget(vbox);
01014   vbox->setSpacing(spacingHint());
01015   new QLabel(i18n("Select the syntax highlighting files you want to update:"), vbox);
01016   list = new QTreeWidget(vbox);
01017   list->setColumnCount(4);
01018   list->setHeaderLabels(QStringList() << "" << i18n("Name") << i18n("Installed") << i18n("Latest"));
01019   list->setSelectionMode(QAbstractItemView::MultiSelection);
01020   list->setAllColumnsShowFocus(true);
01021   list->setRootIsDecorated(false);
01022   list->setColumnWidth(0, 22);
01023 
01024   new QLabel(i18n("<b>Note:</b> New versions are selected automatically."), vbox);
01025   setButtonIcon(User1, KIcon("dialog-ok"));
01026 
01027   transferJob = KIO::get(
01028     KUrl(QString(HLDOWNLOADPATH)
01029        + QString("update-")
01030        + KateGlobal::katePartVersion()
01031        + QString(".xml")), KIO::Reload );
01032   connect(transferJob, SIGNAL(data(KIO::Job *, const QByteArray &)),
01033     this, SLOT(listDataReceived(KIO::Job *, const QByteArray &)));
01034 //        void data( KIO::Job *, const QByteArray &data);
01035   resize(450, 400);
01036   connect(this,SIGNAL(user1Clicked()),this,SLOT(slotUser1()));
01037 }
01038 
01039 KateHlDownloadDialog::~KateHlDownloadDialog(){}
01040 
01041 void KateHlDownloadDialog::listDataReceived(KIO::Job *, const QByteArray &data)
01042 {
01043   if (!transferJob || transferJob->isErrorPage())
01044   {
01045     enableButton( User1, false );
01046     return;
01047   }
01048 
01049   listData+=QString(data);
01050   kDebug(13000)<<QString("CurrentListData: ")<<listData;
01051   kDebug(13000)<<QString("Data length: %1").arg(data.size());
01052   kDebug(13000)<<QString("listData length: %1").arg(listData.length());
01053   if (data.size()==0)
01054   {
01055     if (listData.length()>0)
01056     {
01057       QString installedVersion;
01058       KateHlManager *hlm=KateHlManager::self();
01059       QDomDocument doc;
01060       doc.setContent(listData);
01061       QDomElement DocElem=doc.documentElement();
01062       QDomNode n=DocElem.firstChild();
01063       KateHighlighting *hl = 0;
01064 
01065       if (n.isNull()) kDebug(13000)<<"There is no usable childnode";
01066       while (!n.isNull())
01067       {
01068         installedVersion="    --";
01069 
01070         QDomElement e=n.toElement();
01071         if (!e.isNull())
01072         kDebug(13000)<<QString("NAME: ")<<e.tagName()<<QString(" - ")<<e.attribute("name");
01073         n=n.nextSibling();
01074 
01075         QString Name=e.attribute("name");
01076 
01077         for (int i=0;i<hlm->highlights();i++)
01078         {
01079           hl=hlm->getHl(i);
01080           if (hl && hl->name()==Name)
01081           {
01082             installedVersion="    "+hl->version();
01083             break;
01084           }
01085           else hl = 0;
01086         }
01087 
01088         // autoselect entry if new or updated.
01089         QTreeWidgetItem* entry = new QTreeWidgetItem(list);
01090         entry->setText(0, "");
01091         entry->setText(1, e.attribute("name"));
01092         entry->setText(2, installedVersion);
01093         entry->setText(3, e.attribute("version"));
01094         entry->setText(4, e.attribute("url"));
01095 
01096         if (!hl || hl->version() < e.attribute("version"))
01097         {
01098           entry->treeWidget()->setItemSelected(entry, true);
01099           entry->setIcon(0, SmallIcon(("get-hot-new-stuff")));
01100         }
01101       }
01102       list->resizeColumnToContents(1);
01103     }
01104   }
01105 }
01106 
01107 void KateHlDownloadDialog::slotUser1()
01108 {
01109   QString destdir=KGlobal::dirs()->saveLocation("data","katepart/syntax/");
01110   foreach (QTreeWidgetItem *it, list->selectedItems())
01111   {
01112     KUrl src(it->text(4));
01113     QString filename=src.fileName(KUrl::ObeyTrailingSlash);
01114     QString dest = destdir+filename;
01115 
01116     KIO::NetAccess::download(src,dest, this);
01117   }
01118 
01119   // update Config !!
01120   // this rewrites the cache....
01121   KateSyntaxDocument doc (KateHlManager::self()->getKConfig(), true);
01122 }
01123 //END KateHlDownloadDialog
01124 
01125 //BEGIN KateGotoBar
01126 KateGotoBar::KateGotoBar(KateView* view, QWidget *parent)
01127   : KateViewBarWidget( true, view, parent )
01128 {
01129   QHBoxLayout *topLayout = new QHBoxLayout( centralWidget() );
01130   topLayout->setMargin(0);
01131   //topLayout->setSpacing(spacingHint());
01132   gotoRange = new QSpinBox(centralWidget());
01133 
01134   QLabel *label = new QLabel(i18n("&Go to line:"), centralWidget() );
01135   label->setBuddy(gotoRange);
01136 
01137   btnOK = new QToolButton();
01138   btnOK->setAutoRaise(true);
01139   btnOK->setIcon(QIcon(SmallIcon("go-jump")));
01140   btnOK->setText(i18n("Go"));
01141   btnOK->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
01142   connect(btnOK, SIGNAL(clicked()), this, SLOT(gotoLine()));
01143 
01144   topLayout->addWidget(label);
01145   topLayout->addWidget(gotoRange, 1);
01146   topLayout->setStretchFactor( gotoRange, 0 );
01147   topLayout->addWidget(btnOK);
01148   topLayout->addStretch();
01149 }
01150 
01151 void KateGotoBar::updateData()
01152 {
01153   if (!view())
01154     return;
01155 
01156   gotoRange->setMaximum(view()->doc()->lines());
01157   if (!isVisible())
01158   {
01159     gotoRange->setValue(view()->cursorPosition().line() + 1);
01160     gotoRange->adjustSize(); // ### does not respect the range :-(
01161   }
01162   gotoRange->setFocus(Qt::OtherFocusReason);
01163   gotoRange->selectAll();
01164 }
01165 
01166 void KateGotoBar::keyPressEvent(QKeyEvent* event)
01167 {
01168   int key = event->key();
01169   if (key == Qt::Key_Return || key == Qt::Key_Enter) {
01170     gotoLine();
01171     return;
01172   }
01173   KateViewBarWidget::keyPressEvent(event);
01174 }
01175 
01176 void KateGotoBar::gotoLine()
01177 {
01178   view()->setCursorPosition( KTextEditor::Cursor(gotoRange->value() - 1, 0) );
01179   view()->setFocus();
01180   emit hideMe();
01181 }
01182 //END KateGotoBar
01183 
01184 //BEGIN KateModOnHdPrompt
01185 KateModOnHdPrompt::KateModOnHdPrompt( KateDocument *doc,
01186                                       KTextEditor::ModificationInterface::ModifiedOnDiskReason modtype,
01187                                       const QString &reason,
01188                                       QWidget *parent )
01189   : KDialog( parent ),
01190     m_doc( doc ),
01191     m_modtype ( modtype ),
01192     m_proc( 0 ),
01193     m_diffFile( 0 )
01194 {
01195   setButtons( Ok | Apply | Cancel | User1 );
01196 
01197   QString title, btnOK, whatisok;
01198   if ( modtype == KTextEditor::ModificationInterface::OnDiskDeleted )
01199   {
01200     title = i18n("File Was Deleted on Disk");
01201     btnOK = i18n("&Save File As...");
01202     whatisok = i18n("Lets you select a location and save the file again.");
01203   } else {
01204     title = i18n("File Changed on Disk");
01205     btnOK = i18n("&Reload File");
01206     whatisok = i18n("Reload the file from disk. If you have unsaved changes, "
01207         "they will be lost.");
01208   }
01209 
01210   setButtonText( Ok, btnOK );
01211   setButtonText( Apply, i18n("&Ignore") );
01212 
01213   setButtonWhatsThis( Ok, whatisok );
01214   setButtonWhatsThis( Apply, i18n("Ignore the changes. You will not be prompted again.") );
01215   setButtonWhatsThis( Cancel, i18n("Do nothing. Next time you focus the file, "
01216       "or try to save it or close it, you will be prompted again.") );
01217 
01218   showButtonSeparator( true );
01219   setCaption( title );
01220 
01221   QWidget *w = new QWidget(this);
01222   ui = new Ui::ModOnHdWidget();
01223   ui->setupUi( w );
01224   setMainWidget( w );
01225 
01226   ui->lblIcon->setPixmap( DesktopIcon("dialog-warning" ) );
01227   ui->lblText->setText( reason + "\n\n" + i18n("What do you want to do?") );
01228 
01229   // If the file isn't deleted, present a diff button, and a overwrite action.
01230   if ( modtype != KTextEditor::ModificationInterface::OnDiskDeleted )
01231   {
01232     setButtonText( User1, i18n("Overwrite") );
01233     setButtonWhatsThis( User1, i18n("Overwrite the disk file with the editor content.") );
01234     connect( ui->btnDiff, SIGNAL(clicked()), this, SLOT(slotDiff()) );
01235   }
01236   else
01237   {
01238     ui->chkIgnoreWhiteSpaces->setVisible( false );
01239     ui->btnDiff->setVisible( false );
01240     showButton( User1, false );
01241   }
01242 }
01243 
01244 KateModOnHdPrompt::~KateModOnHdPrompt()
01245 {
01246   delete m_proc;
01247   m_proc = 0;
01248   if (m_diffFile) {
01249     m_diffFile->setAutoRemove(true);
01250     delete m_diffFile;
01251     m_diffFile = 0;
01252   }
01253   delete ui;
01254 }
01255 
01256 void KateModOnHdPrompt::slotDiff()
01257 {
01258   if (m_diffFile)
01259     return;
01260 
01261   m_diffFile = new KTemporaryFile();
01262   m_diffFile->open();
01263 
01264   // Start a KProcess that creates a diff
01265   m_proc = new KProcess( this );
01266   m_proc->setOutputChannelMode( KProcess::MergedChannels );
01267   *m_proc << "diff" << QString(ui->chkIgnoreWhiteSpaces->isChecked() ? "-ub" : "-u")
01268      << "-" <<  m_doc->url().path();
01269   connect( m_proc, SIGNAL(readyRead()), this, SLOT(slotDataAvailable()) );
01270   connect( m_proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPDone()) );
01271 
01272   setCursor( Qt::WaitCursor );
01273   // disable the button and checkbox, to hinder the user to run it twice.
01274   ui->chkIgnoreWhiteSpaces->setEnabled( false );
01275   ui->btnDiff->setEnabled( false );
01276 
01277   m_proc->start();
01278 
01279   QTextStream ts(m_proc);
01280   int lastln = m_doc->lines();
01281   for ( int l = 0; l < lastln; ++l )
01282     ts << m_doc->line( l ) << '\n';
01283   ts.flush();
01284   m_proc->closeWriteChannel();
01285 }
01286 
01287 void KateModOnHdPrompt::slotDataAvailable()
01288 {
01289   m_diffFile->write(m_proc->readAll());
01290 }
01291 
01292 void KateModOnHdPrompt::slotPDone()
01293 {
01294   setCursor( Qt::ArrowCursor );
01295   ui->chkIgnoreWhiteSpaces->setEnabled( true );
01296   ui->btnDiff->setEnabled( true );
01297 
01298   const QProcess::ExitStatus es = m_proc->exitStatus();
01299   delete m_proc;
01300   m_proc = 0;
01301 
01302   if ( es != QProcess::NormalExit )
01303   {
01304     KMessageBox::sorry( this,
01305                         i18n("The diff command failed. Please make sure that "
01306                              "diff(1) is installed and in your PATH."),
01307                         i18n("Error Creating Diff") );
01308     delete m_diffFile;
01309     m_diffFile = 0;
01310     return;
01311   }
01312 
01313   if ( m_diffFile->size() == 0 )
01314   {
01315     KMessageBox::information( this,
01316                               i18n("Besides white space changes, the files are identical."),
01317                               i18n("Diff Output") );
01318     delete m_diffFile;
01319     m_diffFile = 0;
01320     return;
01321   }
01322 
01323   m_diffFile->setAutoRemove(false);
01324   KUrl url = KUrl::fromPath(m_diffFile->fileName());
01325   delete m_diffFile;
01326   m_diffFile = 0;
01327 
01328   // KRun::runUrl should delete the file, once the client exits
01329   KRun::runUrl( url, "text/x-patch", this, true );
01330 }
01331 
01332 void KateModOnHdPrompt::slotButtonClicked(int button)
01333 {
01334   switch(button)
01335   {
01336     case Default:
01337     case Ok:
01338       done( (m_modtype == KTextEditor::ModificationInterface::OnDiskDeleted) ?
01339             Save : Reload );
01340       break;
01341     case Apply:
01342     {
01343       if ( KMessageBox::warningContinueCancel(
01344            this,
01345            i18n("Ignoring means that you will not be warned again (unless "
01346            "the disk file changes once more): if you save the document, you "
01347            "will overwrite the file on disk; if you do not save then the disk "
01348            "file (if present) is what you have."),
01349            i18n("You Are on Your Own"),
01350            KStandardGuiItem::cont(),
01351            KStandardGuiItem::cancel(),
01352            "kate_ignore_modonhd" ) != KMessageBox::Continue )
01353         return;
01354       done( Ignore );
01355       break;
01356     }
01357     case User1:
01358       done( Overwrite );
01359       break;
01360     default:
01361       KDialog::slotButtonClicked(button);
01362   }
01363 }
01364 
01365 //END KateModOnHdPrompt
01366 
01367 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal