Chris@175: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@175: Chris@175: /* Chris@175: EasyMercurial Chris@175: Chris@175: Based on HgExplorer by Jari Korhonen Chris@175: Copyright (c) 2010 Jari Korhonen Chris@560: Copyright (c) 2012 Chris Cannam Chris@560: Copyright (c) 2012 Queen Mary, University of London Chris@175: Chris@175: This program is free software; you can redistribute it and/or Chris@175: modify it under the terms of the GNU General Public License as Chris@175: published by the Free Software Foundation; either version 2 of the Chris@175: License, or (at your option) any later version. See the file Chris@175: COPYING included with this distribution for more information. Chris@175: */ Chris@175: Chris@175: #include "settingsdialog.h" Chris@175: #include "common.h" Chris@177: #include "debug.h" Chris@175: Chris@175: #include Chris@175: #include Chris@175: #include Chris@175: #include Chris@181: #include Chris@181: #include Chris@273: #include Chris@466: #include Chris@175: Chris@239: QString Chris@239: SettingsDialog::m_installPath; Chris@239: Chris@175: SettingsDialog::SettingsDialog(QWidget *parent) : Chris@230: QDialog(parent), Chris@230: m_presentationChanged(false) Chris@175: { Chris@175: setModal(true); Chris@175: setWindowTitle(tr("Settings")); Chris@175: Chris@175: QGridLayout *mainLayout = new QGridLayout; Chris@175: setLayout(mainLayout); Chris@175: Chris@472: m_tabs = new QTabWidget; Chris@472: mainLayout->addWidget(m_tabs, 0, 0); Chris@230: Chris@230: Chris@466: // QGroupBox *meBox = new QGroupBox(tr("User details")); Chris@466: // mainLayout->addWidget(meBox, 0, 0); Chris@466: Chris@466: QWidget *meBox = new QWidget; Chris@472: m_tabs->addTab(meBox, tr("User details")); Chris@466: Chris@175: QGridLayout *meLayout = new QGridLayout; Chris@175: meBox->setLayout(meLayout); Chris@175: Chris@175: int row = 0; Chris@175: Chris@175: meLayout->addWidget(new QLabel(tr("Name:")), row, 0); Chris@175: Chris@175: m_nameEdit = new QLineEdit(); Chris@175: meLayout->addWidget(m_nameEdit, row++, 1); Chris@175: Chris@175: meLayout->addWidget(new QLabel(tr("Email address:")), row, 0); Chris@175: Chris@175: m_emailEdit = new QLineEdit(); Chris@175: meLayout->addWidget(m_emailEdit, row++, 1); Chris@175: Chris@466: meLayout->setRowStretch(row, 20); Chris@230: Chris@230: Chris@466: // QGroupBox *lookBox = new QGroupBox(tr("Presentation")); Chris@466: // mainLayout->addWidget(lookBox, 1, 0); Chris@466: Chris@466: QWidget *lookBox = new QWidget; Chris@472: m_tabs->addTab(lookBox, tr("Presentation")); Chris@466: Chris@230: QGridLayout *lookLayout = new QGridLayout; Chris@230: lookBox->setLayout(lookLayout); Chris@230: Chris@230: row = 0; Chris@230: Chris@230: m_showIconLabels = new QCheckBox(tr("Show labels on toolbar icons")); Chris@273: lookLayout->addWidget(m_showIconLabels, row++, 0, 1, 2); Chris@230: Chris@230: m_showExtraText = new QCheckBox(tr("Show long descriptions for file status headings")); Chris@273: lookLayout->addWidget(m_showExtraText, row++, 0, 1, 2); Chris@273: Chris@273: #ifdef NOT_IMPLEMENTED_YET Chris@273: lookLayout->addWidget(new QLabel(tr("Place the work and history views")), row, 0); Chris@273: m_workHistoryArrangement = new QComboBox(); Chris@273: m_workHistoryArrangement->addItem(tr("In separate tabs")); Chris@273: m_workHistoryArrangement->addItem(tr("Side-by-side in a single pane")); Chris@273: lookLayout->addWidget(m_workHistoryArrangement, row++, 1, Qt::AlignLeft); Chris@273: lookLayout->setColumnStretch(1, 20); Chris@273: #endif Chris@230: Chris@273: lookLayout->addWidget(new QLabel(tr("Label the history timeline with")), row, 0); Chris@273: m_dateFormat = new QComboBox(); Chris@273: m_dateFormat->addItem(tr("Ages, for example \"5 weeks ago\"")); Chris@273: m_dateFormat->addItem(tr("Dates, for example \"2010-06-23\"")); Chris@273: lookLayout->addWidget(m_dateFormat, row++, 1, Qt::AlignLeft); Chris@273: lookLayout->setColumnStretch(1, 20); Chris@466: Chris@466: lookLayout->setRowStretch(row, 20); Chris@273: Chris@230: Chris@466: QWidget *pathsBox = new QWidget; Chris@472: m_tabs->addTab(pathsBox, tr("System application locations")); Chris@466: Chris@466: // QGroupBox *pathsBox = new QGroupBox(tr("System application locations")); Chris@466: // mainLayout->addWidget(pathsBox, 2, 0); Chris@175: QGridLayout *pathsLayout = new QGridLayout; Chris@175: pathsBox->setLayout(pathsLayout); Chris@175: Chris@175: row = 0; Chris@175: Chris@175: pathsLayout->addWidget(new QLabel(tr("Mercurial (hg) program:")), row, 0); Chris@175: Chris@195: m_hgPathLabel = new QLineEdit(); Chris@181: pathsLayout->addWidget(m_hgPathLabel, row, 2); Chris@175: Chris@175: QPushButton *browse = new QPushButton(tr("Browse...")); Chris@181: pathsLayout->addWidget(browse, row++, 1); Chris@175: connect(browse, SIGNAL(clicked()), this, SLOT(hgPathBrowse())); Chris@175: Chris@175: pathsLayout->addWidget(new QLabel(tr("External diff program:")), row, 0); Chris@175: Chris@195: m_diffPathLabel = new QLineEdit(); Chris@181: pathsLayout->addWidget(m_diffPathLabel, row, 2); Chris@175: Chris@175: browse = new QPushButton(tr("Browse...")); Chris@181: pathsLayout->addWidget(browse, row++, 1); Chris@175: connect(browse, SIGNAL(clicked()), this, SLOT(diffPathBrowse())); Chris@178: Chris@175: pathsLayout->addWidget(new QLabel(tr("External file-merge program:")), row, 0); Chris@175: Chris@195: m_mergePathLabel = new QLineEdit(); Chris@181: pathsLayout->addWidget(m_mergePathLabel, row, 2); Chris@175: Chris@175: browse = new QPushButton(tr("Browse...")); Chris@181: pathsLayout->addWidget(browse, row++, 1); Chris@175: connect(browse, SIGNAL(clicked()), this, SLOT(mergePathBrowse())); Chris@175: chris@406: pathsLayout->addWidget(new QLabel(tr("SSH program (for ssh URLs):")), row, 0); chris@406: chris@406: m_sshPathLabel = new QLineEdit(); chris@406: pathsLayout->addWidget(m_sshPathLabel, row, 2); chris@406: chris@406: browse = new QPushButton(tr("Browse...")); chris@406: pathsLayout->addWidget(browse, row++, 1); chris@406: connect(browse, SIGNAL(clicked()), this, SLOT(sshPathBrowse())); chris@406: Chris@176: pathsLayout->addWidget(new QLabel(tr("EasyHg Mercurial extension:")), row, 0); Chris@176: Chris@195: m_extensionPathLabel = new QLineEdit(); Chris@181: pathsLayout->addWidget(m_extensionPathLabel, row, 2); Chris@176: Chris@176: browse = new QPushButton(tr("Browse...")); Chris@181: pathsLayout->addWidget(browse, row++, 1); Chris@176: connect(browse, SIGNAL(clicked()), this, SLOT(extensionPathBrowse())); Chris@176: Chris@176: //!!! more info plz Chris@176: m_useExtension = new QCheckBox(tr("Use EasyHg Mercurial extension")); Chris@181: pathsLayout->addWidget(m_useExtension, row++, 2); Chris@176: Chris@466: pathsLayout->setRowStretch(row, 20); Chris@466: Chris@176: Chris@239: reset(); // loads current defaults from settings Chris@175: Chris@230: Chris@175: QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok); Chris@239: connect(bbox->addButton(tr("Restore defaults"), QDialogButtonBox::ResetRole), Chris@239: SIGNAL(clicked()), this, SLOT(restoreDefaults())); Chris@175: connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); Chris@230: mainLayout->addWidget(bbox, 3, 0); Chris@175: m_ok = bbox->button(QDialogButtonBox::Ok); Chris@175: } Chris@175: Chris@175: void Chris@472: SettingsDialog::setCurrentTab(Tab t) Chris@472: { Chris@472: switch (t) { Chris@472: case PersonalDetailsTab: m_tabs->setCurrentIndex(0); break; Chris@472: case PresentationTab: m_tabs->setCurrentIndex(1); break; Chris@472: case PathsTab: m_tabs->setCurrentIndex(2); break; Chris@472: } Chris@472: } Chris@472: Chris@472: void Chris@175: SettingsDialog::hgPathBrowse() Chris@175: { Chris@181: browseFor(tr("Mercurial program"), m_hgPathLabel); Chris@175: } Chris@175: Chris@175: void Chris@175: SettingsDialog::diffPathBrowse() Chris@175: { Chris@181: browseFor(tr("External diff program"), m_diffPathLabel); Chris@175: } Chris@175: Chris@175: void Chris@175: SettingsDialog::mergePathBrowse() Chris@175: { Chris@181: browseFor(tr("External file-merge program"), m_mergePathLabel); Chris@175: } Chris@175: Chris@175: void chris@406: SettingsDialog::sshPathBrowse() chris@406: { chris@406: browseFor(tr("SSH program"), m_sshPathLabel); chris@406: } chris@406: chris@406: void Chris@176: SettingsDialog::extensionPathBrowse() Chris@176: { Chris@181: browseFor(tr("EasyHg Mercurial extension"), m_extensionPathLabel); Chris@181: } Chris@181: Chris@181: void Chris@195: SettingsDialog::browseFor(QString title, QLineEdit *edit) Chris@181: { Chris@181: QString origin = edit->text(); Chris@181: Chris@181: if (origin == "") { Chris@181: #ifdef Q_OS_WIN32 Chris@181: origin = "c:"; Chris@181: #else Chris@181: origin = QDir::homePath(); Chris@181: #endif Chris@181: } Chris@181: Chris@181: QString path = QFileDialog::getOpenFileName(this, title, origin); Chris@181: if (path != QString()) { Chris@181: edit->setText(path); Chris@181: } Chris@176: } Chris@176: Chris@176: void Chris@239: SettingsDialog::restoreDefaults() Chris@239: { Chris@273: if (QMessageBox::question Chris@273: (this, tr("Restore default settings?"), Chris@273: tr("Restore default settings?

Are you sure you want to reset all settings to their default values?"), Chris@273: QMessageBox::Ok | QMessageBox::Cancel, Chris@273: QMessageBox::Cancel) == QMessageBox::Ok) { Chris@273: clear(); Chris@273: findDefaultLocations(); Chris@273: reset(); Chris@273: } Chris@239: } Chris@239: Chris@239: void Chris@239: SettingsDialog::findDefaultLocations(QString installPath) Chris@239: { Chris@239: m_installPath = installPath; Chris@239: findHgBinaryName(); Chris@239: findExtension(); Chris@239: findDiffBinaryName(); Chris@239: findMergeBinaryName(); chris@406: findSshBinaryName(); Chris@239: } Chris@239: Chris@239: void Chris@239: SettingsDialog::findHgBinaryName() Chris@239: { Chris@239: QSettings settings; Chris@239: settings.beginGroup("Locations"); Chris@239: QString hg = settings.value("hgbinary", "").toString(); Chris@611: if (hg == "" || !QFile(hg).exists()) { Chris@239: hg = findInPath("hg", m_installPath, true); Chris@239: } Chris@239: if (hg != "") { Chris@239: settings.setValue("hgbinary", hg); Chris@239: } Chris@239: } Chris@239: Chris@240: QString Chris@240: SettingsDialog::getUnbundledExtensionFileName() Chris@240: { Chris@240: QString home = QDir::homePath(); Chris@240: QString target = QString("%1/.easyhg").arg(home); Chris@240: QString extpath = QString("%1/easyhg.py").arg(target); Chris@240: return extpath; Chris@240: } Chris@240: Chris@239: void Chris@239: SettingsDialog::findExtension() Chris@239: { Chris@239: QSettings settings; Chris@239: settings.beginGroup("Locations"); Chris@239: Chris@239: QString extpath = settings.value("extensionpath", "").toString(); Chris@239: if (extpath != "" || !QFile(extpath).exists()) { Chris@239: Chris@240: extpath = getUnbundledExtensionFileName(); Chris@239: Chris@239: if (!QFile(extpath).exists()) { Chris@239: extpath = findInPath("easyhg.py", m_installPath, false); Chris@239: } Chris@239: } Chris@239: Chris@239: settings.setValue("extensionpath", extpath); Chris@239: } Chris@239: Chris@239: void Chris@239: SettingsDialog::findDiffBinaryName() Chris@239: { Chris@239: QSettings settings; Chris@239: settings.beginGroup("Locations"); Chris@239: QString diff = settings.value("extdiffbinary", "").toString(); Chris@465: if (diff != "" && QFile(diff).exists()) { Chris@465: return; Chris@465: } Chris@465: QStringList bases; Chris@272: #ifdef Q_OS_WIN32 Chris@465: bases << "easyhg-extdiff.bat"; Chris@272: #else Chris@465: bases << "easyhg-extdiff.sh"; Chris@272: #endif Chris@465: bases << "kompare" << "kdiff3" << "meld"; Chris@465: bool found = false; Chris@465: foreach (QString base, bases) { Chris@465: diff = findInPath(base, m_installPath, true); Chris@465: if (diff != "") { Chris@465: found = true; Chris@465: break; Chris@239: } Chris@465: } Chris@465: if (found) { Chris@465: settings.setValue("extdiffbinary", diff); Chris@239: } Chris@239: } Chris@239: Chris@239: void Chris@239: SettingsDialog::findMergeBinaryName() Chris@239: { Chris@239: QSettings settings; Chris@239: settings.beginGroup("Locations"); Chris@465: QString merge = settings.value("mergebinary", "").toString(); Chris@465: if (merge != "" && QFile(merge).exists()) { Chris@239: return; Chris@239: } Chris@239: QStringList bases; Chris@272: #ifdef Q_OS_WIN32 Chris@272: bases << "easyhg-merge.bat"; Chris@272: #else Chris@269: bases << "easyhg-merge.sh"; Chris@272: #endif Chris@269: // NB it's not a good idea to add other tools here, as command Chris@269: // line argument ordering varies. Configure them through hgrc Chris@269: // instead Chris@239: bool found = false; Chris@239: foreach (QString base, bases) { Chris@239: merge = findInPath(base, m_installPath, true); Chris@239: if (merge != "") { Chris@239: found = true; Chris@239: break; Chris@239: } Chris@239: } Chris@239: if (found) { Chris@239: settings.setValue("mergebinary", merge); Chris@239: } Chris@239: } Chris@239: Chris@239: void chris@406: SettingsDialog::findSshBinaryName() chris@406: { chris@406: QSettings settings; chris@406: settings.beginGroup("Locations"); Chris@465: QString ssh = settings.value("sshbinary", "").toString(); Chris@465: if (ssh != "" && QFile(ssh).exists()) { chris@406: return; chris@406: } chris@406: QStringList bases; chris@406: #ifdef Q_OS_WIN32 chris@406: bases << "TortoisePlink.exe"; chris@406: #else chris@406: bases << "ssh"; chris@406: #endif chris@406: bool found = false; chris@406: foreach (QString base, bases) { chris@406: ssh = findInPath(base, m_installPath, true); chris@406: if (ssh != "") { chris@406: found = true; chris@406: break; chris@406: } chris@406: } chris@406: if (found) { chris@406: settings.setValue("sshbinary", ssh); chris@406: } chris@406: } chris@406: chris@406: void Chris@239: SettingsDialog::clear() Chris@239: { Chris@239: // Clear everything that has a default setting Chris@239: DEBUG << "SettingsDialog::clear" << endl; Chris@239: QSettings settings; Chris@239: settings.beginGroup("Presentation"); Chris@239: settings.remove("showiconlabels"); Chris@239: settings.remove("showhelpfultext"); Chris@466: settings.remove("dateformat"); Chris@239: settings.endGroup(); Chris@239: settings.beginGroup("Locations"); Chris@239: settings.remove("hgbinary"); Chris@239: settings.remove("extdiffbinary"); Chris@239: settings.remove("mergebinary"); chris@406: settings.remove("sshbinary"); Chris@239: settings.remove("extensionpath"); Chris@239: settings.endGroup(); Chris@484: settings.beginGroup(""); Chris@239: settings.remove("useextension"); Chris@239: settings.endGroup(); Chris@239: } Chris@239: Chris@239: void Chris@239: SettingsDialog::reset() Chris@239: { Chris@239: DEBUG << "SettingsDialog::reset" << endl; Chris@239: QSettings settings; Chris@239: settings.beginGroup("User Information"); Chris@239: m_nameEdit->setText(settings.value("name", getUserRealName()).toString()); Chris@239: m_emailEdit->setText(settings.value("email").toString()); Chris@239: settings.endGroup(); Chris@239: settings.beginGroup("Presentation"); Chris@239: m_showIconLabels->setChecked(settings.value("showiconlabels", true).toBool()); Chris@239: m_showExtraText->setChecked(settings.value("showhelpfultext", true).toBool()); Chris@273: #ifdef NOT_IMPLEMENTED_YET Chris@273: m_workHistoryArrangement->setCurrentIndex(settings.value("workhistoryarrangement", 0).toInt()); Chris@273: #endif Chris@273: m_dateFormat->setCurrentIndex(settings.value("dateformat", 0).toInt()); Chris@239: settings.endGroup(); Chris@239: settings.beginGroup("Locations"); Chris@239: m_hgPathLabel->setText(settings.value("hgbinary").toString()); Chris@239: m_diffPathLabel->setText(settings.value("extdiffbinary").toString()); Chris@239: m_mergePathLabel->setText(settings.value("mergebinary").toString()); chris@406: m_sshPathLabel->setText(settings.value("sshbinary").toString()); Chris@239: m_extensionPathLabel->setText(settings.value("extensionpath").toString()); Chris@239: settings.endGroup(); Chris@484: settings.beginGroup(""); Chris@239: m_useExtension->setChecked(settings.value("useextension", true).toBool()); Chris@239: settings.endGroup(); Chris@239: } Chris@239: Chris@239: void Chris@175: SettingsDialog::accept() Chris@175: { Chris@177: DEBUG << "SettingsDialog::accept" << endl; Chris@175: QSettings settings; Chris@175: settings.beginGroup("User Information"); Chris@175: settings.setValue("name", m_nameEdit->text()); Chris@175: settings.setValue("email", m_emailEdit->text()); Chris@175: settings.endGroup(); Chris@230: settings.beginGroup("Presentation"); Chris@230: bool b; Chris@230: b = m_showIconLabels->isChecked(); Chris@230: if (b != settings.value("showiconlabels", true)) { Chris@230: settings.setValue("showiconlabels", b); Chris@230: m_presentationChanged = true; Chris@230: } Chris@230: b = m_showExtraText->isChecked(); Chris@230: if (b != settings.value("showhelpfultext", true)) { Chris@230: settings.setValue("showhelpfultext", b); Chris@230: m_presentationChanged = true; Chris@230: } Chris@273: int i; Chris@273: #ifdef NOT_IMPLEMENTED_YET Chris@273: i = m_workHistoryArrangement->currentIndex(); Chris@273: if (i != settings.value("workhistoryarrangement", 0)) { Chris@273: settings.setValue("workhistoryarrangement", i); Chris@273: m_presentationChanged = true; Chris@273: } Chris@273: #endif Chris@273: i = m_dateFormat->currentIndex(); Chris@273: if (i != settings.value("dateformat", 0)) { Chris@273: settings.setValue("dateformat", i); Chris@273: m_presentationChanged = true; Chris@273: } Chris@230: settings.endGroup(); Chris@175: settings.beginGroup("Locations"); Chris@181: settings.setValue("hgbinary", m_hgPathLabel->text()); Chris@181: settings.setValue("extdiffbinary", m_diffPathLabel->text()); Chris@181: settings.setValue("mergebinary", m_mergePathLabel->text()); chris@406: settings.setValue("sshbinary", m_sshPathLabel->text()); Chris@181: settings.setValue("extensionpath", m_extensionPathLabel->text()); Chris@176: settings.endGroup(); Chris@484: settings.beginGroup(""); Chris@176: settings.setValue("useextension", m_useExtension->isChecked()); Chris@175: settings.endGroup(); Chris@175: QDialog::accept(); Chris@175: } Chris@175: Chris@175: