summaryrefslogtreecommitdiff
path: root/noncore/settings/backup/backuprestore.cpp
Unidiff
Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp127
1 files changed, 84 insertions, 43 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 2eccdfe..3889744 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -1,33 +1,35 @@
1#include "backuprestore.h" 1#include "backuprestore.h"
2#include "errordialog.h" 2#include "errordialog.h"
3 3
4
4/* OPIE */ 5/* OPIE */
5#include <opie2/odebug.h> 6#include <opie2/odebug.h>
6#include <opie2/ostorageinfo.h> 7#include <opie2/ostorageinfo.h>
7#include <qpe/qpeapplication.h>
8using namespace Opie::Core; 8using namespace Opie::Core;
9 9
10#include <qpe/qpeapplication.h>
11#include <qpe/resource.h>
12#include <qpe/config.h>
13
10/* QT */ 14/* QT */
11#include <qapplication.h> 15#include <qapplication.h>
12#include <qmultilineedit.h> 16#include <qmultilineedit.h>
13#include <qdir.h> 17#include <qdir.h>
14#include <qfile.h> 18#include <qfile.h>
15#include <qfileinfo.h> 19#include <qfileinfo.h>
16#include <qlistview.h> 20#include <qlistview.h>
17#include <qpushbutton.h> 21#include <qpushbutton.h>
18#include <qheader.h> 22#include <qheader.h>
19#include <qpe/resource.h>
20#include <qpe/config.h>
21#include <qmessagebox.h> 23#include <qmessagebox.h>
22#include <qcombobox.h> 24#include <qcombobox.h>
23#include <qlist.h> 25#include <qlist.h>
24#include <stdlib.h>
25#include <qregexp.h> 26#include <qregexp.h>
26#include <qtextstream.h> 27#include <qtextstream.h>
27#include <qtextview.h> 28#include <qtextview.h>
29#include <qlineedit.h>
28 30
29/* STD */ 31/* STD */
30#include <errno.h> 32#include <errno.h>
31#include <stdlib.h> 33#include <stdlib.h>
32#include <unistd.h> 34#include <unistd.h>
33#include <sys/stat.h> 35#include <sys/stat.h>
@@ -43,51 +45,32 @@ const QString tempFileName = "/tmp/backup.err";
43 45
44BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) 46BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl)
45 : BackupAndRestoreBase(parent, name, fl) 47 : BackupAndRestoreBase(parent, name, fl)
46{ 48{
47 backupList->header()->hide(); 49 backupList->header()->hide();
48 restoreList->header()->hide(); 50 restoreList->header()->hide();
49 connect(backupButton, SIGNAL(clicked()), 51 locationList->header()->hide();
50 this, SLOT(backup())); 52 connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) );
51 connect(restoreButton, SIGNAL(clicked()), 53 connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) );
52 this, SLOT(restore())); 54 connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) );
53 connect(backupList, SIGNAL(clicked(QListViewItem*)), 55 connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) );
54 this, SLOT(selectItem(QListViewItem*))); 56 connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) );
55 connect(restoreSource, SIGNAL(activated(int)), 57 connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) );
56 this, SLOT(sourceDirChanged(int))); 58 connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) );
57 connect(updateList, SIGNAL(clicked()),
58 this, SLOT( fileListUpdate()));
59 59
60 //add directorys for backing up 60 //add directorys for backing up
61 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); 61 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/");
62 selectItem(applicationSettings); 62 selectItem(applicationSettings);
63 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); 63 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/");
64 selectItem(applicationSettings); 64 selectItem(applicationSettings);
65 documents= new QListViewItem(backupList, "Documents", "", "Documents/"); 65 documents= new QListViewItem(backupList, "Documents", "", "Documents/");
66 selectItem(documents); 66 selectItem(documents);
67 67
68 scanForApplicationSettings(); 68 scanForApplicationSettings();
69 69 refreshBackupLocations();
70 Opie::Core::OStorageInfo storage; 70 refreshLocations();
71
72 backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" );
73 if ( storage.hasCf() )
74 {
75 backupLocations.insert( "CF", storage.cfPath() );
76 odebug << "Cf Path: " + storage.cfPath() << oendl;
77 }
78 if ( storage.hasSd() )
79 {
80 backupLocations.insert( "SD", storage.sdPath() );
81 odebug << " Sd Path: " + storage.sdPath() << oendl;
82 }
83 if ( storage.hasMmc() )
84 {
85 backupLocations.insert( "MMC", storage.mmcPath() );
86 odebug << "Mmc Path: " + storage.mmcPath() << oendl;
87 }
88 71
89 Config config("BackupAndRestore"); 72 Config config("BackupAndRestore");
90 //read last locations 73 //read last locations
91 config.setGroup("LastLocation"); 74 config.setGroup("LastLocation");
92 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" ); 75 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" );
93 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" ); 76 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" );
@@ -157,12 +140,38 @@ BackupAndRestore::~BackupAndRestore()
157 140
158 // Remove Temp File 141 // Remove Temp File
159 if ( QFile::exists( tempFileName ) ) 142 if ( QFile::exists( tempFileName ) )
160 QFile::remove( tempFileName ); 143 QFile::remove( tempFileName );
161} 144}
162 145
146void BackupAndRestore::refreshBackupLocations()
147{
148 backupLocations.clear();
149 // Add cards
150 Opie::Core::OStorageInfo storage;
151 backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" );
152 if ( storage.hasCf() )
153 {
154 backupLocations.insert( "CF", storage.cfPath() );
155 odebug << "Cf Path: " + storage.cfPath() << oendl;
156 }
157 if ( storage.hasSd() )
158 {
159 backupLocations.insert( "SD", storage.sdPath() );
160 odebug << " Sd Path: " + storage.sdPath() << oendl;
161 }
162 if ( storage.hasMmc() )
163 {
164 backupLocations.insert( "MMC", storage.mmcPath() );
165 odebug << "Mmc Path: " + storage.mmcPath() << oendl;
166 }
167
168 // Add own locations from locationList
169 // todo implementation
170}
171
163QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) 172QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list)
164{ 173{
165 while(item) 174 while(item)
166 { 175 {
167 if(item->childCount() > 0) 176 if(item->childCount() > 0)
168 getAllItems(item->firstChild(), list); 177 getAllItems(item->firstChild(), list);
@@ -200,13 +209,13 @@ void BackupAndRestore::scanForApplicationSettings()
200 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); 209 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
201 const QFileInfoList *list = d.entryInfoList(); 210 const QFileInfoList *list = d.entryInfoList();
202 QFileInfoListIterator it( *list ); 211 QFileInfoListIterator it( *list );
203 QFileInfo *fi; 212 QFileInfo *fi;
204 while ( (fi=it.current()) ) 213 while ( (fi=it.current()) )
205 { 214 {
206 //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; 215 //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl;
207 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) 216 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) )
208 { 217 {
209 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); 218 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName());
210 selectItem(newItem); 219 selectItem(newItem);
211 } 220 }
212 ++it; 221 ++it;
@@ -246,22 +255,22 @@ void BackupAndRestore::backup()
246 c++; 255 c++;
247 } 256 }
248 257
249 // We execute tar and compressing its output with gzip.. 258 // We execute tar and compressing its output with gzip..
250 // The error output will be written into a temp-file which could be provided 259 // The error output will be written into a temp-file which could be provided
251 // for debugging.. 260 // for debugging..
252 odebug << "Storing file: " << outputFile.latin1() << "" << oendl; 261 odebug << "Storing file: " << outputFile.latin1() << "" << oendl;
253 outputFile += EXTENSION; 262 outputFile += EXTENSION;
254 263
255 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) 264 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() )
256 .arg( getExcludeFile() ) 265 .arg( getExcludeFile() )
257 .arg( backupFiles ) 266 .arg( backupFiles )
258 .arg( outputFile.latin1() ) 267 .arg( outputFile.latin1() )
259 .arg( tempFileName.latin1() ); 268 .arg( tempFileName.latin1() );
260 269
261 odebug << commandLine << oendl; 270 odebug << commandLine << oendl;
262 271
263 int r = system( commandLine ); 272 int r = system( commandLine );
264 273
265 if(r != 0) 274 if(r != 0)
266 { 275 {
267 perror("Error: "); 276 perror("Error: ");
@@ -269,13 +278,13 @@ void BackupAndRestore::backup()
269 278
270 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" 279 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n"
271 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) 280 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) )
272 { 281 {
273 282
274 case 1: 283 case 1:
275 owarn << "Details pressed !" << oendl; 284 owarn << "Details pressed !" << oendl;
276 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 285 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
277 QFile errorFile( tempFileName ); 286 QFile errorFile( tempFileName );
278 if ( errorFile.open(IO_ReadOnly) ) 287 if ( errorFile.open(IO_ReadOnly) )
279 { 288 {
280 QTextStream t( &errorFile ); 289 QTextStream t( &errorFile );
281 QString s; 290 QString s;
@@ -356,25 +365,25 @@ void BackupAndRestore::sourceDirChanged(int selection)
356 restoreList->clear(); 365 restoreList->clear();
357 rescanFolder(backupLocations[restoreSource->text(selection)]); 366 rescanFolder(backupLocations[restoreSource->text(selection)]);
358} 367}
359 368
360void BackupAndRestore::fileListUpdate() 369void BackupAndRestore::fileListUpdate()
361{ 370{
362 owarn << "void BackupAndRestore::fileListUpdate()" << oendl; 371 owarn << "void BackupAndRestore::fileListUpdate()" << oendl;
363 restoreList->clear(); 372 restoreList->clear();
364 rescanFolder( backupLocations[restoreSource->currentText()] ); 373 rescanFolder( backupLocations[restoreSource->currentText()] );
365} 374}
366 375
367/** 376/**
368 * Scans directory for any backup files. Will recursivly go down, 377 * Scans directory for any backup files. Will recursivly go down,
369 * but will not follow symlinks. 378 * but will not follow symlinks.
370 * @param directory - the directory to look in. 379 * @param directory - the directory to look in.
371 */ 380 */
372void BackupAndRestore::rescanFolder(QString directory) 381void BackupAndRestore::rescanFolder(QString directory)
373{ 382{
374 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; 383 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl;
375 QDir d(directory); 384 QDir d(directory);
376 if(!d.exists()) 385 if(!d.exists())
377 return; 386 return;
378 387
379 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); 388 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
380 const QFileInfoList *list = d.entryInfoList(); 389 const QFileInfoList *list = d.entryInfoList();
@@ -416,13 +425,13 @@ void BackupAndRestore::restore()
416 setCaption(tr("Backup and Restore... working...")); 425 setCaption(tr("Backup and Restore... working..."));
417 426
418 QString restoreFile = backupLocations[restoreSource->currentText()]; 427 QString restoreFile = backupLocations[restoreSource->currentText()];
419 428
420 restoreFile += "/" + restoreItem->text(0); 429 restoreFile += "/" + restoreItem->text(0);
421 430
422 odebug << restoreFile << oendl; 431 odebug << restoreFile << oendl;
423 432
424 //check if backup file come from opie 1.0.x 433 //check if backup file come from opie 1.0.x
425 434
426 QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() ); 435 QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() );
427 436
428 int r = system( commandLine ); 437 int r = system( commandLine );
@@ -439,25 +448,25 @@ void BackupAndRestore::restore()
439 448
440 //unpack backup file 449 //unpack backup file
441 commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir ) 450 commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir )
442 .arg( restoreFile.latin1() ) 451 .arg( restoreFile.latin1() )
443 .arg( tempFileName.latin1() ); 452 .arg( tempFileName.latin1() );
444 453
445 odebug << commandLine << oendl; 454 odebug << commandLine << oendl;
446 455
447 r = system( commandLine ); 456 r = system( commandLine );
448 457
449 //error handling 458 //error handling
450 if(r != 0) 459 if(r != 0)
451 { 460 {
452 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 461 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
453 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" 462 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n"
454 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) 463 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) )
455 { 464 {
456 case 1: 465 case 1:
457 owarn << "Details pressed !" << oendl; 466 owarn << "Details pressed !" << oendl;
458 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 467 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
459 QFile errorFile( tempFileName ); 468 QFile errorFile( tempFileName );
460 if ( errorFile.open(IO_ReadOnly) ) 469 if ( errorFile.open(IO_ReadOnly) )
461 { 470 {
462 QTextStream t( &errorFile ); 471 QTextStream t( &errorFile );
463 QString s; 472 QString s;
@@ -496,13 +505,13 @@ void BackupAndRestore::restore()
496 setCaption(tr("Backup and Restore")); 505 setCaption(tr("Backup and Restore"));
497} 506}
498 507
499/** 508/**
500 * Check for exclude in Applications/backup 509 * Check for exclude in Applications/backup
501 * If it does not exist, the function will create the file with *.bck as content 510 * If it does not exist, the function will create the file with *.bck as content
502 * The exclude_files is read by tar and will provide to exclude special files out from backup. 511 * The exclude_files is read by tar and will provide to exclude special files out from backup.
503 * e.g. alle *.bck files (backup-files) will not be backed up by default 512 * e.g. alle *.bck files (backup-files) will not be backed up by default
504 */ 513 */
505 514
506QString BackupAndRestore::getExcludeFile() 515QString BackupAndRestore::getExcludeFile()
507{ 516{
508 QString excludeFileName = Global::applicationFileName( "backup", "exclude" ); 517 QString excludeFileName = Global::applicationFileName( "backup", "exclude" );
@@ -521,8 +530,40 @@ QString BackupAndRestore::getExcludeFile()
521 } 530 }
522 } 531 }
523 532
524 return excludeFileName; 533 return excludeFileName;
525} 534}
526 535
536void BackupAndRestore::refreshLocations()
537{
538 locationList->clear();
539 //todo: implement add locations
540 odebug << "not implemented yet" << oendl;
541}
542
543void BackupAndRestore::addLocation()
544{
545 if ( ( !locationEdit->text().isEmpty() ) &&
546 ( QDir( locationEdit->text() ).exists() ) )
547 {
548 (void) new QListViewItem( locationList, locationEdit->text() );
549 locationEdit->setText( "" );
550 }
551}
552
553void BackupAndRestore::removeLocation()
554{
555 if ( locationList->selectedItem() )
556 {
557 delete( locationList->selectedItem() );
558 }
559}
560
561void BackupAndRestore::saveLocation()
562{
563 //todo: implement
564 odebug << "not implemented yet" << oendl;
565}
566
567
527// backuprestore.cpp 568// backuprestore.cpp
528 569