author | llornkcor <llornkcor> | 2002-11-14 12:34:11 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-14 12:34:11 (UTC) |
commit | d419cd6d7f96341efc16717d68d7f7a0cfc09a80 (patch) (unidiff) | |
tree | 3c12ccf13c348d6e905bcc8976b833295ae608a2 | |
parent | 9daeebf24f8a7cb00216df90527d993c5ff7df0d (diff) | |
download | opie-d419cd6d7f96341efc16717d68d7f7a0cfc09a80.zip opie-d419cd6d7f96341efc16717d68d7f7a0cfc09a80.tar.gz opie-d419cd6d7f96341efc16717d68d7f7a0cfc09a80.tar.bz2 |
use real filepaths instead of Sharps idiotic ones
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 5776f3c..fb892d9 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -1,274 +1,288 @@ | |||
1 | #include "backuprestore.h" | 1 | #include "backuprestore.h" |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qfileinfo.h> | 4 | #include <qfileinfo.h> |
5 | #include <qlistview.h> | 5 | #include <qlistview.h> |
6 | #include <qpushbutton.h> | 6 | #include <qpushbutton.h> |
7 | #include <qheader.h> | 7 | #include <qheader.h> |
8 | #include <qpe/resource.h> | 8 | #include <qpe/resource.h> |
9 | #include <qpe/config.h> | 9 | #include <qpe/config.h> |
10 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
11 | #include <qcombobox.h> | 11 | #include <qcombobox.h> |
12 | #include <qlist.h> | 12 | #include <qlist.h> |
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | #include <qregexp.h> | 14 | #include <qregexp.h> |
15 | 15 | ||
16 | #define HEADER_NAME 0 | 16 | #define HEADER_NAME 0 |
17 | #define HEADER_BACKUP 1 | 17 | #define HEADER_BACKUP 1 |
18 | #define BACKUP_LOCATION 2 | 18 | #define BACKUP_LOCATION 2 |
19 | 19 | ||
20 | #define EXTENSION ".bck" | 20 | #define EXTENSION ".bck" |
21 | 21 | ||
22 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) : BackupAndRestoreBase(parent, name){ | 22 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) |
23 | : BackupAndRestoreBase(parent, name){ | ||
23 | this->showMaximized(); | 24 | this->showMaximized(); |
24 | backupList->header()->hide(); | 25 | backupList->header()->hide(); |
25 | restoreList->header()->hide(); | 26 | restoreList->header()->hide(); |
26 | connect(backupButton, SIGNAL(clicked()), this, SLOT(backupPressed())); | 27 | connect(backupButton, SIGNAL(clicked()), |
27 | connect(restoreButton, SIGNAL(clicked()), this, SLOT(restore())); | 28 | this, SLOT(backupPressed())); |
28 | connect(backupList, SIGNAL(clicked( QListViewItem * )), this, SLOT(selectItem(QListViewItem*))); | 29 | connect(restoreButton, SIGNAL(clicked()), |
29 | connect(restoreSource, SIGNAL(activated( int )), this, SLOT(sourceDirChanged(int))); | 30 | this, SLOT(restore())); |
31 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | ||
32 | this, SLOT(selectItem(QListViewItem*))); | ||
33 | connect(restoreSource, SIGNAL(activated( int )), | ||
34 | this, SLOT(sourceDirChanged(int))); | ||
30 | 35 | ||
31 | systemSettings = new QListViewItem(backupList, "System Settings", "", "/home/etc"); | 36 | systemSettings = new QListViewItem(backupList, "System Settings", "", |
37 | "/etc"); | ||
32 | selectItem(systemSettings); | 38 | selectItem(systemSettings); |
33 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", QDir::homeDirPath() + "/Settings/"); | 39 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", |
40 | QDir::homeDirPath() + "/Settings/"); | ||
34 | selectItem(applicationSettings); | 41 | selectItem(applicationSettings); |
35 | documents= new QListViewItem(backupList, "Documents", "", QDir::homeDirPath() + "/Documents/"); | 42 | documents= new QListViewItem(backupList, "Documents", "", |
43 | QDir::homeDirPath() + "/Documents/"); | ||
36 | selectItem(documents); | 44 | selectItem(documents); |
37 | 45 | ||
38 | scanForApplicationSettings(); | 46 | scanForApplicationSettings(); |
39 | 47 | ||
40 | Config config("BackupAndRestore"); | 48 | Config config("BackupAndRestore"); |
41 | config.setGroup("General"); | 49 | config.setGroup("General"); |
42 | int totalLocations = config.readNumEntry("totalLocations",0); | 50 | int totalLocations = config.readNumEntry("totalLocations",0); |
43 | 51 | ||
52 | //todo make less static here and use Storage class to get infos | ||
44 | if(totalLocations == 0){ | 53 | if(totalLocations == 0){ |
45 | backupLocations.insert("Documents", "/home/root/Documents"); | 54 | backupLocations.insert("Documents", "/root/Documents"); |
46 | backupLocations.insert("CF", "/mnt/cf"); | 55 | backupLocations.insert("CF", "/mnt/cf"); |
47 | backupLocations.insert("SD", "/mnt/card"); | 56 | backupLocations.insert("SD", "/mnt/card"); |
48 | } | 57 | } |
49 | else{ | 58 | else{ |
50 | for(int i = 0; i < totalLocations; i++){ | 59 | for(int i = 0; i < totalLocations; i++){ |
51 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), config.readEntry(QString("backupLocation_%1").arg(i))); | 60 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), |
61 | config.readEntry(QString("backupLocation_%1").arg(i))); | ||
52 | } | 62 | } |
53 | } | 63 | } |
54 | QMap<QString, QString>::Iterator it; | 64 | QMap<QString, QString>::Iterator it; |
55 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ | 65 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ |
56 | storeToLocation->insertItem(it.key()); | 66 | storeToLocation->insertItem(it.key()); |
57 | restoreSource->insertItem(it.key()); | 67 | restoreSource->insertItem(it.key()); |
58 | } | 68 | } |
59 | 69 | ||
60 | // Read the list of items to ignore. | 70 | // Read the list of items to ignore. |
61 | QList<QString> dontBackupList; | 71 | QList<QString> dontBackupList; |
62 | dontBackupList.setAutoDelete(true); | 72 | dontBackupList.setAutoDelete(true); |
63 | config.setGroup("DontBackup"); | 73 | config.setGroup("DontBackup"); |
64 | int total = config.readNumEntry("Total", 0); | 74 | int total = config.readNumEntry("Total", 0); |
65 | for(int i = 0; i < total; i++){ | 75 | for(int i = 0; i < total; i++){ |
66 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | 76 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); |
67 | } | 77 | } |
68 | 78 | ||
69 | QList<QListViewItem> list; | 79 | QList<QListViewItem> list; |
70 | getAllItems(backupList->firstChild(), list); | 80 | getAllItems(backupList->firstChild(), list); |
71 | 81 | ||
72 | for(uint i = 0; i < list.count(); i++){ | 82 | for(uint i = 0; i < list.count(); i++){ |
73 | QString text = list.at(i)->text(HEADER_NAME); | 83 | QString text = list.at(i)->text(HEADER_NAME); |
74 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ | 84 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ |
75 | if(*dontBackupList.at(i2) == text){ | 85 | if(*dontBackupList.at(i2) == text){ |
76 | selectItem(list.at(i)); | 86 | selectItem(list.at(i)); |
77 | break; | 87 | break; |
78 | } | 88 | } |
79 | } | 89 | } |
80 | } | 90 | } |
81 | } | 91 | } |
82 | 92 | ||
83 | BackupAndRestore::~BackupAndRestore(){ | 93 | BackupAndRestore::~BackupAndRestore(){ |
84 | QList<QListViewItem> list; | 94 | QList<QListViewItem> list; |
85 | getAllItems(backupList->firstChild(), list); | 95 | getAllItems(backupList->firstChild(), list); |
86 | 96 | ||
87 | Config config("BackupAndRestore"); | 97 | Config config("BackupAndRestore"); |
88 | config.setGroup("DontBackup"); | 98 | config.setGroup("DontBackup"); |
89 | config.clearGroup(); | 99 | config.clearGroup(); |
90 | 100 | ||
91 | int count = 0; | 101 | int count = 0; |
92 | for(uint i = 0; i < list.count(); i++){ | 102 | for(uint i = 0; i < list.count(); i++){ |
93 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 103 | if(list.at(i)->text(HEADER_BACKUP) == ""){ |
94 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 104 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
95 | count++; | 105 | count++; |
96 | } | 106 | } |
97 | } | 107 | } |
98 | config.writeEntry("Total", count); | 108 | config.writeEntry("Total", count); |
99 | } | 109 | } |
100 | 110 | ||
101 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ | 111 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ |
102 | while(item){ | 112 | while(item){ |
103 | if(item->childCount() > 0) | 113 | if(item->childCount() > 0) |
104 | getAllItems(item->firstChild(), list); | 114 | getAllItems(item->firstChild(), list); |
105 | list.append(item); | 115 | list.append(item); |
106 | item = item->nextSibling(); | 116 | item = item->nextSibling(); |
107 | } | 117 | } |
108 | return list; | 118 | return list; |
109 | } | 119 | } |
110 | 120 | ||
111 | /** | 121 | /** |
112 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. | 122 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. |
113 | * and changing the icon to match | 123 | * and changing the icon to match |
114 | * @param currentItem the item to swich the selection choice. | 124 | * @param currentItem the item to swich the selection choice. |
115 | */ | 125 | */ |
116 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ | 126 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ |
117 | if(!currentItem) | 127 | if(!currentItem) |
118 | return; | 128 | return; |
119 | 129 | ||
120 | if(currentItem->text(HEADER_BACKUP) == "B"){ | 130 | if(currentItem->text(HEADER_BACKUP) == "B"){ |
121 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("null")); | 131 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("null")); |
122 | currentItem->setText(HEADER_BACKUP, ""); | 132 | currentItem->setText(HEADER_BACKUP, ""); |
123 | } | 133 | } |
124 | else{ | 134 | else{ |
125 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("check")); | 135 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("check")); |
126 | currentItem->setText(HEADER_BACKUP, "B"); | 136 | currentItem->setText(HEADER_BACKUP, "B"); |
127 | } | 137 | } |
128 | } | 138 | } |
129 | 139 | ||
130 | void BackupAndRestore::scanForApplicationSettings(){ | 140 | void BackupAndRestore::scanForApplicationSettings(){ |
131 | QDir d(applicationSettings->text(BACKUP_LOCATION)); | 141 | QDir d(applicationSettings->text(BACKUP_LOCATION)); |
132 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 142 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
133 | const QFileInfoList *list = d.entryInfoList(); | 143 | const QFileInfoList *list = d.entryInfoList(); |
134 | QFileInfoListIterator it( *list ); | 144 | QFileInfoListIterator it( *list ); |
135 | QFileInfo *fi; | 145 | QFileInfo *fi; |
136 | while ( (fi=it.current()) ) { | 146 | while ( (fi=it.current()) ) { |
137 | //qDebug((d.path()+fi->fileName()).latin1()); | 147 | //qDebug((d.path()+fi->fileName()).latin1()); |
138 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 148 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
139 | selectItem(newItem); | 149 | selectItem(newItem); |
140 | ++it; | 150 | ++it; |
141 | } | 151 | } |
142 | } | 152 | } |
143 | 153 | ||
144 | /** | 154 | /** |
145 | * The "Backup" button has been pressed. Get a list of all of the files that | 155 | * The "Backup" button has been pressed. Get a list of all of the files that |
146 | * should be backed up. If there are no files, emit and error and exit. | 156 | * should be backed up. If there are no files, emit and error and exit. |
147 | * Determine the file name to store the backup in. Backup the file(s) using | 157 | * Determine the file name to store the backup in. Backup the file(s) using |
148 | * tar and gzip --best. Report failure or success | 158 | * tar and gzip --best. Report failure or success |
149 | */ | 159 | */ |
150 | void BackupAndRestore::backupPressed(){ | 160 | void BackupAndRestore::backupPressed(){ |
151 | QString backupFiles; | 161 | QString backupFiles; |
152 | if(getBackupFiles(backupFiles, NULL) == 0){ | 162 | if(getBackupFiles(backupFiles, NULL) == 0){ |
153 | QMessageBox::critical(this, "Message", "No items selected.",QString("Ok") ); | 163 | QMessageBox::critical(this, "Message", |
154 | return; | 164 | "No items selected.",QString("Ok") ); |
165 | return; | ||
155 | } | 166 | } |
156 | 167 | ||
157 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 168 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
158 | 169 | ||
159 | QDateTime time = QDateTime::currentDateTime(); | 170 | QDateTime time = QDateTime::currentDateTime(); |
160 | QString dateString = time.date().toString().replace(QRegExp(" "), ""); | 171 | QString dateString = time.date().toString().replace(QRegExp(" "), ""); |
161 | outputFile += "/" + dateString; | 172 | outputFile += "/" + dateString; |
162 | 173 | ||
163 | QString t = outputFile; | 174 | QString t = outputFile; |
164 | int c = 1; | 175 | int c = 1; |
165 | while(QFile::exists(outputFile + EXTENSION)){ | 176 | while(QFile::exists(outputFile + EXTENSION)){ |
166 | outputFile = t + QString("%1").arg(c); | 177 | outputFile = t + QString("%1").arg(c); |
167 | c++; | 178 | c++; |
168 | } | 179 | } |
169 | outputFile += EXTENSION; | 180 | outputFile += EXTENSION; |
170 | 181 | ||
171 | int r = system(QString("tar -c %1 | gzip --best > %2").arg(backupFiles).arg(outputFile).latin1()); | 182 | int r = system(QString("tar -c %1 | gzip --best > %2").arg(backupFiles).arg(outputFile).latin1()); |
172 | if(r != 0){ | 183 | if(r != 0){ |
173 | QMessageBox::critical(this, "Message", "Backup Failed.",QString("Ok") ); | 184 | QMessageBox::critical(this, "Message", "Backup Failed.",QString("Ok") ); |
174 | return; | 185 | return; |
175 | } | 186 | } |
176 | else{ | 187 | else{ |
177 | QMessageBox::critical(this, "Message", "Backup Successfull.",QString("Ok") ); | 188 | QMessageBox::critical(this, "Message", "Backup Successfull.",QString("Ok") ); |
178 | } | 189 | } |
179 | } | 190 | } |
180 | 191 | ||
181 | /*** | 192 | /*** |
182 | * Get a list of all of the files to backup. | 193 | * Get a list of all of the files to backup. |
183 | */ | 194 | */ |
184 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ | 195 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ |
185 | QListViewItem * currentItem; | 196 | QListViewItem * currentItem; |
186 | QString currentHome; | 197 | QString currentHome; |
187 | if(!parent) | 198 | if(!parent) |
188 | currentItem = backupList->firstChild(); | 199 | currentItem = backupList->firstChild(); |
189 | else{ | 200 | else{ |
190 | currentItem = parent->firstChild(); | 201 | currentItem = parent->firstChild(); |
191 | currentHome = parent->text(BACKUP_LOCATION); | 202 | currentHome = parent->text(BACKUP_LOCATION); |
192 | } | 203 | } |
193 | 204 | ||
194 | uint count = 0; | 205 | uint count = 0; |
195 | while( currentItem != 0 ){ | 206 | while( currentItem != 0 ){ |
196 | if(currentItem->text(HEADER_BACKUP) == "B" ){ | 207 | if(currentItem->text(HEADER_BACKUP) == "B" ){ |
197 | if(currentItem->childCount() == 0 ){ | 208 | if(currentItem->childCount() == 0 ){ |
198 | if(parent == NULL) | 209 | if(parent == NULL) |
199 | backupFiles += currentItem->text(BACKUP_LOCATION); | 210 | backupFiles += currentItem->text(BACKUP_LOCATION); |
200 | else | 211 | else |
201 | backupFiles += currentHome + currentItem->text(HEADER_NAME); | 212 | backupFiles += currentHome + currentItem->text(HEADER_NAME); |
202 | backupFiles += " "; | 213 | backupFiles += " "; |
203 | count++; | 214 | count++; |
204 | } | 215 | } |
205 | else{ | 216 | else{ |
206 | count += getBackupFiles(backupFiles, currentItem); | 217 | count += getBackupFiles(backupFiles, currentItem); |
207 | } | 218 | } |
208 | } | 219 | } |
209 | currentItem = currentItem->nextSibling(); | 220 | currentItem = currentItem->nextSibling(); |
210 | } | 221 | } |
211 | return count; | 222 | return count; |
212 | } | 223 | } |
213 | 224 | ||
214 | void BackupAndRestore::sourceDirChanged(int selection){ | 225 | void BackupAndRestore::sourceDirChanged(int selection){ |
215 | restoreList->clear(); | 226 | restoreList->clear(); |
216 | rescanFolder(backupLocations[restoreSource->text(selection)]); | 227 | rescanFolder(backupLocations[restoreSource->text(selection)]); |
217 | } | 228 | } |
218 | 229 | ||
219 | /** | 230 | /** |
220 | * Scans directory for any backup files. Will recursivly go down, | 231 | * Scans directory for any backup files. Will recursivly go down, |
221 | * but will not follow symlinks. | 232 | * but will not follow symlinks. |
222 | * @param directory - the directory to look in. | 233 | * @param directory - the directory to look in. |
223 | */ | 234 | */ |
224 | void BackupAndRestore::rescanFolder(QString directory){ | 235 | void BackupAndRestore::rescanFolder(QString directory){ |
225 | //qDebug(QString("rescanFolder: ") + directory.latin1()); | 236 | //qDebug(QString("rescanFolder: ") + directory.latin1()); |
226 | QDir d(directory); | 237 | QDir d(directory); |
227 | if(!d.exists()) | 238 | if(!d.exists()) |
228 | return; | 239 | return; |
229 | 240 | ||
230 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 241 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
231 | const QFileInfoList *list = d.entryInfoList(); | 242 | const QFileInfoList *list = d.entryInfoList(); |
232 | QFileInfoListIterator it( *list ); | 243 | QFileInfoListIterator it( *list ); |
233 | QFileInfo *file; | 244 | QFileInfo *file; |
234 | while ( (file=it.current()) ) { // for each file... | 245 | while ( (file=it.current()) ) { // for each file... |
235 | // If it is a dir and not .. or . then add it as a tab and go down. | 246 | // If it is a dir and not .. or . then add it as a tab and go down. |
236 | if(file->isDir()){ | 247 | if(file->isDir()){ |
237 | if(file->fileName() != ".." && file->fileName() != ".") { | 248 | if(file->fileName() != ".." && file->fileName() != ".") { |
238 | rescanFolder(directory + "/" + file->fileName()); | 249 | rescanFolder(directory + "/" + file->fileName()); |
239 | } | 250 | } |
240 | } | 251 | } |
241 | else{ | 252 | else{ |
242 | // If it is a backup file add to list. | 253 | // If it is a backup file add to list. |
243 | if(file->fileName().contains(EXTENSION)) | 254 | if(file->fileName().contains(EXTENSION)) |
244 | (void)new QListViewItem(restoreList, file->fileName()); | 255 | (void)new QListViewItem(restoreList, file->fileName()); |
245 | } | 256 | } |
246 | ++it; | 257 | ++it; |
247 | } | 258 | } |
248 | } | 259 | } |
249 | 260 | ||
250 | /** | 261 | /** |
251 | * Restore a backup file. | 262 | * Restore a backup file. |
252 | * Report errors or success | 263 | * Report errors or success |
253 | */ | 264 | */ |
254 | void BackupAndRestore::restore(){ | 265 | void BackupAndRestore::restore(){ |
255 | QListViewItem *restoreItem = restoreList->currentItem(); | 266 | QListViewItem *restoreItem = restoreList->currentItem(); |
256 | if(!restoreItem){ | 267 | if(!restoreItem){ |
257 | QMessageBox::critical(this, "Message", "Please select something to restore.",QString("Ok") ); | 268 | QMessageBox::critical(this, "Message", |
258 | return; | 269 | "Please select something to restore.",QString("Ok") ); |
270 | return; | ||
259 | } | 271 | } |
260 | QString restoreFile = backupLocations[restoreSource->currentText()]; | 272 | QString restoreFile = backupLocations[restoreSource->currentText()]; |
261 | 273 | ||
262 | restoreFile += "/" + restoreItem->text(0); | 274 | restoreFile += "/" + restoreItem->text(0); |
263 | 275 | ||
264 | int r = system(QString("tar -C / -zxf %1").arg(restoreFile).latin1()); | 276 | int r = system(QString("tar -C / -zxf %1").arg(restoreFile).latin1()); |
265 | if(r != 0){ | 277 | if(r != 0){ |
266 | QMessageBox::critical(this, "Message", "Restore Failed.",QString("Ok") ); | 278 | QMessageBox::critical(this, "Message", |
279 | "Restore Failed.",QString("Ok") ); | ||
267 | } | 280 | } |
268 | else{ | 281 | else{ |
269 | QMessageBox::critical(this, "Message", "Restore Successfull.",QString("Ok") ); | 282 | QMessageBox::critical(this, "Message", |
283 | "Restore Successfull.",QString("Ok") ); | ||
270 | } | 284 | } |
271 | } | 285 | } |
272 | 286 | ||
273 | // backuprestore.cpp | 287 | // backuprestore.cpp |
274 | 288 | ||