Chris@102
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@102
|
2
|
Chris@102
|
3 /*
|
Chris@102
|
4 EasyMercurial
|
Chris@102
|
5
|
Chris@102
|
6 Based on hgExplorer by Jari Korhonen
|
Chris@102
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@102
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@102
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@102
|
10
|
Chris@102
|
11 This program is free software; you can redistribute it and/or
|
Chris@102
|
12 modify it under the terms of the GNU General Public License as
|
Chris@102
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@102
|
14 License, or (at your option) any later version. See the file
|
Chris@102
|
15 COPYING included with this distribution for more information.
|
Chris@102
|
16 */
|
Chris@102
|
17
|
Chris@102
|
18 #include "confirmcommentdialog.h"
|
Chris@109
|
19 #include "common.h"
|
Chris@102
|
20
|
Chris@102
|
21 #include <QMessageBox>
|
Chris@102
|
22 #include <QInputDialog>
|
Chris@104
|
23 #include <QGridLayout>
|
Chris@104
|
24 #include <QLabel>
|
Chris@104
|
25 #include <QTextEdit>
|
Chris@104
|
26 #include <QDialogButtonBox>
|
Chris@102
|
27
|
Chris@105
|
28 ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent,
|
Chris@105
|
29 QString title,
|
Chris@105
|
30 QString introText,
|
Chris@105
|
31 QString initialComment) :
|
Chris@105
|
32 QDialog(parent)
|
Chris@105
|
33 {
|
Chris@105
|
34 setWindowTitle(title);
|
Chris@105
|
35
|
Chris@105
|
36 QGridLayout *layout = new QGridLayout;
|
Chris@105
|
37 setLayout(layout);
|
Chris@105
|
38 QLabel *label = new QLabel(introText);
|
Chris@105
|
39 layout->addWidget(label, 0, 0);
|
Chris@105
|
40
|
Chris@105
|
41 m_textEdit = new QTextEdit;
|
Chris@105
|
42 m_textEdit->setAcceptRichText(false);
|
Chris@105
|
43 m_textEdit->document()->setPlainText(initialComment);
|
Chris@105
|
44 m_textEdit->setMinimumWidth(360);
|
Chris@105
|
45 connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(commentChanged()));
|
Chris@105
|
46 layout->addWidget(m_textEdit, 1, 0);
|
Chris@105
|
47
|
Chris@105
|
48 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
Chris@105
|
49 QDialogButtonBox::Cancel);
|
Chris@105
|
50 layout->addWidget(bbox, 2, 0);
|
Chris@105
|
51 m_ok = bbox->button(QDialogButtonBox::Ok);
|
Chris@105
|
52 m_ok->setEnabled(initialComment != "");
|
Chris@105
|
53
|
Chris@105
|
54 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@105
|
55 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
|
Chris@105
|
56 }
|
Chris@105
|
57
|
Chris@105
|
58 void ConfirmCommentDialog::commentChanged()
|
Chris@105
|
59 {
|
Chris@105
|
60 m_ok->setEnabled(getComment() != "");
|
Chris@105
|
61 }
|
Chris@105
|
62
|
Chris@105
|
63 QString ConfirmCommentDialog::getComment() const
|
Chris@105
|
64 {
|
Chris@105
|
65 return m_textEdit->document()->toPlainText();
|
Chris@105
|
66 }
|
Chris@105
|
67
|
Chris@109
|
68 QString ConfirmCommentDialog::buildFilesText(QString intro, QStringList files)
|
Chris@109
|
69 {
|
Chris@109
|
70 QString text;
|
Chris@109
|
71 text = "<qt>" + intro;
|
Chris@109
|
72 text += "<p><code>";
|
Chris@109
|
73 foreach (QString file, files) {
|
Chris@109
|
74 text += " " + xmlEncode(file) + "<br>";
|
Chris@109
|
75 }
|
Chris@109
|
76 text += "</code></qt>";
|
Chris@109
|
77 return text;
|
Chris@109
|
78 }
|
Chris@109
|
79
|
Chris@102
|
80 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent,
|
Chris@102
|
81 QString title,
|
Chris@102
|
82 QString introText,
|
Chris@102
|
83 QString introTextWithCount,
|
Chris@102
|
84 QStringList files)
|
Chris@102
|
85 {
|
Chris@102
|
86 QString text;
|
Chris@102
|
87 if (files.size() <= 10) {
|
Chris@109
|
88 text = buildFilesText(introText, files);
|
Chris@102
|
89 } else {
|
Chris@109
|
90 text = "<qt>" + introTextWithCount.arg(files.size()) + "</qt>";
|
Chris@102
|
91 }
|
Chris@102
|
92 return (QMessageBox::information(parent,
|
Chris@102
|
93 title,
|
Chris@102
|
94 text,
|
Chris@102
|
95 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@102
|
96 QMessageBox::Ok)
|
Chris@102
|
97 == QMessageBox::Ok);
|
Chris@102
|
98 }
|
Chris@102
|
99
|
Chris@109
|
100 bool ConfirmCommentDialog::confirmDangerousFilesAction(QWidget *parent,
|
Chris@109
|
101 QString title,
|
Chris@109
|
102 QString introText,
|
Chris@109
|
103 QString introTextWithCount,
|
Chris@109
|
104 QStringList files)
|
Chris@109
|
105 {
|
Chris@109
|
106 QString text;
|
Chris@109
|
107 if (files.size() <= 10) {
|
Chris@109
|
108 text = buildFilesText(introText, files);
|
Chris@109
|
109 } else {
|
Chris@109
|
110 text = "<qt>" + introTextWithCount.arg(files.size()) + "</qt>";
|
Chris@109
|
111 }
|
Chris@109
|
112 return (QMessageBox::warning(parent,
|
Chris@109
|
113 title,
|
Chris@109
|
114 text,
|
Chris@109
|
115 QMessageBox::Ok | QMessageBox::Cancel,
|
Chris@109
|
116 QMessageBox::Cancel)
|
Chris@109
|
117 == QMessageBox::Ok);
|
Chris@109
|
118 }
|
Chris@109
|
119
|
Chris@109
|
120 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent,
|
Chris@109
|
121 QString title,
|
Chris@109
|
122 QString introText,
|
Chris@109
|
123 QString introTextWithCount,
|
Chris@109
|
124 QStringList files,
|
Chris@109
|
125 QString &comment)
|
Chris@109
|
126 {
|
Chris@109
|
127 return confirmAndComment(parent, title, introText,
|
Chris@109
|
128 introTextWithCount, files, comment, false);
|
Chris@109
|
129 }
|
Chris@109
|
130
|
Chris@109
|
131 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent,
|
Chris@109
|
132 QString title,
|
Chris@109
|
133 QString introText,
|
Chris@109
|
134 QString introTextWithCount,
|
Chris@109
|
135 QStringList files,
|
Chris@109
|
136 QString &comment)
|
Chris@109
|
137 {
|
Chris@109
|
138 return confirmAndComment(parent, title, introText,
|
Chris@109
|
139 introTextWithCount, files, comment, true);
|
Chris@109
|
140 }
|
Chris@109
|
141
|
Chris@102
|
142 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
143 QString title,
|
Chris@102
|
144 QString introText,
|
Chris@102
|
145 QString introTextWithCount,
|
Chris@102
|
146 QStringList files,
|
Chris@104
|
147 QString &comment,
|
Chris@104
|
148 bool longComment)
|
Chris@102
|
149 {
|
Chris@102
|
150 QString text;
|
Chris@102
|
151 if (files.size() <= 10) {
|
Chris@109
|
152 text = buildFilesText(introText, files);
|
Chris@102
|
153 } else {
|
Chris@109
|
154 text = "<qt>" + introTextWithCount.arg(files.size());
|
Chris@102
|
155 }
|
Chris@109
|
156 text += tr("<p>Please enter your comment:</qt>");
|
Chris@104
|
157 return confirmAndComment(parent, title, text, comment, longComment);
|
Chris@102
|
158 }
|
Chris@102
|
159
|
Chris@109
|
160 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent,
|
Chris@109
|
161 QString title,
|
Chris@109
|
162 QString introText,
|
Chris@109
|
163 QString &comment)
|
Chris@109
|
164 {
|
Chris@109
|
165 return confirmAndComment(parent, title, introText, comment, false);
|
Chris@109
|
166 }
|
Chris@109
|
167
|
Chris@109
|
168 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent,
|
Chris@109
|
169 QString title,
|
Chris@109
|
170 QString introText,
|
Chris@109
|
171 QString &comment)
|
Chris@109
|
172 {
|
Chris@109
|
173 return confirmAndComment(parent, title, introText, comment, true);
|
Chris@109
|
174 }
|
Chris@109
|
175
|
Chris@102
|
176 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
177 QString title,
|
Chris@102
|
178 QString introText,
|
Chris@104
|
179 QString &comment,
|
Chris@104
|
180 bool longComment)
|
Chris@102
|
181 {
|
Chris@102
|
182 bool ok = false;
|
Chris@104
|
183 if (!longComment) {
|
Chris@104
|
184 comment = QInputDialog::getText(parent, title, introText,
|
Chris@104
|
185 QLineEdit::Normal, comment, &ok);
|
Chris@104
|
186 } else {
|
Chris@105
|
187 ConfirmCommentDialog *d = new ConfirmCommentDialog(parent,
|
Chris@105
|
188 title,
|
Chris@105
|
189 introText,
|
Chris@105
|
190 comment);
|
Chris@104
|
191 if (d->exec() == QDialog::Accepted) {
|
Chris@105
|
192 comment = d->getComment();
|
Chris@104
|
193 ok = true;
|
Chris@104
|
194 }
|
Chris@104
|
195 }
|
Chris@102
|
196 return ok;
|
Chris@102
|
197 }
|