File: settingsdialog.cpp

package info (click to toggle)
cervisia 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,548 kB
  • sloc: cpp: 14,364; xml: 393; makefile: 3; sh: 3
file content (427 lines) | stat: -rw-r--r-- 14,609 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
 *  Copyright (C) 1999-2002 Bernd Gehrmann
 *                          bernd@mail.berlios.de
 *  Copyright (c) 2002-2007 Christian Loose <christian.loose@kdemail.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "settingsdialog.h"

#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qwidget.h>
#include <qradiobutton.h>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QFontDialog>
#include <QLineEdit>

#include <kcolorbutton.h>
#include <kconfig.h>
#include <kurlrequester.h>
#include <KConfigGroup>
#include <KHelpClient>

#include "misc.h"
#include "cervisiasettings.h"
#include "ui_settingsdialog_advanced.h"


FontButton::FontButton( const QString &text, QWidget *parent )
    : QPushButton(text, parent)
{
    connect( this, SIGNAL(clicked()), this, SLOT(chooseFont()) );
}


void FontButton::chooseFont()
{
    QFont newFont(font());

    bool ok;

    QFontDialog::getFont(&ok, newFont, this);

    if ( !ok )
        return;

    setFont(newFont);
    repaint();
}


SettingsDialog::SettingsDialog(KConfig *conf, QWidget *parent)
    : KPageDialog(parent)
{
    setFaceType( List );
    setWindowTitle(i18n("Configure Cervisia"));
    setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Help);

    QPushButton *okButton = button(QDialogButtonBox::Ok);
    okButton->setDefault(true);
    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);

    config = conf;

    // open cvs D-Bus service configuration file
    serviceConfig = new KConfig("cvsservicerc");

    //
    // General Options
    //
    addGeneralPage();

    //
    // Diff Options
    //
    addDiffPage();

    //
    // Status Options
    //
    addStatusPage();

    //
    // Advanced Options
    //
    addAdvancedPage();

    //
    // Look and Feel Options
    //
    addLookAndFeelPage();

    readSettings();

    connect(button(QDialogButtonBox::Help), &QPushButton::clicked, this, &SettingsDialog::slotHelp);
}

SettingsDialog::~SettingsDialog()
{
    delete serviceConfig;
}


void SettingsDialog::slotHelp()
{
  KHelpClient::invokeHelp(QLatin1String("customization"));
}


void SettingsDialog::readSettings()
{
    // read entries from cvs D-Bus service configuration
    KConfigGroup group = serviceConfig->group("General");
    cvspathedit->setUrl(group.readPathEntry("CVSPath", "cvs"));
    m_advancedPage->kcfg_Compression->setValue(group.readEntry(
                                                   "Compression", 0));
    m_advancedPage->kcfg_UseSshAgent->setChecked(group.readEntry(
                                                   "UseSshAgent", false));

    group = config->group("General");
    m_advancedPage->kcfg_Timeout->setValue(CervisiaSettings::timeout());
    usernameedit->setText(group.readEntry("Username", Cervisia::UserName()));

    contextedit->setValue(group.readEntry("ContextLines", 65535));
    tabwidthedit->setValue(group.readEntry("TabWidth", 8));
    diffoptedit->setText(group.readEntry("DiffOptions"));
    extdiffedit->setUrl(group.readPathEntry("ExternalDiff", QString()));
    remotestatusbox->setChecked(group.readEntry("StatusForRemoteRepos", false));
    localstatusbox->setChecked(group.readEntry("StatusForLocalRepos", false));

    // read configuration for look and feel page
    group = config->group("LookAndFeel");
    m_protocolFontBox->setFont(CervisiaSettings::protocolFont());
    m_annotateFontBox->setFont(CervisiaSettings::annotateFont());
    m_diffFontBox->setFont(CervisiaSettings::diffFont());
    m_changelogFontBox->setFont(CervisiaSettings::changeLogFont());
    m_splitterBox->setChecked(group.readEntry("SplitHorizontally",true));

    m_conflictButton->setColor(CervisiaSettings::conflictColor());
    m_localChangeButton->setColor(CervisiaSettings::localChangeColor());
    m_remoteChangeButton->setColor(CervisiaSettings::remoteChangeColor());
    m_notInCvsButton->setColor(CervisiaSettings::notInCvsColor());

    m_diffChangeButton->setColor(CervisiaSettings::diffChangeColor());
    m_diffInsertButton->setColor(CervisiaSettings::diffInsertColor());
    m_diffDeleteButton->setColor(CervisiaSettings::diffDeleteColor());
}


void SettingsDialog::writeSettings()
{
    // write entries to cvs D-Bus service configuration
    KConfigGroup group = serviceConfig->group("General");
    group.writePathEntry("CVSPath", cvspathedit->text());
    group.writeEntry("Compression",
        m_advancedPage->kcfg_Compression->value());
    group.writeEntry("UseSshAgent",
        m_advancedPage->kcfg_UseSshAgent->isChecked());

    // write to disk so other services can reparse the configuration
    serviceConfig->sync();

    group = config->group("General");
    CervisiaSettings::setTimeout(m_advancedPage->kcfg_Timeout->value());
    group.writeEntry("Username", usernameedit->text());

    group.writePathEntry("ExternalDiff", extdiffedit->text());

    group.writeEntry("ContextLines", (unsigned)contextedit->value());
    group.writeEntry("TabWidth", tabwidthedit->value());
    group.writeEntry("DiffOptions", diffoptedit->text());
    group.writeEntry("StatusForRemoteRepos", remotestatusbox->isChecked());
    group.writeEntry("StatusForLocalRepos", localstatusbox->isChecked());

    group = config->group("LookAndFeel");
    CervisiaSettings::setProtocolFont(m_protocolFontBox->font());
    CervisiaSettings::setAnnotateFont(m_annotateFontBox->font());
    CervisiaSettings::setDiffFont(m_diffFontBox->font());
    CervisiaSettings::setChangeLogFont(m_changelogFontBox->font());
    group.writeEntry("SplitHorizontally", m_splitterBox->isChecked());

    CervisiaSettings::setConflictColor(m_conflictButton->color());
    CervisiaSettings::setLocalChangeColor(m_localChangeButton->color());
    CervisiaSettings::setRemoteChangeColor(m_remoteChangeButton->color());
    CervisiaSettings::setNotInCvsColor(m_notInCvsButton->color());
    CervisiaSettings::setDiffChangeColor(m_diffChangeButton->color());
    CervisiaSettings::setDiffInsertColor(m_diffInsertButton->color());
    CervisiaSettings::setDiffDeleteColor(m_diffDeleteButton->color());

    config->sync();

    CervisiaSettings::self()->save();
}

void SettingsDialog::done(int res)
{
    if (res == Accepted)
        writeSettings();
    QDialog::done(res);
}


/*
 * Create a page for the general options
 */
void SettingsDialog::addGeneralPage()
{
    QFrame* generalPage = new QFrame;
    KPageWidgetItem *page = new KPageWidgetItem( generalPage, i18n("General") );
    page->setIcon( QIcon::fromTheme("applications-system") );
    
    QVBoxLayout* layout = new QVBoxLayout(generalPage);

    QLabel *usernamelabel = new QLabel( i18n("&User name for the change log editor:"), generalPage );
    usernameedit = new QLineEdit(generalPage);
    usernameedit->setFocus();
    usernamelabel->setBuddy(usernameedit);

    layout->addWidget(usernamelabel);
    layout->addWidget(usernameedit);

    QLabel *cvspathlabel = new QLabel( i18n("&Path to CVS executable, or 'cvs':"), generalPage );
    cvspathedit = new KUrlRequester(generalPage);
    cvspathlabel->setBuddy(cvspathedit);

    layout->addWidget(cvspathlabel);
    layout->addWidget(cvspathedit);

    layout->addStretch();

    addPage(page);
}


/*
 * Create a page for the diff optionsw
 */
void SettingsDialog::addDiffPage()
{
    QFrame* diffPage = new QFrame;
    KPageWidgetItem *page = new KPageWidgetItem( diffPage, i18n("Diff Viewer") );
    page->setIcon( QIcon::fromTheme("vcs-diff-cvs-cervisia") );

    QGridLayout* layout = new QGridLayout(diffPage);

    QLabel *contextlabel = new QLabel( i18n("&Number of context lines in diff dialog:"), diffPage );
    contextedit = new QSpinBox(diffPage);
    contextedit->setRange(0, 65535);
    contextlabel->setBuddy(contextedit);

    layout->addWidget(contextlabel, 0, 0);
    layout->addWidget(contextedit, 0, 1);

    QLabel *diffoptlabel = new QLabel(i18n("Additional &options for cvs diff:"), diffPage);
    diffoptedit = new QLineEdit(diffPage);
    diffoptlabel->setBuddy(diffoptedit);

    layout->addWidget(diffoptlabel, 1, 0);
    layout->addWidget(diffoptedit, 1, 1);

    QLabel *tabwidthlabel = new QLabel(i18n("Tab &width in diff dialog:"), diffPage);
    tabwidthedit = new QSpinBox(diffPage);
    tabwidthedit->setRange(1, 16);
    tabwidthlabel->setBuddy(tabwidthedit);

    layout->addWidget(tabwidthlabel, 2, 0);
    layout->addWidget(tabwidthedit, 2, 1);

    QLabel *extdifflabel = new QLabel(i18n("External diff &frontend:"), diffPage);
    extdiffedit = new KUrlRequester(diffPage);
    extdifflabel->setBuddy(extdiffedit);

    layout->addWidget(extdifflabel, 3, 0);
    layout->addWidget(extdiffedit, 3, 1);

    layout->setRowStretch(4, 10);

    addPage(page);
}


/*
 * Create a page for the status options
 */
void SettingsDialog::addStatusPage()
{
    QWidget* statusPage = new QWidget;
    QVBoxLayout *statusPageVBoxLayout = new QVBoxLayout(statusPage);
    KPageWidgetItem *page = new KPageWidgetItem( statusPage, i18n("Status") );
    page->setIcon( QIcon::fromTheme("fork") );

    remotestatusbox = new QCheckBox(i18n("When opening a sandbox from a &remote repository,\n"
                                         "start a File->Status command automatically"), statusPage);
    localstatusbox = new QCheckBox(i18n("When opening a sandbox from a &local repository,\n"
                                        "start a File->Status command automatically"), statusPage);

    statusPageVBoxLayout->addWidget(remotestatusbox);
    statusPageVBoxLayout->addWidget(localstatusbox);
    statusPageVBoxLayout->addStretch();

    addPage(page);
}


/*
 * Create a page for the advanced options
 */
void SettingsDialog::addAdvancedPage()
{
    QWidget* frame = new QWidget;
    KPageWidgetItem *page = new KPageWidgetItem( frame, i18n("Advanced") );
    page->setIcon( QIcon::fromTheme("configure") );

    m_advancedPage = new Ui::AdvancedPage;
    m_advancedPage->setupUi(frame);
    m_advancedPage->kcfg_Timeout->setRange(0, 50000);
    m_advancedPage->kcfg_Timeout->setSingleStep(100);
    m_advancedPage->kcfg_Compression->setRange(0, 9);

    addPage(page);
}


/*
 * Create a page for the look & feel options
 */
void SettingsDialog::addLookAndFeelPage()
{
    QWidget* lookPage = new QWidget;
    QVBoxLayout *lookPageVBoxLayout = new QVBoxLayout(lookPage);
    KPageWidgetItem *page = new KPageWidgetItem( lookPage, i18n("Appearance") );
    page->setIcon( QIcon::fromTheme("preferences-desktop-theme") );

    QGroupBox* fontGroupBox = new QGroupBox(i18n("Fonts"), lookPage);
    lookPageVBoxLayout->addWidget(fontGroupBox);

    m_protocolFontBox  = new FontButton(i18n("Font for &Protocol Window..."),
                                        fontGroupBox);
    m_annotateFontBox  = new FontButton(i18n("Font for A&nnotate View..."),
                                        fontGroupBox);
    m_diffFontBox      = new FontButton(i18n("Font for D&iff View..."),
                                        fontGroupBox);
    m_changelogFontBox = new FontButton(i18n("Font for ChangeLog View..."),
                                        fontGroupBox);

    QVBoxLayout* fontLayout( new QVBoxLayout( fontGroupBox ) );
    fontLayout->addWidget( m_protocolFontBox );
    fontLayout->addWidget( m_annotateFontBox );
    fontLayout->addWidget( m_diffFontBox );
    fontLayout->addWidget( m_changelogFontBox );

    QGroupBox* colorGroupBox = new QGroupBox(i18n("Colors"), lookPage);
    lookPageVBoxLayout->addWidget(colorGroupBox);

    QLabel* conflictLabel = new QLabel(i18n("Conflict:"), colorGroupBox);
    m_conflictButton      = new KColorButton(colorGroupBox);
    conflictLabel->setBuddy(m_conflictButton);

    QLabel* diffChangeLabel = new QLabel(i18n("Diff change:"), colorGroupBox);
    m_diffChangeButton      = new KColorButton(colorGroupBox);
    diffChangeLabel->setBuddy(m_diffChangeButton);

    QLabel* localChangeLabel = new QLabel(i18n("Local change:"), colorGroupBox);
    m_localChangeButton      = new KColorButton(colorGroupBox);
    localChangeLabel->setBuddy(m_localChangeButton);

    QLabel* diffInsertLabel = new QLabel(i18n("Diff insertion:"), colorGroupBox);
    m_diffInsertButton      = new KColorButton(colorGroupBox);
    diffInsertLabel->setBuddy(m_diffInsertButton);

    QLabel* remoteChangeLabel = new QLabel(i18n("Remote change:"), colorGroupBox);
    m_remoteChangeButton      = new KColorButton(colorGroupBox);
    remoteChangeLabel->setBuddy( m_remoteChangeButton );

    QLabel* diffDeleteLabel = new QLabel(i18n("Diff deletion:"), colorGroupBox);
    m_diffDeleteButton      = new KColorButton(colorGroupBox);
    diffDeleteLabel->setBuddy(m_diffDeleteButton);

    QLabel* notInCvsLabel = new QLabel(i18n("Not in cvs:"), colorGroupBox);
    m_notInCvsButton      = new KColorButton(colorGroupBox);
    notInCvsLabel->setBuddy(m_notInCvsButton);

    QGridLayout* colorLayout( new QGridLayout( colorGroupBox ) );
    colorLayout->addWidget( conflictLabel, 0, 0 );
    colorLayout->addWidget( m_conflictButton, 0, 1 );
    colorLayout->addWidget( localChangeLabel, 1, 0 );
    colorLayout->addWidget( m_localChangeButton, 1, 1 );
    colorLayout->addWidget( remoteChangeLabel, 2, 0 );
    colorLayout->addWidget( m_remoteChangeButton, 2, 1 );
    colorLayout->addWidget( notInCvsLabel, 3, 0 );
    colorLayout->addWidget( m_notInCvsButton, 3, 1 );

    colorLayout->addWidget( diffChangeLabel, 0, 3 );
    colorLayout->addWidget( m_diffChangeButton, 0, 4 );
    colorLayout->addWidget( diffInsertLabel, 1, 3 );
    colorLayout->addWidget( m_diffInsertButton, 1, 4 );
    colorLayout->addWidget( diffDeleteLabel, 2, 3 );
    colorLayout->addWidget( m_diffDeleteButton, 2, 4 );

    m_splitterBox = new QCheckBox(i18n("Split main window &horizontally"), lookPage);
    lookPageVBoxLayout->addWidget(m_splitterBox);

    addPage(page);
}



// Local Variables:
// c-basic-offset: 4
// End: