diff --git a/outboxinterface/CMakeLists.txt b/outboxinterface/CMakeLists.txt index 4a54d1577..0f143cda3 100644 --- a/outboxinterface/CMakeLists.txt +++ b/outboxinterface/CMakeLists.txt @@ -1,50 +1,51 @@ #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 + outboxactions.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} ) 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 13c6f1a3f..802c64fa5 100644 --- a/outboxinterface/dispatcherinterface.cpp +++ b/outboxinterface/dispatcherinterface.cpp @@ -1,241 +1,124 @@ /* 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 "localfolders.h" +#include "outboxactions.h" #include #include #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; - AgentInstance agent; - // slots - void connectToAgent(); - //void dbusServiceOwnerChanged( const QString &name, const QString &oldOwner, const QString &newOwner ); - void agentInstanceRemoved( const AgentInstance &a ); - void agentInstanceChanged( const AgentInstance &a ); + void massModifyResult( KJob *job ); }; K_GLOBAL_STATIC( DispatcherInterfacePrivate, sInstance ) DispatcherInterfacePrivate::DispatcherInterfacePrivate() : instance( new DispatcherInterface( this ) ) - //, iface( 0 ) { - // 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 ) +void DispatcherInterfacePrivate::massModifyResult( KJob *job ) { - 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.) + // Nothing to do here, really. If the job fails, the user can retry it. + if( job->error() ) { + kDebug() << "failed" << job->errorString(); + } else { + kDebug() << "succeeded."; } } DispatcherInterface::DispatcherInterface( DispatcherInterfacePrivate *dd ) : QObject() , d( dd ) { } DispatcherInterface *DispatcherInterface::self() { return sInstance->instance; } -bool DispatcherInterface::isReady() const -{ - return d->connected; -} - AgentInstance DispatcherInterface::dispatcherInstance() const { - if( !d->connected ) { - kWarning() << "Not connected to the MDA."; - return AgentInstance(); - } - - return d->agent; -} - -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; + AgentInstance a = AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) ); + if( !a.isValid() ) { + kWarning() << "Could not get MDA instance."; } - - return d->agent.progress(); -} - -void DispatcherInterface::abortDispatching() -{ - if( !d->connected ) { - kWarning() << "Not connected to the MDA."; - return; - } - - d->agent.abort(); + return a; } void DispatcherInterface::dispatchManually() { - if( !d->connected ) { - kWarning() << "Not connected to the MDA."; + if( !LocalFolders::self()->isReady() ) { + kWarning() << "LocalFolders not ready."; return; } - kDebug() << "implement me"; //TODO + FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new SendQueuedAction, this ); + connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } void DispatcherInterface::retryDispatching() { - if( !d->connected ) { - kWarning() << "Not connected to the MDA."; + if( !LocalFolders::self()->isReady() ) { + kWarning() << "LocalFolders not ready."; return; } - kDebug() << "implement me"; //TODO + FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new ClearErrorAction, this ); + connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } #include "dispatcherinterface.moc" diff --git a/outboxinterface/dispatcherinterface.h b/outboxinterface/dispatcherinterface.h index d22d1c495..0d1651de4 100644 --- a/outboxinterface/dispatcherinterface.h +++ b/outboxinterface/dispatcherinterface.h @@ -1,98 +1,85 @@ /* 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. + Provides methods such as send queued messages and 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; - Akonadi::AgentInstance dispatcherInstance() const; - // TODO ^ probably makes the following unnecessary ----------------- - 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. + Returns the current instance of the MDA. May return an invalid + AgentInstance in case it cannot find the MDA. */ - void abortDispatching(); - // ---------------------------------------------- until here + Akonadi::AgentInstance dispatcherInstance() const; /** 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 agentInstanceRemoved( const Akonadi::AgentInstance& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceChanged( const Akonadi::AgentInstance& ) ) + Q_PRIVATE_SLOT( d, void massModifyResult( KJob* ) ) }; } #endif diff --git a/outboxinterface/outboxactions.cpp b/outboxinterface/outboxactions.cpp new file mode 100644 index 000000000..082f7bf36 --- /dev/null +++ b/outboxinterface/outboxactions.cpp @@ -0,0 +1,79 @@ +/* + 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 "outboxactions.h" + +#include "dispatchmodeattribute.h" +#include "errorattribute.h" + +#include + +using namespace Akonadi; +using namespace OutboxInterface; + + +ItemFetchScope SendQueuedAction::fetchScope() const +{ + ItemFetchScope scope; + scope.fetchFullPayload( false ); + scope.fetchAttribute(); + return scope; +} + +bool SendQueuedAction::itemAccepted( const Item &item ) const +{ + if( !item.hasAttribute() ) { + kWarning() << "Item doesn't have DispatchModeAttribute."; + return false; + } + + return item.attribute()->dispatchMode() == DispatchModeAttribute::Never; +} + +Job *SendQueuedAction::itemAction( const Item &item ) const +{ + Item cp = item; + cp.addAttribute( new DispatchModeAttribute ); // defaults to Immediately + return new ItemModifyJob( cp ); +} + + + +ItemFetchScope ClearErrorAction::fetchScope() const +{ + ItemFetchScope scope; + scope.fetchFullPayload( false ); + scope.fetchAttribute(); + return scope; +} + +bool ClearErrorAction::itemAccepted( const Item &item ) const +{ + return item.hasAttribute(); +} + +Job *ClearErrorAction::itemAction( const Item &item ) const +{ + Item cp = item; + cp.removeAttribute(); + cp.clearFlag( "error" ); + cp.setFlag( "queued" ); + return new ItemModifyJob( cp ); +} + diff --git a/outboxinterface/outboxactions.h b/outboxinterface/outboxactions.h new file mode 100644 index 000000000..517d4838a --- /dev/null +++ b/outboxinterface/outboxactions.h @@ -0,0 +1,63 @@ +/* + 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_OUTBOXACTIONS_H +#define OUTBOXINTERFACE_OUTBOXACTIONS_H + +#include + +#include +#include +#include + +namespace OutboxInterface +{ + +/** + FilterActionJob functor that finds all messages with a DispatchMode of Never + and assigns them a DispatchMode of Immediately. + + This is used to send "queued" messages on demand. +*/ +class OUTBOXINTERFACE_EXPORT SendQueuedAction : public Akonadi::FilterAction +{ + public: + virtual Akonadi::ItemFetchScope fetchScope() const; + virtual bool itemAccepted( const Akonadi::Item &item ) const; + virtual Akonadi::Job *itemAction( const Akonadi::Item &item ) const; +}; + + +/** + FilterActionJob functor that finds all messages with an ErrorAttribute, + removes the attribute, and sets the "queued" flag. + + This is used to send failed messages again. +*/ +class OUTBOXINTERFACE_EXPORT ClearErrorAction : public Akonadi::FilterAction +{ + public: + virtual Akonadi::ItemFetchScope fetchScope() const; + virtual bool itemAccepted( const Akonadi::Item &item ) const; + virtual Akonadi::Job *itemAction( const Akonadi::Item &item ) const; +}; + +} + +#endif diff --git a/outboxinterface/tests/CMakeLists.txt b/outboxinterface/tests/CMakeLists.txt index fdb021207..53594e1e4 100644 --- a/outboxinterface/tests/CMakeLists.txt +++ b/outboxinterface/tests/CMakeLists.txt @@ -1,56 +1,68 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) set(queuer_srcs queuer.cpp) kde4_add_executable(queuer TEST ${queuer_srcs}) target_link_libraries(queuer ${KDE4_KDEUI_LIBS} ${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KMIME_LIBS} outboxinterface) set( requester_srcs foldersrequester.cpp ) kde4_add_executable( requester TEST ${requester_srcs} ) -target_link_libraries( requester ${KDE4_KDEUI_LIBS} outboxinterface ) +target_link_libraries( requester outboxinterface ) # for racetest add_definitions( -DREQUESTER_EXE=\\"${CMAKE_CURRENT_BINARY_DIR}/requester\\" ) +set( sendqueued_srcs sendqueued.cpp ) +kde4_add_executable( sendqueued TEST ${sendqueued_srcs} ) +target_link_libraries( sendqueued outboxinterface ) + +set( clearerror_srcs clearerror.cpp ) +kde4_add_executable( clearerror TEST ${clearerror_srcs} ) +target_link_libraries( clearerror outboxinterface ) + +set( abort_srcs abort.cpp ) +kde4_add_executable( abort TEST ${abort_srcs} ) +target_link_libraries( abort outboxinterface ) + # Stolen from kdepimlibs/akonadi/tests macro(add_akonadi_isolated_test _source) get_filename_component(_targetName ${_source} NAME_WE) set(_srcList ${_source} ) kde4_add_executable(${_targetName} TEST ${_srcList}) target_link_libraries(${_targetName} ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_AKONADI_LIBS} ${KDE4_KDECORE_LIBS} ${KDE4_MAILTRANSPORT_LIBS} ${KDE4_KMIME_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} outboxinterface ) # based on kde4_add_unit_test if (WIN32) get_target_property( _loc ${_targetName} LOCATION ) set(_executable ${_loc}.bat) else (WIN32) set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_targetName}) endif (WIN32) if (UNIX) set(_executable ${_executable}.shell) endif (UNIX) find_program(_testrunner akonaditest) add_test( outboxinterface-${_targetName} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml ${_executable} ) endmacro(add_akonadi_isolated_test) add_akonadi_isolated_test( messagequeuejobtest.cpp ) add_akonadi_isolated_test( racetest.cpp ) diff --git a/outboxinterface/tests/abort.cpp b/outboxinterface/tests/abort.cpp new file mode 100644 index 000000000..1b0db92ad --- /dev/null +++ b/outboxinterface/tests/abort.cpp @@ -0,0 +1,68 @@ +/* + 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 "abort.h" + +#include + +#include +#include +#include + +#include + +#include + +using namespace Akonadi; +using namespace OutboxInterface; + + +Runner::Runner() +{ + Control::start(); + + QTimer::singleShot( 0, this, SLOT(sendAbort()) ); +} + +void Runner::sendAbort() +{ + const AgentInstance mda = DispatcherInterface::self()->dispatcherInstance(); + if( !mda.isValid() ) { + kDebug() << "Invalid instance; waiting."; + QTimer::singleShot( 1000, this, SLOT(sendAbort()) ); + return; + } + + mda.abort(); + kDebug() << "Told the MDA to abort."; + KApplication::exit( 0 ); +} + +int main( int argc, char **argv ) +{ + KCmdLineArgs::init( argc, argv, "abort", 0, + ki18n( "abort" ), "0", + ki18n( "An app that sends an abort signal to the MDA" ) ); + KApplication app; + new Runner(); + return app.exec(); +} + + +#include "abort.moc" diff --git a/outboxinterface/tests/queuer.h b/outboxinterface/tests/abort.h similarity index 57% copy from outboxinterface/tests/queuer.h copy to outboxinterface/tests/abort.h index 840592412..82037c054 100644 --- a/outboxinterface/tests/queuer.h +++ b/outboxinterface/tests/abort.h @@ -1,56 +1,43 @@ /* - Copyright (c) 2006 - 2007 Volker Krause 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 MESSAGEQUEUER_H -#define MESSAGEQUEUER_H +#ifndef ABORT_H +#define ABORT_H -#include -#include +#include class KJob; -class KLineEdit; -class KTextEdit; - /** - This is stolen from kdepimlibs/mailtransport/tests/transportmgr.{h,cpp} + This class uses the DispatcherInterface to send an abort() signal th the MDA. */ -class MessageQueuer : public KVBox +class Runner : public QObject { Q_OBJECT public: - MessageQueuer(); + Runner(); private slots: - void sendBtnClicked(); - void jobResult( KJob *job ); - void jobPercent( KJob *job, unsigned long percent ); - void jobInfoMessage( KJob *job, const QString &info, const QString &info2 ); - - private: - MailTransport::TransportComboBox *mComboBox; - KLineEdit *mSenderEdit, *mToEdit, *mCcEdit, *mBccEdit; - KTextEdit *mMailEdit; + void sendAbort(); }; #endif diff --git a/outboxinterface/tests/clearerror.cpp b/outboxinterface/tests/clearerror.cpp new file mode 100644 index 000000000..ce59ed669 --- /dev/null +++ b/outboxinterface/tests/clearerror.cpp @@ -0,0 +1,82 @@ +/* + 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 "clearerror.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +using namespace Akonadi; +using namespace OutboxInterface; + + +Runner::Runner() +{ + Control::start(); + + connect( LocalFolders::self(), SIGNAL( foldersReady() ), + this, SLOT( checkFolders() ) ); + LocalFolders::self()->fetch(); +} + +void Runner::checkFolders() +{ + Collection outbox = LocalFolders::self()->outbox(); + kDebug() << "Got outbox" << outbox.id(); + + if( !outbox.isValid() ) { + KApplication::exit( 1 ); + } + + FilterActionJob *fjob = new FilterActionJob( outbox, new ClearErrorAction, this ); + connect( fjob, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); +} + +void Runner::jobResult( KJob *job ) +{ + if( job->error() ) { + kDebug() << "Job error:" << job->errorString(); + KApplication::exit( 2 ); + } else { + kDebug() << "Job success."; + KApplication::exit( 0 ); + } +} + +int main( int argc, char **argv ) +{ + KCmdLineArgs::init( argc, argv, "clearerror", 0, + ki18n( "clearerror" ), "0", + ki18n( "An app that re-queues failed items from the outbox" ) ); + KApplication app; + new Runner(); + return app.exec(); +} + + +#include "clearerror.moc" diff --git a/outboxinterface/tests/queuer.h b/outboxinterface/tests/clearerror.h similarity index 59% copy from outboxinterface/tests/queuer.h copy to outboxinterface/tests/clearerror.h index 840592412..2f319c2c5 100644 --- a/outboxinterface/tests/queuer.h +++ b/outboxinterface/tests/clearerror.h @@ -1,56 +1,45 @@ /* - Copyright (c) 2006 - 2007 Volker Krause 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 MESSAGEQUEUER_H -#define MESSAGEQUEUER_H +#ifndef CLEARERROR_H +#define CLEARERROR_H -#include -#include +#include class KJob; -class KLineEdit; -class KTextEdit; - /** - This is stolen from kdepimlibs/mailtransport/tests/transportmgr.{h,cpp} + This class uses the ClearErrorAction to mark all failed messages in the + outbox for immediate sending. */ -class MessageQueuer : public KVBox +class Runner : public QObject { Q_OBJECT public: - MessageQueuer(); + Runner(); private slots: - void sendBtnClicked(); + void checkFolders(); void jobResult( KJob *job ); - void jobPercent( KJob *job, unsigned long percent ); - void jobInfoMessage( KJob *job, const QString &info, const QString &info2 ); - - private: - MailTransport::TransportComboBox *mComboBox; - KLineEdit *mSenderEdit, *mToEdit, *mCcEdit, *mBccEdit; - KTextEdit *mMailEdit; }; #endif diff --git a/outboxinterface/tests/queuer.cpp b/outboxinterface/tests/queuer.cpp index 5e01f643e..dadb11d0c 100644 --- a/outboxinterface/tests/queuer.cpp +++ b/outboxinterface/tests/queuer.cpp @@ -1,132 +1,138 @@ /* Copyright (c) 2006 - 2007 Volker Krause 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 "queuer.h" #include #include #include #include +#include #include #include #include #include +#include #include using namespace KMime; using namespace MailTransport; using namespace OutboxInterface; MessageQueuer::MessageQueuer() { if( !Akonadi::Control::start() ) { kFatal() << "Could not start Akonadi server."; } mComboBox = new TransportComboBox( this ); mComboBox->setEditable( true ); mSenderEdit = new KLineEdit( this ); mSenderEdit->setClickMessage( "Sender" ); mToEdit = new KLineEdit( this ); mToEdit->setText( "idanoka@gmail.com" ); mToEdit->setClickMessage( "To" ); mCcEdit = new KLineEdit( this ); mCcEdit->setClickMessage( "Cc" ); mBccEdit = new KLineEdit( this ); mBccEdit->setClickMessage( "Bcc" ); mMailEdit = new KTextEdit( this ); mMailEdit->setText( "test from queuer!" ); mMailEdit->setAcceptRichText( false ); mMailEdit->setLineWrapMode( QTextEdit::NoWrap ); QPushButton *b = new QPushButton( "&Send", this ); connect( b, SIGNAL(clicked(bool)), SLOT(sendBtnClicked()) ); + mQueued = new QCheckBox( "&Queue instead of sending immediately", this ); } void MessageQueuer::sendBtnClicked() { Message::Ptr msg = Message::Ptr( new Message ); // No headers; need a '\n' to separate headers from body. // TODO: use real headers msg->setContent( QByteArray("\n") + mMailEdit->document()->toPlainText().toLatin1() ); kDebug() << "msg:" << msg->encodedContent( true ); MessageQueueJob *job = new MessageQueueJob(); job->setMessage( msg ); job->setTransportId( mComboBox->currentTransportId() ); - // default dispatch mode + if( mQueued->isChecked() ) { + job->setDispatchMode( DispatchModeAttribute::Never ); + kDebug() << "DispatchMode: Never"; + } // default sent-mail collection job->setFrom( mSenderEdit->text() ); job->setTo( mToEdit->text().isEmpty() ? QStringList() : mToEdit->text().split( ',' ) ); job->setCc( mCcEdit->text().isEmpty() ? QStringList() : mCcEdit->text().split( ',' ) ); job->setBcc( mBccEdit->text().isEmpty() ? QStringList() : mBccEdit->text().split( ',' ) ); connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) ); connect( job, SIGNAL(percent(KJob*,unsigned long)), SLOT(jobPercent(KJob*,unsigned long)) ); connect( job, SIGNAL(infoMessage(KJob*,QString,QString)), SLOT(jobInfoMessage(KJob*,QString,QString)) ); kDebug() << "MessageQueueJob started."; job->start(); } int main( int argc, char **argv ) { KCmdLineArgs::init( argc, argv, "messagequeuer", 0, ki18n( "messagequeuer" ), "0", ki18n( "MessageQueuerJob Demo" ) ); KApplication app; MessageQueuer *t = new MessageQueuer(); t->show(); app.exec(); delete t; } void MessageQueuer::jobResult( KJob *job ) { if( job->error() ) { kDebug() << "job error:" << job->errorText(); } else { kDebug() << "job success."; } } void MessageQueuer::jobPercent( KJob *job, unsigned long percent ) { Q_UNUSED( job ); kDebug() << percent << "%"; } void MessageQueuer::jobInfoMessage( KJob *job, const QString &info, const QString &info2 ) { Q_UNUSED( job ); kDebug() << info; kDebug() << info2; } #include "queuer.moc" diff --git a/outboxinterface/tests/queuer.h b/outboxinterface/tests/queuer.h index 840592412..149b60bfd 100644 --- a/outboxinterface/tests/queuer.h +++ b/outboxinterface/tests/queuer.h @@ -1,56 +1,58 @@ /* Copyright (c) 2006 - 2007 Volker Krause 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 MESSAGEQUEUER_H #define MESSAGEQUEUER_H #include #include +class QCheckBox; class KJob; class KLineEdit; class KTextEdit; /** This is stolen from kdepimlibs/mailtransport/tests/transportmgr.{h,cpp} */ class MessageQueuer : public KVBox { Q_OBJECT public: MessageQueuer(); private slots: void sendBtnClicked(); void jobResult( KJob *job ); void jobPercent( KJob *job, unsigned long percent ); void jobInfoMessage( KJob *job, const QString &info, const QString &info2 ); private: MailTransport::TransportComboBox *mComboBox; KLineEdit *mSenderEdit, *mToEdit, *mCcEdit, *mBccEdit; KTextEdit *mMailEdit; + QCheckBox *mQueued; }; #endif diff --git a/outboxinterface/tests/sendqueued.cpp b/outboxinterface/tests/sendqueued.cpp new file mode 100644 index 000000000..c973fb177 --- /dev/null +++ b/outboxinterface/tests/sendqueued.cpp @@ -0,0 +1,82 @@ +/* + 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 "sendqueued.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +using namespace Akonadi; +using namespace OutboxInterface; + + +Runner::Runner() +{ + Control::start(); + + connect( LocalFolders::self(), SIGNAL( foldersReady() ), + this, SLOT( checkFolders() ) ); + LocalFolders::self()->fetch(); +} + +void Runner::checkFolders() +{ + Collection outbox = LocalFolders::self()->outbox(); + kDebug() << "Got outbox" << outbox.id(); + + if( !outbox.isValid() ) { + KApplication::exit( 1 ); + } + + FilterActionJob *fjob = new FilterActionJob( outbox, new SendQueuedAction, this ); + connect( fjob, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); +} + +void Runner::jobResult( KJob *job ) +{ + if( job->error() ) { + kDebug() << "Job error:" << job->errorString(); + KApplication::exit( 2 ); + } else { + kDebug() << "Job success."; + KApplication::exit( 0 ); + } +} + +int main( int argc, char **argv ) +{ + KCmdLineArgs::init( argc, argv, "sendqueued", 0, + ki18n( "sendqueued" ), "0", + ki18n( "An app that sends all queued messages" ) ); + KApplication app; + new Runner(); + return app.exec(); +} + + +#include "sendqueued.moc" diff --git a/outboxinterface/tests/queuer.h b/outboxinterface/tests/sendqueued.h similarity index 59% copy from outboxinterface/tests/queuer.h copy to outboxinterface/tests/sendqueued.h index 840592412..470a1f247 100644 --- a/outboxinterface/tests/queuer.h +++ b/outboxinterface/tests/sendqueued.h @@ -1,56 +1,45 @@ /* - Copyright (c) 2006 - 2007 Volker Krause 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 MESSAGEQUEUER_H -#define MESSAGEQUEUER_H +#ifndef SENDQUEUED_H +#define SENDQUEUED_H -#include -#include +#include class KJob; -class KLineEdit; -class KTextEdit; - /** - This is stolen from kdepimlibs/mailtransport/tests/transportmgr.{h,cpp} + This class uses the SendQueuedAction to mark all queued messages in the + outbox for immediate sending. */ -class MessageQueuer : public KVBox +class Runner : public QObject { Q_OBJECT public: - MessageQueuer(); + Runner(); private slots: - void sendBtnClicked(); + void checkFolders(); void jobResult( KJob *job ); - void jobPercent( KJob *job, unsigned long percent ); - void jobInfoMessage( KJob *job, const QString &info, const QString &info2 ); - - private: - MailTransport::TransportComboBox *mComboBox; - KLineEdit *mSenderEdit, *mToEdit, *mCcEdit, *mBccEdit; - KTextEdit *mMailEdit; }; #endif