summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp84
-rw-r--r--noncore/settings/backup/backuprestore.h4
2 files changed, 56 insertions, 32 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 3889744..478b22f 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -14,32 +14,33 @@ using namespace Opie::Core;
14/* QT */ 14/* QT */
15#include <qapplication.h> 15#include <qapplication.h>
16#include <qmultilineedit.h> 16#include <qmultilineedit.h>
17#include <qdir.h> 17#include <qdir.h>
18#include <qfile.h> 18#include <qfile.h>
19#include <qfileinfo.h> 19#include <qfileinfo.h>
20#include <qlistview.h> 20#include <qlistview.h>
21#include <qpushbutton.h> 21#include <qpushbutton.h>
22#include <qheader.h> 22#include <qheader.h>
23#include <qmessagebox.h> 23#include <qmessagebox.h>
24#include <qcombobox.h> 24#include <qcombobox.h>
25#include <qlist.h> 25#include <qlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qtextstream.h> 27#include <qtextstream.h>
28#include <qtextview.h> 28#include <qtextview.h>
29#include <qlineedit.h> 29#include <qlineedit.h>
30#include <qstringlist.h>
30 31
31/* STD */ 32/* STD */
32#include <errno.h> 33#include <errno.h>
33#include <stdlib.h> 34#include <stdlib.h>
34#include <unistd.h> 35#include <unistd.h>
35#include <sys/stat.h> 36#include <sys/stat.h>
36#include <dirent.h> 37#include <dirent.h>
37 38
38#define HEADER_NAME 0 39#define HEADER_NAME 0
39#define HEADER_BACKUP 1 40#define HEADER_BACKUP 1
40#define BACKUP_LOCATION 2 41#define BACKUP_LOCATION 2
41 42
42#define EXTENSION ".bck" 43#define EXTENSION ".bck"
43 44
44const QString tempFileName = "/tmp/backup.err"; 45const QString tempFileName = "/tmp/backup.err";
45 46
@@ -53,59 +54,39 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags f
53 connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) ); 54 connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) );
54 connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) ); 55 connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) );
55 connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) ); 56 connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) );
56 connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) ); 57 connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) );
57 connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) ); 58 connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) );
58 connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) ); 59 connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) );
59 60
60 //add directorys for backing up 61 //add directorys for backing up
61 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); 62 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/");
62 selectItem(applicationSettings); 63 selectItem(applicationSettings);
63 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); 64 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/");
64 selectItem(applicationSettings); 65 selectItem(applicationSettings);
65 documents= new QListViewItem(backupList, "Documents", "", "Documents/"); 66 documents= new QListViewItem(backupList, "Documents", "", "Documents/");
66 selectItem(documents); 67 selectItem(documents);
67 68
68 scanForApplicationSettings(); 69 scanForApplicationSettings();
69 refreshBackupLocations();
70 refreshLocations(); 70 refreshLocations();
71 71 refreshBackupLocations();
72 Config config("BackupAndRestore");
73 //read last locations
74 config.setGroup("LastLocation");
75 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" );
76 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" );
77 int locationIndex = 0;
78
79 QMap<QString, QString>::Iterator it;
80 for( it = backupLocations.begin(); it != backupLocations.end(); ++it )
81 {
82 storeToLocation->insertItem(it.key());
83 restoreSource->insertItem(it.key());
84
85 //check for last locations
86 if ( it.key() == lastStoreLocation )
87 storeToLocation->setCurrentItem( locationIndex );
88 if ( it.key() == lastRestoreLocation )
89 restoreSource->setCurrentItem( locationIndex );
90 locationIndex++;
91 }
92 72
93 // Read the list of items to ignore. 73 // Read the list of items to ignore.
94 QList<QString> dontBackupList; 74 QList<QString> dontBackupList;
95 dontBackupList.setAutoDelete(true); 75 dontBackupList.setAutoDelete(true);
76 Config config("BackupAndRestore");
96 config.setGroup("DontBackup"); 77 config.setGroup("DontBackup");
97 int total = config.readNumEntry("Total", 0); 78 int total = config.readNumEntry("Total", 0);
98 for(int i = 0; i < total; i++) 79 for(int i = 0; i < total; i++)
99 { 80 {
100 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); 81 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), "")));
101 } 82 }
102 83
103 QList<QListViewItem> list; 84 QList<QListViewItem> list;
104 getAllItems(backupList->firstChild(), list); 85 getAllItems(backupList->firstChild(), list);
105 86
106 for(uint i = 0; i < list.count(); i++) 87 for(uint i = 0; i < list.count(); i++)
107 { 88 {
108 QString text = list.at(i)->text(HEADER_NAME); 89 QString text = list.at(i)->text(HEADER_NAME);
109 for(uint i2 = 0; i2 < dontBackupList.count(); i2++) 90 for(uint i2 = 0; i2 < dontBackupList.count(); i2++)
110 { 91 {
111 if(*dontBackupList.at(i2) == text) 92 if(*dontBackupList.at(i2) == text)
@@ -152,34 +133,62 @@ void BackupAndRestore::refreshBackupLocations()
152 if ( storage.hasCf() ) 133 if ( storage.hasCf() )
153 { 134 {
154 backupLocations.insert( "CF", storage.cfPath() ); 135 backupLocations.insert( "CF", storage.cfPath() );
155 odebug << "Cf Path: " + storage.cfPath() << oendl; 136 odebug << "Cf Path: " + storage.cfPath() << oendl;
156 } 137 }
157 if ( storage.hasSd() ) 138 if ( storage.hasSd() )
158 { 139 {
159 backupLocations.insert( "SD", storage.sdPath() ); 140 backupLocations.insert( "SD", storage.sdPath() );
160 odebug << " Sd Path: " + storage.sdPath() << oendl; 141 odebug << " Sd Path: " + storage.sdPath() << oendl;
161 } 142 }
162 if ( storage.hasMmc() ) 143 if ( storage.hasMmc() )
163 { 144 {
164 backupLocations.insert( "MMC", storage.mmcPath() ); 145 backupLocations.insert( "MMC", storage.mmcPath() );
165 odebug << "Mmc Path: " + storage.mmcPath() << oendl; 146 odebug << "Mmc Path: " + storage.mmcPath() << oendl;
166 } 147 }
167 148
168 // Add own locations from locationList 149 for ( QListViewItemIterator it( locationList ); it.current(); ++it )
169 // todo implementation 150 {
151 backupLocations.insert( it.current()->text( 0 ), it.current()->text( 0 ) );
152 }
153
154 //update QComboBox
155 storeToLocation->clear();
156 restoreSource->clear();
157
158 //read last locations
159 Config config("BackupAndRestore");
160 config.setGroup("LastLocation");
161 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" );
162 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" );
163 int locationIndex = 0;
164
165 //fill QComboBox
166 QMap<QString, QString>::Iterator it;
167 for( it = backupLocations.begin(); it != backupLocations.end(); ++it )
168 {
169 storeToLocation->insertItem(it.key());
170 restoreSource->insertItem(it.key());
171
172 //check for last locations
173 if ( it.key() == lastStoreLocation )
174 storeToLocation->setCurrentItem( locationIndex );
175 if ( it.key() == lastRestoreLocation )
176 restoreSource->setCurrentItem( locationIndex );
177 locationIndex++;
178 }
170} 179}
171 180
172QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) 181QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list)
173{ 182{
174 while(item) 183 while(item)
175 { 184 {
176 if(item->childCount() > 0) 185 if(item->childCount() > 0)
177 getAllItems(item->firstChild(), list); 186 getAllItems(item->firstChild(), list);
178 list.append(item); 187 list.append(item);
179 item = item->nextSibling(); 188 item = item->nextSibling();
180 } 189 }
181 return list; 190 return list;
182} 191}
183 192
184/** 193/**
185 * Selects and unselects the item by setting the HEADER_BACKUP to B or !. 194 * Selects and unselects the item by setting the HEADER_BACKUP to B or !.
@@ -297,33 +306,32 @@ void BackupAndRestore::backup()
297 pErrDialog->m_textarea->setText( s ); 306 pErrDialog->m_textarea->setText( s );
298 } 307 }
299 else 308 else
300 { 309 {
301 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); 310 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" );
302 } 311 }
303 QPEApplication::execDialog( pErrDialog ); 312 QPEApplication::execDialog( pErrDialog );
304 delete pErrDialog; 313 delete pErrDialog;
305 break; 314 break;
306 } 315 }
307 setCaption(tr("Backup and Restore.. Failed !!")); 316 setCaption(tr("Backup and Restore.. Failed !!"));
308 return; 317 return;
309 } 318 }
310 else 319 else
311 { 320 {
312 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); 321 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) );
313
314 } 322 }
315 323
316 //write store-location 324 //write store-location
317 Config config( "BackupAndRestore" ); 325 Config config( "BackupAndRestore" );
318 config.setGroup( "LastLocation" ); 326 config.setGroup( "LastLocation" );
319 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); 327 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() );
320 328
321 setCaption(tr("Backup and Restore")); 329 setCaption(tr("Backup and Restore"));
322} 330}
323 331
324/*** 332/***
325 * Get a list of all of the files to backup. 333 * Get a list of all of the files to backup.
326 */ 334 */
327int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) 335int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent)
328{ 336{
329 QListViewItem * currentItem; 337 QListViewItem * currentItem;
@@ -523,47 +531,63 @@ QString BackupAndRestore::getExcludeFile()
523 QTextStream writeStream( &excludeFile ); 531 QTextStream writeStream( &excludeFile );
524 writeStream << "*.bck" << "\n"; 532 writeStream << "*.bck" << "\n";
525 excludeFile.close(); 533 excludeFile.close();
526 } 534 }
527 else 535 else
528 { 536 {
529 return QString::null; 537 return QString::null;
530 } 538 }
531 } 539 }
532 540
533 return excludeFileName; 541 return excludeFileName;
534} 542}
535 543
536void BackupAndRestore::refreshLocations() 544void BackupAndRestore::refreshLocations()
537{ 545{
538 locationList->clear(); 546 locationList->clear();
547
539 //todo: implement add locations 548 //todo: implement add locations
540 odebug << "not implemented yet" << oendl; 549 Config config( "BackupAndRestore" );
550 config.setGroup( "Locations" );
551
552 QStringList locations( config.readListEntry( "locations", '|' ) );
553
554 for ( QStringList::Iterator it = locations.begin(); it != locations.end(); ++it ) {
555 (void) new QListViewItem( locationList, *it );
556 }
541} 557}
542 558
543void BackupAndRestore::addLocation() 559void BackupAndRestore::addLocation()
544{ 560{
545 if ( ( !locationEdit->text().isEmpty() ) && 561 if ( ( !locationEdit->text().isEmpty() ) &&
546 ( QDir( locationEdit->text() ).exists() ) ) 562 ( QDir( locationEdit->text() ).exists() ) )
547 { 563 {
548 (void) new QListViewItem( locationList, locationEdit->text() ); 564 (void) new QListViewItem( locationList, locationEdit->text() );
549 locationEdit->setText( "" ); 565 locationEdit->setText( "" );
550 } 566 }
551} 567}
552 568
553void BackupAndRestore::removeLocation() 569void BackupAndRestore::removeLocation()
554{ 570{
555 if ( locationList->selectedItem() ) 571 if ( locationList->selectedItem() )
556 { 572 {
557 delete( locationList->selectedItem() ); 573 delete( locationList->selectedItem() );
558 } 574 }
559} 575}
560 576
561void BackupAndRestore::saveLocation() 577void BackupAndRestore::saveLocations()
562{ 578{
563 //todo: implement 579 Config config("BackupAndRestore");
564 odebug << "not implemented yet" << oendl; 580 config.setGroup("Locations");
565}
566 581
582 QStringList locations;
583 for ( QListViewItemIterator it( locationList ); it.current(); ++it )
584 {
585 locations.append( it.current()->text( 0 ) );
586 }
587 config.writeEntry( "locations", locations, '|' );
588
589 refreshBackupLocations();
590}
567 591
568// backuprestore.cpp 592// backuprestore.cpp
569 593
diff --git a/noncore/settings/backup/backuprestore.h b/noncore/settings/backup/backuprestore.h
index 527b3cf..caf6243 100644
--- a/noncore/settings/backup/backuprestore.h
+++ b/noncore/settings/backup/backuprestore.h
@@ -1,53 +1,53 @@
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>
5#include "backuprestorebase.h" 5#include "backuprestorebase.h"
6#include <qmap.h> 6#include <qmap.h>
7#include <qlist.h> 7#include <qlist.h>
8 8
9class QListViewItem; 9class QListViewItem;
10class QStringList;
10 11
11class BackupAndRestore : public BackupAndRestoreBase 12class BackupAndRestore : public BackupAndRestoreBase
12{ 13{
13 14
14 Q_OBJECT 15 Q_OBJECT
15 16
16public: 17public:
17 18
18 BackupAndRestore( QWidget* parent = 0, const char* name = 0, WFlags fl = 0); 19 BackupAndRestore( QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
19 ~BackupAndRestore(); 20 ~BackupAndRestore();
20 21
21 static QString appName() { return QString::fromLatin1("backup"); } 22 static QString appName() { return QString::fromLatin1("backup"); }
22 23
23private slots: 24private slots:
24 void backup(); 25 void backup();
25 void restore(); 26 void restore();
26 void selectItem(QListViewItem *currentItem); 27 void selectItem(QListViewItem *currentItem);
27 void sourceDirChanged(int); 28 void sourceDirChanged(int);
28 void rescanFolder(QString directory); 29 void rescanFolder(QString directory);
29 void fileListUpdate(); 30 void fileListUpdate();
30 31
31 void addLocation(); 32 void addLocation();
32 void removeLocation(); 33 void removeLocation();
33 void saveLocation(); 34 void saveLocations();
34 35
35private: 36private:
36 void scanForApplicationSettings(); 37 void scanForApplicationSettings();
37 int getBackupFiles(QString &backupFiles, QListViewItem *parent); 38 int getBackupFiles(QString &backupFiles, QListViewItem *parent);
38 QString getExcludeFile(); 39 QString getExcludeFile();
39 QMap<QString, QString> backupLocations; 40 QMap<QString, QString> backupLocations;
40 QList<QListViewItem> getAllItems(QListViewItem *item, QList<QListViewItem> &list); 41 QList<QListViewItem> getAllItems(QListViewItem *item, QList<QListViewItem> &list);
41 void refreshBackupLocations(); 42 void refreshBackupLocations();
42 void refreshLocations(); 43 void refreshLocations();
43 44
44 QListViewItem *systemSettings; 45 QListViewItem *systemSettings;
45 QListViewItem *applicationSettings; 46 QListViewItem *applicationSettings;
46 QListViewItem *documents; 47 QListViewItem *documents;
47
48}; 48};
49 49
50#endif 50#endif
51 51
52// backuprestore.h 52// backuprestore.h
53 53