Debian Codegraph @

src/patternEditor.cpp

raw symbols SCIP
1 /* ---------------------------------- patternEditor.cpp ---------------------------------------------------------------------------
2 Displays the pattern editor
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 #include "patternEditor.h"
31
32 #include <QSignalMapper>
33 #include <QCloseEvent>
34 #include <QFileDialog>
35
36 #include "global.h"
37 #include "textDialog.h"
38
39 // class patternEditor Constructor=================================================================================================
40 // Displays the pattern editor dialog
41 patternEditor::patternEditor (QString sourceRoot, QWidget *parent) : QDialog (parent)
42 {
43 uiP.setupUi(this);
44 uiP.groupBox_name -> setEnabled (false);
45 uiP.checkBox_pathAbsolute -> setEnabled (false);
46 uiP.checkBox_pathAny -> setEnabled (false);
47 uiP.spinBox_pathDeeper -> setEnabled (false);
48 uiP.label_pathDeeper -> setEnabled (false);
49 uiP.toolButton_browseFile -> setVisible(false);
50 uiP.checkBox_pathAbsolute -> setVisible(false);
51 uiP.label_browse -> setText(tr("directory :"));
52
53 anchorSource="";
54 itsPattern = "no pattern defined yet";
55 SourceRoot = sourceRoot;
56 if (!SourceRoot.endsWith(SLASH))
57 {
58 anchorSource = sourceRoot.right(sourceRoot.size()-sourceRoot.lastIndexOf(SLASH));
59 SourceRoot.append(SLASH);
60 }
61 patternLine = "";
62
63 //connect okay & cancel pushButton SLOTs ----------------
64 connect ( uiP.pushButton_okay, SIGNAL( clicked() ), this, SLOT( okay() ) );
65 connect ( uiP.pushButton_cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
66 connect ( uiP.pushButton_reset, SIGNAL( clicked() ), this, SLOT( resetFileds() ) );
67
68 //Connect all toolButtons with the browse SLOT
69 //Map all the toolButton signals and transmit a different integer depending on the toolbutton
70 QSignalMapper *signalMapper = new QSignalMapper(this);
71 signalMapper -> setMapping ( uiP.toolButton_browseFile, 0 );
72 connect (uiP.toolButton_browseFile, SIGNAL (clicked() ), signalMapper , SLOT (map()));
73 signalMapper -> setMapping ( uiP.toolButton_browseDir, 1 );
74 connect (uiP.toolButton_browseDir, SIGNAL (clicked() ), signalMapper , SLOT (map()));
75 connect(signalMapper, SIGNAL(mapped( const int)), this, SLOT( browse( const int) ) );
76
77 // connect all actions to fill-in the pattern at the lineEdit
78 connect (uiP.radioButton_fileSpecific , SIGNAL(clicked(bool)), this, SLOT(fillPattern()));
79 connect (uiP.radioButton_directorySpecific , SIGNAL(clicked(bool)), this, SLOT(fillPattern()));
80 connect (uiP.radioButton_fileSet , SIGNAL(clicked(bool)), this, SLOT(fillPattern()));
81 connect (uiP.radioButton_directorySet , SIGNAL(clicked(bool)), this, SLOT(fillPattern()));
82 connect (uiP.lineEdit_browse , SIGNAL(textChanged(QString)), this, SLOT(fillPattern()));
83 connect (uiP.spinBox_pathDeeper , SIGNAL(valueChanged(int)), this, SLOT(fillPattern()));
84 connect (uiP.checkBox_directoryContents , SIGNAL(clicked(bool)), this, SLOT(fillPattern()));
85 connect (uiP.lineEdit_nameIsExactly , SIGNAL(textChanged(QString)), this, SLOT(fillPattern()));
86 connect (uiP.lineEdit_nameStartsWith , SIGNAL(textChanged(QString)), this, SLOT(fillPattern()));
87 connect (uiP.lineEdit_nameEndsWith , SIGNAL(textChanged(QString)), this, SLOT(fillPattern()));
88 connect (uiP.lineEdit_nameContains , SIGNAL(textChanged(QString)), this, SLOT(fillPattern()));
89 connect (uiP.radioButton_fileSpecific , SIGNAL(toggled(bool)), this, SLOT(fileRadioChanged()));
90 connect (uiP.checkBox_pathAny , SIGNAL(clicked(bool)), this, SLOT(fillPattern()));
91 connect (uiP.checkBox_pathAbsolute , SIGNAL(clicked(bool)), this, SLOT(fillPattern()));
92 }
93 // SLOTS-------------------------------------------------------------------------------------
94 // --------------------------------okay pressed------------------------------------------------
95 void patternEditor::okay()
96 {
97 itsPattern = uiP.lineEdit_patternFinal -> text();
98 close();
99 }
100 // --------------------------------cancel pressed------------------------------------------------
101 void patternEditor::cancel()
102 {
103 close();
104 }
105
106 void patternEditor::closeEvent(QCloseEvent *event)
107 {
108 event->accept();
109 }
110
111 // --------------------------------reset pressed------------------------------------------------
112 //reset all fields to default values
113 void patternEditor::resetFileds()
114 {
115 uiP.lineEdit_nameIsExactly -> setText("");
116 uiP.lineEdit_nameStartsWith -> setText("");
117 uiP.lineEdit_nameEndsWith -> setText("");
118 uiP.lineEdit_nameContains -> setText("");
119 uiP.groupBox_name -> setEnabled (false);
120
121 uiP.checkBox_pathAbsolute -> setCheckState(Qt::Unchecked);
122 uiP.checkBox_pathAbsolute -> setEnabled (false);
123 uiP.checkBox_pathAbsolute -> setVisible(false);
124
125 uiP.checkBox_pathAny -> setCheckState(Qt::Unchecked);
126 uiP.checkBox_pathAny -> setEnabled (false);
127 uiP.spinBox_pathDeeper -> setValue(0);
128 uiP.spinBox_pathDeeper -> setEnabled (false);
129 uiP.label_pathDeeper -> setEnabled (false);
130
131 uiP.toolButton_browseFile -> setVisible(false);
132
133 uiP.checkBox_directoryContents -> setCheckState(Qt::Unchecked);
134 uiP.radioButton_directorySpecific -> setChecked(true);
135
136 uiP.lineEdit_browse -> setText("");
137 uiP.lineEdit_browse -> setEnabled (true);
138 uiP.lineEdit_patternFinal -> setText("");
139 uiP.toolButton_browseDir -> setVisible(true);
140 uiP.label_browse -> setText(tr("directory :"));
141 }
142 // browse button pressed=====================================================================================================
143 //opens a QFileDialog to browse for files/folders locally
144 void patternEditor::browse(const int type)
145 {
146 QString newLineEdit;
147 switch (type)
148 {
149 //file browse button
150 case 0: newLineEdit = QFileDialog::getOpenFileName (this, tr("Select file"),SourceRoot);
151
152 if (newLineEdit != "") //if something is selected indeed (not cancel pressed)
153 {
154 if (notXnixRunning)
155 newLineEdit.replace("/",SLASH); // The OS2 filedialog captures path with *nix slashes. Change it to OS2 style
156
157 if (!newLineEdit.startsWith(SourceRoot))
158 {
159 textDialog textdialogW ("QtWarning", tr("Please choose a file within the source")+" :<br><br>" +
160 SourceRoot, this);
161 textdialogW.exec();
162 }
163 else
164 uiP.lineEdit_browse -> setText(newLineEdit);
165 }
166 break;
167 //directory browse button
168 case 1: newLineEdit = QFileDialog::getExistingDirectory (this, tr("Select directory"),SourceRoot);
169
170 if (newLineEdit != "") //if something is selected indeed (not cancel pressed)
171 {
172 if (notXnixRunning)
173 newLineEdit.replace("/",SLASH); // The OS2 filedialog captures path with *nix slashes. Change it to OS2 style
174
175 if (!newLineEdit.endsWith(SLASH))
176 newLineEdit.append(SLASH);
177
178 if (newLineEdit == "//") // root selected - *nix
179 newLineEdit = "/";
180
181 if (!newLineEdit.startsWith(SourceRoot))
182 {
183 textDialog textdialogW ("QtWarning", tr("Please choose a directory within the source")+" :<br><br>" +
184 SourceRoot, this);
185 textdialogW.exec();
186 }
187 else
188 uiP.lineEdit_browse -> setText(newLineEdit);
189 }
190 break;
191 }
192
193 }
194 //fillPattern ====================================================================================================================
195 //SLOT to fill-in the pattern from the info in the dialog
196 void patternEditor::fillPattern()
197 {
198 patternLine = "";
199
200 // Use absolute path ----------------------------------------------------------------------------------------------------------
201 if (uiP.checkBox_pathAbsolute -> isEnabled())
202 {
203 bool pathAbsoluteState = uiP.checkBox_pathAbsolute -> isChecked();
204 uiP.lineEdit_browse -> setEnabled(pathAbsoluteState);
205 uiP.toolButton_browseFile -> setEnabled(pathAbsoluteState);
206 uiP.toolButton_browseDir -> setEnabled(pathAbsoluteState);
207 uiP.label_pathDeeper -> setEnabled(pathAbsoluteState);
208 uiP.spinBox_pathDeeper -> setEnabled(pathAbsoluteState);
209 uiP.checkBox_pathAny -> setEnabled(pathAbsoluteState);
210 }
211 else
212 {
213 uiP.lineEdit_browse -> setEnabled(false);
214 uiP.toolButton_browseFile -> setEnabled(false);
215 uiP.toolButton_browseDir -> setEnabled(false);
216 uiP.label_pathDeeper -> setEnabled(false);
217 uiP.spinBox_pathDeeper -> setEnabled(false);
218 uiP.checkBox_pathAny -> setEnabled(false);
219 }
220
221 if ( (uiP.radioButton_fileSpecific -> isChecked()) || (uiP.radioButton_directorySpecific -> isChecked()) )
222 {
223 uiP.lineEdit_browse -> setEnabled(true);
224 uiP.toolButton_browseFile -> setEnabled(true);
225 uiP.toolButton_browseDir -> setEnabled(true);
226 }
227
228 // Read the path lineEdit
229 if (uiP.lineEdit_browse -> isEnabled())
230 {
231 patternLine = uiP.lineEdit_browse -> text(); //first get the string from the path lineEdit
232 if (patternLine.startsWith(SourceRoot))
233 patternLine.replace (SourceRoot, anchorSource + SLASH); // replace the starting source in the pattern with /
234 }
235
236 //go deeper in path ------------------- -------------------------------------------------------------------------------
237 if ( (uiP.checkBox_pathAny->isEnabled()) && (uiP.checkBox_pathAny->isChecked()) )
238 patternLine.append("**"+SLASH);
239 else
240 {
241 count=0;
242 while ( (count < uiP.spinBox_pathDeeper->value()) && (uiP.spinBox_pathDeeper->isEnabled()))
243 {
244 patternLine.append("*"+SLASH);
245 count++;
246 }
247 }
248
249 // groupbox NAME actions ------------------------------------------------------------------------------------------------
250 if (uiP.lineEdit_nameIsExactly->text()=="")
251 {
252 uiP.lineEdit_nameStartsWith -> setEnabled(true);
253 uiP.lineEdit_nameEndsWith -> setEnabled(true);
254 uiP.lineEdit_nameContains -> setEnabled(true);
255 }
256 else
257 {
258 uiP.lineEdit_nameStartsWith -> setEnabled(false);
259 uiP.lineEdit_nameEndsWith -> setEnabled(false);
260 uiP.lineEdit_nameContains -> setEnabled(false);
261 }
262
263 if (uiP.lineEdit_nameIsExactly -> isEnabled())
264 patternLine.append(uiP.lineEdit_nameIsExactly->text());
265
266 if ( (uiP.lineEdit_nameStartsWith -> isEnabled()) && (!(uiP.lineEdit_nameStartsWith->text() == "")) )
267 patternLine.append(uiP.lineEdit_nameStartsWith -> text() + "*");
268
269 if ( (uiP.lineEdit_nameContains -> isEnabled()) && (!(uiP.lineEdit_nameContains -> text()=="")) )
270 {
271 if (uiP.lineEdit_nameStartsWith -> text()=="")
272 patternLine.append("*");
273 patternLine.append(uiP.lineEdit_nameContains -> text() + "*");
274 }
275
276 if ( (uiP.lineEdit_nameEndsWith->isEnabled()) && (!(uiP.lineEdit_nameEndsWith -> text()=="")) )
277 {
278 if ( (uiP.lineEdit_nameContains -> text()=="") && (uiP.lineEdit_nameStartsWith -> text()=="") )
279 patternLine.append("*");
280 patternLine.append( uiP.lineEdit_nameEndsWith->text());
281 }
282
283 // RADIO BUTTONS actions ----------------------------------------------------------------------------------------------------
284 if (uiP.radioButton_fileSpecific -> isChecked()) // if file specific radio button is selected
285 {
286 uiP.label_browse -> setVisible(true);
287
288 uiP.label_browse -> setText(tr("file :"));
289 if (patternLine.endsWith(SLASH))
290 patternLine.chop(1);
291 }
292 if (uiP.radioButton_directorySpecific -> isChecked()) // if directory specific radio button is selected
293 {
294 uiP.label_browse -> setVisible(true);
295 uiP.label_browse -> setText(tr("directory :"));
296 if ((!(patternLine.endsWith(SLASH))) && (!(patternLine == "")) )
297 patternLine.append(SLASH);
298 }
299 if (uiP.radioButton_fileSet -> isChecked()) // if file set radio button is selected
300 {
301 uiP.checkBox_pathAbsolute -> setEnabled (true);
302 uiP.label_browse -> setVisible(false);
303 if (patternLine.endsWith(SLASH))
304 patternLine.chop(1);
305 }
306 if (uiP.radioButton_directorySet -> isChecked()) // if directory set radio button is selected
307 {
308 uiP.checkBox_pathAbsolute -> setEnabled (true);
309 uiP.label_browse -> setVisible(false);
310 if ( (!(patternLine.endsWith(SLASH))) && (!(patternLine == "")) )
311 patternLine.append(SLASH);
312 }
313
314 //just the contents of a directory -------------------------------------------------------------------------------
315 if ( (uiP.checkBox_directoryContents->isChecked()) && (uiP.checkBox_directoryContents->isEnabled()) )
316 patternLine.append("**");
317
318 if (notXnixRunning)
319 patternLine.replace(SLASH,"/"); // replace OS2 slashes with *nix ones -> OS2 uses *nix slashes for patterns
320
321 uiP.lineEdit_patternFinal -> setText(patternLine);
322 }
323 //fileRadioChanged----------------------------------------------------------------------------
324 //actions when the file specific radio button is toggled
325 void patternEditor::fileRadioChanged()
326 {
327 uiP.lineEdit_browse -> setText("");
328 }
329
330 // --------------------------------accessors-----------------------------------
331 QString patternEditor::getPattern()
332 {
333 return itsPattern;
334 }
335
336
337 // end of patternEditor.cpp ---------------------------------------------------------------------------
338