summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp13
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,268 +1,275 @@
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
37const QString tempFileName = "/tmp/backup.err"; 38const QString tempFileName = "/tmp/backup.err";
38 39
39 40
40BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) 41BackupAndRestore::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
113BackupAndRestore::~BackupAndRestore(){ 120BackupAndRestore::~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
135QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list){ 142QList<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 */
150void BackupAndRestore::selectItem(QListViewItem *currentItem){ 157void 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
164void BackupAndRestore::scanForApplicationSettings(){ 171void 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 */
186void BackupAndRestore::backupPressed(){ 193void 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 */
268int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ 275int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){