Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 922523b..1c854d9 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -36,23 +36,23 @@ | |||
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, WFlags fl) |
41 | : BackupAndRestoreBase(parent, name){ | 41 | : BackupAndRestoreBase(parent, name, fl){ |
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); |
@@ -61,15 +61,15 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
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 | backupLocations.insert("Documents", "/root/Documents"); | 74 | backupLocations.insert("Documents", "/root/Documents"); |
75 | backupLocations.insert("CF", "/mnt/cf"); | 75 | backupLocations.insert("CF", "/mnt/cf"); |
@@ -85,10 +85,10 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
85 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ | 85 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ |
86 | storeToLocation->insertItem(it.key()); | 86 | storeToLocation->insertItem(it.key()); |
87 | restoreSource->insertItem(it.key()); | 87 | restoreSource->insertItem(it.key()); |
88 | } | 88 | } |
89 | 89 | ||
90 | // Read the list of items to ignore. | 90 | // Read the list of items to ignore. |
91 | QList<QString> dontBackupList; | 91 | QList<QString> dontBackupList; |
92 | dontBackupList.setAutoDelete(true); | 92 | dontBackupList.setAutoDelete(true); |
93 | config.setGroup("DontBackup"); | 93 | config.setGroup("DontBackup"); |
94 | int total = config.readNumEntry("Total", 0); | 94 | int total = config.readNumEntry("Total", 0); |
@@ -97,9 +97,9 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
97 | } | 97 | } |
98 | 98 | ||
99 | QList<QListViewItem> list; | 99 | QList<QListViewItem> list; |
100 | getAllItems(backupList->firstChild(), list); | 100 | getAllItems(backupList->firstChild(), list); |
101 | 101 | ||
102 | for(uint i = 0; i < list.count(); i++){ | 102 | for(uint i = 0; i < list.count(); i++){ |
103 | QString text = list.at(i)->text(HEADER_NAME); | 103 | QString text = list.at(i)->text(HEADER_NAME); |
104 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ | 104 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ |
105 | if(*dontBackupList.at(i2) == text){ | 105 | if(*dontBackupList.at(i2) == text){ |
@@ -112,13 +112,13 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | |||
112 | 112 | ||
113 | BackupAndRestore::~BackupAndRestore(){ | 113 | BackupAndRestore::~BackupAndRestore(){ |
114 | QList<QListViewItem> list; | 114 | QList<QListViewItem> list; |
115 | getAllItems(backupList->firstChild(), list); | 115 | getAllItems(backupList->firstChild(), list); |
116 | 116 | ||
117 | Config config("BackupAndRestore"); | 117 | Config config("BackupAndRestore"); |
118 | config.setGroup("DontBackup"); | 118 | config.setGroup("DontBackup"); |
119 | config.clearGroup(); | 119 | config.clearGroup(); |
120 | 120 | ||
121 | int count = 0; | 121 | int count = 0; |
122 | for(uint i = 0; i < list.count(); i++){ | 122 | for(uint i = 0; i < list.count(); i++){ |
123 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 123 | if(list.at(i)->text(HEADER_BACKUP) == ""){ |
124 | 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,9 +134,9 @@ BackupAndRestore::~BackupAndRestore(){ | |||
134 | 134 | ||
135 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ | 135 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ |
136 | while(item){ | 136 | while(item){ |
137 | if(item->childCount() > 0) | 137 | if(item->childCount() > 0) |
138 | getAllItems(item->firstChild(), list); | 138 | getAllItems(item->firstChild(), list); |
139 | list.append(item); | 139 | list.append(item); |
140 | item = item->nextSibling(); | 140 | item = item->nextSibling(); |
141 | } | 141 | } |
142 | return list; | 142 | return list; |
@@ -178,37 +178,37 @@ void BackupAndRestore::scanForApplicationSettings(){ | |||
178 | } | 178 | } |
179 | 179 | ||
180 | /** | 180 | /** |
181 | * The "Backup" button has been pressed. Get a list of all of the files that | 181 | * The "Backup" button has been pressed. Get a list of all of the files that |
182 | * should be backed up. If there are no files, emit and error and exit. | 182 | * should be backed up. If there are no files, emit and error and exit. |
183 | * Determine the file name to store the backup in. Backup the file(s) using | 183 | * Determine the file name to store the backup in. Backup the file(s) using |
184 | * tar and gzip --best. Report failure or success | 184 | * tar and gzip --best. Report failure or success |
185 | */ | 185 | */ |
186 | void BackupAndRestore::backupPressed(){ | 186 | void BackupAndRestore::backupPressed(){ |
187 | QString backupFiles; | 187 | QString backupFiles; |
188 | if(getBackupFiles(backupFiles, NULL) == 0){ | 188 | if(getBackupFiles(backupFiles, NULL) == 0){ |
189 | QMessageBox::critical(this, "Message", | 189 | QMessageBox::critical(this, "Message", |
190 | "No items selected.",QString("Ok") ); | 190 | "No items selected.",QString("Ok") ); |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | 193 | ||
194 | setCaption(tr("Backup and Restore... working...")); | 194 | setCaption(tr("Backup and Restore... working...")); |
195 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 195 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
196 | 196 | ||
197 | QDateTime datetime = QDateTime::currentDateTime(); | 197 | QDateTime datetime = QDateTime::currentDateTime(); |
198 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 198 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
199 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 199 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
200 | 200 | ||
201 | outputFile += "/" + dateString; | 201 | outputFile += "/" + dateString; |
202 | 202 | ||
203 | QString t = outputFile; | 203 | QString t = outputFile; |
204 | int c = 1; | 204 | int c = 1; |
205 | while(QFile::exists(outputFile + EXTENSION)){ | 205 | while(QFile::exists(outputFile + EXTENSION)){ |
206 | outputFile = t + QString("%1").arg(c); | 206 | outputFile = t + QString("%1").arg(c); |
207 | c++; | 207 | c++; |
208 | } | 208 | } |
209 | 209 | ||
210 | // We execute tar and compressing its output with gzip.. | 210 | // We execute tar and compressing its output with gzip.. |
211 | // The error output will be written into a temp-file which could be provided | 211 | // The error output will be written into a temp-file which could be provided |
212 | // for debugging.. | 212 | // for debugging.. |
213 | qDebug( "Storing file: %s", outputFile.latin1() ); | 213 | qDebug( "Storing file: %s", outputFile.latin1() ); |
214 | outputFile += EXTENSION; | 214 | outputFile += EXTENSION; |
@@ -227,9 +227,9 @@ void BackupAndRestore::backupPressed(){ | |||
227 | if(r != 0){ | 227 | if(r != 0){ |
228 | perror("Error: "); | 228 | perror("Error: "); |
229 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 229 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
230 | 230 | ||
231 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | 231 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" |
232 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ | 232 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ |
233 | 233 | ||
234 | case 1: | 234 | case 1: |
235 | qWarning("Details pressed !"); | 235 | qWarning("Details pressed !"); |
@@ -241,9 +241,9 @@ void BackupAndRestore::backupPressed(){ | |||
241 | while ( !t.eof() ) { // until end of file... | 241 | while ( !t.eof() ) { // until end of file... |
242 | s += t.readLine(); // line of text excluding '\n' | 242 | s += t.readLine(); // line of text excluding '\n' |
243 | } | 243 | } |
244 | errorFile.close(); | 244 | errorFile.close(); |
245 | 245 | ||
246 | pErrDialog->m_textarea->setText( s ); | 246 | pErrDialog->m_textarea->setText( s ); |
247 | }else{ | 247 | }else{ |
248 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); | 248 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); |
249 | } | 249 | } |
@@ -252,20 +252,20 @@ void BackupAndRestore::backupPressed(){ | |||
252 | delete pErrDialog; | 252 | delete pErrDialog; |
253 | break; | 253 | break; |
254 | } | 254 | } |
255 | setCaption(tr("Backup and Restore.. Failed !!")); | 255 | setCaption(tr("Backup and Restore.. Failed !!")); |
256 | return; | 256 | return; |
257 | } | 257 | } |
258 | else{ | 258 | else{ |
259 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); | 259 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); |
260 | 260 | ||
261 | } | 261 | } |
262 | setCaption(tr("Backup and Restore")); | 262 | setCaption(tr("Backup and Restore")); |
263 | } | 263 | } |
264 | 264 | ||
265 | /*** | 265 | /*** |
266 | * Get a list of all of the files to backup. | 266 | * Get a list of all of the files to backup. |
267 | */ | 267 | */ |
268 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ | 268 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ |
269 | QListViewItem * currentItem; | 269 | QListViewItem * currentItem; |
270 | QString currentHome; | 270 | QString currentHome; |
271 | if(!parent) | 271 | if(!parent) |
@@ -273,9 +273,9 @@ int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent | |||
273 | else{ | 273 | else{ |
274 | currentItem = parent->firstChild(); | 274 | currentItem = parent->firstChild(); |
275 | currentHome = parent->text(BACKUP_LOCATION); | 275 | currentHome = parent->text(BACKUP_LOCATION); |
276 | } | 276 | } |
277 | 277 | ||
278 | uint count = 0; | 278 | uint count = 0; |
279 | while( currentItem != 0 ){ | 279 | while( currentItem != 0 ){ |
280 | if(currentItem->text(HEADER_BACKUP) == "B" ){ | 280 | if(currentItem->text(HEADER_BACKUP) == "B" ){ |
281 | if(currentItem->childCount() == 0 ){ | 281 | if(currentItem->childCount() == 0 ){ |
@@ -316,9 +316,9 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
316 | //qDebug(QString("rescanFolder: ") + directory.latin1()); | 316 | //qDebug(QString("rescanFolder: ") + directory.latin1()); |
317 | QDir d(directory); | 317 | QDir d(directory); |
318 | if(!d.exists()) | 318 | if(!d.exists()) |
319 | return; | 319 | return; |
320 | 320 | ||
321 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 321 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
322 | const QFileInfoList *list = d.entryInfoList(); | 322 | const QFileInfoList *list = d.entryInfoList(); |
323 | QFileInfoListIterator it( *list ); | 323 | QFileInfoListIterator it( *list ); |
324 | QFileInfo *file; | 324 | QFileInfo *file; |
@@ -340,28 +340,28 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
340 | 340 | ||
341 | /** | 341 | /** |
342 | * Restore a backup file. | 342 | * Restore a backup file. |
343 | * Report errors or success | 343 | * Report errors or success |
344 | */ | 344 | */ |
345 | void BackupAndRestore::restore(){ | 345 | void BackupAndRestore::restore(){ |
346 | QListViewItem *restoreItem = restoreList->currentItem(); | 346 | QListViewItem *restoreItem = restoreList->currentItem(); |
347 | if(!restoreItem){ | 347 | if(!restoreItem){ |
348 | QMessageBox::critical(this, tr( "Message" ), | 348 | QMessageBox::critical(this, tr( "Message" ), |
349 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); | 349 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); |
350 | return; | 350 | return; |
351 | } | 351 | } |
352 | setCaption(tr("Backup and Restore... working...")); | 352 | setCaption(tr("Backup and Restore... working...")); |
353 | 353 | ||
354 | QString restoreFile = backupLocations[restoreSource->currentText()]; | 354 | QString restoreFile = backupLocations[restoreSource->currentText()]; |
355 | 355 | ||
356 | restoreFile += "/" + restoreItem->text(0); | 356 | restoreFile += "/" + restoreItem->text(0); |
357 | 357 | ||
358 | int r = system(QString("tar -C / -zxf %1 2> %3") | 358 | int r = system(QString("tar -C / -zxf %1 2> %3") |
359 | .arg( restoreFile.latin1() ) | 359 | .arg( restoreFile.latin1() ) |
360 | .arg( tempFileName.latin1() ) ); | 360 | .arg( tempFileName.latin1() ) ); |
361 | if(r != 0){ | 361 | if(r != 0){ |
362 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 362 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
363 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" | 363 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
364 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { | 364 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { |
365 | case 1: | 365 | case 1: |
366 | qWarning("Details pressed !"); | 366 | qWarning("Details pressed !"); |
367 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 367 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
@@ -372,9 +372,9 @@ void BackupAndRestore::restore(){ | |||
372 | while ( !t.eof() ) { // until end of file... | 372 | while ( !t.eof() ) { // until end of file... |
373 | s += t.readLine(); // line of text excluding '\n' | 373 | s += t.readLine(); // line of text excluding '\n' |
374 | } | 374 | } |
375 | errorFile.close(); | 375 | errorFile.close(); |
376 | 376 | ||
377 | pErrDialog->m_textarea->setText( s ); | 377 | pErrDialog->m_textarea->setText( s ); |
378 | }else{ | 378 | }else{ |
379 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | 379 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); |
380 | } | 380 | } |
@@ -382,9 +382,9 @@ void BackupAndRestore::restore(){ | |||
382 | pErrDialog->exec(); | 382 | pErrDialog->exec(); |
383 | delete pErrDialog; | 383 | delete pErrDialog; |
384 | 384 | ||
385 | setCaption(tr("Backup and Restore.. Failed !!")); | 385 | setCaption(tr("Backup and Restore.. Failed !!")); |
386 | return; | 386 | return; |
387 | 387 | ||
388 | break; | 388 | break; |
389 | 389 | ||
390 | } | 390 | } |