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/actions-live.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/actions-live.cpp (limited to 'src/actions-live.cpp') diff --git a/src/actions-live.cpp b/src/actions-live.cpp new file mode 100644 index 0000000..08e1466 --- /dev/null +++ b/src/actions-live.cpp @@ -0,0 +1,84 @@ +/* + * 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 + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +void LiveActions::open_desktop_settings() +{ + g_message ("%s", G_STRFUNC); +} + +void LiveActions::open_phone_settings() +{ + g_message("%s", G_STRFUNC); +} + +void LiveActions::open_phone_clock() +{ + g_message("%s", G_STRFUNC); +} + +void LiveActions::open_phone_planner() +{ + g_message("%s", G_STRFUNC); +} + +void LiveActions::open_planner_at(const DateTime&) +{ + g_message("%s", G_STRFUNC); +} + +void LiveActions::open_calendar_at(const DateTime&) +{ + g_message("%s", G_STRFUNC); +} + +void LiveActions::open_appointment(const std::string& uid) +{ + g_message("%s - %s", G_STRFUNC, uid.c_str()); +} + +void LiveActions::set_location(const std::string& zone, const std::string& name) +{ + g_message("%s - %s %s", G_STRFUNC, zone.c_str(), name.c_str()); +} + +void LiveActions::set_calendar_date(const DateTime&) +{ + g_message("%s", G_STRFUNC); +} + + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity -- cgit v1.2.3 From 2e9d3bb48946ccebf49cff64ab5de67e5714e1e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 21:23:57 -0600 Subject: get timezone, clock tests running again with Settings & State --- include/datetime/actions-live.h | 7 +- include/datetime/actions.h | 2 +- src/actions-live.cpp | 9 +-- src/actions.cpp | 6 +- tests/geoclue-fixture.h | 48 +++++++----- tests/test-clock.cc | 168 +++++++++------------------------------- tests/test-dbus-fixture.h | 14 ++-- tests/test-timezones.cc | 21 ++--- 8 files changed, 91 insertions(+), 184 deletions(-) (limited to 'src/actions-live.cpp') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 2059a4d..3d04660 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,15 +36,14 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(std::shared_ptr& state): Actions(state) {} + LiveActions(const std::shared_ptr& state): Actions(state) {} ~LiveActions() =default; void open_desktop_settings(); void open_phone_settings(); - void open_phone_clock(); - void open_phone_planner(); + void open_phone_clock_app(); + void open_planner(); void open_planner_at(const DateTime&); - void open_calendar_at(const DateTime&); void open_appointment(const std::string& uid); void set_location(const std::string& zone, const std::string& name); void set_calendar_date(const DateTime&); diff --git a/include/datetime/actions.h b/include/datetime/actions.h index ed45c3c..a4c6017 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -51,7 +51,7 @@ public: std::shared_ptr state() { return m_state; } protected: - Actions(std::shared_ptr& state); + Actions(const std::shared_ptr& state); virtual ~Actions(); private: diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 08e1466..c699aff 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -39,12 +39,12 @@ void LiveActions::open_phone_settings() g_message("%s", G_STRFUNC); } -void LiveActions::open_phone_clock() +void LiveActions::open_phone_clock_app() { g_message("%s", G_STRFUNC); } -void LiveActions::open_phone_planner() +void LiveActions::open_planner() { g_message("%s", G_STRFUNC); } @@ -54,11 +54,6 @@ void LiveActions::open_planner_at(const DateTime&) g_message("%s", G_STRFUNC); } -void LiveActions::open_calendar_at(const DateTime&) -{ - g_message("%s", G_STRFUNC); -} - void LiveActions::open_appointment(const std::string& uid) { g_message("%s - %s", G_STRFUNC, uid.c_str()); diff --git a/src/actions.cpp b/src/actions.cpp index 52ee1eb..0df7d53 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -130,7 +130,7 @@ GVariant* create_default_header_state() return g_variant_builder_end(&b); } -GVariant* create_calendar_state(std::shared_ptr& state) +GVariant* create_calendar_state(const std::shared_ptr& state) { gboolean days[32] = { 0 }; for(const auto& appt : state->planner->thisMonth.get()) @@ -138,7 +138,7 @@ GVariant* create_calendar_state(std::shared_ptr& state) GVariantBuilder day_builder; g_variant_builder_init(&day_builder, G_VARIANT_TYPE("ai")); - for (int i=0; i& state) **** ***/ -Actions::Actions(std::shared_ptr& state): +Actions::Actions(const std::shared_ptr& state): m_state(state), m_actions(g_simple_action_group_new()) { diff --git a/tests/geoclue-fixture.h b/tests/geoclue-fixture.h index 890204a..7e29018 100644 --- a/tests/geoclue-fixture.h +++ b/tests/geoclue-fixture.h @@ -33,8 +33,10 @@ class GeoclueFixture : public GlibFixture DbusTestService * service = nullptr; DbusTestDbusMock * mock = nullptr; - DbusTestDbusMockObject * obj_master = nullptr; - DbusTestDbusMockObject * obj_client = nullptr; + DbusTestDbusMockObject * obj_geo = nullptr; + DbusTestDbusMockObject * obj_geo_m = nullptr; + DbusTestDbusMockObject * obj_geo_mc = nullptr; + DbusTestDbusMockObject * obj_geo_addr = nullptr; const std::string timezone_1 = "America/Denver"; void SetUp () @@ -42,25 +44,31 @@ class GeoclueFixture : public GlibFixture super::SetUp(); GError * error = nullptr; - const gchar * const client_path = "/org/freedesktop/Geoclue/Master/client0"; + const auto master_path = "/org/freedesktop/Geoclue/Master"; + const auto client_path = "/org/freedesktop/Geoclue/Master/client0"; GString * gstr = g_string_new (nullptr); service = dbus_test_service_new (nullptr); mock = dbus_test_dbus_mock_new ("org.freedesktop.Geoclue.Master"); - obj_master = dbus_test_dbus_mock_get_object (mock, - "/org/freedesktop/Geoclue/Master", - "org.freedesktop.Geoclue.Master", - nullptr); + auto interface = "org.freedesktop.Geoclue.Master"; + obj_geo_m = dbus_test_dbus_mock_get_object (mock, master_path, interface, nullptr); g_string_printf (gstr, "ret = '%s'", client_path); - dbus_test_dbus_mock_object_add_method (mock, obj_master, nullptr, "Create", nullptr, G_VARIANT_TYPE_OBJECT_PATH, gstr->str, &error); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_m, "Create", nullptr, G_VARIANT_TYPE_OBJECT_PATH, gstr->str, &error); - obj_client = dbus_test_dbus_mock_get_object (mock, client_path, "org.freedesktop.Geoclue.MasterClient", nullptr); - dbus_test_dbus_mock_object_add_method (mock, obj_client, nullptr, "SetRequirements", G_VARIANT_TYPE("(iibi)"), nullptr, "", &error); - dbus_test_dbus_mock_object_add_method (mock, obj_client, nullptr, "AddressStart", nullptr, nullptr, "", &error); - dbus_test_dbus_mock_object_add_method (mock, obj_client, "org.freedesktop.Geoclue", "AddReference", nullptr, nullptr, "", &error); + interface = "org.freedesktop.Geoclue.MasterClient"; + obj_geo_mc = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_mc, "SetRequirements", G_VARIANT_TYPE("(iibi)"), nullptr, "", &error); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_mc, "AddressStart", nullptr, nullptr, "", &error); + + interface = "org.freedesktop.Geoclue"; + obj_geo = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr); + dbus_test_dbus_mock_object_add_method (mock, obj_geo, "AddReference", nullptr, nullptr, "", &error); g_string_printf (gstr, "ret = (1385238033, {'timezone': '%s'}, (3, 0.0, 0.0))", timezone_1.c_str()); - dbus_test_dbus_mock_object_add_method (mock, obj_client, "org.freedesktop.Geoclue.Address", "GetAddress", nullptr, G_VARIANT_TYPE("(ia{ss}(idd))"), gstr->str, &error); + + interface = "org.freedesktop.Geoclue.Address"; + obj_geo_addr = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_addr, "GetAddress", nullptr, G_VARIANT_TYPE("(ia{ss}(idd))"), gstr->str, &error); dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); dbus_test_service_start_tasks(service); @@ -101,11 +109,11 @@ private: struct EmitAddressChangedData { DbusTestDbusMock * mock = nullptr; - DbusTestDbusMockObject * obj_client = nullptr; + DbusTestDbusMockObject * obj_geo_addr = nullptr; std::string timezone; - EmitAddressChangedData(DbusTestDbusMock * mock_, - DbusTestDbusMockObject * obj_client_, - const std::string& timezone_): mock(mock_), obj_client(obj_client_), timezone(timezone_) {} + EmitAddressChangedData(DbusTestDbusMock* mock_, + DbusTestDbusMockObject* obj_geo_addr_, + const std::string& timezone_): mock(mock_), obj_geo_addr(obj_geo_addr_), timezone(timezone_) {} }; static gboolean emit_address_changed_idle (gpointer gdata) @@ -114,8 +122,8 @@ private: auto fmt = g_strdup_printf ("(1385238033, {'timezone': '%s'}, (3, 0.0, 0.0))", data->timezone.c_str()); GError * error = nullptr; - dbus_test_dbus_mock_object_emit_signal(data->mock, data->obj_client, - "org.freedesktop.Geoclue.Address", + dbus_test_dbus_mock_object_emit_signal(data->mock, data->obj_geo_addr, + //"org.freedesktop.Geoclue.Address", "AddressChanged", G_VARIANT_TYPE("(ia{ss}(idd))"), g_variant_new_parsed (fmt), @@ -135,7 +143,7 @@ public: void setGeoclueTimezoneOnIdle (const std::string& newZone) { - g_timeout_add (50, emit_address_changed_idle, new EmitAddressChangedData(mock, obj_client, newZone.c_str())); + g_timeout_add (50, emit_address_changed_idle, new EmitAddressChangedData(mock, obj_geo_addr, newZone.c_str())); } }; diff --git a/tests/test-clock.cc b/tests/test-clock.cc index 7d3a35e..142ccad 100644 --- a/tests/test-clock.cc +++ b/tests/test-clock.cc @@ -20,95 +20,56 @@ #include #include -#include "glib-fixture.h" +#include "test-dbus-fixture.h" /*** **** ***/ -using unity::indicator::datetime::Clock; -using unity::indicator::datetime::LiveClock; -using unity::indicator::datetime::Timezones; +using namespace unity::indicator::datetime; -class ClockFixture: public GlibFixture +class ClockFixture: public TestDBusFixture { private: - - typedef GlibFixture super; - - static void - on_bus_opened(GObject* /*object*/, GAsyncResult* res, gpointer gself) - { - auto self = static_cast(gself); - - GError * err = 0; - self->system_bus = g_bus_get_finish(res, &err); - g_assert_no_error(err); - - g_main_loop_quit(self->loop); - } - - static void - on_bus_closed(GObject* /*object*/, GAsyncResult* res, gpointer gself) - { - auto self = static_cast(gself); - - GError * err = 0; - g_dbus_connection_close_finish(self->system_bus, res, &err); - g_assert_no_error(err); - - g_main_loop_quit(self->loop); - } - - protected: - - GTestDBus * test_dbus; - GDBusConnection * system_bus; - - virtual void SetUp() - { - super::SetUp(); - - // pull up a test dbus - test_dbus = g_test_dbus_new(G_TEST_DBUS_NONE); - g_test_dbus_up(test_dbus); - const char * address = g_test_dbus_get_bus_address(test_dbus); - g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, TRUE); - g_debug("test_dbus's address is %s", address); - - // wait for the GDBusConnection before returning - g_bus_get(G_BUS_TYPE_SYSTEM, nullptr, on_bus_opened, this); - g_main_loop_run(loop); - } - - virtual void TearDown() - { - // close the system bus - g_dbus_connection_close(system_bus, nullptr, on_bus_closed, this); - g_main_loop_run(loop); - g_clear_object(&system_bus); - - // tear down the test dbus - g_test_dbus_down(test_dbus); - g_clear_object(&test_dbus); - - super::TearDown(); - } + typedef TestDBusFixture super; public: - void emitPrepareForSleep() { g_dbus_connection_emit_signal(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr), - NULL, - "/org/freedesktop/login1", // object path - "org.freedesktop.login1.Manager", // interface - "PrepareForSleep", // signal name - g_variant_new("(b)", FALSE), - NULL); + NULL, + "/org/freedesktop/login1", // object path + "org.freedesktop.login1.Manager", // interface + "PrepareForSleep", // signal name + g_variant_new("(b)", FALSE), + NULL); } }; +/** + * Confirm that normal time passing doesn't trigger a skew event. + * that idling changing the clock's time triggers a skew event + */ +TEST_F(ClockFixture, IdleDoesNotTriggerSkew) +{ + std::shared_ptr zones(new Timezones); + zones->timezone.set("America/New_York"); + LiveClock clock(zones); + wait_msec(500); // wait for the bus to set up + + bool skewed = false; + clock.skewDetected.connect([&skewed](){ + skewed = true; + g_warn_if_reached(); + return G_SOURCE_REMOVE; + }); + + const unsigned int intervalSec = 3; + clock.skewTestIntervalSec.set(intervalSec); + wait_msec(intervalSec * 2.5 * 1000); + EXPECT_FALSE(skewed); +} + /*** **** ***/ @@ -120,37 +81,6 @@ TEST_F(ClockFixture, HelloFixture) std::shared_ptr zones(new Timezones); zones->timezone.set("America/New_York"); LiveClock clock(zones); - -#if 0 - GTimeZone * tz_nyc = g_time_zone_new(file_timezone.c_str()); - GDateTime * now_nyc = g_date_time_new_now(tz_nyc); - GDateTime * now = clock.localtime(); - EXPECT_EQ(g_date_time_get_utc_offset(now_nyc), g_date_time_get_utc_offset(now)); - EXPECT_LE(abs(g_date_time_difference(now_nyc,now)), G_USEC_PER_SEC); - g_date_time_unref(now); - g_date_time_unref(now_nyc); - g_time_zone_unref(tz_nyc); - - /// change the timezones! - clock.skewDetected.connect([this](){ - g_main_loop_quit(loop); - }); - file_timezone = "America/Los_Angeles"; - g_idle_add([](gpointer str){ - set_file(static_cast(str)); - return G_SOURCE_REMOVE; - }, const_cast(file_timezone.c_str())); - g_main_loop_run(loop); - - GTimeZone * tz_la = g_time_zone_new(file_timezone.c_str()); - GDateTime * now_la = g_date_time_new_now(tz_la); - now = clock.localtime(); - EXPECT_EQ(g_date_time_get_utc_offset(now_la), g_date_time_get_utc_offset(now)); - EXPECT_LE(abs(g_date_time_difference(now_la,now)), G_USEC_PER_SEC); - g_date_time_unref(now); - g_date_time_unref(now_la); - g_time_zone_unref(tz_la); -#endif } @@ -159,10 +89,6 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) std::shared_ptr zones(new Timezones); zones->timezone.set("America/New_York"); LiveClock clock(zones); - //std::string file_timezone = "America/New_York"; - //set_file(file_timezone); - //std::shared_ptr detector(new TimezoneDetector(TIMEZONE_FILE)); - //LiveClock clock(detector); auto tz_nyc = g_time_zone_new("America/New_York"); auto now_nyc = g_date_time_new_now(tz_nyc); @@ -213,30 +139,6 @@ TEST_F(ClockFixture, SleepTriggersSkew) return G_SOURCE_REMOVE; }, this); - wait_msec(1000); + g_main_loop_run(loop); EXPECT_TRUE(skewed); } - -/** - * Confirm that normal time passing doesn't trigger a skew event. - * that idling changing the clock's time triggers a skew event - */ -TEST_F(ClockFixture, IdleDoesNotTriggerSkew) -{ - std::shared_ptr zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); - wait_msec(500); // wait for the bus to set up - - bool skewed = false; - clock.skewDetected.connect([&skewed](){ - skewed = true; - g_warn_if_reached(); - return G_SOURCE_REMOVE; - }); - - const unsigned int intervalSec = 4; - clock.skewTestIntervalSec.set(intervalSec); - wait_msec(intervalSec * 2.5 * 1000); - EXPECT_FALSE(skewed); -} diff --git a/tests/test-dbus-fixture.h b/tests/test-dbus-fixture.h index fc7ab5a..db06be2 100644 --- a/tests/test-dbus-fixture.h +++ b/tests/test-dbus-fixture.h @@ -86,15 +86,17 @@ class TestDBusFixture: public GlibFixture virtual void TearDown () { + wait_msec(); + // close the system bus - g_dbus_connection_close (system_bus, nullptr, on_bus_closed, this); - g_main_loop_run (loop); - g_clear_object (&system_bus); + g_dbus_connection_close(system_bus, nullptr, on_bus_closed, this); + g_main_loop_run(loop); + g_clear_object(&system_bus); // tear down the test dbus - g_test_dbus_down (test_dbus); - g_clear_object (&test_dbus); + g_test_dbus_down(test_dbus); + g_clear_object(&test_dbus); - super::TearDown (); + super::TearDown(); } }; diff --git a/tests/test-timezones.cc b/tests/test-timezones.cc index d3c8e3a..3f02761 100644 --- a/tests/test-timezones.cc +++ b/tests/test-timezones.cc @@ -19,12 +19,15 @@ #include "geoclue-fixture.h" +#include #include +#include // std::shared_ptr + #include // fopen() #include // sync() -using unity::indicator::datetime::LiveTimezones; +using namespace unity::indicator::datetime; typedef GeoclueFixture TimezonesFixture; @@ -49,7 +52,8 @@ TEST_F(TimezonesFixture, ManagerTest) std::string timezone_geo = "America/Denver"; set_file(timezone_file); - LiveTimezones z(TIMEZONE_FILE); + std::shared_ptr settings(new Settings); + LiveTimezones z(settings, TIMEZONE_FILE); wait_msec(500); // wait for the bus to get set up EXPECT_EQ(timezone_file, z.timezone.get()); auto zones = z.timezones.get(); @@ -71,13 +75,13 @@ TEST_F(TimezonesFixture, ManagerTest) g_main_loop_quit(loop); }); - g_idle_add([](gpointer gz) { - auto az = static_cast(gz); - g_message("geolocation was %d", (int)az->geolocationEnabled.get()); + g_idle_add([](gpointer s_in) { + auto s = static_cast(s_in); + g_message("geolocation was %d", (int)s->show_detected_location.get()); g_message("turning geolocation on"); - az->geolocationEnabled.set(true); + s->show_detected_location.set(true); return G_SOURCE_REMOVE; - }, &z); + }, settings.get()); // turn on geoclue during the idle... this should add timezone_1 to the 'timezones' property g_main_loop_run(loop); @@ -115,9 +119,6 @@ TEST_F(TimezonesFixture, ManagerTest) EXPECT_EQ(2, zones.size()); EXPECT_EQ(1, zones.count(timezone_file)); EXPECT_EQ(1, zones.count(timezone_geo)); - - - } -- cgit v1.2.3 From 74f8897902c99180e721d616614a9962c819d90b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 21 Jan 2014 23:29:19 -0600 Subject: add LiveActions implementation and unit tests --- include/datetime/actions-live.h | 6 +- src/actions-live.cpp | 153 ++++++++++++++++++++++++++++++++++++---- tests/CMakeLists.txt | 9 ++- tests/test-menus.cc | 2 +- 4 files changed, 154 insertions(+), 16 deletions(-) (limited to 'src/actions-live.cpp') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 3d04660..1947e6e 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,7 +36,7 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(const std::shared_ptr& state): Actions(state) {} + LiveActions(const std::shared_ptr& state_in): Actions(state_in) {} ~LiveActions() =default; void open_desktop_settings(); @@ -47,6 +47,10 @@ public: void open_appointment(const std::string& uid); void set_location(const std::string& zone, const std::string& name); void set_calendar_date(const DateTime&); + +protected: + virtual void execute_command(const std::string& command); + virtual void dispatch_url(const std::string& url); }; } // namespace datetime diff --git a/src/actions-live.cpp b/src/actions-live.cpp index c699aff..e4f5e9f 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -19,6 +19,8 @@ #include +#include + #include namespace unity { @@ -29,46 +31,171 @@ namespace datetime { **** ***/ +void LiveActions::execute_command(const std::string& cmdstr) +{ + const auto cmd = cmdstr.c_str(); + g_debug("Issuing command '%s'", cmd); + + GError* error = nullptr; + if (!g_spawn_command_line_async(cmd, &error)) + { + g_warning("Unable to start \"%s\": %s", cmd, error->message); + g_error_free(error); + } +} + +void LiveActions::dispatch_url(const std::string& url) +{ + url_dispatch_send(url.c_str(), nullptr, nullptr); +} + +/*** +**** +***/ + void LiveActions::open_desktop_settings() { - g_message ("%s", G_STRFUNC); +#ifdef HAVE_CCPANEL + execute_command("gnome-control-center indicator-datetime"); +#else + execute_command("gnome-control-center datetime"); +#endif +} + +void LiveActions::open_planner() +{ + execute_command("evolution -c calendar"); } void LiveActions::open_phone_settings() { - g_message("%s", G_STRFUNC); + dispatch_url("settings:///system/time-date"); } void LiveActions::open_phone_clock_app() { - g_message("%s", G_STRFUNC); + dispatch_url("appid://com.ubuntu.clock/clock/current-user-version"); } -void LiveActions::open_planner() +void LiveActions::open_planner_at(const DateTime& dt) { - g_message("%s", G_STRFUNC); + auto cmd = dt.format("evolution \"calendar:///?startdate=%Y%m%d\""); + execute_command(cmd.c_str()); } -void LiveActions::open_planner_at(const DateTime&) +void LiveActions::open_appointment(const std::string& uid) { - g_message("%s", G_STRFUNC); + for(const auto& appt : state()->planner->upcoming.get()) + { + if(appt.uid != uid) + continue; + + if (!appt.url.empty()) + dispatch_url(appt.url); + break; + } } -void LiveActions::open_appointment(const std::string& uid) +void LiveActions::set_calendar_date(const DateTime& dt) { - g_message("%s - %s", G_STRFUNC, uid.c_str()); + state()->calendar_day.set(dt); } -void LiveActions::set_location(const std::string& zone, const std::string& name) +/*** +**** +***/ + +namespace +{ + +struct setlocation_data { - g_message("%s - %s %s", G_STRFUNC, zone.c_str(), name.c_str()); + std::string tzid; + std::string name; + std::shared_ptr settings; +}; + +static void +on_datetime1_set_timezone_response(GObject * object, + GAsyncResult * res, + gpointer gdata) +{ + GError* err = nullptr; + auto response = g_dbus_proxy_call_finish(G_DBUS_PROXY(object), res, &err); + auto data = static_cast(gdata); + + if (err != nullptr) + { + if (!g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning("Could not set new timezone: %s", err->message); + + g_error_free(err); + } + else + { + data->settings->timezone_name.set(data->tzid + " " + data->name); + g_variant_unref(response); + } + + delete data; } -void LiveActions::set_calendar_date(const DateTime&) +static void +on_datetime1_proxy_ready (GObject * object G_GNUC_UNUSED, + GAsyncResult * res, + gpointer gdata) { - g_message("%s", G_STRFUNC); + auto data = static_cast(gdata); + + GError * err = nullptr; + auto proxy = g_dbus_proxy_new_for_bus_finish(res, &err); + if (err != NULL) + { + if (!g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning("Could not grab DBus proxy for timedated: %s", err->message); + + g_error_free(err); + + delete data; + } + else + { + g_dbus_proxy_call(proxy, + "SetTimezone", + g_variant_new ("(sb)", data->tzid.c_str(), TRUE), + G_DBUS_CALL_FLAGS_NONE, + -1, + nullptr, + on_datetime1_set_timezone_response, + data); + + g_object_unref (proxy); + } } +} // unnamed namespace + + +void LiveActions::set_location(const std::string& tzid, const std::string& name) +{ + g_return_if_fail(!tzid.empty()); + g_return_if_fail(!name.empty()); + + auto data = new struct setlocation_data; + data->tzid = tzid; + data->name = name; + data->settings = state()->settings; + + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + nullptr, + "org.freedesktop.timedate1", + "/org/freedesktop/timedate1", + "org.freedesktop.timedate1", + nullptr, + on_datetime1_proxy_ready, + data); +} /*** **** diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a908801..9bc1d75 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -84,6 +84,13 @@ add_test (${TEST_NAME} ${TEST_NAME}) add_dependencies (${TEST_NAME} libindicatordatetimeservice) target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) +# test-live-actions +set (TEST_NAME test-live-actions) +add_executable (${TEST_NAME} ${TEST_NAME}.cc) +add_test (${TEST_NAME} ${TEST_NAME}) +add_dependencies (${TEST_NAME} libindicatordatetimeservice) +target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) + # test-menus set (TEST_NAME test-menus) add_executable (${TEST_NAME} ${TEST_NAME}.cc) @@ -98,7 +105,7 @@ add_test (${TEST_NAME} ${TEST_NAME}) add_dependencies (${TEST_NAME} libindicatordatetimeservice) target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) -# test-utils +# test-settings set (TEST_NAME test-settings) add_executable (${TEST_NAME} ${TEST_NAME}.cc) add_test (${TEST_NAME} ${TEST_NAME}) diff --git a/tests/test-menus.cc b/tests/test-menus.cc index 0f86b0d..95ac5c2 100644 --- a/tests/test-menus.cc +++ b/tests/test-menus.cc @@ -148,7 +148,7 @@ protected: auto gdt_tomorrow = g_date_time_add_days(now.get(), 1); auto tomorrow = DateTime(gdt_tomorrow); g_date_time_unref(gdt_tomorrow); - m_clock->set_localtime(tomorrow); + m_mock_state->mock_clock->set_localtime(tomorrow); wait_msec(); section = g_menu_model_get_item_link(submenu, Menu::Calendar, G_MENU_LINK_SECTION); -- cgit v1.2.3 From 7b09a0ff5652bdca7c8d8e046d2af6a696f94147 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 25 Jan 2014 16:54:41 -0600 Subject: sync the exported calendar state with the #State backend --- include/datetime/actions.h | 4 +- include/datetime/state.h | 2 - src/actions-live.cpp | 5 -- src/actions.cpp | 30 +++++++++++- src/state-live.cpp | 1 - tests/actions-mock.h | 8 +--- tests/state-mock.h | 1 - tests/test-actions.cpp | 19 +++++--- tests/test-live-actions.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 157 insertions(+), 27 deletions(-) (limited to 'src/actions-live.cpp') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 18286dc..3686b95 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -49,8 +49,7 @@ public: virtual void open_planner_at(const DateTime&) =0; virtual void open_appointment(const std::string& uid) =0; virtual void set_location(const std::string& zone, const std::string& name)=0; - virtual void set_calendar_date(const DateTime&) =0; - + void set_calendar_date(const DateTime&); GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); } std::shared_ptr state() { return m_state; } @@ -61,6 +60,7 @@ protected: private: std::shared_ptr m_state; GSimpleActionGroup* m_actions = nullptr; + void update_calendar_state(); // we've got raw pointers in here, so disable copying Actions(const Actions&) =delete; diff --git a/include/datetime/state.h b/include/datetime/state.h index b14908e..414be32 100644 --- a/include/datetime/state.h +++ b/include/datetime/state.h @@ -66,8 +66,6 @@ struct State /** \brief Configuration options that modify the view */ std::shared_ptr settings; - - core::Property calendar_day; }; } // namespace datetime diff --git a/src/actions-live.cpp b/src/actions-live.cpp index e4f5e9f..d5f7180 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -96,11 +96,6 @@ void LiveActions::open_appointment(const std::string& uid) } } -void LiveActions::set_calendar_date(const DateTime& dt) -{ - state()->calendar_day.set(dt); -} - /*** **** ***/ diff --git a/src/actions.cpp b/src/actions.cpp index 1d80c99..a6a7c0b 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -150,7 +150,7 @@ GVariant* create_calendar_state(const std::shared_ptr& state) g_variant_builder_add(&dict_builder, "{sv}", key, v); key = "calendar-day"; - v = g_variant_new_int64(state->calendar_day.get().to_unix()); + v = g_variant_new_int64(state->planner->time.get().to_unix()); g_variant_builder_add(&dict_builder, "{sv}", key, v); key = "show-week-numbers"; @@ -200,7 +200,20 @@ Actions::Actions(const std::shared_ptr& state): a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v); g_action_map_add_action(gam, G_ACTION(a)); g_signal_connect(a, "activate", G_CALLBACK(on_calendar_activated), this); - //m_calendar_action = a; + + /// + /// Keep our GActionGroup's action's states in sync with m_state + /// + + m_state->planner->time.changed().connect([this](const DateTime&){ + update_calendar_state(); + }); + m_state->planner->thisMonth.changed().connect([this](const std::vector&){ + update_calendar_state(); + }); + m_state->settings->show_week_numbers.changed().connect([this](bool){ + update_calendar_state(); + }); // FIXME: rebuild the calendar state when show-week-number changes } @@ -210,6 +223,19 @@ Actions::~Actions() g_clear_object(&m_actions); } +void Actions::update_calendar_state() +{ + g_action_group_change_action_state(action_group(), + "calendar", + create_calendar_state(m_state)); +} + +void Actions::set_calendar_date(const DateTime& date) +{ + m_state->planner->time.set(date); +} + + } // namespace datetime } // namespace indicator } // namespace unity diff --git a/src/state-live.cpp b/src/state-live.cpp index 8ee663b..fe1e6cd 100644 --- a/src/state-live.cpp +++ b/src/state-live.cpp @@ -45,7 +45,6 @@ LiveState::LiveState() locations.reset(new SettingsLocations(live_settings, live_timezones)); planner.reset(new PlannerEds); planner->time = clock->localtime(); - calendar_day = clock->localtime(); } /*** diff --git a/tests/actions-mock.h b/tests/actions-mock.h index 112900b..da93cb9 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -35,8 +35,7 @@ public: ~MockActions() =default; enum Action { OpenDesktopSettings, OpenPhoneSettings, OpenPhoneClockApp, - OpenPlanner, OpenPlannerAt, OpenAppointment, - SetLocation, SetCalendarDate }; + OpenPlanner, OpenPlannerAt, OpenAppointment, SetLocation }; const std::vector& history() const { return m_history; } const DateTime& date_time() const { return m_date_time; } const std::string& zone() const { return m_zone; } @@ -68,11 +67,6 @@ public: m_url = url_; } - void set_calendar_date(const DateTime& date_time_) { - m_history.push_back(SetCalendarDate); - m_date_time = date_time_; - } - private: std::string m_url; std::string m_zone; diff --git a/tests/state-mock.h b/tests/state-mock.h index 64ab08b..721b82f 100644 --- a/tests/state-mock.h +++ b/tests/state-mock.h @@ -38,7 +38,6 @@ public: planner.reset(new MockPlanner); planner->time = now; locations.reset(new Locations); - calendar_day = now; } }; diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index 4329608..c30d1fb 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -137,18 +137,23 @@ TEST_F(ActionsFixture, SetLocation) TEST_F(ActionsFixture, SetCalendarDate) { + // confirm that such an action exists const auto action_name = "calendar"; auto action_group = m_actions->action_group(); EXPECT_TRUE(m_mock_actions->history().empty()); EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); - auto unix = m_state->clock->localtime().to_unix(); - auto v = g_variant_new_int64(unix); - g_action_group_activate_action(action_group, action_name, v); - const auto expected_action = MockActions::SetCalendarDate; - ASSERT_EQ(1, m_mock_actions->history().size()); - EXPECT_EQ(expected_action, m_mock_actions->history()[0]); - EXPECT_EQ(unix, m_mock_actions->date_time().to_unix()); + // pick an arbitrary DateTime... + auto tmp = g_date_time_new_local(2010, 1, 2, 3, 4, 5); + const auto now = DateTime(tmp); + g_date_time_unref(tmp); + + // confirm that Planner.time gets changed to that date when we + // activate the 'calendar' action with that date's time_t as the arg + EXPECT_NE (now, m_state->planner->time.get()); + auto v = g_variant_new_int64(now.to_unix()); + g_action_group_activate_action (action_group, action_name, v); + EXPECT_EQ (now, m_state->planner->time.get()); } TEST_F(ActionsFixture, OpenAppointment) diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index d3d7720..562b358 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -287,3 +287,117 @@ TEST_F(LiveActionsFixture, OpenPlannerAt) const std::string expected = now.format("evolution \"calendar:///?startdate=%Y%m%d\""); EXPECT_EQ(expected, m_live_actions->last_cmd); } + +TEST_F(LiveActionsFixture, CalendarState) +{ + // init the clock + auto tmp = g_date_time_new_local (2014, 1, 1, 0, 0, 0); + const DateTime now (tmp); + g_date_time_unref (tmp); + m_mock_state->mock_clock->set_localtime (now); + m_state->planner->time.set(now); + + /// + /// Test the default calendar state. + /// + + auto action_group = m_actions->action_group(); + auto calendar_state = g_action_group_get_action_state (action_group, "calendar"); + EXPECT_TRUE (calendar_state != nullptr); + EXPECT_TRUE (g_variant_is_of_type (calendar_state, G_VARIANT_TYPE_DICTIONARY)); + + // there's nothing in the planner yet, so appointment-days should be an empty array + auto v = g_variant_lookup_value (calendar_state, "appointment-days", G_VARIANT_TYPE_ARRAY); + EXPECT_TRUE (v != nullptr); + EXPECT_EQ (0, g_variant_n_children (v)); + g_clear_pointer (&v, g_variant_unref); + + // calendar-day should be in sync with m_state->calendar_day + v = g_variant_lookup_value (calendar_state, "calendar-day", G_VARIANT_TYPE_INT64); + EXPECT_TRUE (v != nullptr); + EXPECT_EQ (m_state->planner->time.get().to_unix(), g_variant_get_int64(v)); + g_clear_pointer (&v, g_variant_unref); + + // show-week-numbers should be false because MockSettings defaults everything to 0 + v = g_variant_lookup_value (calendar_state, "show-week-numbers", G_VARIANT_TYPE_BOOLEAN); + EXPECT_TRUE (v != nullptr); + EXPECT_FALSE (g_variant_get_boolean (v)); + g_clear_pointer (&v, g_variant_unref); + + // cleanup this step + g_clear_pointer (&calendar_state, g_variant_unref); + + + /// + /// Now add appointments to the planner and confirm that the state keeps in sync + /// + + auto tomorrow = g_date_time_add_days (now.get(), 1); + auto tomorrow_begin = g_date_time_add_full (tomorrow, 0, 0, 0, + -g_date_time_get_hour(tomorrow), + -g_date_time_get_minute(tomorrow), + -g_date_time_get_seconds(tomorrow)); + auto tomorrow_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1); + Appointment a1; + a1.color = "green"; + a1.summary = "write unit tests"; + a1.url = "http://www.ubuntu.com/"; + a1.uid = "D4B57D50247291478ED31DED17FF0A9838DED402"; + a1.begin = tomorrow_begin; + a1.end = tomorrow_end; + + auto next_begin = g_date_time_add_days (tomorrow_begin, 1); + auto next_end = g_date_time_add_full (next_begin, 0, 0, 1, 0, 0, -1); + Appointment a2; + a2.color = "orange"; + a2.summary = "code review"; + a2.url = "http://www.ubuntu.com/"; + a2.uid = "2756ff7de3745bbffd65d2e4779c37c7ca60d843"; + a2.begin = next_begin; + a2.end = next_end; + + m_state->planner->thisMonth.set(std::vector({a1, a2})); + + /// + /// Now test the calendar state again. + /// The thisMonth field should now contain the appointments we just added. + /// + + calendar_state = g_action_group_get_action_state (action_group, "calendar"); + v = g_variant_lookup_value (calendar_state, "appointment-days", G_VARIANT_TYPE_ARRAY); + EXPECT_TRUE (v != nullptr); + int i; + g_variant_get_child (v, 0, "i", &i); + EXPECT_EQ (g_date_time_get_day_of_month(a1.begin.get()), i); + g_variant_get_child (v, 1, "i", &i); + EXPECT_EQ (g_date_time_get_day_of_month(a2.begin.get()), i); + g_clear_pointer(&v, g_variant_unref); + g_clear_pointer(&calendar_state, g_variant_unref); + + // cleanup this step + g_date_time_unref (next_end); + g_date_time_unref (next_begin); + g_date_time_unref (tomorrow_end); + g_date_time_unref (tomorrow_begin); + g_date_time_unref (tomorrow); + + /// + /// Confirm that the action state's dictionary + /// keeps in sync with settings.show_week_numbers + /// + + auto b = m_state->settings->show_week_numbers.get(); + for (i=0; i<2; i++) + { + b = !b; + m_state->settings->show_week_numbers.set(b); + + calendar_state = g_action_group_get_action_state (action_group, "calendar"); + v = g_variant_lookup_value (calendar_state, "show-week-numbers", G_VARIANT_TYPE_BOOLEAN); + EXPECT_TRUE(v != nullptr); + EXPECT_EQ(b, g_variant_get_boolean(v)); + + g_clear_pointer(&v, g_variant_unref); + g_clear_pointer(&calendar_state, g_variant_unref); + } +} -- cgit v1.2.3 From cc2ad2ad457313cb87e4483bf0278f670a5a5cea Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:00:22 -0600 Subject: as per review, don't inline unless there are performance issues --- include/datetime/actions-live.h | 2 +- include/datetime/appointment.h | 12 +--------- include/datetime/date-time.h | 6 ++--- include/datetime/locations.h | 12 ++-------- include/datetime/menu.h | 2 +- include/datetime/timezone-file.h | 6 ++--- include/datetime/timezone.h | 1 - src/CMakeLists.txt | 1 + src/actions-live.cpp | 5 +++++ src/appointment.cpp | 48 ++++++++++++++++++++++++++++++++++++++++ src/date-time.cpp | 17 ++++++++++++++ src/locations.cpp | 8 +++++++ src/menu.cpp | 6 +++++ src/timezone-file.cpp | 14 ++++++++++++ 14 files changed, 110 insertions(+), 30 deletions(-) create mode 100644 src/appointment.cpp (limited to 'src/actions-live.cpp') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 949222d..3607836 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,7 +36,7 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(const std::shared_ptr& state_in): Actions(state_in) {} + LiveActions(const std::shared_ptr& state_in); ~LiveActions() =default; void open_desktop_settings(); diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index e034c08..a5283c9 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -45,17 +45,7 @@ public: DateTime begin; DateTime end; - bool operator== (const Appointment& that) const - { - return (color==that.color) && - (summary==that.summary) && - (url==that.url) && - (uid==that.uid) && - (is_event==that.is_event) && - (has_alarms==that.has_alarms) && - (begin==that.begin) && - (end==that.end); - } + bool operator== (const Appointment& that) const; }; } // namespace datetime diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index c2429eb..2ad7856 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -37,9 +37,9 @@ class DateTime public: static DateTime NowLocal(); explicit DateTime(time_t t); - explicit DateTime(GDateTime* in=nullptr) {reset(in);} - DateTime& operator=(GDateTime* in) {reset(in); return *this;} - DateTime& operator=(const DateTime& in) {m_dt=in.m_dt; return *this; } + explicit DateTime(GDateTime* in=nullptr); + DateTime& operator=(GDateTime* in); + DateTime& operator=(const DateTime& in); DateTime to_timezone(const std::string& zone) const; void reset(GDateTime* in=nullptr); diff --git a/include/datetime/locations.h b/include/datetime/locations.h index fc776bb..b840436 100644 --- a/include/datetime/locations.h +++ b/include/datetime/locations.h @@ -39,18 +39,10 @@ namespace datetime { class Location { public: + Location (const std::string& zone, const std::string& name); const std::string& zone() const; - const std::string& name() const; - - bool operator== (const Location& that) const - { - return (name() == that.name()) && - (zone() == that.zone()) && - (m_offset == that.m_offset); - } - - Location (const std::string& zone, const std::string& name); + bool operator== (const Location& that) const; private: diff --git a/include/datetime/menu.h b/include/datetime/menu.h index f097b02..526cd9f 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -48,7 +48,7 @@ public: GMenuModel* menu_model(); protected: - Menu (Profile profile_in, const std::string& name_in): m_profile(profile_in), m_name(name_in) {} + Menu (Profile profile_in, const std::string& name_in); virtual ~Menu() =default; GMenu* m_menu = nullptr; diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h index 7f47df6..d77aaae 100644 --- a/include/datetime/timezone-file.h +++ b/include/datetime/timezone-file.h @@ -37,9 +37,9 @@ namespace datetime { class FileTimezone: public Timezone { public: - FileTimezone() {} - FileTimezone(const std::string& filename) { setFilename(filename); } - ~FileTimezone() {clear();} + FileTimezone(); + FileTimezone(const std::string& filename); + ~FileTimezone(); private: void setFilename(const std::string& filename); diff --git a/include/datetime/timezone.h b/include/datetime/timezone.h index ffa5a84..7d2ace8 100644 --- a/include/datetime/timezone.h +++ b/include/datetime/timezone.h @@ -35,7 +35,6 @@ protected: Timezone() =default; public: - //virtual ~Timezone() {} core::Property timezone; }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb716d4..d5236ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ endif () add_library (${SERVICE_LIB} STATIC actions.cpp actions-live.cpp + appointment.cpp clock.cpp clock-live.cpp date-time.cpp diff --git a/src/actions-live.cpp b/src/actions-live.cpp index afd83f4..c0fd8ff 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -31,6 +31,11 @@ namespace datetime { **** ***/ +LiveActions::LiveActions(const std::shared_ptr& state_in): + Actions(state_in) +{ +} + void LiveActions::execute_command(const std::string& cmdstr) { const auto cmd = cmdstr.c_str(); diff --git a/src/appointment.cpp b/src/appointment.cpp new file mode 100644 index 0000000..6e742c3 --- /dev/null +++ b/src/appointment.cpp @@ -0,0 +1,48 @@ +/* + * 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 + +namespace unity { +namespace indicator { +namespace datetime { + +/**** +***** +****/ + +bool Appointment::operator==(const Appointment& that) const +{ + return (color==that.color) + && (summary==that.summary) + && (url==that.url) + && (uid==that.uid) + && (is_event==that.is_event) + && (has_alarms==that.has_alarms) + && (begin==that.begin) + && (end==that.end); +} + +/**** +***** +****/ + +} // namespace datetime +} // namespace indicator +} // namespace unity diff --git a/src/date-time.cpp b/src/date-time.cpp index 40c638f..a634c5e 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -27,6 +27,23 @@ namespace datetime { **** ***/ +DateTime::DateTime(GDateTime* gdt) +{ + reset(gdt); +} + +DateTime& DateTime::operator=(GDateTime* gdt) +{ + reset(gdt); + return *this; +} + +DateTime& DateTime::operator=(const DateTime& that) +{ + m_dt = that.m_dt; + return *this; +} + DateTime::DateTime(time_t t) { GDateTime * gdt = g_date_time_new_from_unix_local(t); diff --git a/src/locations.cpp b/src/locations.cpp index 8d1a086..c59f988 100644 --- a/src/locations.cpp +++ b/src/locations.cpp @@ -35,6 +35,14 @@ const std::string& Location::name() const return m_name; } +bool Location::operator== (const Location& that) const +{ + return (m_name == that.m_name) + && (m_zone == that.m_zone) + && (m_offset == that.m_offset); +} + + Location::Location(const std::string& zone_, const std::string& name_): m_zone(zone_), m_name(name_) diff --git a/src/menu.cpp b/src/menu.cpp index 4bb4fb6..b263520 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -35,6 +35,12 @@ namespace datetime { ***** ****/ +Menu::Menu (Profile profile_in, const std::string& name_in): + m_profile(profile_in), + m_name(name_in) +{ +} + const std::string& Menu::name() const { return m_name; diff --git a/src/timezone-file.cpp b/src/timezone-file.cpp index 3a0c240..76737b4 100644 --- a/src/timezone-file.cpp +++ b/src/timezone-file.cpp @@ -23,6 +23,20 @@ namespace unity { namespace indicator { namespace datetime { +FileTimezone::FileTimezone() +{ +} + +FileTimezone::FileTimezone(const std::string& filename) +{ + setFilename(filename); +} + +FileTimezone::~FileTimezone() +{ + clear(); +} + void FileTimezone::clear() { -- cgit v1.2.3