23 #include "kalarmsettings.h"
24 #include "kalarmdirsettings.h"
25 #include "controlinterface.h"
27 #include <akonadi/agentfilterproxymodel.h>
28 #include <akonadi/agentinstancecreatejob.h>
29 #include <akonadi/agentmanager.h>
30 #include <akonadi/agenttypedialog.h>
31 #include <akonadi/dbusconnectionpool.h>
33 #include <kmessagebox.h>
39 using namespace Akonadi;
40 using namespace KAlarmCal;
46 mDefaultType(defaultType)
55 QTimer::singleShot(0,
this, SLOT(getAgentType()));
58 void AkonadiResourceCreator::getAgentType()
60 kDebug() <<
"Type:" << mDefaultType;
68 case CalEvent::ACTIVE:
69 mimeType = KAlarmCal::MIME_ACTIVE;
71 case CalEvent::ARCHIVED:
72 mimeType = KAlarmCal::MIME_ARCHIVED;
74 case CalEvent::TEMPLATE:
75 mimeType = KAlarmCal::MIME_TEMPLATE;
81 dlg->agentFilterProxyModel()->addMimeTypeFilter(mimeType);
82 dlg->agentFilterProxyModel()->addCapabilityFilter(QLatin1String(
"Resource"));
83 if (dlg->exec() != QDialog::Accepted)
88 mAgentType = dlg->agentType();
89 if (!mAgentType.isValid())
94 AgentInstanceCreateJob* job =
new AgentInstanceCreateJob(mAgentType, mParent);
95 connect(job, SIGNAL(result(
KJob*)), SLOT(agentInstanceCreated(
KJob*)));
103 void AkonadiResourceCreator::agentInstanceCreated(
KJob* j)
105 AgentInstanceCreateJob* job =
static_cast<AgentInstanceCreateJob*
>(j);
108 kError() <<
"Failed to create new calendar resource:" << j->errorString();
109 KMessageBox::error(0, i18nc(
"@info",
"%1<nl/>(%2)", i18nc(
"@info/plain",
"Failed to create new calendar resource"), j->errorString()));
115 mAgentInstance = job->instance();
116 QString type = mAgentInstance.type().identifier();
117 if (type == QLatin1String(
"akonadi_kalarm_dir_resource"))
118 setResourceAlarmType<OrgKdeAkonadiKAlarmDirSettingsInterface>();
119 else if (type == QLatin1String(
"akonadi_kalarm_resource"))
120 setResourceAlarmType<OrgKdeAkonadiKAlarmSettingsInterface>();
124 org::freedesktop::Akonadi::Agent::Control* agentControlIface =
125 new org::freedesktop::Akonadi::Agent::Control(QLatin1String(
"org.freedesktop.Akonadi.Agent.") + mAgentInstance.identifier(),
126 QLatin1String(
"/"), DBusConnectionPool::threadConnection(),
this);
127 bool controlOk = agentControlIface && agentControlIface->isValid();
130 delete agentControlIface;
131 kWarning() <<
"Unable to access D-Bus interface of created agent.";
135 connect(agentControlIface, SIGNAL(configurationDialogAccepted()), SLOT(configurationDialogAccepted()));
136 connect(agentControlIface, SIGNAL(configurationDialogRejected()), SLOT(exitWithError()));
138 mAgentInstance.configure(mParent);
148 template <
class Settings>
149 void AkonadiResourceCreator::setResourceAlarmType()
151 Settings iface(QLatin1String(
"org.freedesktop.Akonadi.Resource.") + mAgentInstance.identifier(),
152 QLatin1String(
"/Settings"), QDBusConnection::sessionBus(),
this);
153 if (!iface.isValid())
154 kError() <<
"Error creating D-Bus interface for" << mAgentInstance.identifier() <<
"resource configuration.";
157 iface.setAlarmTypes(CalEvent::mimeTypes(mDefaultType));
159 mAgentInstance.reconfigure();
166 void AkonadiResourceCreator::configurationDialogAccepted()
175 void AkonadiResourceCreator::exitWithError()
177 AgentManager::self()->removeInstance(mAgentInstance);
AkonadiResourceCreator(CalEvent::Type defaultType, QWidget *parent)
void finished(AkonadiResourceCreator *, bool success)