author | ar <ar> | 2003-12-15 22:21:34 (UTC) |
---|---|---|
committer | ar <ar> | 2003-12-15 22:21:34 (UTC) |
commit | 32d48372f7b5ec9e4586ea74cc444838b157248e (patch) (unidiff) | |
tree | a73c24014ce8a9ef2bbbe30d01a880b8a87ed482 | |
parent | 0d9ef683fbd3822723e350b09d4c700316889ba6 (diff) | |
download | opie-32d48372f7b5ec9e4586ea74cc444838b157248e.zip opie-32d48372f7b5ec9e4586ea74cc444838b157248e.tar.gz opie-32d48372f7b5ec9e4586ea74cc444838b157248e.tar.bz2 |
- backup and restore relative to users homedir
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 657 | ||||
-rw-r--r-- | noncore/settings/backup/backuprestore.h | 41 |
2 files changed, 370 insertions, 328 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 19e7cf9..7d0daf7 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -41,110 +41,109 @@ const QString tempFileName = "/tmp/backup.err"; | |||
41 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) | 41 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) |
42 | : BackupAndRestoreBase(parent, name, fl){ | 42 | : BackupAndRestoreBase(parent, name, fl) |
43 | this->showMaximized(); | 43 | { |
44 | backupList->header()->hide(); | 44 | this->showMaximized(); |
45 | restoreList->header()->hide(); | 45 | backupList->header()->hide(); |
46 | connect(backupButton, SIGNAL(clicked()), | 46 | restoreList->header()->hide(); |
47 | this, SLOT(backupPressed())); | 47 | connect(backupButton, SIGNAL(clicked()), |
48 | connect(restoreButton, SIGNAL(clicked()), | 48 | this, SLOT(backup())); |
49 | this, SLOT(restore())); | 49 | connect(restoreButton, SIGNAL(clicked()), |
50 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | 50 | this, SLOT(restore())); |
51 | this, SLOT(selectItem(QListViewItem*))); | 51 | connect(backupList, SIGNAL(clicked( QListViewItem * )), |
52 | connect(restoreSource, SIGNAL(activated( int )), | 52 | this, SLOT(selectItem(QListViewItem*))); |
53 | this, SLOT(sourceDirChanged(int))); | 53 | connect(restoreSource, SIGNAL(activated( int )), |
54 | connect(updateList, SIGNAL(clicked()), | 54 | this, SLOT(sourceDirChanged(int))); |
55 | this, SLOT( fileListUpdate())); | 55 | connect(updateList, SIGNAL(clicked()), |
56 | 56 | this, SLOT( fileListUpdate())); | |
57 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", | 57 | |
58 | QDir::homeDirPath() + "/Settings/"); | 58 | //add directorys for backing up |
59 | selectItem(applicationSettings); | 59 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); |
60 | applicationSettings = new QListViewItem(backupList, "Application Data", "", | 60 | selectItem(applicationSettings); |
61 | QDir::homeDirPath() + "/Applications/"); | 61 | applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); |
62 | selectItem(applicationSettings); | 62 | selectItem(applicationSettings); |
63 | documents= new QListViewItem(backupList, "Documents", "", | 63 | documents= new QListViewItem(backupList, "Documents", "", "Documents/"); |
64 | QDir::homeDirPath() + "/Documents/"); | 64 | selectItem(documents); |
65 | selectItem(documents); | 65 | |
66 | 66 | scanForApplicationSettings(); | |
67 | scanForApplicationSettings(); | 67 | |
68 | 68 | backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" ); | |
69 | Config config("BackupAndRestore"); | 69 | if (StorageInfo::hasCf()) |
70 | config.setGroup("General"); | 70 | { |
71 | int totalLocations = config.readNumEntry("totalLocations",0); | 71 | backupLocations.insert("CF", "/mnt/cf"); |
72 | |||
73 | //todo make less static here and use Storage class to get infos | ||
74 | if(totalLocations == 0){ | ||
75 | QString home = QDir::homeDirPath(); | ||
76 | home += "/Documents"; | ||
77 | backupLocations.insert("Documents", home); | ||
78 | if (StorageInfo::hasCf()) { | ||
79 | backupLocations.insert("CF", "/mnt/cf"); | ||
80 | } | ||
81 | if (StorageInfo::hasSd || StorageInfo::hasMmc) { | ||
82 | backupLocations.insert("SD", "/mnt/card"); | ||
83 | } | 72 | } |
84 | } | 73 | if (StorageInfo::hasSd || StorageInfo::hasMmc) |
85 | else{ | 74 | { |
86 | for(int i = 0; i < totalLocations; i++){ | 75 | backupLocations.insert("SD", "/mnt/card"); |
87 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), | ||
88 | config.readEntry(QString("backupLocation_%1").arg(i))); | ||
89 | } | 76 | } |
90 | } | 77 | |
91 | QMap<QString, QString>::Iterator it; | 78 | QMap<QString, QString>::Iterator it; |
92 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ | 79 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ) |
93 | storeToLocation->insertItem(it.key()); | 80 | { |
94 | restoreSource->insertItem(it.key()); | 81 | storeToLocation->insertItem(it.key()); |
95 | } | 82 | restoreSource->insertItem(it.key()); |
96 | |||
97 | // Read the list of items to ignore. | ||
98 | QList<QString> dontBackupList; | ||
99 | dontBackupList.setAutoDelete(true); | ||
100 | config.setGroup("DontBackup"); | ||
101 | int total = config.readNumEntry("Total", 0); | ||
102 | for(int i = 0; i < total; i++){ | ||
103 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | ||
104 | } | ||
105 | |||
106 | QList<QListViewItem> list; | ||
107 | getAllItems(backupList->firstChild(), list); | ||
108 | |||
109 | for(uint i = 0; i < list.count(); i++){ | ||
110 | QString text = list.at(i)->text(HEADER_NAME); | ||
111 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ | ||
112 | if(*dontBackupList.at(i2) == text){ | ||
113 | selectItem(list.at(i)); | ||
114 | break; | ||
115 | } | ||
116 | } | 83 | } |
117 | } | ||
118 | } | ||
119 | 84 | ||
120 | BackupAndRestore::~BackupAndRestore(){ | 85 | // Read the list of items to ignore. |
121 | QList<QListViewItem> list; | 86 | Config config("BackupAndRestore"); |
122 | getAllItems(backupList->firstChild(), list); | 87 | |
88 | QList<QString> dontBackupList; | ||
89 | dontBackupList.setAutoDelete(true); | ||
90 | config.setGroup("DontBackup"); | ||
91 | int total = config.readNumEntry("Total", 0); | ||
92 | for(int i = 0; i < total; i++) | ||
93 | { | ||
94 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | ||
95 | } | ||
123 | 96 | ||
124 | Config config("BackupAndRestore"); | 97 | QList<QListViewItem> list; |
125 | config.setGroup("DontBackup"); | 98 | getAllItems(backupList->firstChild(), list); |
126 | config.clearGroup(); | 99 | |
100 | for(uint i = 0; i < list.count(); i++) | ||
101 | { | ||
102 | QString text = list.at(i)->text(HEADER_NAME); | ||
103 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++) | ||
104 | { | ||
105 | if(*dontBackupList.at(i2) == text) | ||
106 | { | ||
107 | selectItem(list.at(i)); | ||
108 | break; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | } | ||
127 | 113 | ||
128 | int count = 0; | 114 | BackupAndRestore::~BackupAndRestore() |
129 | for(uint i = 0; i < list.count(); i++){ | 115 | { |
130 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 116 | QList<QListViewItem> list; |
131 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 117 | getAllItems(backupList->firstChild(), list); |
132 | count++; | 118 | |
119 | Config config("BackupAndRestore"); | ||
120 | config.setGroup("DontBackup"); | ||
121 | config.clearGroup(); | ||
122 | |||
123 | int count = 0; | ||
124 | for(uint i = 0; i < list.count(); i++) | ||
125 | { | ||
126 | if(list.at(i)->text(HEADER_BACKUP) == "") | ||
127 | { | ||
128 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | ||
129 | count++; | ||
130 | } | ||
133 | } | 131 | } |
134 | } | 132 | config.writeEntry("Total", count); |
135 | config.writeEntry("Total", count); | ||
136 | 133 | ||
137 | // Remove Temp File | 134 | // Remove Temp File |
138 | if ( QFile::exists( tempFileName ) ) | 135 | if ( QFile::exists( tempFileName ) ) |
139 | QFile::remove( tempFileName ); | 136 | QFile::remove( tempFileName ); |
140 | } | 137 | } |
141 | 138 | ||
142 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ | 139 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) |
143 | while(item){ | 140 | { |
144 | if(item->childCount() > 0) | 141 | while(item) |
145 | getAllItems(item->firstChild(), list); | 142 | { |
146 | list.append(item); | 143 | if(item->childCount() > 0) |
147 | item = item->nextSibling(); | 144 | getAllItems(item->firstChild(), list); |
148 | } | 145 | list.append(item); |
149 | return list; | 146 | item = item->nextSibling(); |
147 | } | ||
148 | return list; | ||
150 | } | 149 | } |
@@ -156,30 +155,36 @@ QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QL | |||
156 | */ | 155 | */ |
157 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ | 156 | void BackupAndRestore::selectItem(QListViewItem *currentItem) |
158 | if(!currentItem) | 157 | { |
159 | return; | 158 | if(!currentItem) |
160 | 159 | return; | |
161 | if(currentItem->text(HEADER_BACKUP) == "B"){ | 160 | |
162 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); | 161 | if(currentItem->text(HEADER_BACKUP) == "B") |
163 | currentItem->setText(HEADER_BACKUP, ""); | 162 | { |
164 | } | 163 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); |
165 | else{ | 164 | currentItem->setText(HEADER_BACKUP, ""); |
166 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); | 165 | } |
167 | currentItem->setText(HEADER_BACKUP, "B"); | 166 | else |
168 | } | 167 | { |
168 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); | ||
169 | currentItem->setText(HEADER_BACKUP, "B"); | ||
170 | } | ||
169 | } | 171 | } |
170 | 172 | ||
171 | void BackupAndRestore::scanForApplicationSettings(){ | 173 | void BackupAndRestore::scanForApplicationSettings() |
172 | QDir d(applicationSettings->text(BACKUP_LOCATION)); | 174 | { |
173 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); | 175 | QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); |
174 | const QFileInfoList *list = d.entryInfoList(); | 176 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); |
175 | QFileInfoListIterator it( *list ); | 177 | const QFileInfoList *list = d.entryInfoList(); |
176 | QFileInfo *fi; | 178 | QFileInfoListIterator it( *list ); |
177 | while ( (fi=it.current()) ) { | 179 | QFileInfo *fi; |
178 | // qDebug((d.path()+fi->fileName()).latin1()); | 180 | while ( (fi=it.current()) ) |
179 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) { | 181 | { |
180 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 182 | //qDebug((d.path()+"/"+fi->fileName()).latin1()); |
181 | selectItem(newItem); | 183 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) |
182 | } | 184 | { |
183 | ++it; | 185 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
184 | } | 186 | selectItem(newItem); |
187 | } | ||
188 | ++it; | ||
189 | } | ||
185 | } | 190 | } |
@@ -192,79 +197,87 @@ void BackupAndRestore::scanForApplicationSettings(){ | |||
192 | */ | 197 | */ |
193 | void BackupAndRestore::backupPressed(){ | 198 | void BackupAndRestore::backup() |
194 | QString backupFiles; | 199 | { |
195 | if(getBackupFiles(backupFiles, NULL) == 0){ | 200 | QString backupFiles; |
196 | QMessageBox::critical(this, "Message", | 201 | if(getBackupFiles(backupFiles, NULL) == 0) |
197 | "No items selected.",QString("Ok") ); | 202 | { |
198 | return; | 203 | QMessageBox::critical(this, "Message", |
199 | } | 204 | "No items selected.",QString("Ok") ); |
200 | 205 | return; | |
201 | setCaption(tr("Backup and Restore... working...")); | 206 | } |
202 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 207 | |
203 | 208 | setCaption(tr("Backup and Restore... working...")); | |
204 | QDateTime datetime = QDateTime::currentDateTime(); | 209 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
205 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 210 | |
206 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 211 | QDateTime datetime = QDateTime::currentDateTime(); |
207 | 212 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | |
208 | outputFile += "/" + dateString; | 213 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
209 | 214 | ||
210 | QString t = outputFile; | 215 | outputFile += "/" + dateString; |
211 | int c = 1; | 216 | |
212 | while(QFile::exists(outputFile + EXTENSION)){ | 217 | QString t = outputFile; |
213 | outputFile = t + QString("%1").arg(c); | 218 | int c = 1; |
214 | c++; | 219 | while(QFile::exists(outputFile + EXTENSION)) |
215 | } | 220 | { |
216 | 221 | outputFile = t + QString("%1").arg(c); | |
217 | // We execute tar and compressing its output with gzip.. | 222 | c++; |
218 | // The error output will be written into a temp-file which could be provided | 223 | } |
219 | // for debugging.. | 224 | |
220 | qDebug( "Storing file: %s", outputFile.latin1() ); | 225 | // We execute tar and compressing its output with gzip.. |
221 | outputFile += EXTENSION; | 226 | // The error output will be written into a temp-file which could be provided |
222 | 227 | // for debugging.. | |
223 | qWarning( QString("(tar -c %1 | gzip > %2 ) 2> %3") | 228 | qDebug( "Storing file: %s", outputFile.latin1() ); |
224 | .arg( backupFiles ) | 229 | outputFile += EXTENSION; |
225 | .arg( outputFile.latin1() ) | 230 | |
226 | .arg( tempFileName.latin1() ) ); | 231 | QString commandLine = QString( "(tar -C %1 -c %2 | gzip > %3 ) 2> %4" ).arg( QDir::homeDirPath() ) |
227 | 232 | .arg( backupFiles ) | |
228 | 233 | .arg( outputFile.latin1() ) | |
229 | int r = system( QString("(tar -c %1 | gzip > %2 ) 2> %3") | 234 | .arg( tempFileName.latin1() ); |
230 | .arg( backupFiles ) | 235 | |
231 | .arg( outputFile.latin1() ) | 236 | qDebug( commandLine ); |
232 | .arg( tempFileName.latin1() ) ); | 237 | |
233 | 238 | int r = system( commandLine ); | |
234 | if(r != 0){ | 239 | |
235 | perror("Error: "); | 240 | if(r != 0) |
236 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 241 | { |
237 | 242 | perror("Error: "); | |
238 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | 243 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
239 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ | 244 | |
240 | 245 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | |
241 | case 1: | 246 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) |
242 | qWarning("Details pressed !"); | 247 | { |
243 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 248 | |
244 | QFile errorFile( tempFileName ); | 249 | case 1: |
245 | if ( errorFile.open(IO_ReadOnly) ) { | 250 | qWarning("Details pressed !"); |
246 | QTextStream t( &errorFile ); | 251 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
247 | QString s; | 252 | QFile errorFile( tempFileName ); |
248 | while ( !t.eof() ) { // until end of file... | 253 | if ( errorFile.open(IO_ReadOnly) ) |
249 | s += t.readLine(); // line of text excluding '\n' | 254 | { |
250 | } | 255 | QTextStream t( &errorFile ); |
251 | errorFile.close(); | 256 | QString s; |
252 | 257 | while ( !t.eof() ) | |
253 | pErrDialog->m_textarea->setText( s ); | 258 | { // until end of file... |
254 | }else{ | 259 | s += t.readLine(); // line of text excluding '\n' |
255 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); | 260 | } |
256 | } | 261 | errorFile.close(); |
257 | pErrDialog->showMaximized(); | 262 | |
258 | pErrDialog->exec(); | 263 | pErrDialog->m_textarea->setText( s ); |
259 | delete pErrDialog; | 264 | } |
260 | break; | 265 | else |
261 | } | 266 | { |
262 | setCaption(tr("Backup and Restore.. Failed !!")); | 267 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); |
263 | return; | 268 | } |
264 | } | 269 | pErrDialog->showMaximized(); |
265 | else{ | 270 | pErrDialog->exec(); |
266 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); | 271 | delete pErrDialog; |
267 | 272 | break; | |
268 | } | 273 | } |
269 | setCaption(tr("Backup and Restore")); | 274 | setCaption(tr("Backup and Restore.. Failed !!")); |
275 | return; | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); | ||
280 | |||
281 | } | ||
282 | setCaption(tr("Backup and Restore")); | ||
270 | } | 283 | } |
@@ -274,35 +287,42 @@ void BackupAndRestore::backupPressed(){ | |||
274 | */ | 287 | */ |
275 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ | 288 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) |
276 | QListViewItem * currentItem; | 289 | { |
277 | QString currentHome; | 290 | QListViewItem * currentItem; |
278 | if(!parent) | 291 | QString currentHome; |
279 | currentItem = backupList->firstChild(); | 292 | if(!parent) |
280 | else{ | 293 | currentItem = backupList->firstChild(); |
281 | currentItem = parent->firstChild(); | 294 | else |
282 | currentHome = parent->text(BACKUP_LOCATION); | 295 | { |
283 | } | 296 | currentItem = parent->firstChild(); |
284 | 297 | currentHome = parent->text(BACKUP_LOCATION); | |
285 | uint count = 0; | ||
286 | while( currentItem != 0 ){ | ||
287 | if(currentItem->text(HEADER_BACKUP) == "B" ){ | ||
288 | if(currentItem->childCount() == 0 ){ | ||
289 | if(parent == NULL) | ||
290 | backupFiles += currentItem->text(BACKUP_LOCATION); | ||
291 | else | ||
292 | backupFiles += currentHome + currentItem->text(HEADER_NAME); | ||
293 | backupFiles += " "; | ||
294 | count++; | ||
295 | } | ||
296 | else{ | ||
297 | count += getBackupFiles(backupFiles, currentItem); | ||
298 | } | ||
299 | } | 298 | } |
300 | currentItem = currentItem->nextSibling(); | 299 | |
301 | } | 300 | uint count = 0; |
302 | return count; | 301 | while( currentItem != 0 ) |
302 | { | ||
303 | if(currentItem->text(HEADER_BACKUP) == "B" ) | ||
304 | { | ||
305 | if(currentItem->childCount() == 0 ) | ||
306 | { | ||
307 | if(parent == NULL) | ||
308 | backupFiles += currentItem->text(BACKUP_LOCATION); | ||
309 | else | ||
310 | backupFiles += currentHome + currentItem->text(HEADER_NAME); | ||
311 | backupFiles += " "; | ||
312 | count++; | ||
313 | } | ||
314 | else | ||
315 | { | ||
316 | count += getBackupFiles(backupFiles, currentItem); | ||
317 | } | ||
318 | } | ||
319 | currentItem = currentItem->nextSibling(); | ||
320 | } | ||
321 | return count; | ||
303 | } | 322 | } |
304 | 323 | ||
305 | void BackupAndRestore::sourceDirChanged(int selection){ | 324 | void BackupAndRestore::sourceDirChanged(int selection) |
306 | restoreList->clear(); | 325 | { |
307 | rescanFolder(backupLocations[restoreSource->text(selection)]); | 326 | restoreList->clear(); |
327 | rescanFolder(backupLocations[restoreSource->text(selection)]); | ||
308 | } | 328 | } |
@@ -311,5 +331,5 @@ void BackupAndRestore::fileListUpdate() | |||
311 | { | 331 | { |
312 | qWarning("void BackupAndRestore::fileListUpdate()"); | 332 | qWarning("void BackupAndRestore::fileListUpdate()"); |
313 | restoreList->clear(); | 333 | restoreList->clear(); |
314 | rescanFolder( backupLocations[restoreSource->currentText()] ); | 334 | rescanFolder( backupLocations[restoreSource->currentText()] ); |
315 | } | 335 | } |
@@ -321,26 +341,31 @@ void BackupAndRestore::fileListUpdate() | |||
321 | */ | 341 | */ |
322 | void BackupAndRestore::rescanFolder(QString directory){ | 342 | void BackupAndRestore::rescanFolder(QString directory) |
323 | //qDebug(QString("rescanFolder: ") + directory.latin1()); | 343 | { |
324 | QDir d(directory); | 344 | //qDebug(QString("rescanFolder: ") + directory.latin1()); |
325 | if(!d.exists()) | 345 | QDir d(directory); |
326 | return; | 346 | if(!d.exists()) |
327 | 347 | return; | |
328 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 348 | |
329 | const QFileInfoList *list = d.entryInfoList(); | 349 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
330 | QFileInfoListIterator it( *list ); | 350 | const QFileInfoList *list = d.entryInfoList(); |
331 | QFileInfo *file; | 351 | QFileInfoListIterator it( *list ); |
332 | while ( (file=it.current()) ) { // for each file... | 352 | QFileInfo *file; |
333 | // If it is a dir and not .. or . then add it as a tab and go down. | 353 | while ( (file=it.current()) ) |
334 | if(file->isDir()){ | 354 | { // for each file... |
335 | if(file->fileName() != ".." && file->fileName() != ".") { | 355 | // If it is a dir and not .. or . then add it as a tab and go down. |
336 | rescanFolder(directory + "/" + file->fileName()); | 356 | if(file->isDir()) |
337 | } | 357 | { |
338 | } | 358 | if(file->fileName() != ".." && file->fileName() != ".") |
339 | else{ | 359 | { |
340 | // If it is a backup file add to list. | 360 | rescanFolder(directory + "/" + file->fileName()); |
341 | if(file->fileName().contains(EXTENSION)) | 361 | } |
342 | (void)new QListViewItem(restoreList, file->fileName()); | 362 | } |
363 | else | ||
364 | { | ||
365 | // If it is a backup file add to list. | ||
366 | if(file->fileName().contains(EXTENSION)) | ||
367 | (void)new QListViewItem(restoreList, file->fileName()); | ||
368 | } | ||
369 | ++it; | ||
343 | } | 370 | } |
344 | ++it; | ||
345 | } | ||
346 | } | 371 | } |
@@ -351,54 +376,70 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
351 | */ | 376 | */ |
352 | void BackupAndRestore::restore(){ | 377 | void BackupAndRestore::restore() |
353 | QListViewItem *restoreItem = restoreList->currentItem(); | 378 | { |
354 | if(!restoreItem){ | 379 | QListViewItem *restoreItem = restoreList->currentItem(); |
355 | QMessageBox::critical(this, tr( "Message" ), | 380 | if(!restoreItem) |
356 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); | 381 | { |
357 | return; | 382 | QMessageBox::critical(this, tr( "Message" ), |
358 | } | 383 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); |
359 | setCaption(tr("Backup and Restore... working...")); | 384 | return; |
360 | 385 | } | |
361 | QString restoreFile = backupLocations[restoreSource->currentText()]; | 386 | setCaption(tr("Backup and Restore... working...")); |
362 | 387 | ||
363 | restoreFile += "/" + restoreItem->text(0); | 388 | QString restoreFile = backupLocations[restoreSource->currentText()]; |
364 | 389 | ||
365 | int r = system(QString("tar -C / -zxf %1 2> %3") | 390 | restoreFile += "/" + restoreItem->text(0); |
366 | .arg( restoreFile.latin1() ) | 391 | |
367 | .arg( tempFileName.latin1() ) ); | 392 | qDebug( restoreFile ); |
368 | if(r != 0){ | 393 | |
369 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 394 | QString commandLine = QString( "tar -C %1 -zxf %2 2> %3" ).arg( QDir::homeDirPath() ) |
370 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" | 395 | .arg( restoreFile.latin1() ) |
371 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { | 396 | .arg( tempFileName.latin1() ); |
372 | case 1: | 397 | |
373 | qWarning("Details pressed !"); | 398 | qDebug( commandLine ); |
374 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 399 | |
375 | QFile errorFile( tempFileName ); | 400 | int r = system( commandLine ); |
376 | if ( errorFile.open(IO_ReadOnly) ) { | 401 | |
377 | QTextStream t( &errorFile ); | 402 | if(r != 0) |
378 | QString s; | 403 | { |
379 | while ( !t.eof() ) { // until end of file... | 404 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
380 | s += t.readLine(); // line of text excluding '\n' | 405 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
381 | } | 406 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) |
382 | errorFile.close(); | 407 | { |
383 | 408 | case 1: | |
384 | pErrDialog->m_textarea->setText( s ); | 409 | qWarning("Details pressed !"); |
385 | }else{ | 410 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
386 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | 411 | QFile errorFile( tempFileName ); |
387 | } | 412 | if ( errorFile.open(IO_ReadOnly) ) |
388 | pErrDialog->showMaximized(); | 413 | { |
389 | pErrDialog->exec(); | 414 | QTextStream t( &errorFile ); |
390 | delete pErrDialog; | 415 | QString s; |
391 | 416 | while ( !t.eof() ) | |
392 | setCaption(tr("Backup and Restore.. Failed !!")); | 417 | { // until end of file... |
393 | return; | 418 | s += t.readLine(); // line of text excluding '\n' |
394 | 419 | } | |
395 | break; | 420 | errorFile.close(); |
396 | 421 | ||
422 | pErrDialog->m_textarea->setText( s ); | ||
423 | } | ||
424 | else | ||
425 | { | ||
426 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | ||
427 | } | ||
428 | pErrDialog->showMaximized(); | ||
429 | pErrDialog->exec(); | ||
430 | delete pErrDialog; | ||
431 | |||
432 | setCaption(tr("Backup and Restore.. Failed !!")); | ||
433 | return; | ||
434 | |||
435 | break; | ||
436 | |||
437 | } | ||
438 | } | ||
439 | else | ||
440 | { | ||
441 | QMessageBox::critical(this, tr( "Message" ), | ||
442 | tr( "Restore Successfull." ), QString( tr( "Ok") ) ); | ||
397 | } | 443 | } |
398 | } | 444 | setCaption(tr("Backup and Restore")); |
399 | else{ | ||
400 | QMessageBox::critical(this, tr( "Message" ), | ||
401 | tr( "Restore Successfull." ), QString( tr( "Ok") ) ); | ||
402 | } | ||
403 | setCaption(tr("Backup and Restore")); | ||
404 | } | 445 | } |
diff --git a/noncore/settings/backup/backuprestore.h b/noncore/settings/backup/backuprestore.h index 4bdc758..fdc2bf2 100644 --- a/noncore/settings/backup/backuprestore.h +++ b/noncore/settings/backup/backuprestore.h | |||
@@ -10,5 +10,6 @@ class QListViewItem; | |||
10 | 10 | ||
11 | class BackupAndRestore : public BackupAndRestoreBase { | 11 | class BackupAndRestore : public BackupAndRestoreBase |
12 | { | ||
12 | 13 | ||
13 | Q_OBJECT | 14 | Q_OBJECT |
14 | 15 | ||
@@ -16,24 +17,24 @@ public: | |||
16 | 17 | ||
17 | BackupAndRestore( QWidget* parent = 0, const char* name = 0, WFlags fl = 0); | 18 | BackupAndRestore( QWidget* parent = 0, const char* name = 0, WFlags fl = 0); |
18 | ~BackupAndRestore(); | 19 | ~BackupAndRestore(); |
19 | 20 | ||
20 | static QString appName() { return QString::fromLatin1("backup"); } | 21 | static QString appName() { return QString::fromLatin1("backup"); } |
21 | 22 | ||
22 | private slots: | 23 | private slots: |
23 | void backupPressed(); | 24 | void backup(); |
24 | void restore(); | 25 | void restore(); |
25 | void selectItem(QListViewItem *currentItem); | 26 | void selectItem(QListViewItem *currentItem); |
26 | void sourceDirChanged(int); | 27 | void sourceDirChanged(int); |
27 | void rescanFolder(QString directory); | 28 | void rescanFolder(QString directory); |
28 | void fileListUpdate(); | 29 | void fileListUpdate(); |
29 | 30 | ||
30 | private: | 31 | private: |
31 | void scanForApplicationSettings(); | 32 | void scanForApplicationSettings(); |
32 | int getBackupFiles(QString &backupFiles, QListViewItem *parent); | 33 | int getBackupFiles(QString &backupFiles, QListViewItem *parent); |
33 | QMap<QString, QString> backupLocations; | 34 | QMap<QString, QString> backupLocations; |
34 | QList<QListViewItem> getAllItems(QListViewItem *item, QList<QListViewItem> &list); | 35 | QList<QListViewItem> getAllItems(QListViewItem *item, QList<QListViewItem> &list); |
35 | 36 | ||
36 | QListViewItem *systemSettings; | 37 | QListViewItem *systemSettings; |
37 | QListViewItem *applicationSettings; | 38 | QListViewItem *applicationSettings; |
38 | QListViewItem *documents; | 39 | QListViewItem *documents; |
39 | 40 | ||
@@ -43,3 +44,3 @@ private: | |||
43 | 44 | ||
44 | // backuprestore.h | 45 | // backuprestore.h |
45 | 46 | ||