Mercurial > hg > easyhg
comparison settingsdialog.cpp @ 181:731aef59d5f4
* Settings dialog: This Will Do For Now
author | Chris Cannam |
---|---|
date | Fri, 17 Dec 2010 09:36:39 +0000 |
parents | 1a3af8617ea4 |
children | bf366e0b9050 |
comparison
equal
deleted
inserted
replaced
180:3d6d826b04ad | 181:731aef59d5f4 |
---|---|
21 | 21 |
22 #include <QGridLayout> | 22 #include <QGridLayout> |
23 #include <QGroupBox> | 23 #include <QGroupBox> |
24 #include <QDialogButtonBox> | 24 #include <QDialogButtonBox> |
25 #include <QSettings> | 25 #include <QSettings> |
26 #include <QDir> | |
27 #include <QFileDialog> | |
26 | 28 |
27 SettingsDialog::SettingsDialog(QWidget *parent) : | 29 SettingsDialog::SettingsDialog(QWidget *parent) : |
28 QDialog(parent) | 30 QDialog(parent) |
29 { | 31 { |
30 setModal(true); | 32 setModal(true); |
33 QSettings settings; | 35 QSettings settings; |
34 | 36 |
35 QGridLayout *mainLayout = new QGridLayout; | 37 QGridLayout *mainLayout = new QGridLayout; |
36 setLayout(mainLayout); | 38 setLayout(mainLayout); |
37 | 39 |
38 QGroupBox *meBox = new QGroupBox(tr("About me")); | 40 QGroupBox *meBox = new QGroupBox(tr("User details")); |
39 mainLayout->addWidget(meBox, 0, 0); | 41 mainLayout->addWidget(meBox, 0, 0); |
40 QGridLayout *meLayout = new QGridLayout; | 42 QGridLayout *meLayout = new QGridLayout; |
41 meBox->setLayout(meLayout); | 43 meBox->setLayout(meLayout); |
42 | 44 |
43 settings.beginGroup("User Information"); | 45 settings.beginGroup("User Information"); |
46 | 48 |
47 meLayout->addWidget(new QLabel(tr("Name:")), row, 0); | 49 meLayout->addWidget(new QLabel(tr("Name:")), row, 0); |
48 | 50 |
49 m_nameEdit = new QLineEdit(); | 51 m_nameEdit = new QLineEdit(); |
50 m_nameEdit->setText(settings.value("name", getUserRealName()).toString()); | 52 m_nameEdit->setText(settings.value("name", getUserRealName()).toString()); |
51 connect(m_nameEdit, SIGNAL(textChanged(const QString &)), | |
52 this, SLOT(realNameChanged(const QString &))); | |
53 meLayout->addWidget(m_nameEdit, row++, 1); | 53 meLayout->addWidget(m_nameEdit, row++, 1); |
54 | 54 |
55 meLayout->addWidget(new QLabel(tr("Email address:")), row, 0); | 55 meLayout->addWidget(new QLabel(tr("Email address:")), row, 0); |
56 | 56 |
57 m_emailEdit = new QLineEdit(); | 57 m_emailEdit = new QLineEdit(); |
58 m_emailEdit->setText(settings.value("email").toString()); | 58 m_emailEdit->setText(settings.value("email").toString()); |
59 connect(m_emailEdit, SIGNAL(textChanged(const QString &)), | |
60 this, SLOT(emailChanged(const QString &))); | |
61 meLayout->addWidget(m_emailEdit, row++, 1); | 59 meLayout->addWidget(m_emailEdit, row++, 1); |
62 | 60 |
63 settings.endGroup(); | 61 settings.endGroup(); |
64 | 62 |
65 QGroupBox *pathsBox = new QGroupBox(tr("System application locations")); | 63 QGroupBox *pathsBox = new QGroupBox(tr("System application locations")); |
71 | 69 |
72 row = 0; | 70 row = 0; |
73 | 71 |
74 pathsLayout->addWidget(new QLabel(tr("Mercurial (hg) program:")), row, 0); | 72 pathsLayout->addWidget(new QLabel(tr("Mercurial (hg) program:")), row, 0); |
75 | 73 |
76 m_hgPathEdit = new QLineEdit(); | 74 m_hgPathLabel = new QLabel(); |
77 m_hgPathEdit->setText(settings.value("hgbinary").toString()); | 75 m_hgPathLabel->setText(settings.value("hgbinary").toString()); |
78 connect(m_hgPathEdit, SIGNAL(textChanged(const QString &)), | 76 pathsLayout->addWidget(m_hgPathLabel, row, 2); |
79 this, SLOT(hgPathChanged(const QString &))); | |
80 pathsLayout->addWidget(m_hgPathEdit, row, 1); | |
81 | 77 |
82 QPushButton *browse = new QPushButton(tr("Browse...")); | 78 QPushButton *browse = new QPushButton(tr("Browse...")); |
83 pathsLayout->addWidget(browse, row++, 2); | 79 pathsLayout->addWidget(browse, row++, 1); |
84 connect(browse, SIGNAL(clicked()), this, SLOT(hgPathBrowse())); | 80 connect(browse, SIGNAL(clicked()), this, SLOT(hgPathBrowse())); |
85 | 81 |
86 pathsLayout->addWidget(new QLabel(tr("External diff program:")), row, 0); | 82 pathsLayout->addWidget(new QLabel(tr("External diff program:")), row, 0); |
87 | 83 |
88 m_diffPathEdit = new QLineEdit(); | 84 m_diffPathLabel = new QLabel(); |
89 m_diffPathEdit->setText(settings.value("extdiffbinary").toString()); | 85 m_diffPathLabel->setText(settings.value("extdiffbinary").toString()); |
90 connect(m_diffPathEdit, SIGNAL(textChanged(const QString &)), | 86 pathsLayout->addWidget(m_diffPathLabel, row, 2); |
91 this, SLOT(diffPathChanged(const QString &))); | 87 |
92 pathsLayout->addWidget(m_diffPathEdit, row, 1); | 88 browse = new QPushButton(tr("Browse...")); |
93 | 89 pathsLayout->addWidget(browse, row++, 1); |
94 browse = new QPushButton(tr("Browse...")); | |
95 pathsLayout->addWidget(browse, row++, 2); | |
96 connect(browse, SIGNAL(clicked()), this, SLOT(diffPathBrowse())); | 90 connect(browse, SIGNAL(clicked()), this, SLOT(diffPathBrowse())); |
97 | 91 |
98 pathsLayout->addWidget(new QLabel(tr("External file-merge program:")), row, 0); | 92 pathsLayout->addWidget(new QLabel(tr("External file-merge program:")), row, 0); |
99 | 93 |
100 m_mergePathEdit = new QLineEdit(); | 94 m_mergePathLabel = new QLabel(); |
101 m_mergePathEdit->setText(settings.value("mergebinary").toString()); | 95 m_mergePathLabel->setText(settings.value("mergebinary").toString()); |
102 connect(m_mergePathEdit, SIGNAL(textChanged(const QString &)), | 96 pathsLayout->addWidget(m_mergePathLabel, row, 2); |
103 this, SLOT(mergePathChanged(const QString &))); | 97 |
104 pathsLayout->addWidget(m_mergePathEdit, row, 1); | 98 browse = new QPushButton(tr("Browse...")); |
105 | 99 pathsLayout->addWidget(browse, row++, 1); |
106 browse = new QPushButton(tr("Browse...")); | |
107 pathsLayout->addWidget(browse, row++, 2); | |
108 connect(browse, SIGNAL(clicked()), this, SLOT(mergePathBrowse())); | 100 connect(browse, SIGNAL(clicked()), this, SLOT(mergePathBrowse())); |
109 | 101 |
110 pathsLayout->addWidget(new QLabel(tr("External text editor:")), row, 0); | 102 pathsLayout->addWidget(new QLabel(tr("External text editor:")), row, 0); |
111 | 103 |
112 m_editPathEdit = new QLineEdit(); | 104 m_editPathLabel = new QLabel(); |
113 m_editPathEdit->setText(settings.value("editorbinary").toString()); | 105 m_editPathLabel->setText(settings.value("editorbinary").toString()); |
114 connect(m_editPathEdit, SIGNAL(textChanged(const QString &)), | 106 pathsLayout->addWidget(m_editPathLabel, row, 2); |
115 this, SLOT(editPathChanged(const QString &))); | 107 |
116 pathsLayout->addWidget(m_editPathEdit, row, 1); | 108 browse = new QPushButton(tr("Browse...")); |
117 | 109 pathsLayout->addWidget(browse, row++, 1); |
118 browse = new QPushButton(tr("Browse...")); | |
119 pathsLayout->addWidget(browse, row++, 2); | |
120 connect(browse, SIGNAL(clicked()), this, SLOT(editPathBrowse())); | 110 connect(browse, SIGNAL(clicked()), this, SLOT(editPathBrowse())); |
121 | 111 |
122 settings.endGroup(); | 112 settings.endGroup(); |
123 | 113 |
124 settings.beginGroup("Locations"); | 114 settings.beginGroup("Locations"); |
125 | 115 |
126 pathsLayout->addWidget(new QLabel(tr("EasyHg Mercurial extension:")), row, 0); | 116 pathsLayout->addWidget(new QLabel(tr("EasyHg Mercurial extension:")), row, 0); |
127 | 117 |
128 m_extensionPathEdit = new QLineEdit(); | 118 m_extensionPathLabel = new QLabel(); |
129 m_extensionPathEdit->setText(settings.value("extensionpath").toString()); | 119 m_extensionPathLabel->setText(settings.value("extensionpath").toString()); |
130 connect(m_extensionPathEdit, SIGNAL(textChanged(const QString &)), | 120 pathsLayout->addWidget(m_extensionPathLabel, row, 2); |
131 this, SLOT(extensionPathChanged(const QString &))); | 121 |
132 pathsLayout->addWidget(m_extensionPathEdit, row, 1); | 122 browse = new QPushButton(tr("Browse...")); |
133 | 123 pathsLayout->addWidget(browse, row++, 1); |
134 browse = new QPushButton(tr("Browse...")); | |
135 pathsLayout->addWidget(browse, row++, 2); | |
136 connect(browse, SIGNAL(clicked()), this, SLOT(extensionPathBrowse())); | 124 connect(browse, SIGNAL(clicked()), this, SLOT(extensionPathBrowse())); |
137 | 125 |
138 settings.endGroup(); | 126 settings.endGroup(); |
139 | 127 |
140 settings.beginGroup("General"); | 128 settings.beginGroup("General"); |
141 | 129 |
142 //!!! more info plz | 130 //!!! more info plz |
143 m_useExtension = new QCheckBox(tr("Use EasyHg Mercurial extension")); | 131 m_useExtension = new QCheckBox(tr("Use EasyHg Mercurial extension")); |
144 m_useExtension->setChecked(settings.value("useextension", true).toBool()); | 132 m_useExtension->setChecked(settings.value("useextension", true).toBool()); |
145 pathsLayout->addWidget(m_useExtension, row++, 1); | 133 pathsLayout->addWidget(m_useExtension, row++, 2); |
146 | 134 |
147 settings.endGroup(); | 135 settings.endGroup(); |
148 | 136 |
149 | 137 |
150 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok); | 138 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok); |
156 //!!! m_ok->setEnabled(m_name != ""); | 144 //!!! m_ok->setEnabled(m_name != ""); |
157 // updateExample(); | 145 // updateExample(); |
158 } | 146 } |
159 | 147 |
160 void | 148 void |
161 SettingsDialog::realNameChanged(const QString &s) | |
162 { | |
163 } | |
164 | |
165 void | |
166 SettingsDialog::emailChanged(const QString &s) | |
167 { | |
168 } | |
169 | |
170 void | |
171 SettingsDialog::hgPathChanged(const QString &s) | |
172 { | |
173 } | |
174 | |
175 void | |
176 SettingsDialog::hgPathBrowse() | 149 SettingsDialog::hgPathBrowse() |
177 { | 150 { |
178 } | 151 browseFor(tr("Mercurial program"), m_hgPathLabel); |
179 | |
180 void | |
181 SettingsDialog::diffPathChanged(const QString &s) | |
182 { | |
183 } | 152 } |
184 | 153 |
185 void | 154 void |
186 SettingsDialog::diffPathBrowse() | 155 SettingsDialog::diffPathBrowse() |
187 { | 156 { |
188 } | 157 browseFor(tr("External diff program"), m_diffPathLabel); |
189 | |
190 void | |
191 SettingsDialog::mergePathChanged(const QString &s) | |
192 { | |
193 } | 158 } |
194 | 159 |
195 void | 160 void |
196 SettingsDialog::mergePathBrowse() | 161 SettingsDialog::mergePathBrowse() |
197 { | 162 { |
198 } | 163 browseFor(tr("External file-merge program"), m_mergePathLabel); |
199 | |
200 void | |
201 SettingsDialog::editPathChanged(const QString &s) | |
202 { | |
203 } | 164 } |
204 | 165 |
205 void | 166 void |
206 SettingsDialog::editPathBrowse() | 167 SettingsDialog::editPathBrowse() |
207 { | 168 { |
208 } | 169 browseFor(tr("External text editor"), m_editPathLabel); |
209 | |
210 void | |
211 SettingsDialog::extensionPathChanged(const QString &s) | |
212 { | |
213 } | 170 } |
214 | 171 |
215 void | 172 void |
216 SettingsDialog::extensionPathBrowse() | 173 SettingsDialog::extensionPathBrowse() |
217 { | 174 { |
175 browseFor(tr("EasyHg Mercurial extension"), m_extensionPathLabel); | |
176 } | |
177 | |
178 void | |
179 SettingsDialog::browseFor(QString title, QLabel *edit) | |
180 { | |
181 QString origin = edit->text(); | |
182 | |
183 if (origin == "") { | |
184 #ifdef Q_OS_WIN32 | |
185 origin = "c:"; | |
186 #else | |
187 origin = QDir::homePath(); | |
188 #endif | |
189 } | |
190 | |
191 QString path = QFileDialog::getOpenFileName(this, title, origin); | |
192 if (path != QString()) { | |
193 edit->setText(path); | |
194 } | |
218 } | 195 } |
219 | 196 |
220 void | 197 void |
221 SettingsDialog::accept() | 198 SettingsDialog::accept() |
222 { | 199 { |
225 settings.beginGroup("User Information"); | 202 settings.beginGroup("User Information"); |
226 settings.setValue("name", m_nameEdit->text()); | 203 settings.setValue("name", m_nameEdit->text()); |
227 settings.setValue("email", m_emailEdit->text()); | 204 settings.setValue("email", m_emailEdit->text()); |
228 settings.endGroup(); | 205 settings.endGroup(); |
229 settings.beginGroup("Locations"); | 206 settings.beginGroup("Locations"); |
230 settings.setValue("hgbinary", m_hgPathEdit->text()); | 207 settings.setValue("hgbinary", m_hgPathLabel->text()); |
231 settings.setValue("extdiffbinary", m_diffPathEdit->text()); | 208 settings.setValue("extdiffbinary", m_diffPathLabel->text()); |
232 settings.setValue("mergebinary", m_mergePathEdit->text()); | 209 settings.setValue("mergebinary", m_mergePathLabel->text()); |
233 settings.setValue("extensionpath", m_extensionPathEdit->text()); | 210 settings.setValue("extensionpath", m_extensionPathLabel->text()); |
234 settings.endGroup(); | 211 settings.endGroup(); |
235 settings.beginGroup("General"); | 212 settings.beginGroup("General"); |
236 settings.setValue("useextension", m_useExtension->isChecked()); | 213 settings.setValue("useextension", m_useExtension->isChecked()); |
237 settings.endGroup(); | 214 settings.endGroup(); |
238 QDialog::accept(); | 215 QDialog::accept(); |