Commit c53602ca authored by Laurent Montel's avatar Laurent Montel 😁

Extract code to manager server side subscriptipn

parent f92207ee
......@@ -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
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
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 <KLocalizedString>
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QDBusPendingReply>
#include "kmkernel.h"
#include <akonadi/dbusconnectionpool.h>
#include <KDebug>
#include <KMessageBox>
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<int> 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<MailCommon::FolderCollection> &currentFolder)
{
mCurrentFolder = currentFolder;
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
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 <QObject>
#include <QSharedPointer>
#include <foldercollection.h>
class QDBusPendingCallWatcher;
class ManageServerSideSubscriptionJob : public QObject
{
Q_OBJECT
public:
explicit ManageServerSideSubscriptionJob(QObject *parent=0);
~ManageServerSideSubscriptionJob();
void start();
void setCurrentFolder(const QSharedPointer<MailCommon::FolderCollection> &currentFolder);
void setParentWidget(QWidget *parentWidget);
private slots:
void slotConfigureSubscriptionFinished(QDBusPendingCallWatcher *watcher);
private:
QSharedPointer<MailCommon::FolderCollection> mCurrentFolder;
QWidget *mParentWidget;
};
#endif // MANAGESERVERSIDESUBSCRIPTIONJOB_H
......@@ -196,6 +196,7 @@ using KSieveUi::SieveDebugDialog;
// System includes
#include <errno.h> // ugh
#include <akonadi/standardactionmanager.h>
#include <job/manageserversidesubscriptionjob.h>
#include <job/removeduplicatemailjob.h>
......@@ -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<int> 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()
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment