annotate src/hgignoredialog.cpp @ 598:5bf32465213c

Add script to pull out an i386-only build from the standard universal build -- it seems 10.5 users are getting the x86 one and it isn't working for them
author Chris Cannam
date Tue, 24 Apr 2012 16:55:26 +0100
parents 533519ebc0cb
children ae67ea0af696
rev   line source
Chris@414 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@414 2
Chris@414 3 /*
Chris@414 4 EasyMercurial
Chris@414 5
Chris@414 6 Based on hgExplorer by Jari Korhonen
Chris@414 7 Copyright (c) 2010 Jari Korhonen
Chris@560 8 Copyright (c) 2012 Chris Cannam
Chris@560 9 Copyright (c) 2012 Queen Mary, University of London
Chris@414 10
Chris@414 11 This program is free software; you can redistribute it and/or
Chris@414 12 modify it under the terms of the GNU General Public License as
Chris@414 13 published by the Free Software Foundation; either version 2 of the
Chris@414 14 License, or (at your option) any later version. See the file
Chris@414 15 COPYING included with this distribution for more information.
Chris@414 16 */
Chris@414 17
Chris@414 18 #include "hgignoredialog.h"
Chris@414 19 #include "common.h"
Chris@414 20 #include "debug.h"
Chris@414 21
Chris@415 22 #include <QGridLayout>
Chris@415 23 #include <QRadioButton>
Chris@415 24 #include <QLabel>
Chris@415 25 #include <QDialogButtonBox>
Chris@415 26 #include <QPushButton>
Chris@415 27
Chris@415 28 HgIgnoreDialog::HgIgnoreDialog(QWidget *parent,
Chris@415 29 QString title,
Chris@415 30 QString introText,
Chris@415 31 QString question,
Chris@415 32 QStringList options,
Chris@415 33 QString okButtonText) :
Chris@415 34 QDialog(parent)
Chris@415 35 {
Chris@415 36 setWindowTitle(title);
Chris@415 37
Chris@415 38 QGridLayout *layout = new QGridLayout;
Chris@415 39 setLayout(layout);
Chris@415 40
Chris@415 41 int row = 0;
Chris@415 42
Chris@415 43 QLabel *label = new QLabel(QString("%1%2").arg(introText).arg(question));
Chris@415 44 label->setWordWrap(true);
Chris@415 45 layout->addWidget(label, row++, 0, 1, 2);
Chris@415 46
Chris@415 47 if (!options.empty()) {
Chris@415 48 layout->addWidget(new QLabel(" "), row, 0);
Chris@415 49 layout->setColumnStretch(1, 10);
Chris@415 50 bool first = true;
Chris@415 51 foreach (QString option, options) {
Chris@415 52 QRadioButton *b = new QRadioButton(option);
Chris@415 53 layout->addWidget(b, row++, 1);
Chris@416 54 if (first) {
Chris@416 55 m_option = option;
Chris@416 56 b->setChecked(true);
Chris@416 57 first = false;
Chris@416 58 }
Chris@416 59 connect(b, SIGNAL(toggled(bool)), this, SLOT(optionToggled(bool)));
Chris@415 60 }
Chris@415 61 }
Chris@415 62
Chris@415 63 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@415 64 QDialogButtonBox::Cancel);
Chris@415 65 layout->addWidget(bbox, row++, 0, 1, 2);
Chris@415 66 bbox->button(QDialogButtonBox::Ok)->setDefault(true);
Chris@415 67 bbox->button(QDialogButtonBox::Ok)->setText(okButtonText);
Chris@415 68 bbox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);
Chris@415 69
Chris@415 70 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
Chris@415 71 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
Chris@415 72 }
Chris@415 73
Chris@416 74 void
Chris@416 75 HgIgnoreDialog::optionToggled(bool checked)
Chris@416 76 {
Chris@416 77 QObject *s = sender();
Chris@416 78 QRadioButton *rb = qobject_cast<QRadioButton *>(s);
Chris@416 79 if (rb && checked) {
Chris@416 80 m_option = rb->text();
Chris@416 81 }
Chris@416 82 }
Chris@416 83
Chris@414 84 HgIgnoreDialog::IgnoreType
Chris@415 85 HgIgnoreDialog::confirmIgnore(QWidget *parent,
Chris@419 86 QStringList files,
Chris@419 87 QStringList suffixes,
Chris@419 88 QString directory)
Chris@414 89 {
Chris@415 90 QString intro = "<qt><h3>";
Chris@415 91 intro += tr("Ignore files");
Chris@415 92 intro += "</h3><p>";
Chris@414 93
Chris@414 94 if (files.size() < 10) {
Chris@415 95 intro += tr("You have asked to ignore the following files:</p><p>");
Chris@415 96 intro += "<code>&nbsp;&nbsp;&nbsp;"
Chris@415 97 + files.join("<br>&nbsp;&nbsp;&nbsp;") + "</code>";
Chris@414 98 } else {
Chris@415 99 intro += tr("You have asked to ignore %n file(s).", "", files.size());
Chris@414 100 }
Chris@414 101
Chris@415 102 intro += "</p></qt>";
Chris@415 103
Chris@419 104 QString textTheseFiles;
Chris@419 105 QString textTheseNames;
Chris@419 106 if (files.size() > 1) {
Chris@419 107 textTheseFiles = tr("Ignore these files only");
Chris@419 108 textTheseNames = tr("Ignore files with these names, in any folder");
Chris@419 109 } else {
Chris@419 110 textTheseFiles = tr("Ignore this file only");
Chris@419 111 textTheseNames = tr("Ignore files with the same name as this, in any folder");
Chris@419 112 }
Chris@414 113
Chris@419 114 QString textThisFolder;
Chris@419 115 QString textTheseSuffixes;
Chris@414 116
Chris@419 117 QStringList options;
Chris@419 118 options << textTheseFiles;
Chris@419 119 options << textTheseNames;
Chris@414 120
Chris@419 121 if (directory != "") {
Chris@419 122 textThisFolder = tr("Ignore the whole folder \"%1\"")
Chris@419 123 .arg(directory);
Chris@419 124 options << textThisFolder;
Chris@419 125 }
Chris@415 126
Chris@419 127 if (suffixes.size() > 1) {
Chris@415 128
Chris@419 129 textTheseSuffixes = tr("Ignore all files with these extensions:\n%1")
Chris@419 130 .arg(suffixes.join(", "));
Chris@419 131 options << textTheseSuffixes;
Chris@415 132
Chris@419 133 } else if (suffixes.size() > 0) {
Chris@415 134
Chris@419 135 textTheseSuffixes = tr("Ignore all files with the extension \"%1\"")
Chris@419 136 .arg(suffixes[0]);
Chris@419 137 options << textTheseSuffixes;
Chris@419 138 }
Chris@419 139
Chris@419 140 HgIgnoreDialog d(parent, tr("Ignore files"),
Chris@419 141 intro, tr("<p>Please choose whether to:</p>"),
Chris@419 142 options, tr("Ignore"));
Chris@419 143
Chris@419 144 if (d.exec() == QDialog::Accepted) {
Chris@419 145 QString option = d.getOption();
Chris@419 146 DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl;
Chris@419 147 if (option == textTheseFiles) return IgnoreGivenFilesOnly;
Chris@419 148 else if (option == textTheseNames) return IgnoreAllFilesOfGivenNames;
Chris@419 149 else if (option == textTheseSuffixes) return IgnoreAllFilesOfGivenSuffixes;
Chris@419 150 else if (option == textThisFolder) return IgnoreWholeDirectory;
Chris@419 151 }
Chris@414 152
Chris@414 153 return IgnoreNothing;
Chris@414 154 }
Chris@414 155