[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim/work/akonadi-ports] akregator: - make doStart() delayed
From: Frank Osterfeld <frank.osterfeld () kdab ! com>
Date: 2011-09-19 17:36:51
Message-ID: 20110919173651.4F3E6A607A () git ! kde ! org
[Download RAW message or body]
Git commit 7e723c344a4f0c7caac13f87c19d6089a264354d by Frank Osterfeld.
Committed on 19/09/2011 at 06:21.
Pushed by osterfeld into branch 'work/akonadi-ports'.
- make doStart() delayed
- add convenience API to show an error dialog on command finish (common use case)
M +45 -2 akregator/interfaces/command.cpp
M +5 -0 akregator/interfaces/command.h
C +13 -29 akregator/interfaces/command_p.h [from: akregator/interfaces/command.h \
- 060% similarity] M +1 -2 akregator/src/mainwidget.cpp
M +3 -0 akregator/src/modifycommands.cpp
http://commits.kde.org/kdepim/7e723c344a4f0c7caac13f87c19d6089a264354d
diff --git a/akregator/interfaces/command.cpp b/akregator/interfaces/command.cpp
index e1661e1..c1d2882 100644
--- a/akregator/interfaces/command.cpp
+++ b/akregator/interfaces/command.cpp
@@ -23,6 +23,10 @@
*/
#include "command.h"
+#include "command_p.h"
+
+#include <KLocalizedString>
+#include <KMessageBox>
#include <QEventLoop>
#include <QPointer>
@@ -30,21 +34,44 @@
using namespace Akregator;
+ShowErrorJob::ShowErrorJob( const QString& errorText, QWidget* parent )
+ : KJob( parent )
+ , m_parentWidget( parent )
+ , m_errorText( errorText )
+{
+}
+
+void ShowErrorJob::start() {
+ QMetaObject::invokeMethod( this, "doStart", Qt::QueuedConnection );
+}
+
+void ShowErrorJob::doStart() {
+ QPointer<QObject> that( this );
+ KMessageBox::error( m_parentWidget, m_errorText, i18nc("msg box caption", \
"Error") ); + if ( that )
+ emitResult();
+}
+
class Command::Private
{
public:
Private();
QPointer<QWidget> parentWidget;
bool userVisible;
+ bool showErrorDialog;
};
-Command::Private::Private() : parentWidget(), userVisible( true )
+Command::Private::Private()
+ : parentWidget()
+ , userVisible( true )
+ , showErrorDialog( false )
{
}
Command::Command( QObject* parent ) : KJob( parent ), d( new Private )
{
-
+ connect( this, SIGNAL(finished(KJob*)),
+ this, SLOT(jobFinished()) );
}
Command::~Command()
@@ -64,6 +91,11 @@ void Command::setParentWidget( QWidget* parentWidget )
void Command::start()
{
+ QMetaObject::invokeMethod( this, "delayedStart", Qt::QueuedConnection );
+}
+
+void Command::delayedStart()
+{
doStart();
emit started();
}
@@ -76,5 +108,16 @@ void Command::setUserVisible( bool visible ) {
d->userVisible = visible;
}
+void Command::setShowErrorDialog( bool s ) {
+ d->showErrorDialog = s;
+}
+
+void Command::jobFinished() {
+ if ( error() && d->showErrorDialog )
+ //don't show error dialog synchronously, to not disturb the
+ //finished signals with a local event loop
+ (new ShowErrorJob( errorText(), d->parentWidget ))->start();
+}
#include "command.moc"
+#include "command_p.moc"
diff --git a/akregator/interfaces/command.h b/akregator/interfaces/command.h
index 65d594c..44d7336 100644
--- a/akregator/interfaces/command.h
+++ b/akregator/interfaces/command.h
@@ -63,8 +63,13 @@ Q_SIGNALS:
void started();
protected:
+ void setShowErrorDialog( bool );
virtual void doStart() = 0;
+private Q_SLOTS:
+ void jobFinished();
+ void delayedStart();
+
private:
class Private;
Private* const d;
diff --git a/akregator/interfaces/command.h b/akregator/interfaces/command_p.h
similarity index 60%
copy from akregator/interfaces/command.h
copy to akregator/interfaces/command_p.h
index 65d594c..369f43e 100644
--- a/akregator/interfaces/command.h
+++ b/akregator/interfaces/command_p.h
@@ -1,7 +1,7 @@
/*
This file is part of Akregator.
- Copyright (C) 2008 Frank Osterfeld <osterfeld@kde.org>
+ Copyright (C) 2011 Frank Osterfeld <osterfeld@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,54 +22,38 @@
without including the source code for Qt in the source distribution.
*/
-#ifndef AKREGATOR_COMMAND_H
-#define AKREGATOR_COMMAND_H
+#ifndef AKREGATOR_COMMAND_P_H
+#define AKREGATOR_COMMAND_P_H
#include "akregator_export.h"
#include <KJob>
-#include <QtCore/QObject>
+#include <KJob>
+#include <QString>
+#include <QPointer>
class QWidget;
namespace Akregator {
-class EmitResultGuard;
-
-class AKREGATORINTERFACES_EXPORT Command : public KJob
+class AKREGATORINTERFACES_EXPORT ShowErrorJob : public KJob
{
Q_OBJECT
- friend class ::Akregator::EmitResultGuard;
-
public:
- explicit Command( QObject* parent = 0 );
- virtual ~Command();
-
- QWidget* parentWidget() const;
- void setParentWidget( QWidget* parentWidget );
+ explicit ShowErrorJob( const QString& errorText, QWidget* parent );
/* reimp */ void start();
- /**
- * whether the UI should display the job e.g. via progress items
- * defaults to @p true
- */
- bool isUserVisible() const;
- void setUserVisible( bool visible );
-
-Q_SIGNALS:
- void started();
-
-protected:
- virtual void doStart() = 0;
+private Q_SLOTS:
+ void doStart();
private:
- class Private;
- Private* const d;
+ QPointer<QWidget> m_parentWidget;
+ QString m_errorText;
};
}
-#endif // AKREGATOR_COMMAND_H
+#endif // AKREGATOR_COMMAND_P_H
diff --git a/akregator/src/mainwidget.cpp b/akregator/src/mainwidget.cpp
index 66f7bbf..12b558b 100644
--- a/akregator/src/mainwidget.cpp
+++ b/akregator/src/mainwidget.cpp
@@ -733,11 +733,10 @@ void Akregator::MainWidget::slotMarkFeedRead()
const Akonadi::Collection c = m_selectionController->selectedCollection();
if ( !c.isValid() )
return;
- MarkAsReadCommand* cmd = new MarkAsReadCommand( this );
+ MarkAsReadCommand* cmd = new MarkAsReadCommand( this );
cmd->setCollection( c );
cmd->setSession( m_session );
- connect( cmd, SIGNAL( result( KJob* ) ), this, SLOT( slotJobFinished( KJob* ) ) \
); d->setUpAndStart( cmd );
#ifdef KRSS_PORT_DISABLED
diff --git a/akregator/src/modifycommands.cpp b/akregator/src/modifycommands.cpp
index 9986902..c2793d1 100644
--- a/akregator/src/modifycommands.cpp
+++ b/akregator/src/modifycommands.cpp
@@ -51,6 +51,7 @@ MarkAsReadCommand::MarkAsReadCommand( QObject* parent )
: Command( parent )
, d( new Private )
{
+ setShowErrorDialog( true );
}
void MarkAsReadCommand::setCollection( const Collection& c ) {
@@ -77,6 +78,7 @@ void MarkAsReadCommand::doStart() {
void MarkAsReadCommand::itemsFetched( KJob* j ) {
if ( j->error() ) {
+ setError( KJob::UserDefinedError );
setErrorText( i18n("Could not fetch items for collection %1: %2", \
d->collection.title(), j->errorString() ) ); emitResult();
return;
@@ -102,6 +104,7 @@ void MarkAsReadCommand::itemsFetched( KJob* j ) {
void MarkAsReadCommand::itemsModified( KJob* j ) {
if ( j->error() ) {
+ setError( KJob::UserDefinedError );
setErrorText( i18n("Could not mark items as read: %1", j->errorString() ) );
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic