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

List:       kde-commits
Subject:    playground/pim/kblogger/src
From:       Christian Weilbach <christian () whiletaker ! homeip ! net>
Date:       2008-01-31 19:00:44
Message-ID: 1201806044.884735.21036.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 769175 by weilbach:

Renamed BackendJob to BlogJob (not BlowJob :P) and strapped all dependencies on \
KBlogger out of it, so we can move it to KBlog. d_ptr is already basically done, need \
to check for private inheritance. Signals for the events are needed, maybe we can put \
the information with member functions in the result. KBlogger is currently broken due \
to not having ItemsManager ported to Backend yet. It is imo really not good to use \
singletons to call the from everywhere and replace the SIGNAL and SLOT behaviour with \
that. It breaks clear interfaces.


 M  +2 -2      CMakeLists.txt  
 M  +76 -46    backend/backend.cpp  
 M  +7 -12     backend/backend.h  
 D             backend/backendjob.cpp  
 D             backend/backendjob.h  
 D             backend/backendjobqueue.cpp  
 D             backend/backendjobqueue.h  
 A             backend/blogjob.cpp   [License: GPL (v2+)]
 A             backend/blogjob.h   [License: GPL (v2+)]
 A             backend/blogjob_p.h   [License: GPL (v2+)]
 A             backend/blogjobqueue.cpp   [License: GPL (v2+)]
 A             backend/blogjobqueue.h   [License: GPL (v2+)]


--- trunk/playground/pim/kblogger/src/CMakeLists.txt #769174:769175
@@ -38,8 +38,8 @@
    profiles/profileconfigdialog.cpp
    backend/bloghash.cpp
    backend/backend.cpp
-   backend/backendjob.cpp
-   backend/backendjobqueue.cpp
+   backend/blogjob.cpp
+   backend/blogjobqueue.cpp
    backend/waitwidget.cpp
    backend/waitdialog.cpp
    itemsmanager.cpp
--- trunk/playground/pim/kblogger/src/backend/backend.cpp #769174:769175
@@ -32,8 +32,9 @@
 #include "blogserver.h"
 #include "mainwindow.h"
 #include "profileconfig.h"
-#include "backend/backendjob.h"
-#include "backend/backendjobqueue.h"
+#include "backend/blogjob.h"
+#include "backend/bloghash.h"
+#include "backend/blogjobqueue.h"
 #include "backend/waitdialog.h"
 
 Q_DECLARE_METATYPE(KBlogger::Post*);
@@ -69,7 +70,7 @@
 
     mItemsManager = ItemsManager::self(this);
     delete mJobsQueue;
-    mJobsQueue = new BackendJobQueue(this);
+    mJobsQueue = new BlogJobQueue(this);
 
     connect(mJobsQueue, SIGNAL(jobDone()),
             this, SLOT( slotJobDone() ));
@@ -99,8 +100,8 @@
     delete mWaitDialog;
     // create mWaitDialog with max jobs size and mMainWindow as its parent
     mWaitDialog = new WaitDialog( mJobsQueue->queueSize(), mMainWindow );
-    connect( mWaitDialog, SIGNAL( cancelClicked() ), 
-             this, SLOT( slotStopQueue() ) );
+    connect( mWaitDialog, SIGNAL( closed() ),
+             this, SLOT( slotCancelClicked() ) );
     connect( mJobsQueue, SIGNAL(waitMessage(QString)),
             mWaitDialog, SLOT( setText(QString) ));
     mWaitDialog->show();
@@ -155,10 +156,8 @@
     BlogServer blog = blogsMap[blogname];
     kDebug() << "blogname of blog is" << blog.blogname() << endl;
 
-    BackendJob *mJob = new BackendJob(blog,
-                                        BackendJob::LIST_RECENT_POSTS,
-                                        n, caller,
-                                        this);
+    BlogJob *mJob = createBlogJob(blog,BlogJob::LIST_RECENT_POSTS,n);
+    jobToWidget[mJob]=caller;
     if (mJobsQueue->addJob(mJob)){
         runQueuedJobs();
     }
@@ -170,12 +169,12 @@
     BlogServer blog = blogsMap[blogname];
     if (!caller)
         caller = qobject_cast<QWidget*>(mMainWindow);
-    BackendJob *mJob = new BackendJob(blog,
-                                        BackendJob::FETCH_CATEGORIES,
-                                        0, caller,
-                                        this);
+    QVariant n(0);
+    BlogJob *mJob = createBlogJob(blog,BlogJob::FETCH_CATEGORIES,n);
     connect( mJob, SIGNAL(listedCategories(const QList<QMap<QString, QString> >&)),
              this, SLOT(slotListedCategories(const QList<QMap<QString, QString> >& \
))); +
+    jobToWidget[mJob]=caller;
     if ( mJobsQueue->addJob(mJob) ) {
         runQueuedJobs();
     }
@@ -186,44 +185,40 @@
     kDebug();
     Q_ASSERT(kbPost);
 
-    if (!caller) caller = qobject_cast<QWidget*>(mMainWindow);
-
     if ( kbPost->status() != KBlog::BlogPost::New ) {
         kError() << "This post is already uploaded, is this a bug?" << endl;
         return;
     }
 
+    if (!caller)
+       caller = qobject_cast<QWidget*>(mMainWindow);
+
     kDebug() << "\tPost Title:" << kbPost->title() << endl;
     kDebug() << "\tContent:" << kbPost->content() << endl;
     kDebug() << "\tCategories:" << kbPost->categories().join(", ") << endl;
     kDebug() << "\tDateTime:" <<  kbPost->creationDateTime().dateTime().toString() \
<< endl;  
-    //Test: The post is sent only if all media in it are already uploaded.
-    /*  if ( kbPost->hasPendingMedia() ) {
-            KMessageBox::sorry( 0 ,
-                                i18n("This post cannot be uploaded. Upload its media \
                first"));
-            return;
-        }*/
+    if ( kbPost->hasPendingMedia() ) {
+        KMessageBox::sorry( caller ,
+                     i18n("This post cannot be uploaded. Upload its media first"));
+        return;
+    }
 
     QVariant n;
     n.setValue(kbPost);
 
     BlogServer blog = blogsMap[kbPost->getBlogName()];
-    BackendJob *mJob;
+    BlogJob *mJob;
     QString statusBarMsg;
     if ( QString(kbPost->postId()).isEmpty() ) {
-        mJob = new BackendJob(blog,
-                               BackendJob::CREATE_POST,
-                               n, caller,
-                               this);
+        mJob = createBlogJob(blog,BlogJob::CREATE_POST,n);
         statusBarMsg = i18n("New post upload enqueued in the job list.");
     } else {
-        mJob = new BackendJob(blog,
-                               BackendJob::MODIFY_POST,
-                               n, caller,
-                               this);
+        mJob = createBlogJob(blog,BlogJob::MODIFY_POST,n);
         statusBarMsg = i18n("Modified post upload enqueued in the job list.");
     }
+
+    jobToWidget[mJob]=caller;
     if ( mJobsQueue->addJob(mJob) )
         emit statusBarMessage( statusBarMsg );
     else
@@ -246,10 +241,9 @@
     QVariant n;
     n.setValue(kbPost);
     BlogServer blog = blogsMap[kbPost->getBlogName()];
-    BackendJob *mJob = new BackendJob(blog,
-                                        BackendJob::FETCH_POST,
-                                        n, caller,
-                                        this);
+    BlogJob *mJob = createBlogJob(blog,BlogJob::FETCH_POST,n);
+
+    jobToWidget[mJob]=caller;
     mJobsQueue->addJob(mJob);
 }
 
@@ -260,6 +254,12 @@
     if (!caller)
         caller = qobject_cast<QWidget*>(mMainWindow);
 
+    if ( kbPost->hasPendingMedia() ) {
+        KMessageBox::sorry( caller ,
+                     i18n("This post cannot be uploaded. Upload its media first"));
+        return;
+    }
+
     QString id = kbPost->postId();
     if (id.isEmpty()){
        kDebug() << "The id is empty.";
@@ -270,10 +270,8 @@
     n.setValue(kbPost);
 
     BlogServer blog = blogsMap[kbPost->getBlogName()];
-    BackendJob *mJob = new BackendJob(blog,
-                                        BackendJob::REMOVE_POST,
-                                        n, caller,
-                                        this);
+    BlogJob *mJob = createBlogJob(blog,BlogJob::REMOVE_POST,n);
+    jobToWidget[mJob]=caller;
     if ( mJobsQueue->addJob(mJob) ) {
         runQueuedJobs();
     }
@@ -285,15 +283,20 @@
     Q_ASSERT(kbMedia);
     if (!caller)
         caller = qobject_cast<QWidget*>(mMainWindow);
+
+//     if ( kbMedia->hasPendingMedia() ) {
+//         KMessageBox::sorry( caller ,
+//                      i18n("This post cannot be uploaded. Upload its media \
first")); +//         return;
+//     }
+
     KBlog::BlogMedia *media = static_cast<KBlog::BlogMedia*>(kbMedia);
-
     QVariant n;
     n.setValue(media);
     BlogServer blog = blogsMap[ kbMedia->getBlogname() ];
-    BackendJob *mJob = new BackendJob(  blog,
-                                          BackendJob::CREATE_MEDIA,
-                                          n, caller,
-                                          this);
+    BlogJob *mJob = createBlogJob(blog,BlogJob::CREATE_MEDIA,n);
+
+    jobToWidget[mJob]=caller;
     if ( mJobsQueue->addJob(mJob) )
         emit statusBarMessage( i18n("New Media upload enqueued in the job list.") );
     else
@@ -306,7 +309,6 @@
     mJobsQueue->clear();
     mItemsManager->enqueueMediaToUpload();
     mItemsManager->enqueuePostsToUpload();
-
     runQueuedJobs();
 }
 
@@ -333,7 +335,7 @@
 void Backend::slotJobsDone()
 {
     kDebug();
-    delete mWaitDialog;
+    if(mWaitDialog) mWaitDialog->close();
     mWaitDialog = 0;
     emit statusBarMessage(i18n("All Jobs Done."));
     emit jobsFinished();
@@ -348,10 +350,17 @@
 void Backend::slotJobsStopped()
 {
     kDebug();
-    delete mWaitDialog;
+    if(mWaitDialog) mWaitDialog->close();
     mWaitDialog = 0;
 }
 
+void Backend::slotCancelClicked()
+{
+    kDebug();
+    mWaitDialog = 0;
+    mJobsQueue->stop();
+}
+
 void Backend::slotError( const QString& message )
 {
     kDebug();
@@ -370,6 +379,27 @@
     return blogsMap.values();
 }
 
+BlogJob* Backend::createBlogJob( BlogServer &blogServer, BlogJob::BlogActions \
action, QVariant& arg ) +{
+    kDebug();
+    kDebug() << "BlogServer blogname=" << blogServer.blogname() << endl;
+    QList<QHash<QString,QVariant> > blogList = BlogList();
+    QHash<QString,QVariant> blogHash = blogList[blogServer.type()];
+    QString api = blogHash["api"].toString();
+    KUrl url = blogServer.url();
+    if( api == "Blogger1" )
+        return new BlogJob( BlogJob::BLOGGER1, url, action, arg, this );
+    if( api == "MetaWeblog" )
+        return new BlogJob( BlogJob::METAWEBLOG, url, action, arg, this );
+    if( api == "MovableType" )
+        return new BlogJob( BlogJob::MOVABLETYPE, url, action, arg, this );
+    if( api == "WordpressBuggy" )
+        return new BlogJob( BlogJob::WORDPRESSBUGGY, url, action, arg, this );
+    if( api == "GData" )
+        return new BlogJob( BlogJob::GDATA, url, action, arg, this );
+    return 0;
+}
+
 } //namespace
 
 #include "backend.moc"
--- trunk/playground/pim/kblogger/src/backend/backend.h #769174:769175
@@ -23,7 +23,8 @@
 
 #include <kdatetime.h>
 
-#include "backend/backendjobqueue.h"
+#include "backend/blogjobqueue.h"
+#include "backend/blogjob.h"
 
 namespace KBlogger
 {
@@ -32,7 +33,6 @@
 class ItemsManager;
 class Post;
 class BlogServer;
-class BackendJob;
 class Media;
 class BackendJobQueue;
 class WaitDialog;
@@ -45,17 +45,10 @@
 
 class Backend : public QObject
 {
-    friend class BackendJob;
+//     friend class BlogJob;
 
     Q_OBJECT
 public:
-    enum api_type { BLOGGER_API = 0,
-                    METAWEBLOG_API,
-                    MOVABLETYPE_API,
-                    WORDPRESSBUGGY_API,
-                    GDATA_API
-                  };
-
     //Singleton
     static Backend *self(QObject* parent = 0);
 
@@ -92,21 +85,23 @@
     void slotJobsDone();
     void slotJobDone();
     void slotJobsStopped();
+    void slotCancelClicked();
     void slotError(const QString&);
 
 private:
     //Default Costructor
     Backend( QObject* parent = 0);
     void initialize();
-    //void killCurrentJob();
+    BlogJob* createBlogJob( BlogServer&, BlogJob::BlogActions, QVariant& );
 
     //Vars
     static Backend *s_self;
     ItemsManager *mItemsManager;
     MainWindow *mMainWindow;
     QMap<QString, BlogServer> blogsMap;
-    BackendJobQueue *mJobsQueue;
+    BlogJobQueue *mJobsQueue;
     WaitDialog* mWaitDialog;
+    QMap<BlogJob*,QWidget*> jobToWidget;
 
 Q_SIGNALS:
     void listedCategories( const QList< QMap<QString, QString> >& categories );


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

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