[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: [Kde-pim] KBlog library
From: Christian Weilbach <christian () whiletaker ! homeip ! net>
Date: 2006-09-12 22:56:59
Message-ID: 200609130055.00488.christian () whiletaker ! homeip ! net
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hi,
I'm sending you a first code for the kblog library in kdepimlibs. I don't
want to submit it right now, since the documentation is not finished yet and
I haven't tested the functionality of the ported code yet. But I would like
to know if there are any problems with it.
Cheers,
Christian Weilbach
["blogger.h" (text/x-c++hdr)]
/*
This file is part of kdepimlibs.
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 Christian Weilbach <christian@whiletaker.homeip.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef API_BLOGGER_H
#define API_BLOGGER_H
#include <blog.h>
#include <QtCore/QString>
#include <QtCore/QVariant>
#include <QtCore/QList>
namespace KBlog {
class APIBlogger : public APIBlog
{
public:
APIBlogger( const KUrl &server, QObject *parent = 0L, const char *name = 0L );
virtual ~APIBlogger();
QString getFunctionName( blogFunctions type );
QString interfaceName() const { return "Blogger API 1.0"; }
void userInfo();
void listBlogs();
void listPostings( const KUrl &url );
void listCategories( const KUrl &url );
void fetchPosting( const KUrl &url );
void modifyPosting( const KUrl &url, KBlog::BlogPosting *posting );
void createPosting( KBlog::BlogPosting *posting );
void createMedia( const KUrl &url, KBlog::BlogMedia *media );
void removePosting( const KUrl &url, const QString &postid );
public slots:
void slotUserInfo( const QList<QVariant> &result, const QVariant &id );
void slotListBlogs( const QList<QVariant> &result, const QVariant &id );
void slotListPostings( const QList<QVariant> &result, const QVariant &id );
void slotListCategoriesJob( const QList<QVariant> &result, const QVariant &id );
void slotFetchPosting( const QList<QVariant> &result, const QVariant &id );
void slotCreatePosting( const QList<QVariant> &result, const QVariant &id );
void slotCreateMedia( const QList<QVariant> &result, const QVariant &id );
void faultSlot( int, const QString&, const QVariant& );
protected:
bool readPostingFromMap( BlogPosting *post, const QMap<QString, QVariant> &postInfo );
private:
class Private;
Private* const d;
};
}
#endif
["blog.cpp" (text/x-c++src)]
/*
This file is part of kdepimlibs.
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 Christian Weilbach <christian@whiletaker.homeip.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <kxmlrpcclient/client.h>
#include <QtCore/QVariant>
#include <QtCore/QList>
#include <QtCore/QDateTime>
using namespace KBlog;
class BlogPosting::Private
{
public:
bool mPublish;
QString mUserID;
QString mBlogID;
QString mPostID;
QString mTitle;
QString mContent;
QString mCategory;
QString mFingerprint; // TODO what is that for?
QDateTime mDateTime;
QDateTime mCreationDateTime;
QDateTime mModificationDateTime;
};
BlogPosting::BlogPosting(): d( new Private )
{
d->mPublish=false;
}
BlogPosting::~BlogPosting()
{
delete d;
}
bool BlogPosting::publish() const { return d->mPublish; }
void BlogPosting::setPublish( const bool publish ) { d->mPublish = publish; }
QString BlogPosting::userID() const { return d->mUserID; }
void BlogPosting::setUserID( const QString &userID ) { d->mUserID = userID; }
QString BlogPosting::blogID() const { return d->mBlogID; }
void BlogPosting::setBlogID( const QString &blogID ) { d->mBlogID = blogID; }
QString BlogPosting::postID() const { return d->mPostID; }
void BlogPosting::setPostID( const QString &postID ) { assignPostID( postID ); \
d->mPostID = postID; }
QString BlogPosting::title() const { return d->mTitle; }
void BlogPosting::setTitle( const QString &title ) { d->mTitle = title; }
QString BlogPosting::content() const { return d->mContent; }
void BlogPosting::setContent( const QString &content ) { d->mContent = content; }
QString BlogPosting::category() const { return d->mCategory; }
void BlogPosting::setCategory( const QString &category ) { d->mCategory = category; }
//QString BlogPosting::fingerprint() const { return d->mFingerprint; } // TODO do we \
really need it? //void BlogPosting::setFingerprint( const QString &fp ) { \
d->mFingerprint = fp; }
// TODO check if we need all the dateTime objects
QDateTime BlogPosting::dateTime() const { return d->mDateTime; }
void BlogPosting::setDateTime( const QDateTime &datetime ) { d->mDateTime = datetime; \
}
QDateTime BlogPosting::creationDateTime() const { return d->mCreationDateTime; }
void BlogPosting::setCreationDateTime( const QDateTime &datetime ) { \
d->mCreationDateTime = datetime; }
QDateTime BlogPosting::modificationDateTime() const { return \
d->mModificationDateTime; } void BlogPosting::setModificationDateTime( const \
QDateTime &datetime ) { d->mModificationDateTime = datetime; }
class BlogMedia::Private
{
public:
QString mName;
QString mMimetype;
QByteArray mData;
QString mBlogID;
};
BlogMedia::BlogMedia(): d( new Private ) {}
BlogMedia::~BlogMedia()
{
delete d;
}
QString BlogMedia::name() { return d->mName; }
void BlogMedia::setName( const QString& name ) { d->mName = name; }
QString BlogMedia::mimetype() { return d->mMimetype; }
void BlogMedia::setMimetype( const QString& mimetype ) { d->mMimetype = mimetype; }
QByteArray BlogMedia::data() { return d->mData; }
void BlogMedia::setData( const QByteArray& data ) { d->mData = data; }
QString BlogMedia::blogID() { return d->mBlogID; }
void BlogMedia::setBlogID( const QString& blogID ) { d->mBlogID = blogID; }
class APIBlog::Private
{
public:
QString mAppID;
QString mUsername;
QString mPassword;
KUrl mUrl;
unsigned int mDownloadCount;
};
APIBlog::APIBlog( const KUrl &url, QObject *parent, const char *name ) :
QObject( parent, name ), d( new Private )
{
}
APIBlog::~APIBlog()
{
// TODO check for pending queries of client?
delete d;
}
void APIBlog::setPassword( const QString &pass ) { d->mPassword = pass; }
QString APIBlog::password() const { return d->mPassword; }
void APIBlog::setUsername( const QString &uname ) { d->mUsername = uname; }
QString APIBlog::username() const { return d->mUsername; }
void APIBlog::setUrl( const KUrl& url ) { d->mUrl = url; }
KUrl APIBlog::url() const { return d->mUrl; }
void APIBlog::setDownloadCount( int nr ) { d->mDownloadCount = nr; }
int APIBlog::downloadCount() const { return d->mDownloadCount; }
void APIBlog::dumpBlog( BlogPosting *blog )
{
kndDebug() << "-----------------------------------" << endl;
kndDebug() << "Post " << blog->postID() << " by \"" <<
blog->userID() << "\" on " <<
blog->dateTime().toString() << endl;
kndDebug() << "Title: " << blog->title() << endl;
kndDebug() << blog->content() <<endl;
kndDebug() << "-----------------------------------" << endl;
}
/*void APIBlog::setTemplateTags( const BlogTemplate& Template )
{
mTemplate = Template;
}
BlogTemplate APIBlog::templateTags() const
{
return mTemplate;
}*/
/*void APIBlog::deletePost( const QString &postID )
{
BlogPosting *post = new BlogPosting();
post->setPostID( postID );
deletePost( post );
delete post;
}*/
QList<QVariant> APIBlog::defaultArgs( const QString &id )
{
QList<QVariant> args;
if ( !d->mAppID.isNull() )
args << QVariant( d->mAppID );
if ( !id.isNull() ) {
args << QVariant( id );
}
args << QVariant( d->mUsername )
<< QVariant( d->mPassword );
return args;
}
/*KCal::Journal *APIBlog::journalFromPosting( KBlog::BlogPosting *blog )
{
if ( !blog ) return 0;
KCal::Journal *j = new KCal::Journal();
QDateTime dt = blog->dateTime();
QDateTime creationDt = blog->creationDateTime();
QDateTime modificationDt = blog->modificationDateTime();
kndDebug() << "dt ="<<dt.toString( Qt::ISODate ) << endl;
kndDebug() << "creationDt ="<<creationDt.toString( Qt::ISODate ) << endl;
kndDebug() << "modificationDt="<<modificationDt.toString( Qt::ISODate ) << endl;
if ( dt.isValid() && !dt.isNull() ) {
j->setDtStart( dt );
} else if ( creationDt.isValid() && !creationDt.isNull() ) {
j->setDtStart( creationDt );
} else if ( modificationDt.isValid() && !modificationDt.isNull() ) {
j->setDtStart( modificationDt );
}
j->setCreated( blog->creationDateTime() );
j->setLastModified( blog->modificationDateTime() );
j->setFloats( false );
kndDebug() << "Date for blog " << blog->title() << " is "
<< blog->dateTime().toString()<<endl;
j->setSummary( blog->title() );
j->setDescription( blog->content() );
j->setCategories( QStringList( blog->category() ) );
j->setOrganizer( blog->userID() );
j->setCustomProperty( "KCalBloggerRes", "UserID", blog->userID() );
j->setCustomProperty( "KCalBloggerRes", "BlogID", blog->blogID() );
j->setCustomProperty( "KCalBloggerRes", "PostID", blog->postID() );
// TODO: Set the read-only flag in the resource!
// j->setReadOnly( readOnly() );
return j;
}*/
/*KBlog::BlogPosting *APIBlog::postingFromJournal( KCal::Journal *journal )
{
KBlog::BlogPosting *item = new KBlog::BlogPosting();
if ( journal && item ) {
item->setContent( journal->description() );
item->setTitle( journal->summary() );
item->setCategory( journal->categories().first() );
item->setDateTime( journal->dtStart() );
item->setModificationDateTime( journal->lastModified() );
item->setCreationDateTime( journal->created() );
item->setUserID( journal->customProperty( "KCalBloggerRes", "UserID" ) );
item->setBlogID( journal->customProperty( "KCalBloggerRes", "BlogID" ) );
item->setPostID( journal->customProperty( "KCalBloggerRes", "PostID" ) );
}
return item;
}*/
#include "blog.moc"
["blog.h" (text/x-c++hdr)]
/*
This file is part of kdepimlibs.
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 Christian Weilbach <christian@whiletaker.homeip.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef API_BLOG_H
#define API_BLOG_H
#include <kurl.h>
#include <kio/job.h>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QDateTime>
/**
This is the main interface for blog backends
@author Ian Reinhart Geiser, Reinhold Kainhofer, Christian Weilbach
*/
namespace KBlog {
/**
@file
This file is part of the API for accessing Blog Servers
and defines the #BlogPosting, #BlogMedia, and #APIBlog class.
@author Reinhold Kainhofer <reinhold@kainhofer.com>
@author Christian Weilbach <christian@whiletaker.homeip.net>
\par Maintainer: Christian Weilbach <christian@whiletaker.homeip.net>
*/
/**
@brief
A class that represents a blog posting on the server.
@code
KBlog::BlogPosting *post = new BlogPosting();
post->setUserID( "some_user_id" );
post->setBlogID( "some_blog_id" );
post->setTitle( "This is the title." );
post->setContent( "Here is some the content..." );
@endcode
@author Christian Weilbach <christian@whiletaker.homeip.net>
*/
class BlogPosting
{
public:
BlogPosting();
virtual ~BlogPosting();
bool publish() const;
void setPublish( const bool publish );
QString userID() const;
void setUserID( const QString &userID );
QString blogID() const;
void setBlogID( const QString &blogID );
QString postID() const;
void setPostID( const QString &postID );
QString title() const;
void setTitle( const QString &title );
QString content() const;
void setContent( const QString &content );
QString category() const;
void setCategory( const QString &category );
QDateTime dateTime() const;
void setDateTime( const QDateTime &datetime );
QDateTime creationDateTime() const;
void setCreationDateTime( const QDateTime &datetime );
QDateTime modificationDateTime() const;
void setModificationDateTime( const QDateTime &datetime );
// TODO do we need them?
// virtual void wasDeleted( bool ) {}
// virtual void wasUploaded( bool ) {}
// virtual void error( int /*code*/, const QString &/*error*/ ) {}
protected:
// Override this method to detect the new postID assigned when adding a new post
// TODO: is this easily possible with current API's like MetaWeblog or Blogger?
virtual void assignPostID( const QString &/*postID*/ ) {}
private:
class Private;
Private* const d;
};
/**
@brief
A class that represents a media object on the server.
@code
KBlog::BlogMedia *media = new BlogMedia();
post->setName( "some_name" );
post->setMimetype( "some_mimetype" );
post->setData( some_qbytestream );
@endcode
@author Christian Weilbach <christian@whiletaker.homeip.net>
*/
class BlogMedia {
public:
BlogMedia();
~BlogMedia();
QString name();
void setName( const QString& name );
QString mimetype();
void setMimetype( const QString& mimetype );
QByteArray data();
void setData( const QByteArray& data );
QString blogID();
void setBlogID( const QString& blogID );
private:
class Private;
Private* const d;
};
/**
@brief
A virtual basis class that represents a connection to a blog server.
This is the main interface to the blog client library.
@author Christian Weilbach <christian@whiletaker.homeip.net>
@author Reinhold Kainhofer <reinhold@kainhofer.com>
*/
class APIBlog : public QObject
{
Q_OBJECT
public:
/**
Construtor used by the API implementations.
@param server the server url of the server.
@param parent the parent of this object, defaults to NULL.
@param name the name of the instance.
*/
APIBlog( const KUrl &server, QObject *parent = 0L, const char *name = 0L );
/**
Destroys the APIBlog object.
*/
virtual ~APIBlog();
/**
Returns the API of the inherited object.
*/
virtual QString interfaceName() const = 0;
/**
Sets the password for the blog.
@see password();
*/
void setPassword( const QString &pass );
/**
Returns the password of the blog.
@see setPassword();
*/
QString password() const;
/**
Sets the username for the blog.
@see username()
*/
void setUsername( const QString &uname );
/**
Get the username of the blog.
@see setUsername()
*/
QString username() const;
/**
Sets the URL for the blog.
@see url()
*/
void setUrl( const KUrl& url );
/**
Get the URL for the blog.
@see setUrl()
*/
KUrl url() const;
// TODO once again, do we need this?
void setDownloadCount( int nr );
int downloadCount() const;
// TODO not really sure, if we need this
static void dumpBlog( BlogPosting *blog );
enum blogFunctions {
blogGetUserInfo,
blogGetUsersBlogs,
blogGetCategories,
blogGetRecentPosts,
blogNewPost,
blogNewMedia,
blogEditPost,
blogDeletePost,
blogGetPost,
blogGetTemplate, // not implemented yet
blogSetTemplate // not implemented yet
};
virtual QString getFunctionName( blogFunctions type ) = 0;
virtual QList<QVariant> defaultArgs( const QString &id = QString::null );
virtual void userInfo() = 0;
virtual void listBlogs() = 0;
virtual void listPostings( const KUrl &url ) = 0;
virtual void listCategories( const KUrl &url ) = 0;
virtual void fetchPosting( const KUrl &url ) = 0;
virtual void modifyPosting( const KUrl &url, KBlog::BlogPosting *posting ) = 0;
virtual void createPosting( KBlog::BlogPosting *posting ) = 0;
virtual void createMedia( const KUrl &url, KBlog::BlogMedia *media ) = 0;
virtual void removePosting( const KUrl &url, const QString &postid ) = 0;
signals:
void userInfoRetrieved( const QString &nickname, const QString &userid, const QString &email );
void folderInfoRetrieved( const QString &id, const QString &name );
void categoryInfoRetrieved( const QString &name, const QString &description );
void mediaInfoRetrieved( const QString &url );
void itemOnServer( KBlog::BlogPosting &posting );
void error( const QString &errorMessage );
void uploadPostId( const int );
void fetchingPostsFinished();
void fetchingCategoriesFinished();
private:
class Private;
Private* const d;
};
}
#endif
["blogger.cpp" (text/x-c++src)]
/*
This file is part of kdepimlibs.
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 Christian Weilbach <christian@whiletaker.homeip.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "blog.h"
#include <kxmlrpcclient/client.h>
#include <kdebug.h>
#include <klocale.h>
#include <QtCore/QList>
using namespace KBlog;
class APIBlogger::Private
{
public:
KXmlRpc::Client* mXmlRpcClient;
};
APIBlogger::APIBlogger( const KUrl &server, QObject *parent, const char *name ) : \
APIBlog( server, parent, name ), d( new Private)
{
d->mXmlRpcClient = new KXmlRpc::Client( server );
}
APIBlogger::~APIBlogger()
{
delete d->mXmlRpcClient;
delete d;
}
QString APIBlogger::getFunctionName( blogFunctions type )
{
switch ( type ) {
case blogGetUserInfo: return "blogger.getUserInfo";
case blogGetUsersBlogs: return "blogger.getUsersBlogs";
case blogGetCategories: return "blogger.getCategories"; // not implemented in \
fact case blogGetRecentPosts: return "blogger.getRecentPosts";
case blogNewPost: return "blogger.newPost";
case blogNewMedia: return "blogger.newMedia"; // not implemented in fact
case blogEditPost: return "blogger.editPost";
case blogDeletePost: return "blogger.deletePost";
case blogGetPost: return "blogger.getPost";
case blogGetTemplate: return "blogger.getTemplate";
case blogSetTemplate: return "blogger.setTemplate";
default: return QString::null;
}
}
void APIBlogger::userInfo()
{
kndDebug() << "read user info..." << endl;
QList<QVariant> args( defaultArgs() );
d->mXmlRpcClient->call( getFunctionName( blogGetUserInfo ), args, this, SLOT( \
slotUserInfo(const QList<QVariant>&, const QVariant&) ), this, SLOT( faultSlot( int, \
const QString&, const QVariant& ) ) ); }
void APIBlogger::listBlogs()
{
// TODO: Check if we're already authenticated. If not, do it!
kndDebug() << "Fetch List of Blogs..." << endl;
QList<QVariant> args( defaultArgs() );
d->mXmlRpcClient->call( getFunctionName( blogEditPost ), args, this, SLOT( \
slotListBlogs( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIBlogger::listPostings( const KUrl &url )
{
// TODO: Check if we're already authenticated. If not, do it!
kndDebug() << "Fetch List of Posts..." << endl;
QList<QVariant> args( defaultArgs( url.url() ) );
args << QVariant( downloadCount() );
d->mXmlRpcClient->call( getFunctionName( blogGetRecentPosts ), args, this, SLOT( \
slotListPostings( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIBlogger::listCategories( const KUrl &url ){
kndDebug() << "Categories are not supported in Blogger API 1.0" << endl;
}
void APIBlogger::fetchPosting( const KUrl &url )
{
kndDebug() << "Fetch Posting with url " << url.url() << endl;
QList<QVariant> args( defaultArgs( url.url() ) );
d->mXmlRpcClient->call( getFunctionName( blogGetPost ), args, this, SLOT( \
slotFetchPosting( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIBlogger::modifyPosting( const KUrl &url, KBlog::BlogPosting *posting )
{
if ( !posting ) {
kndDebug() << "APIBlogger::modifyPosting: posting=0" << endl;
}
kndDebug() << "Uploading Posting with url " << url.url() << endl;
QList<QVariant> args( defaultArgs( posting->postID() ) );
args << QVariant( posting->content() );
args << QVariant( posting->publish() );
d->mXmlRpcClient->call( getFunctionName( blogEditPost ), args, this, SLOT( \
slotCreatePosting( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIBlogger::createPosting( KBlog::BlogPosting *posting )
{
if ( !posting ) {
kndDebug() << "APIBlogger::createPosting: posting=0" << endl;
}
kndDebug() << "Creating new Posting with blogid " << posting->blogID() << " at \
url " << url() << endl; QList<QVariant> args( defaultArgs( posting->blogID() ) );
args << QVariant( posting->content() );
args << QVariant( posting->publish() );
d->mXmlRpcClient->call( getFunctionName( blogNewPost ), args, this, SLOT( \
slotCreatePosting( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIBlogger::createMedia( const KUrl &url, KBlog::BlogMedia *media ){
kndDebug() << "APIBlogger::createMedia: not available in Blogger API." << endl;
}
void APIBlogger::removePosting( const KUrl &/*url*/, const QString &postid )
{
kndDebug() << "APIBlogger::removePosting: postid=" << postid << endl;
QList<QVariant> args( defaultArgs( postid ) );
args << QVariant( /*publish=*/true );
d->mXmlRpcClient->call( getFunctionName( blogDeletePost ), args, this, SLOT( \
slotCreateMedia( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIBlogger::slotUserInfo( const QList<QVariant> &result, const QVariant &id )
{
// TODO: Implement user authentication
kndDebug () << "TOP: " << result[ 0 ].typeName() << endl;
const QList<QVariant> posts = result;
QList<QVariant>::ConstIterator it = posts.begin();
QList<QVariant>::ConstIterator end = posts.end();
for ( ; it != end; ++it ) {
kndDebug () << "MIDDLE: " << ( *it ).typeName() << endl;
const QMap<QString, QVariant> postInfo = ( *it ).toMap();
const QString nickname = postInfo[ "nickname" ].toString();
const QString userid = postInfo[ "userid" ].toString();
const QString email = postInfo[ "email" ].toString();
kndDebug() << "Post " << nickname << " " << userid << " " << email << endl;
// FIXME: How about a BlogUserInfo class???
emit userInfoRetrieved( nickname, userid, email );
}
}
void APIBlogger::slotListBlogs( const QList<QVariant> &result, const QVariant &id )
{
kndDebug() << "APIBlogger::slotListBlogs" << endl;
kndDebug () << "TOP: " << result[ 0 ].typeName() << endl;
const QList<QVariant> posts = result[ 0 ].toList();
QList<QVariant>::ConstIterator it = posts.begin();
QList<QVariant>::ConstIterator end = posts.end();
for ( ; it != end; ++it ) {
kndDebug () << "MIDDLE: " << ( *it ).typeName() << endl;
const QMap<QString, QVariant> postInfo = ( *it ).toMap();
const QString id( postInfo[ "blogid" ].toString() );
const QString name( postInfo[ "blogName" ].toString() );
const QString url( postInfo[ "url" ].toString() );
// Use the Blog ID instead of the URL. The ID already indicates the correct blog, \
and the // URL for all calls will be the XML-RPC interface, anyway.
if ( !id.isEmpty() && !name.isEmpty() ) {
emit folderInfoRetrieved( id, name );
kndDebug()<< "Emitting folderInfoRetrieved( id=" << id << ", name=" << name << \
"); " << endl; }
}
}
void APIBlogger::slotListCategoriesJob( const QList<QVariant> &result, const QVariant \
&id ){ kndDebug() << "Categories are not supported in Blogger API 1.0" << endl;
emit error( i18n("Categories are not supported in Blogger API 1.0") );
}
void APIBlogger::slotListPostings( const QList<QVariant> &result, const QVariant &id \
) {
slotFetchPosting( result, id );
}
void APIBlogger::slotFetchPosting( const QList<QVariant> &result, const QVariant &id \
) {
kndDebug(5800)<<"APIBlogger::slotFetchPosting"<<endl;
//array of structs containing ISO.8601 dateCreated, String userid, String postid, \
String content; // TODO: Time zone for the dateCreated!
kndDebug () << "TOP: " << result[ 0 ].typeName() << endl;
const QList<QVariant> postReceived = result[ 0 ].toList();
QList<QVariant>::ConstIterator it = postReceived.begin();
QList<QVariant>::ConstIterator end = postReceived.end();
for ( ; it != end; ++it ) {
BlogPosting posting;
kndDebug () << "MIDDLE: " << ( *it ).typeName() << endl;
const QMap<QString, QVariant> postInfo = ( *it ).toMap();
if ( readPostingFromMap( &posting, postInfo ) ) {
kndDebug() << "Emitting itemOnServer( posting.postID()=" <<posting.postID() << \
"); " << endl; emit itemOnServer( posting ); // KUrl( posting.postID() ) );
} else {
kndDebug() << "readPostingFromMap failed! " << endl;
emit error( i18n("Couldn't read posting.") );
}
}
kndDebug() << "Emitting fetchingPostsFinished()" << endl;
emit fetchingPostsFinished();
}
void APIBlogger::slotCreatePosting( const QList<QVariant> &result, const QVariant &id \
) {
kndDebug(5800)<<"APIBlogger::slotCreatePosting"<<endl;
//array of structs containing ISO.8601 dateCreated, String userid, String postid, \
String content; // TODO: Time zone for the dateCreated!
kndDebug () << "TOP: " << result[ 0 ].typeName() << endl;
const QList<QVariant> postReceived = result[ 0 ].toList();
QList<QVariant>::ConstIterator it = postReceived.begin();
QList<QVariant>::ConstIterator end = postReceived.end();
kndDebug () << "MIDDLE: " << ( *it ).typeName() << endl;
emit uploadPostId( ( *it ).toInt() );
kndDebug() << "emitting uploadPostId( " << ( *it ).toInt() << " )" << endl;
}
void APIBlogger::slotCreateMedia( const QList<QVariant> &result, const QVariant &id \
){ kndDebug()<< "Sending Media is not available in Blogger API." << endl;
emit error ( i18n( "Sending Media is not available in Blogger API." ) );
}
void APIBlogger::faultSlot( int number, const QString& errorString, const QVariant& \
id ) {
emit error( errorString );
}
bool APIBlogger::readPostingFromMap( BlogPosting *post, const QMap<QString, QVariant> \
&postInfo ) {
// FIXME: integrate error handling
if ( !post ) return false;
QStringList mapkeys = postInfo.keys();
kndDebug() << endl << "Keys: " << mapkeys.join(", ") << endl << endl;
QDateTime dt( postInfo[ "dateCreated" ].toDateTime() );
if ( dt.isValid() && !dt.isNull() ) {
post->setCreationDateTime( dt );
}
dt = postInfo[ "postDate" ].toDateTime();
if ( dt.isValid() && !dt.isNull() ) {
post->setDateTime( dt );
}
dt = postInfo[ "lastModified" ].toDateTime();
if ( dt.isValid() && !dt.isNull() ) {
post->setModificationDateTime( dt );
}
post->setUserID( postInfo[ "userid" ].toString() );
post->setPostID( postInfo[ "postid" ].toString() );
QString title( postInfo[ "title" ].toString() );
QString description( postInfo[ "description" ].toString() );
QString contents( postInfo[ "content" ].toString() );
QString category;
post->setTitle( title );
post->setContent( contents );
if ( !category.isEmpty() )
post->setCategory( category );
return true;
}
["CMakeLists.txt" (text/plain)]
project(kblog)
add_subdirectory( tests )
include_directories( ${KDE4_KIO_INCLUDES} )
add_definitions(${QDBUS_DEFINITIONS})
########### next target ###############
set(kblog_LIB_SRCS
blog.cpp
blog.cpp
metaweblog.cpp
)
kde4_automoc(${kblog_LIB_SRCS})
kde4_add_library(kblog SHARED ${kblog_LIB_SRCS})
target_link_libraries(kblog kxmlrpcclient ${KDE4_KIO_LIBS} )
set_target_properties(kblog PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION \
${GENERIC_LIB_SOVERSION} ) install(TARGETS kblog DESTINATION ${LIB_INSTALL_DIR} )
install( FILES kblog.h blog.h blog.h metaweblog.h DESTINATION \
${INCLUDE_INSTALL_DIR}/kblog)
["kblog.h" (text/x-chdr)]
/*
This file is part of kdepimlibs.
Copyright (c) 2006 Christian Weilbach <christian@whiletaker.homeip.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KBLOG_H
#define KBLOG_H
#include <kdemacros.h>
#if defined(_WIN32) || defined(_WIN64)
#ifdef MAKE_KBLOG_LIB
#define KBLOG_EXPORT KDE_EXPORT
#else
#define KBLOG_EXPORT KDE_IMPORT
#endif
#else
#define KBLOG_EXPORT KDE_EXPORT
#endif
#endif
["metaweblog.cpp" (text/x-c++src)]
/*
This file is part of kdepimlibs.
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 Christian Weilbach <christian@whiletaker.homeip.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "metaweblog.h"
#include "kxmlrpcclient/client.h"
#include <kdebug.h>
#include <klocale.h>
#include <QtCore/QList>
using namespace KBlog;
class APIMetaWeblog::Private
{
public:
KXmlRpc::Client* mXmlRpcClient;
};
APIMetaWeblog::APIMetaWeblog( const KUrl &server, QObject *parent, const char *name ) \
: APIBlog( server, parent, name ), d( new Private)
{
d->mXmlRpcClient = new KXmlRpc::Client( server );
}
APIMetaWeblog::~APIMetaWeblog()
{
delete d->mXmlRpcClient;
delete d;
}
QString APIMetaWeblog::getFunctionName( blogFunctions type )
{
switch ( type ) {
case blogGetUserInfo: return "metaWeblog.getUserInfo";
case blogGetUsersBlogs: return "metaWeblog.getUsersBlogs";
case blogGetCategories: return "metaWeblog.getCategories";
case blogGetRecentPosts: return "metaWeblog.getRecentPosts";
case blogNewPost: return "metaWeblog.newPost";
case blogNewMedia: return "metaWeblog.newMediaObject";
case blogEditPost: return "metaWeblog.editPost";
case blogDeletePost: return "metaWeblog.deletePost";
case blogGetPost: return "metaWeblog.getPost";
case blogGetTemplate: return "metaWeblog.getTemplate";
case blogSetTemplate: return "metaWeblog.setTemplate";
default: return QString::null;
}
}
void APIMetaWeblog::userInfo()
{
kndDebug() << "userInfo(): getUserInfo is not available in MetaWeblog API." << \
endl; emit error( i18n( "User info is not available in MetaWeblog API." ) );
}
void APIMetaWeblog::listBlogs()
{
kndDebug() << "userInfo(): getUsersBlogs is not available in MetaWeblog API." << \
endl; emit error( i18n( "Fetching user's blogs is not available in MetaWeblog API." \
) ); }
void APIMetaWeblog::listPostings( const KUrl &url )
{
// TODO: Check if we're already authenticated. If not, do it!
kndDebug() << "Fetch List of Posts..." << endl;
QList<QVariant> args( defaultArgs( url.url() ) );
args << QVariant( downloadCount() );
d->mXmlRpcClient->call( getFunctionName( blogGetRecentPosts ), args, this, SLOT( \
slotListPostings( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIMetaWeblog::listCategories( const KUrl &url ){
kndDebug() << "Fetch List of Categories..." << endl;
QList<QVariant> args( defaultArgs( url.url() ) );
d->mXmlRpcClient->call( getFunctionName( blogGetCategories ), args, this, SLOT( \
slotListCategories( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( \
faultSlot( int, const QString&, const QVariant& ) ) );
}
void APIMetaWeblog::fetchPosting( const KUrl &url )
{
kndDebug() << "Fetch Posting with url " << url.url() << endl;
QList<QVariant> args( defaultArgs( url.url() ) );
d->mXmlRpcClient->call( getFunctionName( blogGetPost ), args, this, SLOT( \
slotFetchPosting( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIMetaWeblog::modifyPosting( const KUrl &url, KBlog::BlogPosting *posting )
{
if ( !posting ) {
kndDebug() << "APIMetaWeblog::modifyPosting: posting=0" << endl;
}
kndDebug() << "Uploading Posting with url " << url.url() << endl;
QList<QVariant> args( defaultArgs( posting->postID() ) );
QMap<QString, QVariant> map;
QList<QVariant> list;
list.append( QString( posting->category() ) );
map["categories"]=list;
map["description"]=posting->content();
map["title"]=posting->title();
QDateTime date;
map["dateCreated"]=date.currentDateTime();
args << map;
args << QVariant( posting->publish() );
d->mXmlRpcClient->call( getFunctionName( blogEditPost ), args, this, SLOT( \
slotCreatePosting( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIMetaWeblog::createPosting( KBlog::BlogPosting *posting )
{
if ( !posting ) {
kndDebug() << "APIMetaWeblog::createPosting: posting=0" << endl;
}
kndDebug() << "Creating new Posting with blogid " << posting->blogID() << " at url \
" << url() << endl; QList<QVariant> args( defaultArgs( posting->blogID() ) );
QMap<QString, QVariant> map;
QList<QVariant> list;
list.append( QString( posting->category() ) );
map["categories"]=list;
map["description"]=posting->content();
map["title"]=posting->title();
QDateTime date;
map["dateCreated"]=date.currentDateTime(); // TODO use original date of result?
args << map;
args << QVariant( posting->publish() );
d->mXmlRpcClient->call( getFunctionName( blogNewPost ), args, this, SLOT( \
slotCreatePosting( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIMetaWeblog::createMedia( const KUrl &url, KBlog::BlogMedia *media ){
kndDebug() << "APIMetaWeblog::createMedia: name="<< media->name() << endl;
QList<QVariant> args( defaultArgs( media->blogID() ) );
QMap<QString, QVariant> map;
QList<QVariant> list;
map["name"]=media->name();
map["type"]=media->mimetype();
map["bits"]=media->data();
args << map;
d->mXmlRpcClient->call( getFunctionName( blogNewMedia ), args, this, SLOT( \
slotCreateMedia( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIMetaWeblog::removePosting( const KUrl &/*url*/, const QString &postid )
{
kndDebug() << "APIMetaWeblog::removePosting: postid=" << postid << endl;
QList<QVariant> args( defaultArgs( postid ) );
args << QVariant( /*publish=*/true );
d->mXmlRpcClient->call( getFunctionName( blogDeletePost ), args, this, SLOT( \
slotCreateMedia( QList<QVariant> &result, QVariant &id ) ), this, SLOT ( faultSlot( \
int, const QString&, const QVariant& ) ) ); }
void APIMetaWeblog::slotUserInfo( const QList<QVariant> &result, const QVariant &id )
{
kndDebug()<< "APIMetaWeblog::slotUserInfo not implemented for MetaWeblog API" << \
endl; }
void APIMetaWeblog::slotListBlogs( const QList<QVariant> &result, const QVariant &id \
) {
kndDebug() << "APIMetaWeblog::slotListBlogs not implemented for MetaWeblog API" << \
endl; }
void APIMetaWeblog::slotListCategories( const QList<QVariant> &result, const QVariant \
&id ) {
kndDebug() << "APIMetaWeblog::slotListCategories" << endl;
kndDebug () << "TOP: " << result[0].typeName() << endl;
const QMap<QString, QVariant> categories = result[0].toMap();
const QList<QString> categoryNames = categories.keys();
QList<QString>::ConstIterator it = categoryNames.begin();
QList<QString>::ConstIterator end = categoryNames.end();
for ( ; it != end; ++it ) {
kndDebug () << "MIDDLE: " << ( *it ) << endl;
const QString name( *it );
const QMap<QString, QVariant> category = categories[ *it ].toMap();
const QString description( category["description"].toString() );
if ( !name.isEmpty() ) {
emit categoryInfoRetrieved( name, description );
kndDebug()<< "Emitting categorieInfoRetrieved( name=" << name << " \
description=" << description << " ); " << endl; }
}
kndDebug() << "Emitting fetchingCategoriesFinished()" << endl;
emit fetchingCategoriesFinished();
}
void APIMetaWeblog::slotListPostings( const QList<QVariant> &result, const QVariant \
&id ) {
kndDebug()<<"APIMetaWeblog::slotListPostings"<<endl;
kndDebug () << "TOP: " << result[ 0 ].typeName() << endl;
const QList<QVariant> postReceived = result[ 0 ].toList();
QList<QVariant>::ConstIterator it = postReceived.begin();
QList<QVariant>::ConstIterator end = postReceived.end();
for ( ; it != end; ++it ) {
BlogPosting posting;
kndDebug () << "MIDDLE: " << ( *it ).typeName() << endl;
const QMap<QString, QVariant> postInfo = ( *it ).toMap();
if ( readPostingFromMap( &posting, postInfo ) ) {
kndDebug() << "Emitting itemOnServer( posting with postID()=" << \
posting.postID() << "); " << endl; emit itemOnServer( posting ); //KUrl( \
posting.postID() ) ); } else {
kndDebug() << "readPostingFromMap failed! " << endl;
emit error( i18n( "Couldn't read posting." ) );
}
}
kndDebug() << "Emitting fetchingPostsFinished() " << endl;
emit fetchingPostsFinished();
}
void APIMetaWeblog::slotFetchPosting( const QList<QVariant> &result, const QVariant \
&id ) {
//array of structs containing ISO.8601 dateCreated, String userid, String postid, \
String content; // TODO: Time zone for the dateCreated!
kndDebug () << "TOP: " << result[ 0 ].typeName() << endl;
BlogPosting posting;
const QMap<QString, QVariant> postInfo = result[ 0 ].toMap();
if ( readPostingFromMap( &posting, postInfo ) ) {
kndDebug() << "Emitting itemOnServer( posting with postID()=" << \
posting.postID() << "); " << endl; emit itemOnServer( posting ); //KUrl( \
posting.postID() ) ); } else {
kndDebug() << "readPostingFromMap failed! " << endl;
emit error( "Couldn't read posting." );
}
}
void APIMetaWeblog::slotCreatePosting( const QList<QVariant> &result, const QVariant \
&id ) {
//array of structs containing ISO.8601 dateCreated, String userid, String postid, \
String content; // TODO: Time zone for the dateCreated!
kndDebug () << "TOP: " << result[ 0 ].typeName() << endl;
QString postId = result[ 0 ].toString();
kndDebug() << "MIDDLE: postId=" << postId << endl;
emit uploadPostId( postId.toInt() );
kndDebug() << "Emitting uploadPostId( " << postId.toInt() << " )" << endl;
}
void APIMetaWeblog::slotCreateMedia( const QList<QVariant> &result, const QVariant \
&id ) {
kndDebug() << "APIMetaWeblog::slotCreateMedia, no error!" << endl;
kndDebug () << "TOP: " << result[0].typeName() << endl;
const QMap<QString, QVariant> resultStruct = result[0].toMap();
const QString url = resultStruct["url"].toString();
kndDebug() << "APIMetaWeblog::slotCreateMedia url="<< url << endl;
if ( !url.isEmpty() ) {
emit mediaInfoRetrieved( url );
kndDebug()<< "Emitting mediaInfoRetrieved( url=" << url << " ); " << endl;
}
}
void APIMetaWeblog::faultSlot( int number, const QString& errorString, const \
QVariant& id ) {
emit error( errorString );
}
bool APIMetaWeblog::readPostingFromMap( BlogPosting *post, const QMap<QString, \
QVariant> &postInfo ) {
// FIXME: integrate error handling
if ( !post ) return false;
QStringList mapkeys = postInfo.keys();
kndDebug() << endl << "Keys: " << mapkeys.join(", ") << endl << endl;
QDateTime dt( postInfo[ "dateCreated" ].toDateTime() );
if ( dt.isValid() && !dt.isNull() ) {
post->setCreationDateTime( dt );
}
dt = postInfo[ "postDate" ].toDateTime();
if ( dt.isValid() && !dt.isNull() ) {
post->setDateTime( dt );
}
dt = postInfo[ "lastModified" ].toDateTime();
if ( dt.isValid() && !dt.isNull() ) {
post->setModificationDateTime( dt );
}
post->setUserID( postInfo[ "userid" ].toString() );
post->setPostID( postInfo[ "postid" ].toString() );
QString title( postInfo[ "title" ].toString() );
QString description( postInfo[ "description" ].toString() );
// QString contents( postInfo[ "content" ].toString() ); // FIXME delete if not \
necessary QList<QVariant> categories( postInfo[ "categories" ].toList() );
post->setTitle( title );
post->setContent( description );
if ( !categories.isEmpty() ){
QString category = ( *categories.begin() ).toString();
kndDebug() << "Category: " << category << endl;
post->setCategory( category );
}
return true;
}
["metaweblog.h" (text/x-c++hdr)]
/*
This file is part of kdepimlibs.
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 Christian Weilbach <christian@whiletaker.homeip.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef API_METAWEBLOG_H
#define API_METAWEBLOG_H
#include "blog.h"
#include <QtCore/QString>
#include <QtCore/QVariant>
#include <QtCore/QList>
namespace KBlog {
class APIMetaWeblog : public APIBlog
{
public:
APIMetaWeblog( const KUrl &server, QObject *parent = 0L, const char *name = 0L );
~APIMetaWeblog();
QString getFunctionName( blogFunctions type );
QString interfaceName() const { return "MetaWeblog API"; }
void userInfo();
void listBlogs();
void listPostings( const KUrl &url );
void listCategories( const KUrl &url );
void fetchPosting( const KUrl &url );
void modifyPosting( const KUrl &url, KBlog::BlogPosting *posting );
void createPosting( KBlog::BlogPosting *posting );
void createMedia( const KUrl &url, KBlog::BlogMedia *media );
void removePosting( const KUrl &url, const QString &postid );
public slots:
void slotUserInfo( const QList<QVariant> &result, const QVariant &id );
void slotListBlogs( const QList<QVariant> &result, const QVariant &id );
void slotListPostings( const QList<QVariant> &result, const QVariant &id );
void slotListCategories( const QList<QVariant> &result, const QVariant &id );
void slotFetchPosting( const QList<QVariant> &result, const QVariant &id );
void slotCreatePosting( const QList<QVariant> &result, const QVariant &id );
void slotCreateMedia( const QList<QVariant> &result, const QVariant &id );
void faultSlot( int, const QString&, const QVariant& );
protected:
bool readPostingFromMap( BlogPosting *post, const QMap<QString, QVariant> &postInfo );
private:
class Private;
Private* const d;
};
}
#endif
[Attachment #15 (application/pgp-signature)]
_______________________________________________
kde-pim mailing list
kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic