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,410 +1,495 @@ | |||
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); |