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

List:       kde-commits
Subject:    KDE/kdepim/kresources
From:       Mike Arthur <mike () mikearthur ! co ! uk>
Date:       2007-07-31 22:07:50
Message-ID: 1185919670.765614.10308.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 694847 by mikearthur:

KBlog API completed, fixed code so it compiles (doesn't fully work
again yet) and readded to build system.


 M  +1 -1      CMakeLists.txt  
 M  +53 -79    blog/resourceblog.cpp  
 M  +4 -21     blog/resourceblog.h  
 M  +11 -11    blog/resourceblogconfig.cpp  


--- trunk/KDE/kdepim/kresources/CMakeLists.txt #694846:694847
@@ -8,6 +8,6 @@
 add_subdirectory( featureplan ) 
 add_subdirectory( groupdav ) 
 add_subdirectory( birthdays ) 
-#add_subdirectory( blog ) REMOVING TILL API FROZEN
+add_subdirectory( blog )
 #add_subdirectory( groupwise )
 
--- trunk/KDE/kdepim/kresources/blog/resourceblog.cpp #694846:694847
@@ -22,9 +22,9 @@
 #include <QDateTime>
 #include <QString>
 
-#include <kdebug.h>
-#include <kurl.h>
-#include <klocale.h>
+#include <KDebug>
+#include <KUrl>
+#include <KLocale>
 
 #include <kcal/journal.h>
 
@@ -33,7 +33,6 @@
 #include <libkdepim/progressmanager.h>
 
 #include <kblog/blogposting.h>
-#include <kblog/blogger.h>
 #include <kblog/metaweblog.h>
 
 #include "resourceblog.h"
@@ -59,11 +58,6 @@
   close();
 
   delete mLock;
-
-  //FIXME: Delete contents of mJournalList
-  //kDebug() << mJournalsMap << endl;
-  //qDeleteAll( mJournalsMap );
-  mJournalsMap.clear();
 }
 
 void ResourceBlog::init()
@@ -79,37 +73,17 @@
   enableChangeNotification();
 }
 
-  QString ResourceBlog::APITypeToQString( const ResourceBlog::APIType &type ) {
-    if ( type == ResourceBlog::MetaWeblog ) {
-      return "MetaWeblog";
-    }
-    else if ( type == ResourceBlog::Blogger ) {
-      return "Blogger";
-    }
-    return 0;
-  }
-
-  ResourceBlog::APIType ResourceBlog::QStringToAPIType( const QString &type ) {
-    if ( type == "MetaWeblog" ) {
-      return MetaWeblog;
-    }
-    else if ( type == "Blogger" ) {
-      return Blogger;
-    }
-    return Unknown;
-  }
-
 void ResourceBlog::readConfig( const KConfigGroup &group )
 {
-  kDebug( 5800 ) << "ResourceBlog::readConfig()" << endl;
+  kDebug( 5800 ) << "ResourceBlog::readConfig()";
 
   QString url = group.readEntry( "URL" );
   mUrl = KUrl( url );
   mUsername = group.readEntry( "Username" );
   mPassword = group.readEntry( "Password" );
-  setAPI( QStringToAPIType ( group.readEntry( "API" ) ) );
+  setAPI( group.readEntry( "API" ) );
   mBlogID = group.readEntry( "BlogID" );
-  kDebug( 5800 ) << "ResourceBlog::readConfig(): ID: " << mBlogID << endl;
+  kDebug( 5800 ) << "ResourceBlog::readConfig(): ID: " << mBlogID;
   mBlogName = group.readEntry( "BlogName" );
 
   ResourceCached::readConfig( group );
@@ -117,12 +91,12 @@
 
 void ResourceBlog::writeConfig( KConfigGroup &group )
 {
-  kDebug( 5800 ) << "ResourceBlog::writeConfig()" << endl;
+  kDebug( 5800 ) << "ResourceBlog::writeConfig()";
 
   group.writeEntry( "URL", mUrl.url() );
   group.writeEntry( "Username", mUsername );
   group.writeEntry( "Password", mPassword );
-  group.writeEntry( "API", APITypeToQString ( API() ) );
+  group.writeEntry( "API", API() );
   group.writeEntry( "BlogID", mBlogID );
   group.writeEntry( "BlogName", mBlogName );
 
@@ -160,31 +134,32 @@
   return mPassword;
 }
 
-void ResourceBlog::setAPI( const APIType &API )
+void ResourceBlog::setAPI( const QString &API )
 {
-  if ( API == MetaWeblog ) {
-    mAPI = new KBlog::APIMetaWeblog( mUrl, this );
-  } else if ( API == Blogger ) {
-    mAPI = new KBlog::APIBlogger( mUrl, this );
+  kDebug( 5800 ) << "ResourceBlog::setAPI(): " << API;
+  if ( API == "MetaWeblog" ) {
+    mAPI = new KBlog::MetaWeblog( mUrl, this );
+  } else if ( API == "Blogger 1.0" ) {
+    mAPI = new KBlog::Blogger1( mUrl, this );
   } else {
-    kError() << "ResourceBlog::setAPI(): Unrecognised API: " << API << endl;
+    kError() << "ResourceBlog::setAPI(): Unrecognised API: " << API;
     return;
   }
   mAPI->setUsername( mUsername );
   mAPI->setPassword( mPassword );
 }
 
-ResourceBlog::APIType ResourceBlog::API() const
+QString ResourceBlog::API() const
 {
   if ( mAPI ) {
-    if ( qobject_cast<KBlog::APIMetaWeblog*>( mAPI ) ) {
-      return MetaWeblog;
+    if ( qobject_cast<KBlog::MetaWeblog*>( mAPI ) ) {
+      return "MetaWeblog";
     }
-    else if ( qobject_cast<KBlog::APIBlogger*>( mAPI ) ) {
-      return Blogger;
+    else if ( qobject_cast<KBlog::Blogger1*>( mAPI ) ) {
+      return "Blogger 1.0";
     }
   }
-  return Unknown;
+  return "Unknown";
 }
 
 void ResourceBlog::setUseProgressManager( bool useProgressManager )
@@ -209,27 +184,24 @@
 
 bool ResourceBlog::doLoad( bool fullReload )
 {
-  kDebug( 5800 ) << "ResourceBlog::load()" << endl;
+  kDebug( 5800 ) << "ResourceBlog::load()";
 
   if ( mAPI ) {
     if ( mLock->lock() ) {
+      int downloadCount = 100;
       //FIXME Actually do something? Calculate posts for non-full reload.
       if ( fullReload ) {
-        mAPI->setDownloadCount( 100 );
+        // TODO: downloadCount = math;
         mJournalsMap.clear();
         ResourceCached::deleteAllJournals();
       }
-      else {
-        mAPI->setDownloadCount( 100 );
-      }
-
       mAPI->setBlogId( mBlogID );
       connect ( mAPI, SIGNAL( listedPosting( KBlog::BlogPosting & ) ),
                 this, SLOT( slotListedPosting( KBlog::BlogPosting & ) ) );
       connect ( mAPI, SIGNAL( listPostingsFinished() ),
                 this, SLOT( slotListPostingsFinished() ));
-      connect ( mAPI, SIGNAL( error( const KBlog::APIBlog::ErrorType &, const QString & ) ),
-                this, SLOT( slotError( const KBlog::APIBlog::ErrorType &, const QString & ) ) );
+      connect ( mAPI, SIGNAL( error( const KBlog::Blog::ErrorType &, const QString & ) ),
+                this, SLOT( slotError( const KBlog::Blog::ErrorType &, const QString & ) ) );
 
       if ( mUseProgressManager ) {
         mProgress = KPIM::ProgressManager::createProgressItem(
@@ -237,28 +209,29 @@
             i18n("Downloading blog posts") );
         mProgress->setProgress( 0 );
       }
-      mAPI->listPostings();
+      mAPI->listRecentPostings( downloadCount );
       mLock->unlock();
       return true;
     } else {
       kDebug( 5800 ) << "ResourceBlog::load(): cache file is locked"
-          << " - something else must be loading the file" << endl;
+          << " - something else must be loading the file";
     }
   }
+  kError( 5800 ) << "ResourceBlog::load(): null mAPI";
   return false;
 }
 
 void ResourceBlog::slotListedPosting( KBlog::BlogPosting &blogPosting )
 {
-  kDebug( 5800 ) << "ResourceBlog::slotListedPosting()" << endl;
+  kDebug( 5800 ) << "ResourceBlog::slotListedPosting()";
   Journal *journalBlog = new Journal();
   QString id = "kblog-" + mUrl.url() + "-" + mUsername + "-" +
       blogPosting.postingId();
   if ( mJournalsMap.value( id ) == 0 ) {
     connect ( mAPI, SIGNAL( createdPosting( QString & ) ),
       this, SLOT( slotCreatedPosting( QString & ) ) );
-    connect ( mAPI, SIGNAL( error( const KBlog::APIBlog::ErrorType &, const QString & ) ),
-      this, SLOT( slotError( const KBlog::APIBlog::ErrorType &, const QString & ) ) );
+    connect ( mAPI, SIGNAL( error( const KBlog::Blog::ErrorType &, const QString & ) ),
+      this, SLOT( slotError( const KBlog::Blog::ErrorType &, const QString & ) ) );
     journalBlog->setUid( id );
     journalBlog->setSummary( blogPosting.title() );
     journalBlog->setCategories( blogPosting.categories() );
@@ -266,7 +239,7 @@
     journalBlog->setDtStart( blogPosting.creationDateTime() );
     if ( ResourceCached::addJournal( journalBlog ) ) {
       kDebug( 5800 ) << "ResourceBlog::slotListedPosting(): Journal added"
-          << endl;
+         ;
       mJournalsMap.insert( id, journalBlog );
     }
   }
@@ -274,7 +247,7 @@
 
 void ResourceBlog::slotListPostingsFinished()
 {
-  kDebug( 5800 ) << "ResourceBlog::slotListPostingsFinished()" << endl;
+  kDebug( 5800 ) << "ResourceBlog::slotListPostingsFinished()";
 
   emit resourceChanged( this );
 
@@ -286,16 +259,16 @@
   emit resourceLoaded( this );
 }
 
-void ResourceBlog::slotError( const KBlog::APIBlog::ErrorType &type,
+void ResourceBlog::slotError( const KBlog::Blog::ErrorType &type,
                               const QString &errorMessage )
 {
-  kError( 5800 ) << "ResourceBlog: " << type << ": " << errorMessage << endl;
-  Q_ASSERT(false);
+  kError( 5800 ) << "ResourceBlog: " << type << ": " << errorMessage;
+  //Q_ASSERT(false);
 }
 
 void ResourceBlog::slotCreatedPosting( const QString &id )
 {
-  kDebug( 5800 ) << "ResourceBlog: Posting created with id " << id << endl;
+  kDebug( 5800 ) << "ResourceBlog: Posting created with id " << id;
   mPostID = id.toInt();
 }
 
@@ -303,14 +276,14 @@
                                           const QString &name )
 {
   kDebug( 5800 ) << "ResourceBlog::slotBlogInfoRetrieved( id=" << id <<
-      ", name=" << name << endl;
+      ", name=" << name;
   mBlogsMap.insert( name, id );
   emit signalBlogInfoRetrieved( id, name );
 }
 
 bool ResourceBlog::doSave( bool )
 {
-  kDebug( 5800 ) << "ResourceBlog::save()" << endl;
+  kDebug( 5800 ) << "ResourceBlog::save()";
 
   if ( readOnly() || !hasChanges() ) {
     emit resourceSaved( this );
@@ -331,10 +304,10 @@
 void ResourceBlog::dump() const
 {
   ResourceCalendar::dump();
-  kDebug( 5800 ) << "  URL: " << mUrl.url() << endl;
-  kDebug( 5800 ) << "  Username: " << mUsername << endl;
-  kDebug( 5800 ) << "  API: " << API() << endl;
-  kDebug( 5800 ) << "  ReloadPolicy: " << reloadPolicy() << endl;
+  kDebug( 5800 ) << "  URL: " << mUrl.url();
+  kDebug( 5800 ) << "  Username: " << mUsername;
+  kDebug( 5800 ) << "  API: " << API();
+  kDebug( 5800 ) << "  ReloadPolicy: " << reloadPolicy();
 }
 
 void ResourceBlog::addInfoText( QString &txt ) const
@@ -356,7 +329,7 @@
     setPassword( value );
     return true;
   } else if ( key == "API" ) {
-    setAPI( QStringToAPIType( value ) );
+    setAPI( value );
     return true;
   } else {
     return ResourceCached::setValue( key, value );
@@ -365,7 +338,7 @@
 
 bool ResourceBlog::addJournal( Journal *journal )
 {
-  kDebug( 5800 ) << "ResourceBlog::addJournal()" << endl;
+  kDebug( 5800 ) << "ResourceBlog::addJournal()";
   QString title = journal->summary();
   QString content = journal->description();
   KDateTime date = journal->dtStart();
@@ -378,12 +351,12 @@
   if ( mAPI ) {
     mAPI->setBlogId( mBlogID );
     post->setCreationDateTime( date );
-    connect ( mAPI, SIGNAL( error( const KBlog::APIBlog::ErrorType &, const QString & ) ),
-              this, SLOT( slotError( const KBlog::APIBlog::ErrorType &, const QString & ) ) );
+    connect ( mAPI, SIGNAL( error( const KBlog::Blog::ErrorType &, const QString & ) ),
+              this, SLOT( slotError( const KBlog::Blog::ErrorType &, const QString & ) ) );
     mAPI->createPosting( post );
     return true;
   }
-  kError() << "ResourceBlog::addJournal(): Journal not initialised." << endl;
+  kError() << "ResourceBlog::addJournal(): Journal not initialised.";
   return false;
 }
 
@@ -393,10 +366,11 @@
                                                const QString & ) ),
         this, SLOT( slotBlogInfoRetrieved( const QString &,
                                            const QString & ) ) );
-    mAPI->listBlogs();
+    //Check if we're using Blogger or higher
+    //mAPI->listBlogs();
     return true;
   }
-  kError( 5800 ) << "ResourceBlog::fetchBlogs(): Journal not initialised." << endl;
+  kError( 5800 ) << "ResourceBlog::fetchBlogs(): Journal not initialised.";
   return false;
 }
 
@@ -405,7 +379,7 @@
     mBlogID = mBlogsMap.value( name );
     mBlogName = name;
     kDebug( 5800 ) << "ResourceBlog::setBlog( id=" << mBlogID <<
-      ", name=" << mBlogName << endl;
+      ", name=" << mBlogName;
     return true;
   }
   return false;
--- trunk/KDE/kdepim/kresources/blog/resourceblog.h #694846:694847
@@ -62,23 +62,6 @@
     ~ResourceBlog();
 
     /**
-      The available APIs for accessing blogs.
-    */
-    enum APIType {
-      MetaWeblog, Blogger, Unknown
-    };
-
-    /**
-      Convert the API type enumerator to a QString.
-    */
-    static QString APITypeToQString( const APIType &type ) ;
-
-    /**
-      Convert the API type enumerator to a QString.
-    */
-    static APIType QStringToAPIType( const QString &type ) ;
-
-    /**
       Read resource parameters from configuration information.
 
       @param group The configuration information.
@@ -131,14 +114,14 @@
     /**
       Set the XML-RPC API used to access the blog.
     */
-    void setAPI( const APIType & );
+    void setAPI( const QString & );
 
     /**
       Get name of the XML-RPC API used to access the blog.
 
       @return The enumeration of the chosen API.
     */
-    APIType API() const;
+    QString API() const;
 
     /**
       Set whether to display the progress of operations.
@@ -288,7 +271,7 @@
       @param type The type of the error.
       @param errorMessage The specific cause of the error.
     */
-    void slotError( const KBlog::APIBlog::ErrorType &type,
+    void slotError( const KBlog::Blog::ErrorType &type,
                     const QString &errorMessage );
 
     /**
@@ -356,7 +339,7 @@
     /**
       The XML-RPC object used to access the blog.
     */
-    KBlog::APIBlog *mAPI;
+    KBlog::Blog *mAPI;
 
     /**
       The unique ID of the blog to send posts to.
--- trunk/KDE/kdepim/kresources/blog/resourceblogconfig.cpp #694846:694847
@@ -64,8 +64,8 @@
 
   label = new QLabel( i18n( "API:" ), this );
   mAPI = new KComboBox( false, this );
-  mAPI->addItem( "MetaWeblog", ResourceBlog::MetaWeblog );
-  mAPI->addItem( "Blogger", ResourceBlog::Blogger );
+  mAPI->addItem( "MetaWeblog" );
+  mAPI->addItem( "Blogger 1.0" );
 
   mainLayout->addWidget( label, 4, 0 );
   mainLayout->addWidget( mAPI, 4, 1 );
@@ -89,7 +89,7 @@
     mUrl->setUrl( resource->url().url() );
     mUsername->setText( resource->username() );
     mPassword->setText( resource->password() );
-    mAPI->setCurrentIndex( resource->API() );
+    mAPI->setCurrentItem( resource->API(), false );
     QPair<QString, QString> blog = resource->blog();
     if ( !blog.second.isEmpty() ) {
       mBlogs->addItem( blog.second, blog.first );
@@ -98,10 +98,10 @@
     connect ( mAPI, SIGNAL( currentIndexChanged( int ) ),
         this, SLOT( slotBlogAPIChanged( int ) ) );
     mReloadConfig->loadSettings( resource );
-    kDebug( 5700 ) << "ResourceBlogConfig::loadSettings(): reloaded" << endl;
+    kDebug( 5700 ) << "ResourceBlogConfig::loadSettings(): reloaded";
   } else {
     kError( 5700 ) << "ResourceBlogConfig::loadSettings():"
-                   << " no ResourceBlog, cast failed" << endl;
+                   << " no ResourceBlog, cast failed";
   }
 }
 
@@ -112,16 +112,16 @@
     resource->setUrl( mUrl->url().url() );
     resource->setUsername( mUsername->text() );
     resource->setPassword( mPassword->text() );
-    resource->setAPI( resource->QStringToAPIType( mAPI->currentText() ) );
+    resource->setAPI( mAPI->currentText() );
     QPair<QString, QString> blog = resource->blog();
     if ( !mBlogs->currentText().isEmpty() ) {
       resource->setBlog( mBlogs->currentText() );
     }
     mReloadConfig->saveSettings( resource );
-    kDebug( 5700 ) << "ResourceBlogConfig::saveSettings(): saved" << endl;
+    kDebug( 5700 ) << "ResourceBlogConfig::saveSettings(): saved";
   } else {
     kError( 5700 ) << "ResourceBlogConfig::saveSettings():"
-      " no ResourceBlog, cast failed" << endl;
+      " no ResourceBlog, cast failed";
   }
 }
 
@@ -129,7 +129,7 @@
                                                 const QString &name )
 {
   kDebug( 5700 ) << "ResourceBlogConfig::slotBlogInfoRetrieved( id=" << id <<
-      ", name=" << name << endl;
+      ", name=" << name;
   if ( !mBlogs->contains( name ) ) {
     mBlogs->addItem( name );
     mBlogs->setEnabled( true );
@@ -138,14 +138,14 @@
 
 void ResourceBlogConfig::slotBlogAPIChanged( int index )
 {
-  kDebug( 5700 ) << "ResourceBlogConfig::slotBlogAPIChanged" << endl;
+  kDebug( 5700 ) << "ResourceBlogConfig::slotBlogAPIChanged";
   if ( !mBlogs->count() ) {
     // TODO Delete
     ResourceBlog *blog =  new ResourceBlog();
     blog->setUrl( mUrl->url() );
     blog->setUsername( mUsername->text() );
     blog->setPassword( mPassword->text() );
-    blog->setAPI( blog->QStringToAPIType( mAPI->itemText( index ) ) );
+    blog->setAPI( mAPI->itemText( index ) );
     connect ( blog, SIGNAL( signalBlogInfoRetrieved( const QString &, const QString & ) ),
               this, SLOT( slotBlogInfoRetrieved( const QString &, const QString & ) ) );
     blog->fetchBlogs();
[prev in list] [next in list] [prev in thread] [next in thread] 

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