aboutsummaryrefslogtreecommitdiff
path: root/include/notifications/notifications.h
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-26 23:35:38 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-07-26 23:35:38 -0500
commitfcd77b806a8826d5f694f78c63943d0f768ef6ec (patch)
tree22738c06ae6599e729ad386bc3126772dda13299 /include/notifications/notifications.h
parenta7e8b219e8a9301249301cff6fbe989670d4e312 (diff)
downloadayatana-indicator-datetime-fcd77b806a8826d5f694f78c63943d0f768ef6ec.tar.gz
ayatana-indicator-datetime-fcd77b806a8826d5f694f78c63943d0f768ef6ec.tar.bz2
ayatana-indicator-datetime-fcd77b806a8826d5f694f78c63943d0f768ef6ec.zip
refactor the Notifications / sound / awake code
Diffstat (limited to 'include/notifications/notifications.h')
-rw-r--r--include/notifications/notifications.h116
1 files changed, 116 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef UNITY_INDICATOR_NOTIFICATIONS_NOTIFICATIONS_H
+#define UNITY_INDICATOR_NOTIFICATIONS_NOTIFICATIONS_H
+
+#include <chrono>
+#include <functional>
+#include <memory>
+#include <string>
+
+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<void(const std::string& action)>);
+
+private:
+ friend class Engine;
+ class Impl;
+ std::unique_ptr<Impl> 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> impl;
+};
+
+} // namespace notifications
+} // namespace indicator
+} // namespace unity
+
+#endif // UNITY_INDICATOR_NOTIFICATIONS_NOTIFICATIONS_H