parent
4778911df5
commit
165d87f692
5 changed files with 141 additions and 28 deletions
@ -0,0 +1,89 @@ |
||||
/*
|
||||
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> ¤tFolder) |
||||
{ |
||||
mCurrentFolder = currentFolder; |
||||
} |
||||
|
||||
|
||||
@ -0,0 +1,46 @@ |
||||
/*
|
||||
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> ¤tFolder); |
||||
|
||||
void setParentWidget(QWidget *parentWidget); |
||||
|
||||
private slots: |
||||
void slotConfigureSubscriptionFinished(QDBusPendingCallWatcher *watcher); |
||||
private: |
||||
QSharedPointer<MailCommon::FolderCollection> mCurrentFolder; |
||||
QWidget *mParentWidget; |
||||
}; |
||||
|
||||
#endif // MANAGESERVERSIDESUBSCRIPTIONJOB_H
|
||||
Loading…
Reference in new issue