-rw-r--r-- | noncore/settings/backup/backup.pro | 7 | ||||
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 68 | ||||
-rw-r--r-- | noncore/settings/backup/backuprestore.h | 13 | ||||
-rw-r--r-- | noncore/settings/backup/main.cpp | 10 |
4 files changed, 44 insertions, 54 deletions
diff --git a/noncore/settings/backup/backup.pro b/noncore/settings/backup/backup.pro index cadb381..1e9af61 100644 --- a/noncore/settings/backup/backup.pro +++ b/noncore/settings/backup/backup.pro | |||
@@ -1,6 +1,4 @@ | |||
1 | TEMPLATE= app | 1 | CONFIG = qt warn_on release quick-app |
2 | #CONFIG = qt warn_on debug | ||
3 | CONFIG = qt warn_on release | ||
4 | HEADERS = backuprestore.h | 2 | HEADERS = backuprestore.h |
5 | SOURCES = main.cpp backuprestore.cpp | 3 | SOURCES = main.cpp backuprestore.cpp |
6 | INCLUDEPATH+= $(OPIEDIR)/include | 4 | INCLUDEPATH+= $(OPIEDIR)/include |
@@ -8,7 +6,6 @@ DEPENDPATH += $(OPIEDIR)/include | |||
8 | LIBS += -lqpe | 6 | LIBS += -lqpe |
9 | INTERFACES= backuprestorebase.ui errordialog.ui | 7 | INTERFACES= backuprestorebase.ui errordialog.ui |
10 | TARGET = backup | 8 | TARGET = backup |
11 | DESTDIR = $(OPIEDIR)/bin | ||
12 | 9 | ||
13 | TRANSLATIONS = ../../../i18n/de/backup.ts \ | 10 | TRANSLATIONS = ../../../i18n/de/backup.ts \ |
14 | ../../../i18n/nl/backup.ts \ | 11 | ../../../i18n/nl/backup.ts \ |
@@ -30,6 +27,4 @@ TRANSLATIONS = ../../../i18n/de/backup.ts \ | |||
30 | ../../../i18n/da/backup.ts | 27 | ../../../i18n/da/backup.ts |
31 | 28 | ||
32 | 29 | ||
33 | |||
34 | |||
35 | include ( $(OPIEDIR)/include.pro ) | 30 | include ( $(OPIEDIR)/include.pro ) |
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 | |||
@@ -37,8 +37,8 @@ | |||
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(); |
@@ -47,11 +47,11 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
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/"); |
@@ -62,13 +62,13 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
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"); |
@@ -86,8 +86,8 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
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"); |
@@ -98,7 +98,7 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
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++){ |
@@ -113,11 +113,11 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
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) == ""){ |
@@ -135,7 +135,7 @@ BackupAndRestore::~BackupAndRestore(){ | |||
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 | } |
@@ -179,27 +179,27 @@ void BackupAndRestore::scanForApplicationSettings(){ | |||
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)){ |
@@ -207,7 +207,7 @@ void BackupAndRestore::backupPressed(){ | |||
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() ); |
@@ -228,7 +228,7 @@ void BackupAndRestore::backupPressed(){ | |||
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: |
@@ -242,7 +242,7 @@ void BackupAndRestore::backupPressed(){ | |||
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" ); |
@@ -253,18 +253,18 @@ void BackupAndRestore::backupPressed(){ | |||
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; |
@@ -274,7 +274,7 @@ int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent | |||
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" ){ |
@@ -317,7 +317,7 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
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 ); |
@@ -341,26 +341,26 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
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 !"); |
@@ -373,7 +373,7 @@ void BackupAndRestore::restore(){ | |||
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" ) ); |
@@ -383,7 +383,7 @@ void BackupAndRestore::restore(){ | |||
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 | ||
diff --git a/noncore/settings/backup/backuprestore.h b/noncore/settings/backup/backuprestore.h index 8c733e3..4bdc758 100644 --- a/noncore/settings/backup/backuprestore.h +++ b/noncore/settings/backup/backuprestore.h | |||
@@ -1,4 +1,4 @@ | |||
1 | #ifndef WINDOW_H | 1 | #ifndef WINDOW_H |
2 | #define WINDOW_H | 2 | #define WINDOW_H |
3 | 3 | ||
4 | #include <qmainwindow.h> | 4 | #include <qmainwindow.h> |
@@ -8,16 +8,17 @@ | |||
8 | 8 | ||
9 | class QListViewItem; | 9 | class QListViewItem; |
10 | 10 | ||
11 | class BackupAndRestore : public BackupAndRestoreBase { | 11 | class BackupAndRestore : public BackupAndRestoreBase { |
12 | 12 | ||
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | 16 | ||
17 | BackupAndRestore( QWidget* parent = 0, const char* name = 0); | 17 | BackupAndRestore( QWidget* parent = 0, const char* name = 0, WFlags fl = 0); |
18 | ~BackupAndRestore(); | 18 | ~BackupAndRestore(); |
19 | 19 | ||
20 | 20 | static QString appName() { return QString::fromLatin1("backup"); } | |
21 | |||
21 | private slots: | 22 | private slots: |
22 | void backupPressed(); | 23 | void backupPressed(); |
23 | void restore(); | 24 | void restore(); |
diff --git a/noncore/settings/backup/main.cpp b/noncore/settings/backup/main.cpp index 676e1f0..b375a3b 100644 --- a/noncore/settings/backup/main.cpp +++ b/noncore/settings/backup/main.cpp | |||
@@ -1,14 +1,8 @@ | |||
1 | #include "backuprestore.h" | 1 | #include "backuprestore.h" |
2 | #include "qnetworkprotocol.h" | 2 | #include "qnetworkprotocol.h" |
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <opie/oapplicationfactory.h> | ||
4 | 5 | ||
5 | int main(int argc, char *argv[]) { | ||
6 | QPEApplication a( argc, argv ); | ||
7 | |||
8 | BackupAndRestore app(0, "mainwindow"); | ||
9 | a.showMainWidget(&app); | ||
10 | return a.exec(); | ||
11 | } | ||
12 | 6 | ||
13 | // main.cpp | 7 | OPIE_EXPORT_APP( OApplicationFactory<BackupAndRestore> ) |
14 | 8 | ||