summaryrefslogtreecommitdiff
Unidiff
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,267 +1,276 @@
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 );