author | llornkcor <llornkcor> | 2002-11-14 12:58:48 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-14 12:58:48 (UTC) |
commit | d7d53215cef9420872a4e0f42b547b4148ca33a9 (patch) (unidiff) | |
tree | 32afa92f283c65607fed532e66b7b55d3f748795 | |
parent | d419cd6d7f96341efc16717d68d7f7a0cfc09a80 (diff) | |
download | opie-d7d53215cef9420872a4e0f42b547b4148ca33a9.zip opie-d7d53215cef9420872a4e0f42b547b4148ca33a9.tar.gz opie-d7d53215cef9420872a4e0f42b547b4148ca33a9.tar.bz2 |
no --best option for gzip, buzybox already is set at best
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index fb892d9..02998f0 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -1,108 +1,108 @@ | |||
1 | #include "backuprestore.h" | 1 | #include "backuprestore.h" |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qfileinfo.h> | 4 | #include <qfileinfo.h> |
5 | #include <qlistview.h> | 5 | #include <qlistview.h> |
6 | #include <qpushbutton.h> | 6 | #include <qpushbutton.h> |
7 | #include <qheader.h> | 7 | #include <qheader.h> |
8 | #include <qpe/resource.h> | 8 | #include <qpe/resource.h> |
9 | #include <qpe/config.h> | 9 | #include <qpe/config.h> |
10 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
11 | #include <qcombobox.h> | 11 | #include <qcombobox.h> |
12 | #include <qlist.h> | 12 | #include <qlist.h> |
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | #include <qregexp.h> | 14 | #include <qregexp.h> |
15 | 15 | ||
16 | #define HEADER_NAME 0 | 16 | #define HEADER_NAME 0 |
17 | #define HEADER_BACKUP 1 | 17 | #define HEADER_BACKUP 1 |
18 | #define BACKUP_LOCATION 2 | 18 | #define BACKUP_LOCATION 2 |
19 | 19 | ||
20 | #define EXTENSION ".bck" | 20 | #define EXTENSION ".bck" |
21 | 21 | ||
22 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) | 22 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) |
23 | : BackupAndRestoreBase(parent, name){ | 23 | : BackupAndRestoreBase(parent, name){ |
24 | this->showMaximized(); | 24 | this->showMaximized(); |
25 | backupList->header()->hide(); | 25 | backupList->header()->hide(); |
26 | restoreList->header()->hide(); | 26 | restoreList->header()->hide(); |
27 | connect(backupButton, SIGNAL(clicked()), | 27 | connect(backupButton, SIGNAL(clicked()), |
28 | this, SLOT(backupPressed())); | 28 | this, SLOT(backupPressed())); |
29 | connect(restoreButton, SIGNAL(clicked()), | 29 | connect(restoreButton, SIGNAL(clicked()), |
30 | this, SLOT(restore())); | 30 | this, SLOT(restore())); |
31 | connect(backupList, SIGNAL(clicked( QListViewItem * )), | 31 | connect(backupList, SIGNAL(clicked( QListViewItem * )), |
32 | this, SLOT(selectItem(QListViewItem*))); | 32 | this, SLOT(selectItem(QListViewItem*))); |
33 | connect(restoreSource, SIGNAL(activated( int )), | 33 | connect(restoreSource, SIGNAL(activated( int )), |
34 | this, SLOT(sourceDirChanged(int))); | 34 | this, SLOT(sourceDirChanged(int))); |
35 | 35 | ||
36 | systemSettings = new QListViewItem(backupList, "System Settings", "", | 36 | systemSettings = new QListViewItem(backupList, "System Settings", "", |
37 | "/etc"); | 37 | "/etc"); |
38 | selectItem(systemSettings); | 38 | // selectItem(systemSettings); |
39 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", | 39 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", |
40 | QDir::homeDirPath() + "/Settings/"); | 40 | QDir::homeDirPath() + "/Settings/"); |
41 | selectItem(applicationSettings); | 41 | selectItem(applicationSettings); |
42 | documents= new QListViewItem(backupList, "Documents", "", | 42 | documents= new QListViewItem(backupList, "Documents", "", |
43 | QDir::homeDirPath() + "/Documents/"); | 43 | QDir::homeDirPath() + "/Documents/"); |
44 | selectItem(documents); | 44 | // selectItem(documents); |
45 | 45 | ||
46 | scanForApplicationSettings(); | 46 | scanForApplicationSettings(); |
47 | 47 | ||
48 | Config config("BackupAndRestore"); | 48 | Config config("BackupAndRestore"); |
49 | config.setGroup("General"); | 49 | config.setGroup("General"); |
50 | int totalLocations = config.readNumEntry("totalLocations",0); | 50 | int totalLocations = config.readNumEntry("totalLocations",0); |
51 | 51 | ||
52 | //todo make less static here and use Storage class to get infos | 52 | //todo make less static here and use Storage class to get infos |
53 | if(totalLocations == 0){ | 53 | if(totalLocations == 0){ |
54 | backupLocations.insert("Documents", "/root/Documents"); | 54 | backupLocations.insert("Documents", "/root/Documents"); |
55 | backupLocations.insert("CF", "/mnt/cf"); | 55 | backupLocations.insert("CF", "/mnt/cf"); |
56 | backupLocations.insert("SD", "/mnt/card"); | 56 | backupLocations.insert("SD", "/mnt/card"); |
57 | } | 57 | } |
58 | else{ | 58 | else{ |
59 | for(int i = 0; i < totalLocations; i++){ | 59 | for(int i = 0; i < totalLocations; i++){ |
60 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), | 60 | backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), |
61 | config.readEntry(QString("backupLocation_%1").arg(i))); | 61 | config.readEntry(QString("backupLocation_%1").arg(i))); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | QMap<QString, QString>::Iterator it; | 64 | QMap<QString, QString>::Iterator it; |
65 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ | 65 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ){ |
66 | storeToLocation->insertItem(it.key()); | 66 | storeToLocation->insertItem(it.key()); |
67 | restoreSource->insertItem(it.key()); | 67 | restoreSource->insertItem(it.key()); |
68 | } | 68 | } |
69 | 69 | ||
70 | // Read the list of items to ignore. | 70 | // Read the list of items to ignore. |
71 | QList<QString> dontBackupList; | 71 | QList<QString> dontBackupList; |
72 | dontBackupList.setAutoDelete(true); | 72 | dontBackupList.setAutoDelete(true); |
73 | config.setGroup("DontBackup"); | 73 | config.setGroup("DontBackup"); |
74 | int total = config.readNumEntry("Total", 0); | 74 | int total = config.readNumEntry("Total", 0); |
75 | for(int i = 0; i < total; i++){ | 75 | for(int i = 0; i < total; i++){ |
76 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | 76 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); |
77 | } | 77 | } |
78 | 78 | ||
79 | QList<QListViewItem> list; | 79 | QList<QListViewItem> list; |
80 | getAllItems(backupList->firstChild(), list); | 80 | getAllItems(backupList->firstChild(), list); |
81 | 81 | ||
82 | for(uint i = 0; i < list.count(); i++){ | 82 | for(uint i = 0; i < list.count(); i++){ |
83 | QString text = list.at(i)->text(HEADER_NAME); | 83 | QString text = list.at(i)->text(HEADER_NAME); |
84 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ | 84 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ |
85 | if(*dontBackupList.at(i2) == text){ | 85 | if(*dontBackupList.at(i2) == text){ |
86 | selectItem(list.at(i)); | 86 | selectItem(list.at(i)); |
87 | break; | 87 | break; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | BackupAndRestore::~BackupAndRestore(){ | 93 | BackupAndRestore::~BackupAndRestore(){ |
94 | QList<QListViewItem> list; | 94 | QList<QListViewItem> list; |
95 | getAllItems(backupList->firstChild(), list); | 95 | getAllItems(backupList->firstChild(), list); |
96 | 96 | ||
97 | Config config("BackupAndRestore"); | 97 | Config config("BackupAndRestore"); |
98 | config.setGroup("DontBackup"); | 98 | config.setGroup("DontBackup"); |
99 | config.clearGroup(); | 99 | config.clearGroup(); |
100 | 100 | ||
101 | int count = 0; | 101 | int count = 0; |
102 | for(uint i = 0; i < list.count(); i++){ | 102 | for(uint i = 0; i < list.count(); i++){ |
103 | if(list.at(i)->text(HEADER_BACKUP) == ""){ | 103 | if(list.at(i)->text(HEADER_BACKUP) == ""){ |
104 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 104 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
105 | count++; | 105 | count++; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | config.writeEntry("Total", count); | 108 | config.writeEntry("Total", count); |
@@ -117,130 +117,130 @@ QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QL | |||
117 | } | 117 | } |
118 | return list; | 118 | return list; |
119 | } | 119 | } |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. | 122 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. |
123 | * and changing the icon to match | 123 | * and changing the icon to match |
124 | * @param currentItem the item to swich the selection choice. | 124 | * @param currentItem the item to swich the selection choice. |
125 | */ | 125 | */ |
126 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ | 126 | void BackupAndRestore::selectItem(QListViewItem *currentItem){ |
127 | if(!currentItem) | 127 | if(!currentItem) |
128 | return; | 128 | return; |
129 | 129 | ||
130 | if(currentItem->text(HEADER_BACKUP) == "B"){ | 130 | if(currentItem->text(HEADER_BACKUP) == "B"){ |
131 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("null")); | 131 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("null")); |
132 | currentItem->setText(HEADER_BACKUP, ""); | 132 | currentItem->setText(HEADER_BACKUP, ""); |
133 | } | 133 | } |
134 | else{ | 134 | else{ |
135 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("check")); | 135 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("check")); |
136 | currentItem->setText(HEADER_BACKUP, "B"); | 136 | currentItem->setText(HEADER_BACKUP, "B"); |
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
140 | void BackupAndRestore::scanForApplicationSettings(){ | 140 | void BackupAndRestore::scanForApplicationSettings(){ |
141 | QDir d(applicationSettings->text(BACKUP_LOCATION)); | 141 | QDir d(applicationSettings->text(BACKUP_LOCATION)); |
142 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 142 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
143 | const QFileInfoList *list = d.entryInfoList(); | 143 | const QFileInfoList *list = d.entryInfoList(); |
144 | QFileInfoListIterator it( *list ); | 144 | QFileInfoListIterator it( *list ); |
145 | QFileInfo *fi; | 145 | QFileInfo *fi; |
146 | while ( (fi=it.current()) ) { | 146 | while ( (fi=it.current()) ) { |
147 | //qDebug((d.path()+fi->fileName()).latin1()); | 147 | //qDebug((d.path()+fi->fileName()).latin1()); |
148 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 148 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
149 | selectItem(newItem); | 149 | selectItem(newItem); |
150 | ++it; | 150 | ++it; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | /** | 154 | /** |
155 | * The "Backup" button has been pressed. Get a list of all of the files that | 155 | * The "Backup" button has been pressed. Get a list of all of the files that |
156 | * should be backed up. If there are no files, emit and error and exit. | 156 | * should be backed up. If there are no files, emit and error and exit. |
157 | * Determine the file name to store the backup in. Backup the file(s) using | 157 | * Determine the file name to store the backup in. Backup the file(s) using |
158 | * tar and gzip --best. Report failure or success | 158 | * tar and gzip --best. Report failure or success |
159 | */ | 159 | */ |
160 | void BackupAndRestore::backupPressed(){ | 160 | void BackupAndRestore::backupPressed(){ |
161 | QString backupFiles; | 161 | QString backupFiles; |
162 | if(getBackupFiles(backupFiles, NULL) == 0){ | 162 | if(getBackupFiles(backupFiles, NULL) == 0){ |
163 | QMessageBox::critical(this, "Message", | 163 | QMessageBox::critical(this, "Message", |
164 | "No items selected.",QString("Ok") ); | 164 | "No items selected.",QString("Ok") ); |
165 | return; | 165 | return; |
166 | } | 166 | } |
167 | 167 | ||
168 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 168 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
169 | 169 | ||
170 | QDateTime time = QDateTime::currentDateTime(); | 170 | QDateTime time = QDateTime::currentDateTime(); |
171 | QString dateString = time.date().toString().replace(QRegExp(" "), ""); | 171 | QString dateString = time.date().toString().replace(QRegExp(" "), ""); |
172 | outputFile += "/" + dateString; | 172 | outputFile += "/" + dateString; |
173 | 173 | ||
174 | QString t = outputFile; | 174 | QString t = outputFile; |
175 | int c = 1; | 175 | int c = 1; |
176 | while(QFile::exists(outputFile + EXTENSION)){ | 176 | while(QFile::exists(outputFile + EXTENSION)){ |
177 | outputFile = t + QString("%1").arg(c); | 177 | outputFile = t + QString("%1").arg(c); |
178 | c++; | 178 | c++; |
179 | } | 179 | } |
180 | outputFile += EXTENSION; | 180 | outputFile += EXTENSION; |
181 | 181 | qDebug("system(\"tar -c %1 | gzip > %2\").arg(backupFiles).arg(outputFile).latin1())"); | |
182 | int r = system(QString("tar -c %1 | gzip --best > %2").arg(backupFiles).arg(outputFile).latin1()); | 182 | int r = system(QString("tar -c %1 | gzip > %2").arg(backupFiles).arg(outputFile).latin1() ); |
183 | if(r != 0){ | 183 | if(r != 0){ |
184 | QMessageBox::critical(this, "Message", "Backup Failed.",QString("Ok") ); | 184 | QMessageBox::critical(this, "Message", "Backup Failed.",QString("Ok") ); |
185 | return; | 185 | return; |
186 | } | 186 | } |
187 | else{ | 187 | else{ |
188 | QMessageBox::critical(this, "Message", "Backup Successfull.",QString("Ok") ); | 188 | QMessageBox::critical(this, "Message", "Backup Successfull.",QString("Ok") ); |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | /*** | 192 | /*** |
193 | * Get a list of all of the files to backup. | 193 | * Get a list of all of the files to backup. |
194 | */ | 194 | */ |
195 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ | 195 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent){ |
196 | QListViewItem * currentItem; | 196 | QListViewItem * currentItem; |
197 | QString currentHome; | 197 | QString currentHome; |
198 | if(!parent) | 198 | if(!parent) |
199 | currentItem = backupList->firstChild(); | 199 | currentItem = backupList->firstChild(); |
200 | else{ | 200 | else{ |
201 | currentItem = parent->firstChild(); | 201 | currentItem = parent->firstChild(); |
202 | currentHome = parent->text(BACKUP_LOCATION); | 202 | currentHome = parent->text(BACKUP_LOCATION); |
203 | } | 203 | } |
204 | 204 | ||
205 | uint count = 0; | 205 | uint count = 0; |
206 | while( currentItem != 0 ){ | 206 | while( currentItem != 0 ){ |
207 | if(currentItem->text(HEADER_BACKUP) == "B" ){ | 207 | if(currentItem->text(HEADER_BACKUP) == "B" ){ |
208 | if(currentItem->childCount() == 0 ){ | 208 | if(currentItem->childCount() == 0 ){ |
209 | if(parent == NULL) | 209 | if(parent == NULL) |
210 | backupFiles += currentItem->text(BACKUP_LOCATION); | 210 | backupFiles += currentItem->text(BACKUP_LOCATION); |
211 | else | 211 | else |
212 | backupFiles += currentHome + currentItem->text(HEADER_NAME); | 212 | backupFiles += currentHome + currentItem->text(HEADER_NAME); |
213 | backupFiles += " "; | 213 | backupFiles += " "; |
214 | count++; | 214 | count++; |
215 | } | 215 | } |
216 | else{ | 216 | else{ |
217 | count += getBackupFiles(backupFiles, currentItem); | 217 | count += getBackupFiles(backupFiles, currentItem); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | currentItem = currentItem->nextSibling(); | 220 | currentItem = currentItem->nextSibling(); |
221 | } | 221 | } |
222 | return count; | 222 | return count; |
223 | } | 223 | } |
224 | 224 | ||
225 | void BackupAndRestore::sourceDirChanged(int selection){ | 225 | void BackupAndRestore::sourceDirChanged(int selection){ |
226 | restoreList->clear(); | 226 | restoreList->clear(); |
227 | rescanFolder(backupLocations[restoreSource->text(selection)]); | 227 | rescanFolder(backupLocations[restoreSource->text(selection)]); |
228 | } | 228 | } |
229 | 229 | ||
230 | /** | 230 | /** |
231 | * Scans directory for any backup files. Will recursivly go down, | 231 | * Scans directory for any backup files. Will recursivly go down, |
232 | * but will not follow symlinks. | 232 | * but will not follow symlinks. |
233 | * @param directory - the directory to look in. | 233 | * @param directory - the directory to look in. |
234 | */ | 234 | */ |
235 | void BackupAndRestore::rescanFolder(QString directory){ | 235 | void BackupAndRestore::rescanFolder(QString directory){ |
236 | //qDebug(QString("rescanFolder: ") + directory.latin1()); | 236 | //qDebug(QString("rescanFolder: ") + directory.latin1()); |
237 | QDir d(directory); | 237 | QDir d(directory); |
238 | if(!d.exists()) | 238 | if(!d.exists()) |
239 | return; | 239 | return; |
240 | 240 | ||
241 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 241 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
242 | const QFileInfoList *list = d.entryInfoList(); | 242 | const QFileInfoList *list = d.entryInfoList(); |
243 | QFileInfoListIterator it( *list ); | 243 | QFileInfoListIterator it( *list ); |
244 | QFileInfo *file; | 244 | QFileInfo *file; |
245 | while ( (file=it.current()) ) { // for each file... | 245 | while ( (file=it.current()) ) { // for each file... |
246 | // If it is a dir and not .. or . then add it as a tab and go down. | 246 | // If it is a dir and not .. or . then add it as a tab and go down. |