Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index a00193d..977c283 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -1,68 +1,70 @@ | |||
1 | 1 | ||
2 | #include "backuprestore.h" | 2 | #include "backuprestore.h" |
3 | //#include "output.h" | ||
4 | #include "errordialog.h" | 3 | #include "errordialog.h" |
5 | 4 | ||
5 | /* OPIE */ | ||
6 | #include <opie2/ostorageinfo.h> | ||
7 | #include <qpe/qpeapplication.h> | ||
8 | |||
9 | /* QT */ | ||
6 | #include <qapplication.h> | 10 | #include <qapplication.h> |
7 | #include <qmultilineedit.h> | 11 | #include <qmultilineedit.h> |
8 | |||
9 | #include <qdir.h> | 12 | #include <qdir.h> |
10 | #include <qfile.h> | 13 | #include <qfile.h> |
11 | #include <qfileinfo.h> | 14 | #include <qfileinfo.h> |
12 | #include <qlistview.h> | 15 | #include <qlistview.h> |
13 | #include <qpushbutton.h> | 16 | #include <qpushbutton.h> |
14 | #include <qheader.h> | 17 | #include <qheader.h> |
15 | #include <qpe/resource.h> | 18 | #include <qpe/resource.h> |
16 | #include <qpe/config.h> | 19 | #include <qpe/config.h> |
17 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
18 | #include <qcombobox.h> | 21 | #include <qcombobox.h> |
19 | #include <qlist.h> | 22 | #include <qlist.h> |
20 | #include <stdlib.h> | 23 | #include <stdlib.h> |
21 | #include <qregexp.h> | 24 | #include <qregexp.h> |
22 | #include <qtextstream.h> | 25 | #include <qtextstream.h> |
23 | #include <qtextview.h> | 26 | #include <qtextview.h> |
24 | #include <opie2/ostorageinfo.h> | ||
25 | 27 | ||
28 | /* STD */ | ||
26 | #include <errno.h> | 29 | #include <errno.h> |
27 | #include <stdlib.h> | 30 | #include <stdlib.h> |
28 | #include <unistd.h> | 31 | #include <unistd.h> |
29 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
30 | #include <dirent.h> | 33 | #include <dirent.h> |
31 | 34 | ||
32 | #define HEADER_NAME 0 | 35 | #define HEADER_NAME 0 |
33 | #define HEADER_BACKUP 1 | 36 | #define HEADER_BACKUP 1 |
34 | #define BACKUP_LOCATION 2 | 37 | #define BACKUP_LOCATION 2 |
35 | 38 | ||
36 | #define EXTENSION ".bck" | 39 | #define EXTENSION ".bck" |
37 | 40 | ||
38 | const QString tempFileName = "/tmp/backup.err"; | 41 | const QString tempFileName = "/tmp/backup.err"; |
39 | 42 | ||
40 | 43 | ||
41 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) | 44 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) |
42 | : BackupAndRestoreBase(parent, name, fl) | 45 | : BackupAndRestoreBase(parent, name, fl) |
43 | { | 46 | { |
44 | this->showMaximized(); | ||
45 | backupList->header()->hide(); | 47 | backupList->header()->hide(); |
46 | restoreList->header()->hide(); | 48 | restoreList->header()->hide(); |
47 | connect(backupButton, SIGNAL(clicked()), | 49 | connect(backupButton, SIGNAL(clicked()), |
48 | this, SLOT(backup())); | 50 | this, SLOT(backup())); |
49 | connect(restoreButton, SIGNAL(clicked()), | 51 | connect(restoreButton, SIGNAL(clicked()), |
50 | this, SLOT(restore())); | 52 | this, SLOT(restore())); |
51 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | 53 | connect(backupList, SIGNAL(clicked( QListViewItem * )), |
52 | this, SLOT(selectItem(QListViewItem*))); | 54 | this, SLOT(selectItem(QListViewItem*))); |
53 | connect(restoreSource, SIGNAL(activated( int )), | 55 | connect(restoreSource, SIGNAL(activated( int )), |
54 | this, SLOT(sourceDirChanged(int))); | 56 | this, SLOT(sourceDirChanged(int))); |
55 | connect(updateList, SIGNAL(clicked()), | 57 | connect(updateList, SIGNAL(clicked()), |
56 | this, SLOT( fileListUpdate())); | 58 | this, SLOT( fileListUpdate())); |
57 | 59 | ||
58 | //add directorys for backing up | 60 | //add directorys for backing up |
59 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); | 61 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); |
60 | selectItem(applicationSettings); | 62 | selectItem(applicationSettings); |
61 | applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); | 63 | applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); |
62 | selectItem(applicationSettings); | 64 | selectItem(applicationSettings); |
63 | documents= new QListViewItem(backupList, "Documents", "", "Documents/"); | 65 | documents= new QListViewItem(backupList, "Documents", "", "Documents/"); |
64 | selectItem(documents); | 66 | selectItem(documents); |
65 | 67 | ||
66 | scanForApplicationSettings(); | 68 | scanForApplicationSettings(); |
67 | 69 | ||
68 | OStorageInfo storage; | 70 | OStorageInfo storage; |
@@ -109,48 +111,49 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags f | |||
109 | QList<QString> dontBackupList; | 111 | QList<QString> dontBackupList; |
110 | dontBackupList.setAutoDelete(true); | 112 | dontBackupList.setAutoDelete(true); |
111 | config.setGroup("DontBackup"); | 113 | config.setGroup("DontBackup"); |
112 | int total = config.readNumEntry("Total", 0); | 114 | int total = config.readNumEntry("Total", 0); |
113 | for(int i = 0; i < total; i++) | 115 | for(int i = 0; i < total; i++) |
114 | { | 116 | { |
115 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | 117 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); |
116 | } | 118 | } |
117 | 119 | ||
118 | QList<QListViewItem> list; | 120 | QList<QListViewItem> list; |
119 | getAllItems(backupList->firstChild(), list); | 121 | getAllItems(backupList->firstChild(), list); |
120 | 122 | ||
121 | for(uint i = 0; i < list.count(); i++) | 123 | for(uint i = 0; i < list.count(); i++) |
122 | { | 124 | { |
123 | QString text = list.at(i)->text(HEADER_NAME); | 125 | QString text = list.at(i)->text(HEADER_NAME); |
124 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++) | 126 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++) |
125 | { | 127 | { |
126 | if(*dontBackupList.at(i2) == text) | 128 | if(*dontBackupList.at(i2) == text) |
127 | { | 129 | { |
128 | selectItem(list.at(i)); | 130 | selectItem(list.at(i)); |
129 | break; | 131 | break; |
130 | } | 132 | } |
131 | } | 133 | } |
132 | } | 134 | } |
135 | QPEApplication::showWidget( this ); | ||
133 | } | 136 | } |
134 | 137 | ||
135 | BackupAndRestore::~BackupAndRestore() | 138 | BackupAndRestore::~BackupAndRestore() |
136 | { | 139 | { |
137 | QList<QListViewItem> list; | 140 | QList<QListViewItem> list; |
138 | getAllItems(backupList->firstChild(), list); | 141 | getAllItems(backupList->firstChild(), list); |
139 | 142 | ||
140 | Config config("BackupAndRestore"); | 143 | Config config("BackupAndRestore"); |
141 | config.setGroup("DontBackup"); | 144 | config.setGroup("DontBackup"); |
142 | config.clearGroup(); | 145 | config.clearGroup(); |
143 | 146 | ||
144 | int count = 0; | 147 | int count = 0; |
145 | for(uint i = 0; i < list.count(); i++) | 148 | for(uint i = 0; i < list.count(); i++) |
146 | { | 149 | { |
147 | if(list.at(i)->text(HEADER_BACKUP) == "") | 150 | if(list.at(i)->text(HEADER_BACKUP) == "") |
148 | { | 151 | { |
149 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 152 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
150 | count++; | 153 | count++; |
151 | } | 154 | } |
152 | } | 155 | } |
153 | config.writeEntry("Total", count); | 156 | config.writeEntry("Total", count); |
154 | 157 | ||
155 | // Remove Temp File | 158 | // Remove Temp File |
156 | if ( QFile::exists( tempFileName ) ) | 159 | if ( QFile::exists( tempFileName ) ) |
@@ -266,50 +269,49 @@ void BackupAndRestore::backup() | |||
266 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | 269 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" |
267 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) | 270 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) |
268 | { | 271 | { |
269 | 272 | ||
270 | case 1: | 273 | case 1: |
271 | qWarning("Details pressed !"); | 274 | qWarning("Details pressed !"); |
272 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 275 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
273 | QFile errorFile( tempFileName ); | 276 | QFile errorFile( tempFileName ); |
274 | if ( errorFile.open(IO_ReadOnly) ) | 277 | if ( errorFile.open(IO_ReadOnly) ) |
275 | { | 278 | { |
276 | QTextStream t( &errorFile ); | 279 | QTextStream t( &errorFile ); |
277 | QString s; | 280 | QString s; |
278 | while ( !t.eof() ) | 281 | while ( !t.eof() ) |
279 | { // until end of file... | 282 | { // until end of file... |
280 | s += t.readLine(); // line of text excluding '\n' | 283 | s += t.readLine(); // line of text excluding '\n' |
281 | } | 284 | } |
282 | errorFile.close(); | 285 | errorFile.close(); |
283 | 286 | ||
284 | pErrDialog->m_textarea->setText( s ); | 287 | pErrDialog->m_textarea->setText( s ); |
285 | } | 288 | } |
286 | else | 289 | else |
287 | { | 290 | { |
288 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); | 291 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); |
289 | } | 292 | } |
290 | pErrDialog->showMaximized(); | 293 | QPEApplication::execDialog( pErrDialog ); |
291 | pErrDialog->exec(); | ||
292 | delete pErrDialog; | 294 | delete pErrDialog; |
293 | break; | 295 | break; |
294 | } | 296 | } |
295 | setCaption(tr("Backup and Restore.. Failed !!")); | 297 | setCaption(tr("Backup and Restore.. Failed !!")); |
296 | return; | 298 | return; |
297 | } | 299 | } |
298 | else | 300 | else |
299 | { | 301 | { |
300 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); | 302 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); |
301 | 303 | ||
302 | } | 304 | } |
303 | 305 | ||
304 | //write store-location | 306 | //write store-location |
305 | Config config( "BackupAndRestore" ); | 307 | Config config( "BackupAndRestore" ); |
306 | config.setGroup( "LastLocation" ); | 308 | config.setGroup( "LastLocation" ); |
307 | config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); | 309 | config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); |
308 | 310 | ||
309 | setCaption(tr("Backup and Restore")); | 311 | setCaption(tr("Backup and Restore")); |
310 | } | 312 | } |
311 | 313 | ||
312 | /*** | 314 | /*** |
313 | * Get a list of all of the files to backup. | 315 | * Get a list of all of the files to backup. |
314 | */ | 316 | */ |
315 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) | 317 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) |
@@ -431,50 +433,49 @@ void BackupAndRestore::restore() | |||
431 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 433 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
432 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" | 434 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
433 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) | 435 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) |
434 | { | 436 | { |
435 | case 1: | 437 | case 1: |
436 | qWarning("Details pressed !"); | 438 | qWarning("Details pressed !"); |
437 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 439 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
438 | QFile errorFile( tempFileName ); | 440 | QFile errorFile( tempFileName ); |
439 | if ( errorFile.open(IO_ReadOnly) ) | 441 | if ( errorFile.open(IO_ReadOnly) ) |
440 | { | 442 | { |
441 | QTextStream t( &errorFile ); | 443 | QTextStream t( &errorFile ); |
442 | QString s; | 444 | QString s; |
443 | while ( !t.eof() ) | 445 | while ( !t.eof() ) |
444 | { // until end of file... | 446 | { // until end of file... |
445 | s += t.readLine(); // line of text excluding '\n' | 447 | s += t.readLine(); // line of text excluding '\n' |
446 | } | 448 | } |
447 | errorFile.close(); | 449 | errorFile.close(); |
448 | 450 | ||
449 | pErrDialog->m_textarea->setText( s ); | 451 | pErrDialog->m_textarea->setText( s ); |
450 | } | 452 | } |
451 | else | 453 | else |
452 | { | 454 | { |
453 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | 455 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); |
454 | } | 456 | } |
455 | pErrDialog->showMaximized(); | 457 | QPEApplication::execDialog( pErrDialog ); |
456 | pErrDialog->exec(); | ||
457 | delete pErrDialog; | 458 | delete pErrDialog; |
458 | 459 | ||
459 | setCaption(tr("Backup and Restore.. Failed !!")); | 460 | setCaption(tr("Backup and Restore.. Failed !!")); |
460 | return; | 461 | return; |
461 | 462 | ||
462 | break; | 463 | break; |
463 | 464 | ||
464 | } | 465 | } |
465 | } | 466 | } |
466 | else | 467 | else |
467 | { | 468 | { |
468 | QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) ); | 469 | QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) ); |
469 | } | 470 | } |
470 | 471 | ||
471 | //write restore-location | 472 | //write restore-location |
472 | Config config( "BackupAndRestore" ); | 473 | Config config( "BackupAndRestore" ); |
473 | config.setGroup( "LastLocation" ); | 474 | config.setGroup( "LastLocation" ); |
474 | config.writeEntry( "LastRestoreLocation", restoreSource->currentText() ); | 475 | config.writeEntry( "LastRestoreLocation", restoreSource->currentText() ); |
475 | 476 | ||
476 | setCaption(tr("Backup and Restore")); | 477 | setCaption(tr("Backup and Restore")); |
477 | } | 478 | } |
478 | 479 | ||
479 | // backuprestore.cpp | 480 | // backuprestore.cpp |
480 | 481 | ||