Use Akonadi's AgentManager to invoke agent's configuration dialog

Avoid using direct DBus calls to interact with standard Akonadi Agent
functions.
wilder
Daniel Vrátil 8 years ago
parent 51f6c248ab
commit 8a2b1ccd3a
  1. 25
      agents/archivemailagent/archivemailagent.cpp
  2. 1
      agents/archivemailagent/archivemailagent.h
  3. 3
      agents/archivemailagent/org.freedesktop.Akonadi.ArchiveMailAgent.xml
  4. 8
      agents/followupreminderagent/followupreminderagent.cpp
  5. 2
      agents/followupreminderagent/followupreminderagent.h
  6. 3
      agents/followupreminderagent/org.freedesktop.Akonadi.FollowUpReminder.xml
  7. 3
      agents/sendlateragent/org.freedesktop.Akonadi.SendLaterAgent.xml
  8. 15
      agents/sendlateragent/sendlateragent.cpp
  9. 2
      agents/sendlateragent/sendlateragent.h
  10. 9
      src/configuredialog/configureplugins/configurepluginslistwidget.cpp
  11. 33
      src/kmlaunchexternalcomponent.cpp

@ -106,20 +106,6 @@ void ArchiveMailAgent::mailCollectionRemoved(const Akonadi::Collection &collecti
mArchiveManager->removeCollection(collection);
}
void ArchiveMailAgent::showConfigureDialog(qlonglong windowId)
{
QPointer<ArchiveMailDialog> dialog = new ArchiveMailDialog();
if (windowId) {
KWindowSystem::setMainWindow(dialog, windowId);
}
connect(dialog.data(), &ArchiveMailDialog::archiveNow, mArchiveManager, &ArchiveMailManager::slotArchiveNow);
connect(this, &ArchiveMailAgent::needUpdateConfigDialogBox, dialog.data(), &ArchiveMailDialog::slotNeedReloadConfig);
if (dialog->exec()) {
mArchiveManager->load();
}
delete dialog;
}
void ArchiveMailAgent::doSetOnline(bool online)
{
if (online) {
@ -139,7 +125,16 @@ void ArchiveMailAgent::reload()
void ArchiveMailAgent::configure(WId windowId)
{
showConfigureDialog(static_cast<qulonglong>(windowId));
QPointer<ArchiveMailDialog> dialog = new ArchiveMailDialog();
if (windowId) {
KWindowSystem::setMainWindow(dialog, windowId);
}
connect(dialog.data(), &ArchiveMailDialog::archiveNow, mArchiveManager, &ArchiveMailManager::slotArchiveNow);
connect(this, &ArchiveMailAgent::needUpdateConfigDialogBox, dialog.data(), &ArchiveMailDialog::slotNeedReloadConfig);
if (dialog->exec()) {
mArchiveManager->load();
}
delete dialog;
}
void ArchiveMailAgent::pause()

@ -36,7 +36,6 @@ public:
explicit ArchiveMailAgent(const QString &id);
~ArchiveMailAgent() override;
void showConfigureDialog(qlonglong windowId = 0);
QString printArchiveListInfo();
void setEnableAgent(bool b);

@ -1,9 +1,6 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Akonadi.ArchiveMailAgent">
<method name="showConfigureDialog" >
<arg direction="in" type="x" name="windowId" />
</method>
<method name="pause"/>
<method name="resume"/>
<method name="printArchiveListInfo">

@ -52,7 +52,6 @@ FollowUpReminderAgent::FollowUpReminderAgent(const QString &id)
if (Akonadi::ServerManager::hasInstanceIdentifier()) {
service += QLatin1Char('.') + Akonadi::ServerManager::instanceIdentifier();
}
KDBusConnectionPool::threadConnection().registerService(service);
mManager = new FollowUpReminderManager(this);
setNeedsNetwork(true);
@ -101,7 +100,7 @@ bool FollowUpReminderAgent::enabledAgent() const
return FollowUpReminderAgentSettings::self()->enabled();
}
void FollowUpReminderAgent::showConfigureDialog(qlonglong windowId)
void FollowUpReminderAgent::configure(WId windowId)
{
QPointer<FollowUpReminderInfoDialog> dialog = new FollowUpReminderInfoDialog();
dialog->load();
@ -117,11 +116,6 @@ void FollowUpReminderAgent::showConfigureDialog(qlonglong windowId)
delete dialog;
}
void FollowUpReminderAgent::configure(WId windowId)
{
showConfigureDialog(static_cast<qlonglong>(windowId));
}
void FollowUpReminderAgent::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection)
{
if (!enabledAgent()) {

@ -32,8 +32,6 @@ public:
void setEnableAgent(bool b);
bool enabledAgent() const;
void showConfigureDialog(qlonglong windowId = 0);
QString printDebugInfo();
public Q_SLOTS:

@ -1,9 +1,6 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Akonadi.FollowUpReminderAgent">
<method name="showConfigureDialog" >
<arg direction="in" type="x" name="windowId" />
</method>
<method name="setEnableAgent" >
<arg type="b" direction="in"/>
</method>

@ -1,9 +1,6 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Akonadi.SendLaterAgent">
<method name="showConfigureDialog" >
<arg direction="in" type="x" name="windowId" />
</method>
<method name="setEnableAgent" >
<arg type="b" direction="in"/>
</method>

@ -137,16 +137,6 @@ bool SendLaterAgent::enabledAgent() const
}
void SendLaterAgent::configure(WId windowId)
{
showConfigureDialog(static_cast<qlonglong>(windowId));
}
void SendLaterAgent::slotSendNow(Akonadi::Item::Id id)
{
mManager->sendNow(id);
}
void SendLaterAgent::showConfigureDialog(qlonglong windowId)
{
QPointer<SendLaterConfigureDialog> dialog = new SendLaterConfigureDialog();
if (windowId) {
@ -166,6 +156,11 @@ void SendLaterAgent::showConfigureDialog(qlonglong windowId)
delete dialog;
}
void SendLaterAgent::slotSendNow(Akonadi::Item::Id id)
{
mManager->sendNow(id);
}
void SendLaterAgent::itemsRemoved(const Akonadi::Item::List &items)
{
for (const Akonadi::Item &item : items) {

@ -32,8 +32,6 @@ public:
explicit SendLaterAgent(const QString &id);
~SendLaterAgent() override;
void showConfigureDialog(qlonglong windowId = 0);
QString printDebugInfo();
void setEnableAgent(bool b);

@ -335,12 +335,9 @@ void ConfigurePluginsListWidget::slotConfigureClicked(const QString &configureGr
} else if (configureGroupName == agentAkonadiGroupName()) {
for (const PimCommon::PluginUtilData &data : qAsConst(mPluginUtilDataList)) {
if (data.mIdentifier == identifier) {
const QString service = Akonadi::ServerManager::agentServiceName(Akonadi::ServerManager::Agent, data.mExtraInfo.at(0));
QDBusInterface interface(service, data.mExtraInfo.at(1));
if (interface.isValid()) {
interface.call(QStringLiteral("showConfigureDialog"), static_cast<qlonglong>(winId()));
} else {
qCDebug(KMAIL_LOG) << " interface does not exist when trying to configure the plugin";
auto instance = Akonadi::AgentManager::self()->instance(identifier);
if (instance.isValid()) {
instance.configure(this);
}
break;
}

@ -21,6 +21,7 @@
#include <KMessageBox>
#include <KLocalizedString>
#include <KRun>
#include <AkonadiCore/AgentManager>
#include "util.h"
#include "archivemailagentinterface.h"
@ -44,21 +45,11 @@ KMLaunchExternalComponent::~KMLaunchExternalComponent()
{
}
QString KMLaunchExternalComponent::akonadiPath(QString service)
{
if (Akonadi::ServerManager::hasInstanceIdentifier()) {
service += QLatin1Char('.') + Akonadi::ServerManager::instanceIdentifier();
}
return service;
}
void KMLaunchExternalComponent::slotConfigureAutomaticArchiving()
{
const QString service = akonadiPath(QStringLiteral("org.freedesktop.Akonadi.ArchiveMailAgent"));
OrgFreedesktopAkonadiArchiveMailAgentInterface archiveMailInterface(service, QStringLiteral("/ArchiveMailAgent"),
QDBusConnection::sessionBus(), this);
if (archiveMailInterface.isValid()) {
archiveMailInterface.showConfigureDialog(static_cast<qlonglong>(mParentWidget->winId()));
auto agent = Akonadi::AgentManager::self()->instance(QStringLiteral("akonadi_archivemail_agent"));
if (agent.isValid()) {
agent.configure(mParentWidget);
} else {
KMessageBox::error(mParentWidget, i18n("Archive Mail Agent was not registered."));
}
@ -66,10 +57,9 @@ void KMLaunchExternalComponent::slotConfigureAutomaticArchiving()
void KMLaunchExternalComponent::slotConfigureSendLater()
{
const QString service = akonadiPath(QStringLiteral("org.freedesktop.Akonadi.SendLaterAgent"));
OrgFreedesktopAkonadiSendLaterAgentInterface sendLaterInterface(service, QStringLiteral("/SendLaterAgent"), QDBusConnection::sessionBus(), this);
if (sendLaterInterface.isValid()) {
sendLaterInterface.showConfigureDialog(static_cast<qlonglong>(mParentWidget->winId()));
auto agent = Akonadi::AgentManager::self()->instance(QStringLiteral("akonadi_sendlater_agent"));
if (agent.isValid()) {
agent.configure(mParentWidget);
} else {
KMessageBox::error(mParentWidget, i18n("Send Later Agent was not registered."));
}
@ -77,12 +67,9 @@ void KMLaunchExternalComponent::slotConfigureSendLater()
void KMLaunchExternalComponent::slotConfigureFollowupReminder()
{
const QString service = akonadiPath(QStringLiteral("org.freedesktop.Akonadi.FollowUpReminder"));
OrgFreedesktopAkonadiFollowUpReminderAgentInterface followUpInterface(service, QStringLiteral("/FollowUpReminder"),
QDBusConnection::sessionBus(), this);
if (followUpInterface.isValid()) {
followUpInterface.showConfigureDialog(static_cast<qlonglong>(mParentWidget->winId()));
auto agent = Akonadi::AgentManager::self()->instance(QStringLiteral("akonadi_followupreminder_agent"));
if (agent.isValid()) {
agent.configure(mParentWidget);
} else {
KMessageBox::error(mParentWidget, i18n("Followup Reminder Agent was not registered."));
}

Loading…
Cancel
Save