Chris@414: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@414: Chris@414: /* Chris@414: EasyMercurial Chris@414: Chris@414: Based on hgExplorer by Jari Korhonen Chris@414: Copyright (c) 2010 Jari Korhonen Chris@414: Copyright (c) 2011 Chris Cannam Chris@414: Copyright (c) 2011 Queen Mary, University of London Chris@414: Chris@414: This program is free software; you can redistribute it and/or Chris@414: modify it under the terms of the GNU General Public License as Chris@414: published by the Free Software Foundation; either version 2 of the Chris@414: License, or (at your option) any later version. See the file Chris@414: COPYING included with this distribution for more information. Chris@414: */ Chris@414: Chris@414: #include "hgignoredialog.h" Chris@414: #include "common.h" Chris@414: #include "debug.h" Chris@414: Chris@415: #include Chris@415: #include Chris@415: #include Chris@415: #include Chris@415: #include Chris@415: Chris@415: HgIgnoreDialog::HgIgnoreDialog(QWidget *parent, Chris@415: QString title, Chris@415: QString introText, Chris@415: QString question, Chris@415: QStringList options, Chris@415: QString okButtonText) : Chris@415: QDialog(parent) Chris@415: { Chris@415: setWindowTitle(title); Chris@415: Chris@415: QGridLayout *layout = new QGridLayout; Chris@415: setLayout(layout); Chris@415: Chris@415: int row = 0; Chris@415: Chris@415: QLabel *label = new QLabel(QString("%1%2").arg(introText).arg(question)); Chris@415: label->setWordWrap(true); Chris@415: layout->addWidget(label, row++, 0, 1, 2); Chris@415: Chris@415: if (!options.empty()) { Chris@415: layout->addWidget(new QLabel(" "), row, 0); Chris@415: layout->setColumnStretch(1, 10); Chris@415: bool first = true; Chris@415: foreach (QString option, options) { Chris@415: QRadioButton *b = new QRadioButton(option); Chris@415: layout->addWidget(b, row++, 1); Chris@416: if (first) { Chris@416: m_option = option; Chris@416: b->setChecked(true); Chris@416: first = false; Chris@416: } Chris@416: connect(b, SIGNAL(toggled(bool)), this, SLOT(optionToggled(bool))); Chris@415: } Chris@415: } Chris@415: Chris@415: QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | Chris@415: QDialogButtonBox::Cancel); Chris@415: layout->addWidget(bbox, row++, 0, 1, 2); Chris@415: bbox->button(QDialogButtonBox::Ok)->setDefault(true); Chris@415: bbox->button(QDialogButtonBox::Ok)->setText(okButtonText); Chris@415: bbox->button(QDialogButtonBox::Cancel)->setAutoDefault(false); Chris@415: Chris@415: connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); Chris@415: connect(bbox, SIGNAL(rejected()), this, SLOT(reject())); Chris@415: } Chris@415: Chris@416: void Chris@416: HgIgnoreDialog::optionToggled(bool checked) Chris@416: { Chris@416: QObject *s = sender(); Chris@416: QRadioButton *rb = qobject_cast(s); Chris@416: if (rb && checked) { Chris@416: m_option = rb->text(); Chris@416: } Chris@416: } Chris@416: Chris@414: HgIgnoreDialog::IgnoreType Chris@415: HgIgnoreDialog::confirmIgnore(QWidget *parent, Chris@415: QStringList files, QStringList suffixes) Chris@414: { Chris@415: QString intro = "

"; Chris@415: intro += tr("Ignore files"); Chris@415: intro += "

"; Chris@414: Chris@414: if (files.size() < 10) { Chris@415: intro += tr("You have asked to ignore the following files:

"); Chris@415: intro += "   " Chris@415: + files.join("
   ") + "
"; Chris@414: } else { Chris@415: intro += tr("You have asked to ignore %n file(s).", "", files.size()); Chris@414: } Chris@414: Chris@415: intro += "

"; Chris@415: Chris@414: if (suffixes.size() > 0) { Chris@414: Chris@415: QStringList options; Chris@415: options << tr("Ignore these files only"); Chris@415: options << tr("Ignore files with these names in any subdirectory"); Chris@414: Chris@415: if (suffixes.size() > 1) { Chris@415: options << tr("Ignore all files with these extensions:\n%1") Chris@415: .arg(suffixes.join(", ")); Chris@415: } else { Chris@415: options << tr("Ignore all files with the extension \"%1\"") Chris@415: .arg(suffixes[0]); Chris@415: } Chris@414: Chris@415: HgIgnoreDialog d(parent, tr("Ignore files"), Chris@415: intro, tr("

Please choose whether to:

"), Chris@415: options, tr("Ignore")); Chris@415: Chris@415: if (d.exec() == QDialog::Accepted) { Chris@416: QString option = d.getOption(); Chris@416: DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl; Chris@416: if (option == options[0]) return IgnoreGivenFilesOnly; Chris@416: else if (option == options[1]) return IgnoreAllFilesOfGivenNames; Chris@416: else return IgnoreAllFilesOfGivenSuffixes; Chris@415: } Chris@414: Chris@415: } else { Chris@415: Chris@415: QStringList options; Chris@415: options << tr("Ignore these files only"); Chris@415: options << tr("Ignore files with these names in any subdirectory"); Chris@415: Chris@415: HgIgnoreDialog d(parent, tr("Ignore files"), Chris@415: intro, tr("

Please choose whether to:

"), Chris@415: options, tr("Ignore")); Chris@415: Chris@415: if (d.exec() == QDialog::Accepted) { Chris@416: QString option = d.getOption(); Chris@416: DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl; Chris@416: if (option == options[0]) return IgnoreGivenFilesOnly; Chris@416: else return IgnoreAllFilesOfGivenNames; Chris@415: } Chris@415: } Chris@414: Chris@414: return IgnoreNothing; Chris@414: } Chris@414: