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@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 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@419
|
20 #include "debug.h"
|
Chris@102
|
21
|
Chris@102
|
22 #include <QMessageBox>
|
Chris@102
|
23 #include <QInputDialog>
|
Chris@104
|
24 #include <QGridLayout>
|
Chris@104
|
25 #include <QLabel>
|
Chris@104
|
26 #include <QTextEdit>
|
Chris@104
|
27 #include <QDialogButtonBox>
|
Chris@102
|
28
|
Chris@105
|
29 ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent,
|
Chris@105
|
30 QString title,
|
Chris@105
|
31 QString introText,
|
Chris@193
|
32 QString initialComment,
|
Chris@193
|
33 QString okButtonText) :
|
Chris@105
|
34 QDialog(parent)
|
Chris@105
|
35 {
|
Chris@105
|
36 setWindowTitle(title);
|
Chris@105
|
37
|
Chris@105
|
38 QGridLayout *layout = new QGridLayout;
|
Chris@105
|
39 setLayout(layout);
|
Chris@105
|
40 QLabel *label = new QLabel(introText);
|
Chris@237
|
41 label->setWordWrap(true);
|
Chris@105
|
42 layout->addWidget(label, 0, 0);
|
Chris@105
|
43
|
Chris@105
|
44 m_textEdit = new QTextEdit;
|
Chris@105
|
45 m_textEdit->setAcceptRichText(false);
|
Chris@105
|
46 m_textEdit->document()->setPlainText(initialComment);
|
Chris@105
|
47 m_textEdit->setMinimumWidth(360);
|
Chris@105
|
48 connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(commentChanged()));
|
Chris@105
|
49 layout->addWidget(m_textEdit, 1, 0);
|
Chris@105
|
50
|
Chris@105
|
51 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
Chris@105
|
52 QDialogButtonBox::Cancel);
|
Chris@105
|
53 layout->addWidget(bbox, 2, 0);
|
Chris@105
|
54 m_ok = bbox->button(QDialogButtonBox::Ok);
|
Chris@275
|
55 m_ok->setDefault(true);
|
Chris@105
|
56 m_ok->setEnabled(initialComment != "");
|
Chris@193
|
57 m_ok->setText(okButtonText);
|
Chris@275
|
58 bbox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);
|
Chris@105
|
59
|
Chris@105
|
60 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@105
|
61 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
|
Chris@105
|
62 }
|
Chris@105
|
63
|
Chris@105
|
64 void ConfirmCommentDialog::commentChanged()
|
Chris@105
|
65 {
|
Chris@105
|
66 m_ok->setEnabled(getComment() != "");
|
Chris@105
|
67 }
|
Chris@105
|
68
|
Chris@105
|
69 QString ConfirmCommentDialog::getComment() const
|
Chris@105
|
70 {
|
Chris@419
|
71 /*
|
Chris@419
|
72 DEBUG << "ConfirmCommentDialog: as html is:" << endl;
|
Chris@419
|
73 DEBUG << m_textEdit->document()->toHtml() << endl;
|
Chris@419
|
74 DEBUG << "ConfirmCommentDialog: as plain text is:" << endl;
|
Chris@419
|
75 QString t = m_textEdit->document()->toPlainText();
|
Chris@419
|
76 DEBUG << t << endl;
|
Chris@419
|
77 DEBUG << "Characters: " << endl;
|
Chris@419
|
78 for (int i = 0; i < t.length(); ++i) DEBUG << t[i].unicode();
|
Chris@419
|
79 DEBUG << endl;
|
Chris@419
|
80 return t;
|
Chris@419
|
81 */
|
Chris@105
|
82 }
|
Chris@105
|
83
|
Chris@109
|
84 QString ConfirmCommentDialog::buildFilesText(QString intro, QStringList files)
|
Chris@109
|
85 {
|
Chris@109
|
86 QString text;
|
Chris@298
|
87
|
Chris@298
|
88 if (intro == "") text = "<qt>";
|
Chris@298
|
89 else text = "<qt>" + intro + "<p>";
|
Chris@298
|
90
|
Chris@298
|
91 text += "<code>";
|
Chris@109
|
92 foreach (QString file, files) {
|
Chris@109
|
93 text += " " + xmlEncode(file) + "<br>";
|
Chris@109
|
94 }
|
Chris@109
|
95 text += "</code></qt>";
|
Chris@298
|
96
|
Chris@109
|
97 return text;
|
Chris@109
|
98 }
|
Chris@109
|
99
|
Chris@193
|
100 bool ConfirmCommentDialog::confirm(QWidget *parent,
|
Chris@193
|
101 QString title,
|
Chris@298
|
102 QString head,
|
Chris@193
|
103 QString text,
|
Chris@193
|
104 QString okButtonText)
|
Chris@193
|
105 {
|
Chris@193
|
106 QMessageBox box(QMessageBox::Question,
|
Chris@193
|
107 title,
|
Chris@298
|
108 head,
|
Chris@193
|
109 QMessageBox::Cancel,
|
Chris@193
|
110 parent);
|
Chris@193
|
111
|
Chris@298
|
112 box.setInformativeText(text);
|
Chris@298
|
113
|
Chris@193
|
114 QPushButton *ok = box.addButton(QMessageBox::Ok);
|
Chris@193
|
115 ok->setText(okButtonText);
|
Chris@275
|
116 box.setDefaultButton(QMessageBox::Ok);
|
Chris@194
|
117 if (box.exec() == -1) return false;
|
Chris@194
|
118 return box.standardButton(box.clickedButton()) == QMessageBox::Ok;
|
Chris@193
|
119 }
|
Chris@193
|
120
|
Chris@193
|
121 bool ConfirmCommentDialog::confirmDangerous(QWidget *parent,
|
Chris@193
|
122 QString title,
|
Chris@298
|
123 QString head,
|
Chris@193
|
124 QString text,
|
Chris@193
|
125 QString okButtonText)
|
Chris@193
|
126 {
|
Chris@193
|
127 QMessageBox box(QMessageBox::Warning,
|
Chris@193
|
128 title,
|
Chris@298
|
129 head,
|
Chris@193
|
130 QMessageBox::Cancel,
|
Chris@193
|
131 parent);
|
Chris@193
|
132
|
Chris@298
|
133 box.setInformativeText(text);
|
Chris@298
|
134
|
Chris@193
|
135 QPushButton *ok = box.addButton(QMessageBox::Ok);
|
Chris@193
|
136 ok->setText(okButtonText);
|
Chris@275
|
137 box.setDefaultButton(QMessageBox::Cancel);
|
Chris@194
|
138 if (box.exec() == -1) return false;
|
Chris@194
|
139 return box.standardButton(box.clickedButton()) == QMessageBox::Ok;
|
Chris@193
|
140 }
|
Chris@193
|
141
|
Chris@102
|
142 bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent,
|
Chris@102
|
143 QString title,
|
Chris@102
|
144 QString introText,
|
Chris@102
|
145 QString introTextWithCount,
|
Chris@193
|
146 QStringList files,
|
Chris@193
|
147 QString okButtonText)
|
Chris@102
|
148 {
|
Chris@102
|
149 QString text;
|
Chris@102
|
150 if (files.size() <= 10) {
|
Chris@109
|
151 text = buildFilesText(introText, files);
|
Chris@102
|
152 } else {
|
Chris@155
|
153 text = "<qt>" + introTextWithCount + "</qt>";
|
Chris@102
|
154 }
|
Chris@298
|
155 return confirm(parent, title, text, "", okButtonText);
|
Chris@102
|
156 }
|
Chris@102
|
157
|
Chris@109
|
158 bool ConfirmCommentDialog::confirmDangerousFilesAction(QWidget *parent,
|
Chris@109
|
159 QString title,
|
Chris@109
|
160 QString introText,
|
Chris@109
|
161 QString introTextWithCount,
|
Chris@193
|
162 QStringList files,
|
Chris@193
|
163 QString okButtonText)
|
Chris@109
|
164 {
|
Chris@109
|
165 QString text;
|
Chris@109
|
166 if (files.size() <= 10) {
|
Chris@109
|
167 text = buildFilesText(introText, files);
|
Chris@109
|
168 } else {
|
Chris@155
|
169 text = "<qt>" + introTextWithCount + "</qt>";
|
Chris@109
|
170 }
|
Chris@298
|
171 return confirmDangerous(parent, title, text, "", okButtonText);
|
Chris@109
|
172 }
|
Chris@109
|
173
|
Chris@109
|
174 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent,
|
Chris@109
|
175 QString title,
|
Chris@109
|
176 QString introText,
|
Chris@109
|
177 QString introTextWithCount,
|
Chris@109
|
178 QStringList files,
|
Chris@193
|
179 QString &comment,
|
Chris@193
|
180 QString okButtonText)
|
Chris@109
|
181 {
|
Chris@109
|
182 return confirmAndComment(parent, title, introText,
|
Chris@193
|
183 introTextWithCount, files, comment, false,
|
Chris@193
|
184 okButtonText);
|
Chris@109
|
185 }
|
Chris@109
|
186
|
Chris@109
|
187 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent,
|
Chris@109
|
188 QString title,
|
Chris@109
|
189 QString introText,
|
Chris@109
|
190 QString introTextWithCount,
|
Chris@109
|
191 QStringList files,
|
Chris@193
|
192 QString &comment,
|
Chris@193
|
193 QString okButtonText)
|
Chris@109
|
194 {
|
Chris@109
|
195 return confirmAndComment(parent, title, introText,
|
Chris@193
|
196 introTextWithCount, files, comment, true,
|
Chris@193
|
197 okButtonText);
|
Chris@109
|
198 }
|
Chris@109
|
199
|
Chris@102
|
200 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
201 QString title,
|
Chris@102
|
202 QString introText,
|
Chris@102
|
203 QString introTextWithCount,
|
Chris@102
|
204 QStringList files,
|
Chris@104
|
205 QString &comment,
|
Chris@193
|
206 bool longComment,
|
Chris@193
|
207 QString okButtonText)
|
Chris@102
|
208 {
|
Chris@102
|
209 QString text;
|
Chris@102
|
210 if (files.size() <= 10) {
|
Chris@109
|
211 text = buildFilesText(introText, files);
|
Chris@102
|
212 } else {
|
Chris@155
|
213 text = "<qt>" + introTextWithCount;
|
Chris@102
|
214 }
|
Chris@109
|
215 text += tr("<p>Please enter your comment:</qt>");
|
Chris@193
|
216 return confirmAndComment(parent, title, text, comment, longComment,
|
Chris@193
|
217 okButtonText);
|
Chris@102
|
218 }
|
Chris@102
|
219
|
Chris@109
|
220 bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent,
|
Chris@109
|
221 QString title,
|
Chris@109
|
222 QString introText,
|
Chris@193
|
223 QString &comment,
|
Chris@193
|
224 QString okButtonText)
|
Chris@109
|
225 {
|
Chris@193
|
226 return confirmAndComment(parent, title, introText, comment, false,
|
Chris@193
|
227 okButtonText);
|
Chris@109
|
228 }
|
Chris@109
|
229
|
Chris@109
|
230 bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent,
|
Chris@109
|
231 QString title,
|
Chris@109
|
232 QString introText,
|
Chris@193
|
233 QString &comment,
|
Chris@193
|
234 QString okButtonText)
|
Chris@109
|
235 {
|
Chris@193
|
236 return confirmAndComment(parent, title, introText, comment, true,
|
Chris@193
|
237 okButtonText);
|
Chris@109
|
238 }
|
Chris@109
|
239
|
Chris@102
|
240 bool ConfirmCommentDialog::confirmAndComment(QWidget *parent,
|
Chris@102
|
241 QString title,
|
Chris@102
|
242 QString introText,
|
Chris@104
|
243 QString &comment,
|
Chris@193
|
244 bool longComment,
|
Chris@193
|
245 QString okButtonText)
|
Chris@102
|
246 {
|
Chris@102
|
247 bool ok = false;
|
Chris@104
|
248 if (!longComment) {
|
Chris@193
|
249 QInputDialog d(parent);
|
Chris@193
|
250 d.setWindowTitle(title);
|
Chris@193
|
251 d.setLabelText(introText);
|
Chris@193
|
252 d.setTextValue(comment);
|
Chris@193
|
253 d.setOkButtonText(okButtonText);
|
Chris@193
|
254 d.setTextEchoMode(QLineEdit::Normal);
|
Chris@193
|
255 if (d.exec() == QDialog::Accepted) {
|
Chris@193
|
256 comment = d.textValue();
|
Chris@193
|
257 ok = true;
|
Chris@193
|
258 }
|
Chris@104
|
259 } else {
|
Chris@193
|
260 ConfirmCommentDialog d(parent, title, introText, comment, okButtonText);
|
Chris@193
|
261 if (d.exec() == QDialog::Accepted) {
|
Chris@193
|
262 comment = d.getComment();
|
Chris@104
|
263 ok = true;
|
Chris@104
|
264 }
|
Chris@104
|
265 }
|
Chris@193
|
266
|
Chris@102
|
267 return ok;
|
Chris@102
|
268 }
|