summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index 3500403..a00193d 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -156,193 +156,193 @@ BackupAndRestore::~BackupAndRestore()
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 -z --exclude=*.bck -c %2 > %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;