summaryrefslogtreecommitdiff
path: root/noncore
authorar <ar>2004-07-25 14:35:09 (UTC)
committer ar <ar>2004-07-25 14:35:09 (UTC)
commit8b3a81d53c7db43bf748c2390b429dde2ab9aa82 (patch) (side-by-side diff)
treeeb0da156fba85f8ade489a42382ace3a88df87af /noncore
parentda9a436a866e608451115316c7374a6730174130 (diff)
downloadopie-8b3a81d53c7db43bf748c2390b429dde2ab9aa82.zip
opie-8b3a81d53c7db43bf748c2390b429dde2ab9aa82.tar.gz
opie-8b3a81d53c7db43bf748c2390b429dde2ab9aa82.tar.bz2
- begin implementation of custom backup- and restore-locations
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp127
-rw-r--r--noncore/settings/backup/backuprestore.h6
-rw-r--r--noncore/settings/backup/backuprestorebase.ui129
3 files changed, 202 insertions, 60 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,99 +1,82 @@
#include "backuprestore.h"
#include "errordialog.h"
+
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/ostorageinfo.h>
-#include <qpe/qpeapplication.h>
using namespace Opie::Core;
+#include <qpe/qpeapplication.h>
+#include <qpe/resource.h>
+#include <qpe/config.h>
+
/* QT */
#include <qapplication.h>
#include <qmultilineedit.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qheader.h>
-#include <qpe/resource.h>
-#include <qpe/config.h>
#include <qmessagebox.h>
#include <qcombobox.h>
#include <qlist.h>
-#include <stdlib.h>
#include <qregexp.h>
#include <qtextstream.h>
#include <qtextview.h>
+#include <qlineedit.h>
/* STD */
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#define HEADER_NAME 0
#define HEADER_BACKUP 1
#define BACKUP_LOCATION 2
#define EXTENSION ".bck"
const QString tempFileName = "/tmp/backup.err";
BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl)
: BackupAndRestoreBase(parent, name, fl)
{
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/");
selectItem(applicationSettings);
applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/");
selectItem(applicationSettings);
documents= new QListViewItem(backupList, "Documents", "", "Documents/");
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
config.setGroup("LastLocation");
QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" );
QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" );
int locationIndex = 0;
QMap<QString, QString>::Iterator it;
for( it = backupLocations.begin(); it != backupLocations.end(); ++it )
{
storeToLocation->insertItem(it.key());
@@ -151,24 +134,50 @@ BackupAndRestore::~BackupAndRestore()
{
config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME));
count++;
}
}
config.writeEntry("Total", count);
// Remove Temp File
if ( QFile::exists( tempFileName ) )
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<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list)
{
while(item)
{
if(item->childCount() > 0)
getAllItems(item->firstChild(), list);
list.append(item);
item = item->nextSibling();
}
return list;
}
@@ -194,25 +203,25 @@ void BackupAndRestore::selectItem(QListViewItem *currentItem)
}
}
void BackupAndRestore::scanForApplicationSettings()
{
QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) );
d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
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());
selectItem(newItem);
}
++it;
}
}
/**
* The "Backup" button has been pressed. Get a list of all of the files that
* should be backed up. If there are no files, emit and error and exit.
@@ -240,48 +249,48 @@ void BackupAndRestore::backup()
QString t = outputFile;
int c = 1;
while(QFile::exists(outputFile + EXTENSION))
{
outputFile = t + QString("%1").arg(c);
c++;
}
// 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() )
.arg( getExcludeFile() )
.arg( backupFiles )
.arg( outputFile.latin1() )
.arg( tempFileName.latin1() );
- odebug << commandLine << oendl;
+ odebug << commandLine << oendl;
int r = system( commandLine );
if(r != 0)
{
perror("Error: ");
QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n"
+ 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) )
{
QTextStream t( &errorFile );
QString s;
while ( !t.eof() )
{ // until end of file...
s += t.readLine(); // line of text excluding '\n'
}
errorFile.close();
@@ -350,37 +359,37 @@ int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent
}
return count;
}
void BackupAndRestore::sourceDirChanged(int selection)
{
restoreList->clear();
rescanFolder(backupLocations[restoreSource->text(selection)]);
}
void BackupAndRestore::fileListUpdate()
{
- owarn << "void BackupAndRestore::fileListUpdate()" << oendl;
+ owarn << "void BackupAndRestore::fileListUpdate()" << oendl;
restoreList->clear();
rescanFolder( backupLocations[restoreSource->currentText()] );
}
/**
* Scans directory for any backup files. Will recursivly go down,
* but will not follow symlinks.
* @param directory - the directory to look in.
*/
void BackupAndRestore::rescanFolder(QString directory)
{
- //odebug << QString("rescanFolder: ") + directory.latin1() << oendl;
+ //odebug << QString("rescanFolder: ") + directory.latin1() << oendl;
QDir d(directory);
if(!d.exists())
return;
d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *file;
while ( (file=it.current()) )
{ // for each file...
// If it is a dir and not .. or . then add it as a tab and go down.
if(file->isDir())
@@ -410,60 +419,60 @@ void BackupAndRestore::restore()
if(!restoreItem)
{
QMessageBox::critical(this, tr( "Message" ),
tr( "Please select something to restore." ),QString( tr( "Ok") ) );
return;
}
setCaption(tr("Backup and Restore... working..."));
QString restoreFile = backupLocations[restoreSource->currentText()];
restoreFile += "/" + restoreItem->text(0);
- odebug << restoreFile << oendl;
+ odebug << restoreFile << oendl;
//check if backup file come from opie 1.0.x
QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() );
int r = system( commandLine );
QString startDir;
if( r != 0 ) //Applications/backup/exclude not found - old backup file
{
startDir = QString( "/" );
} else
{
startDir = QDir::homeDirPath();
}
//unpack backup file
commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir )
.arg( restoreFile.latin1() )
.arg( tempFileName.latin1() );
- odebug << commandLine << oendl;
+ odebug << commandLine << oendl;
r = system( commandLine );
//error handling
if(r != 0)
{
QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n"
+ 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) )
{
QTextStream t( &errorFile );
QString s;
while ( !t.eof() )
{ // until end of file...
s += t.readLine(); // line of text excluding '\n'
}
errorFile.close();
@@ -490,39 +499,71 @@ void BackupAndRestore::restore()
//write restore-location
Config config( "BackupAndRestore" );
config.setGroup( "LastLocation" );
config.writeEntry( "LastRestoreLocation", restoreSource->currentText() );
setCaption(tr("Backup and 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
*/
QString BackupAndRestore::getExcludeFile()
{
QString excludeFileName = Global::applicationFileName( "backup", "exclude" );
if ( !QFile::exists( excludeFileName ) )
{
QFile excludeFile( excludeFileName);
if ( excludeFile.open( IO_WriteOnly ) == true )
{
QTextStream writeStream( &excludeFile );
writeStream << "*.bck" << "\n";
excludeFile.close();
}
else
{
return QString::null;
}
}
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
@@ -19,29 +19,35 @@ public:
~BackupAndRestore();
static QString appName() { return QString::fromLatin1("backup"); }
private slots:
void backup();
void restore();
void selectItem(QListViewItem *currentItem);
void sourceDirChanged(int);
void rescanFolder(QString directory);
void fileListUpdate();
+ void addLocation();
+ void removeLocation();
+ void saveLocation();
+
private:
void scanForApplicationSettings();
int getBackupFiles(QString &backupFiles, QListViewItem *parent);
QString getExcludeFile();
QMap<QString, QString> backupLocations;
QList<QListViewItem> getAllItems(QListViewItem *item, QList<QListViewItem> &list);
+ void refreshBackupLocations();
+ void refreshLocations();
QListViewItem *systemSettings;
QListViewItem *applicationSettings;
QListViewItem *documents;
};
#endif
// backuprestore.h
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
@@ -2,71 +2,77 @@
<class>BackupAndRestoreBase</class>
<widget>
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>BackupAndRestoreBase</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>231</width>
- <height>275</height>
+ <width>290</width>
+ <height>243</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>Backup And Restore</string>
</property>
<property>
<name>layoutMargin</name>
</property>
+ <property>
+ <name>layoutSpacing</name>
+ </property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
- <number>6</number>
+ <number>0</number>
</property>
<widget>
<class>QTabWidget</class>
<property stdset="1">
<name>name</name>
<cstring>tabWidget</cstring>
</property>
<property>
<name>layoutMargin</name>
</property>
+ <property>
+ <name>layoutSpacing</name>
+ </property>
<widget>
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Widget2</cstring>
</property>
<attribute>
<name>title</name>
<string>Backup</string>
</attribute>
<grid>
<property stdset="1">
<name>margin</name>
- <number>11</number>
+ <number>4</number>
</property>
<property stdset="1">
<name>spacing</name>
- <number>6</number>
+ <number>4</number>
</property>
<widget row="0" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Save To</string>
</property>
</widget>
@@ -123,38 +129,60 @@
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Widget3</cstring>
</property>
<attribute>
<name>title</name>
<string>Restore</string>
</attribute>
<grid>
<property stdset="1">
<name>margin</name>
- <number>11</number>
+ <number>4</number>
</property>
<property stdset="1">
<name>spacing</name>
- <number>6</number>
+ <number>4</number>
</property>
<widget row="0" column="1" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>restoreSource</cstring>
</property>
</widget>
<widget row="2" column="0" rowspan="1" colspan="2" >
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>restoreButton</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>&amp;Restore</string>
+ </property>
+ </widget>
+ <widget row="0" column="0" >
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel1_2</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Select Source</string>
+ </property>
+ </widget>
+ <widget row="1" column="0" rowspan="1" colspan="2" >
<class>QListView</class>
<column>
<property>
<name>text</name>
<string>Column 1</string>
</property>
<property>
<name>clickable</name>
<bool>true</bool>
</property>
<property>
<name>resizeable</name>
@@ -164,51 +192,118 @@
<property stdset="1">
<name>name</name>
<cstring>restoreList</cstring>
</property>
<property stdset="1">
<name>minimumSize</name>
<size>
<width>0</width>
<height>100</height>
</size>
</property>
</widget>
- <widget row="3" column="0" rowspan="1" colspan="2" >
+ </grid>
+ </widget>
+ <widget>
+ <class>QWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>tab</cstring>
+ </property>
+ <attribute>
+ <name>title</name>
+ <string>Locations</string>
+ </attribute>
+ <grid>
+ <property stdset="1">
+ <name>margin</name>
+ <number>4</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>4</number>
+ </property>
+ <widget row="0" column="0" rowspan="1" colspan="3" >
+ <class>QLineEdit</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>locationEdit</cstring>
+ </property>
+ </widget>
+ <widget row="0" column="3" >
+ <class>QToolButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>locationSelectBtn</cstring>
+ </property>
+ <property stdset="1">
+ <name>maximumSize</name>
+ <size>
+ <width>20</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>...</string>
+ </property>
+ </widget>
+ <widget row="1" column="0" rowspan="1" colspan="4" >
+ <class>QListView</class>
+ <column>
+ <property>
+ <name>text</name>
+ <string>Locations</string>
+ </property>
+ <property>
+ <name>clickable</name>
+ <bool>true</bool>
+ </property>
+ <property>
+ <name>resizeable</name>
+ <bool>true</bool>
+ </property>
+ </column>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>locationList</cstring>
+ </property>
+ </widget>
+ <widget row="2" column="0" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
- <cstring>restoreButton</cstring>
+ <cstring>addLocationButton</cstring>
</property>
<property stdset="1">
<name>text</name>
- <string>&amp;Restore</string>
+ <string>Add</string>
</property>
</widget>
- <widget row="0" column="0" >
- <class>QLabel</class>
+ <widget row="2" column="1" >
+ <class>QPushButton</class>
<property stdset="1">
<name>name</name>
- <cstring>TextLabel1_2</cstring>
+ <cstring>removeLocationButton</cstring>
</property>
<property stdset="1">
<name>text</name>
- <string>Select Source</string>
+ <string>Remove</string>
</property>
</widget>
- <widget row="1" column="0" rowspan="1" colspan="2" >
+ <widget row="2" column="2" rowspan="1" colspan="2" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
- <cstring>updateList</cstring>
+ <cstring>saveLocationsButton</cstring>
</property>
<property stdset="1">
<name>text</name>
- <string>Update Filelist</string>
+ <string>Save</string>
</property>
</widget>
</grid>
</widget>
</widget>
</vbox>
</widget>
</UI>