[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-14 14:18:11
Message-ID: 1252937891.249835.25046.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1023321 by weilbach:

Reorder emit calls to emit after the setCategory chain is finished.


 M  +74 -6     movabletype.cpp  
 M  +1 -0      movabletype_p.h  
 M  +28 -19    wordpressbuggy.cpp  


--- trunk/KDE/kdepimlibs/kblog/movabletype.cpp #1023320:1023321
@@ -129,6 +129,11 @@
     // If we do setPostCategories() later than we disable publishing first.
     if( post->categories().count()>1 ){
       post->setPrivate( true );
+      if ( d->mSilentCreationList.contains( post ) ) {
+        kDebug()<< "Post already in mSilentCreationList, this *should* never happen!";
+      } else {
+        d->mSilentCreationList << post;
+      }
     }
     MetaWeblog::createPost( post );
     // HACK: uuh this a bit ugly now... reenable the original publish argument,
@@ -218,23 +223,70 @@
 
 void MovableTypePrivate::slotCreatePost( const QList<QVariant> &result, const QVariant &id )
 {
+  Q_Q( MovableType );
+  // reimplement from Blogger1 to chainload the categories stuff before emit()
   kDebug();
   KBlog::BlogPost *post = mCallMap[ id.toInt() ];
-  MetaWeblogPrivate::slotCreatePost( result, id );
-  // set the categories and publish afterwards
-  if( !post->categories().isEmpty() ){
+  mCallMap.remove( id.toInt() );
+
+  kDebug();
+  //array of structs containing ISO.8601
+  // dateCreated, String userid, String postid, String content;
+  kDebug () << "TOP:" << result[0].typeName();
+  if ( result[0].type() != QVariant::String && result[0].type() != QVariant::Int ) {
+    kError() << "Could not read the postId, not a string or an integer.";
+    emit q->errorPost( Blogger1::ParsingError,
+                          i18n( "Could not read the postId, not a string or an integer." ),
+                          post );
+    return;
+  }
+  QString serverID;
+  if ( result[0].type() == QVariant::String ) {
+    serverID = result[0].toString();
+  }
+  if ( result[0].type() == QVariant::Int ) {
+    serverID = QString( "%1" ).arg( result[0].toInt() );
+  }
+  post->setPostId( serverID );
+  if ( mSilentCreationList.contains(  post ) )
+  {
+    // set the categories and publish afterwards
     setPostCategories( post, !post->isPrivate() );
+  } else {
+    kDebug() << "emitting createdPost()"
+                << "for title: \"" << post->title()
+                << "\" server id: " << serverID;
+    emit q->createdPost( post );
+    post->setStatus( KBlog::BlogPost::Created );
   }
 }
 
 void MovableTypePrivate::slotModifyPost( const QList<QVariant> &result, const QVariant &id )
 {
+  Q_Q( MovableType );
+  // reimplement from Blogger1
   kDebug();
   KBlog::BlogPost *post = mCallMap[ id.toInt() ];
-  MetaWeblogPrivate::slotModifyPost( result, id );
-  if( !post->categories().isEmpty() ){
-    setPostCategories( post, false );
+  mCallMap.remove( id.toInt() );
+
+  //array of structs containing ISO.8601
+  // dateCreated, String userid, String postid, String content;
+  kDebug() << "TOP:" << result[0].typeName();
+  if ( result[0].type() != QVariant::Bool && result[0].type() != QVariant::Int ) {
+    kError() << "Could not read the result, not a boolean.";
+    emit q->errorPost( Blogger1::ParsingError,
+                          i18n( "Could not read the result, not a boolean." ),
+                          post );
+    return;
   }
+  if ( mSilentCreationList.contains( post ) ) {
+    emit q->createdPost( post );
+    mSilentCreationList.removeOne( post );
+  } else {
+    if( !post->categories().isEmpty() ){
+      setPostCategories( post, false );
+    }
+  }
 }
 
 void MovableTypePrivate::setPostCategories( BlogPost *post, bool publishAfterCategories )
@@ -298,6 +350,22 @@
   if( publish && !post->isPrivate() ){
     q->modifyPost( post );
   }
+
+  // this is the end of the chain then
+  if ( !publish ) {
+    if ( mSilentCreationList.contains( post ) ) {
+      kDebug() << "emitting createdPost() for title: \""
+              << post->title() << "\"";
+      emit q->createdPost( post );
+      post->setStatus( KBlog::BlogPost::Created );
+      mSilentCreationList.removeOne( post );
+    } else {
+      kDebug() << "emitting modifiedPost() for title: \""
+              << post->title() << "\"";
+      emit q->modifiedPost( post );
+      post->setStatus( KBlog::BlogPost::Modified );
+    }
+  }
 }
 
 QList<QVariant> MovableTypePrivate::defaultArgs( const QString &id )
--- trunk/KDE/kdepimlibs/kblog/movabletype_p.h #1023320:1023321
@@ -62,6 +62,7 @@
     QList<BlogPost*> mCreatePostCache;
     QList<BlogPost*> mModifyPostCache;
     QList<BlogPost*> mFetchPostCache;
+    QList<BlogPost*> mSilentCreationList;
 };
 
 }
--- trunk/KDE/kdepimlibs/kblog/wordpressbuggy.cpp #1023320:1023321
@@ -70,11 +70,6 @@
     listCategories();
   }
   else {
-    bool publish = post->isPrivate();
-    // If we do setPostCategories() later than we disable publishing first.
-    if( !post->categories().isEmpty()){
-      post->setPrivate( true );
-    }
     kDebug() << "createPost()";
     if ( !post ) {
       kError() << "WordpressBuggy::createPost: post is a null pointer";
@@ -82,7 +77,18 @@
       return;
     }
     kDebug() << "Creating new Post with blogId" << blogId();
-  
+
+    bool publish = post->isPrivate();
+    // If we do setPostCategories() later than we disable publishing first.
+    if( post->categories().count()>1 ){
+      post->setPrivate( true );
+      if ( d->mSilentCreationList.contains( post ) ) {
+        kDebug()<< "Post already in mSilentCreationList, this *should* never happen!";
+      } else {
+        d->mSilentCreationList << post;
+      }
+    }
+
     QString xmlMarkup = "<?xml version=\"1.0\"?>";
     xmlMarkup += "<methodCall>";
     xmlMarkup += "<methodName>metaWeblog.newPost</methodName>";
@@ -327,15 +333,16 @@
   kDebug() << "QRegExp rx( \"<string>(.+)</string>\" ) matches" << rxId.cap( 1 );
 
   post->setPostId( rxId.cap( 1 ) );
-  post->setStatus( BlogPost::Created );
-
-  // set the categories and publish afterwards
-  if( !post->categories().isEmpty() ){
+  if ( mSilentCreationList.contains(  post ) )
+  {
+    // set the categories and publish afterwards
     setPostCategories( post, !post->isPrivate() );
+  } else {
+    kDebug() << "emitting createdPost()"
+                << "for title: \"" << post->title();
+    emit q->createdPost( post );
+    post->setStatus( KBlog::BlogPost::Created );
   }
-
-  kDebug() << "Emitting createdPost()";
-  emit q->createdPost( post );
 }
 
 void WordpressBuggyPrivate::slotModifyPost( KJob *job )
@@ -376,13 +383,15 @@
 
   if ( rxId.cap( 1 ).toInt() == 1 ) {
     kDebug() << "Post successfully updated.";
-    post->setStatus( BlogPost::Modified );
-    emit q->modifiedPost( post );
+    if ( mSilentCreationList.contains( post ) ) {
+      emit q->createdPost( post );
+      mSilentCreationList.removeOne( post );
+    } else {
+      if( !post->categories().isEmpty() ){
+        setPostCategories( post, false );
+      }
+    }
   }
-
-  if( !post->categories().isEmpty() ){
-    setPostCategories( post, false );
-  }
 }
 
 #include "wordpressbuggy.moc"
[prev in list] [next in list] [prev in thread] [next in thread] 

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