summaryrefslogtreecommitdiff
path: root/noncore/settings/backup/backuprestore.cpp
Unidiff
Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 922523b..1c854d9 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -34,44 +34,44 @@
34 34
35#define EXTENSION ".bck" 35#define EXTENSION ".bck"
36 36
37const QString tempFileName = "/tmp/backup.err"; 37const QString tempFileName = "/tmp/backup.err";
38 38
39 39
40BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) 40BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl)
41 : BackupAndRestoreBase(parent, name){ 41 : BackupAndRestoreBase(parent, name, fl){
42 this->showMaximized(); 42 this->showMaximized();
43 backupList->header()->hide(); 43 backupList->header()->hide();
44 restoreList->header()->hide(); 44 restoreList->header()->hide();
45 connect(backupButton, SIGNAL(clicked()), 45 connect(backupButton, SIGNAL(clicked()),
46 this, SLOT(backupPressed())); 46 this, SLOT(backupPressed()));
47 connect(restoreButton, SIGNAL(clicked()), 47 connect(restoreButton, SIGNAL(clicked()),
48 this, SLOT(restore())); 48 this, SLOT(restore()));
49 connect(backupList, SIGNAL(clicked( QListViewItem * )), 49 connect(backupList, SIGNAL(clicked( QListViewItem * )),
50 this, SLOT(selectItem(QListViewItem*))); 50 this, SLOT(selectItem(QListViewItem*)));
51 connect(restoreSource, SIGNAL(activated( int )), 51 connect(restoreSource, SIGNAL(activated( int )),
52 this, SLOT(sourceDirChanged(int))); 52 this, SLOT(sourceDirChanged(int)));
53 connect(updateList, SIGNAL(clicked()), 53 connect(updateList, SIGNAL(clicked()),
54 this, SLOT( fileListUpdate())); 54 this, SLOT( fileListUpdate()));
55 55
56 applicationSettings = new QListViewItem(backupList, "Application Settings", "", 56 applicationSettings = new QListViewItem(backupList, "Application Settings", "",
57 QDir::homeDirPath() + "/Settings/"); 57 QDir::homeDirPath() + "/Settings/");
58 selectItem(applicationSettings); 58 selectItem(applicationSettings);
59 applicationSettings = new QListViewItem(backupList, "Application Data", "", 59 applicationSettings = new QListViewItem(backupList, "Application Data", "",
60 QDir::homeDirPath() + "/Applications/"); 60 QDir::homeDirPath() + "/Applications/");
61 selectItem(applicationSettings); 61 selectItem(applicationSettings);
62 documents= new QListViewItem(backupList, "Documents", "", 62 documents= new QListViewItem(backupList, "Documents", "",
63 QDir::homeDirPath() + "/Documents/"); 63 QDir::homeDirPath() + "/Documents/");
64 selectItem(documents); 64 selectItem(documents);
65 65
66 scanForApplicationSettings(); 66 scanForApplicationSettings();
67 67
68 Config config("BackupAndRestore"); 68 Config config("BackupAndRestore");
69 config.setGroup("General"); 69 config.setGroup("General");
70 int totalLocations = config.readNumEntry("totalLocations",0); 70 int totalLocations = config.readNumEntry("totalLocations",0);
71 71
72//todo make less static here and use Storage class to get infos 72//todo make less static here and use Storage class to get infos
73 if(totalLocations == 0){ 73 if(totalLocations == 0){
74 backupLocations.insert("Documents", "/root/Documents"); 74 backupLocations.insert("Documents", "/root/Documents");
75 backupLocations.insert("CF", "/mnt/cf"); 75 backupLocations.insert("CF", "/mnt/cf");
76 backupLocations.insert("SD", "/mnt/card"); 76 backupLocations.insert("SD", "/mnt/card");
77 } 77 }
@@ -83,25 +83,25 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name)
83 } 83 }
84 QMap<QString, QString>::Iterator it; 84 QMap<QString, QString>::Iterator it;
85 for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ 85 for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){
86 storeToLocation->insertItem(it.key()); 86 storeToLocation->insertItem(it.key());
87 restoreSource->insertItem(it.key()); 87 restoreSource->insertItem(it.key());
88 } 88 }
89 89
90 // Read the list of items to ignore. 90 // Read the list of items to ignore.
91 QList<QString> dontBackupList; 91 QList<QString> dontBackupList;
92 dontBackupList.setAutoDelete(true); 92 dontBackupList.setAutoDelete(true);
93 config.setGroup("DontBackup"); 93 config.setGroup("DontBackup");
94 int total = config.readNumEntry("Total", 0); 94 int total = config.readNumEntry("Total", 0);
95 for(int i = 0; i < total; i++){ 95 for(int i = 0; i < total; i++){
96 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); 96 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), "")));
97 } 97 }
98 98
99 QList<QListViewItem> list; 99 QList<QListViewItem> list;
100 getAllItems(backupList->firstChild(), list); 100 getAllItems(backupList->firstChild(), list);
101 101
102 for(uint i = 0; i < list.count(); i++){ 102 for(uint i = 0; i < list.count(); i++){
103 QString text = list.at(i)->text(HEADER_NAME); 103 QString text = list.at(i)->text(HEADER_NAME);
104 for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ 104 for(uint i2 = 0; i2 < dontBackupList.count(); i2++){
105 if(*dontBackupList.at(i2) == text){ 105 if(*dontBackupList.at(i2) == text){
106 selectItem(list.at(i)); 106 selectItem(list.at(i));
107 break; 107 break;
@@ -110,17 +110,17 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name)
110 } 110 }
111} 111}
112 112
113BackupAndRestore::~BackupAndRestore(){ 113BackupAndRestore::~BackupAndRestore(){
114 QList<QListViewItem> list; 114 QList<QListViewItem> list;
115 getAllItems(backupList->firstChild(), list); 115 getAllItems(backupList->firstChild(), list);
116 116
117 Config config("BackupAndRestore"); 117 Config config("BackupAndRestore");
118 config.setGroup("DontBackup"); 118 config.setGroup("DontBackup");
119 config.clearGroup(); 119 config.clearGroup();
120 120
121 int count = 0; 121 int count = 0;
122 for(uint i = 0; i < list.count(); i++){ 122 for(uint i = 0; i < list.count(); i++){
123 if(list.at(i)->text(HEADER_BACKUP) == ""){ 123 if(list.at(i)->text(HEADER_BACKUP) == ""){
124 config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); 124 config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME));
125 count++; 125 count++;
126 } 126 }
@@ -132,13 +132,13 @@ BackupAndRestore::~BackupAndRestore(){
132 QFile::remove( tempFileName ); 132 QFile::remove( tempFileName );
133} 133}
134 134
135QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ 135QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){
136 while(item){ 136 while(item){
137 if(item->childCount() > 0) 137 if(item->childCount() > 0)
138 getAllItems(item->firstChild(), list); 138 getAllItems(item->firstChild(), list);
139 list.append(item); 139 list.append(item);
140 item = item->nextSibling(); 140 item = item->nextSibling();
141 } 141 }
142 return list; 142 return list;
143} 143}
144 144
@@ -176,41 +176,41 @@ void BackupAndRestore::scanForApplicationSettings(){
176 ++it; 176 ++it;
177 } 177 }
178} 178}
179 179
180/** 180/**
181 * The "Backup" button has been pressed. Get a list of all of the files that 181 * 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. 182 * 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 183 * Determine the file name to store the backup in. Backup the file(s) using
184 * tar and gzip --best. Report failure or success 184 * tar and gzip --best. Report failure or success
185 */ 185 */
186void BackupAndRestore::backupPressed(){ 186void BackupAndRestore::backupPressed(){
187 QString backupFiles; 187 QString backupFiles;
188 if(getBackupFiles(backupFiles, NULL) == 0){ 188 if(getBackupFiles(backupFiles, NULL) == 0){
189 QMessageBox::critical(this, "Message", 189 QMessageBox::critical(this, "Message",
190 "No items selected.",QString("Ok") ); 190 "No items selected.",QString("Ok") );
191 return; 191 return;
192 } 192 }
193 193
194 setCaption(tr("Backup and Restore... working...")); 194 setCaption(tr("Backup and Restore... working..."));
195 QString outputFile = backupLocations[storeToLocation->currentText()]; 195 QString outputFile = backupLocations[storeToLocation->currentText()];
196 196
197 QDateTime datetime = QDateTime::currentDateTime(); 197 QDateTime datetime = QDateTime::currentDateTime();
198 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + 198 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
199 QString::number( datetime.date().day() ).rightJustify(2, '0'); 199 QString::number( datetime.date().day() ).rightJustify(2, '0');
200 200
201 outputFile += "/" + dateString; 201 outputFile += "/" + dateString;
202 202
203 QString t = outputFile; 203 QString t = outputFile;
204 int c = 1; 204 int c = 1;
205 while(QFile::exists(outputFile + EXTENSION)){ 205 while(QFile::exists(outputFile + EXTENSION)){
206 outputFile = t + QString("%1").arg(c); 206 outputFile = t + QString("%1").arg(c);
207 c++; 207 c++;
208 } 208 }
209 209
210 // We execute tar and compressing its output with gzip.. 210 // We execute tar and compressing its output with gzip..
211 // The error output will be written into a temp-file which could be provided 211 // The error output will be written into a temp-file which could be provided
212 // for debugging.. 212 // for debugging..
213 qDebug( "Storing file: %s", outputFile.latin1() ); 213 qDebug( "Storing file: %s", outputFile.latin1() );
214 outputFile += EXTENSION; 214 outputFile += EXTENSION;
215 215
216 qWarning( QString("(tar -c %1 | gzip > %2 ) 2> %3") 216 qWarning( QString("(tar -c %1 | gzip > %2 ) 2> %3")
@@ -225,13 +225,13 @@ void BackupAndRestore::backupPressed(){
225 .arg( tempFileName.latin1() ) ); 225 .arg( tempFileName.latin1() ) );
226 226
227 if(r != 0){ 227 if(r != 0){
228 perror("Error: "); 228 perror("Error: ");
229 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 229 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
230 230
231 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" 231 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n"
232 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){ 232 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ){
233 233
234 case 1: 234 case 1:
235 qWarning("Details pressed !"); 235 qWarning("Details pressed !");
236 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 236 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
237 QFile errorFile( tempFileName ); 237 QFile errorFile( tempFileName );
@@ -239,45 +239,45 @@ void BackupAndRestore::backupPressed(){
239 QTextStream t( &errorFile ); 239 QTextStream t( &errorFile );
240 QString s; 240 QString s;
241 while ( !t.eof() ) { // until end of file... 241 while ( !t.eof() ) { // until end of file...
242 s += t.readLine(); // line of text excluding '\n' 242 s += t.readLine(); // line of text excluding '\n'
243 } 243 }
244 errorFile.close(); 244 errorFile.close();
245 245
246 pErrDialog->m_textarea->setText( s ); 246 pErrDialog->m_textarea->setText( s );
247 }else{ 247 }else{
248 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); 248 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" );
249 } 249 }
250 pErrDialog->showMaximized(); 250 pErrDialog->showMaximized();
251 pErrDialog->exec(); 251 pErrDialog->exec();
252 delete pErrDialog; 252 delete pErrDialog;
253 break; 253 break;
254 } 254 }
255 setCaption(tr("Backup and Restore.. Failed !!")); 255 setCaption(tr("Backup and Restore.. Failed !!"));
256 return; 256 return;
257 } 257 }
258 else{ 258 else{
259 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) ); 259 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successfull." ), QString(tr( "Ok" ) ) );
260 260
261 } 261 }
262 setCaption(tr("Backup and Restore")); 262 setCaption(tr("Backup and Restore"));
263} 263}
264 264
265/*** 265/***
266 * Get a list of all of the files to backup. 266 * Get a list of all of the files to backup.
267 */ 267 */
268int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ 268int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){
269 QListViewItem * currentItem; 269 QListViewItem * currentItem;
270 QString currentHome; 270 QString currentHome;
271 if(!parent) 271 if(!parent)
272 currentItem = backupList->firstChild(); 272 currentItem = backupList->firstChild();
273 else{ 273 else{
274 currentItem = parent->firstChild(); 274 currentItem = parent->firstChild();
275 currentHome = parent->text(BACKUP_LOCATION); 275 currentHome = parent->text(BACKUP_LOCATION);
276 } 276 }
277 277
278 uint count = 0; 278 uint count = 0;
279 while( currentItem != 0 ){ 279 while( currentItem != 0 ){
280 if(currentItem->text(HEADER_BACKUP) == "B" ){ 280 if(currentItem->text(HEADER_BACKUP) == "B" ){
281 if(currentItem->childCount() == 0 ){ 281 if(currentItem->childCount() == 0 ){
282 if(parent == NULL) 282 if(parent == NULL)
283 backupFiles += currentItem->text(BACKUP_LOCATION); 283 backupFiles += currentItem->text(BACKUP_LOCATION);
@@ -314,13 +314,13 @@ void BackupAndRestore::fileListUpdate()
314 */ 314 */
315void BackupAndRestore::rescanFolder(QString directory){ 315void BackupAndRestore::rescanFolder(QString directory){
316 //qDebug(QString("rescanFolder: ") + directory.latin1()); 316 //qDebug(QString("rescanFolder: ") + directory.latin1());
317 QDir d(directory); 317 QDir d(directory);
318 if(!d.exists()) 318 if(!d.exists())
319 return; 319 return;
320 320
321 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); 321 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
322 const QFileInfoList *list = d.entryInfoList(); 322 const QFileInfoList *list = d.entryInfoList();
323 QFileInfoListIterator it( *list ); 323 QFileInfoListIterator it( *list );
324 QFileInfo *file; 324 QFileInfo *file;
325 while ( (file=it.current()) ) { // for each file... 325 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. 326 // If it is a dir and not .. or . then add it as a tab and go down.
@@ -338,55 +338,55 @@ void BackupAndRestore::rescanFolder(QString directory){
338 } 338 }
339} 339}
340 340
341/** 341/**
342 * Restore a backup file. 342 * Restore a backup file.
343 * Report errors or success 343 * Report errors or success
344 */ 344 */
345void BackupAndRestore::restore(){ 345void BackupAndRestore::restore(){
346 QListViewItem *restoreItem = restoreList->currentItem(); 346 QListViewItem *restoreItem = restoreList->currentItem();
347 if(!restoreItem){ 347 if(!restoreItem){
348 QMessageBox::critical(this, tr( "Message" ), 348 QMessageBox::critical(this, tr( "Message" ),
349 tr( "Please select something to restore." ),QString( tr( "Ok") ) ); 349 tr( "Please select something to restore." ),QString( tr( "Ok") ) );
350 return; 350 return;
351 } 351 }
352 setCaption(tr("Backup and Restore... working...")); 352 setCaption(tr("Backup and Restore... working..."));
353 353
354 QString restoreFile = backupLocations[restoreSource->currentText()]; 354 QString restoreFile = backupLocations[restoreSource->currentText()];
355 355
356 restoreFile += "/" + restoreItem->text(0); 356 restoreFile += "/" + restoreItem->text(0);
357 357
358 int r = system(QString("tar -C / -zxf %1 2> %3") 358 int r = system(QString("tar -C / -zxf %1 2> %3")
359 .arg( restoreFile.latin1() ) 359 .arg( restoreFile.latin1() )
360 .arg( tempFileName.latin1() ) ); 360 .arg( tempFileName.latin1() ) );
361 if(r != 0){ 361 if(r != 0){
362 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 362 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
363 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" 363 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n"
364 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) { 364 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) {
365 case 1: 365 case 1:
366 qWarning("Details pressed !"); 366 qWarning("Details pressed !");
367 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 367 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
368 QFile errorFile( tempFileName ); 368 QFile errorFile( tempFileName );
369 if ( errorFile.open(IO_ReadOnly) ) { 369 if ( errorFile.open(IO_ReadOnly) ) {
370 QTextStream t( &errorFile ); 370 QTextStream t( &errorFile );
371 QString s; 371 QString s;
372 while ( !t.eof() ) { // until end of file... 372 while ( !t.eof() ) { // until end of file...
373 s += t.readLine(); // line of text excluding '\n' 373 s += t.readLine(); // line of text excluding '\n'
374 } 374 }
375 errorFile.close(); 375 errorFile.close();
376 376
377 pErrDialog->m_textarea->setText( s ); 377 pErrDialog->m_textarea->setText( s );
378 }else{ 378 }else{
379 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); 379 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) );
380 } 380 }
381 pErrDialog->showMaximized(); 381 pErrDialog->showMaximized();
382 pErrDialog->exec(); 382 pErrDialog->exec();
383 delete pErrDialog; 383 delete pErrDialog;
384 384
385 setCaption(tr("Backup and Restore.. Failed !!")); 385 setCaption(tr("Backup and Restore.. Failed !!"));
386 return; 386 return;
387 387
388 break; 388 break;
389 389
390 } 390 }
391 } 391 }
392 else{ 392 else{