aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-03-22 02:25:50 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-03-22 02:25:50 -0500
commit18013dbb911de3d71ad679f697490f161ec19a34 (patch)
tree2289f056757002282a725da3327b5894f99829d2 /src
parent71f97cd047f58ca93303f0262f65fb48682b2e70 (diff)
downloadayatana-indicator-datetime-18013dbb911de3d71ad679f697490f161ec19a34.tar.gz
ayatana-indicator-datetime-18013dbb911de3d71ad679f697490f161ec19a34.tar.bz2
ayatana-indicator-datetime-18013dbb911de3d71ad679f697490f161ec19a34.zip
make the phone and desktop actions more consistent with each other; eg, 'indicator.desktop.open-calendar-app' + 'indicator.phone.open-calendar-app'
Diffstat (limited to 'src')
-rw-r--r--src/actions-live.cpp53
-rw-r--r--src/actions.cpp116
-rw-r--r--src/menu.cpp56
3 files changed, 133 insertions, 92 deletions
diff --git a/src/actions-live.cpp b/src/actions-live.cpp
index 97b12db..068abe7 100644
--- a/src/actions-live.cpp
+++ b/src/actions-live.cpp
@@ -51,6 +51,7 @@ void LiveActions::execute_command(const std::string& cmdstr)
void LiveActions::dispatch_url(const std::string& url)
{
+ g_debug("Dispatching url '%s'", url.c_str());
url_dispatch_send(url.c_str(), nullptr, nullptr);
}
@@ -58,7 +59,7 @@ void LiveActions::dispatch_url(const std::string& url)
****
***/
-void LiveActions::open_desktop_settings()
+void LiveActions::desktop_open_settings_app()
{
auto path = g_find_program_in_path("unity-control-center");
@@ -74,7 +75,7 @@ void LiveActions::open_desktop_settings()
g_free (path);
}
-bool LiveActions::can_open_planner() const
+bool LiveActions::desktop_has_calendar_app() const
{
static bool inited = false;
static bool have_calendar = false;
@@ -98,22 +99,17 @@ bool LiveActions::can_open_planner() const
return have_calendar;
}
-void LiveActions::open_planner()
+void LiveActions::desktop_open_alarm_app()
{
execute_command("evolution -c calendar");
}
-void LiveActions::open_phone_settings()
+void LiveActions::desktop_open_appointment(const Appointment& appt)
{
- dispatch_url("settings:///system/time-date");
-}
-
-void LiveActions::open_phone_clock_app()
-{
- dispatch_url("appid://com.ubuntu.clock/clock/current-user-version");
+ desktop_open_calendar_app(appt.begin);
}
-void LiveActions::open_planner_at(const DateTime& dt)
+void LiveActions::desktop_open_calendar_app(const DateTime& dt)
{
const auto day_begins = dt.add_full(0, 0, 0, -dt.hour(), -dt.minute(), -dt.seconds());
const auto gmt = day_begins.to_timezone("UTC");
@@ -121,17 +117,34 @@ void LiveActions::open_planner_at(const DateTime& dt)
execute_command(cmd.c_str());
}
-void LiveActions::open_appointment(const std::string& uid)
+/***
+****
+***/
+
+void LiveActions::phone_open_alarm_app()
{
- for(const auto& appt : state()->calendar_upcoming->appointments().get())
- {
- if(appt.uid != uid)
- continue;
+ dispatch_url("appid://com.ubuntu.clock/clock/current-user-version");
+}
- if (!appt.url.empty())
- dispatch_url(appt.url);
- break;
- }
+void LiveActions::phone_open_appointment(const Appointment& appt)
+{
+ if (!appt.url.empty())
+ dispatch_url(appt.url);
+ else if (appt.has_alarms)
+ phone_open_alarm_app();
+ else
+ phone_open_calendar_app(DateTime::NowLocal());
+}
+
+void LiveActions::phone_open_calendar_app(const DateTime&)
+{
+ // does calendar app have a mechanism for specifying dates?
+ dispatch_url("appid://com.ubuntu.calendar/calendar/current-user-version");
+}
+
+void LiveActions::phone_open_settings_app()
+{
+ dispatch_url("settings:///system/time-date");
}
/***
diff --git a/src/actions.cpp b/src/actions.cpp
index dc9a34b..31b3394 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -34,67 +34,81 @@ namespace datetime {
namespace
{
-void on_desktop_settings_activated(GSimpleAction * /*action*/,
- GVariant * /*param*/,
- gpointer gself)
+DateTime datetime_from_timet_variant(GVariant* v)
{
- static_cast<Actions*>(gself)->open_desktop_settings();
-}
+ int64_t t = 0;
-void on_phone_settings_activated(GSimpleAction * /*action*/,
- GVariant * /*param*/,
- gpointer gself)
-{
- static_cast<Actions*>(gself)->open_phone_settings();
-}
+ if (v != nullptr)
+ if (g_variant_type_equal(G_VARIANT_TYPE_INT64,g_variant_get_type(v)))
+ t = g_variant_get_int64(v);
-void on_phone_clock_activated(GSimpleAction * /*action*/,
- GVariant * /*param*/,
- gpointer gself)
-{
- static_cast<Actions*>(gself)->open_phone_clock_app();
+ if (t != 0)
+ return DateTime(t);
+ else
+ return DateTime::NowLocal();
}
-void on_activate_appointment(GSimpleAction * /*action*/,
- GVariant * param,
- gpointer gself)
+bool lookup_appointment_by_uid_variant(const std::shared_ptr<State>& state, GVariant* vuid, Appointment& setme)
{
- const auto uid = g_variant_get_string(param, nullptr);
- auto self = static_cast<Actions*>(gself);
-
- g_return_if_fail(uid && *uid);
+ g_return_val_if_fail(vuid != nullptr, false);
+ g_return_val_if_fail(g_variant_type_equal(G_VARIANT_TYPE_STRING,g_variant_get_type(vuid)), false);
+ const auto uid = g_variant_get_string(vuid, nullptr);
+ g_return_val_if_fail(uid && *uid, false);
- // find url of the upcoming appointment with this uid
- for (const auto& appt : self->state()->calendar_upcoming->appointments().get())
+ for(const auto& appt : state->calendar_upcoming->appointments().get())
{
if (appt.uid == uid)
{
- const auto url = appt.url;
- g_debug("%s: uid[%s] -> url[%s]", G_STRFUNC, uid, url.c_str());
- self->open_appointment(url);
- break;
+ setme = appt;
+ return true;
}
}
+
+ return false;
}
-void on_activate_planner(GSimpleAction * /*action*/,
- GVariant * param,
- gpointer gself)
+void on_desktop_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself)
{
- const auto at = g_variant_get_int64(param);
auto self = static_cast<Actions*>(gself);
+ Appointment appt;
+ if (lookup_appointment_by_uid_variant(self->state(), vuid, appt))
+ self->desktop_open_appointment(appt);
+}
+void on_desktop_alarm_activated (GSimpleAction*, GVariant*, gpointer gself)
+{
+ static_cast<Actions*>(gself)->desktop_open_alarm_app();
+}
+void on_desktop_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself)
+{
+ const auto dt = datetime_from_timet_variant(vt);
+ static_cast<Actions*>(gself)->desktop_open_calendar_app(dt);
+}
+void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself)
+{
+ static_cast<Actions*>(gself)->desktop_open_settings_app();
+}
- if (at)
- {
- auto gdt = g_date_time_new_from_unix_local(at);
- self->open_planner_at(DateTime(gdt));
- g_date_time_unref(gdt);
- }
- else // no time specified...
- {
- self->open_planner();
- }
+void on_phone_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself)
+{
+ auto self = static_cast<Actions*>(gself);
+ Appointment appt;
+ if (lookup_appointment_by_uid_variant(self->state(), vuid, appt))
+ self->phone_open_appointment(appt);
+}
+void on_phone_alarm_activated (GSimpleAction*, GVariant*, gpointer gself)
+{
+ static_cast<Actions*>(gself)->phone_open_alarm_app();
}
+void on_phone_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself)
+{
+ const auto dt = datetime_from_timet_variant(vt);
+ static_cast<Actions*>(gself)->phone_open_calendar_app(dt);
+}
+void on_phone_settings_activated (GSimpleAction*, GVariant*, gpointer gself)
+{
+ static_cast<Actions*>(gself)->phone_open_settings_app();
+}
+
void on_set_location(GSimpleAction * /*action*/,
GVariant * param,
@@ -183,11 +197,17 @@ Actions::Actions(const std::shared_ptr<State>& state):
m_actions(g_simple_action_group_new())
{
GActionEntry entries[] = {
- { "desktop.open-settings", on_desktop_settings_activated },
- { "phone.open-settings", on_phone_settings_activated },
- { "activate-phone-clock-app", on_phone_clock_activated },
- { "activate-appointment", on_activate_appointment, "s", nullptr },
- { "activate-planner", on_activate_planner, "x", nullptr },
+
+ { "desktop.open-appointment", on_desktop_appointment_activated, "s", nullptr },
+ { "desktop.open-alarm-app", on_desktop_alarm_activated },
+ { "desktop.open-calendar-app", on_desktop_calendar_activated, "x", nullptr },
+ { "desktop.open-settings-app", on_desktop_settings_activated },
+
+ { "phone.open-appointment", on_phone_appointment_activated, "s", nullptr },
+ { "phone.open-alarm-app", on_phone_alarm_activated },
+ { "phone.open-calendar-app", on_phone_calendar_activated, "x", nullptr },
+ { "phone.open-settings-app", on_phone_settings_activated },
+
{ "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed },
{ "set-location", on_set_location, "s" }
};
diff --git a/src/menu.cpp b/src/menu.cpp
index 9091951..ff5b722 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -225,22 +225,28 @@ private:
GMenuModel* create_calendar_section(Profile profile)
{
- const bool allow_activation = (profile == Desktop)
- || (profile == Phone);
const bool show_calendar = m_state->settings->show_calendar.get() &&
((profile == Desktop) || (profile == DesktopGreeter));
auto menu = g_menu_new();
+ const char * action_name;
+
+ if (profile == Phone)
+ action_name = "indicator.phone.open-calendar-app";
+ else if (profile == Desktop)
+ action_name = "indicator.desktop.open-calendar-app";
+ else
+ action_name = nullptr;
+
// add a menuitem that shows the current date
auto label = m_state->clock->localtime().format(_("%A, %e %B %Y"));
auto item = g_menu_item_new (label.c_str(), nullptr);
auto v = get_serialized_calendar_icon();
g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, v);
- if (allow_activation)
+ if (action_name != nullptr)
{
v = g_variant_new_int64(0);
- const char* action = "indicator.activate-planner";
- g_menu_item_set_action_and_target_value (item, action, v);
+ g_menu_item_set_action_and_target_value (item, action_name, v);
}
g_menu_append_item(menu, item);
g_object_unref(item);
@@ -253,11 +259,8 @@ private:
g_menu_item_set_action_and_target_value (item, "indicator.calendar", v);
g_menu_item_set_attribute (item, "x-canonical-type",
"s", "com.canonical.indicator.calendar");
- if (allow_activation)
- {
- g_menu_item_set_attribute (item, "activation-action",
- "s", "indicator.activate-planner");
- }
+ if (action_name != nullptr)
+ g_menu_item_set_attribute (item, "activation-action", "s", action_name);
g_menu_append_item (menu, item);
g_object_unref (item);
}
@@ -270,6 +273,15 @@ private:
const int MAX_APPTS = 5;
std::set<std::string> added;
+ const char * action_name;
+
+ if (profile == Phone)
+ action_name = "indicator.phone.open-appointment";
+ else if ((profile == Desktop) && m_actions->desktop_has_calendar_app())
+ action_name = "indicator.desktop.open-appointment";
+ else
+ action_name = nullptr;
+
for (const auto& appt : m_upcoming)
{
// don't show duplicates
@@ -303,15 +315,11 @@ private:
if (!appt.color.empty())
g_menu_item_set_attribute (menu_item, "x-canonical-color", "s", appt.color.c_str());
-
- if (profile == Phone)
- g_menu_item_set_action_and_target_value (menu_item,
- "indicator.activate-appointment",
- g_variant_new_string (appt.uid.c_str()));
- else if (m_actions->can_open_planner())
- g_menu_item_set_action_and_target_value (menu_item,
- "indicator.activate-planner",
- g_variant_new_int64 (unix_time));
+
+ if (action_name != nullptr)
+ g_menu_item_set_action_and_target_value (menu_item, action_name,
+ g_variant_new_string (appt.uid.c_str()));
+
g_menu_append_item (menu, menu_item);
g_object_unref (menu_item);
}
@@ -325,11 +333,11 @@ private:
{
add_appointments (menu, profile);
- if (m_actions->can_open_planner())
+ if (m_actions->desktop_has_calendar_app())
{
// add the 'Add Event…' menuitem
auto menu_item = g_menu_item_new(_("Add Event…"), nullptr);
- const gchar* action_name = "indicator.activate-planner";
+ const gchar* action_name = "indicator.desktop.open-calendar-app";
auto v = g_variant_new_int64(0);
g_menu_item_set_action_and_target_value(menu_item, action_name, v);
g_menu_append_item(menu, menu_item);
@@ -338,7 +346,7 @@ private:
}
else if (profile==Phone)
{
- auto menu_item = g_menu_item_new (_("Clock"), "indicator.activate-phone-clock-app");
+ auto menu_item = g_menu_item_new (_("Clock"), "indicator.phone.open-alarm-app");
g_menu_item_set_attribute_value (menu_item, G_MENU_ATTRIBUTE_ICON, get_serialized_alarm_icon());
g_menu_append_item (menu, menu_item);
g_object_unref (menu_item);
@@ -383,11 +391,11 @@ private:
if (profile == Desktop)
{
- g_menu_append (menu, _("Date & Time Settings…"), "indicator.desktop.open-settings");
+ g_menu_append (menu, _("Date & Time Settings…"), "indicator.desktop.open-settings-app");
}
else if (profile == Phone)
{
- g_menu_append (menu, _("Time & Date settings…"), "indicator.phone.open-settings");
+ g_menu_append (menu, _("Time & Date settings…"), "indicator.phone.open-settings-app");
}
return G_MENU_MODEL (menu);