~ubuntu-branches/ubuntu/maverick/luckybackup/maverick

« back to all changes in this revision

Viewing changes to src/global.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2009-05-21 20:09:36 UTC
  • Revision ID: james.westby@ubuntu.com-20090521200936-jcbu6euvoxz7sef7
Tags: upstream-0.3
Import upstream version 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ---------------------------------- global.cpp ---------------------------------------------------------------------------
 
2
 file containing all variables & functions used globaly
 
3
 
 
4
===============================================================================================================================
 
5
===============================================================================================================================
 
6
     This file is part of "luckyBackup" project
 
7
     Copyright 2008-2009, 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          : 30 April 2009
 
26
===============================================================================================================================
 
27
===============================================================================================================================
 
28
*/
 
29
 
 
30
#include "operationClass.h"
 
31
#include "global.h"
 
32
 
 
33
 
 
34
// loadProfile =====================================================================================================================================
 
35
// loads an existing profile
 
36
int loadProfile(QString profileToLoad)
 
37
{
 
38
        int count;
 
39
        profile.setFileName(profileToLoad);
 
40
 
 
41
        if (!profile.open(QIODevice::ReadOnly))         //if the profile cannot be opened
 
42
        {
 
43
                profile.close();
 
44
                return 1;
 
45
        }
 
46
 
 
47
        QDataStream in(&profile);
 
48
        in.setVersion(QDataStream::Qt_4_3);
 
49
 
 
50
        QVariant v;                                     //we will import everything as QVariant using this temp variable
 
51
        QString vString;                                //temp variable to import "labels" of real data
 
52
        QString tempAppName = "asxeto";
 
53
        double tempAppVersion=0;
 
54
        in>>v;  if (v.toString()=="appName")
 
55
                in >> v;        tempAppName = v.toString();     //input the application name & version--------------------------
 
56
        in>>v;  if (v.toString()=="appVersion")
 
57
                in >> v;        tempAppVersion = v.toDouble();
 
58
 
 
59
        if ( (tempAppName != appName) || (tempAppVersion < validProfileVersion) )//check if the file is a valid luckybackup profile
 
60
        {
 
61
                profile.close();
 
62
                return 2;               //profile is not valid
 
63
        }
 
64
 
 
65
        in>>v;  if (v.toString()=="TotalOperations")
 
66
                in >> v;        TotalOperations = v.toInt();    //input the size of the operations list 
 
67
 
 
68
        currentOperation = 0;   vString="";
 
69
        while (currentOperation < TotalOperations)
 
70
        {
 
71
                operation *tempOp = new operation;
 
72
 
 
73
                in>>v;  vString = v.toString(); in >> v;        //input a label in vString and real data in v
 
74
                while (vString != "operation end")
 
75
                {
 
76
                        if (vString == "Name")                  tempOp  -> SetName(v.toString());
 
77
                        if (vString == "Args")                  tempOp  -> SetArgs(v.toStringList());
 
78
 
 
79
                        if (vString == "AlsoCreateRestore")     tempOp  -> SetAlsoCreateRestore(v.toBool());
 
80
                        if (vString == "ConnectRestore")        tempOp  -> SetConnectRestore(v.toString());
 
81
 
 
82
                        if (vString == "TypeDirContents")       tempOp  -> SetTypeDirContents(v.toBool());
 
83
                        if (vString == "TypeDirName")           tempOp  -> SetTypeDirName(v.toBool());
 
84
                        if (vString == "TypeSync")              tempOp  -> SetTypeSync(v.toBool());
 
85
 
 
86
                        if (vString == "Source")                tempOp  -> SetSource(v.toString());
 
87
                        if (vString == "Destination")           tempOp  -> SetDestination(v.toString());
 
88
 
 
89
                        if (vString == "ExcludeTemp")           tempOp  -> SetExcludeTemp(v.toBool());
 
90
                        if (vString == "ExcludeCache")          tempOp  -> SetExcludeCache(v.toBool());
 
91
                        if (vString == "ExcludeBackup")         tempOp  -> SetExcludeBackup(v.toBool());
 
92
                        if (vString == "ExcludeMount")          tempOp  -> SetExcludeMount(v.toBool());
 
93
                        if (vString == "ExcludeLostFound")      tempOp  -> SetExcludeLostFound(v.toBool());
 
94
                        if (vString == "ExcludeSystem")         tempOp  -> SetExcludeSystem(v.toBool());
 
95
                        if (vString == "ExcludeTrash")          tempOp  -> SetExcludeTrash(v.toBool());
 
96
                        if (vString == "ExcludeListSize")
 
97
                        {
 
98
                                int excludeListSize = v.toInt();
 
99
                                count = 0;
 
100
                                while ( count < excludeListSize)
 
101
                                {
 
102
                                        in >> v;                tempOp  -> AddExcludeListItem(v.toString());
 
103
                                        count++;
 
104
                                }
 
105
                        }
 
106
                        tempOp  -> SetExclude();
 
107
 
 
108
                        if (vString == "IncludeListSize")
 
109
                        {
 
110
                                int IncludeListSize = v.toInt();
 
111
                                count = 0;
 
112
                                while ( count < IncludeListSize)
 
113
                                {
 
114
                                        in >> v; 
 
115
                                                                tempOp  -> AddIncludeListItem(v.toString());
 
116
                                        count++;
 
117
                                }
 
118
                        }
 
119
                        tempOp  -> SetInclude();
 
120
 
 
121
                        if (vString == "Remote")                tempOp  -> SetRemote(v.toBool());
 
122
                        if (vString == "RemoteModule")          tempOp  -> SetRemoteModule(v.toBool());
 
123
                        if (vString == "RemoteDestination")     tempOp  -> SetRemoteDestination(v.toBool());
 
124
                        if (vString == "RemoteSource")          tempOp  -> SetRemoteSource(v.toBool());
 
125
                        if (vString == "RemoteSSH")             tempOp  -> SetRemoteSSH(v.toBool());
 
126
                        if (vString == "RemoteHost")            tempOp  -> SetRemoteHost(v.toString());
 
127
                        if (vString == "RemoteUser")            tempOp  -> SetRemoteUser(v.toString());
 
128
                        if (vString == "RemotePassword")        tempOp  -> SetRemotePassword(v.toString());
 
129
                        if (vString == "RemoteSSHPassword")     tempOp  -> SetRemoteSSHPassword(v.toString());
 
130
                        if (vString == "RemoteSSHPort")         tempOp  -> SetRemoteSSHPort(v.toInt());
 
131
 
 
132
                        if (vString == "OptionsUpdate")         tempOp  -> SetOptionsUpdate(v.toBool());
 
133
                        if (vString == "OptionsDelete")         tempOp  -> SetOptionsDelete(v.toBool());
 
134
                        if (vString == "OptionsRecurse")        tempOp  -> SetOptionsRecurse(v.toBool());
 
135
                        if (vString == "OptionsOwnership")      tempOp  -> SetOptionsOwnership(v.toBool());
 
136
                        if (vString == "OptionsSymlinks")       tempOp  -> SetOptionsSymlinks(v.toBool());
 
137
                        if (vString == "OptionsPermissions")    tempOp  -> SetOptionsPermissions(v.toBool());
 
138
                        if (vString == "OptionsDevices")        tempOp  -> SetOptionsDevices(v.toBool());
 
139
                        if (vString == "OptionsCVS")            tempOp  -> SetOptionsCVS(v.toBool());
 
140
                        if (vString == "OptionsHardLinks")      tempOp  -> SetOptionsHardLinks(v.toBool());
 
141
                        if (vString == "OptionsListSize")
 
142
                        {
 
143
                                int OptionsListSize = v.toInt();
 
144
                                count = 0;
 
145
                                while ( count < OptionsListSize)
 
146
                                {
 
147
                                        in >> v;
 
148
                                                                tempOp  -> AddOptionsListItem(v.toString());
 
149
                                        count++;
 
150
                                }
 
151
                        }
 
152
                        if (vString == "ExecuteBeforeListSize")
 
153
                        {
 
154
                                int ExecuteBeforeListSize = v.toInt();
 
155
                                count = 0;
 
156
                                while ( count < ExecuteBeforeListSize)
 
157
                                {
 
158
                                        in >> v;
 
159
                                                                tempOp  -> AddExecuteBeforeListItem(v.toString());
 
160
                                        count++;
 
161
                                }
 
162
                        }
 
163
                        if (vString == "ExecuteAfterListSize")
 
164
                        {
 
165
                                int ExecuteAfterListSize = v.toInt();
 
166
                                count = 0;
 
167
                                while ( count < ExecuteAfterListSize)
 
168
                                {
 
169
                                        in >> v;
 
170
                                                                tempOp  -> AddExecuteAfterListItem(v.toString());
 
171
                                        count++;
 
172
                                }
 
173
                        }
 
174
                        //import include checkbox state
 
175
                        if (vString == "IncludeState")          tempOp  -> SetIncluded(v.toBool());
 
176
                        in>>v;  vString = v.toString();
 
177
                        if (vString!="operation end")
 
178
                                in >> v;
 
179
                        else
 
180
                                Operation[currentOperation] = tempOp;
 
181
                }
 
182
                currentOperation++;
 
183
        }
 
184
        profile.close();
 
185
        return 0;
 
186
}
 
187
 
 
188
// saveProfile =====================================================================================================================================
 
189
// saves an existing profile
 
190
bool saveProfile(QString profileToSave)
 
191
{
 
192
        int count;
 
193
 
 
194
        profile.setFileName(profileToSave);
 
195
        
 
196
        if (!profile.open(QIODevice::WriteOnly))        // if the profile cannot be saved (or fails to create)
 
197
        {
 
198
                profile.close();
 
199
                return FALSE;
 
200
        }
 
201
 
 
202
        //write arrays to profile file
 
203
        QDataStream out(&profile);
 
204
        out.setVersion(QDataStream::Qt_4_3);
 
205
 
 
206
        QVariant v;                                     //we will export everything as QVariant using this temp variable
 
207
        v = "appName";          out << v;       v = appName;            out << v;       //output the application name 
 
208
        v = "appVersion";       out << v;       v = appVersion;         out << v;       //output the application version 
 
209
        v = "TotalOperations";  out << v;       v = TotalOperations;    out << v;       //output the size of the opeartions list 
 
210
 
 
211
 
 
212
        currentOperation = 0;
 
213
 
 
214
        while ( currentOperation < TotalOperations )
 
215
        {
 
216
                v = "Name";                     out << v;       v = Operation[currentOperation] -> GetName();                   out << v;
 
217
                v = "Args";                     out << v;       v = Operation[currentOperation] -> GetArgs();                   out << v;
 
218
 
 
219
                v = "AlsoCreateRestore";        out << v;       v = Operation[currentOperation] -> GetAlsoCreateRestore();      out << v;
 
220
                v = "ConnectRestore";           out << v;       v = Operation[currentOperation] -> GetConnectRestore();         out << v;
 
221
 
 
222
                v = "TypeDirContents";          out << v;       v = Operation[currentOperation] -> GetTypeDirContents();        out << v;
 
223
                v = "TypeDirName";              out << v;       v = Operation[currentOperation] -> GetTypeDirName();            out << v;
 
224
                v = "TypeSync";                 out << v;       v = Operation[currentOperation] -> GetTypeSync();               out << v;
 
225
 
 
226
                v = "Source";                   out << v;       v = Operation[currentOperation] -> GetSource();                 out << v;
 
227
                v = "Destination";              out << v;       v = Operation[currentOperation] -> GetDestination();            out << v;
 
228
 
 
229
                v = "Exclude";                  out << v;       v = Operation[currentOperation] -> GetExclude();                out << v;
 
230
                v = "ExcludeTemp";              out << v;       v = Operation[currentOperation] -> GetExcludeTemp();            out << v;
 
231
                v = "ExcludeCache";             out << v;       v = Operation[currentOperation] -> GetExcludeCache();           out << v;
 
232
                v = "ExcludeBackup";            out << v;       v = Operation[currentOperation] -> GetExcludeBackup();          out << v;
 
233
                v = "ExcludeMount";             out << v;       v = Operation[currentOperation] -> GetExcludeMount();           out << v;
 
234
                v = "ExcludeLostFound";         out << v;       v = Operation[currentOperation] -> GetExcludeLostFound();       out << v;
 
235
                v = "ExcludeSystem";            out << v;       v = Operation[currentOperation] -> GetExcludeSystem();          out << v;
 
236
                v = "ExcludeTrash";             out << v;       v = Operation[currentOperation] -> GetExcludeTrash();           out << v;
 
237
                v = "ExcludeListSize";          out << v;       v = Operation[currentOperation] -> GetExcludeListSize();        out << v;
 
238
                count = 0;
 
239
                while ( count < (Operation[currentOperation] -> GetExcludeListSize()) )
 
240
                {
 
241
                        v = Operation[currentOperation] -> GetExcludeListItem(count); out << v;
 
242
                        count++;
 
243
                }
 
244
 
 
245
                v = "Include";                  out << v;       v = Operation[currentOperation] -> GetInclude();                out << v;
 
246
                v = "IncludeListSize";          out << v;       v = Operation[currentOperation] -> GetIncludeListSize();        out << v;
 
247
                count = 0;
 
248
                while ( count < (Operation[currentOperation] -> GetIncludeListSize()) )
 
249
                {
 
250
                        v = Operation[currentOperation] -> GetIncludeListItem(count); out << v;
 
251
                        count++;
 
252
                }
 
253
 
 
254
                v = "Remote";                   out << v;       v = Operation[currentOperation] -> GetRemote();                 out << v;
 
255
                v = "RemoteModule";             out << v;       v = Operation[currentOperation] -> GetRemoteModule();           out << v;
 
256
                v = "RemoteDestination";        out << v;       v = Operation[currentOperation] -> GetRemoteDestination();      out << v;
 
257
                v = "RemoteSource";             out << v;       v = Operation[currentOperation] -> GetRemoteSource();           out << v;
 
258
                v = "RemoteSSH";                out << v;       v = Operation[currentOperation] -> GetRemoteSSH();              out << v;
 
259
                v = "RemoteHost";               out << v;       v = Operation[currentOperation] -> GetRemoteHost();             out << v;
 
260
                v = "RemoteUser";               out << v;       v = Operation[currentOperation] -> GetRemoteUser();             out << v;
 
261
                v = "RemotePassword";           out << v;       v = Operation[currentOperation] -> GetRemotePassword();         out << v;
 
262
                v = "RemoteSSHPassword";        out << v;       v = Operation[currentOperation] -> GetRemoteSSHPassword();      out << v;
 
263
                v = "RemoteSSHPort";            out << v;       v = Operation[currentOperation] -> GetRemoteSSHPort();          out << v;
 
264
 
 
265
                v = "OptionsUpdate";            out << v;       v = Operation[currentOperation] -> GetOptionsUpdate();          out << v;
 
266
                v = "OptionsDelete";            out << v;       v = Operation[currentOperation] -> GetOptionsDelete();          out << v;
 
267
                v = "OptionsRecurse";           out << v;       v = Operation[currentOperation] -> GetOptionsRecurse();         out << v;
 
268
                v = "OptionsOwnership";         out << v;       v = Operation[currentOperation] -> GetOptionsOwnership();       out << v;
 
269
                v = "OptionsSymlinks";          out << v;       v = Operation[currentOperation] -> GetOptionsSymlinks();        out << v;
 
270
                v = "OptionsPermissions";       out << v;       v = Operation[currentOperation] -> GetOptionsPermissions();     out << v;
 
271
                v = "OptionsDevices";           out << v;       v = Operation[currentOperation] -> GetOptionsDevices();         out << v;
 
272
                v = "OptionsCVS";               out << v;       v = Operation[currentOperation] -> GetOptionsCVS();             out << v;
 
273
                v = "OptionsHardLinks";         out << v;       v = Operation[currentOperation] -> GetOptionsHardLinks();       out << v;
 
274
                v = "OptionsListSize";          out << v;       v = Operation[currentOperation] -> GetOptionsListSize();        out << v;
 
275
                count = 0;
 
276
                while ( count < (Operation[currentOperation] -> GetOptionsListSize()) )
 
277
                {
 
278
                        v = Operation[currentOperation] -> GetOptionsListItem(count); out << v;
 
279
                        count++;
 
280
                }
 
281
                v = "ExecuteBeforeListSize";    out << v;       v = Operation[currentOperation] -> GetExecuteBeforeListSize();  out << v;
 
282
                count = 0;
 
283
                while ( count < (Operation[currentOperation] -> GetExecuteBeforeListSize()) )
 
284
                {
 
285
                        v = Operation[currentOperation] -> GetExecuteBeforeListItem(count); out << v;
 
286
                        count++;
 
287
                }
 
288
                v = "ExecuteAfterListSize";     out << v;       v = Operation[currentOperation] -> GetExecuteAfterListSize();   out << v;
 
289
                count = 0;
 
290
                while ( count < (Operation[currentOperation] -> GetExecuteAfterListSize()) )
 
291
                {
 
292
                        v = Operation[currentOperation] -> GetExecuteAfterListItem(count); out << v;
 
293
                        count++;
 
294
                }
 
295
                //export include state
 
296
                v = "IncludeState";             out << v;       v = Operation[currentOperation] -> GetIncluded();               out << v;
 
297
 
 
298
                v = "operation end";    out << v;       
 
299
                currentOperation++;
 
300
        }
 
301
        v = "profile end";      out << v;
 
302
 
 
303
        profile.close();
 
304
        return TRUE;
 
305
}
 
306
 
 
307
// checkTaskList =====================================================================================================================================
 
308
// Checks if the Task list is ok to proceed
 
309
bool checkTaskList()
 
310
{
 
311
        int count;
 
312
        QString tempConnect="";
 
313
        message="";
 
314
        messageCLI="";
 
315
        ask = FALSE;
 
316
        NothingIncluded=TRUE;
 
317
 
 
318
        if (TotalOperations==0)                                         //check if the operations list is empty ------------------------------
 
319
        {
 
320
                message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><b>" +
 
321
                                QObject::tr("The task list is empty")+" !!</b><br>..."+
 
322
                        QObject::tr("nothing to start"));
 
323
                messageCLI.append("\nThe task list is empty !!\n"
 
324
                        "nothing to start !!\n\n");
 
325
                ask = TRUE;
 
326
                return FALSE;
 
327
        }
 
328
 
 
329
        //first check if 2 connected operations have been selected for execution--------------------------------------------------------------
 
330
        //set NothingInluded to FALSE if 1 or more operation is included
 
331
        bool askTemp = FALSE;   QString dirNames="";    QString dirNamesCLI=""; currentOperation=0;
 
332
        while  (currentOperation < TotalOperations)
 
333
        {
 
334
                if (Operation[currentOperation] -> GetIncluded())       //if the operations is "included"
 
335
                {
 
336
                        NothingIncluded = FALSE;
 
337
 
 
338
                        tempConnect = Operation[currentOperation] -> GetConnectRestore();
 
339
                        if (tempConnect != "")                                                  //if it is connected to another operation
 
340
                        {
 
341
                                count = currentOperation+1;
 
342
                                while (count < TotalOperations)
 
343
                                {
 
344
                                        if  ( (Operation[count]->GetName() == tempConnect)      //if 2 connected operations are both included
 
345
                                        && (Operation[count] -> GetIncluded()) )
 
346
                                        {
 
347
                                                dirNames.append("* " + Operation[currentOperation]->GetName() + "<br>* " + tempConnect + "<br>");
 
348
                                                dirNamesCLI.append(Operation[currentOperation]->GetName() + "\n" + tempConnect + "\n\n");
 
349
                                                askTemp = TRUE; ask=TRUE;
 
350
                                                break;
 
351
                                        }
 
352
                                        count++;
 
353
                                }
 
354
                        }
 
355
                }
 
356
                currentOperation++;
 
357
        }
 
358
        if (askTemp)
 
359
        {
 
360
                message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>" +
 
361
                                QObject::tr("You have included both of the following connected tasks:")+"<b><br>" + dirNames + 
 
362
                                "</b>" + QObject::tr("this is not allowed for obvious reasons")+" !!<br>"+
 
363
                                QObject::tr("Please <b>uncheck appropriate include boxes</b> before proceeding")+"... <br>");
 
364
                messageCLI.append("\nYou have included both of the following connected tasks:\n" + dirNamesCLI + 
 
365
                                "this is not allowed for obvious reasons !!\n"
 
366
                                "Please uncheck appropriate include boxes before proceeding...\n\n");
 
367
        }
 
368
 
 
369
        if ( (NothingIncluded) && (TotalOperations!=0) )                //if no checkboxes are selected show this message ---------------------
 
370
        {
 
371
                message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><b>"+
 
372
                        QObject::tr("You have not included any tasks")+" !!</b><br>"
 
373
                        "..." + QObject::tr("nothing to start"));
 
374
                messageCLI.append("\nYou have not included any tasks !!\n\n"
 
375
                        "nothing to start !!\n\n");
 
376
                ask = TRUE;
 
377
                return FALSE;
 
378
        }
 
379
 
 
380
        //check if 2 or more identical destination directories are decleared & "Backup dir contents" is checked -------------------------------
 
381
        currentOperation=0;     askTemp = FALSE;        dirNames="";    dirNamesCLI="";
 
382
        QString dest1="", dest2="";
 
383
        //the following loop compares an included operation (currentoperation) with all the other included
 
384
        //to check if they share the same destination
 
385
        while  (currentOperation < TotalOperations)
 
386
        {
 
387
                dest1 = Operation[currentOperation] -> GetDestination();
 
388
                if (dest1.endsWith("/")) dest1.chop(1);
 
389
 
 
390
                if (Operation[currentOperation] -> GetIncluded())
 
391
                {
 
392
                        count = 0;
 
393
                        while (count < TotalOperations)
 
394
                        {
 
395
                                if (count == currentOperation) count++;
 
396
                                else
 
397
                                {
 
398
                                        dest2 = Operation[count] -> GetDestination();
 
399
                                        if (dest2.endsWith("/")) dest2.chop(1);
 
400
                                
 
401
                                //if this operation's destination is identical to another one's which is included and is of type 'Backup dir contents'
 
402
                                        if ( (Operation[count] -> GetIncluded()) 
 
403
                                        && ( dest1 == dest2 ) 
 
404
                                        && ( ((Operation[count] -> GetTypeDirContents()) && (!Operation[count] -> GetIncluded())) ||
 
405
                                        ((Operation[currentOperation] -> GetTypeDirContents()) && (!Operation[currentOperation] -> GetIncluded()))) )
 
406
                                        {
 
407
                                                dirNames.append("* " + Operation[currentOperation]->GetName() + "<br>");
 
408
                                                dirNamesCLI.append(Operation[currentOperation]->GetName() + "\n");
 
409
                                                askTemp = TRUE; ask=TRUE;
 
410
                                                break;
 
411
                                        }
 
412
                                        count++;
 
413
                                }
 
414
                        }
 
415
                }
 
416
                currentOperation++;
 
417
        }
 
418
        if (askTemp)
 
419
        {
 
420
                message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>" +
 
421
                                QObject::tr("The following included tasks <b>share the same destination directory</b> (all together or at groups) and at least one of them will backup the contents of a directory")+" :<br><b>"
 
422
                                + dirNames +
 
423
                                "</b>" + QObject::tr("this will lead to one task canceling the other")+" !!<br>"+
 
424
                                QObject::tr("Please uncheck appropriate include boxes or change all task types to other than '<b>Backup dir contents</b>' "
 
425
                                " or use 'Backup dir contents' together with the '<b>Only include</b>' option, before proceeding")+"...");
 
426
 
 
427
                messageCLI.append("\nThe following included tasks share the same destination directory (all together or at groups) and at least one of them will backup the contents of a directory :\n"
 
428
                                + dirNamesCLI +
 
429
                                "\nthis will lead to one task canceling the other !!\n"
 
430
                                "Please uncheck appropriate include boxes or change all task types to other than 'Backup dir contents'\n "
 
431
                                "or use 'Backup dir contents' together with the 'Only include' option, before proceeding...\n\n");
 
432
        }
 
433
 
 
434
        return TRUE;
 
435
}
 
436
 
 
437
// checkDeclaredDirs =================================================================================================================================
 
438
//Check if the declared data are ok by calling checkBackupDirs or checkSyncDirs 
 
439
bool checkDeclaredDirs()
 
440
{
 
441
        int count;
 
442
        ask=FALSE;
 
443
        NothingToDo = TRUE;
 
444
 
 
445
        QString source, dest;
 
446
 
 
447
        count = 0;
 
448
        currentOperation = 0;
 
449
        CheckedData = "";
 
450
        CheckedDataCLI = "";
 
451
        while (currentOperation < TotalOperations)
 
452
        {
 
453
                Operation[currentOperation] -> SetOK(FALSE);
 
454
                Operation[currentOperation] -> SetWARNING(FALSE);
 
455
                Operation[currentOperation] -> SetCRITICAL(FALSE);
 
456
                Operation[currentOperation] -> SetSourcePerms(FALSE);
 
457
                Operation[currentOperation] -> SetDestPerms(FALSE);
 
458
 
 
459
                if (Operation[currentOperation] -> GetIncluded())       //if the operations is "included"
 
460
                {
 
461
                        //first set  variables source & dest as well as itsPerform which will finaly decide if the task will be preformed
 
462
                        source = Operation[currentOperation] -> GetSource();
 
463
                        dest = Operation[currentOperation] -> GetDestination();
 
464
                        Operation[currentOperation] -> SetIncluded(TRUE);
 
465
                        Operation[currentOperation] -> SetPerform(TRUE);        //this will change at the next commands
 
466
 
 
467
                        if ( (Operation[currentOperation] -> GetTypeDirContents()) || (Operation[currentOperation] -> GetTypeDirName()) )       
 
468
                                checkBackupDirs(source,dest);                   //if the operation is of type "backup dir ...'
 
469
                        if (Operation[currentOperation] -> GetTypeSync())       //if the operation is of type "sync dirs'
 
470
                                checkSyncDirs(source,dest);
 
471
                }
 
472
                else
 
473
                {
 
474
                        Operation[currentOperation] -> SetIncluded(FALSE);
 
475
                        Operation[currentOperation] -> SetPerform(FALSE);       
 
476
                }
 
477
                currentOperation++;
 
478
        }
 
479
        return TRUE;
 
480
}
 
481
 
 
482
//===================================================================================================================================================
 
483
//Check if the directories to be synced are empty or don't exist
 
484
void checkSyncDirs(QString source, QString dest)
 
485
{
 
486
        Operation[currentOperation] -> SetOK(FALSE);
 
487
        Operation[currentOperation] -> SetWARNING(FALSE);
 
488
        Operation[currentOperation] -> SetCRITICAL(FALSE);
 
489
        Operation[currentOperation] -> SetSourcePerms(FALSE);
 
490
        Operation[currentOperation] -> SetDestPerms(FALSE);
 
491
 
 
492
        bool remoteSource = FALSE;
 
493
        bool remoteDest = FALSE;
 
494
 
 
495
        if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteSource()) )
 
496
        {
 
497
                if (Operation[currentOperation] -> GetRemoteModule())
 
498
                        source.prepend(":");
 
499
                source.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
 
500
                if (Operation[currentOperation] -> GetRemoteUser()!="")
 
501
                        source.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
 
502
                remoteSource = TRUE;
 
503
        }
 
504
 
 
505
        if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteDestination()) )
 
506
        {
 
507
                if (Operation[currentOperation] -> GetRemoteModule())
 
508
                        dest.prepend(":");
 
509
                dest.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
 
510
                if (Operation[currentOperation] -> GetRemoteUser()!="")
 
511
                        dest.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
 
512
                remoteDest = TRUE;
 
513
        }
 
514
 
 
515
        //If user does not have sufficient permissions for the dirA or dirB, skip it
 
516
        QFileInfo dirAFile(source);
 
517
        QFileInfo dirBFile(dest);
 
518
 
 
519
        if ( (dirAFile.exists()) && ((!dirAFile.isReadable()) || (!dirAFile.isExecutable())) && (!remoteSource) )
 
520
        {
 
521
                CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
 
522
                CheckedData.append(QObject::tr("I do not have the permission to read/enter sync directory A")+":<b><br>");
 
523
                CheckedData.append(source);
 
524
                CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
 
525
 
 
526
                CheckedDataCLI.append("[WARNING]        ->      ");
 
527
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
528
                CheckedDataCLI.append("\nI do not have the permission to read/enter sync directory A :\n");
 
529
                CheckedDataCLI.append(source);
 
530
                CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
 
531
                "_____________________________________________________________________________________________\n");
 
532
 
 
533
                Operation[currentOperation] -> SetPerform(FALSE);       //don't perform this operation
 
534
                Operation[currentOperation] -> SetSourcePerms(TRUE);
 
535
                ask=TRUE;       //ask the user if he/she wants to continue
 
536
                return;
 
537
        }
 
538
 
 
539
        if ( (dirBFile.exists()) && ((!dirBFile.isReadable()) || (!dirBFile.isExecutable())) && (!remoteDest) )
 
540
        {
 
541
                CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
 
542
                CheckedData.append(QObject::tr("I do not have the permission to read/enter sync directory B")+":<b><br>");
 
543
                CheckedData.append(dest);
 
544
                CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
 
545
 
 
546
                CheckedDataCLI.append("[WARNING]        ->      ");
 
547
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
548
                CheckedDataCLI.append("\nI do not have the permission to read/enter sync directory B :\n");
 
549
                CheckedDataCLI.append(dest);
 
550
                CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
 
551
                "_____________________________________________________________________________________________\n");
 
552
 
 
553
                ask=TRUE;       //ask the user if he/she wants to continue
 
554
                Operation[currentOperation] -> SetPerform(FALSE);       //don't perform this operation
 
555
                Operation[currentOperation] -> SetDestPerms(TRUE);
 
556
                return;
 
557
        }
 
558
 
 
559
        QDir dirA (source);
 
560
        QDir dirB (dest);
 
561
        QStringList dirAList = dirA.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
 
562
        QStringList dirBList = dirB.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
 
563
        bool dirAIsEmpty, dirBIsEmpty;
 
564
        if (dirAList.size() == 0)
 
565
                dirAIsEmpty = TRUE;
 
566
        else
 
567
                dirAIsEmpty = FALSE;
 
568
        if (dirBList.size() == 0)
 
569
                dirBIsEmpty = TRUE;
 
570
        else
 
571
                dirBIsEmpty = FALSE;
 
572
 
 
573
        //Do directories exist and are not emty ??(skip remote)                                                         ->      [ Ok ]
 
574
        if ( ( ((dirA.exists())  && !(dirAIsEmpty)) || (remoteSource) )
 
575
        && (((dirB.exists()) && !(dirBIsEmpty)) ||(remoteDest) ) )
 
576
        {
 
577
                CheckedData.append(QObject::tr("status") + ": <font color=green><b>" + QObject::tr("OK") + "</font></b><br>");
 
578
                CheckedData.append(QObject::tr("Sync directory")+" A: <b>");
 
579
                CheckedData.append(source);
 
580
                if (remoteSource)
 
581
                        CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font>");
 
582
                CheckedData.append("</b><br>" + QObject::tr("Sync directory")+" B: <b>");
 
583
                CheckedData.append(dest);
 
584
                if (remoteDest)
 
585
                        CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font>");
 
586
                CheckedData.append("</b>");
 
587
 
 
588
                CheckedDataCLI.append("[Ok]             ->      ");
 
589
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
590
                CheckedDataCLI.append("\nSync directory A       : ");
 
591
                CheckedDataCLI.append(source);
 
592
                CheckedDataCLI.append("\nSync directory B       : ");
 
593
                CheckedDataCLI.append(dest);
 
594
                CheckedDataCLI.append("\n_____________________________________________________________________________________________\n");
 
595
 
 
596
                NothingToDo = FALSE;
 
597
                Operation[currentOperation] -> SetOK(TRUE);
 
598
        }
 
599
        
 
600
        //is one or both sync dirs non-existent ??                                                                      ->      [ WARNING ]
 
601
        else if ( !(dirA.exists()) || !(dirB.exists()) )
 
602
        {
 
603
                CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
 
604
                CheckedData.append(QObject::tr("Directory")+" <b>");
 
605
                CheckedData.append(source);
 
606
                CheckedData.append("</b><br>"+QObject::tr("and/or")+" <b>");
 
607
                CheckedData.append(dest);
 
608
                CheckedData.append("</b><br><font color=red><b>"+QObject::tr("does not exist")+"</b></font>.<br>"+
 
609
                QObject::tr("I will <font color=red><b>skip</b></font> this task for that reason"));
 
610
 
 
611
                CheckedDataCLI.append("[WARNING]        ->      ");
 
612
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
613
                CheckedDataCLI.append("\nDirectory ");
 
614
                CheckedDataCLI.append(source);
 
615
                CheckedDataCLI.append("\nand/or ");
 
616
                CheckedDataCLI.append(dest);
 
617
                CheckedDataCLI.append("\ndoes not exist.\n"
 
618
                "I will SKIP this task for that reason\n"
 
619
                "_____________________________________________________________________________________________\n");
 
620
 
 
621
                Operation[currentOperation] -> SetPerform(FALSE);       //don't perform this operation
 
622
                Operation[currentOperation] -> SetWARNING(TRUE);
 
623
                ask=TRUE;
 
624
        }
 
625
 
 
626
        //Is one or both of the directories empty ??                                                                    ->      [ CRITICAL ]
 
627
        else
 
628
        {
 
629
                CheckedData.append(QObject::tr("status") + ": <font color=orange><b>"+QObject::tr("CRITICAL")+"</font></b><br>");
 
630
                CheckedData.append(QObject::tr("Directory")+" <b>");
 
631
                CheckedData.append(source);
 
632
                CheckedData.append("</b><br>"+QObject::tr("and/or")+" <b>");
 
633
                CheckedData.append(dest);
 
634
                CheckedData.append("</b><br><font color=orange><b>"+QObject::tr("is empty")+"</b></font>.<br>"+
 
635
                QObject::tr("I will <font color=orange><b>not skip</b></font> this task. Synchronizing is going to be performed anyway"));
 
636
 
 
637
                CheckedDataCLI.append("[CRITICAL]       ->      ");
 
638
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
639
                CheckedDataCLI.append("\nDirectory ");
 
640
                CheckedDataCLI.append(source);
 
641
                CheckedDataCLI.append("\nand/or ");
 
642
                CheckedDataCLI.append(dest);
 
643
                CheckedDataCLI.append("\nis empty.\n"
 
644
                "I will NOT skip this task (unless '--skip-critical' is given as argument).\n"
 
645
                "Synchronizing is going to be performed anyway !!\n"
 
646
                "_____________________________________________________________________________________________\n");
 
647
 
 
648
                ask=TRUE;       //ask the user if he/she wants to continue
 
649
                NothingToDo = FALSE;
 
650
                Operation[currentOperation] -> SetCRITICAL(TRUE);
 
651
        }
 
652
 
 
653
}
 
654
 
 
655
//===================================================================================================================================================
 
656
//Check if the source and destination backup directories are empty or don't exist
 
657
void checkBackupDirs(QString source, QString dest)
 
658
{
 
659
        Operation[currentOperation] -> SetOK(FALSE);
 
660
        Operation[currentOperation] -> SetWARNING(FALSE);
 
661
        Operation[currentOperation] -> SetCRITICAL(FALSE);
 
662
        Operation[currentOperation] -> SetSourcePerms(FALSE);
 
663
        Operation[currentOperation] -> SetDestPerms(FALSE);
 
664
 
 
665
        bool remoteSource = FALSE;
 
666
        bool remoteDest = FALSE;
 
667
 
 
668
        //first check if a remote source or dest is used so that to skip checks
 
669
        if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteSource()) )
 
670
        {
 
671
                if (Operation[currentOperation] -> GetRemoteModule())
 
672
                        source.prepend(":");
 
673
                source.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
 
674
                if (Operation[currentOperation] -> GetRemoteUser()!="")
 
675
                        source.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
 
676
                remoteSource = TRUE;
 
677
        }
 
678
        if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteDestination()) )
 
679
        {
 
680
                if (Operation[currentOperation] -> GetRemoteModule())
 
681
                        dest.prepend(":");
 
682
                dest.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
 
683
                if (Operation[currentOperation] -> GetRemoteUser()!="")
 
684
                        dest.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
 
685
                remoteDest = TRUE;
 
686
        }
 
687
 
 
688
        //If user does not have sufficient permissions for the source or dest, skip it
 
689
        QFileInfo destFile(dest);
 
690
        QFileInfo sourceFile(source);
 
691
 
 
692
        if ( (sourceFile.exists()) && ((!sourceFile.isReadable()) || (!sourceFile.isExecutable())) && (!remoteSource) )
 
693
        {
 
694
                CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
 
695
                CheckedData.append(QObject::tr("I do not have the permission to read/enter the source directory")+":<b><br>");
 
696
                CheckedData.append(source);
 
697
                CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
 
698
 
 
699
                CheckedDataCLI.append("[WARNING]        ->      ");
 
700
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
701
                CheckedDataCLI.append("\nI do not have the permission to read/enter the source directory :\n");
 
702
                CheckedDataCLI.append(source);
 
703
                CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
 
704
                "_____________________________________________________________________________________________\n");
 
705
 
 
706
                Operation[currentOperation] -> SetPerform(FALSE);       //don't perform this operation
 
707
                ask=TRUE;       //ask the user if he/she wants to continue
 
708
                Operation[currentOperation] -> SetSourcePerms(TRUE);
 
709
                return;
 
710
        }
 
711
 
 
712
        if ( (destFile.exists()) && ((!destFile.isReadable()) || (!destFile.isExecutable())) && (!remoteDest) )
 
713
        {
 
714
                CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
 
715
                CheckedData.append(QObject::tr("I do not have the permission to read/enter the destination directory")+":<b><br>");
 
716
                CheckedData.append(dest);
 
717
                CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
 
718
 
 
719
                CheckedDataCLI.append("[WARNING]        ->      ");
 
720
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
721
                CheckedDataCLI.append("\nI do not have the permission to read/enter the destination directory :\n");
 
722
                CheckedDataCLI.append(dest);
 
723
                CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
 
724
                "_____________________________________________________________________________________________\n");
 
725
 
 
726
                Operation[currentOperation] -> SetPerform(FALSE);       //don't perform this operation
 
727
                ask=TRUE;       //ask the user if he/she wants to continue
 
728
                Operation[currentOperation] -> SetDestPerms(TRUE);
 
729
                return;
 
730
        }
 
731
 
 
732
        QDir sourceDir (source);
 
733
        QDir destDir (dest);
 
734
        QStringList sourceList = sourceDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
 
735
        QStringList destList = destDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
 
736
        bool SourceIsEmpty, DestIsEmpty;
 
737
        if (sourceList.size() == 0)
 
738
                SourceIsEmpty = TRUE;
 
739
        else
 
740
                SourceIsEmpty = FALSE;
 
741
        if (destList.size() == 0)
 
742
                DestIsEmpty = TRUE;
 
743
        else
 
744
                DestIsEmpty = FALSE;
 
745
 
 
746
        //Does the source directory exist and it is not empty OR we're using remote source?? 
 
747
        if  ( ((sourceDir.exists())  && !(SourceIsEmpty)) || (remoteSource) )
 
748
        {
 
749
                //Does the destination directory exist and it is not empty ??                                                           ->      [ Ok ]
 
750
                if ( ((destDir.exists())  && !(DestIsEmpty)) || (remoteDest) )
 
751
                {
 
752
                        CheckedData.append(QObject::tr("status") + ": <font color=green><b>" + QObject::tr("OK") + "</font></b><br>");
 
753
                        CheckedData.append(QObject::tr("Source directory")+": <b>");
 
754
                        CheckedData.append(source);
 
755
                        if (remoteSource)
 
756
                                CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font>");
 
757
                        CheckedData.append("</b><br>"+QObject::tr("Destination directory")+": <b>");
 
758
                        CheckedData.append(dest);
 
759
                        if (remoteDest)
 
760
                                CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font></b>");
 
761
 
 
762
                        CheckedDataCLI.append("[Ok]             ->      ");
 
763
                        CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
764
                        CheckedDataCLI.append("\nSource directory       : ");
 
765
                        CheckedDataCLI.append(source);
 
766
                        if (remoteSource)
 
767
                                CheckedDataCLI.append(" (Using remote, check is skipped...)");
 
768
                        CheckedDataCLI.append("\nDestination directory  : ");
 
769
                        CheckedDataCLI.append(dest);
 
770
                        if (remoteDest)
 
771
                                CheckedDataCLI.append(" (Using remote, check is skipped...)");
 
772
                        CheckedDataCLI.append("\n_____________________________________________________________________________________________\n");
 
773
 
 
774
                        Operation[currentOperation] -> SetOK(TRUE);
 
775
                        NothingToDo = FALSE;
 
776
                }
 
777
                else //The destination directory does not exist or it is empty                                                  ->      [ CRITICAL ]
 
778
                {
 
779
                        CheckedData.append(QObject::tr("status") + ": <font color=orange><b>"+QObject::tr("CRITICAL")+"</font></b><br>");
 
780
                        CheckedData.append(QObject::tr("Destination directory")+": <b>");
 
781
                        CheckedData.append(dest);
 
782
                        CheckedData.append("<br><font color=orange> "+QObject::tr("is empty or does not exist")+"</font>.</b><br>"+
 
783
                        QObject::tr("This task will <font color=orange><b>not be skipped")+"</b></font> <br>"+
 
784
                        QObject::tr("The Destination Directory will be created if it doesn't exist and filled with new backup data")+".");
 
785
 
 
786
                        CheckedDataCLI.append("[CRITICAL]       ->      ");
 
787
                        CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
788
                        CheckedDataCLI.append("\nSource directory       : ");
 
789
                        CheckedDataCLI.append(source);
 
790
                        if (remoteSource)
 
791
                                CheckedDataCLI.append(" <font color=magenta>(Using remote, check is skipped...)</font>");
 
792
                        CheckedDataCLI.append("\nDestination directory  : ");
 
793
                        CheckedDataCLI.append(dest);
 
794
                        CheckedDataCLI.append(" is empty or does not exist.\n"
 
795
                        "This task will NOT be skipped (unless '--skip-critical' is given as argument)\n"
 
796
                        "The Destination Directory will be created if it doesn't exist and filled with new backup data.\n"
 
797
                        "_____________________________________________________________________________________________\n");
 
798
 
 
799
                        ask=TRUE;       //ask the user if he/she wants to continue
 
800
                        NothingToDo = FALSE;
 
801
                        Operation[currentOperation] -> SetCRITICAL(TRUE);
 
802
                }
 
803
        }
 
804
        else //The source directory does not exist or it is empty                                                               ->      [WARNING ]
 
805
        {
 
806
                CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
 
807
                CheckedData.append(QObject::tr("Source directory")+": <b>");
 
808
                CheckedData.append(source);
 
809
                CheckedData.append("<br><font color=red> "+QObject::tr("is empty or does not exist")+"</font>.</b><br>");
 
810
                CheckedData.append(QObject::tr("This task will be <font color=red><b>skipped</b></font> to protect your backup data (if any !!)"));
 
811
 
 
812
                CheckedDataCLI.append("[WARNING]        ->      ");
 
813
                CheckedDataCLI.append(Operation[currentOperation] -> GetName());
 
814
                CheckedDataCLI.append("\nSource directory       : ");
 
815
                CheckedDataCLI.append(source);
 
816
                CheckedDataCLI.append(" is empty or does not exist.\n"
 
817
                                "Destination directory  : ");
 
818
                CheckedDataCLI.append(dest);
 
819
                if (remoteDest)
 
820
                        CheckedDataCLI.append(" (Using remote, check is skipped...)");
 
821
                CheckedDataCLI.append("\nThis task will be SKIPPED to protect your backup data (if any !!)\n"
 
822
                "_____________________________________________________________________________________________\n");
 
823
 
 
824
                Operation[currentOperation] -> SetPerform(FALSE);       //don't perform this operation
 
825
                Operation[currentOperation] -> SetWARNING(TRUE);
 
826
                ask=TRUE;       //ask the user if he/she wants to continue
 
827
        }
 
828
 
 
829
}
 
830
 
 
831
// /AppendArguments =======================================================================================================
 
832
//function to append "arguments" object at a given operation according to the fields of the modify window
 
833
QStringList AppendArguments(operation *operationToAppend)
 
834
{
 
835
        QStringList arguments; int count;
 
836
        arguments << "-h" << "--progress" << "--stats"; //These are the standard arguments used by rsync
 
837
 
 
838
        //add rsync arguments   --------------------------------------------------------------------------------------------------
 
839
        if (operationToAppend -> GetOptionsRecurse())           arguments.append("-r");
 
840
        if (operationToAppend -> GetOptionsOwnership())         arguments.append("-tgo");
 
841
        if (operationToAppend -> GetOptionsSymlinks())          arguments.append("-l");
 
842
        if (operationToAppend -> GetOptionsPermissions())       arguments.append("-p");
 
843
        if (operationToAppend -> GetOptionsDevices())           arguments.append("-D");
 
844
        if (operationToAppend -> GetOptionsCVS())               arguments.append("-C");
 
845
        if (operationToAppend -> GetOptionsHardLinks())         arguments.append("-H");
 
846
        if (operationToAppend -> GetOptionsUpdate())            arguments.append("--update");
 
847
        if (operationToAppend -> GetOptionsDelete())            arguments.append("--delete-after");
 
848
        count =0;
 
849
        while ( count < (operationToAppend -> GetOptionsListSize()) )
 
850
        {
 
851
                arguments.append(operationToAppend -> GetOptionsListItem(count));
 
852
                count++;
 
853
        }
 
854
        
 
855
        //add excluded items if groupbox is checked------------------------------------------------------------------------------
 
856
        if (operationToAppend -> GetExclude())
 
857
        {
 
858
                if (operationToAppend -> GetOptionsDelete())    arguments.append("--delete-excluded");
 
859
                if (operationToAppend -> GetExcludeTemp())      arguments.append("--exclude=**/*tmp*/");
 
860
                if (operationToAppend -> GetExcludeCache()){    arguments.append("--exclude=**/*cache*/");
 
861
                                                                arguments.append("--exclude=**/*Cache*/");}
 
862
                if (operationToAppend -> GetExcludeBackup())    arguments.append("--exclude=**~");
 
863
                if (operationToAppend -> GetExcludeMount()){    arguments.append("--exclude=/mnt/*/**");
 
864
                                                                arguments.append("--exclude=/media/*/**");}
 
865
                if (operationToAppend -> GetExcludeLostFound()) arguments.append("--exclude=**/lost+found*/");
 
866
                if (operationToAppend -> GetExcludeSystem()){   arguments.append("--exclude=/var/**");
 
867
                                                                arguments.append("--exclude=/proc/**");
 
868
                                                                arguments.append("--exclude=/dev/**");
 
869
                                                                arguments.append("--exclude=/sys/**");}
 
870
                if (operationToAppend -> GetExcludeTrash()){    arguments.append("--exclude=**/*Trash*/");
 
871
                                                                arguments.append("--exclude=**/*trash*/");}
 
872
        
 
873
                //also read the custom exclude list
 
874
                count =0;
 
875
                while ( count < (operationToAppend -> GetExcludeListSize()) )
 
876
                {
 
877
                        arguments.append("--exclude=" + (operationToAppend -> GetExcludeListItem(count)) );
 
878
                        count++;
 
879
                }
 
880
        }
 
881
        //add included items if groupbox is checked------------------------------------------------------------------------------
 
882
        if (operationToAppend -> GetInclude())
 
883
        {
 
884
                count =0;
 
885
                while ( count < (operationToAppend -> GetIncludeListSize()) )
 
886
                {
 
887
                        arguments.append("--include=" + (operationToAppend -> GetIncludeListItem(count)) );
 
888
                        count++;
 
889
                }
 
890
                arguments.append("--include=*/");
 
891
                arguments.append("--exclude=*");
 
892
                arguments.append("--prune-empty-dirs");
 
893
        }
 
894
 
 
895
        //set temp strings sourceString & destString accordingly if groupbox "remote" is checked--------------------------------------------
 
896
        //also add -e ssh if "ssh" is checked & --password-file=FILE
 
897
        QString sourceString, destString, remoteHost = "";      //temp strings
 
898
        if (operationToAppend -> GetRemote())
 
899
        {
 
900
                if (operationToAppend -> GetRemoteUser() != "") //append remote user@ if applicable to temp string
 
901
                        remoteHost.append(operationToAppend -> GetRemoteUser() + "@");
 
902
 
 
903
                if (operationToAppend -> GetRemoteModule())     //append remote host: (or :: if it's a module) to temp string
 
904
                {
 
905
                        remoteHost.append(operationToAppend -> GetRemoteHost() + "::");
 
906
                        //add --password-file=FILE if password file lineEdit is not empty
 
907
                        if (operationToAppend -> GetRemotePassword() != "")
 
908
                                arguments.append("--password-file=" + (operationToAppend -> GetRemotePassword()) );
 
909
                }
 
910
                else
 
911
                        remoteHost.append(operationToAppend -> GetRemoteHost() + ":");
 
912
 
 
913
                if (operationToAppend -> GetRemoteDestination())        //set temp source & destination strings
 
914
                {       remoteHost.append(operationToAppend -> GetDestination());
 
915
                        destString = remoteHost;
 
916
                        sourceString    = operationToAppend -> GetSource();}
 
917
                else {  remoteHost.append(operationToAppend -> GetSource());
 
918
                        sourceString = remoteHost;
 
919
                        destString      = operationToAppend -> GetDestination();}
 
920
 
 
921
                //add argument for ssh if the checkbox is checked & ssh keyfile
 
922
                if (operationToAppend -> GetRemoteSSH())
 
923
                {
 
924
                        if (operationToAppend -> GetRemoteSSHPassword() != "")
 
925
                                //arguments.append("-e \"ssh -i " + uiM.lineEdit_sshPassword -> text() + "\"");
 
926
                                if (operationToAppend -> GetRemoteSSHPort() != 0)
 
927
                                        arguments.append("-e ssh -i " + operationToAppend -> GetRemoteSSHPassword() +
 
928
                                                        " -p " + countStr.setNum(operationToAppend -> GetRemoteSSHPort()) );
 
929
                                else
 
930
                                        arguments.append("-e ssh -i " + operationToAppend -> GetRemoteSSHPassword());
 
931
                        else
 
932
                                if (operationToAppend -> GetRemoteSSHPort() != 0)
 
933
                                        arguments.append("-e ssh -p " + countStr.setNum(operationToAppend -> GetRemoteSSHPort()) );
 
934
                                else
 
935
                                        arguments.append("-e ssh");
 
936
                }
 
937
        }       
 
938
        else            //Operate locally----------------------------------------------------------------------------------------
 
939
        {
 
940
                sourceString    = operationToAppend -> GetSource();
 
941
                destString      = operationToAppend -> GetDestination();
 
942
        }
 
943
 
 
944
        //set source & destination according to sourceString & destString ---------------------------------------------------------
 
945
        arguments.append(sourceString);
 
946
        arguments.append(destString);
 
947
 
 
948
        return arguments;
 
949
}
 
950
// end of global.cpp ---------------------------------------------------------------------------
 
951