From 8b3a81d53c7db43bf748c2390b429dde2ab9aa82 Mon Sep 17 00:00:00 2001 From: ar Date: Sun, 25 Jul 2004 14:35:09 +0000 Subject: - begin implementation of custom backup- and restore-locations --- (limited to 'noncore') 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,12 +1,16 @@ #include "backuprestore.h" #include "errordialog.h" + /* OPIE */ #include #include -#include using namespace Opie::Core; +#include +#include +#include + /* QT */ #include #include @@ -16,15 +20,13 @@ using namespace Opie::Core; #include #include #include -#include -#include #include #include #include -#include #include #include #include +#include /* STD */ #include @@ -46,16 +48,14 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags f { backupList->header()->hide(); restoreList->header()->hide(); - connect(backupButton, SIGNAL(clicked()), - this, SLOT(backup())); - connect(restoreButton, SIGNAL(clicked()), - this, SLOT(restore())); - connect(backupList, SIGNAL(clicked(QListViewItem*)), - this, SLOT(selectItem(QListViewItem*))); - connect(restoreSource, SIGNAL(activated(int)), - this, SLOT(sourceDirChanged(int))); - connect(updateList, SIGNAL(clicked()), - this, SLOT( fileListUpdate())); + locationList->header()->hide(); + connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) ); + connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) ); + connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) ); + connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) ); + connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) ); + connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) ); + connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) ); //add directorys for backing up applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); @@ -66,25 +66,8 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags f selectItem(documents); scanForApplicationSettings(); - - Opie::Core::OStorageInfo storage; - - backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" ); - if ( storage.hasCf() ) - { - backupLocations.insert( "CF", storage.cfPath() ); - odebug << "Cf Path: " + storage.cfPath() << oendl; - } - if ( storage.hasSd() ) - { - backupLocations.insert( "SD", storage.sdPath() ); - odebug << " Sd Path: " + storage.sdPath() << oendl; - } - if ( storage.hasMmc() ) - { - backupLocations.insert( "MMC", storage.mmcPath() ); - odebug << "Mmc Path: " + storage.mmcPath() << oendl; - } + refreshBackupLocations(); + refreshLocations(); Config config("BackupAndRestore"); //read last locations @@ -160,6 +143,32 @@ BackupAndRestore::~BackupAndRestore() QFile::remove( tempFileName ); } +void BackupAndRestore::refreshBackupLocations() +{ + backupLocations.clear(); + // Add cards + Opie::Core::OStorageInfo storage; + backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" ); + if ( storage.hasCf() ) + { + backupLocations.insert( "CF", storage.cfPath() ); + odebug << "Cf Path: " + storage.cfPath() << oendl; + } + if ( storage.hasSd() ) + { + backupLocations.insert( "SD", storage.sdPath() ); + odebug << " Sd Path: " + storage.sdPath() << oendl; + } + if ( storage.hasMmc() ) + { + backupLocations.insert( "MMC", storage.mmcPath() ); + odebug << "Mmc Path: " + storage.mmcPath() << oendl; + } + + // Add own locations from locationList + // todo implementation +} + QList BackupAndRestore::getAllItems(QListViewItem *item, QList &list) { while(item) @@ -203,7 +212,7 @@ void BackupAndRestore::scanForApplicationSettings() QFileInfo *fi; while ( (fi=it.current()) ) { - //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; + //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) { QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); @@ -249,7 +258,7 @@ void BackupAndRestore::backup() // We execute tar and compressing its output with gzip.. // The error output will be written into a temp-file which could be provided // for debugging.. - odebug << "Storing file: " << outputFile.latin1() << "" << oendl; + odebug << "Storing file: " << outputFile.latin1() << "" << oendl; outputFile += EXTENSION; QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) @@ -258,7 +267,7 @@ void BackupAndRestore::backup() .arg( outputFile.latin1() ) .arg( tempFileName.latin1() ); - odebug << commandLine << oendl; + odebug << commandLine << oendl; int r = system( commandLine ); @@ -272,7 +281,7 @@ void BackupAndRestore::backup() { case 1: - owarn << "Details pressed !" << oendl; + owarn << "Details pressed !" << oendl; ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); QFile errorFile( tempFileName ); if ( errorFile.open(IO_ReadOnly) ) @@ -359,7 +368,7 @@ void BackupAndRestore::sourceDirChanged(int selection) void BackupAndRestore::fileListUpdate() { - owarn << "void BackupAndRestore::fileListUpdate()" << oendl; + owarn << "void BackupAndRestore::fileListUpdate()" << oendl; restoreList->clear(); rescanFolder( backupLocations[restoreSource->currentText()] ); } @@ -371,7 +380,7 @@ void BackupAndRestore::fileListUpdate() */ void BackupAndRestore::rescanFolder(QString directory) { - //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; + //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; QDir d(directory); if(!d.exists()) return; @@ -419,7 +428,7 @@ void BackupAndRestore::restore() restoreFile += "/" + restoreItem->text(0); - odebug << restoreFile << oendl; + odebug << restoreFile << oendl; //check if backup file come from opie 1.0.x @@ -442,7 +451,7 @@ void BackupAndRestore::restore() .arg( restoreFile.latin1() ) .arg( tempFileName.latin1() ); - odebug << commandLine << oendl; + odebug << commandLine << oendl; r = system( commandLine ); @@ -454,7 +463,7 @@ void BackupAndRestore::restore() + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { case 1: - owarn << "Details pressed !" << oendl; + owarn << "Details pressed !" << oendl; ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); QFile errorFile( tempFileName ); if ( errorFile.open(IO_ReadOnly) ) @@ -499,7 +508,7 @@ void BackupAndRestore::restore() /** * Check for exclude in Applications/backup * If it does not exist, the function will create the file with *.bck as content - * The exclude_files is read by tar and will provide to exclude special files out from backup. + * The exclude_files is read by tar and will provide to exclude special files out from backup. * e.g. alle *.bck files (backup-files) will not be backed up by default */ @@ -524,5 +533,37 @@ QString BackupAndRestore::getExcludeFile() return excludeFileName; } +void BackupAndRestore::refreshLocations() +{ + locationList->clear(); + //todo: implement add locations + odebug << "not implemented yet" << oendl; +} + +void BackupAndRestore::addLocation() +{ + if ( ( !locationEdit->text().isEmpty() ) && + ( QDir( locationEdit->text() ).exists() ) ) + { + (void) new QListViewItem( locationList, locationEdit->text() ); + locationEdit->setText( "" ); + } +} + +void BackupAndRestore::removeLocation() +{ + if ( locationList->selectedItem() ) + { + delete( locationList->selectedItem() ); + } +} + +void BackupAndRestore::saveLocation() +{ + //todo: implement + odebug << "not implemented yet" << oendl; +} + + // backuprestore.cpp diff --git a/noncore/settings/backup/backuprestore.h b/noncore/settings/backup/backuprestore.h index 0d88f8d..527b3cf 100644 --- a/noncore/settings/backup/backuprestore.h +++ b/noncore/settings/backup/backuprestore.h @@ -28,12 +28,18 @@ private slots: void rescanFolder(QString directory); void fileListUpdate(); + void addLocation(); + void removeLocation(); + void saveLocation(); + private: void scanForApplicationSettings(); int getBackupFiles(QString &backupFiles, QListViewItem *parent); QString getExcludeFile(); QMap backupLocations; QList getAllItems(QListViewItem *item, QList &list); + void refreshBackupLocations(); + void refreshLocations(); QListViewItem *systemSettings; QListViewItem *applicationSettings; diff --git a/noncore/settings/backup/backuprestorebase.ui b/noncore/settings/backup/backuprestorebase.ui index a52b42d..b4624bb 100644 --- a/noncore/settings/backup/backuprestorebase.ui +++ b/noncore/settings/backup/backuprestorebase.ui @@ -11,8 +11,8 @@ 0 0 - 231 - 275 + 290 + 243 @@ -22,6 +22,9 @@ layoutMargin + + layoutSpacing + margin @@ -29,7 +32,7 @@ spacing - 6 + 0 QTabWidget @@ -40,6 +43,9 @@ layoutMargin + + layoutSpacing + QWidget @@ -53,11 +59,11 @@ margin - 11 + 4 spacing - 6 + 4 QLabel @@ -132,11 +138,11 @@ margin - 11 + 4 spacing - 6 + 4 QComboBox @@ -146,6 +152,28 @@ + QPushButton + + name + restoreButton + + + text + &Restore + + + + QLabel + + name + TextLabel1_2 + + + text + Select Source + + + QListView @@ -173,37 +201,104 @@ - + + + + QWidget + + name + tab + + + title + Locations + + + + margin + 4 + + + spacing + 4 + + + QLineEdit + + name + locationEdit + + + + QToolButton + + name + locationSelectBtn + + + maximumSize + + 20 + 30 + + + + text + ... + + + + QListView + + + text + Locations + + + clickable + true + + + resizeable + true + + + + name + locationList + + + QPushButton name - restoreButton + addLocationButton text - &Restore + Add - - QLabel + + QPushButton name - TextLabel1_2 + removeLocationButton text - Select Source + Remove - + QPushButton name - updateList + saveLocationsButton text - Update Filelist + Save -- cgit v0.9.0.2