summaryrefslogtreecommitdiff
authoreilers <eilers>2003-11-04 10:43:54 (UTC)
committer eilers <eilers>2003-11-04 10:43:54 (UTC)
commit9b992a9790f072b76052d42f1182b1d116994061 (patch) (unidiff)
treede512c71ae2def3daf14a115ebd38bc5f32ff102
parent8046118c7d4def83ef1a70628870b5ebad0534a4 (diff)
downloadopie-9b992a9790f072b76052d42f1182b1d116994061.zip
opie-9b992a9790f072b76052d42f1182b1d116994061.tar.gz
opie-9b992a9790f072b76052d42f1182b1d116994061.tar.bz2
Added home-directory patch from Andreas Richter <ar@oszine.de>
Thanks a lot !
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,172 +1,179 @@
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() != ".." ) ) {