From f0fee18c0baf7ef0fb27351db716ee3708c021c6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 00:41:16 -0600 Subject: copyediting: rename Service as Exporter & tweak comments --- include/datetime/exporter.h | 74 +++++++++++++++++++++++ include/datetime/service.h | 72 ---------------------- src/exporter.cpp | 144 ++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 6 +- src/planner-eds.cpp | 2 +- src/service.cpp | 140 ------------------------------------------ 6 files changed, 222 insertions(+), 216 deletions(-) create mode 100644 include/datetime/exporter.h delete mode 100644 include/datetime/service.h create mode 100644 src/exporter.cpp delete mode 100644 src/service.cpp diff --git a/include/datetime/exporter.h b/include/datetime/exporter.h new file mode 100644 index 0000000..a32b941 --- /dev/null +++ b/include/datetime/exporter.h @@ -0,0 +1,74 @@ +/* + * 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: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_EXPORTER_H +#define INDICATOR_DATETIME_EXPORTER_H + +#include +#include + +#include + +#include // GActionGroup + +#include // std::shared_ptr +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Exports actions and menus to DBus. + */ +class Exporter +{ +public: + Exporter() =default; + ~Exporter(); + + core::Signal<> name_lost; + + void publish(std::shared_ptr& actions, + std::vector>& menus); + +private: + static void on_bus_acquired(GDBusConnection*, const gchar *name, gpointer gthis); + void on_bus_acquired(GDBusConnection*, const gchar *name); + + static void on_name_lost(GDBusConnection*, const gchar *name, gpointer gthis); + void on_name_lost(GDBusConnection*, const gchar *name); + + std::set m_exported_menu_ids; + guint m_own_id = 0; + guint m_exported_actions_id = 0; + GDBusConnection * m_dbus_connection = nullptr; + std::shared_ptr m_actions; + std::vector> m_menus; + + // we've got raw pointers and gsignal tags in here, so disable copying + Exporter(const Exporter&) =delete; + Exporter& operator=(const Exporter&) =delete; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_EXPORTER_H diff --git a/include/datetime/service.h b/include/datetime/service.h deleted file mode 100644 index c7171b7..0000000 --- a/include/datetime/service.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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: - * Charles Kerr - */ - -#ifndef INDICATOR_DATETIME_EXPORTER_H -#define INDICATOR_DATETIME_EXPORTER_H - -#include - -#include - -#include // GActionGroup - -#include // std::shared_ptr -#include - -namespace unity { -namespace indicator { -namespace datetime { - -/** - * \brief Exports actions and menus to DBus. - */ -class Service -{ -public: - Service() =default; - ~Service(); - - core::Signal<> name_lost; - - void publish (GActionGroup* actions, std::vector>& menus); - -private: - static void on_bus_acquired(GDBusConnection*, const gchar *name, gpointer gthis); - void on_bus_acquired(GDBusConnection*, const gchar *name); - - static void on_name_lost(GDBusConnection*, const gchar *name, gpointer gthis); - void on_name_lost(GDBusConnection*, const gchar *name); - - std::set m_exported_menu_ids; - guint m_own_id = 0; - guint m_exported_actions_id = 0; - GDBusConnection * m_dbus_connection = nullptr; - GActionGroup* m_actions = nullptr; - std::vector> m_menus; - - // we've got raw pointers and gsignal tags in here, so disable copying - Service(const Service&) =delete; - Service& operator=(const Service&) =delete; -}; - -} // namespace datetime -} // namespace indicator -} // namespace unity - -#endif // INDICATOR_DATETIME_EXPORTER_H diff --git a/src/exporter.cpp b/src/exporter.cpp new file mode 100644 index 0000000..aa021f3 --- /dev/null +++ b/src/exporter.cpp @@ -0,0 +1,144 @@ +/* + * 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: + * Charles Kerr + */ + +#include +#include + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +Exporter::~Exporter() +{ + if (m_dbus_connection != nullptr) + { + for(auto& id : m_exported_menu_ids) + g_dbus_connection_unexport_menu_model(m_dbus_connection, id); + + if (m_exported_actions_id) + g_dbus_connection_unexport_action_group(m_dbus_connection, m_exported_actions_id); + } + + if (m_own_id) + g_bus_unown_name(m_own_id); + + g_clear_object(&m_dbus_connection); +} + +/*** +**** +***/ + +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); +} + +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) + { + m_exported_actions_id = id; + } + else + { + 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_dbus_connection, path.c_str(), menu->menu_model(), &error); + if (id) + { + m_exported_menu_ids.insert(id); + } + else + { + g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); + g_clear_error(&error); + } + } +} + +/*** +**** +***/ + +void +Exporter::on_name_lost(GDBusConnection* connection, const gchar* name, gpointer gthis) +{ + g_debug("name lost: %s", name); + static_cast(gthis)->on_name_lost(connection, name); +} + +void +Exporter::on_name_lost(GDBusConnection* /*connection*/, const gchar* /*name*/) +{ + name_lost(); +} + +/*** +**** +***/ + +void +Exporter::publish(std::shared_ptr& actions, + 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); +} + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + diff --git a/src/main.cpp b/src/main.cpp index 6a56163..50d5241 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,7 @@ main(int /*argc*/, char** /*argv*/) // It can be removed when https://bugzilla.gnome.org/show_bug.cgi?id=674885 is fixed. g_type_ensure(G_TYPE_DBUS_CONNECTION); - // init i18n + // boilerplate i18n setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain(GETTEXT_PACKAGE); @@ -47,7 +47,7 @@ main(int /*argc*/, char** /*argv*/) if(!notify_init("indicator-datetime-service")) g_critical("libnotify initialization failed"); - // build the state and menu factory + // build the state and actions for the MenuFactory to use std::shared_ptr state(new LiveState); std::shared_ptr actions(new LiveActions(state)); MenuFactory factory(actions, state); @@ -56,7 +56,7 @@ main(int /*argc*/, char** /*argv*/) std::vector> menus; menus.push_back(factory.buildMenu(Menu::Desktop)); - // export them + // export them & run until we lose the busname auto loop = g_main_loop_new(nullptr, false); Exporter exporter; exporter.name_lost.connect([loop](){ diff --git a/src/planner-eds.cpp b/src/planner-eds.cpp index 275a29e..b3f751a 100644 --- a/src/planner-eds.cpp +++ b/src/planner-eds.cpp @@ -48,7 +48,7 @@ public: e_source_registry_new(m_cancellable, on_source_registry_ready, this); m_owner.time.changed().connect([this](const DateTime& dt) { - g_message("planner's datetime property changed to %s; calling rebuildSoon()", g_date_time_format(dt.get(), "%F %T")); + g_message("planner's datetime property changed to %s; calling rebuildSoon()", dt.format("%F %T").c_str()); rebuildSoon(); }); diff --git a/src/service.cpp b/src/service.cpp deleted file mode 100644 index 0671c61..0000000 --- a/src/service.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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: - * Charles Kerr - */ - -#include -#include - -#include -#include - -namespace unity { -namespace indicator { -namespace datetime { - -/*** -**** -***/ - -Service::~Service() -{ - if (m_dbus_connection != nullptr) - { - for(auto& id : m_exported_menu_ids) - g_dbus_connection_unexport_menu_model(m_dbus_connection, id); - - if (m_exported_actions_id) - g_dbus_connection_unexport_action_group(m_dbus_connection, m_exported_actions_id); - } - - if (m_own_id) - g_bus_unown_name(m_own_id); - - g_clear_object(&m_dbus_connection); -} - -/*** -**** -***/ - -void -Service::on_bus_acquired(GDBusConnection* connection, const gchar* name, gpointer gthis) -{ - g_debug("bus acquired: %s", name); - static_cast(gthis)->on_bus_acquired(connection, name); -} - -void -Service::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, &error); - if (id) - { - m_exported_actions_id = id; - } - else - { - 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_dbus_connection, path.c_str(), menu->menu_model(), &error); - if (id) - { - m_exported_menu_ids.insert(id); - } - else - { - g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); - g_clear_error(&error); - } - } -} - -/*** -**** -***/ - -void -Service::on_name_lost(GDBusConnection* connection, const gchar* name, gpointer gthis) -{ - g_debug("name lost: %s", name); - static_cast(gthis)->on_name_lost(connection, name); -} - -void -Service::on_name_lost(GDBusConnection* /*connection*/, const gchar* /*name*/) -{ - name_lost(); -} - -/*** -**** -***/ - -void -Service::publish(GActionGroup* actions, 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); -} - -/*** -**** -***/ - -} // namespace datetime -} // namespace indicator -} // namespace unity - -- cgit v1.2.3