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