Chris@102: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@102: Chris@102: /* Chris@102: EasyMercurial Chris@102: Chris@102: Based on hgExplorer by Jari Korhonen Chris@102: Copyright (c) 2010 Jari Korhonen Chris@102: Copyright (c) 2010 Chris Cannam Chris@102: Copyright (c) 2010 Queen Mary, University of London Chris@102: Chris@102: This program is free software; you can redistribute it and/or Chris@102: modify it under the terms of the GNU General Public License as Chris@102: published by the Free Software Foundation; either version 2 of the Chris@102: License, or (at your option) any later version. See the file Chris@102: COPYING included with this distribution for more information. Chris@102: */ Chris@102: Chris@102: #include "confirmcommentdialog.h" Chris@109: #include "common.h" Chris@102: Chris@102: #include Chris@102: #include Chris@104: #include Chris@104: #include Chris@104: #include Chris@104: #include Chris@102: Chris@105: ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent, Chris@105: QString title, Chris@105: QString introText, Chris@105: QString initialComment) : Chris@105: QDialog(parent) Chris@105: { Chris@105: setWindowTitle(title); Chris@105: Chris@105: QGridLayout *layout = new QGridLayout; Chris@105: setLayout(layout); Chris@105: QLabel *label = new QLabel(introText); Chris@105: layout->addWidget(label, 0, 0); Chris@105: Chris@105: m_textEdit = new QTextEdit; Chris@105: m_textEdit->setAcceptRichText(false); Chris@105: m_textEdit->document()->setPlainText(initialComment); Chris@105: m_textEdit->setMinimumWidth(360); Chris@105: connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(commentChanged())); Chris@105: layout->addWidget(m_textEdit, 1, 0); Chris@105: Chris@105: QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | Chris@105: QDialogButtonBox::Cancel); Chris@105: layout->addWidget(bbox, 2, 0); Chris@105: m_ok = bbox->button(QDialogButtonBox::Ok); Chris@105: m_ok->setEnabled(initialComment != ""); Chris@105: Chris@105: connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); Chris@105: connect(bbox, SIGNAL(rejected()), this, SLOT(reject())); Chris@105: } Chris@105: Chris@105: void ConfirmCommentDialog::commentChanged() Chris@105: { Chris@105: m_ok->setEnabled(getComment() != ""); Chris@105: } Chris@105: Chris@105: QString ConfirmCommentDialog::getComment() const Chris@105: { Chris@105: return m_textEdit->document()->toPlainText(); Chris@105: } Chris@105: Chris@109: QString ConfirmCommentDialog::buildFilesText(QString intro, QStringList files) Chris@109: { Chris@109: QString text; Chris@109: text = "" + intro; Chris@109: text += "

"; Chris@109: foreach (QString file, files) { Chris@109: text += "   " + xmlEncode(file) + "
"; Chris@109: } Chris@109: text += "
"; Chris@109: return text; Chris@109: } Chris@109: Chris@102: bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent, Chris@102: QString title, Chris@102: QString introText, Chris@102: QString introTextWithCount, Chris@102: QStringList files) Chris@102: { Chris@102: QString text; Chris@102: if (files.size() <= 10) { Chris@109: text = buildFilesText(introText, files); Chris@102: } else { Chris@109: text = "" + introTextWithCount.arg(files.size()) + ""; Chris@102: } Chris@102: return (QMessageBox::information(parent, Chris@102: title, Chris@102: text, Chris@102: QMessageBox::Ok | QMessageBox::Cancel, Chris@102: QMessageBox::Ok) Chris@102: == QMessageBox::Ok); Chris@102: } Chris@102: Chris@109: bool ConfirmCommentDialog::confirmDangerousFilesAction(QWidget *parent, Chris@109: QString title, Chris@109: QString introText, Chris@109: QString introTextWithCount, Chris@109: QStringList files) Chris@109: { Chris@109: QString text; Chris@109: if (files.size() <= 10) { Chris@109: text = buildFilesText(introText, files); Chris@109: } else { Chris@109: text = "" + introTextWithCount.arg(files.size()) + ""; Chris@109: } Chris@109: return (QMessageBox::warning(parent, Chris@109: title, Chris@109: text, Chris@109: QMessageBox::Ok | QMessageBox::Cancel, Chris@109: QMessageBox::Cancel) Chris@109: == QMessageBox::Ok); Chris@109: } Chris@109: Chris@109: bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, Chris@109: QString title, Chris@109: QString introText, Chris@109: QString introTextWithCount, Chris@109: QStringList files, Chris@109: QString &comment) Chris@109: { Chris@109: return confirmAndComment(parent, title, introText, Chris@109: introTextWithCount, files, comment, false); Chris@109: } Chris@109: Chris@109: bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, Chris@109: QString title, Chris@109: QString introText, Chris@109: QString introTextWithCount, Chris@109: QStringList files, Chris@109: QString &comment) Chris@109: { Chris@109: return confirmAndComment(parent, title, introText, Chris@109: introTextWithCount, files, comment, true); Chris@109: } Chris@109: Chris@102: bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, Chris@102: QString title, Chris@102: QString introText, Chris@102: QString introTextWithCount, Chris@102: QStringList files, Chris@104: QString &comment, Chris@104: bool longComment) Chris@102: { Chris@102: QString text; Chris@102: if (files.size() <= 10) { Chris@109: text = buildFilesText(introText, files); Chris@102: } else { Chris@109: text = "" + introTextWithCount.arg(files.size()); Chris@102: } Chris@109: text += tr("

Please enter your comment:"); Chris@104: return confirmAndComment(parent, title, text, comment, longComment); Chris@102: } Chris@102: Chris@109: bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, Chris@109: QString title, Chris@109: QString introText, Chris@109: QString &comment) Chris@109: { Chris@109: return confirmAndComment(parent, title, introText, comment, false); Chris@109: } Chris@109: Chris@109: bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, Chris@109: QString title, Chris@109: QString introText, Chris@109: QString &comment) Chris@109: { Chris@109: return confirmAndComment(parent, title, introText, comment, true); Chris@109: } Chris@109: Chris@102: bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, Chris@102: QString title, Chris@102: QString introText, Chris@104: QString &comment, Chris@104: bool longComment) Chris@102: { Chris@102: bool ok = false; Chris@104: if (!longComment) { Chris@104: comment = QInputDialog::getText(parent, title, introText, Chris@104: QLineEdit::Normal, comment, &ok); Chris@104: } else { Chris@105: ConfirmCommentDialog *d = new ConfirmCommentDialog(parent, Chris@105: title, Chris@105: introText, Chris@105: comment); Chris@104: if (d->exec() == QDialog::Accepted) { Chris@105: comment = d->getComment(); Chris@104: ok = true; Chris@104: } Chris@104: } Chris@102: return ok; Chris@102: }