From da980e33f340734c91950d244b980c7d8b5eef95 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Jun 2014 15:55:17 -0500 Subject: Add Exporter's implementation to an Impl file because I'm about to shovel more methods and fields in there. --- src/exporter.cpp | 170 +++++++++++++++++++++++++++++++++---------------------- src/main.cpp | 2 +- 2 files changed, 104 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/exporter.cpp b/src/exporter.cpp index ccd6e5c..a4919e9 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -31,108 +31,144 @@ namespace datetime { **** ***/ -Exporter::~Exporter() +class Exporter::Impl { - if (m_dbus_connection != nullptr) - { - for(auto& id : m_exported_menu_ids) - g_dbus_connection_unexport_menu_model(m_dbus_connection, id); +public: - if (m_exported_actions_id) - g_dbus_connection_unexport_action_group(m_dbus_connection, m_exported_actions_id); + Impl (Exporter* owner): + m_owner(owner) + { } - if (m_own_id) - g_bus_unown_name(m_own_id); + ~Impl() + { + if (m_bus != nullptr) + { + for(auto& id : m_exported_menu_ids) + g_dbus_connection_unexport_menu_model(m_bus, id); - g_clear_object(&m_dbus_connection); -} + if (m_exported_actions_id) + g_dbus_connection_unexport_action_group(m_bus, m_exported_actions_id); + } -/*** -**** -***/ + if (m_own_id) + g_bus_unown_name(m_own_id); -void -Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* name, gpointer gthis) -{ - g_debug("bus acquired: %s", name); - static_cast(gthis)->on_bus_acquired(connection, name); -} + g_clear_object(&m_bus); + } -void -Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* /*name*/) -{ - m_dbus_connection = static_cast(g_object_ref(G_OBJECT(connection))); - - // export the actions - GError * error = nullptr; - const auto id = g_dbus_connection_export_action_group(m_dbus_connection, - BUS_PATH, - m_actions->action_group(), - &error); - if (id) + core::Signal<> name_lost; + + void publish(const std::shared_ptr& actions, + const std::vector>& menus) { - m_exported_actions_id = id; + m_actions = actions; + m_menus = menus; + m_own_id = g_bus_own_name(G_BUS_TYPE_SESSION, + BUS_NAME, + G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, + on_bus_acquired, + nullptr, + on_name_lost, + this, + nullptr); } - else + +private: + + static void on_bus_acquired(GDBusConnection* connection, + const gchar* name, + gpointer gthis) { - g_warning("cannot export action group: %s", error->message); - g_clear_error(&error); + g_debug("bus acquired: %s", name); + static_cast(gthis)->on_bus_acquired(connection, name); } - // export the menus - for(auto& menu : m_menus) + void on_bus_acquired(GDBusConnection* bus, const gchar* /*name*/) { - const auto path = std::string(BUS_PATH) + "/" + menu->name(); - const auto id = g_dbus_connection_export_menu_model(m_dbus_connection, path.c_str(), menu->menu_model(), &error); + m_bus = static_cast(g_object_ref(G_OBJECT(bus))); + + // export the actions + GError * error = nullptr; + const auto id = g_dbus_connection_export_action_group(m_bus, + BUS_PATH, + m_actions->action_group(), + &error); if (id) { - m_exported_menu_ids.insert(id); + m_exported_actions_id = id; } else { - if (error != nullptr) - g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); + g_warning("cannot export action group: %s", error->message); g_clear_error(&error); } + + // export the menus + for(auto& menu : m_menus) + { + const auto path = std::string(BUS_PATH) + "/" + menu->name(); + const auto id = g_dbus_connection_export_menu_model(m_bus, path.c_str(), menu->menu_model(), &error); + if (id) + { + m_exported_menu_ids.insert(id); + } + else + { + if (error != nullptr) + g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); + g_clear_error(&error); + } + } } -} + + /*** + **** + ***/ + + static void on_name_lost(GDBusConnection*, const gchar* name, gpointer gthis) + { + g_debug("name lost: %s", name); + static_cast(gthis)->name_lost(); + } + + /*** + **** + ***/ + + Exporter const * m_owner; + std::set m_exported_menu_ids; + guint m_own_id = 0; + guint m_exported_actions_id = 0; + GDBusConnection* m_bus = nullptr; + std::shared_ptr m_actions; + std::vector> m_menus; +}; + /*** **** ***/ -void -Exporter::on_name_lost(GDBusConnection* connection, const gchar* name, gpointer gthis) +Exporter::Exporter(): + p(new Impl(this)) { - g_debug("name lost: %s", name); - static_cast(gthis)->on_name_lost(connection, name); } -void -Exporter::on_name_lost(GDBusConnection* /*connection*/, const gchar* /*name*/) + +Exporter::~Exporter() { - name_lost(); } -/*** -**** -***/ +core::Signal<>& Exporter::name_lost() +{ + return p->name_lost; +} -void -Exporter::publish(const std::shared_ptr& actions, - const std::vector>& menus) +void Exporter::publish(const std::shared_ptr& actions, + const std::vector>& menus) { - m_actions = actions; - m_menus = menus; - m_own_id = g_bus_own_name(G_BUS_TYPE_SESSION, - BUS_NAME, - G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, - on_bus_acquired, - nullptr, - on_name_lost, - this, - nullptr); + p->publish(actions, menus); } /*** diff --git a/src/main.cpp b/src/main.cpp index 1940eb6..04845ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -164,7 +164,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.name_lost.connect([loop](){ + exporter.name_lost().connect([loop](){ g_message("%s exiting; failed/lost bus ownership", GETTEXT_PACKAGE); g_main_loop_quit(loop); }); -- cgit v1.2.3 From 90debef5ca85c6a51cf85d6f6b9d402ff5077b0b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Jun 2014 20:46:06 -0500 Subject: fix clang++ warning about an unused private field in EdsEngine --- src/engine-eds.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 80a47da..58be0c4 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -41,8 +41,7 @@ class EdsEngine::Impl { public: - Impl(EdsEngine& owner): - m_owner(owner), + Impl(): m_cancellable(g_cancellable_new()) { e_source_registry_new(m_cancellable, on_source_registry_ready, this); @@ -492,7 +491,6 @@ private: return G_SOURCE_CONTINUE; } - EdsEngine& m_owner; core::Signal<> m_changed; std::set m_sources; std::map m_clients; @@ -508,7 +506,7 @@ private: ***/ EdsEngine::EdsEngine(): - p(new Impl(*this)) + p(new Impl()) { } -- cgit v1.2.3 From dda9044eb9740ca995139711cd8318815bf88e2a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Jun 2014 20:47:52 -0500 Subject: fix clang++ warning about unused private field in snap.cpp's Sound class --- src/snap.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 25632e9..4a19d6e 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -60,7 +60,6 @@ public: m_clock(clock), m_filename(filename), m_volume(volume), - m_duration_minutes(duration_minutes), m_loop(loop), m_canberra_id(get_next_canberra_id()), m_loop_end_time(clock->localtime().add_full(0, 0, 0, 0, duration_minutes, 0.0)) @@ -184,7 +183,6 @@ private: const std::shared_ptr m_clock; const std::string m_filename; const AlarmVolume m_volume; - const int m_duration_minutes; const bool m_loop; const int32_t m_canberra_id; const DateTime m_loop_end_time; -- cgit v1.2.3 From c5081444f4f493dc386012bcb99d2430fe26dc5a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Jun 2014 21:36:42 -0500 Subject: Expose the alarm settings via dbus properties. --- src/CMakeLists.txt | 31 +++++++++++---- src/exporter.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/main.cpp | 2 +- 3 files changed, 134 insertions(+), 14 deletions(-) (limited to 'src') 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 #include +#include "dbus-alarm-properties.h" + #include #include @@ -35,9 +37,11 @@ class Exporter::Impl { public: - Impl (Exporter* owner): - m_owner(owner) + Impl(const std::shared_ptr& 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*>(p)->set(val); + g_free(val); + } + void bind_string_property(gpointer o, const char* propname, + core::Property& 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*>(p)->set(val); + } + void bind_int_property(gpointer o, const char* propname, core::Property& 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*>(p)->set(AlarmVolume(val)); + } + void bind_volume_property(gpointer o, const char* propname, core::Property& 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(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 m_settings; std::set m_exported_menu_ids; guint m_own_id = 0; guint m_exported_actions_id = 0; GDBusConnection* m_bus = nullptr; std::shared_ptr m_actions; std::vector> 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): + 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); -- cgit v1.2.3 From 8bb09ca0225886c18e351d3c6156521ed479edd1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 26 Jun 2014 22:13:13 -0500 Subject: Design prefers to have a volume slider instead of presets, so remove the AlarmVolume enum and replace it with an int range. --- src/exporter.cpp | 26 +------------------------- src/settings-live.cpp | 6 +++--- src/snap.cpp | 29 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/exporter.cpp b/src/exporter.cpp index 3ba95bf..a5a059d 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -137,34 +137,10 @@ private: } - 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*>(p)->set(AlarmVolume(val)); - } - void bind_volume_property(gpointer o, const char* propname, core::Property& 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_int_property(m_alarm_props, "default-volume", m_settings->alarm_volume); bind_string_property(m_alarm_props, "default-sound", m_settings->alarm_sound); } diff --git a/src/settings-live.cpp b/src/settings-live.cpp index e34ace1..369d2d6 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -123,8 +123,8 @@ LiveSettings::LiveSettings(): g_settings_set_string(m_settings, SETTINGS_ALARM_SOUND_S, value.c_str()); }); - alarm_volume.changed().connect([this](AlarmVolume value){ - g_settings_set_enum(m_settings, SETTINGS_ALARM_VOLUME_S, gint(value)); + alarm_volume.changed().connect([this](int value){ + g_settings_set_int(m_settings, SETTINGS_ALARM_VOLUME_S, value); }); alarm_duration.changed().connect([this](int value){ @@ -229,7 +229,7 @@ void LiveSettings::update_alarm_sound() void LiveSettings::update_alarm_volume() { - alarm_volume.set((AlarmVolume)g_settings_get_enum(m_settings, SETTINGS_ALARM_VOLUME_S)); + alarm_volume.set(g_settings_get_int(m_settings, SETTINGS_ALARM_VOLUME_S)); } void LiveSettings::update_alarm_duration() diff --git a/src/snap.cpp b/src/snap.cpp index 4a19d6e..40fd541 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -54,7 +54,7 @@ public: Sound(const std::shared_ptr& clock, const std::string& filename, - AlarmVolume volume, + int volume, int duration_minutes, bool loop): m_clock(clock), @@ -132,18 +132,17 @@ private: g_clear_pointer(&props, ca_proplist_destroy); } - static float get_gain_level(const AlarmVolume volume) + static float get_gain_level(int volume) { - /* These values aren't set in stone -- - arrived at from from manual tests on Nexus 4 */ - switch (volume) - { - case ALARM_VOLUME_VERY_QUIET: return -8; - case ALARM_VOLUME_QUIET: return -4; - case ALARM_VOLUME_LOUD: return 4; - case ALARM_VOLUME_VERY_LOUD: return 8; - default: return 0; - } + const int clamped_volume = CLAMP(volume, 1, 100); + + /* This range isn't set in stone -- + arrived at from manual tests on Nextus 4 */ + constexpr float gain_low = -10; + constexpr float gain_high = 10; + + constexpr float gain_range = gain_high - gain_low; + return gain_low + (gain_range * (clamped_volume / 100.0f)); } static void on_done_playing(ca_context*, uint32_t, int rv, void* gself) @@ -182,7 +181,7 @@ private: const std::shared_ptr m_clock; const std::string m_filename; - const AlarmVolume m_volume; + const int m_volume; const bool m_loop; const int32_t m_canberra_id; const DateTime m_loop_end_time; @@ -195,7 +194,7 @@ class SoundBuilder public: void set_clock(const std::shared_ptr& c) {m_clock = c;} void set_filename(const std::string& s) {m_filename = s;} - void set_volume(const AlarmVolume v) {m_volume = v;} + void set_volume(const int v) {m_volume = v;} void set_duration_minutes(int i) {m_duration_minutes=i;} void set_looping(bool b) {m_looping=b;} @@ -210,7 +209,7 @@ public: private: std::shared_ptr m_clock; std::string m_filename; - AlarmVolume m_volume = ALARM_VOLUME_NORMAL; + int m_volume = 50; int m_duration_minutes = 30; bool m_looping = true; }; -- cgit v1.2.3 From eebf8f911cedf5124ada2f91576f821da6f421b0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 27 Jun 2014 09:46:21 -0500 Subject: use unsigned ints for the alarm volume, duration properties --- src/exporter.cpp | 24 +++++++++++++----------- src/settings-live.cpp | 12 ++++++------ src/snap.cpp | 18 +++++++++--------- 3 files changed, 28 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/exporter.cpp b/src/exporter.cpp index a5a059d..e2b60f2 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -107,20 +107,22 @@ private: 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); + p.changed().connect([o, propname](const std::string& val){ + g_object_set(o, propname, val.c_str(), nullptr); }); } static void - on_gobject_notify_int(GObject* o, GParamSpec* pspec, gpointer p) + on_gobject_notify_uint(GObject* o, GParamSpec* pspec, gpointer p) { - int val = 0; + uint val = 0; g_object_get (o, pspec->name, &val, nullptr); - static_cast*>(p)->set(val); + static_cast*>(p)->set(val); } - void bind_int_property(gpointer o, const char* propname, core::Property& p) + void bind_uint_property(gpointer o, + const char* propname, + core::Property& p) { // initialize the GObject property from the Settings g_object_set(o, propname, p.get(), nullptr); @@ -128,19 +130,19 @@ private: // 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); + G_CALLBACK(on_gobject_notify_uint), &p); // when the Settings changes, update the GObject - p.changed().connect([o, propname](int i){ - g_object_set(o, propname, i, nullptr); + p.changed().connect([o, propname](unsigned int val){ + g_object_set(o, propname, val, nullptr); }); } void alarm_properties_init() { - bind_int_property(m_alarm_props, "duration", m_settings->alarm_duration); - bind_int_property(m_alarm_props, "default-volume", m_settings->alarm_volume); + bind_uint_property(m_alarm_props, "duration", m_settings->alarm_duration); + bind_uint_property(m_alarm_props, "default-volume", m_settings->alarm_volume); bind_string_property(m_alarm_props, "default-sound", m_settings->alarm_sound); } diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 369d2d6..71bbd96 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -123,12 +123,12 @@ LiveSettings::LiveSettings(): g_settings_set_string(m_settings, SETTINGS_ALARM_SOUND_S, value.c_str()); }); - alarm_volume.changed().connect([this](int value){ - g_settings_set_int(m_settings, SETTINGS_ALARM_VOLUME_S, value); + alarm_volume.changed().connect([this](unsigned int value){ + g_settings_set_uint(m_settings, SETTINGS_ALARM_VOLUME_S, value); }); - alarm_duration.changed().connect([this](int value){ - g_settings_set_int(m_settings, SETTINGS_ALARM_DURATION_S, value); + alarm_duration.changed().connect([this](unsigned int value){ + g_settings_set_uint(m_settings, SETTINGS_ALARM_DURATION_S, value); }); } @@ -229,12 +229,12 @@ void LiveSettings::update_alarm_sound() void LiveSettings::update_alarm_volume() { - alarm_volume.set(g_settings_get_int(m_settings, SETTINGS_ALARM_VOLUME_S)); + alarm_volume.set(g_settings_get_uint(m_settings, SETTINGS_ALARM_VOLUME_S)); } void LiveSettings::update_alarm_duration() { - alarm_duration.set(g_settings_get_int(m_settings, SETTINGS_ALARM_DURATION_S)); + alarm_duration.set(g_settings_get_uint(m_settings, SETTINGS_ALARM_DURATION_S)); } /*** diff --git a/src/snap.cpp b/src/snap.cpp index 40fd541..eab7001 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -54,8 +54,8 @@ public: Sound(const std::shared_ptr& clock, const std::string& filename, - int volume, - int duration_minutes, + unsigned int volume, + unsigned int duration_minutes, bool loop): m_clock(clock), m_filename(filename), @@ -132,9 +132,9 @@ private: g_clear_pointer(&props, ca_proplist_destroy); } - static float get_gain_level(int volume) + static float get_gain_level(unsigned int volume) { - const int clamped_volume = CLAMP(volume, 1, 100); + const unsigned int clamped_volume = CLAMP(volume, 1, 100); /* This range isn't set in stone -- arrived at from manual tests on Nextus 4 */ @@ -181,7 +181,7 @@ private: const std::shared_ptr m_clock; const std::string m_filename; - const int m_volume; + const unsigned int m_volume; const bool m_loop; const int32_t m_canberra_id; const DateTime m_loop_end_time; @@ -194,8 +194,8 @@ class SoundBuilder public: void set_clock(const std::shared_ptr& c) {m_clock = c;} void set_filename(const std::string& s) {m_filename = s;} - void set_volume(const int v) {m_volume = v;} - void set_duration_minutes(int i) {m_duration_minutes=i;} + void set_volume(const unsigned int v) {m_volume = v;} + void set_duration_minutes(int unsigned i) {m_duration_minutes=i;} void set_looping(bool b) {m_looping=b;} Sound* operator()() { @@ -209,8 +209,8 @@ public: private: std::shared_ptr m_clock; std::string m_filename; - int m_volume = 50; - int m_duration_minutes = 30; + unsigned int m_volume = 50; + unsigned int m_duration_minutes = 30; bool m_looping = true; }; -- cgit v1.2.3