summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/file/resourcefile.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefile.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 2bd9e71..c89939d 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -44,4 +44,5 @@ $Id$
44#include <kstandarddirs.h> 44#include <kstandarddirs.h>
45#include <kmessagebox.h> 45#include <kmessagebox.h>
46#include <kglobalsettings.h>
46 47
47#include "formatfactory.h" 48#include "formatfactory.h"
@@ -80,5 +81,5 @@ ResourceFile::ResourceFile( const KConfig *config )
80 81
81 default_fileName = StdAddressBook::fileName(); 82 default_fileName = StdAddressBook::fileName();
82 83 mLastBackupDate = -1;
83 KConfig *cfg = (KConfig *)config; 84 KConfig *cfg = (KConfig *)config;
84 if ( cfg ) { 85 if ( cfg ) {
@@ -86,4 +87,5 @@ ResourceFile::ResourceFile( const KConfig *config )
86 formatName = cfg->readEntry( "FileFormat", "vcard" ); 87 formatName = cfg->readEntry( "FileFormat", "vcard" );
87 mFamily = cfg->readEntry( "ResourceName", "std" ); 88 mFamily = cfg->readEntry( "ResourceName", "std" );
89 mLastBackupDate = cfg->readNumEntry( "LastBackupDate", 0 );
88 } else { 90 } else {
89 fileName = default_fileName; 91 fileName = default_fileName;
@@ -101,5 +103,5 @@ ResourceFile::ResourceFile( const QString &fileName ,
101 103
102 104
103 105 mLastBackupDate = -1;
104 init( fileName, formatName ); 106 init( fileName, formatName );
105} 107}
@@ -258,4 +260,47 @@ bool ResourceFile::save( Ticket *ticket )
258 mDirWatch.stopScan(); 260 mDirWatch.stopScan();
259#endif 261#endif
262 if ( mLastBackupDate >= 0 && mFamily != "sync_res") {
263 KConfig conf (locateLocal("config","microkdeglobalrc"));
264 conf.setGroup( "BackupSettings" );
265 bool b_enabled = conf.readBoolEntry( "BackupEnabled" );
266 if ( b_enabled ) {
267 int num = conf.readNumEntry( "BackupNumbers" );
268 int d_count = conf.readNumEntry( "BackupDayCount" );
269 bool stdDir = conf.readBoolEntry( "BackupUseDefaultDir" );
270 QString bupDir = conf.readEntry( "BackupDatadir" );
271 QDate reference ( 2000,1,1 );
272 int daysTo = reference.daysTo ( QDate::currentDate() );
273 bool saveDate = false;
274 if ( daysTo - d_count >= mLastBackupDate ) {
275 qDebug("KA: Last backup was %d days ago ", daysTo - mLastBackupDate );
276 if ( stdDir )
277 bupDir = KGlobalSettings::backupDataDir();
278 int retval = KApplication::createBackup( fileName(), bupDir, num );
279 if ( retval == 0 ) {
280 qDebug("KO: Backup cancelled. Will try again tomorrow ");
281 // retval == 0 : backup skipped for today, try again tomorrow
282 mLastBackupDate = daysTo - d_count+1;
283 saveDate = true;
284 } else if ( retval == 1 ){
285 qDebug("KO: Backup created.");
286 // backup ok
287 mLastBackupDate = daysTo;
288 saveDate = true;
289 } else if ( retval == 2 ){
290 qDebug("KO: Backup globally cancelled.");
291 // backup globally cancelled
292 b_enabled = false;
293 }
294 if ( !b_enabled ) {
295 conf.writeEntry( "mBackupEnabled", false );
296 }
297 if ( saveDate ) {
298 KConfig config ( locateLocal("config","kabcrc") );
299 config.setGroup( "Resource_" + identifier() );
300 config.writeEntry( "LastBackupDate", mLastBackupDate );
301 }
302 }
303 }
304 }
260 QFile info; 305 QFile info;
261 info.setName( fileName() ); 306 info.setName( fileName() );