Debian Codegraph @

src/manage.cpp

raw symbols SCIP
1 /* ---------------------------------- manage.cpp ---------------------------------------------------------------------------
2 Class to display the manage backups 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 project version : Please see "main.cpp" for project version
23
24 developer : luckyb
25 last modified : 22 May 2016
26 ===============================================================================================================================
27 ===============================================================================================================================
28 */
29 #include "manage.h"
30
31 #include <QCloseEvent>
32 #include <QDirModel>
33
34 #include "RsyncDirModel.h"
35 #include "calcDiffThread.h"
36 #include "global.h"
37 #include "logDialog.h"
38 #include "manageWizard.h"
39 #include "operationClass.h"
40
41 // class manageDialog Constructor=================================================================================================
42 // Displays the manage backups of a task dialog
43 manageDialog::manageDialog (QDialog *parent) : QDialog (parent)
44 {
45 // initialize variables
46 CurrentSnapshotString = "";
47 CurrentSnapshotDirectory = "";
48 CurrentSnapshotNo = 0;
49
50 //first set string variables source, dest
51 QStringList arguments = Operation[currentOperation] -> GetArgs();
52 source = arguments[arguments.size()-2];
53 dest = arguments[arguments.size()-1];
54 sourceLast = "";
55
56 //fix source and dest
57 if (!source.endsWith(SLASH)) // this means task is of type "backup dir by name"
58 {
59 sourceLast = calculateLastPath(source); // This is the lowest dir of the source
60
61 source.append(SLASH);
62
63 if (WINrunning && Operation[currentOperation] -> GetRemote())
64 {
65 sourceLast.append(XnixSLASH);
66 dest.append(sourceLast);
67 if (dest.endsWith(XnixSLASH+XnixSLASH))
68 dest.chop(1);
69 }
70 else
71 {
72 sourceLast.append(SLASH);
73 dest.append(sourceLast);
74 if (dest.endsWith(SLASH+SLASH))
75 dest.chop(1);
76 }
77 }
78
79 uiG.setupUi(this);
80
81 calcdiffthread = new CalcDiffThread(this);
82 abortCalcThread = false;
83 connect( calcdiffthread, SIGNAL(updateViewer(const QString, const bool)), this, SLOT(refreshDifWindow(const QString &, const bool &)) );
84 connect( calcdiffthread, SIGNAL(terminated()), this, SLOT(calcDiffEnd()));
85 connect( calcdiffthread, SIGNAL(finished()), this, SLOT(calcDiffEnd()));
86
87 //connect pushButton SLOTs ----------------
88 connect ( uiG.pushButton_cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
89 connect ( uiG.pushButton_viewLog, SIGNAL( clicked() ), this, SLOT( logView() ) );
90 connect ( uiG.pushButton_restore, SIGNAL( clicked() ), this, SLOT( restoreBackup() ) );
91 connect ( uiG.pushButton_delete, SIGNAL( clicked() ), this, SLOT( deleteBackup() ) );
92 connect ( uiG.checkBox_viewSource, SIGNAL( clicked() ), this, SLOT( hideSourceStuff() ) );
93 connect ( uiG.listWidget_dates, SIGNAL( itemSelectionChanged() ), this, SLOT( SnapshotsListSelected() ) );
94 connect ( uiG.pushButton_calculate_diffs, SIGNAL ( clicked() ), this, SLOT ( calculateDifferences() ) );
95
96
97 //____________________Initial gui changes (these will remain the same for as long as the gui is visible)_______________
98
99 // set the text to labels profile & task
100 uiG.label_profile -> setText (tr("profile")+ ": <font color = blue><b>" +profileName + "</b></font>");
101 uiG.label_task -> setText (tr("task") + ": <font color = blue><b>" + Operation[currentOperation] -> GetName() + "</b></font>");
102
103 //resize the treeview headers
104 uiG.treeView_browser -> header() -> resizeSection(0,230);
105 uiG.treeView_source -> header() -> resizeSection(0,230);
106 uiG.treeView_browser -> header() -> resizeSection(1,80);
107 uiG.treeView_source -> header() -> resizeSection(1,80);
108 uiG.treeView_browser -> header() -> resizeSection(2,60);
109 uiG.treeView_source -> header() -> resizeSection(2,60);
110 uiG.treeView_browser -> header() -> resizeSection(3,100);
111 uiG.treeView_source -> header() -> resizeSection(3,100);
112
113 // Set the lineEdits source & dest with real paths
114 uiG.lineEdit_destination -> setText(dest);
115 uiG.lineEdit_source -> setText(source);
116
117 (uiG.textBrowser_snapshot->document())->setMaximumBlockCount(50000); // set maximum blocks to avoid freeze
118
119 updateSnapshots(); // update the snapshots listWidget
120 SnapshotsListSelected(); //set currentSnapshotString & No. Will also call fixGui()
121 }
122 // SLOTS-------------------------------------------------------------------------------------
123 // --------------------------------cancel pressed------------------------------------------------
124 void manageDialog::cancel()
125 {
126 close();
127 }
128
129 //do the same if the main window close button (or alt+F4) is pressed
130 void manageDialog::closeEvent(QCloseEvent *event)
131 {
132 // do not close the window if a calc thread is still running
133 if (calcdiffthread->isRunning())
134 event->ignore();
135 }
136
137 // SLOT logView =====================================================================================================================
138 // Display the logfile
139 void manageDialog::logView()
140 {
141 QUrl logURL;
142 logURL.setScheme("file");
143 logURL.setUrl("Does_not_exist");
144
145 //extract the logfilename from the dates listwidget
146 logfilename = CurrentSnapshotString;
147 logfilename.prepend(logDir + profileName + "-" + Operation[currentOperation] -> GetName() + "-");
148 logfilename.append(".log");
149
150 logfile.setFileName(logfilename); // this is the logfile of the item selected
151 if (logfile.exists()) //if the logfile exists
152 logURL.setUrl(logfilename);
153
154 logDialog logdialog (logURL);
155 logdialog.exec();
156 }
157
158 // SLOT restoreBackup =====================================================================================================================
159 // launch the restore wizard
160 void manageDialog::restoreBackup()
161 {
162 manageWizard restoreWizard("restoreBackup", source, dest, CurrentSnapshotNo); //pass the number of the current row
163 restoreWizard.exec();
164
165 fixGui(); // update the gui with new dirs data
166 }
167
168 // SLOT deleteBackup =====================================================================================================================
169 // Launch the delete backup wizard
170 void manageDialog::deleteBackup()
171 {
172
173 // launch the delete backup wizard
174 manageWizard deleteWizard("deleteBackup", source, dest, CurrentSnapshotNo);
175 deleteWizard.exec();
176
177 updateSnapshots(); // update the snapshots listwidget
178 SnapshotsListSelected(); // set a new currentSnapshot and update the gui
179 }
180
181 // fixGui =====================================================================================================================
182 // makes some changes to the gui according to various stuff to make it prettier !!
183 // also update treebrowsers with new snapshot data
184 void manageDialog::fixGui()
185 {
186 // these will become false if dest or source treebrowsers are to be hidden
187 bool destVisible = true;
188 sourceVisible = true;
189
190 //Thesw will become false if relevant pushButtons have to be disabled
191 viewLogVisible = true;
192 deleteVisible = true;
193 restoreVisible = true;
194
195 syncTYPE = false; // This will become true if it is a sync task
196
197 // Destination - Do all things needed to display the current snapshot only.
198 QDir CurrentSnapshotDir(CurrentSnapshotDirectory);
199
200 // set the model of the treebrowsers (source & destination) sort by name & refresh to use new source & dest
201 //destination
202 QDirModel *d_model = new QDirModel;
203
204 //d_model -> setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
205 //d_model -> setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::LocaleAware);
206
207 //uiG.treeView_browser -> setModel(d_model);
208 //uiG.treeView_browser -> sortByColumn (0, Qt::AscendingOrder);
209 //if (CurrentSnapshotDir.exists())
210 // uiG.treeView_browser -> setRootIndex(d_model->index(CurrentSnapshotDirectory));
211 //else
212
213 //uiG.treeView_browser -> setRootIndex(d_model->index(dest));
214
215 //source
216 QDirModel *s_model = new QDirModel;
217
218 //s_model -> setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
219 //s_model -> setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::LocaleAware);
220 //uiG.treeView_source -> setModel(s_model);
221 //uiG.treeView_source -> sortByColumn (0, Qt::AscendingOrder);
222 //uiG.treeView_source -> setRootIndex(s_model->index(source));
223
224 RsyncDirModel *rsyncmodel=new RsyncDirModel;
225
226 // if a snapshot is not selected
227 if (CurrentSnapshotString == "")
228 {
229 viewLogVisible = false;
230 deleteVisible = false;
231 restoreVisible = false;
232
233 if (!Operation[currentOperation] -> GetTypeSync())
234 {
235 destVisible = false;
236 uiG.label_destError -> setText("<font color=magenta>" + tr("Please select a snapshot from the list",
237 "Information message") + "</font>");
238 }
239 }
240
241 // if "not available" is selected
242 if (CurrentSnapshotString == "not available")
243 viewLogVisible = false; //disable the "view log" button
244
245 // _______________________________ source & destination directories checks ____________________________________________
246 // ___________________________________________________________________________________________________________________
247 // check if source & destination exist or have read/enter permissions or are remote ----------------------------------
248 QFileInfo destFile(dest);
249 QFileInfo sourceFile(source);
250 bool sourceRemote = (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteSource());
251 bool destRemote = (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteDestination());
252
253 if (sourceRemote) // If remote is used for source
254 {
255 //sourceVisible = false;
256 //uiG.label_sourceError -> setText("<font color=magenta>" + tr("Display of remote places is not supported",
257 // "Information message") + "</font>");
258
259 // ~~~~~~~~~~~~~~~~ Juan's patch for source~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260 QStringList remoteArgs;
261 remoteArgs.append("--protect-args");
262 if ( Operation[currentOperation]-> GetRemoteModule() && Operation[currentOperation] -> GetRemotePassword() != "")
263 remoteArgs.append("--password-file=" + ( Operation[currentOperation] -> GetRemotePassword()) );
264
265 if ( Operation[currentOperation] -> GetRemoteSSH())
266 {
267 QString sshOptions=(Operation[currentOperation] -> GetRemoteSSHOptions()).replace("\"","\\\"")+" -o \"StrictHostKeyChecking no\" -o \"PasswordAuthentication no\" ";
268 if (WINrunning)
269 {
270 if ( Operation[currentOperation] -> GetRemoteSSHPassword() != "")
271 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
272 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+" -i \"" + Operation[currentOperation] -> GetRemoteSSHPassword() +"\" -p " +
273 countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
274 else
275 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+" -i \"" + Operation[currentOperation] -> GetRemoteSSHPassword()+"\"");
276 else
277 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
278 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+" -p " + countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
279 else
280 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+"");
281 }
282 else
283 {
284 if ( Operation[currentOperation] -> GetRemoteSSHPassword() != "")
285 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
286 remoteArgs.append("-e "+sshCommandPath+" -i " + Operation[currentOperation] -> GetRemoteSSHPassword() +" -p " +
287 countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
288 else
289 remoteArgs.append("-e "+sshCommandPath+" -i " + Operation[currentOperation] -> GetRemoteSSHPassword());
290 else
291 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
292 remoteArgs.append("-e "+sshCommandPath+" -p " + countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
293 else
294 remoteArgs.append("-e "+sshCommandPath);
295 }
296 }
297
298 rsyncmodel -> setUrl(QUrl(source),rsyncCommandPath,remoteArgs);
299 uiG.treeView_source -> setModel(rsyncmodel);
300 uiG.treeView_source -> sortByColumn (0, Qt::AscendingOrder);
301
302 }
303 else
304 {
305 s_model -> setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
306 s_model -> setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::LocaleAware);
307 uiG.treeView_source -> setModel(s_model);
308 uiG.treeView_source -> sortByColumn (0, Qt::AscendingOrder);
309 uiG.treeView_source -> setRootIndex(s_model->index(source));
310 }
311 if (destRemote) // If remote is used for destination
312 {
313 // destVisible = false;
314
315 // ********************** WARNING - Change this when you figure out a way to display/delete remote places *************************************
316 // uiG.label_destError -> setText("<font color=magenta>" + tr("Display of remote places is not supported",
317 // "Information message") + "</font>");
318 deleteVisible = false; //disable the delete button
319
320 // ~~~~~~~~~~~~~~~~ Juan's patch for dest~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
321 QStringList remoteArgs;
322 remoteArgs.append("--protect-args");
323 if ( Operation[currentOperation]-> GetRemoteModule() && Operation[currentOperation] -> GetRemotePassword() != "")
324 remoteArgs.append("--password-file=" + ( Operation[currentOperation] -> GetRemotePassword()) );
325
326 if ( Operation[currentOperation] -> GetRemoteSSH())
327 {
328 QString sshOptions=(Operation[currentOperation] -> GetRemoteSSHOptions()).replace("\"","\\\"")+" -o \"StrictHostKeyChecking no\" -o \"PasswordAuthentication no\" ";
329 if (WINrunning)
330 {
331 if ( Operation[currentOperation] -> GetRemoteSSHPassword() != "")
332 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
333 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+" -i \"" + Operation[currentOperation] -> GetRemoteSSHPassword() +"\" -p " +
334 countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
335 else
336 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+" -i \"" + Operation[currentOperation] -> GetRemoteSSHPassword()+"\"");
337 else
338 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
339 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+" -p " + countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
340 else
341 remoteArgs.append("-e \""+Operation[currentOperation] -> GetSshCommand()+"\" "+sshOptions+"");
342 }
343 else
344 {
345 if ( Operation[currentOperation] -> GetRemoteSSHPassword() != "")
346 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
347 remoteArgs.append("-e "+sshCommandPath+" -i " + Operation[currentOperation] -> GetRemoteSSHPassword() +" -p " +
348 countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
349 else
350 remoteArgs.append("-e "+sshCommandPath+" -i " + Operation[currentOperation] -> GetRemoteSSHPassword());
351 else
352 if ( Operation[currentOperation] -> GetRemoteSSHPort() != 0)
353 remoteArgs.append("-e "+sshCommandPath+" -p " + countStr.setNum( Operation[currentOperation] -> GetRemoteSSHPort()) );
354 else
355 remoteArgs.append("-e "+sshCommandPath);
356 }
357 }
358
359 rsyncmodel->setUrl(QUrl(dest),rsyncCommandPath,remoteArgs);
360 uiG.treeView_browser -> setModel(rsyncmodel);
361 uiG.treeView_browser -> sortByColumn (0, Qt::AscendingOrder);
362 }
363 else // Local destination
364 {
365 //if (CurrentSnapshotDir.exists())
366 // uiG.treeView_browser -> setRootIndex(d_model->index(CurrentSnapshotDirectory));
367 //else
368
369 d_model -> setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
370 d_model -> setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::LocaleAware);
371
372 uiG.treeView_browser -> setModel(d_model);
373 uiG.treeView_browser -> sortByColumn (0, Qt::AscendingOrder);
374 uiG.treeView_browser -> setRootIndex(d_model->index(dest));
375 }
376 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Juan's patch END~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
377
378 // If source does not exist (and is not remote)
379 if ((!sourceFile.exists()) && (!sourceRemote))
380 {
381 sourceVisible = false;
382 uiG.label_sourceError -> setText("<font color=red>" + tr("This directory does not exist") + "</font>");
383 }
384 // If destination does not exist
385 if ((!destFile.exists()) && !(destRemote))
386 {
387 destVisible = false;
388 uiG.label_destError -> setText("<font color=red>" + tr("This directory does not exist",
389 "Information message") + "</font>");
390 if (CurrentSnapshotString == "not available")
391 deleteVisible = false; //disable the delete button
392 restoreVisible = false; //disable the restore button
393 }
394 // If source does not have read/enter permissions
395 if (((!sourceFile.isReadable()) || (!sourceFile.isExecutable())) && (!sourceRemote) && (sourceFile.exists()))
396 {
397 sourceVisible = false;
398 uiG.label_sourceError -> setText("<font color=red>" + tr("I do not have sufficient permissions to read this directory",
399 "Information message") + "</font>");
400 restoreVisible = false; //disable the restore button
401 }
402 // If destination does not have read/enter permissions
403 if (((!destFile.isReadable()) || (!destFile.isExecutable())) && (!destRemote) && (destFile.exists()))
404 {
405 destVisible = false;
406 uiG.label_destError -> setText("<font color=red>" + tr("I do not have sufficient permissions to read this directory",
407 "Information message") + "</font>");
408 deleteVisible = false; //disable the delete button
409 restoreVisible = false; //disable the restore button
410 }
411
412 // _______________________________ source & destination directories checks END____________________________________________
413 // ___________________________________________________________________________________________________________________
414
415 //if this is a "sync" task
416 if (Operation[currentOperation] -> GetTypeSync())
417 {
418 syncTYPE = true;
419 uiG.label_destination -> setText (tr("sync dir A","full phrase: sync dir a: <DIRECTORY_A>")+ ": ");
420 uiG.label_source -> setText (tr("sync dir B","full phrase: sync dir a: <DIRECTORY_b>")+ ": ");
421 uiG.pushButton_viewLog -> setToolTip(tr("View the logfile of the selected sync task","'view log' pushbutton tooltip"));
422 deleteVisible = false;
423 restoreVisible = false;
424 uiG.checkBox_viewSource -> setVisible(false);
425 }
426
427 // hide or show the treebrowsers - textbrowser
428 uiG.textBrowser_snapshot -> setVisible (false);
429 uiG.treeView_browser -> setVisible (destVisible);
430 uiG.label_destError -> setVisible (!destVisible);
431 hideSourceStuff();
432
433 //enable/disable the pushbuttons
434 uiG.pushButton_viewLog -> setEnabled(viewLogVisible);
435 uiG.pushButton_calculate_diffs -> setEnabled(destVisible);
436
437 // Enable the delete button only for the first snapshot in list
438 if (CurrentSnapshotNo > 0)
439 deleteVisible = false;
440
441 uiG.pushButton_delete -> setEnabled(deleteVisible);
442 uiG.pushButton_restore -> setEnabled(restoreVisible);
443 }
444
445 // hideSourceStuff =====================================================================================================================
446 // hides/shows the source treebrowser & label
447 void manageDialog::hideSourceStuff()
448 {
449 // Check the state of the "hide source" checkbox
450 bool boxState = uiG.checkBox_viewSource -> isChecked();
451
452 if (boxState)
453 {
454 uiG.label_source -> setVisible(false);
455 uiG.lineEdit_source -> setVisible(false);
456 uiG.label_sourceError -> setVisible (false);
457 uiG.treeView_source -> setVisible (false);
458 }
459 else
460 {
461 uiG.label_source -> setVisible(true);
462 uiG.lineEdit_source -> setVisible(true);
463 uiG.treeView_source -> setVisible (sourceVisible);
464 uiG.label_sourceError -> setVisible (!sourceVisible);
465 }
466 }
467
468 // SnapshotsListSelected =====================================================================================================================
469 // disables pushbuttons when nothing is selected at snapshots listwidget
470 // Also sets QString CurrentSnapshotString at current snapshot, format YYYY
471 void manageDialog::SnapshotsListSelected()
472 {
473 CurrentSnapshotNo = uiG.listWidget_dates -> currentRow();
474 // if a snapshot is not selected
475 if (CurrentSnapshotNo < 0)
476 {
477 CurrentSnapshotString = "";
478 CurrentSnapshotDirectory = "";
479 }
480 else
481 {
482 CurrentSnapshotString = Operation[currentOperation] -> GetSnapshotsListItem (CurrentSnapshotNo);
483
484 if (WINrunning && Operation[currentOperation] -> GetRemote())
485 CurrentSnapshotDirectory = dest + snapDefaultDir.replace(SLASH,XnixSLASH) + CurrentSnapshotString + XnixSLASH + sourceLast;
486 else
487 CurrentSnapshotDirectory = dest + snapDefaultDir + CurrentSnapshotString + SLASH + sourceLast;
488
489 if (CurrentSnapshotString == "") // if there is no execution time of the current snapshot
490 CurrentSnapshotString = "not available";
491 }
492
493 fixGui(); // update the gui
494 }
495
496 // calculateDifferences() ========================================================================================
497 // calculate differences between source and snapshot
498 // Calls readDirEntries()
499 void manageDialog::calculateDifferences()
500 {
501 // if the thread is running (meaning: STOP is pressed)
502 if (calcdiffthread -> isRunning())
503 {
504 uiG.textBrowser_snapshot -> setText (tr("Please wait until the thread is terminated"));
505 uiG.pushButton_calculate_diffs -> setEnabled(false);
506 calcdiffthread -> setAbort(true);
507 abortCalcThread = true;
508 return;
509 }
510
511 // change the gui a bit
512 if (syncTYPE)
513 {
514 uiG.label_source -> setVisible(false);
515 uiG.lineEdit_source -> setVisible(false);
516 uiG.treeView_source -> setVisible (false);
517 }
518 uiG.treeView_browser -> setVisible (false);
519 uiG.textBrowser_snapshot -> setVisible (true);
520
521 if (!snapCalculated.at(CurrentSnapshotNo)) // if the differences have not been calculated yet
522 {
523 //disable some gui stuff during calculations
524 uiG.pushButton_delete -> setEnabled(false);
525 uiG.pushButton_restore -> setEnabled(false);
526 uiG.pushButton_viewLog -> setEnabled(false);
527 uiG.pushButton_cancel -> setEnabled(false);
528 uiG.pushButton_calculate_diffs -> setText(tr("STOP"));
529 uiG.pushButton_calculate_diffs -> setToolTip(tr("Stop calculations NOW"));
530
531
532 calcdiffthread -> passParams(dest, dest, CurrentSnapshotDirectory, CurrentSnapshotString, sourceLast, source, CurrentSnapshotNo, currentSnaps, syncTYPE);
533 calcdiffthread -> start();
534 }
535 else
536 uiG.textBrowser_snapshot -> setText (calculatedDifferences.at(CurrentSnapshotNo));
537 }
538
539 // calcDiffEnd =====================================================================================================================
540 // // diffs have been calculated - update viewer with new text
541 void manageDialog::calcDiffEnd()
542 {
543 // Update the textBrowser_snapshot with differences data
544 calculatedDifferences.replace(CurrentSnapshotNo, calcdiffthread -> returnResult() );
545 uiG.textBrowser_snapshot -> setText (calculatedDifferences.at(CurrentSnapshotNo));
546
547 if (abortCalcThread)
548 uiG.textBrowser_snapshot -> append ("<p align=\"center\"><font color=red><b>" + tr("Calculations terminated by user") + "</b></font></p>");
549 else
550 snapCalculated.replace(CurrentSnapshotNo, true );
551
552 abortCalcThread = false;
553 calcdiffthread -> setAbort(false);
554
555 // re-enable gui stuff
556 uiG.pushButton_delete -> setEnabled(deleteVisible);
557 uiG.pushButton_restore -> setEnabled(restoreVisible);
558 uiG.pushButton_viewLog -> setEnabled(viewLogVisible);
559 uiG.pushButton_cancel -> setEnabled(true);
560 uiG.pushButton_calculate_diffs -> setEnabled(true);
561 uiG.pushButton_calculate_diffs -> setText(tr("Calculate differences"));
562 uiG.pushButton_calculate_diffs -> setToolTip(tr("Calculate the differences between the source and the selected snapshot"));
563 }
564
565 // FUNCTIONS-------------------------------------------------------------------------------------
566
567 // refreshDifWindow =====================================================================================================
568 //Refresh the calc diff window with text
569 void manageDialog::refreshDifWindow(const QString &newText, const bool &appendText)
570 {
571 if (appendText)
572 uiG.textBrowser_snapshot -> append(newText);
573 else
574 uiG.textBrowser_snapshot -> setText(newText);
575 // QCoreApplication::processEvents();
576 }
577
578 // updateSnapshots =====================================================================================================================
579 // update the snapshots date & times listwidget
580 void manageDialog::updateSnapshots()
581 {
582 //clear the listWidget
583 uiG.listWidget_dates -> clear();
584 calculatedDifferences.clear(); // this holds the calculated differences text for each snapshot
585 snapCalculated.clear();
586
587 //initialize snapshot variables
588 currentSnaps = Operation[currentOperation] -> GetSnapshotsListSize(); // this is the current number of snapshots
589 bool emptySnapList = Operation[currentOperation] -> SnapshotsListIsEmpty(); // Is the list empty ??
590
591 // first check if there is a last execution time available but no snapshots are declared
592 // and add a new snapshot with the last execution date-time
593 time = ( Operation[currentOperation] -> GetLastExecutionTime() ).toString("yyyyMMddhhmmss");
594 if ( !(time == "") && (emptySnapList) )
595 {
596 Operation[currentOperation] -> AddSnapshotsListItem (time);
597 currentSnaps = Operation[currentOperation] -> GetSnapshotsListSize(); // this is the current number of snapshots
598 emptySnapList = Operation[currentOperation] -> SnapshotsListIsEmpty(); // Is the list empty ??
599 }
600
601 //update the listwidget with times from snapshots
602 count=0;
603 while (count < currentSnaps)
604 {
605 QDateTime currentSnapTime = QDateTime::fromString(Operation[currentOperation]-> GetSnapshotsListItem(count),"yyyyMMddhhmmss");
606 if ((Operation[currentOperation]-> GetSnapshotsListItem(count)) == "") // if there is no snapshot time for a reason
607 uiG.listWidget_dates -> addItem (tr("not available","refers to a date-time"));
608 else
609 uiG.listWidget_dates -> addItem (currentSnapTime.toString("yyyy/MM/dd - hh:mm:ss"));
610
611 calculatedDifferences.append("");
612 snapCalculated.append(false);
613
614 count++;
615 }
616
617 if (emptySnapList)
618 {
619 uiG.listWidget_dates -> addItem (tr("not available","refers to a date-time"));
620 calculatedDifferences.append("");
621 snapCalculated.append(false);
622 }
623
624 // select the latest snapshot
625 uiG.listWidget_dates -> setCurrentRow(uiG.listWidget_dates -> count() - 1);
626 }
627
628
629 // end of manage.cpp ---------------------------------------------------------------------------
630