| 1 | /* ------------------ global.h -------------------------------------------------------------------------------------- |
| 2 | header file for luckyBackup project |
| 3 | |
| 4 | =============================================================================================================================== |
| 5 | =============================================================================================================================== |
| 6 | This file is part of "luckyBackup" project |
| 7 | Copyright, Loukas Avgeriou |
| 8 | luckyBackup is distributed under the terms of the GNU General Public License |
| 9 | luckyBackup is free software: you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | luckyBackup is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with luckyBackup. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | |
| 23 | project version : Please see "main.cpp" for project version |
| 24 | |
| 25 | developer : luckyb |
| 26 | last modified : 22 May 2016 |
| 27 | =============================================================================================================================== |
| 28 | =============================================================================================================================== |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | #ifndef GLOBAL_H |
| 33 | #define GLOBAL_H |
| 34 | |
| 35 | #include <QString> |
| 36 | #include <QDir> |
| 37 | #include <QFile> |
| 38 | #include <QLocale> |
| 39 | #include <QTranslator> |
| 40 | #include <QLibraryInfo> |
| 41 | #include <QCoreApplication> |
| 42 | |
| 43 | class operation; |
| 44 | |
| 45 | namespace Global { |
| 46 | extern QString myHome; // user's home directory |
| 47 | extern QString currentUser; // will hold the current username (definition at luckybackupwindow.cpp) |
| 48 | extern QString const appName; // application name |
| 49 | extern double const appVersion; // application version |
| 50 | extern QString appVersionString; // application version |
| 51 | extern double const validProfileVersion; // profile version before this a profile won't be loaded |
| 52 | extern double const validScheduleVersion; // schedule version before this a schedule won't be loaded |
| 53 | extern double const validSettingsVersion; // Settings file valid version |
| 54 | extern QString luckyBackupDir; // app working directory |
| 55 | extern QString luckyBackupDefaultDir; // same as above. WINDOWS use |
| 56 | extern QString settingsFile; // settings file |
| 57 | extern QString profileDir; // profiles directory |
| 58 | extern QString defaultProfile; // default profile |
| 59 | extern QString standardDefaultProfile; // standard default profile |
| 60 | extern QString logDir; // logs directory |
| 61 | extern QString logfilename; // logfile filename - this will change according to the profile an task executed |
| 62 | extern QString cronlogString; // cron logfile full filename: "ProfileName-LastCronLog.log" |
| 63 | extern QString emailLogString; // logfile to send by email (all task logs merged) full filename: "ProfileName-email.log" |
| 64 | extern QString emailLastLogString; // email logfile full filename: "ProfileName-email-LastLog.log" |
| 65 | extern QString snapDefaultDir; // This is the directory where snapshots are placed. It lies inside the destination |
| 66 | extern QString snapChangesDir; // Snapshots changes files are stored here. It lies inside ~ |
| 67 | extern QString snapEmptyDir; // empty directory used to delete older snapshots |
| 68 | extern QString snapchangesfilename; // Snapshot changes filename. This will change according to the snapshot |
| 69 | extern QString snapChangesString; // The log lines format of the "changes" file that stores changes made for every snapshot |
| 70 | extern QString scheduleDir; // schedule directory |
| 71 | extern QString schedulefilename; // cron data filename |
| 72 | extern QString cronfilename; // cron filename |
| 73 | extern QString relativeTransDir; // translation directory when app executed but not installed |
| 74 | extern QString systemTransDir; // system translation directory (when app is installed) |
| 75 | extern QDir transDir; // the current translations directory |
| 76 | extern QTranslator appTranslator; // QTranslator that holds the applications translation |
| 77 | extern QTranslator translator_qt; //QTranslator that holds the standard Qt translations |
| 78 | extern QString locale; // String that holds the current language locale |
| 79 | extern QString relativeLicense; // licence directory when app executed but not installed |
| 80 | extern QString systemLicense; // system licence directory (when app is installed) |
| 81 | extern QString suseLicense; // system licence directory (when app is installed) - openSuse |
| 82 | extern QString debianLicense; // system licence directory (when app is installed) - debian |
| 83 | extern QString relativeManual; // manual directory when app executed but not installed |
| 84 | extern QString systemManual; // system manual directory (when app is installed) |
| 85 | extern QString suseManual; // system manual directory (when app is installed) - opensuse |
| 86 | |
| 87 | extern QString countStr; // this helps displaying integers as strings |
| 88 | extern QString message; // this is really handy to hold messages for dialogs |
| 89 | extern QString messageCLI; // this is really handy to hold messages for the Command-Line |
| 90 | extern int errorsFound; // count errors when executing rync or pre/post command |
| 91 | extern int filesTransfered; // count files transfered when executing rync |
| 92 | extern unsigned long long int bytesTransfered; // count bytes transfered when executing rync |
| 93 | |
| 94 | // Useful variables for operations --------------------------------------------------------------------------------------------------- |
| 95 | extern int const maxOperations; // The maximum number or operations permitted |
| 96 | extern int TotalOperations; // The number of available operations "operations list"- starts from 1 |
| 97 | extern int currentOperation; // this holds the current row from the operations list- starts from 0 |
| 98 | extern int removeCharLimit; // No of characters to remove from lines inside snapshot .changes file |
| 99 | extern bool modifyOK; // bool variable that says create or modify opeartion went ok |
| 100 | extern bool modifyConnected; // if the operation under modification is connected to another op, this becomes true |
| 101 | extern bool DryRun; // shows if dry-run is checked |
| 102 | extern bool ask; // becomes true if we want to ask the user if he/she wants to continue with the execution of operations or not |
| 103 | extern bool newTaskThisIs; // becomes true if "add task" is pressed and false if "modify" task is pressed |
| 104 | extern bool NothingToDo; // Becomes true if there is nothing to do when start button pressed |
| 105 | extern bool NothingIncluded; // Becomes true if there is nothing checked ("include" checkboxes) |
| 106 | extern bool crontabUpdated; // Becomes true if the user's crontab is updated |
| 107 | extern QString currentProfile; // This holds the filename of the currently used profile |
| 108 | extern QString profileName; // just holds the profile name not the full path+filename.profile |
| 109 | extern QString profileDescription; // holds a description of the profile |
| 110 | extern QFile profile; // this is the profile QFile |
| 111 | extern QFile logfile; // this is the logfile QFile |
| 112 | extern QFile snapfile; // this is the snapshot changes QFile |
| 113 | extern QString CheckedData; // String holding the current task message (OK - WARNING - CRITICAL) for info window display |
| 114 | extern QString CheckedDataCLI; // String holding the current task message (OK - WARNING - CRITICAL) for CLI display |
| 115 | extern operation *Operation[]; //The array that holds name, source, destination & arguments of "Opereations list" |
| 116 | |
| 117 | extern bool console; // these become true depending on the argument given at command line |
| 118 | extern bool NoQuestions; // do not ask any questions at console mode |
| 119 | extern bool SkipCritical; // skip critical tasks |
| 120 | extern bool silentMode; // start at silent mode |
| 121 | extern bool runImmediately; // execute a profile immediately after gui loads |
| 122 | extern bool validation; // becomes true if "validation check" button is pressed |
| 123 | extern bool KDErunning; // becomes true if desktop running is KDE |
| 124 | extern bool GNOMErunning; // becomes true if desktop running is GNOME |
| 125 | |
| 126 | // functions ------------------------------------------------------------------------------------------------------------------------ |
| 127 | extern bool argumentsTest(int , char**); // checks the arguments given at command-line and returns true if everything is ok |
| 128 | extern bool loadCurrentProfile(); // loads an already created profile |
| 129 | void declareRsyncCommand(); // Declares the rsync & ssh commands (full path for windows) |
| 130 | extern bool check_list(); // check the operations list |
| 131 | extern bool check_dirs(); // check directories of declared profile data |
| 132 | |
| 133 | void help(); // Displayes command-line usage |
| 134 | void checkSyncDirs(QString, QString); // function to check if the directories to be synced exist or are empty |
| 135 | void checkBackupDirs(QString, QString); // function to check if the source & dest dirs exist and are not empty |
| 136 | int loadProfile(QString); // loads an existing profile - text mode |
| 137 | int loadProfileQV(QString); // loads an existing profile - data mode |
| 138 | extern bool saveProfile(QString); // saves an existing profile |
| 139 | extern bool exportFullProfile(QString,QString); // function to export the .profile file + logs + snaps |
| 140 | extern int importFullProfile(QString,QString); // function to import the .profile file + logs + snaps (whatever is available) |
| 141 | extern bool checkTaskList(); // Checks if the Task list is ok to proceed |
| 142 | extern bool checkDeclaredDirs(bool); // Check if the declared data are ok by calling checkBackupDirs or checkSyncDirs |
| 143 | QStringList AppendArguments(operation*); // Set command's (normally rsync) arguments |
| 144 | extern bool writeToLog; // if the log file is ok to write this becomes true |
| 145 | extern QString logFileUpdate(QString, QString, int); // Update the logfile with some string |
| 146 | extern bool checkMountPoint(QString); // Check if a path belongs to a mountpoint or is a mountpoint itself |
| 147 | void setTextMessages(QString,QString,bool,bool,QString,QString,QString); // function to set text feedback for the user |
| 148 | extern QString fixWinPathForRsync(QString,bool); // Fixes a windows path for rsync use |
| 149 | extern QString calculateLastPath(QString); // Calculates the last part of a path eg path=user@host:destination\path\here -> returns "here" |
| 150 | |
| 151 | extern QString emailCommand; |
| 152 | extern QString emailArguments; |
| 153 | extern bool emailNever; |
| 154 | extern bool emailError; |
| 155 | extern bool emailSchedule; |
| 156 | extern bool emailTLS; |
| 157 | extern QString emailFrom; |
| 158 | extern QString emailTo; |
| 159 | extern QString emailSubject; |
| 160 | extern QString emailSMTP; |
| 161 | extern QString emailBody; |
| 162 | extern QString emailDefaultSubject; // Holds the default subject |
| 163 | extern QString emailDefaultBody; // Holds the default body text |
| 164 | extern QString emailDefaultCommand; // Holds the default email command |
| 165 | extern QString emailDefaultArguments; // Holds the default email arguments |
| 166 | extern QString emailDefaultWinCommand; // Holds the default email command - WINDOWS |
| 167 | extern QString emailDefaultWinArguments; // Holds the default email arguments - WINDOWS |
| 168 | extern QString sendEmailNow(bool); // Send an email after a profile run. bool is true if called for testing purposes |
| 169 | |
| 170 | extern QString rsyncDefaultCommand; // Holds the default rsync command |
| 171 | extern QString sshDefaultCommand; // Holds the default ssh command |
| 172 | |
| 173 | // WINDOWS related variables. Also search variables above for "WINDOWS use" |
| 174 | extern QString rsyncDefaultWinCommand; // Holds the default rsync command for windows |
| 175 | extern QString sshDefaultWinCommand; // Holds the default ssh command for windows |
| 176 | extern QString appPath; // This is used for windows app path. It's also causing a ... |
| 177 | //"QCoreApplication::applicationDirPath: Please instantiate the QApplication object first" WARNING message |
| 178 | //extern QString rsyncDefaultWinCommand; // Holds the default rsync command for windows |
| 179 | //extern QString sshDefaultWinCommand; // Holds the default ssh command for windows |
| 180 | extern QString mapdrive; |
| 181 | extern QString vshadowDir; |
| 182 | extern QString vshadowDefaultDir; |
| 183 | extern QString dosdevCommand; |
| 184 | extern QString dosdevDefaultCommand; |
| 185 | extern QString cygpathCommand; |
| 186 | extern QString cygpathDefaultCommand; |
| 187 | extern bool isTempDirPath; |
| 188 | extern QString tempDirPath; |
| 189 | extern QString tempDefaultDirPath; |
| 190 | void setAppDir(QString s); |
| 191 | /* disable vss until |
| 192 | int doVss=0; |
| 193 | int vssPos=0; |
| 194 | int vssErrPos=0; |
| 195 | QTimer *vssTimer; |
| 196 | int vssSleepTime=50; |
| 197 | int vssReadSize=400; |
| 198 | QFile *pipeVssFile; |
| 199 | QFile *pipeVssErrFile;*/ |
| 200 | //QString createWinMkdirCommand(QString tempPath,bool vss,QStringList rsyncArgs,bool logGui); |
| 201 | extern QString createWinRsyncCommand(QString tempPath,bool vss,QStringList rsyncArgs,bool logGui=true); |
| 202 | // END of Windows related variables |
| 203 | |
| 204 | extern QString rsyncCommandPath; // holds the full path of the rsync command for WINDOWS or just "rsync" for *nix |
| 205 | extern QString sshCommandPath; // holds the full path of the ssh command for WINDOWS or just "ssh" for *nix |
| 206 | |
| 207 | extern QString XnixSLASH; // holds the default Xnix slash which is / |
| 208 | |
| 209 | extern bool OS2running; |
| 210 | extern QString SLASH; |
| 211 | extern bool WINrunning; |
| 212 | extern bool notXnixRunning; |
| 213 | } |
| 214 | using namespace Global; |
| 215 | #endif |
| 216 | // end of global.h-------------------------------------------------------------- |