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@175
|
30 QDialog(parent)
|
Chris@175
|
31 {
|
Chris@175
|
32 setModal(true);
|
Chris@175
|
33 setWindowTitle(tr("Settings"));
|
Chris@175
|
34
|
Chris@175
|
35 QSettings settings;
|
Chris@175
|
36
|
Chris@175
|
37 QGridLayout *mainLayout = new QGridLayout;
|
Chris@175
|
38 setLayout(mainLayout);
|
Chris@175
|
39
|
Chris@181
|
40 QGroupBox *meBox = new QGroupBox(tr("User details"));
|
Chris@175
|
41 mainLayout->addWidget(meBox, 0, 0);
|
Chris@175
|
42 QGridLayout *meLayout = new QGridLayout;
|
Chris@175
|
43 meBox->setLayout(meLayout);
|
Chris@175
|
44
|
Chris@175
|
45 settings.beginGroup("User Information");
|
Chris@175
|
46
|
Chris@175
|
47 int row = 0;
|
Chris@175
|
48
|
Chris@175
|
49 meLayout->addWidget(new QLabel(tr("Name:")), row, 0);
|
Chris@175
|
50
|
Chris@175
|
51 m_nameEdit = new QLineEdit();
|
Chris@175
|
52 m_nameEdit->setText(settings.value("name", getUserRealName()).toString());
|
Chris@175
|
53 meLayout->addWidget(m_nameEdit, row++, 1);
|
Chris@175
|
54
|
Chris@175
|
55 meLayout->addWidget(new QLabel(tr("Email address:")), row, 0);
|
Chris@175
|
56
|
Chris@175
|
57 m_emailEdit = new QLineEdit();
|
Chris@175
|
58 m_emailEdit->setText(settings.value("email").toString());
|
Chris@175
|
59 meLayout->addWidget(m_emailEdit, row++, 1);
|
Chris@175
|
60
|
Chris@175
|
61 settings.endGroup();
|
Chris@175
|
62
|
Chris@175
|
63 QGroupBox *pathsBox = new QGroupBox(tr("System application locations"));
|
Chris@175
|
64 mainLayout->addWidget(pathsBox, 1, 0);
|
Chris@175
|
65 QGridLayout *pathsLayout = new QGridLayout;
|
Chris@175
|
66 pathsBox->setLayout(pathsLayout);
|
Chris@175
|
67
|
Chris@175
|
68 settings.beginGroup("Locations");
|
Chris@175
|
69
|
Chris@175
|
70 row = 0;
|
Chris@175
|
71
|
Chris@175
|
72 pathsLayout->addWidget(new QLabel(tr("Mercurial (hg) program:")), row, 0);
|
Chris@175
|
73
|
Chris@195
|
74 m_hgPathLabel = new QLineEdit();
|
Chris@181
|
75 m_hgPathLabel->setText(settings.value("hgbinary").toString());
|
Chris@181
|
76 pathsLayout->addWidget(m_hgPathLabel, row, 2);
|
Chris@175
|
77
|
Chris@175
|
78 QPushButton *browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
79 pathsLayout->addWidget(browse, row++, 1);
|
Chris@175
|
80 connect(browse, SIGNAL(clicked()), this, SLOT(hgPathBrowse()));
|
Chris@175
|
81
|
Chris@175
|
82 pathsLayout->addWidget(new QLabel(tr("External diff program:")), row, 0);
|
Chris@175
|
83
|
Chris@195
|
84 m_diffPathLabel = new QLineEdit();
|
Chris@181
|
85 m_diffPathLabel->setText(settings.value("extdiffbinary").toString());
|
Chris@181
|
86 pathsLayout->addWidget(m_diffPathLabel, row, 2);
|
Chris@175
|
87
|
Chris@175
|
88 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
89 pathsLayout->addWidget(browse, row++, 1);
|
Chris@175
|
90 connect(browse, SIGNAL(clicked()), this, SLOT(diffPathBrowse()));
|
Chris@178
|
91
|
Chris@175
|
92 pathsLayout->addWidget(new QLabel(tr("External file-merge program:")), row, 0);
|
Chris@175
|
93
|
Chris@195
|
94 m_mergePathLabel = new QLineEdit();
|
Chris@181
|
95 m_mergePathLabel->setText(settings.value("mergebinary").toString());
|
Chris@181
|
96 pathsLayout->addWidget(m_mergePathLabel, row, 2);
|
Chris@175
|
97
|
Chris@175
|
98 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
99 pathsLayout->addWidget(browse, row++, 1);
|
Chris@175
|
100 connect(browse, SIGNAL(clicked()), this, SLOT(mergePathBrowse()));
|
Chris@175
|
101
|
Chris@178
|
102 pathsLayout->addWidget(new QLabel(tr("External text editor:")), row, 0);
|
Chris@178
|
103
|
Chris@195
|
104 m_editPathLabel = new QLineEdit();
|
Chris@181
|
105 m_editPathLabel->setText(settings.value("editorbinary").toString());
|
Chris@181
|
106 pathsLayout->addWidget(m_editPathLabel, row, 2);
|
Chris@178
|
107
|
Chris@178
|
108 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
109 pathsLayout->addWidget(browse, row++, 1);
|
Chris@178
|
110 connect(browse, SIGNAL(clicked()), this, SLOT(editPathBrowse()));
|
Chris@178
|
111
|
Chris@175
|
112 settings.endGroup();
|
Chris@176
|
113
|
Chris@176
|
114 settings.beginGroup("Locations");
|
Chris@176
|
115
|
Chris@176
|
116 pathsLayout->addWidget(new QLabel(tr("EasyHg Mercurial extension:")), row, 0);
|
Chris@176
|
117
|
Chris@195
|
118 m_extensionPathLabel = new QLineEdit();
|
Chris@181
|
119 m_extensionPathLabel->setText(settings.value("extensionpath").toString());
|
Chris@181
|
120 pathsLayout->addWidget(m_extensionPathLabel, row, 2);
|
Chris@176
|
121
|
Chris@176
|
122 browse = new QPushButton(tr("Browse..."));
|
Chris@181
|
123 pathsLayout->addWidget(browse, row++, 1);
|
Chris@176
|
124 connect(browse, SIGNAL(clicked()), this, SLOT(extensionPathBrowse()));
|
Chris@176
|
125
|
Chris@176
|
126 settings.endGroup();
|
Chris@176
|
127
|
Chris@176
|
128 settings.beginGroup("General");
|
Chris@176
|
129
|
Chris@176
|
130 //!!! more info plz
|
Chris@176
|
131 m_useExtension = new QCheckBox(tr("Use EasyHg Mercurial extension"));
|
Chris@176
|
132 m_useExtension->setChecked(settings.value("useextension", true).toBool());
|
Chris@181
|
133 pathsLayout->addWidget(m_useExtension, row++, 2);
|
Chris@176
|
134
|
Chris@176
|
135 settings.endGroup();
|
Chris@176
|
136
|
Chris@175
|
137
|
Chris@175
|
138 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
Chris@175
|
139 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@175
|
140 mainLayout->addWidget(bbox, 2, 0);
|
Chris@175
|
141 m_ok = bbox->button(QDialogButtonBox::Ok);
|
Chris@175
|
142 }
|
Chris@175
|
143
|
Chris@175
|
144 void
|
Chris@175
|
145 SettingsDialog::hgPathBrowse()
|
Chris@175
|
146 {
|
Chris@181
|
147 browseFor(tr("Mercurial program"), m_hgPathLabel);
|
Chris@175
|
148 }
|
Chris@175
|
149
|
Chris@175
|
150 void
|
Chris@175
|
151 SettingsDialog::diffPathBrowse()
|
Chris@175
|
152 {
|
Chris@181
|
153 browseFor(tr("External diff program"), m_diffPathLabel);
|
Chris@175
|
154 }
|
Chris@175
|
155
|
Chris@175
|
156 void
|
Chris@175
|
157 SettingsDialog::mergePathBrowse()
|
Chris@175
|
158 {
|
Chris@181
|
159 browseFor(tr("External file-merge program"), m_mergePathLabel);
|
Chris@175
|
160 }
|
Chris@175
|
161
|
Chris@175
|
162 void
|
Chris@178
|
163 SettingsDialog::editPathBrowse()
|
Chris@175
|
164 {
|
Chris@181
|
165 browseFor(tr("External text editor"), m_editPathLabel);
|
Chris@176
|
166 }
|
Chris@176
|
167
|
Chris@176
|
168 void
|
Chris@176
|
169 SettingsDialog::extensionPathBrowse()
|
Chris@176
|
170 {
|
Chris@181
|
171 browseFor(tr("EasyHg Mercurial extension"), m_extensionPathLabel);
|
Chris@181
|
172 }
|
Chris@181
|
173
|
Chris@181
|
174 void
|
Chris@195
|
175 SettingsDialog::browseFor(QString title, QLineEdit *edit)
|
Chris@181
|
176 {
|
Chris@181
|
177 QString origin = edit->text();
|
Chris@181
|
178
|
Chris@181
|
179 if (origin == "") {
|
Chris@181
|
180 #ifdef Q_OS_WIN32
|
Chris@181
|
181 origin = "c:";
|
Chris@181
|
182 #else
|
Chris@181
|
183 origin = QDir::homePath();
|
Chris@181
|
184 #endif
|
Chris@181
|
185 }
|
Chris@181
|
186
|
Chris@181
|
187 QString path = QFileDialog::getOpenFileName(this, title, origin);
|
Chris@181
|
188 if (path != QString()) {
|
Chris@181
|
189 edit->setText(path);
|
Chris@181
|
190 }
|
Chris@176
|
191 }
|
Chris@176
|
192
|
Chris@176
|
193 void
|
Chris@175
|
194 SettingsDialog::accept()
|
Chris@175
|
195 {
|
Chris@177
|
196 DEBUG << "SettingsDialog::accept" << endl;
|
Chris@175
|
197 QSettings settings;
|
Chris@175
|
198 settings.beginGroup("User Information");
|
Chris@175
|
199 settings.setValue("name", m_nameEdit->text());
|
Chris@175
|
200 settings.setValue("email", m_emailEdit->text());
|
Chris@175
|
201 settings.endGroup();
|
Chris@175
|
202 settings.beginGroup("Locations");
|
Chris@181
|
203 settings.setValue("hgbinary", m_hgPathLabel->text());
|
Chris@181
|
204 settings.setValue("extdiffbinary", m_diffPathLabel->text());
|
Chris@181
|
205 settings.setValue("mergebinary", m_mergePathLabel->text());
|
Chris@181
|
206 settings.setValue("extensionpath", m_extensionPathLabel->text());
|
Chris@176
|
207 settings.endGroup();
|
Chris@176
|
208 settings.beginGroup("General");
|
Chris@176
|
209 settings.setValue("useextension", m_useExtension->isChecked());
|
Chris@175
|
210 settings.endGroup();
|
Chris@175
|
211 QDialog::accept();
|
Chris@175
|
212 }
|
Chris@175
|
213
|
Chris@175
|
214
|