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