Pimcommon

manageserversidesubscriptionjob.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "manageserversidesubscriptionjob.h"
8#include "pimcommonakonadi_debug.h"
9#include "util/mailutil.h"
10
11#include <Akonadi/ServerManager>
12
13#include <KLocalizedString>
14#include <KMessageBox>
15
16#include <QDBusConnection>
17#include <QDBusInterface>
18#include <QDBusPendingCall>
19#include <QDBusPendingReply>
20
21using namespace PimCommon;
22
23class PimCommon::ManageServerSideSubscriptionJobPrivate
24{
25public:
26 ManageServerSideSubscriptionJobPrivate() = default;
27
28 Akonadi::Collection mCurrentCollection;
29 QWidget *mParentWidget = nullptr;
30};
31
32ManageServerSideSubscriptionJob::ManageServerSideSubscriptionJob(QObject *parent)
33 : QObject(parent)
34 , d(new PimCommon::ManageServerSideSubscriptionJobPrivate)
35{
36}
37
38ManageServerSideSubscriptionJob::~ManageServerSideSubscriptionJob() = default;
39
40void ManageServerSideSubscriptionJob::start()
41{
42 if (!d->mCurrentCollection.isValid()) {
43 qCDebug(PIMCOMMONAKONADI_LOG) << " collection not defined";
45 return;
46 }
47 bool isImapOnline = false;
48 if (PimCommon::MailUtil::isImapFolder(d->mCurrentCollection, isImapOnline)) {
49 const QString service = Akonadi::ServerManager::agentServiceName(Akonadi::ServerManager::Resource, d->mCurrentCollection.resource());
50 QDBusInterface iface(service, QStringLiteral("/"), QStringLiteral("org.kde.Akonadi.ImapResourceBase"), QDBusConnection::sessionBus(), this);
51 if (!iface.isValid()) {
52 qCDebug(PIMCOMMONAKONADI_LOG) << "Cannot create imap dbus interface for service " << service;
54 return;
55 }
56 QDBusPendingCall call = iface.asyncCall(QStringLiteral("configureSubscription"), (qlonglong)d->mParentWidget->winId());
57 auto watcher = new QDBusPendingCallWatcher(call, this);
58 connect(watcher, &QDBusPendingCallWatcher::finished, this, &ManageServerSideSubscriptionJob::slotConfigureSubscriptionFinished);
59 }
60}
61
62void ManageServerSideSubscriptionJob::slotConfigureSubscriptionFinished(QDBusPendingCallWatcher *watcher)
63{
64 QDBusPendingReply<int> reply = *watcher;
65 if (reply.isValid()) {
66 if (reply == -2) {
68 d->mParentWidget,
69 i18n("IMAP server not configured yet. Please configure the server in the IMAP account before setting up server-side subscription."));
70 } else if (reply == -1) {
71 KMessageBox::error(d->mParentWidget, i18n("Log in failed, please configure the IMAP account before setting up server-side subscription."));
72 }
73 } else {
74 qCDebug(PIMCOMMONAKONADI_LOG) << "ManageServerSideSubscriptionJob return an invalid reply";
75 }
76 watcher->deleteLater();
78}
79
80void ManageServerSideSubscriptionJob::setParentWidget(QWidget *parentWidget)
81{
82 d->mParentWidget = parentWidget;
83}
84
85void ManageServerSideSubscriptionJob::setCurrentCollection(const Akonadi::Collection &col)
86{
87 d->mCurrentCollection = col;
88}
89
90#include "moc_manageserversidesubscriptionjob.cpp"
static QString agentServiceName(ServiceAgentType agentType, const QString &identifier)
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
folderdialogacltab.h
QDBusConnection sessionBus()
void finished(QDBusPendingCallWatcher *self)
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.