Commit 10697d77 authored by David Jarvie's avatar David Jarvie

Add D-Bus call to return list of scheduled alarms and their times

parent 22996e69
......@@ -72,6 +72,11 @@ bool DBusHandler::triggerEvent(const QString& eventId)
return theApp()->dbusTriggerEvent(eventId);
}
QString DBusHandler::list()
{
return theApp()->dbusList();
}
bool DBusHandler::scheduleMessage(const QString& message, const QString& startDateTime, int lateCancel, unsigned flags,
const QString& bgColor, const QString& fgColor, const QString& font,
const QString& audioUrl, int reminderMins, const QString& recurrence,
......
/*
* dbushandler.h - handler for D-Bus calls by other applications
* Program: kalarm
* Copyright © 2001-2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -47,6 +47,7 @@ class DBusHandler : public QObject, public KAlarmIface
public Q_SLOTS:
Q_SCRIPTABLE bool cancelEvent(const QString& eventId);
Q_SCRIPTABLE bool triggerEvent(const QString& eventId);
Q_SCRIPTABLE QString list();
Q_SCRIPTABLE bool scheduleMessage(const QString& message, const QString& startDateTime, int lateCancel, unsigned flags,
const QString& bgColor, const QString& fgColor, const QString& font,
......
......@@ -349,7 +349,9 @@ int KAlarmApp::newInstance()
else
{
dontRedisplay = true;
listScheduledAlarms();
QStringList alarms = scheduledAlarmList();
for (int i = 0, count = alarms.count(); i < count; ++i)
std::cout << alarms[i].toUtf8().constData() << std::endl;
}
break;
case CommandOptions::EDIT:
......@@ -1144,7 +1146,7 @@ void KAlarmApp::purge(int daysToKeep)
/******************************************************************************
* Output a list of pending alarms, with their next scheduled occurrence.
*/
void KAlarmApp::listScheduledAlarms()
QStringList KAlarmApp::scheduledAlarmList()
{
#ifdef USE_AKONADI
QVector<KAEvent> events = KAlarm::getSortedActiveEvents(this);
......@@ -1152,6 +1154,7 @@ void KAlarmApp::listScheduledAlarms()
KAEvent::List events = KAlarm::getSortedActiveEvents();
#endif
kDebug()<<"List count="<<events.count();
QStringList alarms;
for (int i = 0, count = events.count(); i < count; ++i)
{
#ifdef USE_AKONADI
......@@ -1168,8 +1171,9 @@ kDebug()<<"List count="<<events.count();
text += event->id() + ' '
+ dateTime.toString("%Y%m%dT%H%M ")
+ AlarmText::summary(events[i], 1);
std::cerr << text.toUtf8().constData() << std::endl;
alarms << text;
}
return alarms;
}
/******************************************************************************
......@@ -1283,6 +1287,15 @@ bool KAlarmApp::dbusHandleEvent(const QString& eventID, EventFunc function)
return true;
}
/******************************************************************************
* Called in response to a D-Bus request to list all pending alarms.
*/
QString KAlarmApp::dbusList()
{
kDebug();
return scheduledAlarmList().join("\n") + '\n';
}
/******************************************************************************
* Either:
* a) Display the event and then delete it if it has no outstanding repetitions.
......
......@@ -99,6 +99,7 @@ class KAlarmApp : public KUniqueApplication
const QStringList& mailAttachments = QStringList());
bool dbusTriggerEvent(const QString& eventID) { return dbusHandleEvent(eventID, EVENT_TRIGGER); }
bool dbusDeleteEvent(const QString& eventID) { return dbusHandleEvent(eventID, EVENT_CANCEL); }
QString dbusList();
public slots:
void processQueue();
......@@ -200,7 +201,7 @@ class KAlarmApp : public KUniqueApplication
#ifdef USE_AKONADI
bool checkResourcesPopulated();
#endif
void listScheduledAlarms();
QStringList scheduledAlarmList();
static KAlarmApp* theInstance; // the one and only KAlarmApp instance
static int mActiveCount; // number of active instances without main windows
......
......@@ -9,6 +9,9 @@
<arg type="b" direction="out"/>
<arg name="eventId" type="s" direction="in"/>
</method>
<method name="list">
<arg type="s" direction="out"/>
</method>
<method name="scheduleMessage">
<arg type="b" direction="out"/>
<arg name="message" type="s" direction="in"/>
......
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