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