[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/akonadi/resources/shared
From:       Volker Krause <vkrause () kde ! org>
Date:       2008-10-05 21:23:29
Message-ID: 1223241809.863326.28229.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 868277 by vkrause:

Create the file if it does not exist yet. So, besides importing existing
calendars/addressbooks we can now finally also create new ones.


 M  +18 -3     singlefileresource.h  


--- trunk/KDE/kdepim/akonadi/resources/shared/singlefileresource.h #868276:868277
@@ -25,6 +25,8 @@
 
 #include <KLocale>
 
+#include <QFile>
+
 namespace Akonadi
 {
 
@@ -69,12 +71,25 @@
       // NOTE: Test what happens with remotefile -> save, close before save is finished.
 
       mCurrentUrl = KUrl( Settings::self()->path() );
+
+      // check if the file does not exist yet, if so, create it
+      if ( !QFile::exists( mCurrentUrl.path() ) ) {
+        QFile f( mCurrentUrl.path() );
+        if ( f.open( QIODevice::WriteOnly ) && f.resize( 0 ) ) {
+          emit status( Idle, i18n( "File '%1' created.", mCurrentUrl.prettyUrl() ) );
+        } else {
+          emit status( Broken, i18n( "Could not create file '%1'.", mCurrentUrl.prettyUrl() ) );
+          mCurrentUrl.clear();
+          return;
+        }
+      }
+
       if ( !readFromFile( mCurrentUrl.path() ) ) {
-        mCurrentUrl = KUrl();
+        mCurrentUrl = KUrl(); // reset so we don't accidentally overwrite the file
         return;
       }
 
-      emit status( Idle, i18n( "Data loaded from '%1'.", mCurrentUrl.url() ) );
+      emit status( Idle, i18n( "Data loaded from '%1'.", mCurrentUrl.prettyUrl() ) );
     }
 
     /**
@@ -101,7 +116,7 @@
       if ( !writeToFile( mCurrentUrl.path() ) )
         return;
 
-      emit status( Idle, i18n( "Data successfully saved to '%1'.", mCurrentUrl.url() ) );
+      emit status( Idle, i18n( "Data successfully saved to '%1'.", mCurrentUrl.prettyUrl() ) );
     }
 
   protected:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic