summaryrefslogtreecommitdiff
authorzecke <zecke>2004-01-10 15:12:11 (UTC)
committer zecke <zecke>2004-01-10 15:12:11 (UTC)
commit68376661758627c300aa54eee7573953134b2143 (patch) (unidiff)
treed8a4254470373efd863d768b01f96a481a4d8a2a
parentf4cd001fb21509caff3b83fc620ac092cb5f3913 (diff)
downloadopie-68376661758627c300aa54eee7573953134b2143.zip
opie-68376661758627c300aa54eee7573953134b2143.tar.gz
opie-68376661758627c300aa54eee7573953134b2143.tar.bz2
-First follow Qt naming style
-use const -Fix Doxygen comment. If above a method better skip the @fn -Update backuprestore to use the new names TODO: Alter filename to ostorageinfo
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/ostorageinfo.cpp8
-rw-r--r--libopie2/opiecore/ostorageinfo.h6
-rw-r--r--noncore/settings/backup/backuprestore.cpp12
3 files changed, 12 insertions, 14 deletions
diff --git a/libopie2/opiecore/ostorageinfo.cpp b/libopie2/opiecore/ostorageinfo.cpp
index cf9dc6c..6712282 100644
--- a/libopie2/opiecore/ostorageinfo.cpp
+++ b/libopie2/opiecore/ostorageinfo.cpp
@@ -1,94 +1,92 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de> 3              Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include <opie2/ostorage.h> 30#include <opie2/ostorage.h>
31 31
32OStorageInfo::OStorageInfo( QObject *parent ) 32OStorageInfo::OStorageInfo( QObject *parent )
33 : StorageInfo( parent ) 33 : StorageInfo( parent )
34{ 34{
35} 35}
36 36
37OStorageInfo::~OStorageInfo() 37OStorageInfo::~OStorageInfo()
38{ 38{
39} 39}
40 40
41QString OStorageInfo::getCfPath() 41QString OStorageInfo::cfPath()const
42{ 42{
43 QString r = ""; 43 QString r = "";
44 44
45 for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) 45 for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i)
46 { 46 {
47 if ( (*i)->disk().left( 8 ) == "/dev/hda" ) 47 if ( (*i)->disk().left( 8 ) == "/dev/hda" )
48 { 48 {
49 r = (*i)->path(); 49 r = (*i)->path();
50 break; 50 break;
51 } 51 }
52 } 52 }
53 return r; 53 return r;
54} 54}
55 55
56/*! 56/*!
57* @fn QString StorageInfo::getSdPath()
58* @brief returns the Mount-Path of Sd Card 57* @brief returns the Mount-Path of Sd Card
59* 58*
60*/ 59*/
61QString OStorageInfo::getSdPath() 60QString OStorageInfo::sdPath()const
62{ 61{
63 QString r = ""; 62 QString r = "";
64 63
65 for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) 64 for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i)
66 { 65 {
67 if ( (*i)->disk().left( 9 ) == "/dev/mmcd" ) 66 if ( (*i)->disk().left( 9 ) == "/dev/mmcd" )
68 { 67 {
69 r = (*i)->path(); 68 r = (*i)->path();
70 break; 69 break;
71 } 70 }
72 } 71 }
73 return r; 72 return r;
74} 73}
75 74
76/*! 75/*!
77* @fn QString StorageInfo::getMmcPath()
78* @brief returns the Mount-Path of Mmc Card 76* @brief returns the Mount-Path of Mmc Card
79* 77*
80*/ 78*/
81QString OStorageInfo::getMmcPath() 79QString OStorageInfo::mmcPath()const
82{ 80{
83 QString r = ""; 81 QString r = "";
84 82
85 for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) 83 for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i)
86 { 84 {
87 if ( (*i)->disk().left( 14 ) == "/dev/mmc/part1" ) 85 if ( (*i)->disk().left( 14 ) == "/dev/mmc/part1" )
88 { 86 {
89 r = (*i)->path(); 87 r = (*i)->path();
90 break; 88 break;
91 } 89 }
92 } 90 }
93 return r; 91 return r;
94} 92}
diff --git a/libopie2/opiecore/ostorageinfo.h b/libopie2/opiecore/ostorageinfo.h
index ba87ff4..9b61a2e 100644
--- a/libopie2/opiecore/ostorageinfo.h
+++ b/libopie2/opiecore/ostorageinfo.h
@@ -1,49 +1,49 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de> 3              Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef OSTORAGE_H 30#ifndef OSTORAGE_H
31#define OSTORAGE_H 31#define OSTORAGE_H
32 32
33#include <qpe/storage.h> 33#include <qpe/storage.h>
34 34
35class OStorageInfo : public StorageInfo 35class OStorageInfo : public StorageInfo
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 38
39 public: 39 public:
40public: 40public:
41 OStorageInfo( QObject *parent=0 ); 41 OStorageInfo( QObject *parent=0 );
42 ~OStorageInfo(); 42 ~OStorageInfo();
43 43
44 QString getCfPath(); 44 QString cfPath()const;
45 QString getSdPath(); 45 QString sdPath()const;
46 QString getMmcPath(); 46 QString mmcPath()const;
47}; 47};
48 48
49#endif // OSTORAGE_H 49#endif // OSTORAGE_H
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index eb69a70..2d79384 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -1,468 +1,468 @@
1 1
2#include "backuprestore.h" 2#include "backuprestore.h"
3//#include "output.h" 3//#include "output.h"
4#include "errordialog.h" 4#include "errordialog.h"
5 5
6#include <qapplication.h> 6#include <qapplication.h>
7#include <qmultilineedit.h> 7#include <qmultilineedit.h>
8 8
9#include <qdir.h> 9#include <qdir.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qfileinfo.h> 11#include <qfileinfo.h>
12#include <qlistview.h> 12#include <qlistview.h>
13#include <qpushbutton.h> 13#include <qpushbutton.h>
14#include <qheader.h> 14#include <qheader.h>
15#include <qpe/resource.h> 15#include <qpe/resource.h>
16#include <qpe/config.h> 16#include <qpe/config.h>
17#include <qmessagebox.h> 17#include <qmessagebox.h>
18#include <qcombobox.h> 18#include <qcombobox.h>
19#include <qlist.h> 19#include <qlist.h>
20#include <stdlib.h> 20#include <stdlib.h>
21#include <qregexp.h> 21#include <qregexp.h>
22#include <qtextstream.h> 22#include <qtextstream.h>
23#include <qtextview.h> 23#include <qtextview.h>
24#include <opie2/ostorage.h> 24#include <opie2/ostorage.h>
25 25
26#include <errno.h> 26#include <errno.h>
27#include <stdlib.h> 27#include <stdlib.h>
28#include <unistd.h> 28#include <unistd.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <dirent.h> 30#include <dirent.h>
31 31
32#define HEADER_NAME 0 32#define HEADER_NAME 0
33#define HEADER_BACKUP 1 33#define HEADER_BACKUP 1
34#define BACKUP_LOCATION 2 34#define BACKUP_LOCATION 2
35 35
36#define EXTENSION ".bck" 36#define EXTENSION ".bck"
37 37
38const QString tempFileName = "/tmp/backup.err"; 38const QString tempFileName = "/tmp/backup.err";
39 39
40 40
41BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) 41BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl)
42 : BackupAndRestoreBase(parent, name, fl) 42 : BackupAndRestoreBase(parent, name, fl)
43{ 43{
44 this->showMaximized(); 44 this->showMaximized();
45 backupList->header()->hide(); 45 backupList->header()->hide();
46 restoreList->header()->hide(); 46 restoreList->header()->hide();
47 connect(backupButton, SIGNAL(clicked()), 47 connect(backupButton, SIGNAL(clicked()),
48 this, SLOT(backup())); 48 this, SLOT(backup()));
49 connect(restoreButton, SIGNAL(clicked()), 49 connect(restoreButton, SIGNAL(clicked()),
50 this, SLOT(restore())); 50 this, SLOT(restore()));
51 connect(backupList, SIGNAL(clicked( QListViewItem * )), 51 connect(backupList, SIGNAL(clicked( QListViewItem * )),
52 this, SLOT(selectItem(QListViewItem*))); 52 this, SLOT(selectItem(QListViewItem*)));
53 connect(restoreSource, SIGNAL(activated( int )), 53 connect(restoreSource, SIGNAL(activated( int )),
54 this, SLOT(sourceDirChanged(int))); 54 this, SLOT(sourceDirChanged(int)));
55 connect(updateList, SIGNAL(clicked()), 55 connect(updateList, SIGNAL(clicked()),
56 this, SLOT( fileListUpdate())); 56 this, SLOT( fileListUpdate()));
57 57
58 //add directorys for backing up 58 //add directorys for backing up
59 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); 59 applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/");
60 selectItem(applicationSettings); 60 selectItem(applicationSettings);
61 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); 61 applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/");
62 selectItem(applicationSettings); 62 selectItem(applicationSettings);
63 documents= new QListViewItem(backupList, "Documents", "", "Documents/"); 63 documents= new QListViewItem(backupList, "Documents", "", "Documents/");
64 selectItem(documents); 64 selectItem(documents);
65 65
66 scanForApplicationSettings(); 66 scanForApplicationSettings();
67 67
68 OStorageInfo storage; 68 OStorageInfo storage;
69 69
70 backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" ); 70 backupLocations.insert( "Documents", QDir::homeDirPath() + "/Documents" );
71 if ( storage.hasCf() ) 71 if ( storage.hasCf() )
72 { 72 {
73 backupLocations.insert( "CF", storage.getCfPath() ); 73 backupLocations.insert( "CF", storage.cfPath() );
74 qDebug( "Cf Path: " + storage.getCfPath() ); 74 qDebug( "Cf Path: " + storage.cfPath() );
75 } 75 }
76 if ( storage.hasSd() ) 76 if ( storage.hasSd() )
77 { 77 {
78 backupLocations.insert( "SD", storage.getSdPath() ); 78 backupLocations.insert( "SD", storage.sdPath() );
79 qDebug( " Sd Path: " + storage.getSdPath() ); 79 qDebug( " Sd Path: " + storage.sdPath() );
80 } 80 }
81 if ( storage.hasMmc() ) 81 if ( storage.hasMmc() )
82 { 82 {
83 backupLocations.insert( "MMC", storage.getMmcPath() ); 83 backupLocations.insert( "MMC", storage.mmcPath() );
84 qDebug( "Mmc Path: " + storage.getMmcPath() ); 84 qDebug( "Mmc Path: " + storage.mmcPath() );
85 } 85 }
86 86
87 Config config("BackupAndRestore"); 87 Config config("BackupAndRestore");
88 //read last locations 88 //read last locations
89 config.setGroup("LastLocation"); 89 config.setGroup("LastLocation");
90 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" ); 90 QString lastStoreLocation = config.readEntry( "LastStoreLocation", "" );
91 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" ); 91 QString lastRestoreLocation = config.readEntry( "LastRestoreLocation", "" );
92 int locationIndex = 0; 92 int locationIndex = 0;
93 93
94 QMap<QString, QString>::Iterator it; 94 QMap<QString, QString>::Iterator it;
95 for( it = backupLocations.begin(); it != backupLocations.end(); ++it ) 95 for( it = backupLocations.begin(); it != backupLocations.end(); ++it )
96 { 96 {
97 storeToLocation->insertItem(it.key()); 97 storeToLocation->insertItem(it.key());
98 restoreSource->insertItem(it.key()); 98 restoreSource->insertItem(it.key());
99 99
100 //check for last locations 100 //check for last locations
101 if ( it.key() == lastStoreLocation ) 101 if ( it.key() == lastStoreLocation )
102 storeToLocation->setCurrentItem( locationIndex ); 102 storeToLocation->setCurrentItem( locationIndex );
103 if ( it.key() == lastRestoreLocation ) 103 if ( it.key() == lastRestoreLocation )
104 restoreSource->setCurrentItem( locationIndex ); 104 restoreSource->setCurrentItem( locationIndex );
105 locationIndex++; 105 locationIndex++;
106 } 106 }
107 107
108 // Read the list of items to ignore. 108 // Read the list of items to ignore.
109 QList<QString> dontBackupList; 109 QList<QString> dontBackupList;
110 dontBackupList.setAutoDelete(true); 110 dontBackupList.setAutoDelete(true);
111 config.setGroup("DontBackup"); 111 config.setGroup("DontBackup");
112 int total = config.readNumEntry("Total", 0); 112 int total = config.readNumEntry("Total", 0);
113 for(int i = 0; i < total; i++) 113 for(int i = 0; i < total; i++)
114 { 114 {
115 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); 115 dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), "")));
116 } 116 }
117 117
118 QList<QListViewItem> list; 118 QList<QListViewItem> list;
119 getAllItems(backupList->firstChild(), list); 119 getAllItems(backupList->firstChild(), list);
120 120
121 for(uint i = 0; i < list.count(); i++) 121 for(uint i = 0; i < list.count(); i++)
122 { 122 {
123 QString text = list.at(i)->text(HEADER_NAME); 123 QString text = list.at(i)->text(HEADER_NAME);
124 for(uint i2 = 0; i2 < dontBackupList.count(); i2++) 124 for(uint i2 = 0; i2 < dontBackupList.count(); i2++)
125 { 125 {
126 if(*dontBackupList.at(i2) == text) 126 if(*dontBackupList.at(i2) == text)
127 { 127 {
128 selectItem(list.at(i)); 128 selectItem(list.at(i));
129 break; 129 break;
130 } 130 }
131 } 131 }
132 } 132 }
133} 133}
134 134
135BackupAndRestore::~BackupAndRestore() 135BackupAndRestore::~BackupAndRestore()
136{ 136{
137 QList<QListViewItem> list; 137 QList<QListViewItem> list;
138 getAllItems(backupList->firstChild(), list); 138 getAllItems(backupList->firstChild(), list);
139 139
140 Config config("BackupAndRestore"); 140 Config config("BackupAndRestore");
141 config.setGroup("DontBackup"); 141 config.setGroup("DontBackup");
142 config.clearGroup(); 142 config.clearGroup();
143 143
144 int count = 0; 144 int count = 0;
145 for(uint i = 0; i < list.count(); i++) 145 for(uint i = 0; i < list.count(); i++)
146 { 146 {
147 if(list.at(i)->text(HEADER_BACKUP) == "") 147 if(list.at(i)->text(HEADER_BACKUP) == "")
148 { 148 {
149 config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME)); 149 config.writeEntry(QString("%1").arg(count), list.at(i)->text(HEADER_NAME));
150 count++; 150 count++;
151 } 151 }
152 } 152 }
153 config.writeEntry("Total", count); 153 config.writeEntry("Total", count);
154 154
155 // Remove Temp File 155 // Remove Temp File
156 if ( QFile::exists( tempFileName ) ) 156 if ( QFile::exists( tempFileName ) )
157 QFile::remove( tempFileName ); 157 QFile::remove( tempFileName );
158} 158}
159 159
160QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list) 160QList<QListViewItem> BackupAndRestore::getAllItems(QListViewItem *item, QList<QListViewItem> &list)
161{ 161{
162 while(item) 162 while(item)
163 { 163 {
164 if(item->childCount() > 0) 164 if(item->childCount() > 0)
165 getAllItems(item->firstChild(), list); 165 getAllItems(item->firstChild(), list);
166 list.append(item); 166 list.append(item);
167 item = item->nextSibling(); 167 item = item->nextSibling();
168 } 168 }
169 return list; 169 return list;
170} 170}
171 171
172/** 172/**
173 * Selects and unselects the item by setting the HEADER_BACKUP to B or !. 173 * Selects and unselects the item by setting the HEADER_BACKUP to B or !.
174 * and changing the icon to match 174 * and changing the icon to match
175 * @param currentItem the item to swich the selection choice. 175 * @param currentItem the item to swich the selection choice.
176 */ 176 */
177void BackupAndRestore::selectItem(QListViewItem *currentItem) 177void BackupAndRestore::selectItem(QListViewItem *currentItem)
178{ 178{
179 if(!currentItem) 179 if(!currentItem)
180 return; 180 return;
181 181
182 if(currentItem->text(HEADER_BACKUP) == "B") 182 if(currentItem->text(HEADER_BACKUP) == "B")
183 { 183 {
184 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); 184 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null"));
185 currentItem->setText(HEADER_BACKUP, ""); 185 currentItem->setText(HEADER_BACKUP, "");
186 } 186 }
187 else 187 else
188 { 188 {
189 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); 189 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check"));
190 currentItem->setText(HEADER_BACKUP, "B"); 190 currentItem->setText(HEADER_BACKUP, "B");
191 } 191 }
192} 192}
193 193
194void BackupAndRestore::scanForApplicationSettings() 194void BackupAndRestore::scanForApplicationSettings()
195{ 195{
196 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); 196 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) );
197 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); 197 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
198 const QFileInfoList *list = d.entryInfoList(); 198 const QFileInfoList *list = d.entryInfoList();
199 QFileInfoListIterator it( *list ); 199 QFileInfoListIterator it( *list );
200 QFileInfo *fi; 200 QFileInfo *fi;
201 while ( (fi=it.current()) ) 201 while ( (fi=it.current()) )
202 { 202 {
203 //qDebug((d.path()+"/"+fi->fileName()).latin1()); 203 //qDebug((d.path()+"/"+fi->fileName()).latin1());
204 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) 204 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) )
205 { 205 {
206 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); 206 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName());
207 selectItem(newItem); 207 selectItem(newItem);
208 } 208 }
209 ++it; 209 ++it;
210 } 210 }
211} 211}
212 212
213/** 213/**
214 * The "Backup" button has been pressed. Get a list of all of the files that 214 * The "Backup" button has been pressed. Get a list of all of the files that
215 * should be backed up. If there are no files, emit and error and exit. 215 * should be backed up. If there are no files, emit and error and exit.
216 * Determine the file name to store the backup in. Backup the file(s) using 216 * Determine the file name to store the backup in. Backup the file(s) using
217 * tar and gzip --best. Report failure or success 217 * tar and gzip --best. Report failure or success
218 */ 218 */
219void BackupAndRestore::backup() 219void BackupAndRestore::backup()
220{ 220{
221 QString backupFiles; 221 QString backupFiles;
222 if(getBackupFiles(backupFiles, NULL) == 0) 222 if(getBackupFiles(backupFiles, NULL) == 0)
223 { 223 {
224 QMessageBox::critical(this, "Message", 224 QMessageBox::critical(this, "Message",
225 "No items selected.",QString("Ok") ); 225 "No items selected.",QString("Ok") );
226 return; 226 return;
227 } 227 }
228 228
229 setCaption(tr("Backup and Restore... working...")); 229 setCaption(tr("Backup and Restore... working..."));
230 QString outputFile = backupLocations[storeToLocation->currentText()]; 230 QString outputFile = backupLocations[storeToLocation->currentText()];
231 231
232 QDateTime datetime = QDateTime::currentDateTime(); 232 QDateTime datetime = QDateTime::currentDateTime();
233 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + 233 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
234 QString::number( datetime.date().day() ).rightJustify(2, '0'); 234 QString::number( datetime.date().day() ).rightJustify(2, '0');
235 235
236 outputFile += "/" + dateString; 236 outputFile += "/" + dateString;
237 237
238 QString t = outputFile; 238 QString t = outputFile;
239 int c = 1; 239 int c = 1;
240 while(QFile::exists(outputFile + EXTENSION)) 240 while(QFile::exists(outputFile + EXTENSION))
241 { 241 {
242 outputFile = t + QString("%1").arg(c); 242 outputFile = t + QString("%1").arg(c);
243 c++; 243 c++;
244 } 244 }
245 245
246 // We execute tar and compressing its output with gzip.. 246 // We execute tar and compressing its output with gzip..
247 // The error output will be written into a temp-file which could be provided 247 // The error output will be written into a temp-file which could be provided
248 // for debugging.. 248 // for debugging..
249 qDebug( "Storing file: %s", outputFile.latin1() ); 249 qDebug( "Storing file: %s", outputFile.latin1() );
250 outputFile += EXTENSION; 250 outputFile += EXTENSION;
251 251
252 QString commandLine = QString( "(tar -C %1 -c %2 | gzip > %3 ) 2> %4" ).arg( QDir::homeDirPath() ) 252 QString commandLine = QString( "(tar -C %1 -c %2 | gzip > %3 ) 2> %4" ).arg( QDir::homeDirPath() )
253 .arg( backupFiles ) 253 .arg( backupFiles )
254 .arg( outputFile.latin1() ) 254 .arg( outputFile.latin1() )
255 .arg( tempFileName.latin1() ); 255 .arg( tempFileName.latin1() );
256 256
257 qDebug( commandLine ); 257 qDebug( commandLine );
258 258
259 int r = system( commandLine ); 259 int r = system( commandLine );
260 260
261 if(r != 0) 261 if(r != 0)
262 { 262 {
263 perror("Error: "); 263 perror("Error: ");
264 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 264 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
265 265
266 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" 266 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n"
267 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) 267 + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) )
268 { 268 {
269 269
270 case 1: 270 case 1:
271 qWarning("Details pressed !"); 271 qWarning("Details pressed !");
272 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 272 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
273 QFile errorFile( tempFileName ); 273 QFile errorFile( tempFileName );
274 if ( errorFile.open(IO_ReadOnly) ) 274 if ( errorFile.open(IO_ReadOnly) )
275 { 275 {
276 QTextStream t( &errorFile ); 276 QTextStream t( &errorFile );
277 QString s; 277 QString s;
278 while ( !t.eof() ) 278 while ( !t.eof() )
279 { // until end of file... 279 { // until end of file...
280 s += t.readLine(); // line of text excluding '\n' 280 s += t.readLine(); // line of text excluding '\n'
281 } 281 }
282 errorFile.close(); 282 errorFile.close();
283 283
284 pErrDialog->m_textarea->setText( s ); 284 pErrDialog->m_textarea->setText( s );
285 } 285 }
286 else 286 else
287 { 287 {
288 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" ); 288 pErrDialog->m_textarea->setText( "Unable to open File: /tmp/backup.er" );
289 } 289 }
290 pErrDialog->showMaximized(); 290 pErrDialog->showMaximized();
291 pErrDialog->exec(); 291 pErrDialog->exec();
292 delete pErrDialog; 292 delete pErrDialog;
293 break; 293 break;
294 } 294 }
295 setCaption(tr("Backup and Restore.. Failed !!")); 295 setCaption(tr("Backup and Restore.. Failed !!"));
296 return; 296 return;
297 } 297 }
298 else 298 else
299 { 299 {
300 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) ); 300 QMessageBox::information(this, tr( "Message" ), tr( "Backup Successful." ), QString(tr( "Ok" ) ) );
301 301
302 } 302 }
303 303
304 //write store-location 304 //write store-location
305 Config config( "BackupAndRestore" ); 305 Config config( "BackupAndRestore" );
306 config.setGroup( "LastLocation" ); 306 config.setGroup( "LastLocation" );
307 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() ); 307 config.writeEntry( "LastStoreLocation", storeToLocation->currentText() );
308 308
309 setCaption(tr("Backup and Restore")); 309 setCaption(tr("Backup and Restore"));
310} 310}
311 311
312/*** 312/***
313 * Get a list of all of the files to backup. 313 * Get a list of all of the files to backup.
314 */ 314 */
315int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent) 315int BackupAndRestore::getBackupFiles(QString &backupFiles, QListViewItem *parent)
316{ 316{
317 QListViewItem * currentItem; 317 QListViewItem * currentItem;
318 QString currentHome; 318 QString currentHome;
319 if(!parent) 319 if(!parent)
320 currentItem = backupList->firstChild(); 320 currentItem = backupList->firstChild();
321 else 321 else
322 { 322 {
323 currentItem = parent->firstChild(); 323 currentItem = parent->firstChild();
324 currentHome = parent->text(BACKUP_LOCATION); 324 currentHome = parent->text(BACKUP_LOCATION);
325 } 325 }
326 326
327 uint count = 0; 327 uint count = 0;
328 while( currentItem != 0 ) 328 while( currentItem != 0 )
329 { 329 {
330 if(currentItem->text(HEADER_BACKUP) == "B" ) 330 if(currentItem->text(HEADER_BACKUP) == "B" )
331 { 331 {
332 if(currentItem->childCount() == 0 ) 332 if(currentItem->childCount() == 0 )
333 { 333 {
334 if(parent == NULL) 334 if(parent == NULL)
335 backupFiles += currentItem->text(BACKUP_LOCATION); 335 backupFiles += currentItem->text(BACKUP_LOCATION);
336 else 336 else
337 backupFiles += currentHome + currentItem->text(HEADER_NAME); 337 backupFiles += currentHome + currentItem->text(HEADER_NAME);
338 backupFiles += " "; 338 backupFiles += " ";
339 count++; 339 count++;
340 } 340 }
341 else 341 else
342 { 342 {
343 count += getBackupFiles(backupFiles, currentItem); 343 count += getBackupFiles(backupFiles, currentItem);
344 } 344 }
345 } 345 }
346 currentItem = currentItem->nextSibling(); 346 currentItem = currentItem->nextSibling();
347 } 347 }
348 return count; 348 return count;
349} 349}
350 350
351void BackupAndRestore::sourceDirChanged(int selection) 351void BackupAndRestore::sourceDirChanged(int selection)
352{ 352{
353 restoreList->clear(); 353 restoreList->clear();
354 rescanFolder(backupLocations[restoreSource->text(selection)]); 354 rescanFolder(backupLocations[restoreSource->text(selection)]);
355} 355}
356 356
357void BackupAndRestore::fileListUpdate() 357void BackupAndRestore::fileListUpdate()
358{ 358{
359 qWarning("void BackupAndRestore::fileListUpdate()"); 359 qWarning("void BackupAndRestore::fileListUpdate()");
360 restoreList->clear(); 360 restoreList->clear();
361 rescanFolder( backupLocations[restoreSource->currentText()] ); 361 rescanFolder( backupLocations[restoreSource->currentText()] );
362} 362}
363 363
364/** 364/**
365 * Scans directory for any backup files. Will recursivly go down, 365 * Scans directory for any backup files. Will recursivly go down,
366 * but will not follow symlinks. 366 * but will not follow symlinks.
367 * @param directory - the directory to look in. 367 * @param directory - the directory to look in.
368 */ 368 */
369void BackupAndRestore::rescanFolder(QString directory) 369void BackupAndRestore::rescanFolder(QString directory)
370{ 370{
371 //qDebug(QString("rescanFolder: ") + directory.latin1()); 371 //qDebug(QString("rescanFolder: ") + directory.latin1());
372 QDir d(directory); 372 QDir d(directory);
373 if(!d.exists()) 373 if(!d.exists())
374 return; 374 return;
375 375
376 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); 376 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
377 const QFileInfoList *list = d.entryInfoList(); 377 const QFileInfoList *list = d.entryInfoList();
378 QFileInfoListIterator it( *list ); 378 QFileInfoListIterator it( *list );
379 QFileInfo *file; 379 QFileInfo *file;
380 while ( (file=it.current()) ) 380 while ( (file=it.current()) )
381 { // for each file... 381 { // for each file...
382 // If it is a dir and not .. or . then add it as a tab and go down. 382 // If it is a dir and not .. or . then add it as a tab and go down.
383 if(file->isDir()) 383 if(file->isDir())
384 { 384 {
385 if(file->fileName() != ".." && file->fileName() != ".") 385 if(file->fileName() != ".." && file->fileName() != ".")
386 { 386 {
387 rescanFolder(directory + "/" + file->fileName()); 387 rescanFolder(directory + "/" + file->fileName());
388 } 388 }
389 } 389 }
390 else 390 else
391 { 391 {
392 // If it is a backup file add to list. 392 // If it is a backup file add to list.
393 if(file->fileName().contains(EXTENSION)) 393 if(file->fileName().contains(EXTENSION))
394 (void)new QListViewItem(restoreList, file->fileName()); 394 (void)new QListViewItem(restoreList, file->fileName());
395 } 395 }
396 ++it; 396 ++it;
397 } 397 }
398} 398}
399 399
400/** 400/**
401 * Restore a backup file. 401 * Restore a backup file.
402 * Report errors or success 402 * Report errors or success
403 */ 403 */
404void BackupAndRestore::restore() 404void BackupAndRestore::restore()
405{ 405{
406 QListViewItem *restoreItem = restoreList->currentItem(); 406 QListViewItem *restoreItem = restoreList->currentItem();
407 if(!restoreItem) 407 if(!restoreItem)
408 { 408 {
409 QMessageBox::critical(this, tr( "Message" ), 409 QMessageBox::critical(this, tr( "Message" ),
410 tr( "Please select something to restore." ),QString( tr( "Ok") ) ); 410 tr( "Please select something to restore." ),QString( tr( "Ok") ) );
411 return; 411 return;
412 } 412 }
413 setCaption(tr("Backup and Restore... working...")); 413 setCaption(tr("Backup and Restore... working..."));
414 414
415 QString restoreFile = backupLocations[restoreSource->currentText()]; 415 QString restoreFile = backupLocations[restoreSource->currentText()];
416 416
417 restoreFile += "/" + restoreItem->text(0); 417 restoreFile += "/" + restoreItem->text(0);
418 418
419 qDebug( restoreFile ); 419 qDebug( restoreFile );
420 420
421 QString commandLine = QString( "tar -C %1 -zxf %2 2> %3" ).arg( QDir::homeDirPath() ) 421 QString commandLine = QString( "tar -C %1 -zxf %2 2> %3" ).arg( QDir::homeDirPath() )
422 .arg( restoreFile.latin1() ) 422 .arg( restoreFile.latin1() )
423 .arg( tempFileName.latin1() ); 423 .arg( tempFileName.latin1() );
424 424
425 qDebug( commandLine ); 425 qDebug( commandLine );
426 426
427 int r = system( commandLine ); 427 int r = system( commandLine );
428 428
429 if(r != 0) 429 if(r != 0)
430 { 430 {
431 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); 431 QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno );
432 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" 432 switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n"
433 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) 433 + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) )
434 { 434 {
435 case 1: 435 case 1:
436 qWarning("Details pressed !"); 436 qWarning("Details pressed !");
437 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); 437 ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true );
438 QFile errorFile( tempFileName ); 438 QFile errorFile( tempFileName );
439 if ( errorFile.open(IO_ReadOnly) ) 439 if ( errorFile.open(IO_ReadOnly) )
440 { 440 {
441 QTextStream t( &errorFile ); 441 QTextStream t( &errorFile );
442 QString s; 442 QString s;
443 while ( !t.eof() ) 443 while ( !t.eof() )
444 { // until end of file... 444 { // until end of file...
445 s += t.readLine(); // line of text excluding '\n' 445 s += t.readLine(); // line of text excluding '\n'
446 } 446 }
447 errorFile.close(); 447 errorFile.close();
448 448
449 pErrDialog->m_textarea->setText( s ); 449 pErrDialog->m_textarea->setText( s );
450 } 450 }
451 else 451 else
452 { 452 {
453 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) ); 453 pErrDialog->m_textarea->setText( tr( "Unable to open File: %1" ).arg( "/tmp/backup.er" ) );
454 } 454 }
455 pErrDialog->showMaximized(); 455 pErrDialog->showMaximized();
456 pErrDialog->exec(); 456 pErrDialog->exec();
457 delete pErrDialog; 457 delete pErrDialog;
458 458
459 setCaption(tr("Backup and Restore.. Failed !!")); 459 setCaption(tr("Backup and Restore.. Failed !!"));
460 return; 460 return;
461 461
462 break; 462 break;
463 463
464 } 464 }
465 } 465 }
466 else 466 else
467 { 467 {
468 QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) ); 468 QMessageBox::information(this, tr( "Message" ), tr( "Restore Successful." ), QString( tr( "Ok") ) );