summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 36b101c..1748e8d 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -1,106 +1,107 @@
1#include "backuprestore.h" 1#include "backuprestore.h"
2#include "errordialog.h" 2#include "errordialog.h"
3 3
4 4
5/* OPIE */ 5/* OPIE */
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7#include <opie2/ostorageinfo.h> 7#include <opie2/ostorageinfo.h>
8using namespace Opie::Core; 8using namespace Opie::Core;
9 9
10#include <opie2/ofiledialog.h> 10#include <opie2/ofiledialog.h>
11#include <opie2/owait.h>
11using namespace Opie::Ui; 12using namespace Opie::Ui;
12 13
13#include <qpe/qpeapplication.h> 14#include <qpe/qpeapplication.h>
14#include <qpe/resource.h> 15#include <qpe/resource.h>
15#include <qpe/config.h> 16#include <qpe/config.h>
16 17
17/* QT */ 18/* QT */
18#include <qapplication.h> 19#include <qapplication.h>
19#include <qmultilineedit.h> 20#include <qmultilineedit.h>
20#include <qdir.h> 21#include <qdir.h>
21#include <qfile.h> 22#include <qfile.h>
22#include <qfileinfo.h> 23#include <qfileinfo.h>
23#include <qlistview.h> 24#include <qlistview.h>
24#include <qpushbutton.h> 25#include <qpushbutton.h>
25#include <qheader.h> 26#include <qheader.h>
26#include <qmessagebox.h> 27#include <qmessagebox.h>
27#include <qcombobox.h> 28#include <qcombobox.h>
28#include <qlist.h> 29#include <qlist.h>
29#include <qregexp.h> 30#include <qregexp.h>
30#include <qtextstream.h> 31#include <qtextstream.h>
31#include <qtextview.h> 32#include <qtextview.h>
32#include <qlineedit.h> 33#include <qlineedit.h>
33#include <qstringlist.h> 34#include <qstringlist.h>
34 35
35/* STD */ 36/* STD */
36#include <errno.h> 37#include <errno.h>
37#include <stdlib.h> 38#include <stdlib.h>
38#include <unistd.h> 39#include <unistd.h>
39#include <sys/stat.h> 40#include <sys/stat.h>
40#include <dirent.h> 41#include <dirent.h>
41 42
42#define HEADER_NAME 0 43#define HEADER_NAME 0
43#define HEADER_BACKUP 1 44#define HEADER_BACKUP 1
44#define BACKUP_LOCATION 2 45#define BACKUP_LOCATION 2
45 46
46#define EXTENSION ".bck" 47#define EXTENSION ".bck"
47 48
48const QString tempFileName = "/tmp/backup.err"; 49const QString tempFileName = "/tmp/backup.err";
49 50
50BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) 51BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl)
51 : BackupAndRestoreBase(parent, name, fl) 52 : BackupAndRestoreBase(parent, name, fl)
52{ 53{
53 backupList->header()->hide(); 54 backupList->header()->hide();
54 restoreList->header()->hide(); 55 restoreList->header()->hide();
55 locationList->header()->hide(); 56 locationList->header()->hide();
56 connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) ); 57 connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) );
57 connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) ); 58 connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) );
58 connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) ); 59 connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) );
59 connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) ); 60 connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) );
60 connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) ); 61 connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) );
61 connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) ); 62 connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) );
62 connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) ); 63 connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) );
63 connect( selectLocationButton, SIGNAL( clicked() ), this, SLOT( selectLocation() ) ); 64 connect( selectLocationButton, SIGNAL( clicked() ), this, SLOT( selectLocation() ) );
64 65
65 //add directorys for backing up 66 //add directorys for backing up
66 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); 67 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/");
67 selectItem(applicationSettings); 68 selectItem(applicationSettings);
68 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); 69 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/");
69 selectItem(applicationSettings); 70 selectItem(applicationSettings);
70 documents= new QListViewItem(backupList, "Documents", "", "Documents/"); 71 documents= new QListViewItem(backupList, "Documents", "", "Documents/");
71 selectItem(documents); 72 selectItem(documents);
72 73
73 scanForApplicationSettings(); 74 scanForApplicationSettings();
74 refreshLocations(); 75 refreshLocations();
75 refreshBackupLocations(); 76 refreshBackupLocations();
76 77
77 // Read the list of items to ignore. 78 // Read the list of items to ignore.
78 QList<QString> dontBackupList; 79 QList<QString> dontBackupList;
79 dontBackupList.setAutoDelete(true); 80 dontBackupList.setAutoDelete(true);
80 Config config("BackupAndRestore"); 81 Config config("BackupAndRestore");
81 config.setGroup("DontBackup"); 82 config.setGroup("DontBackup");
82 int total = config.readNumEntry("Total", 0); 83 int total = config.readNumEntry("Total", 0);
83 for(int i = 0; i < total; i++) 84 for(int i = 0; i < total; i++)
84 { 85 {
85 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); 86 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), "")));
86 } 87 }
87 88
88 QList<QListViewItem> list; 89 QList<QListViewItem> list;
89 getAllItems(backupList->firstChild(), list); 90 getAllItems(backupList->firstChild(), list);
90 91
91 for(uint i = 0; i < list.count(); i++) 92 for(uint i = 0; i < list.count(); i++)
92 { 93 {
93 QString text = list.at(i)->text(HEADER_NAME); 94 QString text = list.at(i)->text(HEADER_NAME);
94 for(uint i2 = 0; i2 < dontBackupList.count(); i2++) 95 for(uint i2 = 0; i2 < dontBackupList.count(); i2++)
95 { 96 {
96 if(*dontBackupList.at(i2) == text) 97 if(*dontBackupList.at(i2) == text)
97 { 98 {
98 selectItem(list.at(i)); 99 selectItem(list.at(i));
99 break; 100 break;
100 } 101 }
101 } 102 }
102 } 103 }
103 QPEApplication::showWidget( this ); 104 QPEApplication::showWidget( this );
104} 105}
105 106
106BackupAndRestore::~BackupAndRestore() 107BackupAndRestore::~BackupAndRestore()
@@ -158,408 +159,423 @@ void BackupAndRestore::refreshBackupLocations()
158 //update QComboBox 159 //update QComboBox
159 storeToLocation->clear(); 160 storeToLocation->clear();
160 restoreSource->clear(); 161 restoreSource->clear();
161 162
162 //read last locations 163 //read last locations
163 Config config("BackupAndRestore"); 164 Config config("BackupAndRestore");
164 config.setGroup("LastLocation"); 165 config.setGroup("LastLocation");
165 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" ); 166 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" );
166 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" ); 167 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" );
167 int locationIndex = 0; 168 int locationIndex = 0;
168 169
169 //fill QComboBox 170 //fill QComboBox
170 QMap<QString, QString>::Iterator it; 171 QMap<QString, QString>::Iterator it;
171 for( it = backupLocations.begin(); it != backupLocations.end(); ++it ) 172 for( it = backupLocations.begin(); it != backupLocations.end(); ++it )
172 { 173 {
173 storeToLocation->insertItem(it.key()); 174 storeToLocation->insertItem(it.key());
174 restoreSource->insertItem(it.key()); 175 restoreSource->insertItem(it.key());
175 176
176 //check for last locations 177 //check for last locations
177 if ( it.key() == lastStoreLocation ) 178 if ( it.key() == lastStoreLocation )
178 storeToLocation->setCurrentItem( locationIndex ); 179 storeToLocation->setCurrentItem( locationIndex );
179 if ( it.key() == lastRestoreLocation ) 180 if ( it.key() == lastRestoreLocation )
180 restoreSource->setCurrentItem( locationIndex ); 181 restoreSource->setCurrentItem( locationIndex );
181 locationIndex++; 182 locationIndex++;
182 } 183 }
183} 184}
184 185
185QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) 186QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list)
186{ 187{
187 while(item) 188 while(item)
188 { 189 {
189 if(item->childCount() > 0) 190 if(item->childCount() > 0)
190 getAllItems(item->firstChild(), list); 191 getAllItems(item->firstChild(), list);
191 list.append(item); 192 list.append(item);
192 item = item->nextSibling(); 193 item = item->nextSibling();
193 } 194 }
194 return list; 195 return list;
195} 196}
196 197
197/** 198/**
198 * Selects and unselects the item by setting the HEADER_BACKUP to B or !. 199 * Selects and unselects the item by setting the HEADER_BACKUP to B or !.
199 * and changing the icon to match 200 * and changing the icon to match
200 * @param currentItem the item to swich the selection choice. 201 * @param currentItem the item to swich the selection choice.
201 */ 202 */
202void BackupAndRestore::selectItem(QListViewItem *currentItem) 203void BackupAndRestore::selectItem(QListViewItem *currentItem)
203{ 204{
204 if(!currentItem) 205 if(!currentItem)
205 return; 206 return;
206 207
207 if(currentItem->text(HEADER_BACKUP) == "B") 208 if(currentItem->text(HEADER_BACKUP) == "B")
208 { 209 {
209 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); 210 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null"));
210 currentItem->setText(HEADER_BACKUP, ""); 211 currentItem->setText(HEADER_BACKUP, "");
211 } 212 }
212 else 213 else
213 { 214 {
214 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); 215 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check"));
215 currentItem->setText(HEADER_BACKUP, "B"); 216 currentItem->setText(HEADER_BACKUP, "B");
216 } 217 }
217} 218}
218 219
219void BackupAndRestore::scanForApplicationSettings() 220void BackupAndRestore::scanForApplicationSettings()
220{ 221{
221 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); 222 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) );
222 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); 223 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
223 const QFileInfoList *list = d.entryInfoList(); 224 const QFileInfoList *list = d.entryInfoList();
224 QFileInfoListIterator it( *list ); 225 QFileInfoListIterator it( *list );
225 QFileInfo *fi; 226 QFileInfo *fi;
226 while ( (fi=it.current()) ) 227 while ( (fi=it.current()) )
227 { 228 {
228 //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; 229 //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl;
229 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) 230 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) )
230 { 231 {
231 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); 232 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName());
232 selectItem(newItem); 233 selectItem(newItem);
233 } 234 }
234 ++it; 235 ++it;
235 } 236 }
236} 237}
237 238
238/** 239/**
239 * The "Backup" button has been pressed. Get a list of all of the files that 240 * The "Backup" button has been pressed. Get a list of all of the files that
240 * should be backed up. If there are no files, emit and error and exit. 241 * should be backed up. If there are no files, emit and error and exit.
241 * Determine the file name to store the backup in. Backup the file(s) using 242 * Determine the file name to store the backup in. Backup the file(s) using
242 * tar and gzip --best. Report failure or success 243 * tar and gzip --best. Report failure or success
243 */ 244 */
244void BackupAndRestore::backup() 245void BackupAndRestore::backup()
245{ 246{
246 QString backupFiles; 247 QString backupFiles;
247 if(getBackupFiles(backupFiles, NULL) == 0) 248 if(getBackupFiles(backupFiles, NULL) == 0)
248 { 249 {
249 QMessageBox::critical(this, "Message", 250 QMessageBox::critical(this, "Message",
250 "No items selected.",QString("Ok") ); 251 "No items selected.",QString("Ok") );
251 return; 252 return;
252 } 253 }
253 254
254 setCaption(tr("Backup and Restore... working...")); 255 OWait *owait = new OWait();
256 Global::statusMessage( tr( "Backing up..." ) );
257 owait->show();
258 qApp->processEvents();
259
255 QString outputFile = backupLocations[storeToLocation->currentText()]; 260 QString outputFile = backupLocations[storeToLocation->currentText()];
256 261
257 QDateTime datetime = QDateTime::currentDateTime(); 262 QDateTime datetime = QDateTime::currentDateTime();
258 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + 263 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
259 QString::number( datetime.date().day() ).rightJustify(2, '0'); 264 QString::number( datetime.date().day() ).rightJustify(2, '0');
260 265
261 outputFile += "/" + dateString; 266 outputFile += "/" + dateString;
262 267
263 QString t = outputFile; 268 QString t = outputFile;
264 int c = 1; 269 int c = 1;
265 while(QFile::exists(outputFile + EXTENSION)) 270 while(QFile::exists(outputFile + EXTENSION))
266 { 271 {
267 outputFile = t + QString("%1").arg(c); 272 outputFile = t + QString("%1").arg(c);
268 c++; 273 c++;
269 } 274 }
270 275
271 // We execute tar and compressing its output with gzip.. 276 // We execute tar and compressing its output with gzip..
272 // The error output will be written into a temp-file which could be provided 277 // The error output will be written into a temp-file which could be provided
273 // for debugging.. 278 // for debugging..
274 odebug << "Storing file: " << outputFile.latin1() << "" << oendl; 279 odebug << "Storing file: " << outputFile.latin1() << "" << oendl;
275 outputFile += EXTENSION; 280 outputFile += EXTENSION;
276 281
277 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) 282 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() )
278 .arg( getExcludeFile() ) 283 .arg( getExcludeFile() )
279 .arg( backupFiles ) 284 .arg( backupFiles )
280 .arg( outputFile.latin1() ) 285 .arg( outputFile.latin1() )
281 .arg( tempFileName.latin1() ); 286 .arg( tempFileName.latin1() );
282 287
283 odebug << commandLine << oendl; 288 odebug << commandLine << oendl;
284 289
285 int r = system( commandLine ); 290 int r = system( commandLine );
286 291
292 owait->hide();
293 delete owait;
294
295 //Error-Handling
287 if(r != 0) 296 if(r != 0)
288 { 297 {
289 perror("Error: "); 298 perror("Error: ");
290 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 299 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
291 300
292 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" 301 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n"
293 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) 302 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) )
294 { 303 {
295 304
296 case 1: 305 case 1:
297 owarn << "Details pressed !" << oendl; 306 owarn << "Details pressed !" << oendl;
298 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 307 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
299 QFile errorFile( tempFileName ); 308 QFile errorFile( tempFileName );
300 if ( errorFile.open(IO_ReadOnly) ) 309 if ( errorFile.open(IO_ReadOnly) )
301 { 310 {
302 QTextStream t( &errorFile ); 311 QTextStream t( &errorFile );
303 QString s; 312 QString s;
304 while ( !t.eof() ) 313 while ( !t.eof() )
305 { // until end of file... 314 { // until end of file...
306 s += t.readLine(); // line of text excluding '\n' 315 s += t.readLine(); // line of text excluding '\n'
307 } 316 }
308 errorFile.close(); 317 errorFile.close();
309 318
310 pErrDialog->m_textarea->setText( s ); 319 pErrDialog->m_textarea->setText( s );
311 } 320 }
312 else 321 else
313 { 322 {
314 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); 323 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" );
315 } 324 }
316 QPEApplication::execDialog( pErrDialog ); 325 QPEApplication::execDialog( pErrDialog );
317 delete pErrDialog; 326 delete pErrDialog;
318 break; 327 break;
319 } 328 }
320 setCaption(tr("Backup and Restore.. Failed !!")); 329 setCaption(tr("Backup and Restore.. Failed !!"));
321 return; 330 return;
322 } 331 }
323 else 332 else
324 { 333 {
325 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); 334 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) );
326 } 335 }
327 336
328 //write store-location 337 //write store-location
329 Config config( "BackupAndRestore" ); 338 Config config( "BackupAndRestore" );
330 config.setGroup( "LastLocation" ); 339 config.setGroup( "LastLocation" );
331 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); 340 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() );
332 341
333 setCaption(tr("Backup and Restore")); 342 setCaption(tr("Backup and Restore"));
334} 343}
335 344
336/*** 345/***
337 * Get a list of all of the files to backup. 346 * Get a list of all of the files to backup.
338 */ 347 */
339int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) 348int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent)
340{ 349{
341 QListViewItem * currentItem; 350 QListViewItem * currentItem;
342 QString currentHome; 351 QString currentHome;
343 if(!parent) 352 if(!parent)
344 currentItem = backupList->firstChild(); 353 currentItem = backupList->firstChild();
345 else 354 else
346 { 355 {
347 currentItem = parent->firstChild(); 356 currentItem = parent->firstChild();
348 currentHome = parent->text(BACKUP_LOCATION); 357 currentHome = parent->text(BACKUP_LOCATION);
349 } 358 }
350 359
351 uint count = 0; 360 uint count = 0;
352 while( currentItem != 0 ) 361 while( currentItem != 0 )
353 { 362 {
354 if(currentItem->text(HEADER_BACKUP) == "B" ) 363 if(currentItem->text(HEADER_BACKUP) == "B" )
355 { 364 {
356 if(currentItem->childCount() == 0 ) 365 if(currentItem->childCount() == 0 )
357 { 366 {
358 if(parent == NULL) 367 if(parent == NULL)
359 backupFiles += currentItem->text(BACKUP_LOCATION); 368 backupFiles += currentItem->text(BACKUP_LOCATION);
360 else 369 else
361 backupFiles += currentHome + currentItem->text(HEADER_NAME); 370 backupFiles += currentHome + currentItem->text(HEADER_NAME);
362 backupFiles += " "; 371 backupFiles += " ";
363 count++; 372 count++;
364 } 373 }
365 else 374 else
366 { 375 {
367 count += getBackupFiles(backupFiles, currentItem); 376 count += getBackupFiles(backupFiles, currentItem);
368 } 377 }
369 } 378 }
370 currentItem = currentItem->nextSibling(); 379 currentItem = currentItem->nextSibling();
371 } 380 }
372 return count; 381 return count;
373} 382}
374 383
375void BackupAndRestore::sourceDirChanged(int selection) 384void BackupAndRestore::sourceDirChanged(int selection)
376{ 385{
377 restoreList->clear(); 386 restoreList->clear();
378 rescanFolder(backupLocations[restoreSource->text(selection)]); 387 rescanFolder(backupLocations[restoreSource->text(selection)]);
379} 388}
380 389
381void BackupAndRestore::fileListUpdate() 390void BackupAndRestore::fileListUpdate()
382{ 391{
383 owarn << "void BackupAndRestore::fileListUpdate()" << oendl; 392 owarn << "void BackupAndRestore::fileListUpdate()" << oendl;
384 restoreList->clear(); 393 restoreList->clear();
385 rescanFolder( backupLocations[restoreSource->currentText()] ); 394 rescanFolder( backupLocations[restoreSource->currentText()] );
386} 395}
387 396
388/** 397/**
389 * Scans directory for any backup files. Will recursivly go down, 398 * Scans directory for any backup files. Will recursivly go down,
390 * but will not follow symlinks. 399 * but will not follow symlinks.
391 * @param directory - the directory to look in. 400 * @param directory - the directory to look in.
392 */ 401 */
393void BackupAndRestore::rescanFolder(QString directory) 402void BackupAndRestore::rescanFolder(QString directory)
394{ 403{
395 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; 404 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl;
396 QDir d(directory); 405 QDir d(directory);
397 if(!d.exists()) 406 if(!d.exists())
398 return; 407 return;
399 408
400 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); 409 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
401 const QFileInfoList *list = d.entryInfoList(); 410 const QFileInfoList *list = d.entryInfoList();
402 QFileInfoListIterator it( *list ); 411 QFileInfoListIterator it( *list );
403 QFileInfo *file; 412 QFileInfo *file;
404 while ( (file=it.current()) ) 413 while ( (file=it.current()) )
405 { // for each file... 414 { // for each file...
406 // If it is a dir and not .. or . then add it as a tab and go down. 415 // If it is a dir and not .. or . then add it as a tab and go down.
407 if(file->isDir()) 416 if(file->isDir())
408 { 417 {
409 if(file->fileName() != ".." && file->fileName() != ".") 418 if(file->fileName() != ".." && file->fileName() != ".")
410 { 419 {
411 rescanFolder(directory + "/" + file->fileName()); 420 rescanFolder(directory + "/" + file->fileName());
412 } 421 }
413 } 422 }
414 else 423 else
415 { 424 {
416 // If it is a backup file add to list. 425 // If it is a backup file add to list.
417 if(file->fileName().contains(EXTENSION)) 426 if(file->fileName().contains(EXTENSION))
418 (void)new QListViewItem(restoreList, file->fileName()); 427 (void)new QListViewItem(restoreList, file->fileName());
419 } 428 }
420 ++it; 429 ++it;
421 } 430 }
422} 431}
423 432
424/** 433/**
425 * Restore a backup file. 434 * Restore a backup file.
426 * Report errors or success 435 * Report errors or success
427 */ 436 */
428void BackupAndRestore::restore() 437void BackupAndRestore::restore()
429{ 438{
430 QListViewItem *restoreItem = restoreList->currentItem(); 439 QListViewItem *restoreItem = restoreList->currentItem();
431 if(!restoreItem) 440 if(!restoreItem)
432 { 441 {
433 QMessageBox::critical(this, tr( "Message" ), 442 QMessageBox::critical(this, tr( "Message" ),
434 tr( "Please select something to restore." ),QString( tr( "Ok") ) ); 443 tr( "Please select something to restore." ),QString( tr( "Ok") ) );
435 return; 444 return;
436 } 445 }
437 setCaption(tr("Backup and Restore... working...")); 446
447 OWait *owait = new OWait();
448 Global::statusMessage( tr( "Restore Backup..." ) );
449 owait->show();
450 qApp->processEvents();
438 451
439 QString restoreFile = backupLocations[restoreSource->currentText()]; 452 QString restoreFile = backupLocations[restoreSource->currentText()];
440 453
441 restoreFile += "/" + restoreItem->text(0); 454 restoreFile += "/" + restoreItem->text(0);
442 455
443 odebug << restoreFile << oendl; 456 odebug << restoreFile << oendl;
444 457
445 //check if backup file come from opie 1.0.x 458 //check if backup file come from opie 1.0.x
446 459
447 QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() ); 460 QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() );
448 461
449 int r = system( commandLine ); 462 int r = system( commandLine );
450 463
451 QString startDir; 464 QString startDir;
452 465
453 if( r != 0 ) //Applications/backup/exclude not found - old backup file 466 if( r != 0 ) //Applications/backup/exclude not found - old backup file
454 { 467 {
455 startDir = QString( "/" ); 468 startDir = QString( "/" );
456 } else 469 } else
457 { 470 {
458 startDir = QDir::homeDirPath(); 471 startDir = QDir::homeDirPath();
459 } 472 }
460 473
461 //unpack backup file 474 //unpack backup file
462 commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir ) 475 commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir )
463 .arg( restoreFile.latin1() ) 476 .arg( restoreFile.latin1() )
464 .arg( tempFileName.latin1() ); 477 .arg( tempFileName.latin1() );
465 478
466 odebug << commandLine << oendl; 479 odebug << commandLine << oendl;
467 480
468 r = system( commandLine ); 481 r = system( commandLine );
469 482
483 owait->hide();
484 delete owait;
485
470 //error handling 486 //error handling
471 if(r != 0) 487 if(r != 0)
472 { 488 {
473 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 489 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
474 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" 490 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n"
475 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) 491 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) )
476 { 492 {
477 case 1: 493 case 1:
478 owarn << "Details pressed !" << oendl; 494 owarn << "Details pressed !" << oendl;
479 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 495 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
480 QFile errorFile( tempFileName ); 496 QFile errorFile( tempFileName );
481 if ( errorFile.open(IO_ReadOnly) ) 497 if ( errorFile.open(IO_ReadOnly) )
482 { 498 {
483 QTextStream t( &errorFile ); 499 QTextStream t( &errorFile );
484 QString s; 500 QString s;
485 while ( !t.eof() ) 501 while ( !t.eof() )
486 { // until end of file... 502 { // until end of file...
487 s += t.readLine(); // line of text excluding '\n' 503 s += t.readLine(); // line of text excluding '\n'
488 } 504 }
489 errorFile.close(); 505 errorFile.close();
490 506
491 pErrDialog->m_textarea->setText( s ); 507 pErrDialog->m_textarea->setText( s );
492 } 508 }
493 else 509 else
494 { 510 {
495 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); 511 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) );
496 } 512 }
497 QPEApplication::execDialog( pErrDialog ); 513 QPEApplication::execDialog( pErrDialog );
498 delete pErrDialog; 514 delete pErrDialog;
499 515
500 setCaption(tr("Backup and Restore.. Failed !!")); 516 setCaption(tr("Backup and Restore.. Failed !!"));
501 return; 517 return;
502 518
503 break; 519 break;
504 520
505 } 521 }
506 } 522 }
507 else 523 else
508 { 524 {
509 QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) ); 525 QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) );
510 } 526 }
511 527
512 //write restore-location 528 //write restore-location
513 Config config( "BackupAndRestore" ); 529 Config config( "BackupAndRestore" );
514 config.setGroup( "LastLocation" ); 530 config.setGroup( "LastLocation" );
515 config.writeEntry( "LastRestoreLocation", restoreSource->currentText() ); 531 config.writeEntry( "LastRestoreLocation", restoreSource->currentText() );
516 532
517 setCaption(tr("Backup and Restore")); 533 setCaption(tr("Backup and Restore"));
518} 534}
519 535
520/** 536/**
521 * Check for exclude in Applications/backup 537 * Check for exclude in Applications/backup
522 * If it does not exist, the function will create the file with *.bck as content 538 * If it does not exist, the function will create the file with *.bck as content
523 * The exclude_files is read by tar and will provide to exclude special files out from backup. 539 * The exclude_files is read by tar and will provide to exclude special files out from backup.
524 * e.g. alle *.bck files (backup-files) will not be backed up by default 540 * e.g. alle *.bck files (backup-files) will not be backed up by default
525 */ 541 */
526 542
527QString BackupAndRestore::getExcludeFile() 543QString BackupAndRestore::getExcludeFile()
528{ 544{
529 QString excludeFileName = Global::applicationFileName( "backup", "exclude" ); 545 QString excludeFileName = Global::applicationFileName( "backup", "exclude" );
530 if ( !QFile::exists( excludeFileName ) ) 546 if ( !QFile::exists( excludeFileName ) )
531 { 547 {
532 QFile excludeFile( excludeFileName); 548 QFile excludeFile( excludeFileName);
533 if ( excludeFile.open( IO_WriteOnly ) == true ) 549 if ( excludeFile.open( IO_WriteOnly ) == true )
534 { 550 {
535 QTextStream writeStream( &excludeFile ); 551 QTextStream writeStream( &excludeFile );
536 writeStream << "*.bck" << "\n"; 552 writeStream << "*.bck" << "\n";
537 excludeFile.close(); 553 excludeFile.close();
538 } 554 }
539 else 555 else
540 { 556 {
541 return QString::null; 557 return QString::null;
542 } 558 }
543 } 559 }
544 560
545 return excludeFileName; 561 return excludeFileName;
546} 562}
547 563
548void BackupAndRestore::refreshLocations() 564void BackupAndRestore::refreshLocations()
549{ 565{
550 locationList->clear(); 566 locationList->clear();
551 567
552 //todo: implement add locations 568 //todo: implement add locations
553 Config config( "BackupAndRestore" ); 569 Config config( "BackupAndRestore" );
554 config.setGroup( "Locations" ); 570 config.setGroup( "Locations" );
555 571
556 QStringList locations( config.readListEntry( "locations", '|' ) ); 572 QStringList locations( config.readListEntry( "locations", '|' ) );
557 573
558 for ( QStringList::Iterator it = locations.begin(); it != locations.end(); ++it ) { 574 for ( QStringList::Iterator it = locations.begin(); it != locations.end(); ++it ) {
559 (void) new QListViewItem( locationList, *it ); 575 (void) new QListViewItem( locationList, *it );
560 } 576 }
561} 577}
562 578
563void BackupAndRestore::addLocation() 579void BackupAndRestore::addLocation()
564{ 580{
565 if ( ( !locationEdit->text().isEmpty() ) && 581 if ( ( !locationEdit->text().isEmpty() ) &&