Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 9 |
1 files changed, 0 insertions, 9 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 4ff6be1..922523b 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -1,181 +1,172 @@ | |||
1 | 1 | ||
2 | #include "backuprestore.h" | 2 | #include "backuprestore.h" |
3 | //#include "output.h" | 3 | //#include "output.h" |
4 | #include "errordialog.h" | 4 | #include "errordialog.h" |
5 | 5 | ||
6 | #include <qapplication.h> | 6 | #include <qapplication.h> |
7 | #include <qmultilineedit.h> | 7 | #include <qmultilineedit.h> |
8 | 8 | ||
9 | #include <qdir.h> | 9 | #include <qdir.h> |
10 | #include <qfile.h> | 10 | #include <qfile.h> |
11 | #include <qfileinfo.h> | 11 | #include <qfileinfo.h> |
12 | #include <qlistview.h> | 12 | #include <qlistview.h> |
13 | #include <qpushbutton.h> | 13 | #include <qpushbutton.h> |
14 | #include <qheader.h> | 14 | #include <qheader.h> |
15 | #include <qpe/resource.h> | 15 | #include <qpe/resource.h> |
16 | #include <qpe/config.h> | 16 | #include <qpe/config.h> |
17 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
18 | #include <qcombobox.h> | 18 | #include <qcombobox.h> |
19 | #include <qlist.h> | 19 | #include <qlist.h> |
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <qregexp.h> | 21 | #include <qregexp.h> |
22 | #include <qtextstream.h> | 22 | #include <qtextstream.h> |
23 | #include <qtextview.h> | 23 | #include <qtextview.h> |
24 | 24 | ||
25 | #include <errno.h> | 25 | #include <errno.h> |
26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
27 | #include <unistd.h> | 27 | #include <unistd.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <dirent.h> | 29 | #include <dirent.h> |
30 | 30 | ||
31 | #define HEADER_NAME 0 | 31 | #define HEADER_NAME 0 |
32 | #define HEADER_BACKUP 1 | 32 | #define HEADER_BACKUP 1 |
33 | #define BACKUP_LOCATION 2 | 33 | #define BACKUP_LOCATION 2 |
34 | 34 | ||
35 | #define EXTENSION ".bck" | 35 | #define EXTENSION ".bck" |
36 | 36 | ||
37 | const QString tempFileName = "/tmp/backup.err"; | 37 | const QString tempFileName = "/tmp/backup.err"; |
38 | 38 | ||
39 | 39 | ||
40 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | 40 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) |
41 | : BackupAndRestoreBase(parent, name){ | 41 | : BackupAndRestoreBase(parent, name){ |
42 | this->showMaximized(); | 42 | this->showMaximized(); |
43 | backupList->header()->hide(); | 43 | backupList->header()->hide(); |
44 | restoreList->header()->hide(); | 44 | restoreList->header()->hide(); |
45 | connect(backupButton, SIGNAL(clicked()), | 45 | connect(backupButton, SIGNAL(clicked()), |
46 | this, SLOT(backupPressed())); | 46 | this, SLOT(backupPressed())); |
47 | connect(restoreButton, SIGNAL(clicked()), | 47 | connect(restoreButton, SIGNAL(clicked()), |
48 | this, SLOT(restore())); | 48 | this, SLOT(restore())); |
49 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | 49 | connect(backupList, SIGNAL(clicked( QListViewItem * )), |
50 | this, SLOT(selectItem(QListViewItem*))); | 50 | this, SLOT(selectItem(QListViewItem*))); |
51 | connect(restoreSource, SIGNAL(activated( int )), | 51 | connect(restoreSource, SIGNAL(activated( int )), |
52 | this, SLOT(sourceDirChanged(int))); | 52 | this, SLOT(sourceDirChanged(int))); |
53 | connect(updateList, SIGNAL(clicked()), | 53 | connect(updateList, SIGNAL(clicked()), |
54 | this, SLOT( fileListUpdate())); | 54 | this, SLOT( fileListUpdate())); |
55 | 55 | ||
56 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", | 56 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", |
57 | QDir::homeDirPath() + "/Settings/"); | 57 | QDir::homeDirPath() + "/Settings/"); |
58 | selectItem(applicationSettings); | 58 | selectItem(applicationSettings); |
59 | applicationSettings = new QListViewItem(backupList, "Application Data", "", | 59 | applicationSettings = new QListViewItem(backupList, "Application Data", "", |
60 | QDir::homeDirPath() + "/Applications/"); | 60 | QDir::homeDirPath() + "/Applications/"); |
61 | selectItem(applicationSettings); | 61 | selectItem(applicationSettings); |
62 | documents= new QListViewItem(backupList, "Documents", "", | 62 | documents= new QListViewItem(backupList, "Documents", "", |
63 | QDir::homeDirPath() + "/Documents/"); | 63 | QDir::homeDirPath() + "/Documents/"); |
64 | selectItem(documents); | 64 | selectItem(documents); |
65 | 65 | ||
66 | scanForApplicationSettings(); | 66 | scanForApplicationSettings(); |
67 | 67 | ||
68 | Config config("BackupAndRestore"); | 68 | Config config("BackupAndRestore"); |
69 | config.setGroup("General"); | 69 | config.setGroup("General"); |
70 | int totalLocations = config.readNumEntry("totalLocations",0); | 70 | int totalLocations = config.readNumEntry("totalLocations",0); |
71 | 71 | ||
72 | //todo make less static here and use Storage class to get infos | 72 | //todo make less static here and use Storage class to get infos |
73 | if(totalLocations == 0){ | 73 | if(totalLocations == 0){ |
74 | |||
75 | /* Ramses has a CF-Slot, but that one is internal and you have to dismount the | ||
76 | * the case. There's also almost always a WLAN card inserted there | ||
77 | */ | ||
78 | |||
79 | backupLocations.insert("Documents", "/root/Documents"); | 74 | backupLocations.insert("Documents", "/root/Documents"); |
80 | #if defined(QT_QWS_RAMSES) | ||
81 | backupLocations.insert("MMC", "/mnt/card"); | ||
82 | #else | ||
83 | backupLocations.insert("CF", "/mnt/cf"); | 75 | backupLocations.insert("CF", "/mnt/cf"); |
84 | backupLocations.insert("SD", "/mnt/card"); | 76 | backupLocations.insert("SD", "/mnt/card"); |
85 | #endif | ||
86 | } | 77 | } |
87 | else{ | 78 | else{ |
88 | for(int i = 0; i < totalLocations; i++){ | 79 | for(int i = 0; i < totalLocations; i++){ |
89 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), | 80 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), |
90 | config.readEntry(QString("backupLocation_%1").arg(i))); | 81 | config.readEntry(QString("backupLocation_%1").arg(i))); |
91 | } | 82 | } |
92 | } | 83 | } |
93 | QMap<QString, QString>::Iterator it; | 84 | QMap<QString, QString>::Iterator it; |
94 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ | 85 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ |
95 | storeToLocation->insertItem(it.key()); | 86 | storeToLocation->insertItem(it.key()); |
96 | restoreSource->insertItem(it.key()); | 87 | restoreSource->insertItem(it.key()); |
97 | } | 88 | } |
98 | 89 | ||
99 | // Read the list of items to ignore. | 90 | // Read the list of items to ignore. |
100 | QList<QString> dontBackupList; | 91 | QList<QString> dontBackupList; |
101 | dontBackupList.setAutoDelete(true); | 92 | dontBackupList.setAutoDelete(true); |
102 | config.setGroup("DontBackup"); | 93 | config.setGroup("DontBackup"); |
103 | int total = config.readNumEntry("Total", 0); | 94 | int total = config.readNumEntry("Total", 0); |
104 | for(int i = 0; i < total; i++){ | 95 | for(int i = 0; i < total; i++){ |
105 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | 96 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); |
106 | } | 97 | } |
107 | 98 | ||
108 | QList<QListViewItem> list; | 99 | QList<QListViewItem> list; |
109 | getAllItems(backupList->firstChild(), list); | 100 | getAllItems(backupList->firstChild(), list); |
110 | 101 | ||
111 | for(uint i = 0; i < list.count(); i++){ | 102 | for(uint i = 0; i < list.count(); i++){ |
112 | QString text = list.at(i)->text(HEADER_NAME); | 103 | QString text = list.at(i)->text(HEADER_NAME); |
113 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ | 104 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ |
114 | if(*dontBackupList.at(i2) == text){ | 105 | if(*dontBackupList.at(i2) == text){ |
115 | selectItem(list.at(i)); | 106 | selectItem(list.at(i)); |
116 | break; | 107 | break; |
117 | } | 108 | } |
118 | } | 109 | } |
119 | } | 110 | } |
120 | } | 111 | } |
121 | 112 | ||
122 | BackupAndRestore::~BackupAndRestore(){ | 113 | BackupAndRestore::~BackupAndRestore(){ |
123 | QList<QListViewItem> list; | 114 | QList<QListViewItem> list; |
124 | getAllItems(backupList->firstChild(), list); | 115 | getAllItems(backupList->firstChild(), list); |
125 | 116 | ||
126 | Config config("BackupAndRestore"); | 117 | Config config("BackupAndRestore"); |
127 | config.setGroup("DontBackup"); | 118 | config.setGroup("DontBackup"); |
128 | config.clearGroup(); | 119 | config.clearGroup(); |
129 | 120 | ||
130 | int count = 0; | 121 | int count = 0; |
131 | for(uint i = 0; i < list.count(); i++){ | 122 | for(uint i = 0; i < list.count(); i++){ |
132 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 123 | if(list.at(i)->text(HEADER_BACKUP) == ""){ |
133 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 124 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
134 | count++; | 125 | count++; |
135 | } | 126 | } |
136 | } | 127 | } |
137 | config.writeEntry("Total", count); | 128 | config.writeEntry("Total", count); |
138 | 129 | ||
139 | // Remove Temp File | 130 | // Remove Temp File |
140 | if ( QFile::exists( tempFileName ) ) | 131 | if ( QFile::exists( tempFileName ) ) |
141 | QFile::remove( tempFileName ); | 132 | QFile::remove( tempFileName ); |
142 | } | 133 | } |
143 | 134 | ||
144 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ | 135 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ |
145 | while(item){ | 136 | while(item){ |
146 | if(item->childCount() > 0) | 137 | if(item->childCount() > 0) |
147 | getAllItems(item->firstChild(), list); | 138 | getAllItems(item->firstChild(), list); |
148 | list.append(item); | 139 | list.append(item); |
149 | item = item->nextSibling(); | 140 | item = item->nextSibling(); |
150 | } | 141 | } |
151 | return list; | 142 | return list; |
152 | } | 143 | } |
153 | 144 | ||
154 | /** | 145 | /** |
155 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. | 146 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. |
156 | * and changing the icon to match | 147 | * and changing the icon to match |
157 | * @param currentItem the item to swich the selection choice. | 148 | * @param currentItem the item to swich the selection choice. |
158 | */ | 149 | */ |
159 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ | 150 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ |
160 | if(!currentItem) | 151 | if(!currentItem) |
161 | return; | 152 | return; |
162 | 153 | ||
163 | if(currentItem->text(HEADER_BACKUP) == "B"){ | 154 | if(currentItem->text(HEADER_BACKUP) == "B"){ |
164 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); | 155 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); |
165 | currentItem->setText(HEADER_BACKUP, ""); | 156 | currentItem->setText(HEADER_BACKUP, ""); |
166 | } | 157 | } |
167 | else{ | 158 | else{ |
168 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); | 159 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); |
169 | currentItem->setText(HEADER_BACKUP, "B"); | 160 | currentItem->setText(HEADER_BACKUP, "B"); |
170 | } | 161 | } |
171 | } | 162 | } |
172 | 163 | ||
173 | void BackupAndRestore::scanForApplicationSettings(){ | 164 | void BackupAndRestore::scanForApplicationSettings(){ |
174 | QDir d(applicationSettings->text(BACKUP_LOCATION)); | 165 | QDir d(applicationSettings->text(BACKUP_LOCATION)); |
175 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); | 166 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); |
176 | const QFileInfoList *list = d.entryInfoList(); | 167 | const QFileInfoList *list = d.entryInfoList(); |
177 | QFileInfoListIterator it( *list ); | 168 | QFileInfoListIterator it( *list ); |
178 | QFileInfo *fi; | 169 | QFileInfo *fi; |
179 | while ( (fi=it.current()) ) { | 170 | while ( (fi=it.current()) ) { |
180 | // qDebug((d.path()+fi->fileName()).latin1()); | 171 | // qDebug((d.path()+fi->fileName()).latin1()); |
181 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) { | 172 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) { |