From fcd77b806a8826d5f694f78c63943d0f768ef6ec Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 Jul 2014 23:35:38 -0500 Subject: refactor the Notifications / sound / awake code --- include/CMakeLists.txt | 1 + include/datetime/dbus-shared.h | 14 +--- include/datetime/snap.h | 12 ++-- include/notifications/CMakeLists.txt | 2 + include/notifications/awake.h | 55 ++++++++++++++++ include/notifications/dbus-shared.h | 32 ++++++++++ include/notifications/notifications.h | 116 ++++++++++++++++++++++++++++++++++ include/notifications/sound.h | 60 ++++++++++++++++++ 8 files changed, 274 insertions(+), 18 deletions(-) create mode 100644 include/notifications/CMakeLists.txt create mode 100644 include/notifications/awake.h create mode 100644 include/notifications/dbus-shared.h create mode 100644 include/notifications/notifications.h create mode 100644 include/notifications/sound.h (limited to 'include') diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 486e9c7..15a7c33 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(datetime) +add_subdirectory(notifications) diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h index 4b71ce5..db10c1d 100644 --- a/include/datetime/dbus-shared.h +++ b/include/datetime/dbus-shared.h @@ -18,18 +18,10 @@ * Charles Kerr */ -#ifndef _DBUS_SHARED_H_ -#define _DBUS_SHARED_H_ +#ifndef _INDICATOR_DATETIME_DBUS_SHARED_H_ +#define _INDICATOR_DATETIME_DBUS_SHARED_H_ #define BUS_DATETIME_NAME "com.canonical.indicator.datetime" #define BUS_DATETIME_PATH "/com/canonical/indicator/datetime" -#define BUS_SCREEN_NAME "com.canonical.Unity.Screen" -#define BUS_SCREEN_PATH "/com/canonical/Unity/Screen" -#define BUS_SCREEN_INTERFACE "com.canonical.Unity.Screen" - -#define BUS_POWERD_NAME "com.canonical.powerd" -#define BUS_POWERD_PATH "/com/canonical/powerd" -#define BUS_POWERD_INTERFACE "com.canonical.powerd" - -#endif /* _DBUS_SHARED_H_ */ +#endif /* _INDICATOR_DATETIME_DBUS_SHARED_H_ */ diff --git a/include/datetime/snap.h b/include/datetime/snap.h index 1c90496..78d9f65 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -21,9 +21,10 @@ #define INDICATOR_DATETIME_SNAP_H #include -#include #include +#include + #include #include #include @@ -38,7 +39,7 @@ namespace datetime { class Snap { public: - Snap(const std::shared_ptr& clock, + Snap(const std::shared_ptr& engine, const std::shared_ptr& settings); virtual ~Snap(); @@ -48,12 +49,9 @@ public: appointment_func dismiss); private: - const std::shared_ptr m_clock; + const std::shared_ptr m_engine; const std::shared_ptr m_settings; - - class Popup; - friend class Popup; - std::set m_pending; + std::set m_notifications; }; } // namespace datetime diff --git a/include/notifications/CMakeLists.txt b/include/notifications/CMakeLists.txt new file mode 100644 index 0000000..139597f --- /dev/null +++ b/include/notifications/CMakeLists.txt @@ -0,0 +1,2 @@ + + diff --git a/include/notifications/awake.h b/include/notifications/awake.h new file mode 100644 index 0000000..fd812c1 --- /dev/null +++ b/include/notifications/awake.h @@ -0,0 +1,55 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef UNITY_INDICATOR_NOTIFICATIONS_AWAKE_H +#define UNITY_INDICATOR_NOTIFICATIONS_AWAKE_H + +#include + +namespace unity { +namespace indicator { +namespace notifications { + +/*** +**** +***/ + +/** + * A class that forces the screen display on and inhibits sleep + */ +class Awake +{ +public: + Awake(const std::string& app_name); + ~Awake(); + +private: + class Impl; + std::unique_ptr impl; +}; + +/*** +**** +***/ + +} // namespace notifications +} // namespace indicator +} // namespace unity + +#endif // UNITY_INDICATOR_NOTIFICATIONS_AWAKE_H diff --git a/include/notifications/dbus-shared.h b/include/notifications/dbus-shared.h new file mode 100644 index 0000000..7738cb7 --- /dev/null +++ b/include/notifications/dbus-shared.h @@ -0,0 +1,32 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Ted Gould + * Charles Kerr + */ + +#ifndef UNITY_INDICATOR_NOTIFICATIONS_DBUS_SHARED_H +#define UNITY_INDICATOR_NOTIFICATIONS_DBUS_SHARED_H + +#define BUS_SCREEN_NAME "com.canonical.Unity.Screen" +#define BUS_SCREEN_PATH "/com/canonical/Unity/Screen" +#define BUS_SCREEN_INTERFACE "com.canonical.Unity.Screen" + +#define BUS_POWERD_NAME "com.canonical.powerd" +#define BUS_POWERD_PATH "/com/canonical/powerd" +#define BUS_POWERD_INTERFACE "com.canonical.powerd" + +#endif /* INDICATOR_NOTIFICATIONS_DBUS_SHARED_H */ diff --git a/include/notifications/notifications.h b/include/notifications/notifications.h new file mode 100644 index 0000000..b4c88b4 --- /dev/null +++ b/include/notifications/notifications.h @@ -0,0 +1,116 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef UNITY_INDICATOR_NOTIFICATIONS_NOTIFICATIONS_H +#define UNITY_INDICATOR_NOTIFICATIONS_NOTIFICATIONS_H + +#include +#include +#include +#include + +namespace unity { +namespace indicator { +namespace notifications { + +class Engine; + +/** + * Helper class for showing notifications. + * + * Populate the builder, with the relevant properites, + * then pass it to Engine::show(). + * + * @see Engine::show(Builder) + */ +class Builder +{ +public: + Builder(); + ~Builder(); + + void set_title (const std::string& title); + void set_body (const std::string& body); + void set_icon_name (const std::string& icon_name); + + /* Set an interval, after which the notification will automatically + be closed. If not set, the notification server's default timeout + is used. */ + void set_timeout (const std::chrono::seconds& duration); + + /* Add a notification hint. + These keys may be dependent on the notification server. */ + void add_hint (const std::string& name); + static constexpr char const * HINT_SNAP {"x-canonical-snap-decisions"}; + static constexpr char const * HINT_TINT {"x-canonical-private-button-tint"}; + + /* Add an action button. + This may fail if the Engine doesn't support actions. + @see Engine::supports_actions() */ + void add_action (const std::string& action, const std::string& label); + + /** Sets the closed callback. This will be called exactly once. */ + void set_closed_callback (std::function); + +private: + friend class Engine; + class Impl; + std::unique_ptr impl; +}; + +/** + * Manages Notifications and the connection to the notification server. + * + * When this class is destroyed, any remaining notifications it created + * will be closed and their closed() callbacks will be invoked. + */ +class Engine +{ +public: + Engine(const std::string& app_name); + ~Engine(); + + /** @see Builder::set_action() */ + bool supports_actions() const; + + /** Show a notification. + @return nonzero on success, zero on failure. */ + int show(const Builder& builder); + + /** Close a notification. + @param key the int returned by show() + @return true if the notification was closed. */ + bool close(int key); + + /** Close all remaining notifications. + *@return true if all closed successfully. */ + bool close_all(); + + const std::string& app_name() const; + +private: + class Impl; + std::unique_ptr impl; +}; + +} // namespace notifications +} // namespace indicator +} // namespace unity + +#endif // UNITY_INDICATOR_NOTIFICATIONS_NOTIFICATIONS_H diff --git a/include/notifications/sound.h b/include/notifications/sound.h new file mode 100644 index 0000000..f5f549c --- /dev/null +++ b/include/notifications/sound.h @@ -0,0 +1,60 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef UNITY_INDICATOR_NOTIFICATIONS_SOUND_H +#define UNITY_INDICATOR_NOTIFICATIONS_SOUND_H + +#include +#include + +namespace unity { +namespace indicator { +namespace notifications { + +/*** +**** +***/ + +/** + * Plays a sound, possibly looping. + * + * @param uri the file to play + * @param volume the volume at which to play the sound, [0..100] + * @param loop if true, loop the sound for the lifespan of the object + */ +class Sound +{ +public: + Sound(const std::string& uri, unsigned int volume, bool loop); + ~Sound(); + +private: + class Impl; + std::unique_ptr impl; +}; + +/*** +**** +***/ + +} // namespace notifications +} // namespace indicator +} // namespace unity + +#endif // UNITY_INDICATOR_NOTIFICATIONS_SOUND_H -- cgit v1.2.3 From 7271b2139a5c600a2c3cdb4e552e05ddb0f374dd Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 27 Jul 2014 10:51:54 -0500 Subject: make close return void instead of bool, because after all what more can you do if the call fails? What's the point? --- include/notifications/notifications.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/notifications/notifications.h b/include/notifications/notifications.h index b4c88b4..43442d3 100644 --- a/include/notifications/notifications.h +++ b/include/notifications/notifications.h @@ -96,11 +96,11 @@ public: /** Close a notification. @param key the int returned by show() @return true if the notification was closed. */ - bool close(int key); + void close(int key); /** Close all remaining notifications. *@return true if all closed successfully. */ - bool close_all(); + void close_all(); const std::string& app_name() const; -- cgit v1.2.3 From b0936139bfef6fe169b5c17be4b2dafa3c2e2c3a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 27 Jul 2014 11:01:30 -0500 Subject: copyediting: comments, use anonymous namespace --- include/notifications/notifications.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/notifications/notifications.h b/include/notifications/notifications.h index 43442d3..c2e2d85 100644 --- a/include/notifications/notifications.h +++ b/include/notifications/notifications.h @@ -34,8 +34,7 @@ class Engine; /** * Helper class for showing notifications. * - * Populate the builder, with the relevant properites, - * then pass it to Engine::show(). + * Populate the builder, then pass it to Engine::show(). * * @see Engine::show(Builder) */ @@ -46,7 +45,9 @@ public: ~Builder(); void set_title (const std::string& title); + void set_body (const std::string& body); + void set_icon_name (const std::string& icon_name); /* Set an interval, after which the notification will automatically -- cgit v1.2.3 From d6b290fda978379fb07285aaddfeb31686735667 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 30 Jul 2014 14:54:37 -0500 Subject: move Snap's guts into an Impl class --- include/datetime/snap.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/datetime/snap.h b/include/datetime/snap.h index 78d9f65..ef5c868 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -27,7 +27,6 @@ #include #include -#include namespace unity { namespace indicator { @@ -49,9 +48,8 @@ public: appointment_func dismiss); private: - const std::shared_ptr m_engine; - const std::shared_ptr m_settings; - std::set m_notifications; + class Impl; + std::unique_ptr impl; }; } // namespace datetime -- cgit v1.2.3 From 559d185dd7d51e56fbd8246970ef520d3edd18ae Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 30 Jul 2014 16:01:03 -0500 Subject: initial draft of haptic feedback when alarms play --- include/notifications/haptic.h | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 include/notifications/haptic.h (limited to 'include') diff --git a/include/notifications/haptic.h b/include/notifications/haptic.h new file mode 100644 index 0000000..3036485 --- /dev/null +++ b/include/notifications/haptic.h @@ -0,0 +1,57 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef UNITY_INDICATOR_NOTIFICATIONS_HAPTIC_H +#define UNITY_INDICATOR_NOTIFICATIONS_HAPTIC_H + +#include + +namespace unity { +namespace indicator { +namespace notifications { + +/*** +**** +***/ + +/** + * A class that forces the screen display on and inhibits sleep + */ +class Haptic +{ +public: + enum Mode { VIBRATE_DEFAULT }; + + Haptic(const Mode& mode = VIBRATE_DEFAULT); + ~Haptic(); + +private: + class Impl; + std::unique_ptr impl; +}; + +/*** +**** +***/ + +} // namespace notifications +} // namespace indicator +} // namespace unity + +#endif // UNITY_INDICATOR_NOTIFICATIONS_HAPTIC_H -- cgit v1.2.3 From 5d6108ee4440881b08b419a1c454b1db57e1d6ce Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 30 Jul 2014 17:03:08 -0500 Subject: fix doxygen comments --- include/notifications/notifications.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/notifications/notifications.h b/include/notifications/notifications.h index c2e2d85..d876a57 100644 --- a/include/notifications/notifications.h +++ b/include/notifications/notifications.h @@ -91,16 +91,14 @@ public: bool supports_actions() const; /** Show a notification. - @return nonzero on success, zero on failure. */ + @return zero on failure, or a key that can be passed to close() */ int show(const Builder& builder); /** Close a notification. - @param key the int returned by show() - @return true if the notification was closed. */ + @param key the int returned by show() */ void close(int key); - /** Close all remaining notifications. - *@return true if all closed successfully. */ + /** Close all remaining notifications. */ void close_all(); const std::string& app_name() const; -- cgit v1.2.3 From 9d32289feda6d72e53bcf7e77e2cbef09f88165e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 10:33:14 -0500 Subject: in indicator::noficiations::Haptic, better naming of the Mode enum --- include/notifications/haptic.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/notifications/haptic.h b/include/notifications/haptic.h index 3036485..d82d1c9 100644 --- a/include/notifications/haptic.h +++ b/include/notifications/haptic.h @@ -36,9 +36,12 @@ namespace notifications { class Haptic { public: - enum Mode { VIBRATE_DEFAULT }; + enum Mode + { + MODE_PULSE + }; - Haptic(const Mode& mode = VIBRATE_DEFAULT); + Haptic(const Mode& mode = MODE_PULSE); ~Haptic(); private: -- cgit v1.2.3 From af1b645de9b8116ead5ad72583f51afe28350818 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 15:22:47 -0500 Subject: drop the ubuntu-application-api middleman and call usensorsd directly: ua_sensors_haptic_new() crashes on desktop and ua_sensors_haptic_vibrate_once() makes blocking dbus calls. --- include/notifications/dbus-shared.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/notifications/dbus-shared.h b/include/notifications/dbus-shared.h index 7738cb7..af714e7 100644 --- a/include/notifications/dbus-shared.h +++ b/include/notifications/dbus-shared.h @@ -29,4 +29,8 @@ #define BUS_POWERD_PATH "/com/canonical/powerd" #define BUS_POWERD_INTERFACE "com.canonical.powerd" +#define BUS_HAPTIC_NAME "com.canonical.usensord" +#define BUS_HAPTIC_PATH "/com/canonical/usensord/haptic" +#define BUS_HAPTIC_INTERFACE "com.canonical.usensord.haptic" + #endif /* INDICATOR_NOTIFICATIONS_DBUS_SHARED_H */ -- cgit v1.2.3 From 4148750ea93e67e5d9aaa15ebc8e3c7a5a5554f1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 16:48:00 -0500 Subject: configurable haptic mode, part 1 of 3: add haptic feedback mode to the GSettings schema and to our Settings object --- include/datetime/settings-live.h | 1 + include/datetime/settings-shared.h | 1 + include/datetime/settings.h | 1 + 3 files changed, 3 insertions(+) (limited to 'include') diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 4db2d40..4850e69 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -58,6 +58,7 @@ private: void update_alarm_sound(); void update_alarm_volume(); void update_alarm_duration(); + void update_alarm_haptic(); GSettings* m_settings; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index 23d2e1c..a211821 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -48,5 +48,6 @@ TimeFormatMode; #define SETTINGS_ALARM_SOUND_S "alarm-default-sound" #define SETTINGS_ALARM_VOLUME_S "alarm-default-volume" #define SETTINGS_ALARM_DURATION_S "alarm-duration-minutes" +#define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" #endif // INDICATOR_DATETIME_SETTINGS_SHARED diff --git a/include/datetime/settings.h b/include/datetime/settings.h index e5f885e..c6fe13b 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -57,6 +57,7 @@ public: core::Property time_format_mode; core::Property timezone_name; core::Property alarm_sound; + core::Property alarm_haptic; core::Property alarm_volume; core::Property alarm_duration; }; -- cgit v1.2.3 From d129112ad9ce04fad979af95b5b5cd4fd87f5b2b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 19:52:42 -0500 Subject: in Haptic, make the looping logic easier to read. --- include/notifications/haptic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/notifications/haptic.h b/include/notifications/haptic.h index d82d1c9..bfb5679 100644 --- a/include/notifications/haptic.h +++ b/include/notifications/haptic.h @@ -31,7 +31,7 @@ namespace notifications { ***/ /** - * A class that forces the screen display on and inhibits sleep + * Tries to emit haptic feedback to match the user-specified mode. */ class Haptic { -- cgit v1.2.3 From 6da58726eb18e7205845ec1af4cb43d08d988e31 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 1 Aug 2014 11:42:43 -0500 Subject: refactor changes based on Antti's feedback --- include/notifications/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/notifications/CMakeLists.txt b/include/notifications/CMakeLists.txt index 139597f..e69de29 100644 --- a/include/notifications/CMakeLists.txt +++ b/include/notifications/CMakeLists.txt @@ -1,2 +0,0 @@ - - -- cgit v1.2.3