aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt31
-rw-r--r--src/exporter.cpp115
-rw-r--r--src/main.cpp2
3 files changed, 134 insertions, 14 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ffa1523..af09c71 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,13 +1,13 @@
set (SERVICE_LIB "indicatordatetimeservice")
set (SERVICE_EXEC "indicator-datetime-service")
-SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g ${CXX_WARNING_ARGS} ${GCOV_FLAGS}")
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g ${CXX_WARNING_ARGS} ${GCOV_FLAGS}")
-
add_definitions (-DTIMEZONE_FILE="/etc/timezone"
-DG_LOG_DOMAIN="Indicator-Datetime")
-set (SERVICE_SOURCES
+# handwritten sources
+set (SERVICE_C_SOURCES
+ utils.c)
+set (SERVICE_CXX_SOURCES
actions.cpp
actions-live.cpp
alarm-queue-simple.cpp
@@ -32,16 +32,33 @@ set (SERVICE_SOURCES
timezones-live.cpp
utils.c
wakeup-timer-mainloop.cpp)
-
if (HAVE_UBUNTU_HW_ALARM_H)
- set (SERVICE_SOURCES ${SERVICE_SOURCES} wakeup-timer-uha.cpp)
+ set (SERVICE_CXX_SOURCES ${SERVICE_CXX_SOURCES} wakeup-timer-uha.cpp)
endif ()
-add_library (${SERVICE_LIB} STATIC ${SERVICE_SOURCES})
+# generated sources
+include (GdbusCodegen)
+set(SERVICE_GENERATED_SOURCES)
+add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-alarm-properties
+ com.canonical.indicator
+ ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.AlarmProperties.xml)
+
+# add warnings/coverage info on handwritten files
+# but not the autogenerated ones...
+set_source_files_properties(${SERVICE_CXX_SOURCES}
+ PROPERTIES COMPILE_FLAGS "${CXX_WARNING_ARGS} ${GCOV_FLAGS} -g -std=c++11")
+set_source_files_properties(${SERVICE_C_SOURCES}
+ PROPERTIES COMPILE_FLAGS "${CXX_WARNING_ARGS} ${GCOV_FLAGS} -g -std=c99")
+
+# add the bin dir to our include path so our code can find the generated header files
+include_directories (${CMAKE_CURRENT_BINARY_DIR})
+
+add_library (${SERVICE_LIB} STATIC ${SERVICE_C_SOURCES} ${SERVICE_CXX_SOURCES} ${SERVICE_GENERATED_SOURCES})
include_directories (${CMAKE_SOURCE_DIR})
link_directories (${SERVICE_DEPS_LIBRARY_DIRS})
add_executable (${SERVICE_EXEC} main.cpp)
+set_source_files_properties(${SERVICE_SOURCES} main.cpp PROPERTIES COMPILE_FLAGS "${CXX_WARNING_ARGS} -g -std=c++11")
target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${GCOV_LIBS})
install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR})
diff --git a/src/exporter.cpp b/src/exporter.cpp
index a4919e9..3ba95bf 100644
--- a/src/exporter.cpp
+++ b/src/exporter.cpp
@@ -20,6 +20,8 @@
#include <datetime/dbus-shared.h>
#include <datetime/exporter.h>
+#include "dbus-alarm-properties.h"
+
#include <glib/gi18n.h>
#include <gio/gio.h>
@@ -35,9 +37,11 @@ class Exporter::Impl
{
public:
- Impl (Exporter* owner):
- m_owner(owner)
+ Impl(const std::shared_ptr<Settings>& settings):
+ m_settings(settings),
+ m_alarm_props(datetime_alarm_properties_skeleton_new())
{
+ alarm_properties_init();
}
~Impl()
@@ -51,6 +55,9 @@ public:
g_dbus_connection_unexport_action_group(m_bus, m_exported_actions_id);
}
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(m_alarm_props));
+ g_clear_object(&m_alarm_props);
+
if (m_own_id)
g_bus_unown_name(m_own_id);
@@ -76,6 +83,95 @@ public:
private:
+ /***
+ ****
+ ***/
+
+ static void
+ on_gobject_notify_string(GObject* o, GParamSpec* pspec, gpointer p)
+ {
+ gchar* val = nullptr;
+ g_object_get (o, pspec->name, &val, nullptr);
+ static_cast<core::Property<std::string>*>(p)->set(val);
+ g_free(val);
+ }
+ void bind_string_property(gpointer o, const char* propname,
+ core::Property<std::string>& p)
+ {
+ // initialize the GObject property from the Settings
+ g_object_set(o, propname, p.get().c_str(), nullptr);
+
+ // when the GObject changes, update the Settings
+ const std::string notify_propname = std::string("notify::") + propname;
+ g_signal_connect(o, notify_propname.c_str(),
+ G_CALLBACK(on_gobject_notify_string), &p);
+
+ // when the Settings changes, update the GObject
+ p.changed().connect([o, propname](const std::string& s){
+ g_object_set(o, propname, s.c_str(), nullptr);
+ });
+ }
+
+
+ static void
+ on_gobject_notify_int(GObject* o, GParamSpec* pspec, gpointer p)
+ {
+ int val = 0;
+ g_object_get (o, pspec->name, &val, nullptr);
+ static_cast<core::Property<int>*>(p)->set(val);
+ }
+ void bind_int_property(gpointer o, const char* propname, core::Property<int>& p)
+ {
+ // initialize the GObject property from the Settings
+ g_object_set(o, propname, p.get(), nullptr);
+
+ // when the GObject changes, update the Settings
+ const std::string notify_propname = std::string("notify::") + propname;
+ g_signal_connect(o, notify_propname.c_str(),
+ G_CALLBACK(on_gobject_notify_int), &p);
+
+ // when the Settings changes, update the GObject
+ p.changed().connect([o, propname](int i){
+ g_object_set(o, propname, i, nullptr);
+ });
+ }
+
+
+ static void
+ on_gobject_notify_volume(GObject* o, GParamSpec* pspec, gpointer p)
+ {
+ int val = 0;
+ g_object_get (o, pspec->name, &val, nullptr);
+ static_cast<core::Property<AlarmVolume>*>(p)->set(AlarmVolume(val));
+ }
+ void bind_volume_property(gpointer o, const char* propname, core::Property<AlarmVolume>& p)
+ {
+ // initialize the GObject property from the Settings
+ g_object_set(o, propname, (int)p.get(), nullptr);
+
+ // when the GObject changes, update the Settings
+ const std::string notify_propname = std::string("notify::") + propname;
+ g_signal_connect(o, notify_propname.c_str(),
+ G_CALLBACK(on_gobject_notify_volume), &p);
+
+ // when the Settings changes, update the GObject
+ p.changed().connect([o, propname](AlarmVolume i){
+ g_object_set(o, propname, (int)i, nullptr);
+ });
+ }
+
+
+ void alarm_properties_init()
+ {
+ bind_int_property(m_alarm_props, "duration", m_settings->alarm_duration);
+ bind_volume_property(m_alarm_props, "default-volume", m_settings->alarm_volume);
+ bind_string_property(m_alarm_props, "default-sound", m_settings->alarm_sound);
+ }
+
+ /***
+ ****
+ ***/
+
static void on_bus_acquired(GDBusConnection* connection,
const gchar* name,
gpointer gthis)
@@ -88,8 +184,14 @@ private:
{
m_bus = static_cast<GDBusConnection*>(g_object_ref(G_OBJECT(bus)));
- // export the actions
+ // export the alarm properties
GError * error = nullptr;
+ g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(m_alarm_props),
+ m_bus,
+ BUS_PATH"/AlarmProperties",
+ &error);
+
+ // export the actions
const auto id = g_dbus_connection_export_action_group(m_bus,
BUS_PATH,
m_actions->action_group(),
@@ -136,13 +238,14 @@ private:
****
***/
- Exporter const * m_owner;
+ std::shared_ptr<Settings> m_settings;
std::set<guint> m_exported_menu_ids;
guint m_own_id = 0;
guint m_exported_actions_id = 0;
GDBusConnection* m_bus = nullptr;
std::shared_ptr<Actions> m_actions;
std::vector<std::shared_ptr<Menu>> m_menus;
+ DatetimeAlarmProperties* m_alarm_props = nullptr;
};
@@ -150,8 +253,8 @@ private:
****
***/
-Exporter::Exporter():
- p(new Impl(this))
+Exporter::Exporter(const std::shared_ptr<Settings>& settings):
+ p(new Impl(settings))
{
}
diff --git a/src/main.cpp b/src/main.cpp
index 04845ce..cc81cd7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -163,7 +163,7 @@ main(int /*argc*/, char** /*argv*/)
// export them & run until we lose the busname
auto loop = g_main_loop_new(nullptr, false);
- Exporter exporter;
+ Exporter exporter(state->settings);
exporter.name_lost().connect([loop](){
g_message("%s exiting; failed/lost bus ownership", GETTEXT_PACKAGE);
g_main_loop_quit(loop);