summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp62
1 files changed, 38 insertions, 24 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 5776f3c..fb892d9 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -19,20 +19,28 @@
19 19
20#define EXTENSION ".bck" 20#define EXTENSION ".bck"
21 21
22BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) : BackupAndRestoreBase(parent, name){ 22BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name)
23 : BackupAndRestoreBase(parent, name){
23 this->showMaximized(); 24 this->showMaximized();
24 backupList->header()->hide(); 25 backupList->header()->hide();
25 restoreList->header()->hide(); 26 restoreList->header()->hide();
26 connect(backupButton, SIGNAL(clicked()), this, SLOT(backupPressed())); 27 connect(backupButton, SIGNAL(clicked()),
27 connect(restoreButton, SIGNAL(clicked()), this, SLOT(restore())); 28 this, SLOT(backupPressed()));
28 connect(backupList, SIGNAL(clicked( QListViewItem * )), this, SLOT(selectItem(QListViewItem*))); 29 connect(restoreButton, SIGNAL(clicked()),
29 connect(restoreSource, SIGNAL(activated( int )), this, SLOT(sourceDirChanged(int))); 30 this, SLOT(restore()));
31 connect(backupList, SIGNAL(clicked( QListViewItem * )),
32 this, SLOT(selectItem(QListViewItem*)));
33 connect(restoreSource, SIGNAL(activated( int )),
34 this, SLOT(sourceDirChanged(int)));
30 35
31 systemSettings = new QListViewItem(backupList, "System Settings", "", "/home/etc"); 36 systemSettings = new QListViewItem(backupList, "System Settings", "",
37 "/etc");
32 selectItem(systemSettings); 38 selectItem(systemSettings);
33 applicationSettings = new QListViewItem(backupList, "Application Settings", "", QDir::homeDirPath() + "/Settings/"); 39 applicationSettings = new QListViewItem(backupList, "Application Settings", "",
40 QDir::homeDirPath() + "/Settings/");
34 selectItem(applicationSettings); 41 selectItem(applicationSettings);
35 documents= new QListViewItem(backupList, "Documents", "", QDir::homeDirPath() + "/Documents/"); 42 documents= new QListViewItem(backupList, "Documents", "",
43 QDir::homeDirPath() + "/Documents/");
36 selectItem(documents); 44 selectItem(documents);
37 45
38 scanForApplicationSettings(); 46 scanForApplicationSettings();
@@ -41,14 +49,16 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) : BackupA
41 config.setGroup("General"); 49 config.setGroup("General");
42 int totalLocations = config.readNumEntry("totalLocations",0); 50 int totalLocations = config.readNumEntry("totalLocations",0);
43 51
52//todo make less static here and use Storage class to get infos
44 if(totalLocations == 0){ 53 if(totalLocations == 0){
45 backupLocations.insert("Documents", "/home/root/Documents"); 54 backupLocations.insert("Documents", "/root/Documents");
46 backupLocations.insert("CF", "/mnt/cf"); 55 backupLocations.insert("CF", "/mnt/cf");
47 backupLocations.insert("SD", "/mnt/card"); 56 backupLocations.insert("SD", "/mnt/card");
48 } 57 }
49 else{ 58 else{
50 for(int i = 0; i < totalLocations; i++){ 59 for(int i = 0; i < totalLocations; i++){
51 backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)), config.readEntry(QString("backupLocation_%1").arg(i))); 60 backupLocations.insert(config.readEntry(QString("backupLocationName_%1").arg(i)),
61 config.readEntry(QString("backupLocation_%1").arg(i)));
52 } 62 }
53 } 63 }
54 QMap<QString, QString>::Iterator it; 64 QMap<QString, QString>::Iterator it;
@@ -68,7 +78,7 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) : BackupA
68 78
69 QList<QListViewItem> list; 79 QList<QListViewItem> list;
70 getAllItems(backupList->firstChild(), list); 80 getAllItems(backupList->firstChild(), list);
71 81
72 for(uint i = 0; i < list.count(); i++){ 82 for(uint i = 0; i < list.count(); i++){
73 QString text = list.at(i)->text(HEADER_NAME); 83 QString text = list.at(i)->text(HEADER_NAME);
74 for(uint i2 = 0; i2 < dontBackupList.count(); i2++){ 84 for(uint i2 = 0; i2 < dontBackupList.count(); i2++){
@@ -83,7 +93,7 @@ BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name) : BackupA
83BackupAndRestore::~BackupAndRestore(){ 93BackupAndRestore::~BackupAndRestore(){
84 QList<QListViewItem> list; 94 QList<QListViewItem> list;
85 getAllItems(backupList->firstChild(), list); 95 getAllItems(backupList->firstChild(), list);
86 96
87 Config config("BackupAndRestore"); 97 Config config("BackupAndRestore");
88 config.setGroup("DontBackup"); 98 config.setGroup("DontBackup");
89 config.clearGroup(); 99 config.clearGroup();
@@ -150,8 +160,9 @@ void BackupAndRestore::scanForApplicationSettings(){
150void BackupAndRestore::backupPressed(){ 160void BackupAndRestore::backupPressed(){
151 QString backupFiles; 161 QString backupFiles;
152 if(getBackupFiles(backupFiles, NULL) == 0){ 162 if(getBackupFiles(backupFiles, NULL) == 0){
153 QMessageBox::critical(this, "Message", "No items selected.",QString("Ok") ); 163 QMessageBox::critical(this, "Message",
154 return; 164 "No items selected.",QString("Ok") );
165 return;
155 } 166 }
156 167
157 QString outputFile = backupLocations[storeToLocation->currentText()]; 168 QString outputFile = backupLocations[storeToLocation->currentText()];
@@ -171,7 +182,7 @@ void BackupAndRestore::backupPressed(){
171 int r = system(QString("tar -c %1 | gzip --best > %2").arg(backupFiles).arg(outputFile).latin1()); 182 int r = system(QString("tar -c %1 | gzip --best > %2").arg(backupFiles).arg(outputFile).latin1());
172 if(r != 0){ 183 if(r != 0){
173 QMessageBox::critical(this, "Message", "Backup Failed.",QString("Ok") ); 184 QMessageBox::critical(this, "Message", "Backup Failed.",QString("Ok") );
174 return; 185 return;
175 } 186 }
176 else{ 187 else{
177 QMessageBox::critical(this, "Message", "Backup Successfull.",QString("Ok") ); 188 QMessageBox::critical(this, "Message", "Backup Successfull.",QString("Ok") );
@@ -196,11 +207,11 @@ int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent
196 if(currentItem->text(HEADER_BACKUP) == "B" ){ 207 if(currentItem->text(HEADER_BACKUP) == "B" ){
197 if(currentItem->childCount() == 0 ){ 208 if(currentItem->childCount() == 0 ){
198 if(parent == NULL) 209 if(parent == NULL)
199 backupFiles += currentItem->text(BACKUP_LOCATION); 210 backupFiles += currentItem->text(BACKUP_LOCATION);
200 else 211 else
201 backupFiles += currentHome + currentItem->text(HEADER_NAME); 212 backupFiles += currentHome + currentItem->text(HEADER_NAME);
202 backupFiles += " "; 213 backupFiles += " ";
203 count++; 214 count++;
204 } 215 }
205 else{ 216 else{
206 count += getBackupFiles(backupFiles, currentItem); 217 count += getBackupFiles(backupFiles, currentItem);
@@ -235,7 +246,7 @@ void BackupAndRestore::rescanFolder(QString directory){
235 // 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.
236 if(file->isDir()){ 247 if(file->isDir()){
237 if(file->fileName() != ".." && file->fileName() != ".") { 248 if(file->fileName() != ".." && file->fileName() != ".") {
238 rescanFolder(directory + "/" + file->fileName()); 249 rescanFolder(directory + "/" + file->fileName());
239 } 250 }
240 } 251 }
241 else{ 252 else{
@@ -254,8 +265,9 @@ void BackupAndRestore::rescanFolder(QString directory){
254void BackupAndRestore::restore(){ 265void BackupAndRestore::restore(){
255 QListViewItem *restoreItem = restoreList->currentItem(); 266 QListViewItem *restoreItem = restoreList->currentItem();
256 if(!restoreItem){ 267 if(!restoreItem){
257 QMessageBox::critical(this, "Message", "Please select something to restore.",QString("Ok") ); 268 QMessageBox::critical(this, "Message",
258 return; 269 "Please select something to restore.",QString("Ok") );
270 return;
259 } 271 }
260 QString restoreFile = backupLocations[restoreSource->currentText()]; 272 QString restoreFile = backupLocations[restoreSource->currentText()];
261 273
@@ -263,10 +275,12 @@ void BackupAndRestore::restore(){
263 275
264 int r = system(QString("tar -C / -zxf %1").arg(restoreFile).latin1()); 276 int r = system(QString("tar -C / -zxf %1").arg(restoreFile).latin1());
265 if(r != 0){ 277 if(r != 0){
266 QMessageBox::critical(this, "Message", "Restore Failed.",QString("Ok") ); 278 QMessageBox::critical(this, "Message",
279 "Restore Failed.",QString("Ok") );
267 } 280 }
268 else{ 281 else{
269 QMessageBox::critical(this, "Message", "Restore Successfull.",QString("Ok") ); 282 QMessageBox::critical(this, "Message",
283 "Restore Successfull.",QString("Ok") );
270 } 284 }
271} 285}
272 286