From ee64bb2698adfe27e55615a8856b0e2c78ad8469 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 14 Jan 2014 23:07:10 -0600 Subject: Function: add fully-tested ActionGroups, per-profile Menus, state object. Form: Add code annotations/comments. Remove dead code. Use Mir style guide. Todo: GSettings toggles, sync with new dbus-test-runner API, get GNOME Panel building again --- src/main.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/main.cpp (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c246296 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include /* exit() */ + +using namespace unity::indicator::datetime; + +int +main(int /*argc*/, char** /*argv*/) +{ + // Work around a deadlock in glib's type initialization. + // It can be removed when https://bugzilla.gnome.org/show_bug.cgi?id=674885 is fixed. + g_type_ensure(G_TYPE_DBUS_CONNECTION); + + // boilerplate i18n + setlocale(LC_ALL, ""); + bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); + textdomain(GETTEXT_PACKAGE); + + // init libnotify + if(!notify_init("indicator-datetime-service")) + g_critical("libnotify initialization failed"); + + // build the menu factory + GActionGroup * actions = G_ACTION_GROUP(g_simple_action_group_new()); + std::shared_ptr timezones(new LiveTimezones(TIMEZONE_FILE)); + std::shared_ptr clock(new LiveClock(timezones)); + std::shared_ptr planner(new PlannerEds); + std::shared_ptr locations(new SettingsLocations(SETTINGS_INTERFACE, timezones)); + planner->time = clock->localtime(); + MenuFactory factory(actions, timezones, clock, planner, locations); + + // create the menus + std::vector> menus; + menus.push_back(factory.buildMenu(MenuFactory::Desktop)); + + // export them + auto loop = g_main_loop_new(nullptr, false); + Service service; + service.name_lost.connect([loop](){ + g_message("exiting: service couldn't acquire or lost ownership of busname"); + g_main_loop_quit(loop); + }); + service.publish(actions, menus); + g_main_loop_run(loop); + g_main_loop_unref(loop); + return 0; +} -- cgit v1.2.3 From 06a5132025ba2ab43de9d1d583a81d8e0b326da8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 21:21:41 -0600 Subject: sync with new State class changes --- src/main.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index c246296..7bd6f9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,13 +17,14 @@ * with this program. If not, see . */ +#include #include #include #include #include #include #include -#include +#include #include #include @@ -54,18 +55,28 @@ main(int /*argc*/, char** /*argv*/) if(!notify_init("indicator-datetime-service")) g_critical("libnotify initialization failed"); - // build the menu factory - GActionGroup * actions = G_ACTION_GROUP(g_simple_action_group_new()); - std::shared_ptr timezones(new LiveTimezones(TIMEZONE_FILE)); + // build the state + std::shared_ptr settings(new LiveSettings); + std::shared_ptr timezones(new LiveTimezones(settings, TIMEZONE_FILE)); std::shared_ptr clock(new LiveClock(timezones)); std::shared_ptr planner(new PlannerEds); - std::shared_ptr locations(new SettingsLocations(SETTINGS_INTERFACE, timezones)); planner->time = clock->localtime(); - MenuFactory factory(actions, timezones, clock, planner, locations); + std::shared_ptr locations(new SettingsLocations(settings, timezones)); + std::shared_ptr state(new State); + state->settings = settings; + state->timezones = timezones; + state->clock = clock; + state->locations = locations; + state->planner = planner; + state->calendar_day = clock->localtime(); + + // build the menu factory + std::shared_ptr actions(new LiveActions(state)); + MenuFactory factory(actions, state); // create the menus std::vector> menus; - menus.push_back(factory.buildMenu(MenuFactory::Desktop)); + menus.push_back(factory.buildMenu(Menu::Desktop)); // export them auto loop = g_main_loop_new(nullptr, false); @@ -74,7 +85,7 @@ main(int /*argc*/, char** /*argv*/) g_message("exiting: service couldn't acquire or lost ownership of busname"); g_main_loop_quit(loop); }); - service.publish(actions, menus); + //service.publish(actions, menus); g_main_loop_run(loop); g_main_loop_unref(loop); return 0; -- cgit v1.2.3 From d611929649cc4ef6b04ad9c453f14c85e1108842 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 00:36:07 -0600 Subject: extract LiveState to its own State subclass to make main()'s flow easier to follow --- include/datetime/state-live.h | 49 ++++++++++++++++++++++++++++++++++++ src/main.cpp | 46 +++++++++------------------------- src/state-live.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 34 deletions(-) create mode 100644 include/datetime/state-live.h create mode 100644 src/state-live.cpp (limited to 'src/main.cpp') diff --git a/include/datetime/state-live.h b/include/datetime/state-live.h new file mode 100644 index 0000000..2b93722 --- /dev/null +++ b/include/datetime/state-live.h @@ -0,0 +1,49 @@ +/* + * 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_STATE_LIVE_H +#define INDICATOR_DATETIME_STATE_LIVE_H + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +class LiveState: public State +{ +public: + LiveState(); + virtual ~LiveState() =default; +}; + +/*** +**** +***/ + + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_SETTINGS_LIVE_H diff --git a/src/main.cpp b/src/main.cpp index 7bd6f9d..6a56163 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,24 +18,16 @@ */ #include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include +#include -#include +#include // bindtextdomain() #include #include -#include - #include -#include /* exit() */ +#include // exit() using namespace unity::indicator::datetime; @@ -46,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); - // boilerplate i18n + // init i18n setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain(GETTEXT_PACKAGE); @@ -55,22 +47,8 @@ main(int /*argc*/, char** /*argv*/) if(!notify_init("indicator-datetime-service")) g_critical("libnotify initialization failed"); - // build the state - std::shared_ptr settings(new LiveSettings); - std::shared_ptr timezones(new LiveTimezones(settings, TIMEZONE_FILE)); - std::shared_ptr clock(new LiveClock(timezones)); - std::shared_ptr planner(new PlannerEds); - planner->time = clock->localtime(); - std::shared_ptr locations(new SettingsLocations(settings, timezones)); - std::shared_ptr state(new State); - state->settings = settings; - state->timezones = timezones; - state->clock = clock; - state->locations = locations; - state->planner = planner; - state->calendar_day = clock->localtime(); - - // build the menu factory + // build the state and menu factory + std::shared_ptr state(new LiveState); std::shared_ptr actions(new LiveActions(state)); MenuFactory factory(actions, state); @@ -80,12 +58,12 @@ main(int /*argc*/, char** /*argv*/) // export them auto loop = g_main_loop_new(nullptr, false); - Service service; - service.name_lost.connect([loop](){ - g_message("exiting: service couldn't acquire or lost ownership of busname"); - g_main_loop_quit(loop); + Exporter exporter; + exporter.name_lost.connect([loop](){ + g_message("%s exiting; failed/lost bus ownership", GETTEXT_PACKAGE); + g_main_loop_quit(loop); }); - //service.publish(actions, menus); + exporter.publish(actions, menus); g_main_loop_run(loop); g_main_loop_unref(loop); return 0; diff --git a/src/state-live.cpp b/src/state-live.cpp new file mode 100644 index 0000000..f4690b3 --- /dev/null +++ b/src/state-live.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +LiveState::LiveState() +{ + std::shared_ptr live_settings(new LiveSettings); + std::shared_ptr live_timezones(new LiveTimezones(live_settings, TIMEZONE_FILE)); + std::shared_ptr live_clock(new LiveClock(live_timezones)); + + settings = live_settings; + timezones = live_timezones; + clock = live_clock; + locations.reset(new SettingsLocations(live_settings, live_timezones)); + planner.reset(new PlannerEds); + planner->time = clock->localtime(); + calendar_day = clock->localtime(); +} + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity -- cgit v1.2.3 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 (limited to 'src/main.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 From 6e447b7bdb1273048dbaf9ead0eea629e73042e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 08:08:44 -0600 Subject: plug in the greeter menus --- src/exporter.cpp | 4 +++- src/main.cpp | 3 ++- src/menu.cpp | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main.cpp') diff --git a/src/exporter.cpp b/src/exporter.cpp index aa021f3..8103b5b 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -85,13 +85,15 @@ Exporter::on_bus_acquired(GDBusConnection* connection, 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); +g_message ("path %s id %d", path.c_str(), (int)id); if (id) { m_exported_menu_ids.insert(id); } else { - g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); + if (error != nullptr) + g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); g_clear_error(&error); } } diff --git a/src/main.cpp b/src/main.cpp index 50d5241..2c4f160 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,8 @@ main(int /*argc*/, char** /*argv*/) // create the menus std::vector> menus; - menus.push_back(factory.buildMenu(Menu::Desktop)); + for(int i=0, n=Menu::NUM_PROFILES; i& state_, std::shared_ptr& actions_): - DesktopBaseMenu(DesktopGreeter,"desktop-greeter", state_, actions_) {} + DesktopBaseMenu(DesktopGreeter,"desktop_greeter", state_, actions_) {} }; class PhoneBaseMenu: public MenuImpl @@ -454,7 +454,7 @@ class PhoneGreeterMenu: public PhoneBaseMenu public: PhoneGreeterMenu(std::shared_ptr& state_, std::shared_ptr& actions_): - PhoneBaseMenu(PhoneGreeter, "phone-greeter", state_, actions_) {} + PhoneBaseMenu(PhoneGreeter, "phone_greeter", state_, actions_) {} }; /**** -- cgit v1.2.3 From fee34f529e85e97cb439ea9fbbb210cffd51a6cf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:06:33 -0600 Subject: as per review, make explicit the dependency injection that was implicit in main() --- include/datetime/state-live.h | 49 ------------------------------------- src/CMakeLists.txt | 1 - src/main.cpp | 21 +++++++++++++--- src/state-live.cpp | 56 ------------------------------------------- 4 files changed, 18 insertions(+), 109 deletions(-) delete mode 100644 include/datetime/state-live.h delete mode 100644 src/state-live.cpp (limited to 'src/main.cpp') diff --git a/include/datetime/state-live.h b/include/datetime/state-live.h deleted file mode 100644 index 2b93722..0000000 --- a/include/datetime/state-live.h +++ /dev/null @@ -1,49 +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_STATE_LIVE_H -#define INDICATOR_DATETIME_STATE_LIVE_H - -#include - -namespace unity { -namespace indicator { -namespace datetime { - -/*** -**** -***/ - -class LiveState: public State -{ -public: - LiveState(); - virtual ~LiveState() =default; -}; - -/*** -**** -***/ - - -} // namespace datetime -} // namespace indicator -} // namespace unity - -#endif // INDICATOR_DATETIME_SETTINGS_LIVE_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5236ad..810e299 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,6 @@ add_library (${SERVICE_LIB} STATIC menu.cpp planner-eds.cpp settings-live.cpp - state-live.cpp timezone-file.cpp timezone-geoclue.cpp timezones-live.cpp diff --git a/src/main.cpp b/src/main.cpp index 2c4f160..1534777 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,10 +17,17 @@ * with this program. If not, see . */ + + #include +#include #include +#include #include -#include +#include +#include +#include +#include #include // bindtextdomain() #include @@ -47,8 +54,16 @@ main(int /*argc*/, char** /*argv*/) if(!notify_init("indicator-datetime-service")) g_critical("libnotify initialization failed"); - // build the state and actions for the MenuFactory to use - std::shared_ptr state(new LiveState); + // build the state, actions, and menufactory + std::shared_ptr state(new State); + std::shared_ptr live_settings(new LiveSettings); + std::shared_ptr live_timezones(new LiveTimezones(live_settings, TIMEZONE_FILE)); + std::shared_ptr live_clock(new LiveClock(live_timezones)); + state->settings = live_settings; + state->clock = live_clock; + state->locations.reset(new SettingsLocations(live_settings, live_timezones)); + state->planner.reset(new PlannerEds); + state->planner->time = live_clock->localtime(); std::shared_ptr actions(new LiveActions(state)); MenuFactory factory(actions, state); diff --git a/src/state-live.cpp b/src/state-live.cpp deleted file mode 100644 index fe1e6cd..0000000 --- a/src/state-live.cpp +++ /dev/null @@ -1,56 +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 -#include -#include -#include - -namespace unity { -namespace indicator { -namespace datetime { - -/*** -**** -***/ - -LiveState::LiveState() -{ - std::shared_ptr live_settings(new LiveSettings); - std::shared_ptr live_timezones(new LiveTimezones(live_settings, TIMEZONE_FILE)); - std::shared_ptr live_clock(new LiveClock(live_timezones)); - - settings = live_settings; - clock = live_clock; - locations.reset(new SettingsLocations(live_settings, live_timezones)); - planner.reset(new PlannerEds); - planner->time = clock->localtime(); -} - -/*** -**** -***/ - -} // namespace datetime -} // namespace indicator -} // namespace unity -- cgit v1.2.3