author | mickeyl <mickeyl> | 2004-11-10 14:03:37 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-11-10 14:03:37 (UTC) |
commit | 9088b52d1ef7c4e70e62a53e225c69508cc8afe3 (patch) (unidiff) | |
tree | 38ac61c1004edecdec8cf5b1708816e13bb643df | |
parent | fcd9c62650dd1bb9c04bfd798d243cb894a8f393 (diff) | |
download | opie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.zip opie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.tar.gz opie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.tar.bz2 |
start working on clone functionality
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index c944c6d..869c1b8 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -1,662 +1,747 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002-2004 The Opie Team <opie-devel@handhelds.org> | 4 | .=l. Copyright (c) 2002-2004 The Opie Team <opie-devel@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "backuprestore.h" | 29 | #include "backuprestore.h" |
30 | #include "errordialog.h" | 30 | #include "errordialog.h" |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
37 | #include <opie2/odevice.h> | ||
37 | #include <opie2/ostorageinfo.h> | 38 | #include <opie2/ostorageinfo.h> |
38 | #include <opie2/ofiledialog.h> | 39 | #include <opie2/ofiledialog.h> |
39 | #include <opie2/owait.h> | 40 | #include <opie2/owait.h> |
40 | using namespace Opie::Core; | 41 | using namespace Opie::Core; |
41 | using namespace Opie::Ui; | 42 | using namespace Opie::Ui; |
42 | 43 | ||
43 | /* QT */ | 44 | /* QT */ |
44 | #include <qapplication.h> | 45 | #include <qapplication.h> |
45 | #include <qmultilineedit.h> | 46 | #include <qmultilineedit.h> |
46 | #include <qdir.h> | 47 | #include <qdir.h> |
47 | #include <qfile.h> | 48 | #include <qfile.h> |
48 | #include <qfileinfo.h> | 49 | #include <qfileinfo.h> |
49 | #include <qlistview.h> | 50 | #include <qlistview.h> |
50 | #include <qpushbutton.h> | 51 | #include <qpushbutton.h> |
51 | #include <qradiobutton.h> | 52 | #include <qradiobutton.h> |
52 | #include <qheader.h> | 53 | #include <qheader.h> |
53 | #include <qmessagebox.h> | 54 | #include <qmessagebox.h> |
54 | #include <qcombobox.h> | 55 | #include <qcombobox.h> |
55 | #include <qlist.h> | 56 | #include <qlist.h> |
56 | #include <qregexp.h> | 57 | #include <qregexp.h> |
57 | #include <qtextstream.h> | 58 | #include <qtextstream.h> |
58 | #include <qtextview.h> | 59 | #include <qtextview.h> |
59 | #include <qlineedit.h> | 60 | #include <qlineedit.h> |
60 | #include <qstringlist.h> | 61 | #include <qstringlist.h> |
61 | 62 | ||
62 | /* STD */ | 63 | /* STD */ |
63 | #include <errno.h> | 64 | #include <errno.h> |
64 | #include <stdlib.h> | 65 | #include <stdlib.h> |
65 | #include <unistd.h> | 66 | #include <unistd.h> |
66 | #include <sys/stat.h> | 67 | #include <sys/stat.h> |
67 | #include <dirent.h> | 68 | #include <dirent.h> |
68 | 69 | ||
69 | #define HEADER_NAME 0 | 70 | #define HEADER_NAME 0 |
70 | #define HEADER_BACKUP 1 | 71 | #define HEADER_BACKUP 1 |
71 | #define BACKUP_LOCATION 2 | 72 | #define BACKUP_LOCATION 2 |
72 | 73 | ||
73 | #define EXTENSION ".bck" | 74 | #define EXTENSION ".bck" |
74 | 75 | ||
75 | const QString tempFileName = "/tmp/backup.err"; | 76 | const QString tempFileName = "/tmp/backup.err"; |
76 | 77 | ||
77 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) | 78 | BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) |
78 | : BackupAndRestoreBase(parent, name, fl) | 79 | : BackupAndRestoreBase(parent, name, fl) |
79 | { | 80 | { |
80 | backupList->header()->hide(); | 81 | backupList->header()->hide(); |
81 | restoreList->header()->hide(); | 82 | restoreList->header()->hide(); |
82 | locationList->header()->hide(); | 83 | locationList->header()->hide(); |
83 | connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) ); | 84 | connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) ); |
84 | connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) ); | 85 | connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) ); |
85 | connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) ); | 86 | connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) ); |
86 | connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) ); | 87 | connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) ); |
87 | connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) ); | 88 | connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) ); |
88 | connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) ); | 89 | connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) ); |
89 | connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) ); | 90 | connect( saveLocationsButton, SIGNAL( clicked() ), this, SLOT( saveLocations() ) ); |
90 | connect( selectLocationButton, SIGNAL( clicked() ), this, SLOT( selectLocation() ) ); | 91 | connect( selectLocationButton, SIGNAL( clicked() ), this, SLOT( selectLocation() ) ); |
91 | 92 | ||
92 | //add directorys for backing up | 93 | //add directorys for backing up |
93 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); | 94 | applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); |
94 | selectItem(applicationSettings); | 95 | selectItem(applicationSettings); |
95 | applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); | 96 | applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); |
96 | selectItem(applicationSettings); | 97 | selectItem(applicationSettings); |
97 | documents= new QListViewItem(backupList, "Documents", "", "Documents/"); | 98 | documents= new QListViewItem(backupList, "Documents", "", "Documents/"); |
98 | selectItem(documents); | 99 | selectItem(documents); |
99 | 100 | ||
100 | scanForApplicationSettings(); | 101 | scanForApplicationSettings(); |
101 | refreshLocations(); | 102 | refreshLocations(); |
102 | refreshBackupLocations(); | 103 | refreshBackupLocations(); |
103 | 104 | ||
104 | // Read the list of items to ignore. | 105 | // Read the list of items to ignore. |
105 | QList<QString> dontBackupList; | 106 | QList<QString> dontBackupList; |
106 | dontBackupList.setAutoDelete(true); | 107 | dontBackupList.setAutoDelete(true); |
107 | Config config("BackupAndRestore"); | 108 | Config config("BackupAndRestore"); |
108 | config.setGroup("DontBackup"); | 109 | config.setGroup("DontBackup"); |
109 | int total = config.readNumEntry("Total", 0); | 110 | int total = config.readNumEntry("Total", 0); |
110 | for(int i = 0; i < total; i++) | 111 | for(int i = 0; i < total; i++) |
111 | { | 112 | { |
112 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); | 113 | dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); |
113 | } | 114 | } |
114 | 115 | ||
115 | QList<QListViewItem> list; | 116 | QList<QListViewItem> list; |
116 | getAllItems(backupList->firstChild(), list); | 117 | getAllItems(backupList->firstChild(), list); |
117 | 118 | ||
118 | for(uint i = 0; i < list.count(); i++) | 119 | for(uint i = 0; i < list.count(); i++) |
119 | { | 120 | { |
120 | QString text = list.at(i)->text(HEADER_NAME); | 121 | QString text = list.at(i)->text(HEADER_NAME); |
121 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++) | 122 | for(uint i2 = 0; i2 < dontBackupList.count(); i2++) |
122 | { | 123 | { |
123 | if(*dontBackupList.at(i2) == text) | 124 | if(*dontBackupList.at(i2) == text) |
124 | { | 125 | { |
125 | selectItem(list.at(i)); | 126 | selectItem(list.at(i)); |
126 | break; | 127 | break; |
127 | } | 128 | } |
128 | } | 129 | } |
129 | } | 130 | } |
130 | QPEApplication::showWidget( this ); | 131 | QPEApplication::showWidget( this ); |
131 | } | 132 | } |
132 | 133 | ||
133 | BackupAndRestore::~BackupAndRestore() | 134 | BackupAndRestore::~BackupAndRestore() |
134 | { | 135 | { |
135 | QList<QListViewItem> list; | 136 | QList<QListViewItem> list; |
136 | getAllItems(backupList->firstChild(), list); | 137 | getAllItems(backupList->firstChild(), list); |
137 | 138 | ||
138 | Config config("BackupAndRestore"); | 139 | Config config("BackupAndRestore"); |
139 | config.setGroup("DontBackup"); | 140 | config.setGroup("DontBackup"); |
140 | config.clearGroup(); | 141 | config.clearGroup(); |
141 | 142 | ||
142 | int count = 0; | 143 | int count = 0; |
143 | for(uint i = 0; i < list.count(); i++) | 144 | for(uint i = 0; i < list.count(); i++) |
144 | { | 145 | { |
145 | if(list.at(i)->text(HEADER_BACKUP) == "") | 146 | if(list.at(i)->text(HEADER_BACKUP) == "") |
146 | { | 147 | { |
147 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); | 148 | config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); |
148 | count++; | 149 | count++; |
149 | } | 150 | } |
150 | } | 151 | } |
151 | config.writeEntry("Total", count); | 152 | config.writeEntry("Total", count); |
152 | 153 | ||
153 | // Remove Temp File | 154 | // Remove Temp File |
154 | if ( QFile::exists( tempFileName ) ) | 155 | if ( QFile::exists( tempFileName ) ) |
155 | QFile::remove( tempFileName ); | 156 | QFile::remove( tempFileName ); |
156 | } | 157 | } |
157 | 158 | ||
158 | void BackupAndRestore::refreshBackupLocations() | 159 | void BackupAndRestore::refreshBackupLocations() |
159 | { | 160 | { |
160 | backupLocations.clear(); | 161 | backupLocations.clear(); |
161 | // Add cards | 162 | // Add cards |
162 | Opie::Core::OStorageInfo storage; | 163 | Opie::Core::OStorageInfo storage; |
163 | backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" ); | 164 | backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" ); |
164 | if ( storage.hasCf() ) | 165 | if ( storage.hasCf() ) |
165 | { | 166 | { |
166 | backupLocations.insert( "CF", storage.cfPath() ); | 167 | backupLocations.insert( "CF", storage.cfPath() ); |
167 | odebug << "Cf Path: " + storage.cfPath() << oendl; | 168 | odebug << "Cf Path: " + storage.cfPath() << oendl; |
168 | } | 169 | } |
169 | if ( storage.hasSd() ) | 170 | if ( storage.hasSd() ) |
170 | { | 171 | { |
171 | backupLocations.insert( "SD", storage.sdPath() ); | 172 | backupLocations.insert( "SD", storage.sdPath() ); |
172 | odebug << " Sd Path: " + storage.sdPath() << oendl; | 173 | odebug << " Sd Path: " + storage.sdPath() << oendl; |
173 | } | 174 | } |
174 | if ( storage.hasMmc() ) | 175 | if ( storage.hasMmc() ) |
175 | { | 176 | { |
176 | backupLocations.insert( "MMC", storage.mmcPath() ); | 177 | backupLocations.insert( "MMC", storage.mmcPath() ); |
177 | odebug << "Mmc Path: " + storage.mmcPath() << oendl; | 178 | odebug << "Mmc Path: " + storage.mmcPath() << oendl; |
178 | } | 179 | } |
179 | 180 | ||
180 | for ( QListViewItemIterator it( locationList ); it.current(); ++it ) | 181 | for ( QListViewItemIterator it( locationList ); it.current(); ++it ) |
181 | { | 182 | { |
182 | backupLocations.insert( it.current()->text( 0 ), it.current()->text( 0 ) ); | 183 | backupLocations.insert( it.current()->text( 0 ), it.current()->text( 0 ) ); |
183 | } | 184 | } |
184 | 185 | ||
185 | //update QComboBox | 186 | //update QComboBox |
186 | storeToLocation->clear(); | 187 | storeToLocation->clear(); |
187 | restoreSource->clear(); | 188 | restoreSource->clear(); |
188 | 189 | ||
189 | //read last locations | 190 | //read last locations |
190 | Config config("BackupAndRestore"); | 191 | Config config("BackupAndRestore"); |
191 | config.setGroup("LastLocation"); | 192 | config.setGroup("LastLocation"); |
192 | QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" ); | 193 | QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" ); |
193 | QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" ); | 194 | QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" ); |
194 | int locationIndex = 0; | 195 | int locationIndex = 0; |
195 | 196 | ||
196 | //fill QComboBox | 197 | //fill QComboBox |
197 | QMap<QString, QString>::Iterator it; | 198 | QMap<QString, QString>::Iterator it; |
198 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ) | 199 | for( it = backupLocations.begin(); it != backupLocations.end(); ++it ) |
199 | { | 200 | { |
200 | storeToLocation->insertItem(it.key()); | 201 | storeToLocation->insertItem(it.key()); |
201 | restoreSource->insertItem(it.key()); | 202 | restoreSource->insertItem(it.key()); |
202 | 203 | ||
203 | //check for last locations | 204 | //check for last locations |
204 | if ( it.key() == lastStoreLocation ) | 205 | if ( it.key() == lastStoreLocation ) |
205 | storeToLocation->setCurrentItem( locationIndex ); | 206 | storeToLocation->setCurrentItem( locationIndex ); |
206 | if ( it.key() == lastRestoreLocation ) | 207 | if ( it.key() == lastRestoreLocation ) |
207 | restoreSource->setCurrentItem( locationIndex ); | 208 | restoreSource->setCurrentItem( locationIndex ); |
208 | locationIndex++; | 209 | locationIndex++; |
209 | } | 210 | } |
210 | } | 211 | } |
211 | 212 | ||
212 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) | 213 | QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) |
213 | { | 214 | { |
214 | while(item) | 215 | while(item) |
215 | { | 216 | { |
216 | if(item->childCount() > 0) | 217 | if(item->childCount() > 0) |
217 | getAllItems(item->firstChild(), list); | 218 | getAllItems(item->firstChild(), list); |
218 | list.append(item); | 219 | list.append(item); |
219 | item = item->nextSibling(); | 220 | item = item->nextSibling(); |
220 | } | 221 | } |
221 | return list; | 222 | return list; |
222 | } | 223 | } |
223 | 224 | ||
224 | /** | 225 | /** |
225 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. | 226 | * Selects and unselects the item by setting the HEADER_BACKUP to B or !. |
226 | * and changing the icon to match | 227 | * and changing the icon to match |
227 | * @param currentItem the item to swich the selection choice. | 228 | * @param currentItem the item to swich the selection choice. |
228 | */ | 229 | */ |
229 | void BackupAndRestore::selectItem(QListViewItem *currentItem) | 230 | void BackupAndRestore::selectItem(QListViewItem *currentItem) |
230 | { | 231 | { |
231 | if(!currentItem) | 232 | if(!currentItem) |
232 | return; | 233 | return; |
233 | 234 | ||
234 | if(currentItem->text(HEADER_BACKUP) == "B") | 235 | if(currentItem->text(HEADER_BACKUP) == "B") |
235 | { | 236 | { |
236 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); | 237 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); |
237 | currentItem->setText(HEADER_BACKUP, ""); | 238 | currentItem->setText(HEADER_BACKUP, ""); |
238 | } | 239 | } |
239 | else | 240 | else |
240 | { | 241 | { |
241 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); | 242 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); |
242 | currentItem->setText(HEADER_BACKUP, "B"); | 243 | currentItem->setText(HEADER_BACKUP, "B"); |
243 | } | 244 | } |
244 | } | 245 | } |
245 | 246 | ||
246 | void BackupAndRestore::scanForApplicationSettings() | 247 | void BackupAndRestore::scanForApplicationSettings() |
247 | { | 248 | { |
248 | QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); | 249 | QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); |
249 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); | 250 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); |
250 | const QFileInfoList *list = d.entryInfoList(); | 251 | const QFileInfoList *list = d.entryInfoList(); |
251 | QFileInfoListIterator it( *list ); | 252 | QFileInfoListIterator it( *list ); |
252 | QFileInfo *fi; | 253 | QFileInfo *fi; |
253 | while ( (fi=it.current()) ) | 254 | while ( (fi=it.current()) ) |
254 | { | 255 | { |
255 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; | 256 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; |
256 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) | 257 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) |
257 | { | 258 | { |
258 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 259 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
259 | selectItem(newItem); | 260 | selectItem(newItem); |
260 | } | 261 | } |
261 | ++it; | 262 | ++it; |
262 | } | 263 | } |
263 | } | 264 | } |
264 | 265 | ||
265 | /** | 266 | /** |
266 | * The "Backup" button has been pressed. Get a list of all of the files that | 267 | * The "Backup" button has been pressed. Get a list of all of the files that |
267 | * should be backed up. If there are no files, emit and error and exit. | 268 | * should be backed up. If there are no files, emit and error and exit. |
268 | * Determine the file name to store the backup in. Backup the file(s) using | 269 | * Determine the file name to store the backup in. Backup the file(s) using |
269 | * tar and gzip --best. Report failure or success | 270 | * tar and gzip --best. Report failure or success |
270 | */ | 271 | */ |
271 | void BackupAndRestore::backup() | 272 | void BackupAndRestore::backup() |
272 | { | 273 | { |
273 | if ( cb_type_userdata->isChecked() ) | 274 | if ( cb_type_userdata->isChecked() ) |
274 | backupUserData(); | 275 | backupUserData(); |
275 | else | 276 | else |
276 | backupRootFs(); | 277 | backupRootFs(); |
277 | } | 278 | } |
278 | 279 | ||
279 | 280 | ||
280 | void BackupAndRestore::backupRootFs() | 281 | void BackupAndRestore::backupRootFs() |
281 | { | 282 | { |
282 | QMessageBox::critical(this, "Message", "Not Yet Implemented", "Ok" ); | 283 | //#define MDEBUG |
284 | #ifndef MDEBUG | ||
285 | QMessageBox::critical( this, "Opie-Backup", "<qt>This feature is not yet implemented.</qt>", "Bummer!" ); | ||
286 | return; | ||
287 | #endif | ||
288 | // call 'mount' and parse its output to gather the device on which the root partition is mounted | ||
289 | FILE* mountp = popen( "mount", "r" ); | ||
290 | QString device; | ||
291 | QString mountpoint; | ||
292 | { | ||
293 | QTextStream mounto( mountp, IO_ReadOnly ); | ||
294 | QString on; | ||
295 | QString type; | ||
296 | QString filesystem; | ||
297 | QString options; | ||
298 | while ( !mounto.atEnd() ) | ||
299 | { | ||
300 | mounto >> device >> on >> mountpoint >> type >> filesystem >> options; | ||
301 | if ( mountpoint == "/" ) break; | ||
302 | } | ||
303 | odebug << device << " is formatted w/ " << filesystem << " and mounted on " << mountpoint << oendl; | ||
304 | |||
305 | if ( !mountpoint.startsWith( "/dev/mtdblock" ) ) | ||
306 | { | ||
307 | QMessageBox::critical( this, "Can't backup!", QString( "<qt>unsupported rootfs %1 - needs to be /dev/mtdblockN</qt>").arg( device ), "Ok" ); | ||
308 | #ifndef MDEBUG | ||
309 | return; | ||
310 | #endif | ||
311 | } | ||
312 | } // at this point, the QTextStream has been destroy and we can close the FILE* | ||
313 | pclose( mountp ); | ||
314 | |||
315 | #ifndef MDEBUG | ||
316 | int rootmtd = device.right( 1 ).toInt(); | ||
317 | #else | ||
318 | int rootmtd = 0; | ||
319 | #endif | ||
320 | odebug << "root mtdblock seems to be '" << rootmtd << "'" << oendl; | ||
321 | |||
322 | // scan /proc/mtd to gather the size and erasesize of the root mtdblock | ||
323 | QFile procmtdf( "/proc/mtd" ); | ||
324 | if ( !procmtdf.open( IO_ReadOnly ) ) | ||
325 | { | ||
326 | QMessageBox::critical( this, "Can't backup!", "<qt>Can't open /proc/mtd</qt>", "Ok" ); | ||
327 | } | ||
328 | |||
329 | QTextStream procmtd( &procmtdf ); | ||
330 | for ( int i = 0; i <= rootmtd; ++i ) procmtd.readLine(); // skip uninteresting things | ||
331 | QString dev; | ||
332 | QString size; | ||
333 | QString erasesize; | ||
334 | QString devname; | ||
335 | procmtd >> dev >> size >> erasesize >> devname; | ||
336 | |||
337 | odebug << "device " << dev << " size = " << size << ", erase size = " << erasesize << ", name = " << devname << "\"" << oendl; | ||
338 | |||
339 | // compute pad | ||
340 | QString pad = "--pad"; | ||
341 | switch ( ODevice::inst()->model() ) | ||
342 | { | ||
343 | case Model_Zaurus_SL5000: pad = "--pad=14680064"; break; | ||
344 | case Model_Zaurus_SL5500: pad = "--pad=14680064"; break; | ||
345 | // FIXME: Add Beagle and SIMpad | ||
346 | } | ||
347 | |||
348 | // compute eraseblock | ||
349 | QString eraseblock = "--eraseblock=0x" + erasesize; | ||
350 | |||
351 | // compute output | ||
352 | QString outputFile = "--output=" + backupLocations[storeToLocation->currentText()]; | ||
353 | QDateTime datetime = QDateTime::currentDateTime(); | ||
354 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | ||
355 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | ||
356 | outputFile += "/initrd.bin-" + dateString; | ||
357 | |||
358 | // call mkfs.jffs2 to create the backup | ||
359 | QString cmdline = QString( "mkfs.jffs2 --root=/ %1 --little-endian %2 %3 -n" ).arg( outputFile ).arg( pad ).arg( eraseblock ); | ||
360 | owarn << "Calling '" << cmdline << "'" << oendl; | ||
361 | |||
362 | #ifndef MDEBUG | ||
363 | ::system( cmdline ); | ||
364 | #endif | ||
365 | |||
366 | // FIXME: Add image postprocessing for C7x0 and C8x0, for Beagle, for SIMpad | ||
367 | |||
283 | } | 368 | } |
284 | 369 | ||
285 | void BackupAndRestore::backupUserData() | 370 | void BackupAndRestore::backupUserData() |
286 | { | 371 | { |
287 | QString backupFiles; | 372 | QString backupFiles; |
288 | if(getBackupFiles(backupFiles, NULL) == 0) | 373 | if(getBackupFiles(backupFiles, NULL) == 0) |
289 | { | 374 | { |
290 | QMessageBox::critical(this, "Message", | 375 | QMessageBox::critical(this, "Message", |
291 | "No items selected.",QString("Ok") ); | 376 | "No items selected.",QString("Ok") ); |
292 | return; | 377 | return; |
293 | } | 378 | } |
294 | 379 | ||
295 | OWait *owait = new OWait(); | 380 | OWait *owait = new OWait(); |
296 | Global::statusMessage( tr( "Backing up..." ) ); | 381 | Global::statusMessage( tr( "Backing up..." ) ); |
297 | owait->show(); | 382 | owait->show(); |
298 | qApp->processEvents(); | 383 | qApp->processEvents(); |
299 | 384 | ||
300 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 385 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
301 | 386 | ||
302 | QDateTime datetime = QDateTime::currentDateTime(); | 387 | QDateTime datetime = QDateTime::currentDateTime(); |
303 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 388 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
304 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 389 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
305 | 390 | ||
306 | outputFile += "/" + dateString; | 391 | outputFile += "/" + dateString; |
307 | 392 | ||
308 | QString t = outputFile; | 393 | QString t = outputFile; |
309 | int c = 1; | 394 | int c = 1; |
310 | while(QFile::exists(outputFile + EXTENSION)) | 395 | while(QFile::exists(outputFile + EXTENSION)) |
311 | { | 396 | { |
312 | outputFile = t + QString("%1").arg(c); | 397 | outputFile = t + QString("%1").arg(c); |
313 | c++; | 398 | c++; |
314 | } | 399 | } |
315 | 400 | ||
316 | // We execute tar and compressing its output with gzip.. | 401 | // We execute tar and compressing its output with gzip.. |
317 | // The error output will be written into a temp-file which could be provided | 402 | // The error output will be written into a temp-file which could be provided |
318 | // for debugging.. | 403 | // for debugging.. |
319 | odebug << "Storing file: " << outputFile.latin1() << "" << oendl; | 404 | odebug << "Storing file: " << outputFile.latin1() << "" << oendl; |
320 | outputFile += EXTENSION; | 405 | outputFile += EXTENSION; |
321 | 406 | ||
322 | QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) | 407 | QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) |
323 | .arg( getExcludeFile() ) | 408 | .arg( getExcludeFile() ) |
324 | .arg( backupFiles ) | 409 | .arg( backupFiles ) |
325 | .arg( outputFile.latin1() ) | 410 | .arg( outputFile.latin1() ) |
326 | .arg( tempFileName.latin1() ); | 411 | .arg( tempFileName.latin1() ); |
327 | 412 | ||
328 | odebug << commandLine << oendl; | 413 | odebug << commandLine << oendl; |
329 | 414 | ||
330 | int r = system( commandLine ); | 415 | int r = system( commandLine ); |
331 | 416 | ||
332 | owait->hide(); | 417 | owait->hide(); |
333 | delete owait; | 418 | delete owait; |
334 | 419 | ||
335 | //Error-Handling | 420 | //Error-Handling |
336 | if(r != 0) | 421 | if(r != 0) |
337 | { | 422 | { |
338 | perror("Error: "); | 423 | perror("Error: "); |
339 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 424 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
340 | 425 | ||
341 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | 426 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" |
342 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) | 427 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) |
343 | { | 428 | { |
344 | 429 | ||
345 | case 1: | 430 | case 1: |
346 | owarn << "Details pressed !" << oendl; | 431 | owarn << "Details pressed !" << oendl; |
347 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 432 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
348 | QFile errorFile( tempFileName ); | 433 | QFile errorFile( tempFileName ); |
349 | if ( errorFile.open(IO_ReadOnly) ) | 434 | if ( errorFile.open(IO_ReadOnly) ) |
350 | { | 435 | { |
351 | QTextStream t( &errorFile ); | 436 | QTextStream t( &errorFile ); |
352 | QString s; | 437 | QString s; |
353 | while ( !t.eof() ) | 438 | while ( !t.eof() ) |
354 | { // until end of file... | 439 | { // until end of file... |
355 | s += t.readLine(); // line of text excluding '\n' | 440 | s += t.readLine(); // line of text excluding '\n' |
356 | } | 441 | } |
357 | errorFile.close(); | 442 | errorFile.close(); |
358 | 443 | ||
359 | pErrDialog->m_textarea->setText( s ); | 444 | pErrDialog->m_textarea->setText( s ); |
360 | } | 445 | } |
361 | else | 446 | else |
362 | { | 447 | { |
363 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); | 448 | pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); |
364 | } | 449 | } |
365 | QPEApplication::execDialog( pErrDialog ); | 450 | QPEApplication::execDialog( pErrDialog ); |
366 | delete pErrDialog; | 451 | delete pErrDialog; |
367 | break; | 452 | break; |
368 | } | 453 | } |
369 | setCaption(tr("Backup and Restore.. Failed !!")); | 454 | setCaption(tr("Backup and Restore.. Failed !!")); |
370 | return; | 455 | return; |
371 | } | 456 | } |
372 | else | 457 | else |
373 | { | 458 | { |
374 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); | 459 | QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); |
375 | } | 460 | } |
376 | 461 | ||
377 | //write store-location | 462 | //write store-location |
378 | Config config( "BackupAndRestore" ); | 463 | Config config( "BackupAndRestore" ); |
379 | config.setGroup( "LastLocation" ); | 464 | config.setGroup( "LastLocation" ); |
380 | config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); | 465 | config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); |
381 | 466 | ||
382 | setCaption(tr("Backup and Restore")); | 467 | setCaption(tr("Backup and Restore")); |
383 | } | 468 | } |
384 | 469 | ||
385 | /*** | 470 | /*** |
386 | * Get a list of all of the files to backup. | 471 | * Get a list of all of the files to backup. |
387 | */ | 472 | */ |
388 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) | 473 | int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) |
389 | { | 474 | { |
390 | QListViewItem * currentItem; | 475 | QListViewItem * currentItem; |
391 | QString currentHome; | 476 | QString currentHome; |
392 | if(!parent) | 477 | if(!parent) |
393 | currentItem = backupList->firstChild(); | 478 | currentItem = backupList->firstChild(); |
394 | else | 479 | else |
395 | { | 480 | { |
396 | currentItem = parent->firstChild(); | 481 | currentItem = parent->firstChild(); |
397 | currentHome = parent->text(BACKUP_LOCATION); | 482 | currentHome = parent->text(BACKUP_LOCATION); |
398 | } | 483 | } |
399 | 484 | ||
400 | uint count = 0; | 485 | uint count = 0; |
401 | while( currentItem != 0 ) | 486 | while( currentItem != 0 ) |
402 | { | 487 | { |
403 | if(currentItem->text(HEADER_BACKUP) == "B" ) | 488 | if(currentItem->text(HEADER_BACKUP) == "B" ) |
404 | { | 489 | { |
405 | if(currentItem->childCount() == 0 ) | 490 | if(currentItem->childCount() == 0 ) |
406 | { | 491 | { |
407 | if(parent == NULL) | 492 | if(parent == NULL) |
408 | backupFiles += currentItem->text(BACKUP_LOCATION); | 493 | backupFiles += currentItem->text(BACKUP_LOCATION); |
409 | else | 494 | else |
410 | backupFiles += currentHome + currentItem->text(HEADER_NAME); | 495 | backupFiles += currentHome + currentItem->text(HEADER_NAME); |
411 | backupFiles += " "; | 496 | backupFiles += " "; |
412 | count++; | 497 | count++; |
413 | } | 498 | } |
414 | else | 499 | else |
415 | { | 500 | { |
416 | count += getBackupFiles(backupFiles, currentItem); | 501 | count += getBackupFiles(backupFiles, currentItem); |
417 | } | 502 | } |
418 | } | 503 | } |
419 | currentItem = currentItem->nextSibling(); | 504 | currentItem = currentItem->nextSibling(); |
420 | } | 505 | } |
421 | return count; | 506 | return count; |
422 | } | 507 | } |
423 | 508 | ||
424 | void BackupAndRestore::sourceDirChanged(int selection) | 509 | void BackupAndRestore::sourceDirChanged(int selection) |
425 | { | 510 | { |
426 | restoreList->clear(); | 511 | restoreList->clear(); |
427 | rescanFolder(backupLocations[restoreSource->text(selection)]); | 512 | rescanFolder(backupLocations[restoreSource->text(selection)]); |
428 | } | 513 | } |
429 | 514 | ||
430 | void BackupAndRestore::fileListUpdate() | 515 | void BackupAndRestore::fileListUpdate() |
431 | { | 516 | { |
432 | owarn << "void BackupAndRestore::fileListUpdate()" << oendl; | 517 | owarn << "void BackupAndRestore::fileListUpdate()" << oendl; |
433 | restoreList->clear(); | 518 | restoreList->clear(); |
434 | rescanFolder( backupLocations[restoreSource->currentText()] ); | 519 | rescanFolder( backupLocations[restoreSource->currentText()] ); |
435 | } | 520 | } |
436 | 521 | ||
437 | /** | 522 | /** |
438 | * Scans directory for any backup files. Will recursivly go down, | 523 | * Scans directory for any backup files. Will recursivly go down, |
439 | * but will not follow symlinks. | 524 | * but will not follow symlinks. |
440 | * @param directory - the directory to look in. | 525 | * @param directory - the directory to look in. |
441 | */ | 526 | */ |
442 | void BackupAndRestore::rescanFolder(QString directory) | 527 | void BackupAndRestore::rescanFolder(QString directory) |
443 | { | 528 | { |
444 | //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; | 529 | //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; |
445 | QDir d(directory); | 530 | QDir d(directory); |
446 | if(!d.exists()) | 531 | if(!d.exists()) |
447 | return; | 532 | return; |
448 | 533 | ||
449 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 534 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
450 | const QFileInfoList *list = d.entryInfoList(); | 535 | const QFileInfoList *list = d.entryInfoList(); |
451 | QFileInfoListIterator it( *list ); | 536 | QFileInfoListIterator it( *list ); |
452 | QFileInfo *file; | 537 | QFileInfo *file; |
453 | while ( (file=it.current()) ) | 538 | while ( (file=it.current()) ) |
454 | { // for each file... | 539 | { // for each file... |
455 | // If it is a dir and not .. or . then add it as a tab and go down. | 540 | // If it is a dir and not .. or . then add it as a tab and go down. |
456 | if(file->isDir()) | 541 | if(file->isDir()) |
457 | { | 542 | { |
458 | if(file->fileName() != ".." && file->fileName() != ".") | 543 | if(file->fileName() != ".." && file->fileName() != ".") |
459 | { | 544 | { |
460 | rescanFolder(directory + "/" + file->fileName()); | 545 | rescanFolder(directory + "/" + file->fileName()); |
461 | } | 546 | } |
462 | } | 547 | } |
463 | else | 548 | else |
464 | { | 549 | { |
465 | // If it is a backup file add to list. | 550 | // If it is a backup file add to list. |
466 | if(file->fileName().contains(EXTENSION)) | 551 | if(file->fileName().contains(EXTENSION)) |
467 | (void)new QListViewItem(restoreList, file->fileName()); | 552 | (void)new QListViewItem(restoreList, file->fileName()); |
468 | } | 553 | } |
469 | ++it; | 554 | ++it; |
470 | } | 555 | } |
471 | } | 556 | } |
472 | 557 | ||
473 | /** | 558 | /** |
474 | * Restore a backup file. | 559 | * Restore a backup file. |
475 | * Report errors or success | 560 | * Report errors or success |
476 | */ | 561 | */ |
477 | void BackupAndRestore::restore() | 562 | void BackupAndRestore::restore() |
478 | { | 563 | { |
479 | QListViewItem *restoreItem = restoreList->currentItem(); | 564 | QListViewItem *restoreItem = restoreList->currentItem(); |
480 | if(!restoreItem) | 565 | if(!restoreItem) |
481 | { | 566 | { |
482 | QMessageBox::critical(this, tr( "Message" ), | 567 | QMessageBox::critical(this, tr( "Message" ), |
483 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); | 568 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); |
484 | return; | 569 | return; |
485 | } | 570 | } |
486 | 571 | ||
487 | OWait *owait = new OWait(); | 572 | OWait *owait = new OWait(); |
488 | Global::statusMessage( tr( "Restore Backup..." ) ); | 573 | Global::statusMessage( tr( "Restore Backup..." ) ); |
489 | owait->show(); | 574 | owait->show(); |
490 | qApp->processEvents(); | 575 | qApp->processEvents(); |
491 | 576 | ||
492 | QString restoreFile = backupLocations[restoreSource->currentText()]; | 577 | QString restoreFile = backupLocations[restoreSource->currentText()]; |
493 | 578 | ||
494 | restoreFile += "/" + restoreItem->text(0); | 579 | restoreFile += "/" + restoreItem->text(0); |
495 | 580 | ||
496 | odebug << restoreFile << oendl; | 581 | odebug << restoreFile << oendl; |
497 | 582 | ||
498 | //check if backup file come from opie 1.0.x | 583 | //check if backup file come from opie 1.0.x |
499 | 584 | ||
500 | QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() ); | 585 | QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() ); |
501 | 586 | ||
502 | int r = system( commandLine ); | 587 | int r = system( commandLine ); |
503 | 588 | ||
504 | QString startDir; | 589 | QString startDir; |
505 | 590 | ||
506 | if( r != 0 ) //Applications/backup/exclude not found - old backup file | 591 | if( r != 0 ) //Applications/backup/exclude not found - old backup file |
507 | { | 592 | { |
508 | startDir = QString( "/" ); | 593 | startDir = QString( "/" ); |
509 | } else | 594 | } else |
510 | { | 595 | { |
511 | startDir = QDir::homeDirPath(); | 596 | startDir = QDir::homeDirPath(); |
512 | } | 597 | } |
513 | 598 | ||
514 | //unpack backup file | 599 | //unpack backup file |
515 | commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir ) | 600 | commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir ) |
516 | .arg( restoreFile.latin1() ) | 601 | .arg( restoreFile.latin1() ) |
517 | .arg( tempFileName.latin1() ); | 602 | .arg( tempFileName.latin1() ); |
518 | 603 | ||
519 | odebug << commandLine << oendl; | 604 | odebug << commandLine << oendl; |
520 | 605 | ||
521 | r = system( commandLine ); | 606 | r = system( commandLine ); |
522 | 607 | ||
523 | owait->hide(); | 608 | owait->hide(); |
524 | delete owait; | 609 | delete owait; |
525 | 610 | ||
526 | //error handling | 611 | //error handling |
527 | if(r != 0) | 612 | if(r != 0) |
528 | { | 613 | { |
529 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 614 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
530 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" | 615 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
531 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) | 616 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) |
532 | { | 617 | { |
533 | case 1: | 618 | case 1: |
534 | owarn << "Details pressed !" << oendl; | 619 | owarn << "Details pressed !" << oendl; |
535 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 620 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
536 | QFile errorFile( tempFileName ); | 621 | QFile errorFile( tempFileName ); |
537 | if ( errorFile.open(IO_ReadOnly) ) | 622 | if ( errorFile.open(IO_ReadOnly) ) |
538 | { | 623 | { |
539 | QTextStream t( &errorFile ); | 624 | QTextStream t( &errorFile ); |
540 | QString s; | 625 | QString s; |
541 | while ( !t.eof() ) | 626 | while ( !t.eof() ) |
542 | { // until end of file... | 627 | { // until end of file... |
543 | s += t.readLine(); // line of text excluding '\n' | 628 | s += t.readLine(); // line of text excluding '\n' |
544 | } | 629 | } |
545 | errorFile.close(); | 630 | errorFile.close(); |
546 | 631 | ||
547 | pErrDialog->m_textarea->setText( s ); | 632 | pErrDialog->m_textarea->setText( s ); |
548 | } | 633 | } |
549 | else | 634 | else |
550 | { | 635 | { |
551 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); | 636 | pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); |
552 | } | 637 | } |
553 | QPEApplication::execDialog( pErrDialog ); | 638 | QPEApplication::execDialog( pErrDialog ); |
554 | delete pErrDialog; | 639 | delete pErrDialog; |
555 | 640 | ||
556 | setCaption(tr("Backup and Restore.. Failed !!")); | 641 | setCaption(tr("Backup and Restore.. Failed !!")); |
557 | return; | 642 | return; |
558 | 643 | ||
559 | break; | 644 | break; |
560 | 645 | ||
561 | } | 646 | } |
562 | } | 647 | } |
563 | else | 648 | else |
564 | { | 649 | { |
565 | QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) ); | 650 | QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) ); |
566 | } | 651 | } |
567 | 652 | ||
568 | //write restore-location | 653 | //write restore-location |
569 | Config config( "BackupAndRestore" ); | 654 | Config config( "BackupAndRestore" ); |
570 | config.setGroup( "LastLocation" ); | 655 | config.setGroup( "LastLocation" ); |
571 | config.writeEntry( "LastRestoreLocation", restoreSource->currentText() ); | 656 | config.writeEntry( "LastRestoreLocation", restoreSource->currentText() ); |
572 | 657 | ||
573 | setCaption(tr("Backup and Restore")); | 658 | setCaption(tr("Backup and Restore")); |
574 | } | 659 | } |
575 | 660 | ||
576 | /** | 661 | /** |
577 | * Check for exclude in Applications/backup | 662 | * Check for exclude in Applications/backup |
578 | * If it does not exist, the function will create the file with *.bck as content | 663 | * If it does not exist, the function will create the file with *.bck as content |
579 | * The exclude_files is read by tar and will provide to exclude special files out from backup. | 664 | * The exclude_files is read by tar and will provide to exclude special files out from backup. |
580 | * e.g. alle *.bck files (backup-files) will not be backed up by default | 665 | * e.g. alle *.bck files (backup-files) will not be backed up by default |
581 | */ | 666 | */ |
582 | 667 | ||
583 | QString BackupAndRestore::getExcludeFile() | 668 | QString BackupAndRestore::getExcludeFile() |
584 | { | 669 | { |
585 | QString excludeFileName = Global::applicationFileName( "backup", "exclude" ); | 670 | QString excludeFileName = Global::applicationFileName( "backup", "exclude" ); |
586 | if ( !QFile::exists( excludeFileName ) ) | 671 | if ( !QFile::exists( excludeFileName ) ) |
587 | { | 672 | { |
588 | QFile excludeFile( excludeFileName); | 673 | QFile excludeFile( excludeFileName); |
589 | if ( excludeFile.open( IO_WriteOnly ) == true ) | 674 | if ( excludeFile.open( IO_WriteOnly ) == true ) |
590 | { | 675 | { |
591 | QTextStream writeStream( &excludeFile ); | 676 | QTextStream writeStream( &excludeFile ); |
592 | writeStream << "*.bck" << "\n"; | 677 | writeStream << "*.bck" << "\n"; |
593 | excludeFile.close(); | 678 | excludeFile.close(); |
594 | } | 679 | } |
595 | else | 680 | else |
596 | { | 681 | { |
597 | return QString::null; | 682 | return QString::null; |
598 | } | 683 | } |
599 | } | 684 | } |
600 | 685 | ||
601 | return excludeFileName; | 686 | return excludeFileName; |
602 | } | 687 | } |
603 | 688 | ||
604 | void BackupAndRestore::refreshLocations() | 689 | void BackupAndRestore::refreshLocations() |
605 | { | 690 | { |
606 | locationList->clear(); | 691 | locationList->clear(); |
607 | 692 | ||
608 | //todo: implement add locations | 693 | //todo: implement add locations |
609 | Config config( "BackupAndRestore" ); | 694 | Config config( "BackupAndRestore" ); |
610 | config.setGroup( "Locations" ); | 695 | config.setGroup( "Locations" ); |
611 | 696 | ||
612 | QStringList locations( config.readListEntry( "locations", '|' ) ); | 697 | QStringList locations( config.readListEntry( "locations", '|' ) ); |
613 | 698 | ||
614 | for ( QStringList::Iterator it = locations.begin(); it != locations.end(); ++it ) { | 699 | for ( QStringList::Iterator it = locations.begin(); it != locations.end(); ++it ) { |
615 | (void) new QListViewItem( locationList, *it ); | 700 | (void) new QListViewItem( locationList, *it ); |
616 | } | 701 | } |
617 | } | 702 | } |
618 | 703 | ||
619 | void BackupAndRestore::addLocation() | 704 | void BackupAndRestore::addLocation() |
620 | { | 705 | { |
621 | if ( ( !locationEdit->text().isEmpty() ) && | 706 | if ( ( !locationEdit->text().isEmpty() ) && |
622 | ( QDir( locationEdit->text() ).exists() ) ) | 707 | ( QDir( locationEdit->text() ).exists() ) ) |
623 | { | 708 | { |
624 | (void) new QListViewItem( locationList, locationEdit->text() ); | 709 | (void) new QListViewItem( locationList, locationEdit->text() ); |
625 | locationEdit->setText( "" ); | 710 | locationEdit->setText( "" ); |
626 | } | 711 | } |
627 | } | 712 | } |
628 | 713 | ||
629 | void BackupAndRestore::removeLocation() | 714 | void BackupAndRestore::removeLocation() |
630 | { | 715 | { |
631 | if ( locationList->selectedItem() ) | 716 | if ( locationList->selectedItem() ) |
632 | { | 717 | { |
633 | delete( locationList->selectedItem() ); | 718 | delete( locationList->selectedItem() ); |
634 | } | 719 | } |
635 | } | 720 | } |
636 | 721 | ||
637 | void BackupAndRestore::saveLocations() | 722 | void BackupAndRestore::saveLocations() |
638 | { | 723 | { |
639 | Config config("BackupAndRestore"); | 724 | Config config("BackupAndRestore"); |
640 | config.setGroup("Locations"); | 725 | config.setGroup("Locations"); |
641 | 726 | ||
642 | QStringList locations; | 727 | QStringList locations; |
643 | for ( QListViewItemIterator it( locationList ); it.current(); ++it ) | 728 | for ( QListViewItemIterator it( locationList ); it.current(); ++it ) |
644 | { | 729 | { |
645 | locations.append( it.current()->text( 0 ) ); | 730 | locations.append( it.current()->text( 0 ) ); |
646 | } | 731 | } |
647 | config.writeEntry( "locations", locations, '|' ); | 732 | config.writeEntry( "locations", locations, '|' ); |
648 | 733 | ||
649 | refreshBackupLocations(); | 734 | refreshBackupLocations(); |
650 | } | 735 | } |
651 | 736 | ||
652 | void BackupAndRestore::selectLocation() | 737 | void BackupAndRestore::selectLocation() |
653 | { | 738 | { |
654 | QString location = OFileDialog::getDirectory( OFileSelector::DIRECTORYSELECTOR ); | 739 | QString location = OFileDialog::getDirectory( OFileSelector::DIRECTORYSELECTOR ); |
655 | if ( !location.isEmpty() ) | 740 | if ( !location.isEmpty() ) |
656 | { | 741 | { |
657 | locationEdit->setText( location ); | 742 | locationEdit->setText( location ); |
658 | } | 743 | } |
659 | } | 744 | } |
660 | 745 | ||
661 | // backuprestore.cpp | 746 | // backuprestore.cpp |
662 | 747 | ||