summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 36b101c..1748e8d 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -1,26 +1,27 @@
1#include "backuprestore.h" 1#include "backuprestore.h"
2#include "errordialog.h" 2#include "errordialog.h"
3 3
4 4
5/* OPIE */ 5/* OPIE */
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7#include <opie2/ostorageinfo.h> 7#include <opie2/ostorageinfo.h>
8using namespace Opie::Core; 8using namespace Opie::Core;
9 9
10#include <opie2/ofiledialog.h> 10#include <opie2/ofiledialog.h>
11#include <opie2/owait.h>
11using namespace Opie::Ui; 12using namespace Opie::Ui;
12 13
13#include <qpe/qpeapplication.h> 14#include <qpe/qpeapplication.h>
14#include <qpe/resource.h> 15#include <qpe/resource.h>
15#include <qpe/config.h> 16#include <qpe/config.h>
16 17
17/* QT */ 18/* QT */
18#include <qapplication.h> 19#include <qapplication.h>
19#include <qmultilineedit.h> 20#include <qmultilineedit.h>
20#include <qdir.h> 21#include <qdir.h>
21#include <qfile.h> 22#include <qfile.h>
22#include <qfileinfo.h> 23#include <qfileinfo.h>
23#include <qlistview.h> 24#include <qlistview.h>
24#include <qpushbutton.h> 25#include <qpushbutton.h>
25#include <qheader.h> 26#include <qheader.h>
26#include <qmessagebox.h> 27#include <qmessagebox.h>
@@ -238,65 +239,73 @@ void BackupAndRestore::scanForApplicationSettings()
238/** 239/**
239 * The "Backup" button has been pressed. Get a list of all of the files that 240 * The "Backup" button has been pressed. Get a list of all of the files that
240 * should be backed up. If there are no files, emit and error and exit. 241 * should be backed up. If there are no files, emit and error and exit.
241 * Determine the file name to store the backup in. Backup the file(s) using 242 * Determine the file name to store the backup in. Backup the file(s) using
242 * tar and gzip --best. Report failure or success 243 * tar and gzip --best. Report failure or success
243 */ 244 */
244void BackupAndRestore::backup() 245void BackupAndRestore::backup()
245{ 246{
246 QString backupFiles; 247 QString backupFiles;
247 if(getBackupFiles(backupFiles, NULL) == 0) 248 if(getBackupFiles(backupFiles, NULL) == 0)
248 { 249 {
249 QMessageBox::critical(this, "Message", 250 QMessageBox::critical(this, "Message",
250 "No items selected.",QString("Ok") ); 251 "No items selected.",QString("Ok") );
251 return; 252 return;
252 } 253 }
253 254
254 setCaption(tr("Backup and Restore... working...")); 255 OWait *owait = new OWait();
256 Global::statusMessage( tr( "Backing up..." ) );
257 owait->show();
258 qApp->processEvents();
259
255 QString outputFile = backupLocations[storeToLocation->currentText()]; 260 QString outputFile = backupLocations[storeToLocation->currentText()];
256 261
257 QDateTime datetime = QDateTime::currentDateTime(); 262 QDateTime datetime = QDateTime::currentDateTime();
258 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + 263 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
259 QString::number( datetime.date().day() ).rightJustify(2, '0'); 264 QString::number( datetime.date().day() ).rightJustify(2, '0');
260 265
261 outputFile += "/" + dateString; 266 outputFile += "/" + dateString;
262 267
263 QString t = outputFile; 268 QString t = outputFile;
264 int c = 1; 269 int c = 1;
265 while(QFile::exists(outputFile + EXTENSION)) 270 while(QFile::exists(outputFile + EXTENSION))
266 { 271 {
267 outputFile = t + QString("%1").arg(c); 272 outputFile = t + QString("%1").arg(c);
268 c++; 273 c++;
269 } 274 }
270 275
271 // We execute tar and compressing its output with gzip.. 276 // We execute tar and compressing its output with gzip..
272 // The error output will be written into a temp-file which could be provided 277 // The error output will be written into a temp-file which could be provided
273 // for debugging.. 278 // for debugging..
274 odebug << "Storing file: " << outputFile.latin1() << "" << oendl; 279 odebug << "Storing file: " << outputFile.latin1() << "" << oendl;
275 outputFile += EXTENSION; 280 outputFile += EXTENSION;
276 281
277 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) 282 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() )
278 .arg( getExcludeFile() ) 283 .arg( getExcludeFile() )
279 .arg( backupFiles ) 284 .arg( backupFiles )
280 .arg( outputFile.latin1() ) 285 .arg( outputFile.latin1() )
281 .arg( tempFileName.latin1() ); 286 .arg( tempFileName.latin1() );
282 287
283 odebug << commandLine << oendl; 288 odebug << commandLine << oendl;
284 289
285 int r = system( commandLine ); 290 int r = system( commandLine );
286 291
292 owait->hide();
293 delete owait;
294
295 //Error-Handling
287 if(r != 0) 296 if(r != 0)
288 { 297 {
289 perror("Error: "); 298 perror("Error: ");
290 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 299 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
291 300
292 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" 301 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n"
293 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) 302 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) )
294 { 303 {
295 304
296 case 1: 305 case 1:
297 owarn << "Details pressed !" << oendl; 306 owarn << "Details pressed !" << oendl;
298 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 307 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
299 QFile errorFile( tempFileName ); 308 QFile errorFile( tempFileName );
300 if ( errorFile.open(IO_ReadOnly) ) 309 if ( errorFile.open(IO_ReadOnly) )
301 { 310 {
302 QTextStream t( &errorFile ); 311 QTextStream t( &errorFile );
@@ -421,65 +430,72 @@ void BackupAndRestore::rescanFolder(QString directory)
421 } 430 }
422} 431}
423 432
424/** 433/**
425 * Restore a backup file. 434 * Restore a backup file.
426 * Report errors or success 435 * Report errors or success
427 */ 436 */
428void BackupAndRestore::restore() 437void BackupAndRestore::restore()
429{ 438{
430 QListViewItem *restoreItem = restoreList->currentItem(); 439 QListViewItem *restoreItem = restoreList->currentItem();
431 if(!restoreItem) 440 if(!restoreItem)
432 { 441 {
433 QMessageBox::critical(this, tr( "Message" ), 442 QMessageBox::critical(this, tr( "Message" ),
434 tr( "Please select something to restore." ),QString( tr( "Ok") ) ); 443 tr( "Please select something to restore." ),QString( tr( "Ok") ) );
435 return; 444 return;
436 } 445 }
437 setCaption(tr("Backup and Restore... working...")); 446
447 OWait *owait = new OWait();
448 Global::statusMessage( tr( "Restore Backup..." ) );
449 owait->show();
450 qApp->processEvents();
438 451
439 QString restoreFile = backupLocations[restoreSource->currentText()]; 452 QString restoreFile = backupLocations[restoreSource->currentText()];
440 453
441 restoreFile += "/" + restoreItem->text(0); 454 restoreFile += "/" + restoreItem->text(0);
442 455
443 odebug << restoreFile << oendl; 456 odebug << restoreFile << oendl;
444 457
445 //check if backup file come from opie 1.0.x 458 //check if backup file come from opie 1.0.x
446 459
447 QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() ); 460 QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() );
448 461
449 int r = system( commandLine ); 462 int r = system( commandLine );
450 463
451 QString startDir; 464 QString startDir;
452 465
453 if( r != 0 ) //Applications/backup/exclude not found - old backup file 466 if( r != 0 ) //Applications/backup/exclude not found - old backup file
454 { 467 {
455 startDir = QString( "/" ); 468 startDir = QString( "/" );
456 } else 469 } else
457 { 470 {
458 startDir = QDir::homeDirPath(); 471 startDir = QDir::homeDirPath();
459 } 472 }
460 473
461 //unpack backup file 474 //unpack backup file
462 commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir ) 475 commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir )
463 .arg( restoreFile.latin1() ) 476 .arg( restoreFile.latin1() )
464 .arg( tempFileName.latin1() ); 477 .arg( tempFileName.latin1() );
465 478
466 odebug << commandLine << oendl; 479 odebug << commandLine << oendl;
467 480
468 r = system( commandLine ); 481 r = system( commandLine );
469 482
483 owait->hide();
484 delete owait;
485
470 //error handling 486 //error handling
471 if(r != 0) 487 if(r != 0)
472 { 488 {
473 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 489 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
474 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" 490 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n"
475 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) 491 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) )
476 { 492 {
477 case 1: 493 case 1:
478 owarn << "Details pressed !" << oendl; 494 owarn << "Details pressed !" << oendl;
479 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 495 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
480 QFile errorFile( tempFileName ); 496 QFile errorFile( tempFileName );
481 if ( errorFile.open(IO_ReadOnly) ) 497 if ( errorFile.open(IO_ReadOnly) )
482 { 498 {
483 QTextStream t( &errorFile ); 499 QTextStream t( &errorFile );
484 QString s; 500 QString s;
485 while ( !t.eof() ) 501 while ( !t.eof() )