| 1 | /* ---------------------------------- winDialog.cpp -------------------------------------------------------------------------- |
| 2 | Class to display a dialog and declare rsync and ssh paths |
| 3 | |
| 4 | =============================================================================================================================== |
| 5 | =============================================================================================================================== |
| 6 | This file is part of "luckyBackup" project |
| 7 | Copyright, Loukas Avgeriou |
| 8 | luckyBackup is distributed under the terms of the GNU General Public License |
| 9 | luckyBackup is free software: you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | luckyBackup is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with luckyBackup. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | |
| 23 | project version : Please see "main.cpp" for project version |
| 24 | |
| 25 | developer : luckyb |
| 26 | last modified : 22 May 2016 |
| 27 | |
| 28 | =============================================================================================================================== |
| 29 | =============================================================================================================================== |
| 30 | */ |
| 31 | |
| 32 | #include "winDialog.h" |
| 33 | |
| 34 | #include <QSignalMapper> |
| 35 | #include <QDirModel> |
| 36 | #include <QCompleter> |
| 37 | #include <QCloseEvent> |
| 38 | |
| 39 | #include "qdirdialog.h" |
| 40 | #include "global.h" |
| 41 | |
| 42 | // class winDialog Constructor================================================================================================= |
| 43 | // Displays a simple dialog with text info, ok-cancel buttons and lineEdits for user input |
| 44 | winDialog::winDialog (QWidget *parent) : QDialog (parent) |
| 45 | { |
| 46 | uiD.setupUi(this); |
| 47 | |
| 48 | uiD.lineEdit_rsyncPath -> setText(rsyncCommandPath); |
| 49 | uiD.lineEdit_sshPath -> setText(sshCommandPath); |
| 50 | uiD.lineEdit_cygpath -> setText(cygpathCommand); |
| 51 | uiD.lineEdit_dosdev -> setText(dosdevCommand); |
| 52 | uiD.lineEdit_vshadow -> setText(vshadowDir); |
| 53 | uiD.lineEdit_tempdir -> setText(tempDirPath); |
| 54 | uiD.lineEdit_appdir-> setText(luckyBackupDir); |
| 55 | |
| 56 | |
| 57 | //connect okay & cancel pushButton SLOTs ---------------- |
| 58 | connect ( uiD.pushButton_ok, SIGNAL( clicked() ), this, SLOT( okay() ) ); |
| 59 | connect ( uiD.pushButton_cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) ); |
| 60 | |
| 61 | //Connect all toolButtons with the browse SLOT |
| 62 | //Map all the toolButton signals and transmit a different integer depending on the toolbutton |
| 63 | QSignalMapper *signalMapper = new QSignalMapper(this); |
| 64 | signalMapper -> setMapping ( uiD.toolButton_rsync, 0 ); |
| 65 | connect (uiD.toolButton_rsync, SIGNAL (clicked() ), signalMapper , SLOT (map())); |
| 66 | signalMapper -> setMapping ( uiD.toolButton_ssh, 1 ); |
| 67 | connect (uiD.toolButton_ssh, SIGNAL (clicked() ), signalMapper , SLOT (map())); |
| 68 | signalMapper -> setMapping ( uiD.toolButton_cygpath, 2 ); |
| 69 | connect (uiD.toolButton_cygpath, SIGNAL (clicked() ), signalMapper , SLOT (map())); |
| 70 | signalMapper -> setMapping ( uiD.toolButton_dosdev, 3 ); |
| 71 | connect (uiD.toolButton_dosdev, SIGNAL (clicked() ), signalMapper , SLOT (map())); |
| 72 | signalMapper -> setMapping ( uiD.toolButton_vshadow, 4 ); |
| 73 | connect (uiD.toolButton_vshadow, SIGNAL (clicked() ), signalMapper , SLOT (map())); |
| 74 | signalMapper -> setMapping ( uiD.toolButton_tempdir, 5 ); |
| 75 | connect (uiD.toolButton_tempdir, SIGNAL (clicked() ), signalMapper , SLOT (map())); |
| 76 | signalMapper -> setMapping ( uiD.toolButton_appdir, 6 ); |
| 77 | connect (uiD.toolButton_appdir, SIGNAL (clicked() ), signalMapper , SLOT (map())); |
| 78 | connect(signalMapper, SIGNAL(mapped( const int)), this, SLOT( browse( const int) ) ); |
| 79 | |
| 80 | //Connect all toolButtons with the useDefault SLOT |
| 81 | //Map all the toolButton signals and transmit a different integer depending on the toolbutton |
| 82 | QSignalMapper *signalMapper2 = new QSignalMapper(this); |
| 83 | signalMapper2 -> setMapping ( uiD.toolButton_defaultRsync, 0 ); |
| 84 | connect (uiD.toolButton_defaultRsync, SIGNAL (clicked() ), signalMapper2 , SLOT (map())); |
| 85 | signalMapper2 -> setMapping ( uiD.toolButton_defaultSsh, 1 ); |
| 86 | connect (uiD.toolButton_defaultSsh, SIGNAL (clicked() ), signalMapper2 , SLOT (map())); |
| 87 | signalMapper2 -> setMapping ( uiD.toolButton_defaultCygpath, 2 ); |
| 88 | connect (uiD.toolButton_defaultCygpath, SIGNAL (clicked() ), signalMapper2 , SLOT (map())); |
| 89 | signalMapper2 -> setMapping ( uiD.toolButton_defaultDosdev, 3 ); |
| 90 | connect (uiD.toolButton_defaultDosdev, SIGNAL (clicked() ), signalMapper2 , SLOT (map())); |
| 91 | signalMapper2 -> setMapping ( uiD.toolButton_defaultVshadow, 4 ); |
| 92 | connect (uiD.toolButton_defaultVshadow, SIGNAL (clicked() ), signalMapper2 , SLOT (map())); |
| 93 | signalMapper2 -> setMapping ( uiD.toolButton_defaultTempdir, 5 ); |
| 94 | connect (uiD.toolButton_defaultTempdir, SIGNAL (clicked() ), signalMapper2 , SLOT (map())); |
| 95 | signalMapper2 -> setMapping ( uiD.toolButton_defaultAppdir, 6 ); |
| 96 | connect (uiD.toolButton_defaultAppdir, SIGNAL (clicked() ), signalMapper2 , SLOT (map())); |
| 97 | connect(signalMapper2, SIGNAL(mapped( const int)), this, SLOT( useDefault( const int) ) ); |
| 98 | |
| 99 | //initialize a completer for the lineEdits |
| 100 | QCompleter *completer = new QCompleter(this); |
| 101 | completer -> setModel(new QDirModel(completer)); |
| 102 | uiD.lineEdit_rsyncPath -> setCompleter(completer); |
| 103 | uiD.lineEdit_sshPath -> setCompleter(completer); |
| 104 | uiD.lineEdit_cygpath -> setCompleter(completer); |
| 105 | uiD.lineEdit_dosdev -> setCompleter(completer); |
| 106 | uiD.lineEdit_vshadow -> setCompleter(completer); |
| 107 | uiD.lineEdit_tempdir -> setCompleter(completer); |
| 108 | uiD.lineEdit_appdir -> setCompleter(completer); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | // --------------------------------okay pressed------------------------------------------------ |
| 113 | void winDialog::okay() |
| 114 | { |
| 115 | rsyncCommandPath = uiD.lineEdit_rsyncPath -> text(); |
| 116 | sshCommandPath = uiD.lineEdit_sshPath -> text(); |
| 117 | cygpathCommand = uiD.lineEdit_cygpath -> text(); |
| 118 | dosdevCommand = uiD.lineEdit_dosdev -> text(); |
| 119 | vshadowDir = uiD.lineEdit_vshadow -> text(); |
| 120 | tempDirPath = uiD.lineEdit_tempdir -> text(); |
| 121 | luckyBackupDir = uiD.lineEdit_appdir -> text(); |
| 122 | // if (!vshadowDir.endsWith(SLASH)) |
| 123 | // vshadowDir=vshadowDir+SLASH; |
| 124 | // if (!tempDirPath.endsWith(SLASH)) |
| 125 | // tempDirPath=tempDirPath+SLASH; |
| 126 | if (!luckyBackupDir.endsWith(SLASH)) |
| 127 | luckyBackupDir=luckyBackupDir+SLASH; |
| 128 | setAppDir(luckyBackupDir); |
| 129 | |
| 130 | close(); |
| 131 | } |
| 132 | |
| 133 | // --------------------------------cancel pressed------------------------------------------------ |
| 134 | void winDialog::cancel() |
| 135 | { |
| 136 | close(); |
| 137 | } |
| 138 | |
| 139 | void winDialog::closeEvent(QCloseEvent *event) |
| 140 | { |
| 141 | event->accept(); |
| 142 | } |
| 143 | |
| 144 | // browse button pressed===================================================================================================== |
| 145 | //opens a QFileDialog to browse for files/folders locally |
| 146 | void winDialog::browse(const int type) |
| 147 | { |
| 148 | QString newLineEdit; |
| 149 | QDirDialog* fd; |
| 150 | |
| 151 | switch (type) |
| 152 | { |
| 153 | //rsync browse button |
| 154 | case 0: newLineEdit = QFileDialog::getOpenFileName (this, tr("Select rsync command", |
| 155 | "file selection dialog title"),uiD.lineEdit_rsyncPath -> text(),tr("Executable Files (*.exe)")); |
| 156 | if (newLineEdit != "") //if something is selected indeed |
| 157 | uiD.lineEdit_rsyncPath -> setText(modifySlashes(newLineEdit)); |
| 158 | break; |
| 159 | //ssh browse button |
| 160 | case 1: newLineEdit = QFileDialog::getOpenFileName (this, tr("Select ssh command", |
| 161 | "file selection dialog title"),uiD.lineEdit_sshPath -> text(),tr("Executable Files (*.exe)")); |
| 162 | if (newLineEdit != "") //if something is selected indeed |
| 163 | uiD.lineEdit_sshPath -> setText(modifySlashes(newLineEdit)); |
| 164 | break; |
| 165 | //cygpath browse button |
| 166 | case 2: newLineEdit = QFileDialog::getOpenFileName (this, tr("Select cygpath command", |
| 167 | "file selection dialog title"),uiD.lineEdit_cygpath -> text(),tr("Executable Files (*.exe)")); |
| 168 | if (newLineEdit != "") //if something is selected indeed |
| 169 | uiD.lineEdit_cygpath -> setText(modifySlashes(newLineEdit)); |
| 170 | break; |
| 171 | //dosdev browse button |
| 172 | case 3: newLineEdit = QFileDialog::getOpenFileName (this, tr("Select dosdev command", |
| 173 | "file selection dialog title"),uiD.lineEdit_dosdev -> text(),tr("Executable Files (*.exe)")); |
| 174 | if (newLineEdit != "") //if something is selected indeed |
| 175 | uiD.lineEdit_dosdev -> setText(modifySlashes(newLineEdit)); |
| 176 | break; |
| 177 | //vshadow browse button |
| 178 | case 4: |
| 179 | fd = new QDirDialog( ".exe", uiD.lineEdit_vshadow -> text(), this, |
| 180 | "Dir selection" ); |
| 181 | fd->setWindowTitle( "Select vshadow directory" ); |
| 182 | // show the dialog |
| 183 | if( fd->exec() == QDialog::Accepted ) |
| 184 | newLineEdit = (fd->directory()).absolutePath(); |
| 185 | if (newLineEdit != "") //if something is selected indeed |
| 186 | uiD.lineEdit_vshadow -> setText(modifySlashes(newLineEdit)); |
| 187 | break; |
| 188 | //temp browse button |
| 189 | case 5: |
| 190 | fd = new QDirDialog( "", uiD.lineEdit_tempdir -> text(), this, |
| 191 | "Dir selection" ); |
| 192 | fd->setWindowTitle( "Select temporary directory" ); |
| 193 | // show the dialog |
| 194 | if( fd->exec() == QDialog::Accepted ) |
| 195 | newLineEdit = (fd->directory()).absolutePath(); |
| 196 | if (newLineEdit != "") //if something is selected indeed |
| 197 | uiD.lineEdit_tempdir -> setText(modifySlashes(newLineEdit)); |
| 198 | break; |
| 199 | //luckybackup browse button |
| 200 | case 6: |
| 201 | fd = new QDirDialog( ".ini", uiD.lineEdit_appdir -> text(), this, |
| 202 | "Dir selection" ); |
| 203 | fd->setWindowTitle( "Select luckybackup directory" ); |
| 204 | // show the dialog |
| 205 | if( fd->exec() == QDialog::Accepted ) |
| 206 | newLineEdit = (fd->directory()).absolutePath(); |
| 207 | if (newLineEdit != "") //if something is selected indeed |
| 208 | uiD.lineEdit_appdir -> setText(modifySlashes(newLineEdit)); |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | } |
| 213 | |
| 214 | // default button pressed===================================================================================================== |
| 215 | //opens a QFileDialog to browse for files/folders locally |
| 216 | //This dialog is possible only for non-*nix systems |
| 217 | void winDialog::useDefault(const int type) |
| 218 | { |
| 219 | switch (type) |
| 220 | { |
| 221 | //rsync default button |
| 222 | case 0: if (WINrunning) |
| 223 | uiD.lineEdit_rsyncPath -> setText(rsyncDefaultWinCommand); // Default rsync path for windows (declared in global.h) |
| 224 | if (OS2running) |
| 225 | uiD.lineEdit_rsyncPath -> setText(rsyncDefaultCommand); // Default rsync path for OS2 (declared in global.h) |
| 226 | break; |
| 227 | //ssh default button |
| 228 | case 1: if (WINrunning) |
| 229 | uiD.lineEdit_sshPath -> setText(sshDefaultWinCommand); // Default ssh path for windows (declared in global.h) |
| 230 | if (OS2running) |
| 231 | uiD.lineEdit_sshPath -> setText(sshDefaultCommand); // Default ssh path for OS2 (declared in global.h) |
| 232 | break; |
| 233 | case 2: |
| 234 | uiD.lineEdit_cygpath -> setText(cygpathDefaultCommand); |
| 235 | break; |
| 236 | case 3: |
| 237 | uiD.lineEdit_dosdev -> setText(dosdevDefaultCommand); |
| 238 | break; |
| 239 | case 4: |
| 240 | uiD.lineEdit_vshadow -> setText(vshadowDefaultDir); |
| 241 | break; |
| 242 | case 5: |
| 243 | uiD.lineEdit_tempdir -> setText(tempDefaultDirPath); |
| 244 | break; |
| 245 | case 6: |
| 246 | uiD.lineEdit_appdir -> setText(luckyBackupDefaultDir); |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // modifySlashes =========================================================================================================== |
| 252 | // function to change / to \ for windows (normally when file dialog is used) |
| 253 | QString winDialog::modifySlashes(QString pathToModify) |
| 254 | { |
| 255 | pathToModify.replace("/",SLASH); |
| 256 | return pathToModify; |
| 257 | } |
| 258 | |
| 259 | // end of winDialog.cpp --------------------------------------------------------------------------- |
| 260 |