From 6831c6ac3119879a2e8a40cb9f3ebe10ab311a87 Mon Sep 17 00:00:00 2001 From: hanzes Date: Mon, 1 Feb 2010 13:05:49 +0000 Subject: [PATCH] Alarm dbus connection added --- src/alarm/alarm.cpp | 30 ++++++++++---------- src/alarm/alarm.pro | 18 ++++++++++-- src/alarm/alarmdbus.cpp | 26 ++++++++++++++++++ src/alarm/alarmdbus.h | 24 ++++++++++++++++ src/alarm/alarmdbusadaptor.cpp | 42 ++++++++++++++++++++++++++++ src/alarm/alarmdbusadaptorp.h | 50 ++++++++++++++++++++++++++++++++++ src/app/app.pro | 2 +- src/app/main.cpp | 35 ++++++++++++++++++------ src/gui/gui.pro | 10 +++---- src/mvc/treeview.cpp | 6 ++-- src/src.pro | 2 +- 11 files changed, 209 insertions(+), 36 deletions(-) create mode 100644 src/alarm/alarmdbus.cpp create mode 100644 src/alarm/alarmdbus.h create mode 100644 src/alarm/alarmdbusadaptor.cpp create mode 100644 src/alarm/alarmdbusadaptorp.h diff --git a/src/alarm/alarm.cpp b/src/alarm/alarm.cpp index 70f7649..333ed34 100644 --- a/src/alarm/alarm.cpp +++ b/src/alarm/alarm.cpp @@ -4,6 +4,9 @@ #include #include +#include + +#include int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime) { @@ -16,15 +19,12 @@ int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime) alarm_event_set_alarm_appid(eve, APPID); /* for Deleting purposes */ - alarm_event_set_message(eve, QString::number(aEventId).toLocal8Bit().data()); + alarm_event_set_message(eve, QString::number(aEventId).toLocal8Bit().data()); /* Use absolute time triggering */ eve->alarm_time = time(0) + 5; //aDateTime.toTime_t(); eve->flags = ALARM_EVENT_BOOT; - QString command = QDir::currentPath() + "/" + *qApp->argv() + - QString(" %1").arg(QString::number(aEventId)); - /* Add exec command action */ act = alarm_event_add_actions(eve, 1); alarm_action_set_label(act, "FOSDEM'10"); @@ -32,22 +32,22 @@ int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime) // setup this action to be a "DBus command" act->flags |= ALARM_ACTION_WHEN_RESPONDED; act->flags |= ALARM_ACTION_TYPE_DBUS; - - // DBus params for this action - alarm_action_set_dbus_interface(act, "org.freedesktop.Notifications"); - alarm_action_set_dbus_service(act, "org.freedesktop.Notifications"); - alarm_action_set_dbus_path(act, "/org/freedesktop/Notifications"); - alarm_action_set_dbus_name(act, "SystemNoteDialog"); - + + // DBus params for this action + alarm_action_set_dbus_interface(act, "org.fosdem.schedule.AlarmInterface"); + alarm_action_set_dbus_service(act, "org.fosdem.schedule"); + alarm_action_set_dbus_path(act, "/Fosdem"); + alarm_action_set_dbus_name(act, "Alarm"); + // DBus arguments for the action - alarm_action_set_dbus_args(act, aEventId); + alarm_action_set_dbus_args(act, DBUS_TYPE_INT32, &aEventId, DBUS_TYPE_INVALID); // act->flags |= ALARM_ACTION_TYPE_EXEC; // alarm_action_set_exec_command(act, command.toLocal8Bit().data()); // alarm_event_set_icon(eve, "fosdem"); // alarm_event_set_title(eve, "FOSDEM'10"); - // adds assigned cookie at the end of command string - // act->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; + // adds assigned cookie at the end of command string + // act->flags |= ALARM_ACTION_EXEC_ADD_COOKIE; /* Add stop button action */ /* TODO: send a DBus message to remove that alarm from database */ @@ -55,7 +55,7 @@ int Alarm::addAlarm(int aEventId, const QDateTime &aDateTime) alarm_action_set_label(act, "Stop"); act->flags |= ALARM_ACTION_WHEN_RESPONDED; act->flags |= ALARM_ACTION_TYPE_NOP; - + /* Add snooze button action */ act = alarm_event_add_actions(eve, 1); alarm_action_set_label(act, "Snooze"); diff --git a/src/alarm/alarm.pro b/src/alarm/alarm.pro index ea4b04b..94838c8 100644 --- a/src/alarm/alarm.pro +++ b/src/alarm/alarm.pro @@ -1,13 +1,25 @@ TEMPLATE = lib TARGET = qalarm DESTDIR = ../bin -CONFIG += static +CONFIG += static qdbus +QT += sql dbus # module dependencies LIBS += -lalarm DEPENDPATH += . -HEADERS += alarm.h +HEADERS += alarm.h \ + alarmdbus.h \ + alarmdbusadaptorp.h + +SOURCES += alarm.cpp \ + alarmdbus.cpp \ + alarmdbusadaptor.cpp + +INCLUDEPATH += ../gui \ + ../mvc \ + ../orm \ + ../sql + -SOURCES += alarm.cpp diff --git a/src/alarm/alarmdbus.cpp b/src/alarm/alarmdbus.cpp new file mode 100644 index 0000000..286b851 --- /dev/null +++ b/src/alarm/alarmdbus.cpp @@ -0,0 +1,26 @@ + +#include "alarmdbus.h" +#include "eventdialog.h" + + + + +CAlarmDBus::CAlarmDBus(QWidget * aParent) + : QObject(), + mParent(aParent) +{ + // constructor + //setAutoRelaySignals(true); +} + +CAlarmDBus::~CAlarmDBus() +{ + // destructor +} + +void CAlarmDBus::Alarm(int aEventId) +{ + EventDialog dialog(aEventId,mParent); + dialog.exec(); + +} diff --git a/src/alarm/alarmdbus.h b/src/alarm/alarmdbus.h new file mode 100644 index 0000000..6363b95 --- /dev/null +++ b/src/alarm/alarmdbus.h @@ -0,0 +1,24 @@ +#ifndef SINGLE_INSTANCE_H +#define SINGLE_INSTANCE_H + +#include +#include + +class CAlarmDBus: public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.fosdem.schedule") + +public: + CAlarmDBus(QWidget * aParent); + virtual ~CAlarmDBus(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + void Alarm(int aEventId); +private: + QWidget * mParent; +}; + + +#endif // SINGLE_INSTANCE_H diff --git a/src/alarm/alarmdbusadaptor.cpp b/src/alarm/alarmdbusadaptor.cpp new file mode 100644 index 0000000..c0c903a --- /dev/null +++ b/src/alarm/alarmdbusadaptor.cpp @@ -0,0 +1,42 @@ +/* + * This file was generated by dbusxml2cpp version 0.6 + * Command line was: dbusxml2cpp -c CarAdaptor -a car_adaptor_p.h:car_adaptor.cpp car.xml + * + * dbusxml2cpp is Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "alarmdbusadaptorp.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class CarAdaptor + */ + +AlarmDBusAdaptor::AlarmDBusAdaptor(QObject *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + setAutoRelaySignals(true); +} + +AlarmDBusAdaptor::~AlarmDBusAdaptor() +{ + // destructor +} + +void AlarmDBusAdaptor::Alarm(int aEventId) +{ + // handle method call com.trolltech.Examples.CarInterface.accelerate + QMetaObject::invokeMethod(parent(), "Alarm",Q_ARG(int, aEventId)); +} + + diff --git a/src/alarm/alarmdbusadaptorp.h b/src/alarm/alarmdbusadaptorp.h new file mode 100644 index 0000000..cf22b17 --- /dev/null +++ b/src/alarm/alarmdbusadaptorp.h @@ -0,0 +1,50 @@ +/* + * This file was generated by dbusxml2cpp version 0.6 + * Command line was: dbusxml2cpp -c CarAdaptor -a car_adaptor_p.h:car_adaptor.cpp car.xml + * + * dbusxml2cpp is Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef ALARM_DBUS_ADAPTOR_P_H +#define ALARM_DBUS_ADAPTOR_P_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QByteArray; +template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +/* + * Adaptor class for interface com.trolltech.Examples.CarInterface + */ +class AlarmDBusAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.fosdem.schedule.AlarmInterface") + Q_CLASSINFO("D-Bus Introspection", "" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + AlarmDBusAdaptor(QObject *parent); + virtual ~AlarmDBusAdaptor(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + void Alarm(int aEventId); +}; + +#endif diff --git a/src/app/app.pro b/src/app/app.pro index 675cfd6..dfcd95b 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -2,7 +2,7 @@ include(../global.pri) TEMPLATE = app TARGET = fosdem-schedule DESTDIR = ../bin -QT += sql xml network +QT += sql xml network dbus # module dependencies LIBS += -L$$DESTDIR -lgui -lmvc -lsql diff --git a/src/app/main.cpp b/src/app/main.cpp index fb8042e..d52e063 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,12 +1,15 @@ #include #include -#ifdef MAEMO -#include -#endif /* MAEMO */ +//#ifdef MAEMO +//#include +//#endif /* MAEMO */ #include +#include "alarmdbus.h" +#include "alarmdbusadaptorp.h" + int main(int argc, char *argv[]) { Q_INIT_RESOURCE(icons); @@ -24,16 +27,32 @@ int main(int argc, char *argv[]) // an alarm dialog is to be displayed // Usage: $ ./fosdem eventId alarmId // Example: $ ./fosdem 521 13 - if(argc==3) - window = new AlarmDialog(argc,argv); - else if(argc==2) // display Event dialog automatically - window = new MainWindow(atoi(argv[1])); // eventId = argv[1] - else +// if(argc==3) +// window = new AlarmDialog(argc,argv); +// else if(argc==2) // display Event dialog automatically +// window = new MainWindow(atoi(argv[1])); // eventId = argv[1] +// else window = new MainWindow; #else window = new MainWindow; #endif /* MAEMO */ window->show(); + + // Alarm Dbus + + CAlarmDBus *alarmDBus = new CAlarmDBus(window); + new AlarmDBusAdaptor(alarmDBus); + //QDBusConnection connection = QDBusConnection::sessionBus(); + QDBusConnection connection = QDBusConnection::sessionBus(); + + if(connection.registerObject("/Fosdem", alarmDBus) == true) + { + if( connection.registerService("org.fosdem.schedule") == false) + { + qDebug() << "dbus register service failed"; + } + } + return a.exec(); } diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 5ce8c02..6a4cbed 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -83,8 +83,8 @@ SOURCES += roomstabcontainer.cpp \ mapwindow.cpp \ proxysettingsdialog.cpp -maemo { - FORMS += alarmdialog.ui - HEADERS += alarmdialog.h - SOURCES += alarmdialog.cpp -} +#maemo { +# FORMS += alarmdialog.ui +# HEADERS += alarmdialog.h +# SOURCES += alarmdialog.cpp +#} diff --git a/src/mvc/treeview.cpp b/src/mvc/treeview.cpp index c855aef..5fd63ee 100644 --- a/src/mvc/treeview.cpp +++ b/src/mvc/treeview.cpp @@ -32,7 +32,7 @@ void TreeView::mouseReleaseEvent(QMouseEvent *aEvent) } // returns bool if some Control was clicked -bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) +bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) { bool handled = false; @@ -68,7 +68,7 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP // have to emit 'eventHasChanged' signal on all events in conflict for(int i=0; i