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