Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 922523b..1c854d9 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -28,123 +28,123 @@ | |||
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <dirent.h> | 29 | #include <dirent.h> |
30 | 30 | ||
31 | #define HEADER_NAME 0 | 31 | #define HEADER_NAME 0 |
32 | #define HEADER_BACKUP 1 | 32 | #define HEADER_BACKUP 1 |
33 | #define BACKUP_LOCATION 2 | 33 | #define BACKUP_LOCATION 2 |
34 | 34 | ||
35 | #define EXTENSION ".bck" | 35 | #define EXTENSION ".bck" |
36 | 36 | ||
37 | const QString tempFileName = "/tmp/backup.err"; | 37 | const QString tempFileName = "/tmp/backup.err"; |
38 | 38 | ||
39 | 39 | ||
40 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | 40 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) |
41 | : BackupAndRestoreBase(parent, name){ | 41 | : BackupAndRestoreBase(parent, name, fl){ |
42 | this->showMaximized(); | 42 | this->showMaximized(); |
43 | backupList->header()->hide(); | 43 | backupList->header()->hide(); |
44 | restoreList->header()->hide(); | 44 | restoreList->header()->hide(); |
45 | connect(backupButton, SIGNAL(clicked()), | 45 | connect(backupButton, SIGNAL(clicked()), |
46 | this, SLOT(backupPressed())); | 46 | this, SLOT(backupPressed())); |
47 | connect(restoreButton, SIGNAL(clicked()), | 47 | connect(restoreButton, SIGNAL(clicked()), |
48 | this, SLOT(restore())); | 48 | this, SLOT(restore())); |
49 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | 49 | connect(backupList, SIGNAL(clicked( QListViewItem * )), |
50 | this, SLOT(selectItem(QListViewItem*))); | 50 | this, SLOT(selectItem(QListViewItem*))); |
51 | connect(restoreSource, SIGNAL(activated( int )), | 51 | connect(restoreSource, SIGNAL(activated( int )), |
52 | this, SLOT(sourceDirChanged(int))); | 52 | this, SLOT(sourceDirChanged(int))); |
53 | connect(updateList, SIGNAL(clicked()), | 53 | connect(updateList, SIGNAL(clicked()), |
54 | this, SLOT( fileListUpdate())); | 54 | this, SLOT( fileListUpdate())); |
55 | 55 | ||
56 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", | 56 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", |
57 | QDir::homeDirPath() + "/Settings/"); | 57 | QDir::homeDirPath() + "/Settings/"); |
58 | selectItem(applicationSettings); | 58 | selectItem(applicationSettings); |
59 | applicationSettings = new QListViewItem(backupList, "Application Data", "", | 59 | applicationSettings = new QListViewItem(backupList, "Application Data", "", |
60 | QDir::homeDirPath() + "/Applications/"); | 60 | QDir::homeDirPath() + "/Applications/"); |
61 | selectItem(applicationSettings); | 61 | selectItem(applicationSettings); |
62 | documents= new QListViewItem(backupList, "Documents", "", | 62 | documents= new QListViewItem(backupList, "Documents", "", |
63 | QDir::homeDirPath() + "/Documents/"); | 63 | QDir::homeDirPath() + "/Documents/"); |
64 | selectItem(documents); | 64 | selectItem(documents); |
65 | 65 | ||
66 | scanForApplicationSettings(); | 66 | scanForApplicationSettings(); |
67 | 67 | ||
68 | Config config("BackupAndRestore"); | 68 | Config config("BackupAndRestore"); |
69 | config.setGroup("General"); | 69 | config.setGroup("General"); |
70 | int totalLocations = config.readNumEntry("totalLocations",0); | 70 | int totalLocations = config.readNumEntry("totalLocations",0); |
71 | 71 | ||
72 | //todo make less static here and use Storage class to get infos | 72 | //todo make less static here and use Storage class to get infos |
73 | if(totalLocations == 0){ | 73 | if(totalLocations == 0){ |
74 | backupLocations.insert("Documents", "/root/Documents"); | 74 | backupLocations.insert("Documents", "/root/Documents"); |
75 | backupLocations.insert("CF", "/mnt/cf"); | 75 | backupLocations.insert("CF", "/mnt/cf"); |
76 | backupLocations.insert("SD", "/mnt/card"); | 76 | backupLocations.insert("SD", "/mnt/card"); |
77 | } | 77 | } |
78 | else{ | 78 | else{ |
79 | for(int i = 0; i < totalLocations; i++){ | 79 | for(int i = 0; i < totalLocations; i++){ |
80 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), | 80 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), |
81 | config.readEntry(QString("backupLocation_%1").arg(i))); | 81 | config.readEntry(QString("backupLocation_%1").arg(i))); |
82 | } | 82 | } |
83 | } | 83 | } |
84 | QMap<QString, QString>::Iterator it; | 84 | QMap<QString, QString>::Iterator it; |
85 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ | 85 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ |
86 | storeToLocation->insertItem(it.key()); | 86 | storeToLocation->insertItem(it.key()); |
87 | restoreSource->insertItem(it.key()); | 87 | restoreSource->insertItem(it.key()); |
88 | } | 88 | } |
89 | 89 | ||
90 | // Read the list of items to ignore. | 90 | // Read the list of items to ignore. |
91 | QList<QString> dontBackupList; | 91 | QList<QString> dontBackupList; |
92 | dontBackupList.setAutoDelete(true); | 92 | dontBackupList.setAutoDelete(true); |
93 | config.setGroup("DontBackup"); | 93 | config.setGroup("DontBackup"); |
94 | int total = config.readNumEntry("Total", 0); | 94 | int total = config.readNumEntry("Total", 0); |
95 | for(int i = 0; i < total; i++){ | 95 | for(int i = 0; i < total; i++){ |
96 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | 96 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); |
97 | } | 97 | } |
98 | 98 | ||
99 | QList<QListViewItem> list; | 99 | QList<QListViewItem> list; |
100 | getAllItems(backupList->firstChild(), list); | 100 | getAllItems(backupList->firstChild(), list); |
101 | 101 | ||
102 | for(uint i = 0; i < list.count(); i++){ | 102 | for(uint i = 0; i < list.count(); i++){ |
103 | QString text = list.at(i)->text(HEADER_NAME); | 103 | QString text = list.at(i)->text(HEADER_NAME); |
104 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ | 104 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ |
105 | if(*dontBackupList.at(i2) == text){ | 105 | if(*dontBackupList.at(i2) == text){ |
106 | selectItem(list.at(i)); | 106 | selectItem(list.at(i)); |
107 | break; | 107 | break; |
108 | } | 108 | } |
109 | } | 109 | } |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | BackupAndRestore::~BackupAndRestore(){ | 113 | BackupAndRestore::~BackupAndRestore(){ |
114 | QList<QListViewItem> list; | 114 | QList<QListViewItem> list; |
115 | getAllItems(backupList->firstChild(), list); | 115 | getAllItems(backupList->firstChild(), list); |
116 | 116 | ||
117 | Config config("BackupAndRestore"); | 117 | Config config("BackupAndRestore"); |
118 | config.setGroup("DontBackup"); | 118 | config.setGroup("DontBackup"); |
119 | config.clearGroup(); | 119 | config.clearGroup(); |
120 | 120 | ||
121 | int count = 0; | 121 | int count = 0; |
122 | for(uint i = 0; i < list.count(); i++){ | 122 | for(uint i = 0; i < list.count(); i++){ |
123 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 123 | if(list.at(i)->text(HEADER_BACKUP) == ""){ |
124 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 124 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
125 | count++; | 125 | count++; |
126 | } | 126 | } |
127 | } | 127 | } |
128 | config.writeEntry("Total", count); | 128 | config.writeEntry("Total", count); |
129 | 129 | ||
130 | // Remove Temp File | 130 | // Remove Temp File |
131 | if ( QFile::exists( tempFileName ) ) | 131 | if ( QFile::exists( tempFileName ) ) |
132 | QFile::remove( tempFileName ); | 132 | QFile::remove( tempFileName ); |
133 | } | 133 | } |
134 | 134 | ||
135 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ | 135 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ |
136 | while(item){ | 136 | while(item){ |
137 | if(item->childCount() > 0) | 137 | if(item->childCount() > 0) |
138 | getAllItems(item->firstChild(), list); | 138 | getAllItems(item->firstChild(), list); |
139 | list.append(item); | 139 | list.append(item); |
140 | item = item->nextSibling(); | 140 | item = item->nextSibling(); |
141 | } | 141 | } |
142 | return list; | 142 | return list; |
143 | } | 143 | } |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. | 146 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. |
147 | * and changing the icon to match | 147 | * and changing the icon to match |
148 | * @param currentItem the item to swich the selection choice. | 148 | * @param currentItem the item to swich the selection choice. |
149 | */ | 149 | */ |
150 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ | 150 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ |
@@ -170,120 +170,120 @@ void BackupAndRestore::scanForApplicationSettings(){ | |||
170 | while ( (fi=it.current()) ) { | 170 | while ( (fi=it.current()) ) { |
171 | // qDebug((d.path()+fi->fileName()).latin1()); | 171 | // qDebug((d.path()+fi->fileName()).latin1()); |
172 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) { | 172 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) { |
173 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 173 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
174 | selectItem(newItem); | 174 | selectItem(newItem); |
175 | } | 175 | } |
176 | ++it; | 176 | ++it; |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
180 | /** | 180 | /** |
181 | * The "Backup" button has been pressed. Get a list of all of the files that | 181 | * The "Backup" button has been pressed. Get a list of all of the files that |
182 | * should be backed up. If there are no files, emit and error and exit. | 182 | * should be backed up. If there are no files, emit and error and exit. |
183 | * Determine the file name to store the backup in. Backup the file(s) using | 183 | * Determine the file name to store the backup in. Backup the file(s) using |
184 | * tar and gzip --best. Report failure or success | 184 | * tar and gzip --best. Report failure or success |
185 | */ | 185 | */ |
186 | void BackupAndRestore::backupPressed(){ | 186 | void BackupAndRestore::backupPressed(){ |
187 | QString backupFiles; | 187 | QString backupFiles; |
188 | if(getBackupFiles(backupFiles, NULL) == 0){ | 188 | if(getBackupFiles(backupFiles, NULL) == 0){ |
189 | QMessageBox::critical(this, "Message", | 189 | QMessageBox::critical(this, "Message", |
190 | "No items selected.",QString("Ok") ); | 190 | "No items selected.",QString("Ok") ); |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | 193 | ||
194 | setCaption(tr("Backup and Restore... working...")); | 194 | setCaption(tr("Backup and Restore... working...")); |
195 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 195 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
196 | 196 | ||
197 | QDateTime datetime = QDateTime::currentDateTime(); | 197 | QDateTime datetime = QDateTime::currentDateTime(); |
198 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 198 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
199 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 199 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
200 | 200 | ||
201 | outputFile += "/" + dateString; | 201 | outputFile += "/" + dateString; |
202 | 202 | ||
203 | QString t = outputFile; | 203 | QString t = outputFile; |
204 | int c = 1; | 204 | int c = 1; |
205 | while(QFile::exists(outputFile + EXTENSION)){ | 205 | while(QFile::exists(outputFile + EXTENSION)){ |
206 | outputFile = t + QString("%1").arg(c); | 206 | outputFile = t + QString("%1").arg(c); |
207 | c++; | 207 | c++; |
208 | } | 208 | } |
209 | 209 | ||
210 | // We execute tar and compressing its output with gzip.. | 210 | // We execute tar and compressing its output with gzip.. |
211 | // The error output will be written into a temp-file which could be provided | 211 | // The error output will be written into a temp-file which could be provided |
212 | // for debugging.. | 212 | // for debugging.. |
213 | qDebug( "Storing file: %s", outputFile.latin1() ); | 213 | qDebug( "Storing file: %s", outputFile.latin1() ); |
214 | outputFile += EXTENSION; | 214 | outputFile += EXTENSION; |
215 | 215 | ||
216 | qWarning( QString("(tar -c %1 | gzip > %2 ) 2> %3") | 216 | qWarning( QString("(tar -c %1 | gzip > %2 ) 2> %3") |
217 | .arg( backupFiles ) | 217 | .arg( backupFiles ) |
218 | .arg( outputFile.latin1() ) | 218 | .arg( outputFile.latin1() ) |
219 | .arg( tempFileName.latin1() ) ); | 219 | .arg( tempFileName.latin1() ) ); |
220 | 220 | ||
221 | 221 | ||
222 | int r = system( QString("(tar -c %1 | gzip > %2 ) 2> %3") | 222 | int r = system( QString("(tar -c %1 | gzip > %2 ) 2> %3") |
223 | .arg( backupFiles ) | 223 | .arg( backupFiles ) |
224 | .arg( outputFile.latin1() ) | 224 | .arg( outputFile.latin1() ) |
225 | .arg( tempFileName.latin1() ) ); | 225 | .arg( tempFileName.latin1() ) ); |
226 | 226 | ||
227 | if(r != 0){ | 227 | if(r != 0){ |
228 | perror("Error: "); | 228 | perror("Error: "); |
229 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 229 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
230 | 230 | ||
231 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | 231 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" |
232 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ | 232 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ |
233 | 233 | ||
234 | case 1: | 234 | case 1: |
235 | qWarning("Details pressed !"); | 235 | qWarning("Details pressed !"); |
236 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 236 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
237 | QFile errorFile( tempFileName ); | 237 | QFile errorFile( tempFileName ); |
238 | if ( errorFile.open(IO_ReadOnly) ) { | 238 | if ( errorFile.open(IO_ReadOnly) ) { |
239 | QTextStream t( &errorFile ); | 239 | QTextStream t( &errorFile ); |
240 | QString s; | 240 | QString s; |
241 | while ( !t.eof() ) { // until end of file... | 241 | while ( !t.eof() ) { // until end of file... |
242 | s += t.readLine(); // line of text excluding '\n' | 242 | s += t.readLine(); // line of text excluding '\n' |
243 | } | 243 | } |
244 | errorFile.close(); | 244 | errorFile.close(); |
245 | 245 | ||
246 | pErrDialog->m_textarea->setText( s ); | 246 | pErrDialog->m_textarea->setText( s ); |
247 | }else{ | 247 | }else{ |
248 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); | 248 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); |
249 | } | 249 | } |
250 | pErrDialog->showMaximized(); | 250 | pErrDialog->showMaximized(); |
251 | pErrDialog->exec(); | 251 | pErrDialog->exec(); |
252 | delete pErrDialog; | 252 | delete pErrDialog; |
253 | break; | 253 | break; |
254 | } | 254 | } |
255 | setCaption(tr("Backup and Restore.. Failed !!")); | 255 | setCaption(tr("Backup and Restore.. Failed !!")); |
256 | return; | 256 | return; |
257 | } | 257 | } |
258 | else{ | 258 | else{ |
259 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); | 259 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); |
260 | 260 | ||
261 | } | 261 | } |
262 | setCaption(tr("Backup and Restore")); | 262 | setCaption(tr("Backup and Restore")); |
263 | } | 263 | } |
264 | 264 | ||
265 | /*** | 265 | /*** |
266 | * Get a list of all of the files to backup. | 266 | * Get a list of all of the files to backup. |
267 | */ | 267 | */ |
268 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ | 268 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ |
269 | QListViewItem * currentItem; | 269 | QListViewItem * currentItem; |
270 | QString currentHome; | 270 | QString currentHome; |
271 | if(!parent) | 271 | if(!parent) |
272 | currentItem = backupList->firstChild(); | 272 | currentItem = backupList->firstChild(); |
273 | else{ | 273 | else{ |
274 | currentItem = parent->firstChild(); | 274 | currentItem = parent->firstChild(); |
275 | currentHome = parent->text(BACKUP_LOCATION); | 275 | currentHome = parent->text(BACKUP_LOCATION); |
276 | } | 276 | } |
277 | 277 | ||
278 | uint count = 0; | 278 | uint count = 0; |
279 | while( currentItem != 0 ){ | 279 | while( currentItem != 0 ){ |
280 | if(currentItem->text(HEADER_BACKUP) == "B" ){ | 280 | if(currentItem->text(HEADER_BACKUP) == "B" ){ |
281 | if(currentItem->childCount() == 0 ){ | 281 | if(currentItem->childCount() == 0 ){ |
282 | if(parent == NULL) | 282 | if(parent == NULL) |
283 | backupFiles += currentItem->text(BACKUP_LOCATION); | 283 | backupFiles += currentItem->text(BACKUP_LOCATION); |
284 | else | 284 | else |
285 | backupFiles += currentHome + currentItem->text(HEADER_NAME); | 285 | backupFiles += currentHome + currentItem->text(HEADER_NAME); |
286 | backupFiles += " "; | 286 | backupFiles += " "; |
287 | count++; | 287 | count++; |
288 | } | 288 | } |
289 | else{ | 289 | else{ |
@@ -308,91 +308,91 @@ void BackupAndRestore::fileListUpdate() | |||
308 | } | 308 | } |
309 | 309 | ||
310 | /** | 310 | /** |
311 | * Scans directory for any backup files. Will recursivly go down, | 311 | * Scans directory for any backup files. Will recursivly go down, |
312 | * but will not follow symlinks. | 312 | * but will not follow symlinks. |
313 | * @param directory - the directory to look in. | 313 | * @param directory - the directory to look in. |
314 | */ | 314 | */ |
315 | void BackupAndRestore::rescanFolder(QString directory){ | 315 | void BackupAndRestore::rescanFolder(QString directory){ |
316 | //qDebug(QString("rescanFolder: ") + directory.latin1()); | 316 | //qDebug(QString("rescanFolder: ") + directory.latin1()); |
317 | QDir d(directory); | 317 | QDir d(directory); |
318 | if(!d.exists()) | 318 | if(!d.exists()) |
319 | return; | 319 | return; |
320 | 320 | ||
321 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 321 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
322 | const QFileInfoList *list = d.entryInfoList(); | 322 | const QFileInfoList *list = d.entryInfoList(); |
323 | QFileInfoListIterator it( *list ); | 323 | QFileInfoListIterator it( *list ); |
324 | QFileInfo *file; | 324 | QFileInfo *file; |
325 | while ( (file=it.current()) ) { // for each file... | 325 | while ( (file=it.current()) ) { // for each file... |
326 | // If it is a dir and not .. or . then add it as a tab and go down. | 326 | // If it is a dir and not .. or . then add it as a tab and go down. |
327 | if(file->isDir()){ | 327 | if(file->isDir()){ |
328 | if(file->fileName() != ".." && file->fileName() != ".") { | 328 | if(file->fileName() != ".." && file->fileName() != ".") { |
329 | rescanFolder(directory + "/" + file->fileName()); | 329 | rescanFolder(directory + "/" + file->fileName()); |
330 | } | 330 | } |
331 | } | 331 | } |
332 | else{ | 332 | else{ |
333 | // If it is a backup file add to list. | 333 | // If it is a backup file add to list. |
334 | if(file->fileName().contains(EXTENSION)) | 334 | if(file->fileName().contains(EXTENSION)) |
335 | (void)new QListViewItem(restoreList, file->fileName()); | 335 | (void)new QListViewItem(restoreList, file->fileName()); |
336 | } | 336 | } |
337 | ++it; | 337 | ++it; |
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
341 | /** | 341 | /** |
342 | * Restore a backup file. | 342 | * Restore a backup file. |
343 | * Report errors or success | 343 | * Report errors or success |
344 | */ | 344 | */ |
345 | void BackupAndRestore::restore(){ | 345 | void BackupAndRestore::restore(){ |
346 | QListViewItem *restoreItem = restoreList->currentItem(); | 346 | QListViewItem *restoreItem = restoreList->currentItem(); |
347 | if(!restoreItem){ | 347 | if(!restoreItem){ |
348 | QMessageBox::critical(this, tr( "Message" ), | 348 | QMessageBox::critical(this, tr( "Message" ), |
349 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); | 349 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); |
350 | return; | 350 | return; |
351 | } | 351 | } |
352 | setCaption(tr("Backup and Restore... working...")); | 352 | setCaption(tr("Backup and Restore... working...")); |
353 | 353 | ||
354 | QString restoreFile = backupLocations[restoreSource->currentText()]; | 354 | QString restoreFile = backupLocations[restoreSource->currentText()]; |
355 | 355 | ||
356 | restoreFile += "/" + restoreItem->text(0); | 356 | restoreFile += "/" + restoreItem->text(0); |
357 | 357 | ||
358 | int r = system(QString("tar -C / -zxf %1 2> %3") | 358 | int r = system(QString("tar -C / -zxf %1 2> %3") |
359 | .arg( restoreFile.latin1() ) | 359 | .arg( restoreFile.latin1() ) |
360 | .arg( tempFileName.latin1() ) ); | 360 | .arg( tempFileName.latin1() ) ); |
361 | if(r != 0){ | 361 | if(r != 0){ |
362 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 362 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
363 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" | 363 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
364 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { | 364 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { |
365 | case 1: | 365 | case 1: |
366 | qWarning("Details pressed !"); | 366 | qWarning("Details pressed !"); |
367 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 367 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
368 | QFile errorFile( tempFileName ); | 368 | QFile errorFile( tempFileName ); |
369 | if ( errorFile.open(IO_ReadOnly) ) { | 369 | if ( errorFile.open(IO_ReadOnly) ) { |
370 | QTextStream t( &errorFile ); | 370 | QTextStream t( &errorFile ); |
371 | QString s; | 371 | QString s; |
372 | while ( !t.eof() ) { // until end of file... | 372 | while ( !t.eof() ) { // until end of file... |
373 | s += t.readLine(); // line of text excluding '\n' | 373 | s += t.readLine(); // line of text excluding '\n' |
374 | } | 374 | } |
375 | errorFile.close(); | 375 | errorFile.close(); |
376 | 376 | ||
377 | pErrDialog->m_textarea->setText( s ); | 377 | pErrDialog->m_textarea->setText( s ); |
378 | }else{ | 378 | }else{ |
379 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | 379 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); |
380 | } | 380 | } |
381 | pErrDialog->showMaximized(); | 381 | pErrDialog->showMaximized(); |
382 | pErrDialog->exec(); | 382 | pErrDialog->exec(); |
383 | delete pErrDialog; | 383 | delete pErrDialog; |
384 | 384 | ||
385 | setCaption(tr("Backup and Restore.. Failed !!")); | 385 | setCaption(tr("Backup and Restore.. Failed !!")); |
386 | return; | 386 | return; |
387 | 387 | ||
388 | break; | 388 | break; |
389 | 389 | ||
390 | } | 390 | } |
391 | } | 391 | } |
392 | else{ | 392 | else{ |
393 | QMessageBox::critical(this, tr( "Message" ), | 393 | QMessageBox::critical(this, tr( "Message" ), |
394 | tr( "Restore Successfull." ), QString( tr( "Ok") ) ); | 394 | tr( "Restore Successfull." ), QString( tr( "Ok") ) ); |
395 | } | 395 | } |
396 | setCaption(tr("Backup and Restore")); | 396 | setCaption(tr("Backup and Restore")); |
397 | } | 397 | } |
398 | 398 | ||