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@419: QStringList files, Chris@419: QStringList suffixes, Chris@419: QString directory) 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@419: QString textTheseFiles; Chris@419: QString textTheseNames; Chris@419: if (files.size() > 1) { Chris@419: textTheseFiles = tr("Ignore these files only"); Chris@419: textTheseNames = tr("Ignore files with these names, in any folder"); Chris@419: } else { Chris@419: textTheseFiles = tr("Ignore this file only"); Chris@419: textTheseNames = tr("Ignore files with the same name as this, in any folder"); Chris@419: } Chris@414: Chris@419: QString textThisFolder; Chris@419: QString textTheseSuffixes; Chris@414: Chris@419: QStringList options; Chris@419: options << textTheseFiles; Chris@419: options << textTheseNames; Chris@414: Chris@419: if (directory != "") { Chris@419: textThisFolder = tr("Ignore the whole folder \"%1\"") Chris@419: .arg(directory); Chris@419: options << textThisFolder; Chris@419: } Chris@415: Chris@419: if (suffixes.size() > 1) { Chris@415: Chris@419: textTheseSuffixes = tr("Ignore all files with these extensions:\n%1") Chris@419: .arg(suffixes.join(", ")); Chris@419: options << textTheseSuffixes; Chris@415: Chris@419: } else if (suffixes.size() > 0) { Chris@415: Chris@419: textTheseSuffixes = tr("Ignore all files with the extension \"%1\"") Chris@419: .arg(suffixes[0]); Chris@419: options << textTheseSuffixes; Chris@419: } Chris@419: Chris@419: HgIgnoreDialog d(parent, tr("Ignore files"), Chris@419: intro, tr("

Please choose whether to:

"), Chris@419: options, tr("Ignore")); Chris@419: Chris@419: if (d.exec() == QDialog::Accepted) { Chris@419: QString option = d.getOption(); Chris@419: DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl; Chris@419: if (option == textTheseFiles) return IgnoreGivenFilesOnly; Chris@419: else if (option == textTheseNames) return IgnoreAllFilesOfGivenNames; Chris@419: else if (option == textTheseSuffixes) return IgnoreAllFilesOfGivenSuffixes; Chris@419: else if (option == textThisFolder) return IgnoreWholeDirectory; Chris@419: } Chris@414: Chris@414: return IgnoreNothing; Chris@414: } Chris@414: