Warning, file /sdk/cervisia/settingsdialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (C) 1999-2002 Bernd Gehrmann 0003 * bernd@mail.berlios.de 0004 * Copyright (c) 2002-2007 Christian Loose <christian.loose@kdemail.net> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU General Public License as published by 0008 * the Free Software Foundation; either version 2 of the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "settingsdialog.h" 0022 0023 #include <QDialogButtonBox> 0024 #include <QFontDialog> 0025 #include <QLineEdit> 0026 #include <QPushButton> 0027 #include <QVBoxLayout> 0028 #include <qcheckbox.h> 0029 #include <qgroupbox.h> 0030 #include <qlabel.h> 0031 #include <qlayout.h> 0032 #include <qradiobutton.h> 0033 #include <qwidget.h> 0034 0035 #include <KConfigGroup> 0036 #include <KHelpClient> 0037 #include <kcolorbutton.h> 0038 #include <kconfig.h> 0039 #include <kurlrequester.h> 0040 0041 #include "cervisiasettings.h" 0042 #include "misc.h" 0043 #include "ui_settingsdialog_advanced.h" 0044 0045 FontButton::FontButton(const QString &text, QWidget *parent) 0046 : QPushButton(text, parent) 0047 { 0048 connect(this, SIGNAL(clicked()), this, SLOT(chooseFont())); 0049 } 0050 0051 void FontButton::chooseFont() 0052 { 0053 QFont newFont(font()); 0054 0055 bool ok; 0056 0057 QFontDialog::getFont(&ok, newFont, this); 0058 0059 if (!ok) 0060 return; 0061 0062 setFont(newFont); 0063 repaint(); 0064 } 0065 0066 SettingsDialog::SettingsDialog(KConfig *conf, QWidget *parent) 0067 : KPageDialog(parent) 0068 { 0069 setFaceType(List); 0070 setWindowTitle(i18n("Configure Cervisia")); 0071 setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help); 0072 0073 QPushButton *okButton = button(QDialogButtonBox::Ok); 0074 okButton->setDefault(true); 0075 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0076 0077 config = conf; 0078 0079 // open cvs D-Bus service configuration file 0080 serviceConfig = new KConfig("cvsservicerc"); 0081 0082 // 0083 // General Options 0084 // 0085 addGeneralPage(); 0086 0087 // 0088 // Diff Options 0089 // 0090 addDiffPage(); 0091 0092 // 0093 // Status Options 0094 // 0095 addStatusPage(); 0096 0097 // 0098 // Advanced Options 0099 // 0100 addAdvancedPage(); 0101 0102 // 0103 // Look and Feel Options 0104 // 0105 addLookAndFeelPage(); 0106 0107 readSettings(); 0108 0109 connect(button(QDialogButtonBox::Help), &QPushButton::clicked, this, &SettingsDialog::slotHelp); 0110 } 0111 0112 SettingsDialog::~SettingsDialog() 0113 { 0114 delete serviceConfig; 0115 } 0116 0117 void SettingsDialog::slotHelp() 0118 { 0119 KHelpClient::invokeHelp(QLatin1String("customization")); 0120 } 0121 0122 void SettingsDialog::readSettings() 0123 { 0124 // read entries from cvs D-Bus service configuration 0125 KConfigGroup group = serviceConfig->group("General"); 0126 cvspathedit->setUrl(group.readPathEntry("CVSPath", "cvs")); 0127 m_advancedPage->kcfg_Compression->setValue(group.readEntry("Compression", 0)); 0128 m_advancedPage->kcfg_UseSshAgent->setChecked(group.readEntry("UseSshAgent", false)); 0129 0130 group = config->group("General"); 0131 m_advancedPage->kcfg_Timeout->setValue(CervisiaSettings::timeout()); 0132 usernameedit->setText(group.readEntry("Username", Cervisia::UserName())); 0133 0134 contextedit->setValue(group.readEntry("ContextLines", 65535)); 0135 tabwidthedit->setValue(group.readEntry("TabWidth", 8)); 0136 diffoptedit->setText(group.readEntry("DiffOptions")); 0137 extdiffedit->setUrl(group.readPathEntry("ExternalDiff", QString())); 0138 remotestatusbox->setChecked(group.readEntry("StatusForRemoteRepos", false)); 0139 localstatusbox->setChecked(group.readEntry("StatusForLocalRepos", false)); 0140 0141 // read configuration for look and feel page 0142 group = config->group("LookAndFeel"); 0143 m_protocolFontBox->setFont(CervisiaSettings::protocolFont()); 0144 m_annotateFontBox->setFont(CervisiaSettings::annotateFont()); 0145 m_diffFontBox->setFont(CervisiaSettings::diffFont()); 0146 m_changelogFontBox->setFont(CervisiaSettings::changeLogFont()); 0147 m_splitterBox->setChecked(group.readEntry("SplitHorizontally", true)); 0148 0149 m_conflictButton->setColor(CervisiaSettings::conflictColor()); 0150 m_localChangeButton->setColor(CervisiaSettings::localChangeColor()); 0151 m_remoteChangeButton->setColor(CervisiaSettings::remoteChangeColor()); 0152 m_notInCvsButton->setColor(CervisiaSettings::notInCvsColor()); 0153 0154 m_diffChangeButton->setColor(CervisiaSettings::diffChangeColor()); 0155 m_diffInsertButton->setColor(CervisiaSettings::diffInsertColor()); 0156 m_diffDeleteButton->setColor(CervisiaSettings::diffDeleteColor()); 0157 } 0158 0159 void SettingsDialog::writeSettings() 0160 { 0161 // write entries to cvs D-Bus service configuration 0162 KConfigGroup group = serviceConfig->group("General"); 0163 group.writePathEntry("CVSPath", cvspathedit->text()); 0164 group.writeEntry("Compression", m_advancedPage->kcfg_Compression->value()); 0165 group.writeEntry("UseSshAgent", m_advancedPage->kcfg_UseSshAgent->isChecked()); 0166 0167 // write to disk so other services can reparse the configuration 0168 serviceConfig->sync(); 0169 0170 group = config->group("General"); 0171 CervisiaSettings::setTimeout(m_advancedPage->kcfg_Timeout->value()); 0172 group.writeEntry("Username", usernameedit->text()); 0173 0174 group.writePathEntry("ExternalDiff", extdiffedit->text()); 0175 0176 group.writeEntry("ContextLines", (unsigned)contextedit->value()); 0177 group.writeEntry("TabWidth", tabwidthedit->value()); 0178 group.writeEntry("DiffOptions", diffoptedit->text()); 0179 group.writeEntry("StatusForRemoteRepos", remotestatusbox->isChecked()); 0180 group.writeEntry("StatusForLocalRepos", localstatusbox->isChecked()); 0181 0182 group = config->group("LookAndFeel"); 0183 CervisiaSettings::setProtocolFont(m_protocolFontBox->font()); 0184 CervisiaSettings::setAnnotateFont(m_annotateFontBox->font()); 0185 CervisiaSettings::setDiffFont(m_diffFontBox->font()); 0186 CervisiaSettings::setChangeLogFont(m_changelogFontBox->font()); 0187 group.writeEntry("SplitHorizontally", m_splitterBox->isChecked()); 0188 0189 CervisiaSettings::setConflictColor(m_conflictButton->color()); 0190 CervisiaSettings::setLocalChangeColor(m_localChangeButton->color()); 0191 CervisiaSettings::setRemoteChangeColor(m_remoteChangeButton->color()); 0192 CervisiaSettings::setNotInCvsColor(m_notInCvsButton->color()); 0193 CervisiaSettings::setDiffChangeColor(m_diffChangeButton->color()); 0194 CervisiaSettings::setDiffInsertColor(m_diffInsertButton->color()); 0195 CervisiaSettings::setDiffDeleteColor(m_diffDeleteButton->color()); 0196 0197 config->sync(); 0198 0199 CervisiaSettings::self()->save(); 0200 } 0201 0202 void SettingsDialog::done(int res) 0203 { 0204 if (res == Accepted) 0205 writeSettings(); 0206 QDialog::done(res); 0207 } 0208 0209 /* 0210 * Create a page for the general options 0211 */ 0212 void SettingsDialog::addGeneralPage() 0213 { 0214 auto generalPage = new QFrame; 0215 auto page = new KPageWidgetItem(generalPage, i18n("General")); 0216 page->setIcon(QIcon::fromTheme("applications-system")); 0217 0218 auto layout = new QVBoxLayout(generalPage); 0219 0220 auto usernamelabel = new QLabel(i18n("&User name for the change log editor:"), generalPage); 0221 usernameedit = new QLineEdit(generalPage); 0222 usernameedit->setFocus(); 0223 usernamelabel->setBuddy(usernameedit); 0224 0225 layout->addWidget(usernamelabel); 0226 layout->addWidget(usernameedit); 0227 0228 auto cvspathlabel = new QLabel(i18n("&Path to CVS executable, or 'cvs':"), generalPage); 0229 cvspathedit = new KUrlRequester(generalPage); 0230 cvspathlabel->setBuddy(cvspathedit); 0231 0232 layout->addWidget(cvspathlabel); 0233 layout->addWidget(cvspathedit); 0234 0235 layout->addStretch(); 0236 0237 addPage(page); 0238 } 0239 0240 /* 0241 * Create a page for the diff optionsw 0242 */ 0243 void SettingsDialog::addDiffPage() 0244 { 0245 auto diffPage = new QFrame; 0246 auto page = new KPageWidgetItem(diffPage, i18n("Diff Viewer")); 0247 page->setIcon(QIcon::fromTheme("vcs-diff-cvs-cervisia")); 0248 0249 auto layout = new QGridLayout(diffPage); 0250 0251 auto contextlabel = new QLabel(i18n("&Number of context lines in diff dialog:"), diffPage); 0252 contextedit = new QSpinBox(diffPage); 0253 contextedit->setRange(0, 65535); 0254 contextlabel->setBuddy(contextedit); 0255 0256 layout->addWidget(contextlabel, 0, 0); 0257 layout->addWidget(contextedit, 0, 1); 0258 0259 auto diffoptlabel = new QLabel(i18n("Additional &options for cvs diff:"), diffPage); 0260 diffoptedit = new QLineEdit(diffPage); 0261 diffoptlabel->setBuddy(diffoptedit); 0262 0263 layout->addWidget(diffoptlabel, 1, 0); 0264 layout->addWidget(diffoptedit, 1, 1); 0265 0266 auto tabwidthlabel = new QLabel(i18n("Tab &width in diff dialog:"), diffPage); 0267 tabwidthedit = new QSpinBox(diffPage); 0268 tabwidthedit->setRange(1, 16); 0269 tabwidthlabel->setBuddy(tabwidthedit); 0270 0271 layout->addWidget(tabwidthlabel, 2, 0); 0272 layout->addWidget(tabwidthedit, 2, 1); 0273 0274 auto extdifflabel = new QLabel(i18n("External diff &frontend:"), diffPage); 0275 extdiffedit = new KUrlRequester(diffPage); 0276 extdifflabel->setBuddy(extdiffedit); 0277 0278 layout->addWidget(extdifflabel, 3, 0); 0279 layout->addWidget(extdiffedit, 3, 1); 0280 0281 layout->setRowStretch(4, 10); 0282 0283 addPage(page); 0284 } 0285 0286 /* 0287 * Create a page for the status options 0288 */ 0289 void SettingsDialog::addStatusPage() 0290 { 0291 auto statusPage = new QWidget; 0292 auto statusPageVBoxLayout = new QVBoxLayout(statusPage); 0293 auto page = new KPageWidgetItem(statusPage, i18n("Status")); 0294 page->setIcon(QIcon::fromTheme("fork")); 0295 0296 remotestatusbox = new QCheckBox(i18n("When opening a sandbox from a &remote repository,\n" 0297 "start a File->Status command automatically"), 0298 statusPage); 0299 localstatusbox = new QCheckBox(i18n("When opening a sandbox from a &local repository,\n" 0300 "start a File->Status command automatically"), 0301 statusPage); 0302 0303 statusPageVBoxLayout->addWidget(remotestatusbox); 0304 statusPageVBoxLayout->addWidget(localstatusbox); 0305 statusPageVBoxLayout->addStretch(); 0306 0307 addPage(page); 0308 } 0309 0310 /* 0311 * Create a page for the advanced options 0312 */ 0313 void SettingsDialog::addAdvancedPage() 0314 { 0315 auto frame = new QWidget; 0316 auto page = new KPageWidgetItem(frame, i18n("Advanced")); 0317 page->setIcon(QIcon::fromTheme("configure")); 0318 0319 m_advancedPage = new Ui::AdvancedPage; 0320 m_advancedPage->setupUi(frame); 0321 m_advancedPage->kcfg_Timeout->setRange(0, 50000); 0322 m_advancedPage->kcfg_Timeout->setSingleStep(100); 0323 m_advancedPage->kcfg_Compression->setRange(0, 9); 0324 0325 addPage(page); 0326 } 0327 0328 /* 0329 * Create a page for the look & feel options 0330 */ 0331 void SettingsDialog::addLookAndFeelPage() 0332 { 0333 auto lookPage = new QWidget; 0334 auto lookPageVBoxLayout = new QVBoxLayout(lookPage); 0335 auto page = new KPageWidgetItem(lookPage, i18n("Appearance")); 0336 page->setIcon(QIcon::fromTheme("preferences-desktop-theme")); 0337 0338 auto fontGroupBox = new QGroupBox(i18n("Fonts"), lookPage); 0339 lookPageVBoxLayout->addWidget(fontGroupBox); 0340 0341 m_protocolFontBox = new FontButton(i18n("Font for &Protocol Window..."), fontGroupBox); 0342 m_annotateFontBox = new FontButton(i18n("Font for A&nnotate View..."), fontGroupBox); 0343 m_diffFontBox = new FontButton(i18n("Font for D&iff View..."), fontGroupBox); 0344 m_changelogFontBox = new FontButton(i18n("Font for ChangeLog View..."), fontGroupBox); 0345 0346 auto fontLayout(new QVBoxLayout(fontGroupBox)); 0347 fontLayout->addWidget(m_protocolFontBox); 0348 fontLayout->addWidget(m_annotateFontBox); 0349 fontLayout->addWidget(m_diffFontBox); 0350 fontLayout->addWidget(m_changelogFontBox); 0351 0352 auto colorGroupBox = new QGroupBox(i18n("Colors"), lookPage); 0353 lookPageVBoxLayout->addWidget(colorGroupBox); 0354 0355 auto conflictLabel = new QLabel(i18n("Conflict:"), colorGroupBox); 0356 m_conflictButton = new KColorButton(colorGroupBox); 0357 conflictLabel->setBuddy(m_conflictButton); 0358 0359 auto diffChangeLabel = new QLabel(i18n("Diff change:"), colorGroupBox); 0360 m_diffChangeButton = new KColorButton(colorGroupBox); 0361 diffChangeLabel->setBuddy(m_diffChangeButton); 0362 0363 auto localChangeLabel = new QLabel(i18n("Local change:"), colorGroupBox); 0364 m_localChangeButton = new KColorButton(colorGroupBox); 0365 localChangeLabel->setBuddy(m_localChangeButton); 0366 0367 auto diffInsertLabel = new QLabel(i18n("Diff insertion:"), colorGroupBox); 0368 m_diffInsertButton = new KColorButton(colorGroupBox); 0369 diffInsertLabel->setBuddy(m_diffInsertButton); 0370 0371 auto remoteChangeLabel = new QLabel(i18n("Remote change:"), colorGroupBox); 0372 m_remoteChangeButton = new KColorButton(colorGroupBox); 0373 remoteChangeLabel->setBuddy(m_remoteChangeButton); 0374 0375 auto diffDeleteLabel = new QLabel(i18n("Diff deletion:"), colorGroupBox); 0376 m_diffDeleteButton = new KColorButton(colorGroupBox); 0377 diffDeleteLabel->setBuddy(m_diffDeleteButton); 0378 0379 auto notInCvsLabel = new QLabel(i18n("Not in cvs:"), colorGroupBox); 0380 m_notInCvsButton = new KColorButton(colorGroupBox); 0381 notInCvsLabel->setBuddy(m_notInCvsButton); 0382 0383 auto colorLayout(new QGridLayout(colorGroupBox)); 0384 colorLayout->addWidget(conflictLabel, 0, 0); 0385 colorLayout->addWidget(m_conflictButton, 0, 1); 0386 colorLayout->addWidget(localChangeLabel, 1, 0); 0387 colorLayout->addWidget(m_localChangeButton, 1, 1); 0388 colorLayout->addWidget(remoteChangeLabel, 2, 0); 0389 colorLayout->addWidget(m_remoteChangeButton, 2, 1); 0390 colorLayout->addWidget(notInCvsLabel, 3, 0); 0391 colorLayout->addWidget(m_notInCvsButton, 3, 1); 0392 0393 colorLayout->addWidget(diffChangeLabel, 0, 3); 0394 colorLayout->addWidget(m_diffChangeButton, 0, 4); 0395 colorLayout->addWidget(diffInsertLabel, 1, 3); 0396 colorLayout->addWidget(m_diffInsertButton, 1, 4); 0397 colorLayout->addWidget(diffDeleteLabel, 2, 3); 0398 colorLayout->addWidget(m_diffDeleteButton, 2, 4); 0399 0400 m_splitterBox = new QCheckBox(i18n("Split main window &horizontally"), lookPage); 0401 lookPageVBoxLayout->addWidget(m_splitterBox); 0402 0403 addPage(page); 0404 } 0405 0406 // Local Variables: 0407 // c-basic-offset: 4 0408 // End: