author | eilers <eilers> | 2003-07-04 15:18:38 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-07-04 15:18:38 (UTC) |
commit | 51cb7e4cd9a7ec7f1bf864884928c61b9f2db3b0 (patch) (unidiff) | |
tree | 3afddd69a47a0dc040df163f7796364e9fc2e5f1 /noncore/settings/backup/backuprestore.cpp | |
parent | b3dabf7c01cd586408c2d80125076484283e6236 (diff) | |
download | opie-51cb7e4cd9a7ec7f1bf864884928c61b9f2db3b0.zip opie-51cb7e4cd9a7ec7f1bf864884928c61b9f2db3b0.tar.gz opie-51cb7e4cd9a7ec7f1bf864884928c61b9f2db3b0.tar.bz2 |
Merged all changes of opie-backup into HEAD to be able to work on
Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 115 |
1 files changed, 101 insertions, 14 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 59e15a2..4ff6be1 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -1,9 +1,10 @@ | |||
1 | 1 | ||
2 | #include "backuprestore.h" | 2 | #include "backuprestore.h" |
3 | //#include "output.h" | 3 | //#include "output.h" |
4 | #include "errordialog.h" | ||
4 | 5 | ||
5 | #include <qapplication.h> | 6 | #include <qapplication.h> |
6 | #include <qmultilineedit.h> | 7 | #include <qmultilineedit.h> |
7 | 8 | ||
8 | #include <qdir.h> | 9 | #include <qdir.h> |
9 | #include <qfile.h> | 10 | #include <qfile.h> |
@@ -15,12 +16,14 @@ | |||
15 | #include <qpe/config.h> | 16 | #include <qpe/config.h> |
16 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
17 | #include <qcombobox.h> | 18 | #include <qcombobox.h> |
18 | #include <qlist.h> | 19 | #include <qlist.h> |
19 | #include <stdlib.h> | 20 | #include <stdlib.h> |
20 | #include <qregexp.h> | 21 | #include <qregexp.h> |
22 | #include <qtextstream.h> | ||
23 | #include <qtextview.h> | ||
21 | 24 | ||
22 | #include <errno.h> | 25 | #include <errno.h> |
23 | #include <stdlib.h> | 26 | #include <stdlib.h> |
24 | #include <unistd.h> | 27 | #include <unistd.h> |
25 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
26 | #include <dirent.h> | 29 | #include <dirent.h> |
@@ -28,12 +31,15 @@ | |||
28 | #define HEADER_NAME 0 | 31 | #define HEADER_NAME 0 |
29 | #define HEADER_BACKUP 1 | 32 | #define HEADER_BACKUP 1 |
30 | #define BACKUP_LOCATION 2 | 33 | #define BACKUP_LOCATION 2 |
31 | 34 | ||
32 | #define EXTENSION ".bck" | 35 | #define EXTENSION ".bck" |
33 | 36 | ||
37 | const QString tempFileName = "/tmp/backup.err"; | ||
38 | |||
39 | |||
34 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | 40 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) |
35 | : BackupAndRestoreBase(parent, name){ | 41 | : BackupAndRestoreBase(parent, name){ |
36 | this->showMaximized(); | 42 | this->showMaximized(); |
37 | backupList->header()->hide(); | 43 | backupList->header()->hide(); |
38 | restoreList->header()->hide(); | 44 | restoreList->header()->hide(); |
39 | connect(backupButton, SIGNAL(clicked()), | 45 | connect(backupButton, SIGNAL(clicked()), |
@@ -41,12 +47,14 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
41 | connect(restoreButton, SIGNAL(clicked()), | 47 | connect(restoreButton, SIGNAL(clicked()), |
42 | this, SLOT(restore())); | 48 | this, SLOT(restore())); |
43 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | 49 | connect(backupList, SIGNAL(clicked( QListViewItem * )), |
44 | this, SLOT(selectItem(QListViewItem*))); | 50 | this, SLOT(selectItem(QListViewItem*))); |
45 | connect(restoreSource, SIGNAL(activated( int )), | 51 | connect(restoreSource, SIGNAL(activated( int )), |
46 | this, SLOT(sourceDirChanged(int))); | 52 | this, SLOT(sourceDirChanged(int))); |
53 | connect(updateList, SIGNAL(clicked()), | ||
54 | this, SLOT( fileListUpdate())); | ||
47 | 55 | ||
48 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", | 56 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", |
49 | QDir::homeDirPath() + "/Settings/"); | 57 | QDir::homeDirPath() + "/Settings/"); |
50 | selectItem(applicationSettings); | 58 | selectItem(applicationSettings); |
51 | applicationSettings = new QListViewItem(backupList, "Application Data", "", | 59 | applicationSettings = new QListViewItem(backupList, "Application Data", "", |
52 | QDir::homeDirPath() + "/Applications/"); | 60 | QDir::homeDirPath() + "/Applications/"); |
@@ -124,12 +132,16 @@ BackupAndRestore::~BackupAndRestore(){ | |||
124 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 132 | if(list.at(i)->text(HEADER_BACKUP) == ""){ |
125 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 133 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
126 | count++; | 134 | count++; |
127 | } | 135 | } |
128 | } | 136 | } |
129 | config.writeEntry("Total", count); | 137 | config.writeEntry("Total", count); |
138 | |||
139 | // Remove Temp File | ||
140 | if ( QFile::exists( tempFileName ) ) | ||
141 | QFile::remove( tempFileName ); | ||
130 | } | 142 | } |
131 | 143 | ||
132 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ | 144 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ |
133 | while(item){ | 145 | while(item){ |
134 | if(item->childCount() > 0) | 146 | if(item->childCount() > 0) |
135 | getAllItems(item->firstChild(), list); | 147 | getAllItems(item->firstChild(), list); |
@@ -188,39 +200,75 @@ void BackupAndRestore::backupPressed(){ | |||
188 | return; | 200 | return; |
189 | } | 201 | } |
190 | 202 | ||
191 | setCaption(tr("Backup and Restore... working...")); | 203 | setCaption(tr("Backup and Restore... working...")); |
192 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 204 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
193 | 205 | ||
194 | QDateTime time = QDateTime::currentDateTime(); | 206 | QDateTime datetime = QDateTime::currentDateTime(); |
195 | QString dateString = time.date().toString().replace(QRegExp(" "), ""); | 207 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
208 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | ||
209 | |||
196 | outputFile += "/" + dateString; | 210 | outputFile += "/" + dateString; |
197 | 211 | ||
198 | QString t = outputFile; | 212 | QString t = outputFile; |
199 | int c = 1; | 213 | int c = 1; |
200 | while(QFile::exists(outputFile + EXTENSION)){ | 214 | while(QFile::exists(outputFile + EXTENSION)){ |
201 | outputFile = t + QString("%1").arg(c); | 215 | outputFile = t + QString("%1").arg(c); |
202 | c++; | 216 | c++; |
203 | } | 217 | } |
204 | 218 | ||
205 | qDebug(QString("system(\"tar -c %1 | gzip > %2\")").arg(backupFiles).arg(outputFile).latin1()); | 219 | // We execute tar and compressing its output with gzip.. |
220 | // The error output will be written into a temp-file which could be provided | ||
221 | // for debugging.. | ||
222 | qDebug( "Storing file: %s", outputFile.latin1() ); | ||
206 | outputFile += EXTENSION; | 223 | outputFile += EXTENSION; |
207 | 224 | ||
208 | int r = system( QString("tar -c %1 | gzip > %2").arg(backupFiles).arg(outputFile).latin1() ); | 225 | qWarning( QString("(tar -c %1 | gzip > %2 ) 2> %3") |
226 | .arg( backupFiles ) | ||
227 | .arg( outputFile.latin1() ) | ||
228 | .arg( tempFileName.latin1() ) ); | ||
209 | 229 | ||
210 | 230 | ||
231 | int r = system( QString("(tar -c %1 | gzip > %2 ) 2> %3") | ||
232 | .arg( backupFiles ) | ||
233 | .arg( outputFile.latin1() ) | ||
234 | .arg( tempFileName.latin1() ) ); | ||
211 | 235 | ||
212 | if(r != 0){ | 236 | if(r != 0){ |
213 | perror("Error: "); | 237 | perror("Error: "); |
214 | QString errorMsg="Error\n"+(QString)strerror(errno); | 238 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
239 | |||
240 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | ||
241 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ | ||
215 | 242 | ||
216 | QMessageBox::critical(this, "Message", "Backup Failed.\n"+errorMsg, QString("Ok") ); | 243 | case 1: |
244 | qWarning("Details pressed !"); | ||
245 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | ||
246 | QFile errorFile( tempFileName ); | ||
247 | if ( errorFile.open(IO_ReadOnly) ) { | ||
248 | QTextStream t( &errorFile ); | ||
249 | QString s; | ||
250 | while ( !t.eof() ) { // until end of file... | ||
251 | s += t.readLine(); // line of text excluding '\n' | ||
252 | } | ||
253 | errorFile.close(); | ||
254 | |||
255 | pErrDialog->m_textarea->setText( s ); | ||
256 | }else{ | ||
257 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); | ||
258 | } | ||
259 | pErrDialog->showMaximized(); | ||
260 | pErrDialog->exec(); | ||
261 | delete pErrDialog; | ||
262 | break; | ||
263 | } | ||
264 | setCaption(tr("Backup and Restore.. Failed !!")); | ||
217 | return; | 265 | return; |
218 | } | 266 | } |
219 | else{ | 267 | else{ |
220 | QMessageBox::information(this, "Message", "Backup Successfull.",QString("Ok") ); | 268 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); |
221 | 269 | ||
222 | } | 270 | } |
223 | setCaption(tr("Backup and Restore")); | 271 | setCaption(tr("Backup and Restore")); |
224 | } | 272 | } |
225 | 273 | ||
226 | /*** | 274 | /*** |
@@ -258,12 +306,19 @@ int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent | |||
258 | 306 | ||
259 | void BackupAndRestore::sourceDirChanged(int selection){ | 307 | void BackupAndRestore::sourceDirChanged(int selection){ |
260 | restoreList->clear(); | 308 | restoreList->clear(); |
261 | rescanFolder(backupLocations[restoreSource->text(selection)]); | 309 | rescanFolder(backupLocations[restoreSource->text(selection)]); |
262 | } | 310 | } |
263 | 311 | ||
312 | void BackupAndRestore::fileListUpdate() | ||
313 | { | ||
314 | qWarning("void BackupAndRestore::fileListUpdate()"); | ||
315 | restoreList->clear(); | ||
316 | rescanFolder( backupLocations[restoreSource->currentText()] ); | ||
317 | } | ||
318 | |||
264 | /** | 319 | /** |
265 | * Scans directory for any backup files. Will recursivly go down, | 320 | * Scans directory for any backup files. Will recursivly go down, |
266 | * but will not follow symlinks. | 321 | * but will not follow symlinks. |
267 | * @param directory - the directory to look in. | 322 | * @param directory - the directory to look in. |
268 | */ | 323 | */ |
269 | void BackupAndRestore::rescanFolder(QString directory){ | 324 | void BackupAndRestore::rescanFolder(QString directory){ |
@@ -296,27 +351,59 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
296 | * Restore a backup file. | 351 | * Restore a backup file. |
297 | * Report errors or success | 352 | * Report errors or success |
298 | */ | 353 | */ |
299 | void BackupAndRestore::restore(){ | 354 | void BackupAndRestore::restore(){ |
300 | QListViewItem *restoreItem = restoreList->currentItem(); | 355 | QListViewItem *restoreItem = restoreList->currentItem(); |
301 | if(!restoreItem){ | 356 | if(!restoreItem){ |
302 | QMessageBox::critical(this, "Message", | 357 | QMessageBox::critical(this, tr( "Message" ), |
303 | "Please select something to restore.",QString("Ok") ); | 358 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); |
304 | return; | 359 | return; |
305 | } | 360 | } |
361 | setCaption(tr("Backup and Restore... working...")); | ||
362 | |||
306 | QString restoreFile = backupLocations[restoreSource->currentText()]; | 363 | QString restoreFile = backupLocations[restoreSource->currentText()]; |
307 | 364 | ||
308 | restoreFile += "/" + restoreItem->text(0); | 365 | restoreFile += "/" + restoreItem->text(0); |
309 | 366 | ||
310 | int r = system(QString("tar -C / -zxf %1").arg(restoreFile).latin1()); | 367 | int r = system(QString("tar -C / -zxf %1 2> %3") |
368 | .arg( restoreFile.latin1() ) | ||
369 | .arg( tempFileName.latin1() ) ); | ||
311 | if(r != 0){ | 370 | if(r != 0){ |
312 | QMessageBox::critical(this, "Message", | 371 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
313 | "Restore Failed.",QString("Ok") ); | 372 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
373 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { | ||
374 | case 1: | ||
375 | qWarning("Details pressed !"); | ||
376 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | ||
377 | QFile errorFile( tempFileName ); | ||
378 | if ( errorFile.open(IO_ReadOnly) ) { | ||
379 | QTextStream t( &errorFile ); | ||
380 | QString s; | ||
381 | while ( !t.eof() ) { // until end of file... | ||
382 | s += t.readLine(); // line of text excluding '\n' | ||
383 | } | ||
384 | errorFile.close(); | ||
385 | |||
386 | pErrDialog->m_textarea->setText( s ); | ||
387 | }else{ | ||
388 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | ||
389 | } | ||
390 | pErrDialog->showMaximized(); | ||
391 | pErrDialog->exec(); | ||
392 | delete pErrDialog; | ||
393 | |||
394 | setCaption(tr("Backup and Restore.. Failed !!")); | ||
395 | return; | ||
396 | |||
397 | break; | ||
398 | |||
399 | } | ||
314 | } | 400 | } |
315 | else{ | 401 | else{ |
316 | QMessageBox::critical(this, "Message", | 402 | QMessageBox::critical(this, tr( "Message" ), |
317 | "Restore Successfull.",QString("Ok") ); | 403 | tr( "Restore Successfull." ), QString( tr( "Ok") ) ); |
318 | } | 404 | } |
405 | setCaption(tr("Backup and Restore")); | ||
319 | } | 406 | } |
320 | 407 | ||
321 | // backuprestore.cpp | 408 | // backuprestore.cpp |
322 | 409 | ||