summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 87b7966..58e5c71 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -159,353 +159,370 @@ BackupAndRestore::~BackupAndRestore()
159 if ( QFile::exists( tempFileName ) ) 159 if ( QFile::exists( tempFileName ) )
160 QFile::remove( tempFileName ); 160 QFile::remove( tempFileName );
161} 161}
162 162
163QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) 163QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list)
164{ 164{
165 while(item) 165 while(item)
166 { 166 {
167 if(item->childCount() > 0) 167 if(item->childCount() > 0)
168 getAllItems(item->firstChild(), list); 168 getAllItems(item->firstChild(), list);
169 list.append(item); 169 list.append(item);
170 item = item->nextSibling(); 170 item = item->nextSibling();
171 } 171 }
172 return list; 172 return list;
173} 173}
174 174
175/** 175/**
176 * Selects and unselects the item by setting the HEADER_BACKUP to B or !. 176 * Selects and unselects the item by setting the HEADER_BACKUP to B or !.
177 * and changing the icon to match 177 * and changing the icon to match
178 * @param currentItem the item to swich the selection choice. 178 * @param currentItem the item to swich the selection choice.
179 */ 179 */
180void BackupAndRestore::selectItem(QListViewItem *currentItem) 180void BackupAndRestore::selectItem(QListViewItem *currentItem)
181{ 181{
182 if(!currentItem) 182 if(!currentItem)
183 return; 183 return;
184 184
185 if(currentItem->text(HEADER_BACKUP) == "B") 185 if(currentItem->text(HEADER_BACKUP) == "B")
186 { 186 {
187 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); 187 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null"));
188 currentItem->setText(HEADER_BACKUP, ""); 188 currentItem->setText(HEADER_BACKUP, "");
189 } 189 }
190 else 190 else
191 { 191 {
192 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); 192 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check"));
193 currentItem->setText(HEADER_BACKUP, "B"); 193 currentItem->setText(HEADER_BACKUP, "B");
194 } 194 }
195} 195}
196 196
197void BackupAndRestore::scanForApplicationSettings() 197void BackupAndRestore::scanForApplicationSettings()
198{ 198{
199 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); 199 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) );
200 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); 200 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
201 const QFileInfoList *list = d.entryInfoList(); 201 const QFileInfoList *list = d.entryInfoList();
202 QFileInfoListIterator it( *list ); 202 QFileInfoListIterator it( *list );
203 QFileInfo *fi; 203 QFileInfo *fi;
204 while ( (fi=it.current()) ) 204 while ( (fi=it.current()) )
205 { 205 {
206 //qDebug((d.path()+"/"+fi->fileName()).latin1()); 206 //qDebug((d.path()+"/"+fi->fileName()).latin1());
207 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) 207 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) )
208 { 208 {
209 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); 209 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName());
210 selectItem(newItem); 210 selectItem(newItem);
211 } 211 }
212 ++it; 212 ++it;
213 } 213 }
214} 214}
215 215
216/** 216/**
217 * The "Backup" button has been pressed. Get a list of all of the files that 217 * The "Backup" button has been pressed. Get a list of all of the files that
218 * should be backed up. If there are no files, emit and error and exit. 218 * should be backed up. If there are no files, emit and error and exit.
219 * Determine the file name to store the backup in. Backup the file(s) using 219 * Determine the file name to store the backup in. Backup the file(s) using
220 * tar and gzip --best. Report failure or success 220 * tar and gzip --best. Report failure or success
221 */ 221 */
222void BackupAndRestore::backup() 222void BackupAndRestore::backup()
223{ 223{
224 QString backupFiles; 224 QString backupFiles;
225 if(getBackupFiles(backupFiles, NULL) == 0) 225 if(getBackupFiles(backupFiles, NULL) == 0)
226 { 226 {
227 QMessageBox::critical(this, "Message", 227 QMessageBox::critical(this, "Message",
228 "No items selected.",QString("Ok") ); 228 "No items selected.",QString("Ok") );
229 return; 229 return;
230 } 230 }
231 231
232 setCaption(tr("Backup and Restore... working...")); 232 setCaption(tr("Backup and Restore... working..."));
233 QString outputFile = backupLocations[storeToLocation->currentText()]; 233 QString outputFile = backupLocations[storeToLocation->currentText()];
234 234
235 QDateTime datetime = QDateTime::currentDateTime(); 235 QDateTime datetime = QDateTime::currentDateTime();
236 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + 236 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
237 QString::number( datetime.date().day() ).rightJustify(2, '0'); 237 QString::number( datetime.date().day() ).rightJustify(2, '0');
238 238
239 outputFile += "/" + dateString; 239 outputFile += "/" + dateString;
240 240
241 QString t = outputFile; 241 QString t = outputFile;
242 int c = 1; 242 int c = 1;
243 while(QFile::exists(outputFile + EXTENSION)) 243 while(QFile::exists(outputFile + EXTENSION))
244 { 244 {
245 outputFile = t + QString("%1").arg(c); 245 outputFile = t + QString("%1").arg(c);
246 c++; 246 c++;
247 } 247 }
248 248
249 // We execute tar and compressing its output with gzip.. 249 // We execute tar and compressing its output with gzip..
250 // The error output will be written into a temp-file which could be provided 250 // The error output will be written into a temp-file which could be provided
251 // for debugging.. 251 // for debugging..
252 qDebug( "Storing file: %s", outputFile.latin1() ); 252 qDebug( "Storing file: %s", outputFile.latin1() );
253 outputFile += EXTENSION; 253 outputFile += EXTENSION;
254 254
255 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) 255 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() )
256 .arg( getExcludeFile() ) 256 .arg( getExcludeFile() )
257 .arg( backupFiles ) 257 .arg( backupFiles )
258 .arg( outputFile.latin1() ) 258 .arg( outputFile.latin1() )
259 .arg( tempFileName.latin1() ); 259 .arg( tempFileName.latin1() );
260 260
261 qDebug( commandLine ); 261 qDebug( commandLine );
262 262
263 int r = system( commandLine ); 263 int r = system( commandLine );
264 264
265 if(r != 0) 265 if(r != 0)
266 { 266 {
267 perror("Error: "); 267 perror("Error: ");
268 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 268 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
269 269
270 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" 270 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n"
271 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) 271 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) )
272 { 272 {
273 273
274 case 1: 274 case 1:
275 qWarning("Details pressed !"); 275 qWarning("Details pressed !");
276 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 276 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
277 QFile errorFile( tempFileName ); 277 QFile errorFile( tempFileName );
278 if ( errorFile.open(IO_ReadOnly) ) 278 if ( errorFile.open(IO_ReadOnly) )
279 { 279 {
280 QTextStream t( &errorFile ); 280 QTextStream t( &errorFile );
281 QString s; 281 QString s;
282 while ( !t.eof() ) 282 while ( !t.eof() )
283 { // until end of file... 283 { // until end of file...
284 s += t.readLine(); // line of text excluding '\n' 284 s += t.readLine(); // line of text excluding '\n'
285 } 285 }
286 errorFile.close(); 286 errorFile.close();
287 287
288 pErrDialog->m_textarea->setText( s ); 288 pErrDialog->m_textarea->setText( s );
289 } 289 }
290 else 290 else
291 { 291 {
292 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); 292 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" );
293 } 293 }
294 QPEApplication::execDialog( pErrDialog ); 294 QPEApplication::execDialog( pErrDialog );
295 delete pErrDialog; 295 delete pErrDialog;
296 break; 296 break;
297 } 297 }
298 setCaption(tr("Backup and Restore.. Failed !!")); 298 setCaption(tr("Backup and Restore.. Failed !!"));
299 return; 299 return;
300 } 300 }
301 else 301 else
302 { 302 {
303 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); 303 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) );
304 304
305 } 305 }
306 306
307 //write store-location 307 //write store-location
308 Config config( "BackupAndRestore" ); 308 Config config( "BackupAndRestore" );
309 config.setGroup( "LastLocation" ); 309 config.setGroup( "LastLocation" );
310 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); 310 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() );
311 311
312 setCaption(tr("Backup and Restore")); 312 setCaption(tr("Backup and Restore"));
313} 313}
314 314
315/*** 315/***
316 * Get a list of all of the files to backup. 316 * Get a list of all of the files to backup.
317 */ 317 */
318int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) 318int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent)
319{ 319{
320 QListViewItem * currentItem; 320 QListViewItem * currentItem;
321 QString currentHome; 321 QString currentHome;
322 if(!parent) 322 if(!parent)
323 currentItem = backupList->firstChild(); 323 currentItem = backupList->firstChild();
324 else 324 else
325 { 325 {
326 currentItem = parent->firstChild(); 326 currentItem = parent->firstChild();
327 currentHome = parent->text(BACKUP_LOCATION); 327 currentHome = parent->text(BACKUP_LOCATION);
328 } 328 }
329 329
330 uint count = 0; 330 uint count = 0;
331 while( currentItem != 0 ) 331 while( currentItem != 0 )
332 { 332 {
333 if(currentItem->text(HEADER_BACKUP) == "B" ) 333 if(currentItem->text(HEADER_BACKUP) == "B" )
334 { 334 {
335 if(currentItem->childCount() == 0 ) 335 if(currentItem->childCount() == 0 )
336 { 336 {
337 if(parent == NULL) 337 if(parent == NULL)
338 backupFiles += currentItem->text(BACKUP_LOCATION); 338 backupFiles += currentItem->text(BACKUP_LOCATION);
339 else 339 else
340 backupFiles += currentHome + currentItem->text(HEADER_NAME); 340 backupFiles += currentHome + currentItem->text(HEADER_NAME);
341 backupFiles += " "; 341 backupFiles += " ";
342 count++; 342 count++;
343 } 343 }
344 else 344 else
345 { 345 {
346 count += getBackupFiles(backupFiles, currentItem); 346 count += getBackupFiles(backupFiles, currentItem);
347 } 347 }
348 } 348 }
349 currentItem = currentItem->nextSibling(); 349 currentItem = currentItem->nextSibling();
350 } 350 }
351 return count; 351 return count;
352} 352}
353 353
354void BackupAndRestore::sourceDirChanged(int selection) 354void BackupAndRestore::sourceDirChanged(int selection)
355{ 355{
356 restoreList->clear(); 356 restoreList->clear();
357 rescanFolder(backupLocations[restoreSource->text(selection)]); 357 rescanFolder(backupLocations[restoreSource->text(selection)]);
358} 358}
359 359
360void BackupAndRestore::fileListUpdate() 360void BackupAndRestore::fileListUpdate()
361{ 361{
362 qWarning("void BackupAndRestore::fileListUpdate()"); 362 qWarning("void BackupAndRestore::fileListUpdate()");
363 restoreList->clear(); 363 restoreList->clear();
364 rescanFolder( backupLocations[restoreSource->currentText()] ); 364 rescanFolder( backupLocations[restoreSource->currentText()] );
365} 365}
366 366
367/** 367/**
368 * Scans directory for any backup files. Will recursivly go down, 368 * Scans directory for any backup files. Will recursivly go down,
369 * but will not follow symlinks. 369 * but will not follow symlinks.
370 * @param directory - the directory to look in. 370 * @param directory - the directory to look in.
371 */ 371 */
372void BackupAndRestore::rescanFolder(QString directory) 372void BackupAndRestore::rescanFolder(QString directory)
373{ 373{
374 //qDebug(QString("rescanFolder: ") + directory.latin1()); 374 //qDebug(QString("rescanFolder: ") + directory.latin1());
375 QDir d(directory); 375 QDir d(directory);
376 if(!d.exists()) 376 if(!d.exists())
377 return; 377 return;
378 378
379 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); 379 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
380 const QFileInfoList *list = d.entryInfoList(); 380 const QFileInfoList *list = d.entryInfoList();
381 QFileInfoListIterator it( *list ); 381 QFileInfoListIterator it( *list );
382 QFileInfo *file; 382 QFileInfo *file;
383 while ( (file=it.current()) ) 383 while ( (file=it.current()) )
384 { // for each file... 384 { // for each file...
385 // If it is a dir and not .. or . then add it as a tab and go down. 385 // If it is a dir and not .. or . then add it as a tab and go down.
386 if(file->isDir()) 386 if(file->isDir())
387 { 387 {
388 if(file->fileName() != ".." && file->fileName() != ".") 388 if(file->fileName() != ".." && file->fileName() != ".")
389 { 389 {
390 rescanFolder(directory + "/" + file->fileName()); 390 rescanFolder(directory + "/" + file->fileName());
391 } 391 }
392 } 392 }
393 else 393 else
394 { 394 {
395 // If it is a backup file add to list. 395 // If it is a backup file add to list.
396 if(file->fileName().contains(EXTENSION)) 396 if(file->fileName().contains(EXTENSION))
397 (void)new QListViewItem(restoreList, file->fileName()); 397 (void)new QListViewItem(restoreList, file->fileName());
398 } 398 }
399 ++it; 399 ++it;
400 } 400 }
401} 401}
402 402
403/** 403/**
404 * Restore a backup file. 404 * Restore a backup file.
405 * Report errors or success 405 * Report errors or success
406 */ 406 */
407void BackupAndRestore::restore() 407void BackupAndRestore::restore()
408{ 408{
409 QListViewItem *restoreItem = restoreList->currentItem(); 409 QListViewItem *restoreItem = restoreList->currentItem();
410 if(!restoreItem) 410 if(!restoreItem)
411 { 411 {
412 QMessageBox::critical(this, tr( "Message" ), 412 QMessageBox::critical(this, tr( "Message" ),
413 tr( "Please select something to restore." ),QString( tr( "Ok") ) ); 413 tr( "Please select something to restore." ),QString( tr( "Ok") ) );
414 return; 414 return;
415 } 415 }
416 setCaption(tr("Backup and Restore... working...")); 416 setCaption(tr("Backup and Restore... working..."));
417 417
418 QString restoreFile = backupLocations[restoreSource->currentText()]; 418 QString restoreFile = backupLocations[restoreSource->currentText()];
419 419
420 restoreFile += "/" + restoreItem->text(0); 420 restoreFile += "/" + restoreItem->text(0);
421 421
422 qDebug( restoreFile ); 422 qDebug( restoreFile );
423 423
424 QString commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( QDir::homeDirPath() ) 424 //check if backup file come from opie 1.0.x
425 .arg( restoreFile.latin1() )
426 .arg( tempFileName.latin1() );
427 425
428 qDebug( commandLine ); 426 QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() );
429 427
430 int r = system( commandLine ); 428 int r = system( commandLine );
431 429
430 QString startDir;
431
432 if( r != 0 ) //Applications/backup/exclude not found - old backup file
433 {
434 startDir = QString( "/" );
435 } else
436 {
437 startDir = QDir::homeDirPath();
438 }
439
440 //unpack backup file
441 commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir )
442 .arg( restoreFile.latin1() )
443 .arg( tempFileName.latin1() );
444
445 qDebug( commandLine );
446
447 r = system( commandLine );
448
449 //error handling
432 if(r != 0) 450 if(r != 0)
433 { 451 {
434 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 452 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
435 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" 453 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n"
436 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) 454 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) )
437 { 455 {
438 case 1: 456 case 1:
439 qWarning("Details pressed !"); 457 qWarning("Details pressed !");
440 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 458 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
441 QFile errorFile( tempFileName ); 459 QFile errorFile( tempFileName );
442 if ( errorFile.open(IO_ReadOnly) ) 460 if ( errorFile.open(IO_ReadOnly) )
443 { 461 {
444 QTextStream t( &errorFile ); 462 QTextStream t( &errorFile );
445 QString s; 463 QString s;
446 while ( !t.eof() ) 464 while ( !t.eof() )
447 { // until end of file... 465 { // until end of file...
448 s += t.readLine(); // line of text excluding '\n' 466 s += t.readLine(); // line of text excluding '\n'
449 } 467 }
450 errorFile.close(); 468 errorFile.close();
451 469
452 pErrDialog->m_textarea->setText( s ); 470 pErrDialog->m_textarea->setText( s );
453 } 471 }
454 else 472 else
455 { 473 {
456 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); 474 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) );
457 } 475 }
458 QPEApplication::execDialog( pErrDialog ); 476 QPEApplication::execDialog( pErrDialog );
459 delete pErrDialog; 477 delete pErrDialog;
460 478
461 setCaption(tr("Backup and Restore.. Failed !!")); 479 setCaption(tr("Backup and Restore.. Failed !!"));
462 return; 480 return;
463 481
464 break; 482 break;
465 483
466 } 484 }
467 } 485 }
468 else 486 else
469 { 487 {
470 QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) ); 488 QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) );
471 } 489 }
472 490
473 //write restore-location 491 //write restore-location
474 Config config( "BackupAndRestore" ); 492 Config config( "BackupAndRestore" );
475 config.setGroup( "LastLocation" ); 493 config.setGroup( "LastLocation" );
476 config.writeEntry( "LastRestoreLocation", restoreSource->currentText() ); 494 config.writeEntry( "LastRestoreLocation", restoreSource->currentText() );
477 495
478 setCaption(tr("Backup and Restore")); 496 setCaption(tr("Backup and Restore"));
479} 497}
480 498
481
482/** 499/**
483 * Check for exclude in Applications/backup 500 * Check for exclude in Applications/backup
484 * If it does not exist, the function will create the file with *.bck as content 501 * If it does not exist, the function will create the file with *.bck as content
485 * The exclude_files is read by tar and will provide to exclude special files out from backup. 502 * The exclude_files is read by tar and will provide to exclude special files out from backup.
486 * e.g. alle *.bck files (backup-files) will not be backed up by default 503 * e.g. alle *.bck files (backup-files) will not be backed up by default
487 */ 504 */
488 505
489QString BackupAndRestore::getExcludeFile() 506QString BackupAndRestore::getExcludeFile()
490{ 507{
491 QString excludeFileName = Global::applicationFileName( "backup", "exclude" ); 508 QString excludeFileName = Global::applicationFileName( "backup", "exclude" );
492 if ( !QFile::exists( excludeFileName ) ) 509 if ( !QFile::exists( excludeFileName ) )
493 { 510 {
494 QFile excludeFile( excludeFileName); 511 QFile excludeFile( excludeFileName);
495 if ( excludeFile.open( IO_WriteOnly ) == true ) 512 if ( excludeFile.open( IO_WriteOnly ) == true )
496 { 513 {
497 QTextStream writeStream( &excludeFile ); 514 QTextStream writeStream( &excludeFile );
498 writeStream << "*.bck" << "\n"; 515 writeStream << "*.bck" << "\n";
499 excludeFile.close(); 516 excludeFile.close();
500 } 517 }
501 else 518 else
502 { 519 {
503 return QString::null; 520 return QString::null;
504 } 521 }
505 } 522 }
506 523
507 return excludeFileName; 524 return excludeFileName;
508} 525}
509 526
510// backuprestore.cpp 527// backuprestore.cpp
511 528