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@181
|
74 m_hgPathLabel = new QLabel();
|
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@181
|
84 m_diffPathLabel = new QLabel();
|
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@181
|
94 m_mergePathLabel = new QLabel();
|
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@181
|
104 m_editPathLabel = new QLabel();
|
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@181
|
118 m_extensionPathLabel = new QLabel();
|
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 // m_ok->setEnabled(false);
|
Chris@175
|
143
|
Chris@175
|
144 //!!! m_ok->setEnabled(m_name != "");
|
Chris@175
|
145 // updateExample();
|
Chris@175
|
146 }
|
Chris@175
|
147
|
Chris@175
|
148 void
|
Chris@175
|
149 SettingsDialog::hgPathBrowse()
|
Chris@175
|
150 {
|
Chris@181
|
151 browseFor(tr("Mercurial program"), m_hgPathLabel);
|
Chris@175
|
152 }
|
Chris@175
|
153
|
Chris@175
|
154 void
|
Chris@175
|
155 SettingsDialog::diffPathBrowse()
|
Chris@175
|
156 {
|
Chris@181
|
157 browseFor(tr("External diff program"), m_diffPathLabel);
|
Chris@175
|
158 }
|
Chris@175
|
159
|
Chris@175
|
160 void
|
Chris@175
|
161 SettingsDialog::mergePathBrowse()
|
Chris@175
|
162 {
|
Chris@181
|
163 browseFor(tr("External file-merge program"), m_mergePathLabel);
|
Chris@175
|
164 }
|
Chris@175
|
165
|
Chris@175
|
166 void
|
Chris@178
|
167 SettingsDialog::editPathBrowse()
|
Chris@175
|
168 {
|
Chris@181
|
169 browseFor(tr("External text editor"), m_editPathLabel);
|
Chris@176
|
170 }
|
Chris@176
|
171
|
Chris@176
|
172 void
|
Chris@176
|
173 SettingsDialog::extensionPathBrowse()
|
Chris@176
|
174 {
|
Chris@181
|
175 browseFor(tr("EasyHg Mercurial extension"), m_extensionPathLabel);
|
Chris@181
|
176 }
|
Chris@181
|
177
|
Chris@181
|
178 void
|
Chris@181
|
179 SettingsDialog::browseFor(QString title, QLabel *edit)
|
Chris@181
|
180 {
|
Chris@181
|
181 QString origin = edit->text();
|
Chris@181
|
182
|
Chris@181
|
183 if (origin == "") {
|
Chris@181
|
184 #ifdef Q_OS_WIN32
|
Chris@181
|
185 origin = "c:";
|
Chris@181
|
186 #else
|
Chris@181
|
187 origin = QDir::homePath();
|
Chris@181
|
188 #endif
|
Chris@181
|
189 }
|
Chris@181
|
190
|
Chris@181
|
191 QString path = QFileDialog::getOpenFileName(this, title, origin);
|
Chris@181
|
192 if (path != QString()) {
|
Chris@181
|
193 edit->setText(path);
|
Chris@181
|
194 }
|
Chris@176
|
195 }
|
Chris@176
|
196
|
Chris@176
|
197 void
|
Chris@175
|
198 SettingsDialog::accept()
|
Chris@175
|
199 {
|
Chris@177
|
200 DEBUG << "SettingsDialog::accept" << endl;
|
Chris@175
|
201 QSettings settings;
|
Chris@175
|
202 settings.beginGroup("User Information");
|
Chris@175
|
203 settings.setValue("name", m_nameEdit->text());
|
Chris@175
|
204 settings.setValue("email", m_emailEdit->text());
|
Chris@175
|
205 settings.endGroup();
|
Chris@175
|
206 settings.beginGroup("Locations");
|
Chris@181
|
207 settings.setValue("hgbinary", m_hgPathLabel->text());
|
Chris@181
|
208 settings.setValue("extdiffbinary", m_diffPathLabel->text());
|
Chris@181
|
209 settings.setValue("mergebinary", m_mergePathLabel->text());
|
Chris@181
|
210 settings.setValue("extensionpath", m_extensionPathLabel->text());
|
Chris@176
|
211 settings.endGroup();
|
Chris@176
|
212 settings.beginGroup("General");
|
Chris@176
|
213 settings.setValue("useextension", m_useExtension->isChecked());
|
Chris@175
|
214 settings.endGroup();
|
Chris@175
|
215 QDialog::accept();
|
Chris@175
|
216 }
|
Chris@175
|
217
|
Chris@175
|
218
|