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

List:       kde-commits
Subject:    playground/pim/kblogger
From:       Christian Weilbach <christian () whiletaker ! homeip ! net>
Date:       2008-01-28 18:49:09
Message-ID: 1201546149.741917.13643.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 767768 by weilbach:

Fix building. Trying to move GUI stuff out of the backend, at least only to Backend. \
The progress bar is broken at the moment.


 M  +3 -3      TODO  
 M  +56 -35    src/backend/backend.cpp  
 M  +13 -12    src/backend/backend.h  
 M  +5 -29     src/backend/backendjobqueue.cpp  
 M  +7 -8      src/backend/backendjobqueue.h  
 M  +3 -11     src/backend/waitdialog.cpp  
 M  +2 -5      src/backend/waitdialog.h  
 M  +1 -2      src/backend/waitwidget.cpp  
 M  +2 -2      src/composer/composer.cpp  


--- trunk/playground/pim/kblogger/TODO #767767:767768
@@ -39,9 +39,9 @@
      gnuton: editor magic, main gui
 
      -----------------------------+---- duns_s ------+------- gnuton -------
-     Backend                      |        B         |
-     BackendJob                   |        B         |
-     BackendJobQueue              |        B         |
+     Backend                      |        0         |
+     BackendJob                   |        0         |
+     BackendJobQueue              |        0         |
      Media                        |        O         |
      Post                         |        O         |
      BlogServer                   |        O         |
--- trunk/playground/pim/kblogger/src/backend/backend.cpp #767767:767768
@@ -33,7 +33,8 @@
 #include "mainwindow.h"
 #include "profileconfig.h"
 #include "backend/backendjob.h"
-#include "waitdialog.h"
+#include "backend/backendjobqueue.h"
+#include "backend/waitdialog.h"
 
 Q_DECLARE_METATYPE(KBlogger::Post*);
 Q_DECLARE_METATYPE(KBlog::BlogMedia*);
@@ -53,7 +54,8 @@
     return s_self;
 }
 
-Backend::Backend( QObject* parent): QObject(parent)
+Backend::Backend( QObject* parent): QObject(parent),
+    mWaitDialog(0), mJobsQueue(0)
 {
     kDebug();
     mKblogger = qobject_cast<MainWindow*> (parent);
@@ -67,29 +69,67 @@
 
     //ItemsManager
     mItemsManager = ItemsManager::self(this);
+    delete mJobsQueue;
     mJobsQueue = new BackendJobQueue(this);
 
     connect(mJobsQueue, SIGNAL(jobDone()),
-            this, SLOT(slotJobDone()));
+            this, SLOT( slotJobDone() ));
+    connect(mJobsQueue, SIGNAL(jobsStopped()),
+            this, SLOT( slotJobsStopped() ));
     connect(mJobsQueue, SIGNAL(jobsDone()),
             this, SLOT( slotJobsDone() ));
+    connect(mJobsQueue, SIGNAL(statusMessage(const QString&)),
+            this, SLOT( slotStatusMessage(const QString&) ));
+    connect(mJobsQueue, SIGNAL(statusError(const QString&)),
+            this, SLOT( slotError(const QString&) ));
 }
 
 Backend::~Backend()
 {
     kDebug();
+    delete mWaitDialog;
+    delete mJobsQueue;
     s_self = 0;
 }
 
 void Backend::runQueuedJobs()
 {
     kDebug();
+
+    // show the wait dialog with the progress bar
+    delete mWaitDialog;
+    // create mWaitDialog with max jobs size and mKblogger as its parent
+    mWaitDialog = new WaitDialog( mJobsQueue->queueSize(), mKblogger );
+    connect( mWaitDialog, SIGNAL( cancelClicked() ), 
+             this, SLOT( stopQueue() ) );
+    connect( mJobsQueue, SIGNAL(waitMessage(QString)),
+            mWaitDialog, SLOT( setText(QString) ));
+    mWaitDialog->show();
     mJobsQueue->run();
 }
 
-BlogServer Backend::getKbloggerBlog(const QString& blogname)
+void Backend::slotJobDone()
 {
     kDebug();
+    mWaitDialog->jobDone();
+}
+
+void Backend::slotJobsStopped()
+{
+    kDebug();
+    delete mWaitDialog;
+    mWaitDialog = 0;
+}
+
+void Backend::slotError( const QString& message )
+{
+    kDebug();
+    emit errorMessage(message);
+}
+
+BlogServer Backend::getBlogServer(const QString& blogname)
+{
+    kDebug();
     return blogsMap[blogname];
 }
 
@@ -106,7 +146,7 @@
                                         n, caller,
                                         this);
     if ( mJobsQueue->addJob(mJob) ) {
-        mJobsQueue->run();
+        runQueuedJobs();
     }
 }
 
@@ -121,7 +161,7 @@
                                         0, caller,
                                         this);
     if ( mJobsQueue->addJob(mJob) ) {
-        mJobsQueue->run();
+        runQueuedJobs();
     }
 }
 
@@ -218,7 +258,7 @@
                                         n, caller,
                                         this);
     if ( mJobsQueue->addJob(mJob) ) {
-        mJobsQueue->run();
+        runQueuedJobs();
     }
 }
 
@@ -245,15 +285,6 @@
         emit statusBarMessage( i18n("It is impossible to enqueue this new media.") \
);  }
 
-/*
-void Backend::listBlogs() //void blogInfoRetrieved( const QString &id, const QString \
                &name );
-{
-        connect ( mBackend, SIGNAL ( blogInfoRetrieved( const QString&, const \
                QString& )),
-                  this, SLOT ( blogInfoRetrievedSlot( const QString&, const QString& \
                ) ));
-        mBackend->listBlogs();
-}
-*/
-
 void Backend::sync()
 {
     kDebug();
@@ -265,7 +296,7 @@
     //TODO Update sentList?
 
     //run the enquenqued jobs
-    mJobsQueue->run();
+    runQueuedJobs();
 }
 
 
@@ -309,18 +340,6 @@
     }
 }
 
-int Backend::jobsQueued()
-{
-    kDebug();
-    return mJobsQueue->queueSize();
-}
-
-void Backend::showStatusBarMessage(const QString& message)
-{
-    kDebug();
-    emit statusBarMessage(message);
-}
-
 QList<BlogServer> Backend::getBlogList()
 {
     kDebug();
@@ -337,6 +356,12 @@
     statusBarMessage( i18n("All jobs have been removed from the queue.") );
 }
 
+void Backend::showStatusBarMessage( const QString& message )
+{
+    kDebug();
+    emit statusBarMessage(message);
+}
+
 /*
 void Backend::killCurrentJob(){
     kDebug();
@@ -353,15 +378,11 @@
     emit categoryInfoRetrieved ( categories );
 }
 
-void Backend::slotJobDone()
-{
-    kDebug();
-    mJobsQueue->jobDone();
-}
-
 void Backend::slotJobsDone()
 {
     kDebug();
+    delete mWaitDialog;
+    mWaitDialog = 0;
     emit statusBarMessage(i18n("All Jobs Done."));
     emit jobsFinished();
 }
--- trunk/playground/pim/kblogger/src/backend/backend.h #767767:767768
@@ -25,7 +25,7 @@
 // needed for the ErrorType here only
 #include <kblog/blog.h>
 
-#include "backend/backendjobqueue.h"
+// #include "backend/backendjobqueue.h"
 
 namespace KBlogger
 {
@@ -36,11 +36,13 @@
 class BlogServer;
 class BackendJob;
 class Media;
+class BackendJobQueue;
+class WaitDialog;
 
 /**
   @brief
   This class uses BackendJobQueue and feeds it BackendJob[s]. It is the way to talk \
                to
-  servers for KBlogger.
+  servers for KBlogger. It also handles showing the WaitDialog.
 */
 
 class Backend : public QObject
@@ -62,12 +64,12 @@
     ~Backend();
 
     //return the BlogServer that contains infos
-    BlogServer getKbloggerBlog(const QString& blogname);
+    BlogServer getBlogServer(const QString& blogname);
 
     void runQueuedJobs();
 
     ///Blog's functions (jobs)
-    //List recent posts on the serve
+    //List recent posts on the serve, is run immediatly
     void listPosts(const QString& blogname, int downloadCount = 5, QWidget *caller = \
                0);
     // List the categories of the blog. @see getCategoriesSlot(), \
listCategoriesFinished()  void listCategories(const QString& blogname, QWidget \
*caller = 0); @@ -75,7 +77,7 @@
     void sendPost( Post* kbPost, QWidget *caller = 0 );
     //Fetch Post
     void fetchPost(Post* kbPost, QWidget *caller = 0);
-    //Remove a post from the server.
+    //Remove a post from the server, is run immediatly.
     void removePost( Post *kbPost, QWidget *caller = 0 );
     //Send Media
     void sendMedia( Media *kbMedia, QWidget *caller = 0 );
@@ -86,11 +88,6 @@
 
     void populateBlogsList();
 
-    /// BackendJobQueue functions
-    int jobsQueued();
-
-    void showStatusBarMessage(const QString& message);
-
     ///BlogsMap functions
     QList<BlogServer> getBlogList();
 
@@ -99,16 +96,18 @@
     // (Upload new or modified posts, medias and  delete posts)
     void sync();
     void stopQueue();
+    void showStatusBarMessage(const QString&);
 
-
 private Q_SLOTS:
     //Shows error messages.
     void slotError( KBlog::Blog::ErrorType type, const QString &errorMessage );
 
     void categoryRetrieved ( const QList< QMap<QString, QString> >& categories );
 
+    void slotJobsDone();
     void slotJobDone();
-    void slotJobsDone();
+    void slotJobsStopped();
+    void slotError(const QString&);
 
 private:
     //Default Costructor
@@ -122,11 +121,13 @@
     MainWindow *mKblogger;
     QMap<QString, BlogServer> blogsMap;
     BackendJobQueue *mJobsQueue;
+    WaitDialog* mWaitDialog;
 
 Q_SIGNALS:
     void categoryInfoRetrieved( const QList< QMap<QString, QString> >& categories );
     void statusBarMessage( const QString& message );
     void jobsFinished();
+    void errorMessage( const QString& message );
 };
 
 }
--- trunk/playground/pim/kblogger/src/backend/backendjobqueue.cpp #767767:767768
@@ -19,15 +19,12 @@
  ***************************************************************************/
 
 #include "backend/backendjobqueue.h"
-#include "backend/backend.h"
 
 #include <kdebug.h>
 #include <kjob.h>
 #include <klocale.h>
-#include <kmessagebox.h>
 
 #include "backend/backendjob.h"
-#include "backend/waitdialog.h"
 
 namespace KBlogger
 {
@@ -69,8 +66,7 @@
 
 
 
-BackendJobQueue::BackendJobQueue(QObject *parent): QObject(parent),
-    mWaitDialog(0)
+BackendJobQueue::BackendJobQueue(QObject *parent): QObject(parent)
 {
     kDebug();
     d = new BackendJobQueue_p();
@@ -80,7 +76,6 @@
 {
     kDebug();
     delete d;
-    delete mWaitDialog;
 }
 
 bool BackendJobQueue::addJob( BackendJob* job )
@@ -127,12 +122,6 @@
     mPendingJobs.clear();
 }
 
-void BackendJobQueue::jobDone()
-{
-    kDebug();
-    mWaitDialog->jobDone();
-}
-
 /*
 bool BackendJobQueue::killCurrentJob()
 {
@@ -165,8 +154,6 @@
         emit jobsStopped();
         d->setRunning(false);
         d->setStop(false);
-        delete mWaitDialog;
-        mWaitDialog = 0;
         return;
     }
 
@@ -174,21 +161,13 @@
         BackendJob* currentJob = mPendingJobs.takeFirst();
         Q_ASSERT(currentJob);
 
-        QString message = i18np("1 job left", "%1 jobs left", mPendingJobs.count());
-        Backend::self()->showStatusBarMessage(message);
+        emit waitMessage( currentJob->getWaitMessage() );
+        emit statusMessage( i18np("1 job left", "%1 jobs left", \
mPendingJobs.count()) );  
-        // show the wait dialog with the progress bar
-        delete mWaitDialog;
-        mWaitDialog = new WaitDialog( currentJob->getWidgetParent() );
-        mWaitDialog->setText( currentJob->getWaitMessage() );
-        mWaitDialog->show();
-
         connect(currentJob, SIGNAL( result( KJob * ) ),
                 this, SLOT( slotResult( KJob * ) ) );
         currentJob->start();
     } else {
-        delete mWaitDialog;
-        mWaitDialog = 0;
         d->setRunning(false);
         emit jobsDone();
     }
@@ -197,17 +176,14 @@
 void BackendJobQueue::slotResult( KJob * job)
 {
     kDebug();
-
     emit jobDone();
     runsFirstJob();
 
     // this prevents a crash if kjob has killed itself
     if ( job && job->error() || !job ) {
-        emit jobsDone();
-        delete mWaitDialog;
-        mWaitDialog = 0;
+        emit jobsStopped();
         kError() << "the job died.";
-        KMessageBox::error( 0 ,i18n("The job unexpectedly died."));
+        emit errorMessage( i18n("The job unexpectedly died."));
         d->setRunning(false);
     }
     delete job;
--- trunk/playground/pim/kblogger/src/backend/backendjobqueue.h #767767:767768
@@ -30,15 +30,12 @@
 {
 class BackendJob;
 
-class WaitDialog;
-
 class BackendJobQueue_p;
 
 /**
   @brief
   This class is used to store BackendJob[s] and run them all at once in a
-  queue. It uses BackendJob to do that. Additionally it show WaitDialog when it
-  is running.
+  queue. It uses BackendJob to do that.
 */
 
 class BackendJobQueue: public QObject
@@ -52,10 +49,10 @@
     void run();
     bool stop();
     void clear();
-    void jobDone();
     //bool killCurrentJob();
     bool isRunning();
     int queueSize();
+    QString waitMessage();
 
 protected Q_SLOTS:
     void runsFirstJob();
@@ -68,12 +65,14 @@
 
     QList<BackendJob*> mPendingJobs;
     BackendJobQueue_p *d;
-    WaitDialog* mWaitDialog;
 
 Q_SIGNALS:
-    void jobsStarted(int);
+    void waitMessage( const QString& );
+    void statusMessage( const QString& );
+    void errorMessage( const QString& );
+    void jobsStarted( int );
     void jobsStopped();
-//     void jobDone(); // TODO remove if has no effects
+    void jobDone();
     void jobsDone();
 };
 
--- trunk/playground/pim/kblogger/src/backend/waitdialog.cpp #767767:767768
@@ -24,13 +24,12 @@
 #include <KDebug>
 #include <KDialog>
 
-#include "backend/backend.h"
 #include "waitwidget.h"
 
 namespace KBlogger
 {
 
-WaitDialog::WaitDialog(QWidget* parent ): KDialog(parent),
+WaitDialog::WaitDialog( int jobsQueued, QWidget* parent): KDialog(parent),
                    widget(0)
 {
     kDebug();
@@ -39,9 +38,9 @@
 
     // create the widget for the progress bar and info text
     widget = new WaitWidget( this );
+    widget->setMaxJobs( jobsQueued );
     setMainWidget( widget );
-    connect( this, SIGNAL( cancelClicked() ), this, SLOT( close() ) );
-    connect( this, SIGNAL( cancelClicked() ), Backend::self(), SLOT( stopQueue() ) \
); +    connect( this, SIGNAL( cancelClicked() ), this, SLOT( close() ) );    
 }
 
 WaitDialog::~WaitDialog()
@@ -62,13 +61,6 @@
     widget->jobDone();
 }
 
-void WaitDialog::show()
-{
-    kDebug();
-    widget->setMaxJobs( Backend::self()->jobsQueued() );
-    KDialog::show();
-}
-
 }//namespace
 
 #include "waitdialog.moc"
--- trunk/playground/pim/kblogger/src/backend/waitdialog.h #767767:767768
@@ -38,18 +38,15 @@
 {
     Q_OBJECT
 public:
-    WaitDialog( QWidget* parent = 0 );
+    WaitDialog( int, QWidget* parent = 0 );
 
     virtual ~WaitDialog();
+public Q_SLOTS:
     // update the text in the info label
     void setText( const QString& text );
     // increments the progress bar
     void jobDone();
 
-public Q_SLOTS:
-    // reimplemented to set the progress bar's max value
-    void show();
-
 private:
     WaitWidget* widget;
 };
--- trunk/playground/pim/kblogger/src/backend/waitwidget.cpp #767767:767768
@@ -59,8 +59,7 @@
 void WaitWidget::jobDone()
 {
     kDebug();
-    int value = progressBar->value();
-    progressBar->setValue(++value);
+    progressBar->setValue(progressBar->value()++);
 }
 
 }//namespace
--- trunk/playground/pim/kblogger/src/composer/composer.cpp #767767:767768
@@ -439,9 +439,9 @@
     categoriesList->clear();
 
     QList<QHash<QString,QVariant> > blogList = BlogList();
-    QHash<QString,QVariant> blogHash = blogList[ \
mBackend->getKbloggerBlog(blogname).type() ]; +    QHash<QString,QVariant> blogHash = \
blogList[ mBackend->getBlogServer(blogname).type() ];  kDebug() << "BLOGNAME" << \
                blogname
-    << "USED TYPE=" << mBackend->getKbloggerBlog(blogname).type();
+    << "USED TYPE=" << mBackend->getBlogServer(blogname).type();
 
     if( blogHash["hasCategorySupport"].toBool() ){
         getCategories(blogname);


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

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