• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KBlog Client Library

movabletype.cpp

00001 /*
00002   This file is part of the kblog library.
00003 
00004   Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005   Copyright (c) 2006-2007 Christian Weilbach <christian_weilbach@web.de>
00006   Copyright (c) 2007 Mike Arthur <mike@mikearthur.co.uk>
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Library General Public
00010   License as published by the Free Software Foundation; either
00011   version 2 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Library General Public License for more details.
00017 
00018   You should have received a copy of the GNU Library General Public License
00019   along with this library; see the file COPYING.LIB.  If not, write to
00020   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021   Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "movabletype.h"
00025 #include "movabletype_p.h"
00026 #include "blogpost.h"
00027 
00028 #include <kxmlrpcclient/client.h>
00029 
00030 #include <KDebug>
00031 #include <KLocale>
00032 #include <KDateTime>
00033 
00034 #include <QtCore/QStringList>
00035 
00036 using namespace KBlog;
00037 
00038 MovableType::MovableType( const KUrl &server, QObject *parent )
00039   : MetaWeblog( server, *new MovableTypePrivate, parent )
00040 {
00041   kDebug(5323) << "MovableType()";
00042 }
00043 
00044 MovableType::MovableType( const KUrl &server, MovableTypePrivate &dd,
00045                         QObject *parent )
00046   : MetaWeblog( server, dd, parent )
00047 {
00048   kDebug(5323) << "MovableType()";
00049 }
00050 
00051 MovableType::~MovableType()
00052 {
00053   kDebug(5323) << "~MovableType()";
00054 }
00055 
00056 QString MovableType::interfaceName() const
00057 {
00058   return QLatin1String( "Movable Type" );
00059 }
00060 
00061 void MovableType::listRecentPosts( int number )
00062 {
00063     Q_D( MovableType );
00064     kDebug(5323) << "Fetching List of Posts...";
00065     QList<QVariant> args( d->defaultArgs( blogId() ) );
00066     args << QVariant( number );
00067     d->mXmlRpcClient->call(
00068       "metaWeblog.getRecentPosts", args,
00069       this, SLOT(slotListRecentPosts(const QList<QVariant>&,const QVariant&)),
00070       this, SLOT(slotError(int,const QString&,const QVariant&)),
00071       QVariant( number ) );
00072 }
00073 
00074 void MovableType::listTrackBackPings( KBlog::BlogPost *post )
00075 {
00076   Q_D( MovableType );
00077   kDebug(5323) << "List trackback pings...";
00078   QList<QVariant> args;
00079   args << QVariant( post->postId() );
00080   unsigned int i = d->mCallCounter++;
00081   d->mCallMap[ i ] = post;
00082   d->mXmlRpcClient->call(
00083     "mt.getTracebackPings", args,
00084     this, SLOT(slotListTrackbackPings(const QList<QVariant>&,const QVariant&)),
00085     this, SLOT(slotError(int,const QString&,const QVariant&)),
00086     QVariant( i ) );
00087 }
00088 
00089 MovableTypePrivate::MovableTypePrivate()
00090 {
00091 }
00092 
00093 MovableTypePrivate::~MovableTypePrivate()
00094 {
00095   kDebug(5323) << "~MovableTypePrivate()";
00096 }
00097 
00098 QList<QVariant> MovableTypePrivate::defaultArgs( const QString &id )
00099 {
00100   Q_Q( MovableType );
00101   QList<QVariant> args;
00102   if( !id.isEmpty() ) {
00103     args << QVariant( id );
00104   }
00105   args << QVariant( q->username() )
00106        << QVariant( q->password() );
00107   return args;
00108 }
00109 
00110 bool MovableTypePrivate::readPostFromMap( BlogPost *post, const QMap<QString, QVariant> &postInfo )
00111 {
00112 
00113   // FIXME: integrate error handling
00114   kDebug(5323) << "readPostFromMap()";
00115   if ( !post ) {
00116     return false;
00117   }
00118   QStringList mapkeys = postInfo.keys();
00119   kDebug(5323) << endl << "Keys:" << mapkeys.join( ", " );
00120   kDebug(5323) << endl;
00121 
00122   KDateTime dt =
00123     KDateTime( postInfo["dateCreated"].toDateTime(), KDateTime::UTC );
00124   if ( dt.isValid() && !dt.isNull() ) {
00125     post->setCreationDateTime( dt );
00126   }
00127 
00128   dt =
00129     KDateTime( postInfo["lastModified"].toDateTime(), KDateTime::UTC );
00130   if ( dt.isValid() && !dt.isNull() ) {
00131     post->setModificationDateTime( dt );
00132   }
00133 
00134   post->setPostId( postInfo["postid"].toString() );
00135 
00136   QString title( postInfo["title"].toString() );
00137   QString description( postInfo["description"].toString() );
00138   QStringList categories( postInfo["categories"].toStringList() );
00139   //TODO 2 new keys are:
00140   // String mt_convert_breaks, the value for the convert_breaks field
00141   // String mt_text_more, the value for the additional entry text
00142   post->setTitle( title );
00143   post->setContent( description );
00144   post->setCommentAllowed( (bool)postInfo["mt_allow_comments"].toInt() );
00145   post->setTrackBackAllowed( (bool)postInfo["mt_allow_pings"].toInt() );
00146   post->setSummary( postInfo["mt_excerpt"].toString() );
00147   post->setTags( postInfo["mt_keywords"].toStringList() );
00148   post->setLink( postInfo["link"].toString() );
00149   post->setPermaLink( postInfo["permaLink"].toString() );
00150 
00151   if ( !categories.isEmpty() ){
00152     kDebug(5323) << "Categories:" << categories;
00153     post->setCategories( categories );
00154   }
00155   return true;
00156 }
00157 
00158 void MovableTypePrivate::slotListTrackBackPings(
00159     const QList<QVariant> &result, const QVariant &id )
00160 {
00161   Q_Q( MovableType );
00162   kDebug(5323) << "slotTrackbackPings()";
00163   BlogPost *post = mCallMap[ id.toInt() ];
00164   mCallMap.remove( id.toInt() );
00165   QList<QMap<QString,QString> > trackBackList;
00166   if ( result[0].type() != QVariant::List ) {
00167     kError(5323) << "Could not fetch list of trackback pings out of the"
00168                  << "result from the server.";
00169     emit q->error( MovableType::ParsingError,
00170                    i18n( "Could not fetch list of trackback pings out of the "
00171                          "result from the server." ) );
00172   } else {
00173     const QList<QVariant> trackBackReceived = result[0].toList();
00174     QList<QVariant>::ConstIterator it = trackBackReceived.begin();
00175     QList<QVariant>::ConstIterator end = trackBackReceived.end();
00176     for ( ; it != end; ++it ) {
00177       QMap<QString,QString> tping;
00178       kDebug(5323) << "MIDDLE:" << ( *it ).typeName();
00179       const QMap<QString, QVariant> trackBackInfo = ( *it ).toMap();
00180       tping[ "title" ] = trackBackInfo[ "pingTitle"].toString();
00181       tping[ "url" ] = trackBackInfo[ "pingURL"].toString();
00182       tping[ "ip" ] = trackBackInfo[ "pingIP"].toString();
00183       trackBackList << tping;
00184     }
00185   }
00186   kDebug(5323) << "Emitting listedTrackBackPings()";
00187   emit q->listedTrackBackPings( post, trackBackList );
00188 }
00189 
00190 bool MovableTypePrivate::readArgsFromPost( QList<QVariant> *args, const BlogPost &post )
00191 {
00192   //TODO 3 new keys are:
00193   // String mt_convert_breaks, the value for the convert_breaks field
00194   // String mt_text_more, the value for the additional entry text
00195   // array mt_tb_ping_urls, the list of TrackBack ping URLs for this entry
00196   if ( !args ) {
00197     return false;
00198   }
00199   QMap<QString, QVariant> map;
00200   map["categories"] = post.categories();
00201   map["description"] = post.content();
00202   map["title"] = post.title();
00203   map["dateCreated"] = post.creationDateTime().toUtc().dateTime();
00204   map["mt_allow_comments"] = (int)post.isCommentAllowed();
00205   map["mt_allow_pings"] = (int)post.isTrackBackAllowed();
00206   map["mt_excerpt"] = post.summary();
00207   map["mt_keywords"] = post.tags(); // TODO some convertion needed?
00208   //map["mt_tb_ping_urls"] check for that, i think this should only be done on the server.
00209   *args << map;
00210   *args << QVariant( !post.isPrivate() );
00211   return true;
00212 }
00213 
00214 #include "movabletype.moc"

KBlog Client Library

Skip menu "KBlog Client Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal