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

List:       kde-commits
Subject:    KDE/kdepimlibs/kblog
From:       Christian Weilbach <christian () whiletaker ! homeip ! net>
Date:       2009-09-17 17:36:24
Message-ID: 1253208984.980569.22130.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1024965 by weilbach:

Add a category cache file to avoid loading listCategories on every post operation \
first. BlogPost::Status::Created set before emit and some debug cleanups...


 M  +60 -3     metaweblog.cpp  
 M  +3 -0      metaweblog_p.h  
 M  +8 -5      movabletype.cpp  
 M  +9 -7      wordpressbuggy.cpp  


--- trunk/KDE/kdepimlibs/kblog/metaweblog.cpp #1024964:1024965
@@ -30,24 +30,28 @@
 #include <KDebug>
 #include <KLocale>
 #include <KDateTime>
+#include <kstandarddirs.h>
 
+#include <QtCore/QFile>
+#include <QtCore/QDataStream>
+
 using namespace KBlog;
 
 MetaWeblog::MetaWeblog( const KUrl &server, QObject *parent )
   : Blogger1( server, *new MetaWeblogPrivate, parent )
 {
-  kDebug() << "MetaWeblog()";
+  kDebug();
 }
 
 MetaWeblog::MetaWeblog( const KUrl &server, MetaWeblogPrivate &dd, QObject *parent )
   : Blogger1( server, dd, parent )
 {
-  kDebug() << "MetaWeblog()";
+  kDebug();
 }
 
 MetaWeblog::~MetaWeblog()
 {
-  kDebug() << "~MetaWeblog()";
+  kDebug();
 }
 
 QString MetaWeblog::interfaceName() const
@@ -96,6 +100,7 @@
 {
   kDebug();
   mCallMediaCounter=1;
+  mCatLoaded=false;
 }
 
 MetaWeblogPrivate::~MetaWeblogPrivate()
@@ -115,6 +120,57 @@
   return args;
 }
 
+void MetaWeblogPrivate::loadCategories()
+{
+  kDebug();
+
+  if ( mCatLoaded ) {
+    return;
+  }
+  mCatLoaded = true;
+
+  if ( mUrl.isEmpty() || mBlogId.isEmpty() || mUsername.isEmpty() ) {
+    kDebug() << "We need at least url, blogId and the username to create a unique \
filename."; +    return;
+  }
+
+  QString filename = "kblog/"+mUrl.host()+"_"+mBlogId+"_"+mUsername;
+  filename = KStandardDirs::locateLocal( "data", filename, true );
+
+  QFile file( filename );
+  if ( !file.open( QIODevice::ReadOnly ) ) {
+    kDebug() << "Cannot open cached categories file: " << filename;
+    return;
+  }
+
+  QDataStream stream( &file );
+  stream >> mCategoriesList;
+  file.close();
+}
+
+void MetaWeblogPrivate::saveCategories()
+{
+  kDebug();
+  if ( mUrl.isEmpty() || mBlogId.isEmpty() || mUsername.isEmpty() ) {
+    kDebug() << "We need at least url, blogId and the username to create a unique \
filename."; +    return;
+  }
+
+  QString filename = "kblog/"+mUrl.host()+"_"+mBlogId+"_"+mUsername;
+  filename = KStandardDirs::locateLocal( "data", filename, true );
+
+  QFile file( filename );
+  if ( !file.open( QIODevice::WriteOnly ) ) {
+    kDebug() << "Cannot open cached categories file: " << filename;
+    return;
+  }
+
+  QDataStream stream( &file );
+  stream << mCategoriesList;
+  file.close();
+}
+
+
 void MetaWeblogPrivate::slotListCategories( const QList<QVariant> &result,
                                             const QVariant &id )
 {
@@ -175,6 +231,7 @@
     kDebug() << "Emitting listedCategories()";
     emit q->listedCategories( mCategoriesList );
   }
+  saveCategories();
 }
 
 void MetaWeblogPrivate::slotCreateMedia( const QList<QVariant> &result,
--- trunk/KDE/kdepimlibs/kblog/metaweblog_p.h #1024964:1024965
@@ -39,6 +39,8 @@
     QMap<unsigned int,KBlog::BlogMedia*> mCallMediaMap;
     MetaWeblogPrivate();
     ~MetaWeblogPrivate();
+    virtual void loadCategories();
+    virtual void saveCategories();
     virtual void slotListCategories( const QList<QVariant> &result,
                                      const QVariant &id );
     virtual void slotCreateMedia( const QList<QVariant> &result,
@@ -49,6 +51,7 @@
     bool readPostFromMap( BlogPost *post, const QMap<QString, QVariant> &postInfo );
     bool readArgsFromPost( QList<QVariant> *args, const BlogPost &post );
     QString getCallFromFunction( FunctionToCall type );
+    bool mCatLoaded;
 };
 
 }
--- trunk/KDE/kdepimlibs/kblog/movabletype.cpp #1024964:1024965
@@ -47,7 +47,6 @@
   : MetaWeblog( server, dd, parent )
 {
   kDebug();
-  listCategories();
 }
 
 MovableType::~MovableType()
@@ -92,6 +91,7 @@
 {
   Q_D( MovableType );
   kDebug();
+  d->loadCategories();
   if ( d->mCategoriesList.isEmpty() && post->categories( ).count() ) {
     d->mFetchPostCache << post;
     if ( d->mFetchPostCache.count() ) {
@@ -117,6 +117,7 @@
 
   // we need mCategoriesList to be loaded first, since we cannot use the \
post->categories()  // names later, but we need to map them to categoryId of the blog
+  d->loadCategories();
   if(d->mCategoriesList.isEmpty()&&!post->categories().isEmpty()){
     kDebug() << "No categories in the cache yet. Have to fetch them first.";
     d->mCreatePostCache << post;
@@ -151,6 +152,7 @@
 
   // we need mCategoriesList to be loaded first, since we cannot use the \
post->categories()  // names later, but we need to map them to categoryId of the blog
+  d->loadCategories();
   if(d->mCategoriesList.isEmpty() && !post->categories().isEmpty()){
     kDebug() << "No categories in the cache yet. Have to fetch them first.";
     d->mModifyPostCache << post;
@@ -256,8 +258,8 @@
     kDebug() << "emitting createdPost()"
                 << "for title: \"" << post->title()
                 << "\" server id: " << serverID;
+    post->setStatus( KBlog::BlogPost::Created );
     emit q->createdPost( post );
-    post->setStatus( KBlog::BlogPost::Created );
   }
 }
 
@@ -280,8 +282,9 @@
     return;
   }
   if ( mSilentCreationList.contains( post ) ) {
+    post->setStatus( KBlog::BlogPost::Created );
+    mSilentCreationList.removeOne( post );
     emit q->createdPost( post );
-    mSilentCreationList.removeOne( post );
   } else {
     if( !post->categories().isEmpty() ){
       setPostCategories( post, false );
@@ -356,14 +359,14 @@
     if ( mSilentCreationList.contains( post ) ) {
       kDebug() << "emitting createdPost() for title: \""
               << post->title() << "\"";
-      emit q->createdPost( post );
       post->setStatus( KBlog::BlogPost::Created );
       mSilentCreationList.removeOne( post );
+      emit q->createdPost( post );
     } else {
       kDebug() << "emitting modifiedPost() for title: \""
               << post->title() << "\"";
+      post->setStatus( KBlog::BlogPost::Modified );
       emit q->modifiedPost( post );
-      post->setStatus( KBlog::BlogPost::Modified );
     }
   }
 }
--- trunk/KDE/kdepimlibs/kblog/wordpressbuggy.cpp #1024964:1024965
@@ -38,19 +38,19 @@
 WordpressBuggy::WordpressBuggy( const KUrl &server, QObject *parent )
   : MovableType( server, *new WordpressBuggyPrivate, parent )
 {
-  kDebug() << "WordpressBuggy()";
+  kDebug();
 }
 
 WordpressBuggy::WordpressBuggy( const KUrl &server, WordpressBuggyPrivate &dd,
                                 QObject *parent )
   : MovableType( server, dd, parent )
 {
-  kDebug() << "WordpressBuggy()";
+  kDebug();
 }
 
 WordpressBuggy::~WordpressBuggy()
 {
-  kDebug() << "~WordpressBuggy()";
+  kDebug();
 }
 
 void WordpressBuggy::createPost( KBlog::BlogPost *post )
@@ -62,6 +62,7 @@
 
   // we need mCategoriesList to be loaded first, since we cannot use the \
post->categories()  // names later, but we need to map them to categoryId of the blog
+  d->loadCategories();
   if(d->mCategoriesList.isEmpty()){
     kDebug() << "No categories in the cache yet. Have to fetch them first.";
     d->mCreatePostCache << post;
@@ -174,6 +175,7 @@
 
   // we need mCategoriesList to be loaded first, since we cannot use the \
post->categories()  // names later, but we need to map them to categoryId of the blog
+  d->loadCategories();
   if(d->mCategoriesList.isEmpty()){
     kDebug() << "No categories in the cache yet. Have to fetch them first.";
     d->mModifyPostCache << post;
@@ -279,7 +281,7 @@
 
 WordpressBuggyPrivate::~WordpressBuggyPrivate()
 {
-  kDebug() << "~WordpressBuggyPrivate()";
+  kDebug();
 }
 
 QList<QVariant> WordpressBuggyPrivate::defaultArgs( const QString &id )
@@ -296,7 +298,7 @@
 
 void WordpressBuggyPrivate::slotCreatePost( KJob *job )
 {
-  kDebug() << "slotCreatePost()";
+  kDebug();
 
   KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>(job);
   const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
@@ -347,8 +349,8 @@
 
 void WordpressBuggyPrivate::slotModifyPost( KJob *job )
 {
-  kDebug() << "slotModifyPost()";
-  
+  kDebug();
+
   KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>(job);
   const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
 


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

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