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