annotate src/settingsdialog.cpp @ 548:dca5bd5b2a06

Merge from branch "fswatcher"
author Chris Cannam
date Tue, 14 Feb 2012 17:55:39 +0000
parents 896b7903e8f2
children 533519ebc0cb
rev   line source
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@244 8 Copyright (c) 2011 Chris Cannam
Chris@244 9 Copyright (c) 2011 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@273 28 #include <QMessageBox>
Chris@466 29 #include <QTabWidget>
Chris@175 30
Chris@239 31 QString
Chris@239 32 SettingsDialog::m_installPath;
Chris@239 33
Chris@175 34 SettingsDialog::SettingsDialog(QWidget *parent) :
Chris@230 35 QDialog(parent),
Chris@230 36 m_presentationChanged(false)
Chris@175 37 {
Chris@175 38 setModal(true);
Chris@175 39 setWindowTitle(tr("Settings"));
Chris@175 40
Chris@175 41 QGridLayout *mainLayout = new QGridLayout;
Chris@175 42 setLayout(mainLayout);
Chris@175 43
Chris@472 44 m_tabs = new QTabWidget;
Chris@472 45 mainLayout->addWidget(m_tabs, 0, 0);
Chris@230 46
Chris@230 47
Chris@466 48 // QGroupBox *meBox = new QGroupBox(tr("User details"));
Chris@466 49 // mainLayout->addWidget(meBox, 0, 0);
Chris@466 50
Chris@466 51 QWidget *meBox = new QWidget;
Chris@472 52 m_tabs->addTab(meBox, tr("User details"));
Chris@466 53
Chris@175 54 QGridLayout *meLayout = new QGridLayout;
Chris@175 55 meBox->setLayout(meLayout);
Chris@175 56
Chris@175 57 int row = 0;
Chris@175 58
Chris@175 59 meLayout->addWidget(new QLabel(tr("Name:")), row, 0);
Chris@175 60
Chris@175 61 m_nameEdit = new QLineEdit();
Chris@175 62 meLayout->addWidget(m_nameEdit, row++, 1);
Chris@175 63
Chris@175 64 meLayout->addWidget(new QLabel(tr("Email address:")), row, 0);
Chris@175 65
Chris@175 66 m_emailEdit = new QLineEdit();
Chris@175 67 meLayout->addWidget(m_emailEdit, row++, 1);
Chris@175 68
Chris@466 69 meLayout->setRowStretch(row, 20);
Chris@230 70
Chris@230 71
Chris@466 72 // QGroupBox *lookBox = new QGroupBox(tr("Presentation"));
Chris@466 73 // mainLayout->addWidget(lookBox, 1, 0);
Chris@466 74
Chris@466 75 QWidget *lookBox = new QWidget;
Chris@472 76 m_tabs->addTab(lookBox, tr("Presentation"));
Chris@466 77
Chris@230 78 QGridLayout *lookLayout = new QGridLayout;
Chris@230 79 lookBox->setLayout(lookLayout);
Chris@230 80
Chris@230 81 row = 0;
Chris@230 82
Chris@230 83 m_showIconLabels = new QCheckBox(tr("Show labels on toolbar icons"));
Chris@273 84 lookLayout->addWidget(m_showIconLabels, row++, 0, 1, 2);
Chris@230 85
Chris@230 86 m_showExtraText = new QCheckBox(tr("Show long descriptions for file status headings"));
Chris@273 87 lookLayout->addWidget(m_showExtraText, row++, 0, 1, 2);
Chris@273 88
Chris@273 89 #ifdef NOT_IMPLEMENTED_YET
Chris@273 90 lookLayout->addWidget(new QLabel(tr("Place the work and history views")), row, 0);
Chris@273 91 m_workHistoryArrangement = new QComboBox();
Chris@273 92 m_workHistoryArrangement->addItem(tr("In separate tabs"));
Chris@273 93 m_workHistoryArrangement->addItem(tr("Side-by-side in a single pane"));
Chris@273 94 lookLayout->addWidget(m_workHistoryArrangement, row++, 1, Qt::AlignLeft);
Chris@273 95 lookLayout->setColumnStretch(1, 20);
Chris@273 96 #endif
Chris@230 97
Chris@273 98 lookLayout->addWidget(new QLabel(tr("Label the history timeline with")), row, 0);
Chris@273 99 m_dateFormat = new QComboBox();
Chris@273 100 m_dateFormat->addItem(tr("Ages, for example \"5 weeks ago\""));
Chris@273 101 m_dateFormat->addItem(tr("Dates, for example \"2010-06-23\""));
Chris@273 102 lookLayout->addWidget(m_dateFormat, row++, 1, Qt::AlignLeft);
Chris@273 103 lookLayout->setColumnStretch(1, 20);
Chris@466 104
Chris@466 105 lookLayout->setRowStretch(row, 20);
Chris@273 106
Chris@230 107
Chris@466 108 QWidget *pathsBox = new QWidget;
Chris@472 109 m_tabs->addTab(pathsBox, tr("System application locations"));
Chris@466 110
Chris@466 111 // QGroupBox *pathsBox = new QGroupBox(tr("System application locations"));
Chris@466 112 // mainLayout->addWidget(pathsBox, 2, 0);
Chris@175 113 QGridLayout *pathsLayout = new QGridLayout;
Chris@175 114 pathsBox->setLayout(pathsLayout);
Chris@175 115
Chris@175 116 row = 0;
Chris@175 117
Chris@175 118 pathsLayout->addWidget(new QLabel(tr("Mercurial (hg) program:")), row, 0);
Chris@175 119
Chris@195 120 m_hgPathLabel = new QLineEdit();
Chris@181 121 pathsLayout->addWidget(m_hgPathLabel, row, 2);
Chris@175 122
Chris@175 123 QPushButton *browse = new QPushButton(tr("Browse..."));
Chris@181 124 pathsLayout->addWidget(browse, row++, 1);
Chris@175 125 connect(browse, SIGNAL(clicked()), this, SLOT(hgPathBrowse()));
Chris@175 126
Chris@175 127 pathsLayout->addWidget(new QLabel(tr("External diff program:")), row, 0);
Chris@175 128
Chris@195 129 m_diffPathLabel = new QLineEdit();
Chris@181 130 pathsLayout->addWidget(m_diffPathLabel, row, 2);
Chris@175 131
Chris@175 132 browse = new QPushButton(tr("Browse..."));
Chris@181 133 pathsLayout->addWidget(browse, row++, 1);
Chris@175 134 connect(browse, SIGNAL(clicked()), this, SLOT(diffPathBrowse()));
Chris@178 135
Chris@175 136 pathsLayout->addWidget(new QLabel(tr("External file-merge program:")), row, 0);
Chris@175 137
Chris@195 138 m_mergePathLabel = new QLineEdit();
Chris@181 139 pathsLayout->addWidget(m_mergePathLabel, row, 2);
Chris@175 140
Chris@175 141 browse = new QPushButton(tr("Browse..."));
Chris@181 142 pathsLayout->addWidget(browse, row++, 1);
Chris@175 143 connect(browse, SIGNAL(clicked()), this, SLOT(mergePathBrowse()));
Chris@175 144
chris@406 145 pathsLayout->addWidget(new QLabel(tr("SSH program (for ssh URLs):")), row, 0);
chris@406 146
chris@406 147 m_sshPathLabel = new QLineEdit();
chris@406 148 pathsLayout->addWidget(m_sshPathLabel, row, 2);
chris@406 149
chris@406 150 browse = new QPushButton(tr("Browse..."));
chris@406 151 pathsLayout->addWidget(browse, row++, 1);
chris@406 152 connect(browse, SIGNAL(clicked()), this, SLOT(sshPathBrowse()));
chris@406 153
Chris@176 154 pathsLayout->addWidget(new QLabel(tr("EasyHg Mercurial extension:")), row, 0);
Chris@176 155
Chris@195 156 m_extensionPathLabel = new QLineEdit();
Chris@181 157 pathsLayout->addWidget(m_extensionPathLabel, row, 2);
Chris@176 158
Chris@176 159 browse = new QPushButton(tr("Browse..."));
Chris@181 160 pathsLayout->addWidget(browse, row++, 1);
Chris@176 161 connect(browse, SIGNAL(clicked()), this, SLOT(extensionPathBrowse()));
Chris@176 162
Chris@176 163 //!!! more info plz
Chris@176 164 m_useExtension = new QCheckBox(tr("Use EasyHg Mercurial extension"));
Chris@181 165 pathsLayout->addWidget(m_useExtension, row++, 2);
Chris@176 166
Chris@466 167 pathsLayout->setRowStretch(row, 20);
Chris@466 168
Chris@176 169
Chris@239 170 reset(); // loads current defaults from settings
Chris@175 171
Chris@230 172
Chris@175 173 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok);
Chris@239 174 connect(bbox->addButton(tr("Restore defaults"), QDialogButtonBox::ResetRole),
Chris@239 175 SIGNAL(clicked()), this, SLOT(restoreDefaults()));
Chris@175 176 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
Chris@230 177 mainLayout->addWidget(bbox, 3, 0);
Chris@175 178 m_ok = bbox->button(QDialogButtonBox::Ok);
Chris@175 179 }
Chris@175 180
Chris@175 181 void
Chris@472 182 SettingsDialog::setCurrentTab(Tab t)
Chris@472 183 {
Chris@472 184 switch (t) {
Chris@472 185 case PersonalDetailsTab: m_tabs->setCurrentIndex(0); break;
Chris@472 186 case PresentationTab: m_tabs->setCurrentIndex(1); break;
Chris@472 187 case PathsTab: m_tabs->setCurrentIndex(2); break;
Chris@472 188 }
Chris@472 189 }
Chris@472 190
Chris@472 191 void
Chris@175 192 SettingsDialog::hgPathBrowse()
Chris@175 193 {
Chris@181 194 browseFor(tr("Mercurial program"), m_hgPathLabel);
Chris@175 195 }
Chris@175 196
Chris@175 197 void
Chris@175 198 SettingsDialog::diffPathBrowse()
Chris@175 199 {
Chris@181 200 browseFor(tr("External diff program"), m_diffPathLabel);
Chris@175 201 }
Chris@175 202
Chris@175 203 void
Chris@175 204 SettingsDialog::mergePathBrowse()
Chris@175 205 {
Chris@181 206 browseFor(tr("External file-merge program"), m_mergePathLabel);
Chris@175 207 }
Chris@175 208
Chris@175 209 void
chris@406 210 SettingsDialog::sshPathBrowse()
chris@406 211 {
chris@406 212 browseFor(tr("SSH program"), m_sshPathLabel);
chris@406 213 }
chris@406 214
chris@406 215 void
Chris@176 216 SettingsDialog::extensionPathBrowse()
Chris@176 217 {
Chris@181 218 browseFor(tr("EasyHg Mercurial extension"), m_extensionPathLabel);
Chris@181 219 }
Chris@181 220
Chris@181 221 void
Chris@195 222 SettingsDialog::browseFor(QString title, QLineEdit *edit)
Chris@181 223 {
Chris@181 224 QString origin = edit->text();
Chris@181 225
Chris@181 226 if (origin == "") {
Chris@181 227 #ifdef Q_OS_WIN32
Chris@181 228 origin = "c:";
Chris@181 229 #else
Chris@181 230 origin = QDir::homePath();
Chris@181 231 #endif
Chris@181 232 }
Chris@181 233
Chris@181 234 QString path = QFileDialog::getOpenFileName(this, title, origin);
Chris@181 235 if (path != QString()) {
Chris@181 236 edit->setText(path);
Chris@181 237 }
Chris@176 238 }
Chris@176 239
Chris@176 240 void
Chris@239 241 SettingsDialog::restoreDefaults()
Chris@239 242 {
Chris@273 243 if (QMessageBox::question
Chris@273 244 (this, tr("Restore default settings?"),
Chris@273 245 tr("<qt><b>Restore default settings?</b><br><br>Are you sure you want to reset all settings to their default values?"),
Chris@273 246 QMessageBox::Ok | QMessageBox::Cancel,
Chris@273 247 QMessageBox::Cancel) == QMessageBox::Ok) {
Chris@273 248 clear();
Chris@273 249 findDefaultLocations();
Chris@273 250 reset();
Chris@273 251 }
Chris@239 252 }
Chris@239 253
Chris@239 254 void
Chris@239 255 SettingsDialog::findDefaultLocations(QString installPath)
Chris@239 256 {
Chris@239 257 m_installPath = installPath;
Chris@239 258 findHgBinaryName();
Chris@239 259 findExtension();
Chris@239 260 findDiffBinaryName();
Chris@239 261 findMergeBinaryName();
chris@406 262 findSshBinaryName();
Chris@239 263 }
Chris@239 264
Chris@239 265 void
Chris@239 266 SettingsDialog::findHgBinaryName()
Chris@239 267 {
Chris@239 268 QSettings settings;
Chris@239 269 settings.beginGroup("Locations");
Chris@239 270 QString hg = settings.value("hgbinary", "").toString();
Chris@239 271 if (hg == "") {
Chris@239 272 hg = findInPath("hg", m_installPath, true);
Chris@239 273 }
Chris@239 274 if (hg != "") {
Chris@239 275 settings.setValue("hgbinary", hg);
Chris@239 276 }
Chris@239 277 }
Chris@239 278
Chris@240 279 QString
Chris@240 280 SettingsDialog::getUnbundledExtensionFileName()
Chris@240 281 {
Chris@240 282 QString home = QDir::homePath();
Chris@240 283 QString target = QString("%1/.easyhg").arg(home);
Chris@240 284 QString extpath = QString("%1/easyhg.py").arg(target);
Chris@240 285 return extpath;
Chris@240 286 }
Chris@240 287
Chris@239 288 void
Chris@239 289 SettingsDialog::findExtension()
Chris@239 290 {
Chris@239 291 QSettings settings;
Chris@239 292 settings.beginGroup("Locations");
Chris@239 293
Chris@239 294 QString extpath = settings.value("extensionpath", "").toString();
Chris@239 295 if (extpath != "" || !QFile(extpath).exists()) {
Chris@239 296
Chris@240 297 extpath = getUnbundledExtensionFileName();
Chris@239 298
Chris@239 299 if (!QFile(extpath).exists()) {
Chris@239 300 extpath = findInPath("easyhg.py", m_installPath, false);
Chris@239 301 }
Chris@239 302 }
Chris@239 303
Chris@239 304 settings.setValue("extensionpath", extpath);
Chris@239 305 }
Chris@239 306
Chris@239 307 void
Chris@239 308 SettingsDialog::findDiffBinaryName()
Chris@239 309 {
Chris@239 310 QSettings settings;
Chris@239 311 settings.beginGroup("Locations");
Chris@239 312 QString diff = settings.value("extdiffbinary", "").toString();
Chris@465 313 if (diff != "" && QFile(diff).exists()) {
Chris@465 314 return;
Chris@465 315 }
Chris@465 316 QStringList bases;
Chris@272 317 #ifdef Q_OS_WIN32
Chris@465 318 bases << "easyhg-extdiff.bat";
Chris@272 319 #else
Chris@465 320 bases << "easyhg-extdiff.sh";
Chris@272 321 #endif
Chris@465 322 bases << "kompare" << "kdiff3" << "meld";
Chris@465 323 bool found = false;
Chris@465 324 foreach (QString base, bases) {
Chris@465 325 diff = findInPath(base, m_installPath, true);
Chris@465 326 if (diff != "") {
Chris@465 327 found = true;
Chris@465 328 break;
Chris@239 329 }
Chris@465 330 }
Chris@465 331 if (found) {
Chris@465 332 settings.setValue("extdiffbinary", diff);
Chris@239 333 }
Chris@239 334 }
Chris@239 335
Chris@239 336 void
Chris@239 337 SettingsDialog::findMergeBinaryName()
Chris@239 338 {
Chris@239 339 QSettings settings;
Chris@239 340 settings.beginGroup("Locations");
Chris@465 341 QString merge = settings.value("mergebinary", "").toString();
Chris@465 342 if (merge != "" && QFile(merge).exists()) {
Chris@239 343 return;
Chris@239 344 }
Chris@239 345 QStringList bases;
Chris@272 346 #ifdef Q_OS_WIN32
Chris@272 347 bases << "easyhg-merge.bat";
Chris@272 348 #else
Chris@269 349 bases << "easyhg-merge.sh";
Chris@272 350 #endif
Chris@269 351 // NB it's not a good idea to add other tools here, as command
Chris@269 352 // line argument ordering varies. Configure them through hgrc
Chris@269 353 // instead
Chris@239 354 bool found = false;
Chris@239 355 foreach (QString base, bases) {
Chris@239 356 merge = findInPath(base, m_installPath, true);
Chris@239 357 if (merge != "") {
Chris@239 358 found = true;
Chris@239 359 break;
Chris@239 360 }
Chris@239 361 }
Chris@239 362 if (found) {
Chris@239 363 settings.setValue("mergebinary", merge);
Chris@239 364 }
Chris@239 365 }
Chris@239 366
Chris@239 367 void
chris@406 368 SettingsDialog::findSshBinaryName()
chris@406 369 {
chris@406 370 QSettings settings;
chris@406 371 settings.beginGroup("Locations");
Chris@465 372 QString ssh = settings.value("sshbinary", "").toString();
Chris@465 373 if (ssh != "" && QFile(ssh).exists()) {
chris@406 374 return;
chris@406 375 }
chris@406 376 QStringList bases;
chris@406 377 #ifdef Q_OS_WIN32
chris@406 378 bases << "TortoisePlink.exe";
chris@406 379 #else
chris@406 380 bases << "ssh";
chris@406 381 #endif
chris@406 382 bool found = false;
chris@406 383 foreach (QString base, bases) {
chris@406 384 ssh = findInPath(base, m_installPath, true);
chris@406 385 if (ssh != "") {
chris@406 386 found = true;
chris@406 387 break;
chris@406 388 }
chris@406 389 }
chris@406 390 if (found) {
chris@406 391 settings.setValue("sshbinary", ssh);
chris@406 392 }
chris@406 393 }
chris@406 394
chris@406 395 void
Chris@239 396 SettingsDialog::clear()
Chris@239 397 {
Chris@239 398 // Clear everything that has a default setting
Chris@239 399 DEBUG << "SettingsDialog::clear" << endl;
Chris@239 400 QSettings settings;
Chris@239 401 settings.beginGroup("Presentation");
Chris@239 402 settings.remove("showiconlabels");
Chris@239 403 settings.remove("showhelpfultext");
Chris@466 404 settings.remove("dateformat");
Chris@239 405 settings.endGroup();
Chris@239 406 settings.beginGroup("Locations");
Chris@239 407 settings.remove("hgbinary");
Chris@239 408 settings.remove("extdiffbinary");
Chris@239 409 settings.remove("mergebinary");
chris@406 410 settings.remove("sshbinary");
Chris@239 411 settings.remove("extensionpath");
Chris@239 412 settings.endGroup();
Chris@484 413 settings.beginGroup("");
Chris@239 414 settings.remove("useextension");
Chris@239 415 settings.endGroup();
Chris@239 416 }
Chris@239 417
Chris@239 418 void
Chris@239 419 SettingsDialog::reset()
Chris@239 420 {
Chris@239 421 DEBUG << "SettingsDialog::reset" << endl;
Chris@239 422 QSettings settings;
Chris@239 423 settings.beginGroup("User Information");
Chris@239 424 m_nameEdit->setText(settings.value("name", getUserRealName()).toString());
Chris@239 425 m_emailEdit->setText(settings.value("email").toString());
Chris@239 426 settings.endGroup();
Chris@239 427 settings.beginGroup("Presentation");
Chris@239 428 m_showIconLabels->setChecked(settings.value("showiconlabels", true).toBool());
Chris@239 429 m_showExtraText->setChecked(settings.value("showhelpfultext", true).toBool());
Chris@273 430 #ifdef NOT_IMPLEMENTED_YET
Chris@273 431 m_workHistoryArrangement->setCurrentIndex(settings.value("workhistoryarrangement", 0).toInt());
Chris@273 432 #endif
Chris@273 433 m_dateFormat->setCurrentIndex(settings.value("dateformat", 0).toInt());
Chris@239 434 settings.endGroup();
Chris@239 435 settings.beginGroup("Locations");
Chris@239 436 m_hgPathLabel->setText(settings.value("hgbinary").toString());
Chris@239 437 m_diffPathLabel->setText(settings.value("extdiffbinary").toString());
Chris@239 438 m_mergePathLabel->setText(settings.value("mergebinary").toString());
chris@406 439 m_sshPathLabel->setText(settings.value("sshbinary").toString());
Chris@239 440 m_extensionPathLabel->setText(settings.value("extensionpath").toString());
Chris@239 441 settings.endGroup();
Chris@484 442 settings.beginGroup("");
Chris@239 443 m_useExtension->setChecked(settings.value("useextension", true).toBool());
Chris@239 444 settings.endGroup();
Chris@239 445 }
Chris@239 446
Chris@239 447 void
Chris@175 448 SettingsDialog::accept()
Chris@175 449 {
Chris@177 450 DEBUG << "SettingsDialog::accept" << endl;
Chris@175 451 QSettings settings;
Chris@175 452 settings.beginGroup("User Information");
Chris@175 453 settings.setValue("name", m_nameEdit->text());
Chris@175 454 settings.setValue("email", m_emailEdit->text());
Chris@175 455 settings.endGroup();
Chris@230 456 settings.beginGroup("Presentation");
Chris@230 457 bool b;
Chris@230 458 b = m_showIconLabels->isChecked();
Chris@230 459 if (b != settings.value("showiconlabels", true)) {
Chris@230 460 settings.setValue("showiconlabels", b);
Chris@230 461 m_presentationChanged = true;
Chris@230 462 }
Chris@230 463 b = m_showExtraText->isChecked();
Chris@230 464 if (b != settings.value("showhelpfultext", true)) {
Chris@230 465 settings.setValue("showhelpfultext", b);
Chris@230 466 m_presentationChanged = true;
Chris@230 467 }
Chris@273 468 int i;
Chris@273 469 #ifdef NOT_IMPLEMENTED_YET
Chris@273 470 i = m_workHistoryArrangement->currentIndex();
Chris@273 471 if (i != settings.value("workhistoryarrangement", 0)) {
Chris@273 472 settings.setValue("workhistoryarrangement", i);
Chris@273 473 m_presentationChanged = true;
Chris@273 474 }
Chris@273 475 #endif
Chris@273 476 i = m_dateFormat->currentIndex();
Chris@273 477 if (i != settings.value("dateformat", 0)) {
Chris@273 478 settings.setValue("dateformat", i);
Chris@273 479 m_presentationChanged = true;
Chris@273 480 }
Chris@230 481 settings.endGroup();
Chris@175 482 settings.beginGroup("Locations");
Chris@181 483 settings.setValue("hgbinary", m_hgPathLabel->text());
Chris@181 484 settings.setValue("extdiffbinary", m_diffPathLabel->text());
Chris@181 485 settings.setValue("mergebinary", m_mergePathLabel->text());
chris@406 486 settings.setValue("sshbinary", m_sshPathLabel->text());
Chris@181 487 settings.setValue("extensionpath", m_extensionPathLabel->text());
Chris@176 488 settings.endGroup();
Chris@484 489 settings.beginGroup("");
Chris@176 490 settings.setValue("useextension", m_useExtension->isChecked());
Chris@175 491 settings.endGroup();
Chris@175 492 QDialog::accept();
Chris@175 493 }
Chris@175 494
Chris@175 495