-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 203 | ||||
-rw-r--r-- | noncore/settings/backup/backuprestore.h | 5 |
2 files changed, 125 insertions, 83 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 | |||
@@ -39,12 +39,13 @@ const QString tempFileName = "/tmp/backup.err"; | |||
39 | 39 | ||
40 | 40 | ||
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 | { | ||
43 | this->showMaximized(); | 44 | this->showMaximized(); |
44 | backupList->header()->hide(); | 45 | backupList->header()->hide(); |
45 | restoreList->header()->hide(); | 46 | restoreList->header()->hide(); |
46 | connect(backupButton, SIGNAL(clicked()), | 47 | connect(backupButton, SIGNAL(clicked()), |
47 | this, SLOT(backupPressed())); | 48 | this, SLOT(backup())); |
48 | connect(restoreButton, SIGNAL(clicked()), | 49 | connect(restoreButton, SIGNAL(clicked()), |
49 | this, SLOT(restore())); | 50 | this, SLOT(restore())); |
50 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | 51 | connect(backupList, SIGNAL(clicked( QListViewItem * )), |
@@ -54,62 +55,55 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags f | |||
54 | connect(updateList, SIGNAL(clicked()), | 55 | connect(updateList, SIGNAL(clicked()), |
55 | this, SLOT( fileListUpdate())); | 56 | this, SLOT( fileListUpdate())); |
56 | 57 | ||
57 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", | 58 | //add directorys for backing up |
58 | QDir::homeDirPath() + "/Settings/"); | 59 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); |
59 | selectItem(applicationSettings); | 60 | selectItem(applicationSettings); |
60 | applicationSettings = new QListViewItem(backupList, "Application Data", "", | 61 | applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); |
61 | QDir::homeDirPath() + "/Applications/"); | ||
62 | selectItem(applicationSettings); | 62 | selectItem(applicationSettings); |
63 | documents= new QListViewItem(backupList, "Documents", "", | 63 | documents= new QListViewItem(backupList, "Documents", "", "Documents/"); |
64 | QDir::homeDirPath() + "/Documents/"); | ||
65 | selectItem(documents); | 64 | selectItem(documents); |
66 | 65 | ||
67 | scanForApplicationSettings(); | 66 | scanForApplicationSettings(); |
68 | 67 | ||
69 | Config config("BackupAndRestore"); | 68 | backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" ); |
70 | config.setGroup("General"); | 69 | if (StorageInfo::hasCf()) |
71 | int totalLocations = config.readNumEntry("totalLocations",0); | 70 | { |
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"); | 71 | backupLocations.insert("CF", "/mnt/cf"); |
80 | } | 72 | } |
81 | if (StorageInfo::hasSd || StorageInfo::hasMmc) { | 73 | if (StorageInfo::hasSd || StorageInfo::hasMmc) |
74 | { | ||
82 | backupLocations.insert("SD", "/mnt/card"); | 75 | backupLocations.insert("SD", "/mnt/card"); |
83 | } | 76 | } |
84 | } | 77 | |
85 | else{ | ||
86 | for(int i = 0; i < totalLocations; i++){ | ||
87 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), | ||
88 | config.readEntry(QString("backupLocation_%1").arg(i))); | ||
89 | } | ||
90 | } | ||
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 ) |
80 | { | ||
93 | storeToLocation->insertItem(it.key()); | 81 | storeToLocation->insertItem(it.key()); |
94 | restoreSource->insertItem(it.key()); | 82 | restoreSource->insertItem(it.key()); |
95 | } | 83 | } |
96 | 84 | ||
97 | // Read the list of items to ignore. | 85 | // Read the list of items to ignore. |
86 | Config config("BackupAndRestore"); | ||
87 | |||
98 | QList<QString> dontBackupList; | 88 | QList<QString> dontBackupList; |
99 | dontBackupList.setAutoDelete(true); | 89 | dontBackupList.setAutoDelete(true); |
100 | config.setGroup("DontBackup"); | 90 | config.setGroup("DontBackup"); |
101 | int total = config.readNumEntry("Total", 0); | 91 | int total = config.readNumEntry("Total", 0); |
102 | for(int i = 0; i < total; i++){ | 92 | for(int i = 0; i < total; i++) |
93 | { | ||
103 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | 94 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); |
104 | } | 95 | } |
105 | 96 | ||
106 | QList<QListViewItem> list; | 97 | QList<QListViewItem> list; |
107 | getAllItems(backupList->firstChild(), list); | 98 | getAllItems(backupList->firstChild(), list); |
108 | 99 | ||
109 | for(uint i = 0; i < list.count(); i++){ | 100 | for(uint i = 0; i < list.count(); i++) |
101 | { | ||
110 | QString text = list.at(i)->text(HEADER_NAME); | 102 | QString text = list.at(i)->text(HEADER_NAME); |
111 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ | 103 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++) |
112 | if(*dontBackupList.at(i2) == text){ | 104 | { |
105 | if(*dontBackupList.at(i2) == text) | ||
106 | { | ||
113 | selectItem(list.at(i)); | 107 | selectItem(list.at(i)); |
114 | break; | 108 | break; |
115 | } | 109 | } |
@@ -117,7 +111,8 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags f | |||
117 | } | 111 | } |
118 | } | 112 | } |
119 | 113 | ||
120 | BackupAndRestore::~BackupAndRestore(){ | 114 | BackupAndRestore::~BackupAndRestore() |
115 | { | ||
121 | QList<QListViewItem> list; | 116 | QList<QListViewItem> list; |
122 | getAllItems(backupList->firstChild(), list); | 117 | getAllItems(backupList->firstChild(), list); |
123 | 118 | ||
@@ -126,8 +121,10 @@ BackupAndRestore::~BackupAndRestore(){ | |||
126 | config.clearGroup(); | 121 | config.clearGroup(); |
127 | 122 | ||
128 | int count = 0; | 123 | int count = 0; |
129 | for(uint i = 0; i < list.count(); i++){ | 124 | for(uint i = 0; i < list.count(); i++) |
130 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 125 | { |
126 | if(list.at(i)->text(HEADER_BACKUP) == "") | ||
127 | { | ||
131 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 128 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
132 | count++; | 129 | count++; |
133 | } | 130 | } |
@@ -139,8 +136,10 @@ BackupAndRestore::~BackupAndRestore(){ | |||
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 | { |
141 | while(item) | ||
142 | { | ||
144 | if(item->childCount() > 0) | 143 | if(item->childCount() > 0) |
145 | getAllItems(item->firstChild(), list); | 144 | getAllItems(item->firstChild(), list); |
146 | list.append(item); | 145 | list.append(item); |
@@ -154,29 +153,35 @@ QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QL | |||
154 | * and changing the icon to match | 153 | * and changing the icon to match |
155 | * @param currentItem the item to swich the selection choice. | 154 | * @param currentItem the item to swich the selection choice. |
156 | */ | 155 | */ |
157 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ | 156 | void BackupAndRestore::selectItem(QListViewItem *currentItem) |
157 | { | ||
158 | if(!currentItem) | 158 | if(!currentItem) |
159 | return; | 159 | return; |
160 | 160 | ||
161 | if(currentItem->text(HEADER_BACKUP) == "B"){ | 161 | if(currentItem->text(HEADER_BACKUP) == "B") |
162 | { | ||
162 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); | 163 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); |
163 | currentItem->setText(HEADER_BACKUP, ""); | 164 | currentItem->setText(HEADER_BACKUP, ""); |
164 | } | 165 | } |
165 | else{ | 166 | else |
167 | { | ||
166 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); | 168 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); |
167 | currentItem->setText(HEADER_BACKUP, "B"); | 169 | currentItem->setText(HEADER_BACKUP, "B"); |
168 | } | 170 | } |
169 | } | 171 | } |
170 | 172 | ||
171 | void BackupAndRestore::scanForApplicationSettings(){ | 173 | void BackupAndRestore::scanForApplicationSettings() |
172 | QDir d(applicationSettings->text(BACKUP_LOCATION)); | 174 | { |
175 | QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); | ||
173 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); | 176 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); |
174 | const QFileInfoList *list = d.entryInfoList(); | 177 | const QFileInfoList *list = d.entryInfoList(); |
175 | QFileInfoListIterator it( *list ); | 178 | QFileInfoListIterator it( *list ); |
176 | QFileInfo *fi; | 179 | QFileInfo *fi; |
177 | while ( (fi=it.current()) ) { | 180 | while ( (fi=it.current()) ) |
178 | // qDebug((d.path()+fi->fileName()).latin1()); | 181 | { |
179 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) { | 182 | //qDebug((d.path()+"/"+fi->fileName()).latin1()); |
183 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) | ||
184 | { | ||
180 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 185 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
181 | selectItem(newItem); | 186 | selectItem(newItem); |
182 | } | 187 | } |
@@ -190,9 +195,11 @@ void BackupAndRestore::scanForApplicationSettings(){ | |||
190 | * Determine the file name to store the backup in. Backup the file(s) using | 195 | * Determine the file name to store the backup in. Backup the file(s) using |
191 | * tar and gzip --best. Report failure or success | 196 | * tar and gzip --best. Report failure or success |
192 | */ | 197 | */ |
193 | void BackupAndRestore::backupPressed(){ | 198 | void BackupAndRestore::backup() |
199 | { | ||
194 | QString backupFiles; | 200 | QString backupFiles; |
195 | if(getBackupFiles(backupFiles, NULL) == 0){ | 201 | if(getBackupFiles(backupFiles, NULL) == 0) |
202 | { | ||
196 | QMessageBox::critical(this, "Message", | 203 | QMessageBox::critical(this, "Message", |
197 | "No items selected.",QString("Ok") ); | 204 | "No items selected.",QString("Ok") ); |
198 | return; | 205 | return; |
@@ -209,7 +216,8 @@ void BackupAndRestore::backupPressed(){ | |||
209 | 216 | ||
210 | QString t = outputFile; | 217 | QString t = outputFile; |
211 | int c = 1; | 218 | int c = 1; |
212 | while(QFile::exists(outputFile + EXTENSION)){ | 219 | while(QFile::exists(outputFile + EXTENSION)) |
220 | { | ||
213 | outputFile = t + QString("%1").arg(c); | 221 | outputFile = t + QString("%1").arg(c); |
214 | c++; | 222 | c++; |
215 | } | 223 | } |
@@ -220,38 +228,42 @@ void BackupAndRestore::backupPressed(){ | |||
220 | qDebug( "Storing file: %s", outputFile.latin1() ); | 228 | qDebug( "Storing file: %s", outputFile.latin1() ); |
221 | outputFile += EXTENSION; | 229 | outputFile += EXTENSION; |
222 | 230 | ||
223 | qWarning( QString("(tar -c %1 | gzip > %2 ) 2> %3") | 231 | QString commandLine = QString( "(tar -C %1 -c %2 | gzip > %3 ) 2> %4" ).arg( QDir::homeDirPath() ) |
224 | .arg( backupFiles ) | 232 | .arg( backupFiles ) |
225 | .arg( outputFile.latin1() ) | 233 | .arg( outputFile.latin1() ) |
226 | .arg( tempFileName.latin1() ) ); | 234 | .arg( tempFileName.latin1() ); |
227 | 235 | ||
236 | qDebug( commandLine ); | ||
228 | 237 | ||
229 | int r = system( QString("(tar -c %1 | gzip > %2 ) 2> %3") | 238 | int r = system( commandLine ); |
230 | .arg( backupFiles ) | ||
231 | .arg( outputFile.latin1() ) | ||
232 | .arg( tempFileName.latin1() ) ); | ||
233 | 239 | ||
234 | if(r != 0){ | 240 | if(r != 0) |
241 | { | ||
235 | perror("Error: "); | 242 | perror("Error: "); |
236 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 243 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
237 | 244 | ||
238 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | 245 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" |
239 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ | 246 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) |
247 | { | ||
240 | 248 | ||
241 | case 1: | 249 | case 1: |
242 | qWarning("Details pressed !"); | 250 | qWarning("Details pressed !"); |
243 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 251 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
244 | QFile errorFile( tempFileName ); | 252 | QFile errorFile( tempFileName ); |
245 | if ( errorFile.open(IO_ReadOnly) ) { | 253 | if ( errorFile.open(IO_ReadOnly) ) |
254 | { | ||
246 | QTextStream t( &errorFile ); | 255 | QTextStream t( &errorFile ); |
247 | QString s; | 256 | QString s; |
248 | while ( !t.eof() ) { // until end of file... | 257 | while ( !t.eof() ) |
258 | { // until end of file... | ||
249 | s += t.readLine(); // line of text excluding '\n' | 259 | s += t.readLine(); // line of text excluding '\n' |
250 | } | 260 | } |
251 | errorFile.close(); | 261 | errorFile.close(); |
252 | 262 | ||
253 | pErrDialog->m_textarea->setText( s ); | 263 | pErrDialog->m_textarea->setText( s ); |
254 | }else{ | 264 | } |
265 | else | ||
266 | { | ||
255 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); | 267 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); |
256 | } | 268 | } |
257 | pErrDialog->showMaximized(); | 269 | pErrDialog->showMaximized(); |
@@ -262,7 +274,8 @@ void BackupAndRestore::backupPressed(){ | |||
262 | setCaption(tr("Backup and Restore.. Failed !!")); | 274 | setCaption(tr("Backup and Restore.. Failed !!")); |
263 | return; | 275 | return; |
264 | } | 276 | } |
265 | else{ | 277 | else |
278 | { | ||
266 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); | 279 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); |
267 | 280 | ||
268 | } | 281 | } |
@@ -272,20 +285,25 @@ void BackupAndRestore::backupPressed(){ | |||
272 | /*** | 285 | /*** |
273 | * Get a list of all of the files to backup. | 286 | * Get a list of all of the files to backup. |
274 | */ | 287 | */ |
275 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ | 288 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) |
289 | { | ||
276 | QListViewItem * currentItem; | 290 | QListViewItem * currentItem; |
277 | QString currentHome; | 291 | QString currentHome; |
278 | if(!parent) | 292 | if(!parent) |
279 | currentItem = backupList->firstChild(); | 293 | currentItem = backupList->firstChild(); |
280 | else{ | 294 | else |
295 | { | ||
281 | currentItem = parent->firstChild(); | 296 | currentItem = parent->firstChild(); |
282 | currentHome = parent->text(BACKUP_LOCATION); | 297 | currentHome = parent->text(BACKUP_LOCATION); |
283 | } | 298 | } |
284 | 299 | ||
285 | uint count = 0; | 300 | uint count = 0; |
286 | while( currentItem != 0 ){ | 301 | while( currentItem != 0 ) |
287 | if(currentItem->text(HEADER_BACKUP) == "B" ){ | 302 | { |
288 | if(currentItem->childCount() == 0 ){ | 303 | if(currentItem->text(HEADER_BACKUP) == "B" ) |
304 | { | ||
305 | if(currentItem->childCount() == 0 ) | ||
306 | { | ||
289 | if(parent == NULL) | 307 | if(parent == NULL) |
290 | backupFiles += currentItem->text(BACKUP_LOCATION); | 308 | backupFiles += currentItem->text(BACKUP_LOCATION); |
291 | else | 309 | else |
@@ -293,7 +311,8 @@ int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent | |||
293 | backupFiles += " "; | 311 | backupFiles += " "; |
294 | count++; | 312 | count++; |
295 | } | 313 | } |
296 | else{ | 314 | else |
315 | { | ||
297 | count += getBackupFiles(backupFiles, currentItem); | 316 | count += getBackupFiles(backupFiles, currentItem); |
298 | } | 317 | } |
299 | } | 318 | } |
@@ -302,7 +321,8 @@ int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent | |||
302 | return count; | 321 | return count; |
303 | } | 322 | } |
304 | 323 | ||
305 | void BackupAndRestore::sourceDirChanged(int selection){ | 324 | void BackupAndRestore::sourceDirChanged(int selection) |
325 | { | ||
306 | restoreList->clear(); | 326 | restoreList->clear(); |
307 | rescanFolder(backupLocations[restoreSource->text(selection)]); | 327 | rescanFolder(backupLocations[restoreSource->text(selection)]); |
308 | } | 328 | } |
@@ -319,7 +339,8 @@ void BackupAndRestore::fileListUpdate() | |||
319 | * but will not follow symlinks. | 339 | * but will not follow symlinks. |
320 | * @param directory - the directory to look in. | 340 | * @param directory - the directory to look in. |
321 | */ | 341 | */ |
322 | void BackupAndRestore::rescanFolder(QString directory){ | 342 | void BackupAndRestore::rescanFolder(QString directory) |
343 | { | ||
323 | //qDebug(QString("rescanFolder: ") + directory.latin1()); | 344 | //qDebug(QString("rescanFolder: ") + directory.latin1()); |
324 | QDir d(directory); | 345 | QDir d(directory); |
325 | if(!d.exists()) | 346 | if(!d.exists()) |
@@ -329,14 +350,18 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
329 | const QFileInfoList *list = d.entryInfoList(); | 350 | const QFileInfoList *list = d.entryInfoList(); |
330 | QFileInfoListIterator it( *list ); | 351 | QFileInfoListIterator it( *list ); |
331 | QFileInfo *file; | 352 | QFileInfo *file; |
332 | while ( (file=it.current()) ) { // for each file... | 353 | while ( (file=it.current()) ) |
354 | { // for each file... | ||
333 | // If it is a dir and not .. or . then add it as a tab and go down. | 355 | // If it is a dir and not .. or . then add it as a tab and go down. |
334 | if(file->isDir()){ | 356 | if(file->isDir()) |
335 | if(file->fileName() != ".." && file->fileName() != ".") { | 357 | { |
358 | if(file->fileName() != ".." && file->fileName() != ".") | ||
359 | { | ||
336 | rescanFolder(directory + "/" + file->fileName()); | 360 | rescanFolder(directory + "/" + file->fileName()); |
337 | } | 361 | } |
338 | } | 362 | } |
339 | else{ | 363 | else |
364 | { | ||
340 | // If it is a backup file add to list. | 365 | // If it is a backup file add to list. |
341 | if(file->fileName().contains(EXTENSION)) | 366 | if(file->fileName().contains(EXTENSION)) |
342 | (void)new QListViewItem(restoreList, file->fileName()); | 367 | (void)new QListViewItem(restoreList, file->fileName()); |
@@ -349,9 +374,11 @@ void BackupAndRestore::rescanFolder(QString directory){ | |||
349 | * Restore a backup file. | 374 | * Restore a backup file. |
350 | * Report errors or success | 375 | * Report errors or success |
351 | */ | 376 | */ |
352 | void BackupAndRestore::restore(){ | 377 | void BackupAndRestore::restore() |
378 | { | ||
353 | QListViewItem *restoreItem = restoreList->currentItem(); | 379 | QListViewItem *restoreItem = restoreList->currentItem(); |
354 | if(!restoreItem){ | 380 | if(!restoreItem) |
381 | { | ||
355 | QMessageBox::critical(this, tr( "Message" ), | 382 | QMessageBox::critical(this, tr( "Message" ), |
356 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); | 383 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); |
357 | return; | 384 | return; |
@@ -362,27 +389,40 @@ void BackupAndRestore::restore(){ | |||
362 | 389 | ||
363 | restoreFile += "/" + restoreItem->text(0); | 390 | restoreFile += "/" + restoreItem->text(0); |
364 | 391 | ||
365 | int r = system(QString("tar -C / -zxf %1 2> %3") | 392 | qDebug( restoreFile ); |
393 | |||
394 | QString commandLine = QString( "tar -C %1 -zxf %2 2> %3" ).arg( QDir::homeDirPath() ) | ||
366 | .arg( restoreFile.latin1() ) | 395 | .arg( restoreFile.latin1() ) |
367 | .arg( tempFileName.latin1() ) ); | 396 | .arg( tempFileName.latin1() ); |
368 | if(r != 0){ | 397 | |
398 | qDebug( commandLine ); | ||
399 | |||
400 | int r = system( commandLine ); | ||
401 | |||
402 | if(r != 0) | ||
403 | { | ||
369 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 404 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
370 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" | 405 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
371 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { | 406 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) |
407 | { | ||
372 | case 1: | 408 | case 1: |
373 | qWarning("Details pressed !"); | 409 | qWarning("Details pressed !"); |
374 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 410 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
375 | QFile errorFile( tempFileName ); | 411 | QFile errorFile( tempFileName ); |
376 | if ( errorFile.open(IO_ReadOnly) ) { | 412 | if ( errorFile.open(IO_ReadOnly) ) |
413 | { | ||
377 | QTextStream t( &errorFile ); | 414 | QTextStream t( &errorFile ); |
378 | QString s; | 415 | QString s; |
379 | while ( !t.eof() ) { // until end of file... | 416 | while ( !t.eof() ) |
417 | { // until end of file... | ||
380 | s += t.readLine(); // line of text excluding '\n' | 418 | s += t.readLine(); // line of text excluding '\n' |
381 | } | 419 | } |
382 | errorFile.close(); | 420 | errorFile.close(); |
383 | 421 | ||
384 | pErrDialog->m_textarea->setText( s ); | 422 | pErrDialog->m_textarea->setText( s ); |
385 | }else{ | 423 | } |
424 | else | ||
425 | { | ||
386 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | 426 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); |
387 | } | 427 | } |
388 | pErrDialog->showMaximized(); | 428 | pErrDialog->showMaximized(); |
@@ -396,7 +436,8 @@ void BackupAndRestore::restore(){ | |||
396 | 436 | ||
397 | } | 437 | } |
398 | } | 438 | } |
399 | else{ | 439 | else |
440 | { | ||
400 | QMessageBox::critical(this, tr( "Message" ), | 441 | QMessageBox::critical(this, tr( "Message" ), |
401 | tr( "Restore Successfull." ), QString( tr( "Ok") ) ); | 442 | tr( "Restore Successfull." ), QString( tr( "Ok") ) ); |
402 | } | 443 | } |
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 | |||
@@ -8,7 +8,8 @@ | |||
8 | 8 | ||
9 | class QListViewItem; | 9 | 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 | ||
@@ -20,7 +21,7 @@ public: | |||
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); |