diff --git a/outboxinterface/CMakeLists.txt b/outboxinterface/CMakeLists.txt index c59425f01..4a54d1577 100644 --- a/outboxinterface/CMakeLists.txt +++ b/outboxinterface/CMakeLists.txt @@ -1,50 +1,50 @@ #include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${KDEPIMLIBS_INCLUDE_DIRS}) # TODO: 5324 is mailtransport. we need one of our own! add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5324 ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) add_subdirectory( tests ) set(outboxinterface_lib_srcs dispatcherinterface.cpp localfolders.cpp messagequeuejob.cpp addressattribute.cpp dispatchmodeattribute.cpp errorattribute.cpp sentbehaviourattribute.cpp transportattribute.cpp resourcetester/resourcesynchronizationjob.cpp ) -qt4_add_dbus_interface( outboxinterface_lib_srcs interfaces/org.kde.Akonadi.MailDispatcher.xml mdainterface ) -install( FILES interfaces/org.kde.Akonadi.MailDispatcher.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} ) +# qt4_add_dbus_interface( outboxinterface_lib_srcs interfaces/org.kde.Akonadi.MailDispatcher.xml mdainterface ) +# install( FILES interfaces/org.kde.Akonadi.MailDispatcher.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} ) kde4_add_kcfg_files(outboxinterface_lib_srcs settings.kcfgc) install(FILES outboxinterface.kcfg DESTINATION ${KCFG_INSTALL_DIR}) kde4_add_library(outboxinterface SHARED ${outboxinterface_lib_srcs}) target_link_libraries(outboxinterface ${KDE4_KIO_LIBS} akonadi-kde kmime mailtransport ) set_target_properties(outboxinterface PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) install(TARGETS outboxinterface ${INSTALL_TARGETS_DEFAULT_ARGS}) install( FILES outboxinterface_export.h dispatcherinterface.h localfolders.h messagequeuejob.h addressattribute.h dispatchmodeattribute.h errorattribute.h sentbehaviourattribute.h transportattribute.h DESTINATION ${INCLUDE_INSTALL_DIR}/outboxinterface COMPONENT Devel) diff --git a/outboxinterface/dispatcherinterface.cpp b/outboxinterface/dispatcherinterface.cpp index 2794675b2..9ff32a856 100644 --- a/outboxinterface/dispatcherinterface.cpp +++ b/outboxinterface/dispatcherinterface.cpp @@ -1,224 +1,231 @@ /* Copyright (c) 2009 Constantin Berzan 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 "dispatcherinterface.h" -#include "mdainterface.h" +//#include "mdainterface.h" + +#include #include #include #include #include using namespace Akonadi; using namespace OutboxInterface; /** * Private class that helps to provide binary compatibility between releases. * @internal */ class OutboxInterface::DispatcherInterfacePrivate { public: DispatcherInterfacePrivate(); ~DispatcherInterfacePrivate(); DispatcherInterface *instance; bool connected; - org::kde::Akonadi::MailDispatcher *iface; + //org::kde::Akonadi::MailDispatcher *iface; AgentInstance agent; // slots void connectToAgent(); - void dbusServiceOwnerChanged( const QString &name, const QString &oldOwner, const QString &newOwner ); + //void dbusServiceOwnerChanged( const QString &name, const QString &oldOwner, const QString &newOwner ); void agentInstanceRemoved( const AgentInstance &a ); void agentInstanceChanged( const AgentInstance &a ); }; K_GLOBAL_STATIC( DispatcherInterfacePrivate, sInstance ) DispatcherInterfacePrivate::DispatcherInterfacePrivate() : instance( new DispatcherInterface( this ) ) - , iface( 0 ) + //, iface( 0 ) { - QDBusConnection bus = QDBusConnection::sessionBus(); - QObject::connect( bus.interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), - instance, SLOT(dbusServiceOwnerChanged(QString,QString,QString)) ); + // QDBusConnection bus = QDBusConnection::sessionBus(); + // QObject::connect( bus.interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), + // instance, SLOT(dbusServiceOwnerChanged(QString,QString,QString)) ); + // AgentInstance objects are not updated automatically, so we need to watch // for AgentManager's signals: QObject::connect( AgentManager::self(), SIGNAL(instanceOnline(Akonadi::AgentInstance,bool)), instance, SLOT(agentInstanceChanged(Akonadi::AgentInstance)) ); QObject::connect( AgentManager::self(), SIGNAL(instanceProgressChanged(Akonadi::AgentInstance)), instance, SLOT(agentInstanceChanged(Akonadi::AgentInstance)) ); QObject::connect( AgentManager::self(), SIGNAL(instanceStatusChanged(Akonadi::AgentInstance)), instance, SLOT(agentInstanceChanged(Akonadi::AgentInstance)) ); QObject::connect( AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)), instance, SLOT(agentInstanceRemoved(Akonadi::AgentInstance)) ); connected = false; connectToAgent(); } DispatcherInterfacePrivate::~DispatcherInterfacePrivate() { delete instance; } void DispatcherInterfacePrivate::connectToAgent() { if( connected ) { kDebug() << "Already connected to MDA."; return; } +#if 0 delete iface; iface = new org::kde::Akonadi::MailDispatcher( QLatin1String( "org.freedesktop.Akonadi.Agent.akonadi_maildispatcher_agent" ), QLatin1String( "/" ), QDBusConnection::sessionBus(), instance ); if( !iface->isValid() ) { kDebug() << "Couldn't get D-Bus interface of MDA. Retrying in 1s."; QTimer::singleShot( 1000, instance, SLOT(connectToAgent()) ); return; } +#endif agent = AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) ); if( !agent.isValid() ) { kDebug() << "Could not get agent instance of MDA. Retrying in 1s."; QTimer::singleShot( 1000, instance, SLOT(connectToAgent()) ); return; } kDebug() << "Connected to the MDA."; connected = true; } +#if 0 void DispatcherInterfacePrivate::dbusServiceOwnerChanged( const QString &name, const QString &oldOwner, const QString &newOwner ) { Q_UNUSED( oldOwner ); if( name == QLatin1String( "org.freedesktop.Akonadi.Agent.akonad_maildispatcher_agent" ) ) { if( newOwner.isEmpty() ) { kDebug() << "MDA disappeared from D-Bus."; connected = false; QTimer::singleShot( 0, instance, SLOT(connectToAgent()) ); } } } +#endif void DispatcherInterfacePrivate::agentInstanceRemoved( const AgentInstance &a ) { if( agent == a ) { kDebug() << "MDA agent disappeared."; connected = false; QTimer::singleShot( 0, instance, SLOT(connectToAgent()) ); } } void DispatcherInterfacePrivate::agentInstanceChanged( const AgentInstance &a ) { if( agent == a ) { kDebug() << "Updating instance."; agent = a; // This is not as weird as it looks :) operator== checks the id only, but // operator= copies everything (like status, progress etc.) } } DispatcherInterface::DispatcherInterface( DispatcherInterfacePrivate *dd ) : QObject() , d( dd ) { } DispatcherInterface *DispatcherInterface::self() { return sInstance->instance; } bool DispatcherInterface::isReady() const { return d->connected; } bool DispatcherInterface::dispatcherOnline() const { if( !d->connected ) { kWarning() << "Not connected to the MDA."; return false; } return d->agent.isOnline(); } AgentInstance::Status DispatcherInterface::dispatcherStatus() const { if( !d->connected ) { kWarning() << "Not connected to the MDA."; return AgentInstance::Broken; } return d->agent.status(); } int DispatcherInterface::dispatcherProgress() const { if( !d->connected ) { kWarning() << "Not connected to the MDA."; return -1; } return d->agent.progress(); } void DispatcherInterface::abortDispatching() { if( !d->connected ) { kWarning() << "Not connected to the MDA."; return; } - d->iface->abort(); + d->agent.abort(); } void DispatcherInterface::dispatchManually() { if( !d->connected ) { kWarning() << "Not connected to the MDA."; return; } kDebug() << "implement me"; //TODO } void DispatcherInterface::retryDispatching() { if( !d->connected ) { kWarning() << "Not connected to the MDA."; return; } kDebug() << "implement me"; //TODO } #include "dispatcherinterface.moc" diff --git a/outboxinterface/dispatcherinterface.h b/outboxinterface/dispatcherinterface.h index 6012be3f0..60c6ebf6a 100644 --- a/outboxinterface/dispatcherinterface.h +++ b/outboxinterface/dispatcherinterface.h @@ -1,95 +1,95 @@ /* Copyright (c) 2009 Constantin Berzan 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 OUTBOXINTERFACE_DISPATCHERINTERFACE_H #define OUTBOXINTERFACE_DISPATCHERINTERFACE_H #include #include #include namespace OutboxInterface { class DispatcherInterfacePrivate; /** An interface for apps to interact with the MDA. It connects to the MDA via D-Bus and provides info about queued messages and progress, and methods such as abort or retry sending. TODO dispatchManually and retryDispatching functions should be offered on a per-item basis as well, I imagine when the user will have a messageView of the outbox. Then do we need global ones here (i.e. for all items in the outbox)? */ class OUTBOXINTERFACE_EXPORT DispatcherInterface : public QObject { Q_OBJECT public: /** Returns the DispatcherInterface instance. */ static DispatcherInterface *self(); bool isReady() const; bool dispatcherOnline() const; Akonadi::AgentInstance::Status dispatcherStatus() const; int dispatcherProgress() const; /** Aborts sending the current message, and marks all messages in the queue as DispatchMode::Never. */ void abortDispatching(); /** Looks for messages in the outbox with DispatchMode::Never and marks them DispatchMode::Immediately for sending. */ void dispatchManually(); /** Looks for messages in the outbox with ErrorAttribute, and clears them and queues them again for sending. */ void retryDispatching(); private: friend class DispatcherInterfacePrivate; DispatcherInterfacePrivate *const d; // singleton class; the only instance resides in sInstance->instance DispatcherInterface( DispatcherInterfacePrivate *dd ); Q_PRIVATE_SLOT( d, void connectToAgent() ) - Q_PRIVATE_SLOT( d, void dbusServiceOwnerChanged( const QString&, const QString&, const QString& ) ) + //Q_PRIVATE_SLOT( d, void dbusServiceOwnerChanged( const QString&, const QString&, const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceRemoved( const Akonadi::AgentInstance& ) ) Q_PRIVATE_SLOT( d, void agentInstanceChanged( const Akonadi::AgentInstance& ) ) }; } #endif