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