Chris@175
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@175
|
2
|
Chris@175
|
3 /*
|
Chris@175
|
4 EasyMercurial
|
Chris@175
|
5
|
Chris@175
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@175
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@175
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@175
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@175
|
10
|
Chris@175
|
11 This program is free software; you can redistribute it and/or
|
Chris@175
|
12 modify it under the terms of the GNU General Public License as
|
Chris@175
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@175
|
14 License, or (at your option) any later version. See the file
|
Chris@175
|
15 COPYING included with this distribution for more information.
|
Chris@175
|
16 */
|
Chris@175
|
17
|
Chris@175
|
18 #include "settingsdialog.h"
|
Chris@175
|
19 #include "common.h"
|
Chris@177
|
20 #include "debug.h"
|
Chris@175
|
21
|
Chris@175
|
22 #include <QGridLayout>
|
Chris@175
|
23 #include <QGroupBox>
|
Chris@175
|
24 #include <QDialogButtonBox>
|
Chris@175
|
25 #include <QSettings>
|
Chris@181
|
26 #include <QDir>
|
Chris@181
|
27 #include <QFileDialog>
|
Chris@175
|
28
|
Chris@175
|
29 SettingsDialog::SettingsDialog(QWidget *parent) :
|
Chris@230
|
30 QDialog(parent),
|
Chris@230
|
31 m_presentationChanged(false)
|
Chris@175
|
32 {
|
Chris@175
|
33 setModal(true);
|
Chris@175
|
34 setWindowTitle(tr("Settings"));
|
Chris@175
|
35
|
Chris@175
|
36 QSettings settings;
|
Chris@175
|
37
|
Chris@175
|
38 QGridLayout *mainLayout = new QGridLayout;
|
Chris@175
|
39 setLayout(mainLayout);
|
Chris@175
|
40
|
Chris@230
|
41
|
Chris@230
|
42
|
Chris@181
|
43 QGroupBox *meBox = new QGroupBox(tr("User details"));
|
Chris@175
|
44 mainLayout->addWidget(meBox, 0, 0);
|
Chris@175
|
45 QGridLayout *meLayout = new QGridLayout;
|
Chris@175
|
46 meBox->setLayout(meLayout);
|
Chris@175
|
47
|
Chris@175
|
48 settings.beginGroup("User Information");
|
Chris@175
|
49
|
Chris@175
|
50 int row = 0;
|
Chris@175
|
51
|
Chris@175
|
52 meLayout->addWidget(new QLabel(tr("Name:")), row, 0);
|
Chris@175
|
53
|
Chris@175
|
54 m_nameEdit = new QLineEdit();
|
Chris@175
|
55 m_nameEdit->setText(settings.value("name", getUserRealName()).toString());
|
Chris@175
|
56 meLayout->addWidget(m_nameEdit, row++, 1);
|
Chris@175
|
57
|
Chris@175
|
58 meLayout->addWidget(new QLabel(tr("Email address:")), row, 0);
|
Chris@175
|
59
|
Chris@175
|
60 m_emailEdit = new QLineEdit();
|
Chris@175
|
61 m_emailEdit->setText(settings.value("email").toString());
|
Chris@175
|
62 meLayout->addWidget(m_emailEdit, row++, 1);
|
Chris@175
|
63
|
Chris@175
|
64 settings.endGroup();
|
Chris@175
|
65
|
Chris@230
|
66
|
Chris@230
|
67
|
Chris@230
|
68 QGroupBox *lookBox = new QGroupBox(tr("Presentation"));
|
Chris@230
|
69 mainLayout->addWidget(lookBox, 1, 0);
|
Chris@230
|
70 QGridLayout *lookLayout = new QGridLayout;
|
Chris@230
|
71 lookBox->setLayout(lookLayout);
|
Chris@230
|
72
|
Chris@230
|
73 settings.beginGroup("Presentation");
|
Chris@230
|
74
|
Chris@230
|
75 row = 0;
|
Chris@230
|
76
|
Chris@230
|
77 m_showIconLabels = new QCheckBox(tr("Show labels on toolbar icons"));
|
Chris@230
|
78 m_showIconLabels->setChecked(settings.value("showiconlabels", true).toBool());
|
Chris@230
|
79 lookLayout->addWidget(m_showIconLabels, row++, 0);
|
Chris@230
|
80
|
Chris@230
|
81 m_showExtraText = new QCheckBox(tr("Show long descriptions for file status headings"));
|
Chris@230
|
82 m_showExtraText->setChecked(settings.value("showhelpfultext", true).toBool());
|
Chris@230
|
83 lookLayout->addWidget(m_showExtraText, row++, 0);
|
Chris@230
|
84
|
Chris@230
|
85 settings.endGroup();
|
Chris@230
|
86
|
Chris@230
|
87
|
Chris@230
|
88
|
Chris@175
|
89 QGroupBox *pathsBox = new QGroupBox(tr("System application locations"));
|
Chris@230
|
90 mainLayout->addWidget(pathsBox, 2, 0);
|
Chris@175
|
91 QGridLayout *pathsLayout = new QGridLayout;
|
Chris@175
|
92 pathsBox->setLayout(pathsLayout);
|
Chris@175
|
93
|
Chris@175
|
94 settings.beginGroup("Locations");
|
Chris@175
|
95
|
Chris@175
|
96 row = 0;
|
Chris@175
|
97
|
Chris@175
|
98 pathsLayout->addWidget(new QLabel(tr("Mercurial (hg) program:")), row, 0);
|
Chris@175
|
99
|
Chris@195
|
100 m_hgPathLabel = new QLineEdit();
|
Chris@181
|
101 m_hgPathLabel->setText(settings.value("hgbinary").toString());
|
Chris@181
|
102 pathsLayout->addWidget(m_hgPathLabel, row, 2);
|
Chris@175
|
103
|
Chris@175
|
104 QPushButton *browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
105 pathsLayout->addWidget(browse, row++, 1);
|
Chris@175
|
106 connect(browse, SIGNAL(clicked()), this, SLOT(hgPathBrowse()));
|
Chris@175
|
107
|
Chris@175
|
108 pathsLayout->addWidget(new QLabel(tr("External diff program:")), row, 0);
|
Chris@175
|
109
|
Chris@195
|
110 m_diffPathLabel = new QLineEdit();
|
Chris@181
|
111 m_diffPathLabel->setText(settings.value("extdiffbinary").toString());
|
Chris@181
|
112 pathsLayout->addWidget(m_diffPathLabel, row, 2);
|
Chris@175
|
113
|
Chris@175
|
114 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
115 pathsLayout->addWidget(browse, row++, 1);
|
Chris@175
|
116 connect(browse, SIGNAL(clicked()), this, SLOT(diffPathBrowse()));
|
Chris@178
|
117
|
Chris@175
|
118 pathsLayout->addWidget(new QLabel(tr("External file-merge program:")), row, 0);
|
Chris@175
|
119
|
Chris@195
|
120 m_mergePathLabel = new QLineEdit();
|
Chris@181
|
121 m_mergePathLabel->setText(settings.value("mergebinary").toString());
|
Chris@181
|
122 pathsLayout->addWidget(m_mergePathLabel, row, 2);
|
Chris@175
|
123
|
Chris@175
|
124 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
125 pathsLayout->addWidget(browse, row++, 1);
|
Chris@175
|
126 connect(browse, SIGNAL(clicked()), this, SLOT(mergePathBrowse()));
|
Chris@175
|
127
|
Chris@178
|
128 pathsLayout->addWidget(new QLabel(tr("External text editor:")), row, 0);
|
Chris@178
|
129
|
Chris@195
|
130 m_editPathLabel = new QLineEdit();
|
Chris@181
|
131 m_editPathLabel->setText(settings.value("editorbinary").toString());
|
Chris@181
|
132 pathsLayout->addWidget(m_editPathLabel, row, 2);
|
Chris@178
|
133
|
Chris@178
|
134 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
135 pathsLayout->addWidget(browse, row++, 1);
|
Chris@178
|
136 connect(browse, SIGNAL(clicked()), this, SLOT(editPathBrowse()));
|
Chris@178
|
137
|
Chris@175
|
138 settings.endGroup();
|
Chris@176
|
139
|
Chris@176
|
140 settings.beginGroup("Locations");
|
Chris@176
|
141
|
Chris@176
|
142 pathsLayout->addWidget(new QLabel(tr("EasyHg Mercurial extension:")), row, 0);
|
Chris@176
|
143
|
Chris@195
|
144 m_extensionPathLabel = new QLineEdit();
|
Chris@181
|
145 m_extensionPathLabel->setText(settings.value("extensionpath").toString());
|
Chris@181
|
146 pathsLayout->addWidget(m_extensionPathLabel, row, 2);
|
Chris@176
|
147
|
Chris@176
|
148 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
149 pathsLayout->addWidget(browse, row++, 1);
|
Chris@176
|
150 connect(browse, SIGNAL(clicked()), this, SLOT(extensionPathBrowse()));
|
Chris@176
|
151
|
Chris@176
|
152 settings.endGroup();
|
Chris@176
|
153
|
Chris@176
|
154 settings.beginGroup("General");
|
Chris@176
|
155
|
Chris@176
|
156 //!!! more info plz
|
Chris@176
|
157 m_useExtension = new QCheckBox(tr("Use EasyHg Mercurial extension"));
|
Chris@176
|
158 m_useExtension->setChecked(settings.value("useextension", true).toBool());
|
Chris@181
|
159 pathsLayout->addWidget(m_useExtension, row++, 2);
|
Chris@176
|
160
|
Chris@176
|
161 settings.endGroup();
|
Chris@176
|
162
|
Chris@175
|
163
|
Chris@230
|
164
|
Chris@175
|
165 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
Chris@175
|
166 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@230
|
167 mainLayout->addWidget(bbox, 3, 0);
|
Chris@175
|
168 m_ok = bbox->button(QDialogButtonBox::Ok);
|
Chris@175
|
169 }
|
Chris@175
|
170
|
Chris@175
|
171 void
|
Chris@175
|
172 SettingsDialog::hgPathBrowse()
|
Chris@175
|
173 {
|
Chris@181
|
174 browseFor(tr("Mercurial program"), m_hgPathLabel);
|
Chris@175
|
175 }
|
Chris@175
|
176
|
Chris@175
|
177 void
|
Chris@175
|
178 SettingsDialog::diffPathBrowse()
|
Chris@175
|
179 {
|
Chris@181
|
180 browseFor(tr("External diff program"), m_diffPathLabel);
|
Chris@175
|
181 }
|
Chris@175
|
182
|
Chris@175
|
183 void
|
Chris@175
|
184 SettingsDialog::mergePathBrowse()
|
Chris@175
|
185 {
|
Chris@181
|
186 browseFor(tr("External file-merge program"), m_mergePathLabel);
|
Chris@175
|
187 }
|
Chris@175
|
188
|
Chris@175
|
189 void
|
Chris@178
|
190 SettingsDialog::editPathBrowse()
|
Chris@175
|
191 {
|
Chris@181
|
192 browseFor(tr("External text editor"), m_editPathLabel);
|
Chris@176
|
193 }
|
Chris@176
|
194
|
Chris@176
|
195 void
|
Chris@176
|
196 SettingsDialog::extensionPathBrowse()
|
Chris@176
|
197 {
|
Chris@181
|
198 browseFor(tr("EasyHg Mercurial extension"), m_extensionPathLabel);
|
Chris@181
|
199 }
|
Chris@181
|
200
|
Chris@181
|
201 void
|
Chris@195
|
202 SettingsDialog::browseFor(QString title, QLineEdit *edit)
|
Chris@181
|
203 {
|
Chris@181
|
204 QString origin = edit->text();
|
Chris@181
|
205
|
Chris@181
|
206 if (origin == "") {
|
Chris@181
|
207 #ifdef Q_OS_WIN32
|
Chris@181
|
208 origin = "c:";
|
Chris@181
|
209 #else
|
Chris@181
|
210 origin = QDir::homePath();
|
Chris@181
|
211 #endif
|
Chris@181
|
212 }
|
Chris@181
|
213
|
Chris@181
|
214 QString path = QFileDialog::getOpenFileName(this, title, origin);
|
Chris@181
|
215 if (path != QString()) {
|
Chris@181
|
216 edit->setText(path);
|
Chris@181
|
217 }
|
Chris@176
|
218 }
|
Chris@176
|
219
|
Chris@176
|
220 void
|
Chris@175
|
221 SettingsDialog::accept()
|
Chris@175
|
222 {
|
Chris@177
|
223 DEBUG << "SettingsDialog::accept" << endl;
|
Chris@175
|
224 QSettings settings;
|
Chris@175
|
225 settings.beginGroup("User Information");
|
Chris@175
|
226 settings.setValue("name", m_nameEdit->text());
|
Chris@175
|
227 settings.setValue("email", m_emailEdit->text());
|
Chris@175
|
228 settings.endGroup();
|
Chris@230
|
229 settings.beginGroup("Presentation");
|
Chris@230
|
230 bool b;
|
Chris@230
|
231 b = m_showIconLabels->isChecked();
|
Chris@230
|
232 if (b != settings.value("showiconlabels", true)) {
|
Chris@230
|
233 settings.setValue("showiconlabels", b);
|
Chris@230
|
234 m_presentationChanged = true;
|
Chris@230
|
235 }
|
Chris@230
|
236 b = m_showExtraText->isChecked();
|
Chris@230
|
237 if (b != settings.value("showhelpfultext", true)) {
|
Chris@230
|
238 settings.setValue("showhelpfultext", b);
|
Chris@230
|
239 m_presentationChanged = true;
|
Chris@230
|
240 }
|
Chris@230
|
241 settings.endGroup();
|
Chris@175
|
242 settings.beginGroup("Locations");
|
Chris@181
|
243 settings.setValue("hgbinary", m_hgPathLabel->text());
|
Chris@181
|
244 settings.setValue("extdiffbinary", m_diffPathLabel->text());
|
Chris@181
|
245 settings.setValue("mergebinary", m_mergePathLabel->text());
|
Chris@221
|
246 settings.setValue("editorbinary", m_editPathLabel->text());
|
Chris@181
|
247 settings.setValue("extensionpath", m_extensionPathLabel->text());
|
Chris@176
|
248 settings.endGroup();
|
Chris@176
|
249 settings.beginGroup("General");
|
Chris@176
|
250 settings.setValue("useextension", m_useExtension->isChecked());
|
Chris@175
|
251 settings.endGroup();
|
Chris@175
|
252 QDialog::accept();
|
Chris@175
|
253 }
|
Chris@175
|
254
|
Chris@175
|
255
|