diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b6dea67a..19f3f9099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,7 @@ if (KDEPIM_BUILD_DESKTOP) job/savedraftjob.cpp job/removeduplicatemailjob.cpp job/createfollowupreminderonexistingmessagejob.cpp + job/manageserversidesubscriptionjob.cpp ) set(kmailprivate_widgets_LIB_SRCS diff --git a/job/manageserversidesubscriptionjob.cpp b/job/manageserversidesubscriptionjob.cpp new file mode 100644 index 000000000..dcb0c1383 --- /dev/null +++ b/job/manageserversidesubscriptionjob.cpp @@ -0,0 +1,89 @@ +/* + Copyright (c) 2014 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "manageserversidesubscriptionjob.h" +#include +#include +#include +#include +#include "kmkernel.h" +#include +#include +#include + +ManageServerSideSubscriptionJob::ManageServerSideSubscriptionJob(QObject *parent) + : QObject(parent), + mParentWidget(0) +{ + +} + +ManageServerSideSubscriptionJob::~ManageServerSideSubscriptionJob() +{ + +} + +void ManageServerSideSubscriptionJob::start() +{ + if (!mCurrentFolder) { + qDebug()<<" currentFolder not defined"; + deleteLater(); + return; + } + bool isImapOnline = false; + if ( kmkernel->isImapFolder( mCurrentFolder->collection(), isImapOnline ) ) { + QDBusInterface iface( + QLatin1String( "org.freedesktop.Akonadi.Resource.")+mCurrentFolder->collection().resource(), + QLatin1String( "/" ), QLatin1String( "org.kde.Akonadi.ImapResourceBase" ), + Akonadi::DBusConnectionPool::threadConnection(), this ); + if ( !iface.isValid() ) { + kDebug()<<"Cannot create imap dbus interface"; + deleteLater(); + return; + } + QDBusPendingCall call = iface.asyncCall( QLatin1String( "configureSubscription" ), (qlonglong)mParentWidget->winId() ); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(slotConfigureSubscriptionFinished(QDBusPendingCallWatcher*))); + } +} + +void ManageServerSideSubscriptionJob::slotConfigureSubscriptionFinished(QDBusPendingCallWatcher* watcher) +{ + QDBusPendingReply reply = *watcher; + if ( reply.isValid() ) { + if (reply == -2 ){ + KMessageBox::error(mParentWidget,i18n("IMAP server not configured yet. Please configure the server in the IMAP account before setting up server-side subscription.")); + } else if (reply == -1) { + KMessageBox::error(mParentWidget,i18n("Log in failed, please configure the IMAP account before setting up server-side subscription.")); + } + } + watcher->deleteLater(); + watcher = 0; + deleteLater(); +} + +void ManageServerSideSubscriptionJob::setParentWidget(QWidget *parentWidget) +{ + mParentWidget = parentWidget; +} + +void ManageServerSideSubscriptionJob::setCurrentFolder(const QSharedPointer ¤tFolder) +{ + mCurrentFolder = currentFolder; +} + + diff --git a/job/manageserversidesubscriptionjob.h b/job/manageserversidesubscriptionjob.h new file mode 100644 index 000000000..2cb779522 --- /dev/null +++ b/job/manageserversidesubscriptionjob.h @@ -0,0 +1,46 @@ +/* + Copyright (c) 2014 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef MANAGESERVERSIDESUBSCRIPTIONJOB_H +#define MANAGESERVERSIDESUBSCRIPTIONJOB_H + +#include +#include +#include +class QDBusPendingCallWatcher; + +class ManageServerSideSubscriptionJob : public QObject +{ + Q_OBJECT +public: + explicit ManageServerSideSubscriptionJob(QObject *parent=0); + + ~ManageServerSideSubscriptionJob(); + + void start(); + void setCurrentFolder(const QSharedPointer ¤tFolder); + + void setParentWidget(QWidget *parentWidget); + +private slots: + void slotConfigureSubscriptionFinished(QDBusPendingCallWatcher *watcher); +private: + QSharedPointer mCurrentFolder; + QWidget *mParentWidget; +}; + +#endif // MANAGESERVERSIDESUBSCRIPTIONJOB_H diff --git a/kmmainwidget.cpp b/kmmainwidget.cpp index 79df223ff..092b49c31 100644 --- a/kmmainwidget.cpp +++ b/kmmainwidget.cpp @@ -196,6 +196,7 @@ using KSieveUi::SieveDebugDialog; // System includes #include // ugh #include +#include #include @@ -4698,33 +4699,10 @@ void KMMainWidget::slotServerSideSubscription() { if ( !mCurrentFolder ) return; - bool isImapOnline = false; - if ( kmkernel->isImapFolder( mCurrentFolder->collection(), isImapOnline ) ) { - QDBusInterface iface( - QLatin1String( "org.freedesktop.Akonadi.Resource.")+mCurrentFolder->collection().resource(), - QLatin1String( "/" ), QLatin1String( "org.kde.Akonadi.ImapResourceBase" ), - DBusConnectionPool::threadConnection(), this ); - if ( !iface.isValid() ) { - kDebug()<<"Cannot create imap dbus interface"; - return; - } - QDBusPendingCall call = iface.asyncCall( QLatin1String( "configureSubscription" ), (qlonglong)winId() ); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(slotConfigureSubscriptionFinished(QDBusPendingCallWatcher*))); - } -} - -void KMMainWidget::slotConfigureSubscriptionFinished(QDBusPendingCallWatcher* watcher) -{ - QDBusPendingReply reply = *watcher; - if ( reply.isValid() ) { - if (reply == -2 ){ - KMessageBox::error(this,i18n("IMAP server not configured yet. Please configure the server in the IMAP account before setting up server-side subscription.")); - } else if (reply == -1) { - KMessageBox::error(this,i18n("Log in failed, please configure the IMAP account before setting up server-side subscription.")); - } - } - watcher->deleteLater(); + ManageServerSideSubscriptionJob *job = new ManageServerSideSubscriptionJob(this); + job->setCurrentFolder(mCurrentFolder); + job->setParentWidget(this); + job->start(); } void KMMainWidget::savePaneSelection() diff --git a/kmmainwidget.h b/kmmainwidget.h index e3014f213..ca8b10abb 100644 --- a/kmmainwidget.h +++ b/kmmainwidget.h @@ -530,7 +530,6 @@ private slots: void slotServerSideSubscription(); void slotFetchItemsForFolderDone(KJob*job); void slotServerStateChanged(Akonadi::ServerManager::State state); - void slotConfigureSubscriptionFinished(QDBusPendingCallWatcher* watcher); void slotArchiveMails(); void slotChangeDisplayMessageFormat(MessageViewer::Viewer::DisplayFormatMessage format);