[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/pim/kblogger
From: Antonio Aloisio <antonio.aloisio () gmail ! com>
Date: 2007-08-05 16:16:16
Message-ID: 1186330576.506772.21954.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 696682 by aloisio:
backendJobs partially writted, added new class kbloggerBlog
D NOT_PORTED_YET (directory)
M +48 -13 src/backend.cpp
M +25 -26 src/backend.h
M +105 -44 src/backendjobs.cpp
M +31 -18 src/backendjobs.h
M +1 -1 src/composer.cpp
A src/kbloggerblog.h [License: LGPL (v2+)]
--- trunk/playground/pim/kblogger/src/backend.cpp #696681:696682
@@ -26,9 +26,11 @@
#include <kmessagebox.h>
#include <klocale.h>
-#include <kblog/blogger1.h>
-#include <kblog/metaweblog.h>
-#include <kblog/gdata.h>
+
+#include <kblog/blogger1.h> //REMOVE
+#include <kblog/metaweblog.h> //REMOVE
+#include <kblog/gdata.h> //REMOVE
+
#include <kmessagebox.h>
#include <threadweaver/ThreadWeaver.h>>
@@ -37,15 +39,15 @@
#include "postingsmanager.h"
#include "kbloggerposting.h"
+#include "kbloggerblog.h"
#include "kblogger.h"
#include "profileconfig.h"
#include "backendjobs.h"
using namespace KBlog;
+
+namespace KBlogger{
-namespace KBlogger
-{
-
backend *backend::s_self = 0;
backend *backend::self(QObject* parent)
@@ -60,7 +62,7 @@
mPostingsManager = postingsManager::self(this);
connect (mPostingsManager, SIGNAL( post( KBloggerPosting* ) ), this, SLOT( \
sendPost( KBloggerPosting* )));
- connect ( ThreadWeaver::Weaver::instance(), SIGNAL ( finished() ), SLOT \
(slotStopped () ) ); //TODO slotStopped + connect ( \
ThreadWeaver::Weaver::instance(), SIGNAL ( finished() ), SLOT (slotStopped() ) ); \
//TODO slotStopped
connect ( ThreadWeaver::Weaver::instance(), SIGNAL ( jobDone(ThreadWeaver::Job*) \
),
SLOT (slotJobDone (ThreadWeaver::Job*) ) ); //TODO slotJobDone
connect ( ThreadWeaver::Weaver::instance(), SIGNAL ( suspended() ), SLOT \
(slotStopped () ) ); //TODO slotStopped @@ -117,11 +119,34 @@
i18n("Account doesn't setteted"));
return;
}
- listRecentPostingsJob *mJob=new listRecentPostingsJob(downloadCount, mBackend, \
this);
- mPendingJobs.addJob(mJob);
- ThreadWeaver::Weaver::instance()->enqueue (mJob); //Start the thread!:)
+ connect(mBackend,SIGNAL( listedRecentPostings( const QList<KBlog::BlogPosting*>& \
) ), + this,SLOT( slotListedRecentPostings( const QList<KBlog::BlogPosting*>& )));
+ //backendJobs *mJob=new backendJobs(downloadCount, mBackend, this);
+ // mPendingJobs.addJob(mJob);
+ // ThreadWeaver::Weaver::instance()->enqueue (mJob); //Start! :)
+
}
+void backend::slotListedRecentPostings( const QList<KBlog::BlogPosting*>& postings){
+ kDebug() << "backend::slotListedRecentPostings:" << postings << endl;
+ //<< " state:" << ThreadWeaver::Weaver::instance()->state() << endl;
+}
+void backend::slotStopped(){
+ kDebug() << "backend::slotStopped" << endl;
+}
+
+void backend::slotJobDone (ThreadWeaver::Job* j){
+ kDebug() << "backend::slotJobDone" << endl;
+ backendJobs* job = dynamic_cast<backendJobs*> ( j );//FIXME move to genericJob
+
+ if ( job )
+ {
+ //todo something with job->result() );
+ } else {
+ kDebug ()<< "I do not know anything about this kind of jobs." << endl;
+ }
+}
+
void backend::listedPostingSlot( KBlog::BlogPosting &posting )
{
kDebug() << "backend::listedPostingSlot" << endl;
@@ -251,12 +276,22 @@
mBackend->removePosting(posting);
}
+void backend::addBlog(const QString& blogname){
+ kDebug() << "backend::addBlog" << endl;
+
+}
+
+void backend::delBlog(const QString& blogname){
+ kDebug() << "backend::delBlog" << endl;
+}
+
void backend::listPostingsFinishedSlot()
{
kDebug() << "backend::listPostingsFinished()" << endl;
mBackend->disconnect( SIGNAL( listedPosting( KBlog::BlogPosting &) ));
mBackend->disconnect( SIGNAL( fetchedPosting( KBlog::BlogPosting &) ));
mBackend->disconnect( SIGNAL( listPostingsFinished() ));
+
/*while (!fetchedEntries.isEmpty()){
KBloggerPosting *mPosting=fetchedEntries.takeLast();
kDebug() << "\t sending post with ID" << mPosting->postingId() << endl;
@@ -344,15 +379,15 @@
//Creating the backend
switch ( mProfileconfig->type() ) {
case BLOGGER_API:
- mBackend = new KBlog::Blogger1 ( mServerUrl, this );
+ mBackend = new KBlog::Blogger1 ( mServerUrl, 0 );
break;
case METAWEBLOG_API:
- mBackend = new KBlog::MetaWeblog ( mServerUrl, this );
+ mBackend = new KBlog::MetaWeblog ( mServerUrl, 0 );
break;
case GDATA_API:
- mBackend = new KBlog::GData( mServerUrl, this );
+ mBackend = new KBlog::GData( mServerUrl, 0 );
break;
}
currentProfile = blogName.remove("Account_");
--- trunk/playground/pim/kblogger/src/backend.h #696681:696682
@@ -25,7 +25,7 @@
#ifndef BACKEND_H
#define BACKEND_H
-// #include <QThread>
+
#include <kdatetime.h>
#include <kblog/blog.h>
@@ -37,7 +37,7 @@
*
* @short Backend class
* @author Antonio Aloisio <gnuton@gnuton.org>
- * @version 0.1
+ * @version 0.2
*/
namespace KBlogger
@@ -47,23 +47,18 @@
class postingsManager;
class KBloggerPosting;
-class backend : public QObject //TODO Use a QThread
+class backend : public QObject
{
Q_OBJECT
public:
- /**
- * Enumeration for possible Api.
- */
+ //Classes
+ class kbloggerBlog;
+
+ //Enumeration for possible Api.
enum api_type { BLOGGER_API = 0, METAWEBLOG_API, GDATA_API };
static backend *self(QObject* parent = 0);
~backend();
-
- // Return the interface name from kblog api. (BLOGGER, METWEBLOG...)
- QString interfaceName()
- {
- return mBackend->interfaceName();
- }
///Blog's functions (jobs)
// List the blogs available for this authentication on the server.
@@ -87,8 +82,8 @@
const KDateTime &datetime );
///Others functions
- void addBackend(const QString& blogname){}; //TODO
- void delBackend(const QString& blogname){}; //TODO
+ void addBlog(const QString& blogname);
+ void delBlog(const QString& blogname);
public Q_SLOTS:
@@ -101,6 +96,13 @@
void sync();
private Q_SLOTS:
+
+ void slotListedRecentPostings( const QList<KBlog::BlogPosting*>& postings);
+ void slotStopped();
+ void slotJobDone (ThreadWeaver::Job*);
+
+
+/** OLD **************/
// Disconnect Categories Slot.
void disconnectCategoriesSlot();
@@ -113,14 +115,15 @@
//Shows error messages.
void error( KBlog::Blog::ErrorType type, const QString &errorMessage );
+ void postListReaded();
+ void listedPostingSlot( KBlog::BlogPosting &posting );
+ void fetchedPostingSlot( KBlog::BlogPosting &posting )
+ {
+ emit fetchedPosting( posting );
+ };
/**
- * Disconnect signals of postingsManager->getPosts()
- */
- void postListReaded();
-
- /**
* Inform the user that the post has been created on the server
* and it tries to send another post.
*/
@@ -131,12 +134,7 @@
*/
void postingRemoved(bool modified);
- void listedPostingSlot( KBlog::BlogPosting &posting );
- void fetchedPostingSlot( KBlog::BlogPosting &posting )
- {
- emit fetchedPosting( posting );
- };
void listPostingsFinishedSlot();
@@ -147,12 +145,13 @@
backend( QObject* parent = 0);
//Vars
static backend *s_self;
- KBlog::Blog* mBackend; //Remove
- QMap<QString,KBlog::Blog*> backendList; //QString contains the blogname
postingsManager *mPostingsManager;
kblogger *m_kblogger;
+ QList<kbloggerBlog> *blogsList;
ThreadWeaver::JobCollection mPendingJobs; //use mPendingJobs->addJob (new \
DummyJob (this) );
+ //Remove this vars.
+ KBlog::Blog* mBackend; //Remove
KBloggerPosting* currentItem; //REMOVE
QString currentProfile; //REMOVE
--- trunk/playground/pim/kblogger/src/backendjobs.cpp #696681:696682
@@ -19,76 +19,137 @@
***************************************************************************/
#include "backendjobs.h"
+
+#include <QEventLoop>
+
#include <threadweaver/Thread.h>
-#include <kblog/metaweblog.h>
#include <kurl.h>
#include <kdebug.h>
-namespace KBlogger {
+#include <kblog/blogger1.h>
+#include <kblog/metaweblog.h>
+#include <kblog/gdata.h>
-///DummyJob
-DummyJob::DummyJob (QObject* parent)
- : ThreadWeaver::Job ( parent )
-{
+#include "backend.h"
+#include "kbloggerblog.h"
-}
+#define APPLICATION_NAME "KBlogger"
+#define APPLICATION_VER "0.8-wip"
+#define POSTING_TO_DOWNLOAD 5
-void DummyJob::run ()
-{
- // the job will take (... sleep) a random number of msec between 1 and
- // 1000:
-// thread()->msleep( 1+(int) ( 1000.0*rand () / (RAND_MAX+1.0) ) );
-}
+namespace KBlogger {
-///listRecentPostingsJob
-listRecentPostingsJob::listRecentPostingsJob (int postingsNumber, KBlog::Blog* \
backend, QObject* parent)
- : ThreadWeaver::Job ( parent ), mBackend(backend), \
mPostingsNumber(postingsNumber) +///backendJobs
+backendJobs::backendJobs( kbloggerBlog *backendInfo,
+ Do action,
+ QVariant arg,
+ QObject* parent ):
+ ThreadWeaver::Job ( parent ),
+ mAction(action),
+ mArg(arg),
+ mLoop(new QEventLoop(0))
{
+ kDebug() << "backendJobs::backendJobs" << endl;
+ Q_ASSERT(createBackend(backendInfo));
}
-QList<KBlog::BlogPosting*> listRecentPostingsJob::getPostings(){
- return mPostings;
+backendJobs::~backendJobs(){
+ kDebug() << "backendJobs::~backendJobs" << endl;
}
-void listRecentPostingsJob::run ()
+void backendJobs::run ()
{
- kDebug() << "DEBUG THREAD" << endl;
- loop= new QEventLoop(0);
+ kDebug() << "\tThread Run" << endl;
+ //QMimeType settings
qRegisterMetaType< QList<KBlog::BlogPosting*> >("QList<KBlog::BlogPosting*>");
qRegisterMetaType< KBlog::Blog::ErrorType >("KBlog::Blog::ErrorType");
+ qRegisterMetaType< QVariant >( "QVariant" );
- KBlog::MetaWeblog *mBackend= new \
KBlog::MetaWeblog(KUrl("http://www.gnuton.org/blog/xmlrpc.php"),0);
- mBackend->moveToThread (thread());
- mBackend->setBlogId ( "1" );
- mBackend->setUsername ( "gnuton_user" );
- mBackend->setPassword ( "" );
-
- connect(mBackend, SIGNAL( listedRecentPostings( const QList<KBlog::BlogPosting*>& \
) ),
- this, SLOT( exitOK( ) ) );
+ //Defaul connections
connect(mBackend, SIGNAL( error( KBlog::Blog::ErrorType, const QString& ) ),
- this, SLOT( exitError( )) );
+ this, SLOT( eslotError( KBlog::Blog::ErrorType, const QString&) ) );
- mBackend->listRecentPostings(mPostingsNumber);
- loop->exec();
+ //Specific connections
+ switch(mAction){
+ case LIST_RECENT_POSTINGS:{
+ connect(mBackend, SIGNAL( listedRecentPostings( const \
QList<KBlog::BlogPosting*>& ) ), + this, SLOT( \
slotListedRecentPostings( const QList<KBlog::BlogPosting*>& ) ) ); + int \
postingToDownload=POSTING_TO_DOWNLOAD; +
+ mBackend->listRecentPostings( postingToDownload );
+ }break;
+
+ case FETCH_POSTINGS:{
+ }break;
+
+ case MODIFY_POSTINGS:{
+ }break;
+
+ case CREATE_POSTINGS:{
+ }break;
+
+ case REMOVE_POSTINGS:{
+ }break;
+ }
+
+ mLoop->exec();
}
-
-void listRecentPostingsJob::exitSuccess(){
- kDebug() << "exitSuccess" << endl;
- //disconnect( SIGNAL(listedRecentPostings( const QList<KBlog::BlogPosting*>&)) );
- //mPostings=postings;
- loop->exit();
+
+///Private Slots
+void backendJobs::slotError( KBlog::Blog::ErrorType errorType, const QString& \
message){ + kDebug() << "backendJobs::slotError" << endl;
+ QVariant t(errorType);
+ QVariant m(message);
+ mResults << t << m;
+ exitError();
}
-void listRecentPostingsJob::exitError( ){
- kDebug() << "exitError" << endl;
- //disconnect( SIGNAL(showError( KBlog::Blog::ErrorType type, const QString \
&errorMessage )));
- loop->exit();
- //TODO
+void backendJobs::slotListedRecentPostings( const QList<KBlog::BlogPosting*>& \
postings ){ + kDebug() << "backendJobs::slotListedRecentPostings" << endl;
+
}
+///Private
+void backendJobs::exitSuccess(){
+ kDebug() << "backendJobs::exitSuccess" << endl;
+ mLoop->exit();
}
+void backendJobs::exitError(){
+ kDebug() << "backendJobs::exitError" << endl;
+ mLoop->exit();
+}
+
+bool backendJobs::createBackend(kbloggerBlog *backendInfo){
+ kDebug() << "backendJobs::createBackend" << endl;
+ if ( backendInfo ) return false;
+
+ switch (backendInfo->api()){
+ case backend::BLOGGER_API:{
+ mBackend = new KBlog::Blogger1( KUrl() , 0 );
+ }break;
+ case backend::METAWEBLOG_API:{
+ mBackend = new KBlog::MetaWeblog( KUrl() , 0 );
+ }break;
+ case backend::GDATA_API:{
+ mBackend = new KBlog::GData( KUrl() , 0 );
+ }break;
+
+
+ }
+
+ if (mBackend){
+ mBackend->setUrl( backendInfo->xmlrpcUrl() );
+ mBackend->setBlogId ( backendInfo->blogId() );
+ mBackend->setUsername ( backendInfo->username() );
+ mBackend->setPassword ( backendInfo->password() );
+ }
+ return true;
+}
+
+}
+
#include "backendjobs.moc"
-
\ No newline at end of file
+
\ No newline at end of file
--- trunk/playground/pim/kblogger/src/backendjobs.h #696681:696682
@@ -21,44 +21,57 @@
#ifndef KBLOGGERBACKENDJOBS_H
#define KBLOGGERBACKENDJOBS_H
-#include <QEventLoop>
+#include <QList>
+#include <QVariant>
#include <threadweaver/Job.h>
#include <threadweaver/ThreadWeaver.h>
#include <kblog/blog.h>
+#include "backend.h"
+
+class QEventLoop;
+
namespace KBlogger {
-//DummyJob
-class DummyJob : public ThreadWeaver::Job{
+class kbloggerBlog;
+
+class backendJobs : public ThreadWeaver::Job{
Q_OBJECT
+
+enum Do { LIST_RECENT_POSTINGS, FETCH_POSTINGS, MODIFY_POSTINGS,
+ CREATE_POSTINGS, REMOVE_POSTINGS };
public:
- DummyJob( QObject* parent = 0 );
+ //listRecentPostings( const int number )
+ //fetchPosting( KBlog::BlogPosting *posting )
+ //modifyPosting( KBlog::BlogPosting *posting )
+ //createPosting( KBlog::BlogPosting *posting )
+ //removePosting( KBlog::BlogPosting *posting )
-protected:
- void run();
-};
-
-/** listRecentPostingsJob **/
-class listRecentPostingsJob : public ThreadWeaver::Job{
-Q_OBJECT
-
-public:
- listRecentPostingsJob( int postingsNumber, KBlog::Blog* backend ,QObject* parent = \
0 );
- QList<KBlog::BlogPosting*> getPostings();
+ backendJobs( kbloggerBlog *backendInfo, Do action, QVariant arg ,QObject* parent = \
0 ); +
+ virtual ~backendJobs();
+ //results overloaded functions
+
protected:
void run();
private slots:
+ void slotError( KBlog::Blog::ErrorType errorType, const QString& message);
+ void slotListedRecentPostings( const QList<KBlog::BlogPosting*>& postings );
+
+private:
+ bool createBackend(kbloggerBlog *backendInfo);
void exitSuccess();
void exitError( );
private:
KBlog::Blog* mBackend;
- int mPostingsNumber;
- QList<KBlog::BlogPosting*> mPostings;
- QEventLoop *loop;
+ QVariant mArg;
+ QList<QVariant> mResults;
+ Do mAction;
+ QEventLoop *mLoop;
};
}
--- trunk/playground/pim/kblogger/src/composer.cpp #696681:696682
@@ -214,7 +214,7 @@
CategoryComboBox->clear();
categoriesList->clear();
mBackend->disconnect(SIGNAL ( categoryInfoRetrieved ( const QString&, const \
QString& ) ));
- if ( mBackend->interfaceName() != "Blogger API 1.0" ) { // Only Blogger API \
doesn't support a title and categories + if ( 1 /*mBackend->interfaceName() != \
"Blogger API 1.0"*/ ) { // Only Blogger API doesn't support a title and categories \
TitleLineEdit->setReadOnly ( false ); CategoryComboBox->setEditable ( true );
TimeStampCheckBox->setEnabled ( true );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic