Debian Codegraph @

src/textDialog.cpp

raw symbols SCIP
1 /* ---------------------------------- textDialog.cpp --------------------------------------------------------------------------
2 Class to display a simple go-noGo dialog
3
4 ===============================================================================================================================
5 ===============================================================================================================================
6 This file is part of "luckyBackup" project
7 Copyright, Loukas Avgeriou
8 luckyBackup is distributed under the terms of the GNU General Public License
9 luckyBackup is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 luckyBackup is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with luckyBackup. If not, see <http://www.gnu.org/licenses/>.
21
22
23 project version : Please see "main.cpp" for project version
24
25 developer : luckyb
26 last modified : 22 May 2016
27
28 ===============================================================================================================================
29 ===============================================================================================================================
30 */
31
32 #include "textDialog.h"
33
34 #include <QClipboard>
35
36 #include "global.h"
37
38 // class textDialog Constructor=================================================================================================
39 // Displays a simple dialog with text info, ok-cancel buttons and a lineEdit for user input
40 textDialog::textDialog (const QString type, const QString ReplaceInput, QWidget *parent) : QDialog (parent)
41 {
42 uiT.setupUi(this);
43 uiT.checkBox_select -> setVisible(false);
44 uiT.label_warning -> setVisible(false);
45 uiT.textEdit_userInput -> setVisible(false);
46
47 //connect okay & cancel pushButton SLOTs ----------------
48 connect ( uiT.pushButton_ok, SIGNAL( clicked() ), this, SLOT( okay() ) );
49 connect ( uiT.pushButton_cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
50
51 GoOn = 0;
52 Type = type;
53 TextPassed = ReplaceInput;
54 if (type == "NewProfile")
55 {
56 uiT.label_message -> setText(tr("Enter the name of the new profile :"));
57 uiT.lineEdit_userInput -> setEchoMode (QLineEdit::Normal);
58 }
59 if (type == "RenameProfile")
60 {
61 uiT.label_message -> setText(tr("Enter the new name of the profile :"));
62 uiT.lineEdit_userInput -> setEchoMode (QLineEdit::Normal);
63 uiT.lineEdit_userInput -> setText(ReplaceInput);
64 uiT.lineEdit_userInput -> selectAll();
65 }
66 if (type == "ProfileDescription")
67 {
68 uiT.lineEdit_userInput -> setVisible(false);
69 uiT.textEdit_userInput -> setVisible(true);
70 this -> resize(640, 480);
71 uiT.label_message -> setText(tr("Profile description :"));
72 uiT.textEdit_userInput -> setPlainText(ReplaceInput);
73 uiT.textEdit_userInput -> selectAll();
74 }
75 if (type == "ImportProfile")
76 {
77 uiT.label_message -> setText(tr("A profile with the same name already exists") + "<br>" +
78 tr("Please enter a different name"));
79 uiT.lineEdit_userInput -> setEchoMode (QLineEdit::Normal);
80 uiT.lineEdit_userInput -> setText(ReplaceInput);
81 uiT.lineEdit_userInput -> selectAll();
82 }
83 if (type == "password")
84 {
85 uiT.label_message -> setText(tr("Enter password :"));
86 uiT.lineEdit_userInput -> setEchoMode (QLineEdit::Password);
87 }
88 if (type == "passphrase")
89 {
90 uiT.label_message -> setText(tr("Enter passphrase :"));
91 uiT.lineEdit_userInput -> setEchoMode (QLineEdit::Password);
92 }
93 if (type == "CloneWarning")
94 {
95 uiT.checkBox_select -> setVisible(true);
96 uiT.label_warning -> setVisible(true);
97 uiT.checkBox_select -> setText (tr("Do not show this again for this task"));
98 uiT.lineEdit_userInput -> setVisible(false);
99 uiT.label_message -> setText(tr("You have selected to \"Backup the contents of the source directory\"<br>together with the \"delete files on the destination\" option") +"<br><br>" + tr("BEWARE, if your intention is NOT to clone source to destination !!") +"<br><br>" +
100 tr("Are you sure you wish to proceed ??") + "<br><br>");
101 resize(sizeHint());
102 }
103 if (type == "ValidateDialog")
104 {
105 uiT.lineEdit_userInput -> setVisible(false);
106 uiT.label_warning -> setVisible(true);
107 uiT.label_warning -> setPixmap(QPixmap(":/luckyPrefix/validate.png"));
108 uiT.pushButton_cancel -> setText(tr("Copy command to clipboard"));
109 uiT.pushButton_cancel -> setIcon(QIcon(":/luckyPrefix/copy.png"));
110 uiT.label_message -> setText(ReplaceInput);
111 resize(sizeHint());
112 }
113 if (type == "ViewCurrentCrontab")
114 {
115 this -> resize(640, 480);
116 uiT.lineEdit_userInput -> setVisible(false);
117 uiT.pushButton_cancel -> setVisible(false);
118 uiT.label_message -> setText(ReplaceInput);
119 }
120 if (type == "emailOutput")
121 {
122 uiT.lineEdit_userInput -> setVisible(false);
123 uiT.textEdit_userInput -> setVisible(true);
124 this -> resize(640, 480);
125 uiT.label_message -> setText(tr("eMail information"));
126 uiT.textEdit_userInput -> setPlainText(ReplaceInput);
127 uiT.textEdit_userInput -> setReadOnly(true);
128 uiT.pushButton_cancel -> setVisible(false);
129 }
130
131 // The next are used instead of standard Qt dialogs for translation reasons
132 if (type == "QtInformation")
133 {
134 uiT.lineEdit_userInput -> setVisible(false);
135 uiT.label_warning -> setVisible(true);
136 uiT.label_warning -> setPixmap(QPixmap(":/luckyPrefix/validate.png"));
137 uiT.label_message -> setText(ReplaceInput);
138
139 uiT.pushButton_cancel -> setVisible(false);
140 resize(sizeHint());
141 }
142 if (type == "QtWarning")
143 {
144 uiT.lineEdit_userInput -> setVisible(false);
145 uiT.label_warning -> setVisible(true);
146 uiT.label_warning -> setPixmap(QPixmap(":/luckyPrefix/warning.png"));
147 uiT.label_message -> setText(ReplaceInput);
148
149 uiT.pushButton_cancel -> setVisible(false);
150 resize(sizeHint());
151 }
152 if (type == "QtCritical")
153 {
154 uiT.lineEdit_userInput -> setVisible(false);
155 uiT.label_warning -> setVisible(true);
156 uiT.label_warning -> setPixmap(QPixmap(":/luckyPrefix/cancel.png"));
157 uiT.label_message -> setText(ReplaceInput);
158
159 uiT.pushButton_cancel -> setVisible(false);
160 resize(sizeHint());
161 }
162 if (type == "QtQuestion")
163 {
164 uiT.lineEdit_userInput -> setVisible(false);
165 uiT.label_warning -> setVisible(true);
166 uiT.label_warning -> setPixmap(QPixmap(":/luckyPrefix/about.png"));
167 uiT.label_message -> setText(ReplaceInput);
168
169 uiT.pushButton_cancel -> setText(tr("No"));
170 uiT.pushButton_ok -> setText(tr("Yes"));
171 resize(sizeHint());
172 }
173 }
174 // SLOTS-------------------------------------------------------------------------------------
175 // --------------------------------okay pressed------------------------------------------------
176 void textDialog::okay()
177 {
178 GoOn = 1;
179 userInput = uiT.lineEdit_userInput -> text();
180
181 // Do not perform any further actions for the following categories:
182 if ((Type == "password") || (Type == "passphrase"))
183 {
184 close();
185 return;
186 }
187 if (Type == "ProfileDescription")
188 {
189 userInput = uiT.textEdit_userInput -> toPlainText();
190 close();
191 return;
192 }
193
194 //remove trailing or starting whitespaces and invalid characters
195 QStringList invalid;
196 invalid << "`" << "!" << "@" << "#" << "$" << "%" << "%" << "^" << "&" << "*" << "(" << ")" << "+" << "=" << "{" << "[" << "}"
197 << "]" << ":" << ";" << "\"" << "'" << "|" << "\\" << "<" << "," << ">" << "?" << "/";
198 for (int count=0; count<invalid.size(); ++count)
199 userInput.replace(invalid.at(count),"");
200
201 while ( (userInput.endsWith(" ")) || (userInput.endsWith(".")) )
202 userInput.chop(1);
203 while ( (userInput.startsWith(".")) || (userInput.startsWith(" ")) )
204 userInput.remove(0,1);
205
206 if (userInput == "")
207 GoOn = 2;
208
209 if (userInput == profileName)
210 GoOn = 3;
211
212 if (uiT.checkBox_select -> isChecked()) //"Do not show this again check box
213 GoOn = 4;
214 close();
215 }
216 // --------------------------------cancel pressed------------------------------------------------
217 void textDialog::cancel()
218 {
219 //GoOn == 0
220 if (Type == "ValidateDialog")
221 {
222 QString source, dest, Command_Clipboard;
223
224 //copy command to clipboard
225 TextPassed = TextPassed.right(TextPassed.size()-TextPassed.indexOf("<font color=red>")); //remove all irrelevant text
226 source = TextPassed.right(TextPassed.size()-TextPassed.indexOf("<font color=magenta>")); //copy source & dest inside QString source
227 TextPassed.remove(source); //remove source & dest from whole command
228 dest = source.right(source.size()-source.lastIndexOf("<font color=magenta>")); //copy dest inside QString dest
229 source.remove(dest); //remove dest from source
230
231 source.remove("<font color=magenta>",Qt::CaseSensitive);
232 source.remove("</font>",Qt::CaseSensitive);
233 source.remove("<br>",Qt::CaseSensitive);
234 if (source.endsWith(" "))
235 source.chop(1);
236 source.replace(" ","\\ "); //replace whitespaces with " \"
237
238 dest.remove("<font color=magenta>",Qt::CaseSensitive);
239 dest.remove("</font>",Qt::CaseSensitive);
240 dest.remove("<br>",Qt::CaseSensitive);
241 dest.replace(" ","\\ ");
242
243 Command_Clipboard = TextPassed + source + " " + dest;
244 Command_Clipboard.remove("<font color=red>",Qt::CaseSensitive);
245 Command_Clipboard.remove("<font color=blue>",Qt::CaseSensitive);
246 Command_Clipboard.remove("</font>",Qt::CaseSensitive);
247 Command_Clipboard.remove("<br>",Qt::CaseSensitive);
248
249 QClipboard *clipboard = QApplication::clipboard();
250 clipboard->setText(Command_Clipboard);
251 }
252 else
253 close();
254 }
255
256 void textDialog::closeEvent(QCloseEvent *event)
257 {
258 event->accept();
259 }
260 // --------------------------------accessors-----------------------------------
261 int textDialog::getGoOn()
262 {
263 return GoOn ;
264 }
265 QString textDialog::getUserInput()
266 {
267 return userInput;
268 }
269
270 // end of textDialog.cpp ---------------------------------------------------------------------------
271