81
82
static const char* KTTSD_DBUS_SERVICE = "org.kde.kttsd";
82
83
static const char* KTTDS_DBUS_PATH = "/KSpeech";
86
static const int AKONADI_TIMEOUT = 30; // timeout (seconds) for Akonadi collections to be populated
84
89
static void setEventCommandError(const KAEvent&, KAEvent::CmdErrType);
85
90
static void clearEventCommandError(const KAEvent&, KAEvent::CmdErrType);
328
333
// Display or delete the event with the specified event ID
329
334
EventFunc function = (command == CommandOptions::TRIGGER_EVENT) ? EVENT_TRIGGER : EVENT_CANCEL;
330
if (!initCheck(true)) // open the calendar, don't start processing execution queue yet
335
// Open the calendar, don't start processing execution queue yet,
336
// and wait for the Akonadi collection to be populated.
338
if (!initCheck(true, true, options.eventId().collectionId()))
340
if (!initCheck(true))
334
startProcessQueue(); // start processing the execution queue
345
startProcessQueue(); // start processing the execution queue
346
dontRedisplay = true;
348
if (!handleEvent(options.eventId(), function, true))
335
350
if (!handleEvent(options.eventId(), function))
354
CommandOptions::printError(i18nc("@info:shell", "%1: Event <resource>%2</resource> not found, or not unique", "--" + options.commandName(), options.eventId().eventId()));
356
CommandOptions::printError(i18nc("@info:shell", "%1: Event <resource>%2</resource> not found", "--" + options.commandName(), options.eventId()));
363
case CommandOptions::LIST:
364
// Output a list of scheduled alarms to stdout.
365
// Open the calendar, don't start processing execution queue yet,
366
// and wait for all Akonadi collections to be populated.
368
if (!initCheck(true, true))
370
if (!initCheck(true))
375
dontRedisplay = true;
376
QStringList alarms = scheduledAlarmList();
377
for (int i = 0, count = alarms.count(); i < count; ++i)
378
std::cout << alarms[i].toUtf8().constData() << std::endl;
340
381
case CommandOptions::EDIT:
341
// Edit a specified existing alarm
382
// Edit a specified existing alarm.
383
// Open the calendar and wait for the Akonadi collection to be populated.
385
if (!initCheck(false, true, options.eventId().collectionId()))
342
387
if (!initCheck())
344
390
else if (!KAlarm::editAlarmById(options.eventId()))
346
CommandOptions::printError(i18nc("@info:shell", "<icode>%1</icode>: Event <resource>%2</resource> not found, or not editable", QString::fromLatin1("--edit"), options.eventId()));
393
CommandOptions::printError(i18nc("@info:shell", "%1: Event <resource>%2</resource> not found, or not editable", "--" + options.commandName(), options.eventId().eventId()));
395
CommandOptions::printError(i18nc("@info:shell", "%1: Event <resource>%2</resource> not found, or not editable", "--" + options.commandName(), options.eventId()));
519
569
#if KDE_IS_VERSION(4,5,70)
520
570
if (!KSystemTimeZones::isTimeZoneDaemonAvailable())
522
572
kDebug() << "ktimezoned not running: using UTC only";
523
573
KAMessageBox::information(MainWindow::mainMainWindow(),
524
574
i18nc("@info", "Time zones are not accessible:<nl/>KAlarm will use the UTC time zone.<nl/><nl/>(The KDE time zone service is not available:<nl/>check that <application>ktimezoned</application> is installed.)"),
742
792
* Also called when the execution queue has finished processing to check for the
745
void KAlarmApp::queueAlarmId(const QString& id)
795
void KAlarmApp::queueAlarmId(const KAEvent& event)
800
const QString id(event.id());
747
802
for (int i = 0, end = mActionQueue.count(); i < end; ++i)
749
804
if (mActionQueue[i].function == EVENT_HANDLE && mActionQueue[i].eventId == id)
1129
1184
/******************************************************************************
1185
* Output a list of pending alarms, with their next scheduled occurrence.
1187
QStringList KAlarmApp::scheduledAlarmList()
1190
QVector<KAEvent> events = KAlarm::getSortedActiveEvents(this);
1192
KAEvent::List events = KAlarm::getSortedActiveEvents();
1195
for (int i = 0, count = events.count(); i < count; ++i)
1198
KAEvent* event = &events[i];
1200
KAEvent* event = events[i];
1202
KDateTime dateTime = event->nextTrigger(KAEvent::DISPLAY_TRIGGER).effectiveKDateTime().toLocalZone();
1204
Akonadi::Collection c(event->collectionId());
1205
AkonadiModel::instance()->refresh(c);
1206
QString text(c.resource() + ":");
1210
text += event->id() + ' '
1211
+ dateTime.toString("%Y%m%dT%H%M ")
1212
+ AlarmText::summary(events[i], 1);
1218
/******************************************************************************
1130
1219
* Enable or disable alarm monitoring.
1132
1221
void KAlarmApp::setAlarmsEnabled(bool enabled)
1228
1317
* Optionally display the event. Delete the event from the calendar file and
1229
1318
* from every main window instance.
1321
bool KAlarmApp::dbusHandleEvent(const EventId& eventID, EventFunc function)
1231
1323
bool KAlarmApp::dbusHandleEvent(const QString& eventID, EventFunc function)
1233
1326
kDebug() << eventID;
1234
1327
mActionQueue.append(ActionQEntry(function, eventID));
1240
1333
/******************************************************************************
1334
* Called in response to a D-Bus request to list all pending alarms.
1336
QString KAlarmApp::dbusList()
1339
return scheduledAlarmList().join("\n") + '\n';
1342
/******************************************************************************
1242
1344
* a) Display the event and then delete it if it has no outstanding repetitions.
1243
1345
* b) Delete the event.
1247
1349
* Reply = false if event ID not found, or if more than one event with the same
1353
bool KAlarmApp::handleEvent(const EventId& id, EventFunc function, bool checkDuplicates)
1250
1355
bool KAlarmApp::handleEvent(const QString& eventID, EventFunc function)
1252
1358
// Delete any expired wake-on-suspend config data
1253
1359
KAlarm::checkRtcWakeConfig();
1255
1361
#ifdef USE_AKONADI
1256
KAEvent::List events = AlarmCalendar::resources()->events(eventID);
1257
if (events.count() > 1)
1362
const QString eventID(id.eventId());
1363
KAEvent* event = AlarmCalendar::resources()->event(id, checkDuplicates);
1259
kWarning() << "Multiple events found with ID" << eventID;
1366
if (id.collectionId() != -1)
1367
kWarning() << "Event ID not found, or duplicated:" << eventID;
1369
kWarning() << "Event ID not found:" << eventID;
1262
if (events.isEmpty())
1264
1373
KAEvent* event = AlarmCalendar::resources()->event(eventID);
1268
1376
kWarning() << "Event ID not found:" << eventID;
1272
KAEvent* event = events[0];
1274
1380
switch (function)
2216
2322
* If this is the first time through, open the calendar file, and start
2217
2323
* processing the execution queue.
2326
bool KAlarmApp::initCheck(bool calendarOnly, bool waitForCollection, Akonadi::Collection::Id collectionId)
2219
2328
bool KAlarmApp::initCheck(bool calendarOnly)
2221
2331
static bool firstTime = true;