aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/im-accounts-service.c223
-rw-r--r--src/im-accounts-service.h53
-rw-r--r--src/im-application-list.c169
-rw-r--r--src/im-desktop-menu.c9
-rw-r--r--src/im-menu.c33
-rw-r--r--src/im-menu.h2
-rw-r--r--src/im-phone-menu.c13
-rw-r--r--src/im-phone-menu.h3
-rw-r--r--src/messages-service.c4
10 files changed, 474 insertions, 37 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index bc674c2..36e6a93 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,8 @@ indicator_messages_service_SOURCES = \
gactionmuxer.h \
gsettingsstrv.c \
gsettingsstrv.h \
+ im-accounts-service.c \
+ im-accounts-service.h \
im-menu.c \
im-menu.h \
im-phone-menu.c \
diff --git a/src/im-accounts-service.c b/src/im-accounts-service.c
new file mode 100644
index 0000000..b7ab15d
--- /dev/null
+++ b/src/im-accounts-service.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright © 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Ted Gould <ted@canonical.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <act/act.h>
+
+#include "im-accounts-service.h"
+
+typedef struct _ImAccountsServicePrivate ImAccountsServicePrivate;
+
+struct _ImAccountsServicePrivate {
+ ActUserManager * user_manager;
+ GDBusProxy * touch_settings;
+ GCancellable * cancel;
+};
+
+#define IM_ACCOUNTS_SERVICE_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((o), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsServicePrivate))
+
+static void im_accounts_service_class_init (ImAccountsServiceClass *klass);
+static void im_accounts_service_init (ImAccountsService *self);
+static void im_accounts_service_dispose (GObject *object);
+static void im_accounts_service_finalize (GObject *object);
+static void user_changed (ActUserManager * manager, ActUser * user, gpointer user_data);
+static void on_user_manager_loaded (ActUserManager * manager, GParamSpec * pspect, gpointer user_data);
+static void security_privacy_ready (GObject * obj, GAsyncResult * res, gpointer user_data);
+
+G_DEFINE_TYPE (ImAccountsService, im_accounts_service, G_TYPE_OBJECT);
+
+static void
+im_accounts_service_class_init (ImAccountsServiceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ImAccountsServicePrivate));
+
+ object_class->dispose = im_accounts_service_dispose;
+ object_class->finalize = im_accounts_service_finalize;
+}
+
+static void
+im_accounts_service_init (ImAccountsService *self)
+{
+ ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(self);
+
+ priv->cancel = g_cancellable_new();
+
+ priv->user_manager = act_user_manager_get_default();
+ g_signal_connect(priv->user_manager, "user-changed", G_CALLBACK(user_changed), self);
+ g_signal_connect(priv->user_manager, "notify::is-loaded", G_CALLBACK(on_user_manager_loaded), self);
+
+ gboolean isLoaded = FALSE;
+ g_object_get(G_OBJECT(priv->user_manager), "is-loaded", &isLoaded, NULL);
+ if (isLoaded) {
+ on_user_manager_loaded(priv->user_manager, NULL, NULL);
+ }
+}
+
+static void
+im_accounts_service_dispose (GObject *object)
+{
+ ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(object);
+
+ if (priv->cancel != NULL) {
+ g_cancellable_cancel(priv->cancel);
+ g_clear_object(&priv->cancel);
+ }
+
+ g_clear_object(&priv->user_manager);
+
+ G_OBJECT_CLASS (im_accounts_service_parent_class)->dispose (object);
+}
+
+static void
+im_accounts_service_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (im_accounts_service_parent_class)->finalize (object);
+}
+
+/* Handles a User getting updated */
+static void
+user_changed (ActUserManager * manager, ActUser * user, gpointer user_data)
+{
+ if (g_strcmp0(act_user_get_user_name(user), g_get_user_name()) != 0) {
+ return;
+ }
+
+ ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(user_data);
+ g_debug("User Updated");
+
+ /* Clear old proxies */
+ g_clear_object(&priv->touch_settings);
+
+ /* Start getting a new proxy */
+ g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.Accounts",
+ act_user_get_object_path(user),
+ "com.ubuntu.touch.AccountsService.SecurityPrivacy",
+ priv->cancel,
+ security_privacy_ready,
+ user_data);
+}
+
+/* Respond to the async of setting up the proxy. Mostly we get it or we error. */
+static void
+security_privacy_ready (GObject * obj, GAsyncResult * res, gpointer user_data)
+{
+ GError * error = NULL;
+ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
+
+ if (error != NULL) {
+ g_warning("Unable to get a proxy on accounts service for touch settings: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(user_data);
+ /* Ensure we didn't get a proxy while we weren't looking */
+ g_clear_object(&priv->touch_settings);
+ priv->touch_settings = proxy;
+}
+
+/* When the user manager is loaded see if we have a user already loaded
+ along with. */
+static void
+on_user_manager_loaded (ActUserManager * manager, GParamSpec * pspect, gpointer user_data)
+{
+ ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(user_data);
+ ActUser * user = NULL;
+
+ g_debug("Accounts Manager Loaded");
+
+ user = act_user_manager_get_user(priv->user_manager, g_get_user_name());
+ if (user != NULL) {
+ user_changed(priv->user_manager, user, user_data);
+ g_object_unref(user);
+ }
+}
+
+/* Not the most testable way to do this but, it is a less invasive one, and we'll
+ probably restructure this codebase soonish */
+/* Gets an account service wrapper reference, so then it can be free'd */
+ImAccountsService *
+im_accounts_service_ref_default (void)
+{
+ static ImAccountsService * as = NULL;
+ if (as == NULL) {
+ as = IM_ACCOUNTS_SERVICE(g_object_new(IM_ACCOUNTS_SERVICE_TYPE, NULL));
+ g_object_add_weak_pointer(G_OBJECT(as), (gpointer *)&as);
+ return as;
+ }
+
+ return g_object_ref(as);
+}
+
+/* The draws attention setting is very legacy right now, we've patched and not changed
+ things much. We're gonna do better in the future, this function abstracts out the ugly */
+void
+im_accounts_service_set_draws_attention (ImAccountsService * service, gboolean draws_attention)
+{
+ g_return_if_fail(IM_IS_ACCOUNTS_SERVICE(service));
+ ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(service);
+
+ if (priv->touch_settings == NULL) {
+ return;
+ }
+
+ g_dbus_connection_call(g_dbus_proxy_get_connection(priv->touch_settings),
+ g_dbus_proxy_get_name(priv->touch_settings),
+ g_dbus_proxy_get_object_path(priv->touch_settings),
+ "org.freedesktop.Accounts.User",
+ "SetXHasMessages",
+ g_variant_new("(b)", draws_attention),
+ NULL, /* reply */
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout */
+ priv->cancel, /* cancellable */
+ NULL, NULL); /* cb */
+}
+
+/* Looks at the property that is set by settings. We default to off in any case
+ that we can or we don't know what the state is. */
+gboolean
+im_accounts_service_get_show_on_greeter (ImAccountsService * service)
+{
+ g_return_val_if_fail(IM_IS_ACCOUNTS_SERVICE(service), FALSE);
+
+ ImAccountsServicePrivate * priv = IM_ACCOUNTS_SERVICE_GET_PRIVATE(service);
+
+ if (priv->touch_settings == NULL) {
+ return FALSE;
+ }
+
+ GVariant * val = g_dbus_proxy_get_cached_property(priv->touch_settings, "MessagesWelcomeScreen");
+ if (val == NULL) {
+ return FALSE;
+ }
+
+ gboolean retval = g_variant_get_boolean(val);
+ g_variant_unref(val);
+ return retval;
+}
diff --git a/src/im-accounts-service.h b/src/im-accounts-service.h
new file mode 100644
index 0000000..d7611d8
--- /dev/null
+++ b/src/im-accounts-service.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Ted Gould <ted@canonical.com>
+ */
+
+#ifndef __IM_ACCOUNTS_SERVICE_H__
+#define __IM_ACCOUNTS_SERVICE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define IM_ACCOUNTS_SERVICE_TYPE (im_accounts_service_get_type ())
+#define IM_ACCOUNTS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsService))
+#define IM_ACCOUNTS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsServiceClass))
+#define IM_IS_ACCOUNTS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_ACCOUNTS_SERVICE_TYPE))
+#define IM_IS_ACCOUNTS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_ACCOUNTS_SERVICE_TYPE))
+#define IM_ACCOUNTS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_ACCOUNTS_SERVICE_TYPE, ImAccountsServiceClass))
+
+typedef struct _ImAccountsService ImAccountsService;
+typedef struct _ImAccountsServiceClass ImAccountsServiceClass;
+
+struct _ImAccountsServiceClass {
+ GObjectClass parent_class;
+};
+
+struct _ImAccountsService {
+ GObject parent;
+};
+
+GType im_accounts_service_get_type (void);
+ImAccountsService * im_accounts_service_ref_default (void);
+void im_accounts_service_set_draws_attention (ImAccountsService * service, gboolean draws_attention);
+gboolean im_accounts_service_get_show_on_greeter (ImAccountsService * service);
+
+G_END_DECLS
+
+#endif
diff --git a/src/im-application-list.c b/src/im-application-list.c
index 931e9ad..36b2ff3 100644
--- a/src/im-application-list.c
+++ b/src/im-application-list.c
@@ -22,6 +22,7 @@
#include "indicator-messages-application.h"
#include "gactionmuxer.h"
#include "indicator-desktop-shortcuts.h"
+#include "im-accounts-service.h"
#include <gio/gdesktopappinfo.h>
#include <string.h>
@@ -41,6 +42,8 @@ struct _ImApplicationList
GSimpleAction * statusaction;
GHashTable *app_status;
+
+ ImAccountsService * as;
};
G_DEFINE_TYPE (ImApplicationList, im_application_list, G_TYPE_OBJECT);
@@ -131,6 +134,62 @@ _g_action_group_has_actions (GActionGroup * ag)
return retval;
}
+static gchar *
+escape_action_name (const gchar *name)
+{
+ static const gchar *xdigits = "0123456789abcdef";
+ GString *escaped;
+ gchar c;
+
+ g_return_val_if_fail (name != NULL, NULL);
+
+ escaped = g_string_new (NULL);
+ while ((c = *name++))
+ {
+ if (g_ascii_isalnum (c) || c == '.')
+ {
+ g_string_append_c (escaped, c);
+ }
+ else
+ {
+ g_string_append_c (escaped, '-');
+ g_string_append_c (escaped, xdigits[c >> 4]);
+ g_string_append_c (escaped, xdigits[c & 0xf]);
+ }
+ }
+
+ return g_string_free (escaped, FALSE);
+}
+
+static gchar *
+unescape_action_name (const gchar *name)
+{
+ GString *unescaped;
+ gint i;
+
+ g_return_val_if_fail (name != NULL, NULL);
+
+ unescaped = g_string_new (NULL);
+ for (i = 0; name[i]; i++)
+ {
+ gint one, two;
+
+ if (name[i] == '-' &&
+ (one = g_ascii_xdigit_value (name[i + 1])) >= 0 &&
+ (two = g_ascii_xdigit_value (name[i + 2])) >= 0)
+ {
+ g_string_append_c (unescaped, (one << 4) | two);
+ i += 2;
+ }
+ else
+ {
+ g_string_append_c (unescaped, name[i]);
+ }
+ }
+
+ return g_string_free (unescaped, FALSE);
+}
+
/* Check to see if either of our action groups has any actions, if
so return TRUE so we get chosen! */
static gboolean
@@ -170,9 +229,11 @@ im_application_list_update_root_action (ImApplicationList *list)
if (g_hash_table_find (list->applications, application_draws_attention, NULL)) {
base_icon_name = "indicator-messages-new-%s";
accessible_name = _("New Messages");
+ im_accounts_service_set_draws_attention(list->as, TRUE);
} else {
base_icon_name = "indicator-messages-%s";
accessible_name = _("Messages");
+ im_accounts_service_set_draws_attention(list->as, FALSE);
}
/* Include the IM state in the icon */
@@ -284,18 +345,30 @@ application_update_draws_attention (Application * app)
return was_drawing_attention != app->draws_attention;
}
+static void
+im_application_list_source_removed_action (Application *app,
+ const gchar *action_name)
+{
+ g_action_map_remove_action (G_ACTION_MAP(app->source_actions), action_name);
+ g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, action_name);
+
+ if (application_update_draws_attention(app))
+ im_application_list_update_root_action (app->list);
+}
+
/* Remove a source from an application, signal up and update the status
of the draws attention flag. */
static void
im_application_list_source_removed (Application *app,
const gchar *id)
{
- g_action_map_remove_action (G_ACTION_MAP(app->source_actions), id);
+ gchar *action_name;
- g_signal_emit (app->list, signals[SOURCE_REMOVED], 0, app->id, id);
+ action_name = escape_action_name (id);
- if (application_update_draws_attention(app))
- im_application_list_update_root_action (app->list);
+ im_application_list_source_removed_action (app, action_name);
+
+ g_free (action_name);
}
static void
@@ -304,9 +377,11 @@ im_application_list_source_activated (GSimpleAction *action,
gpointer user_data)
{
Application *app = user_data;
- const gchar *source_id;
+ const gchar *action_name;
+ gchar *source_id;
- source_id = g_action_get_name (G_ACTION (action));
+ action_name = g_action_get_name (G_ACTION (action));
+ source_id = unescape_action_name (action_name);
if (g_variant_get_boolean (parameter))
{
@@ -323,20 +398,35 @@ im_application_list_source_activated (GSimpleAction *action,
app->cancellable, NULL, NULL);
}
- im_application_list_source_removed (app, source_id);
+ im_application_list_source_removed_action (app, action_name);
+
+ g_free (source_id);
}
static void
-im_application_list_message_removed (Application *app,
- const gchar *id)
+im_application_list_message_removed_action (Application *app,
+ const gchar *action_name)
{
- g_action_map_remove_action (G_ACTION_MAP(app->message_actions), id);
- g_action_muxer_remove (app->message_sub_actions, id);
+ g_action_map_remove_action (G_ACTION_MAP(app->message_actions), action_name);
+ g_action_muxer_remove (app->message_sub_actions, action_name);
if (application_update_draws_attention(app))
im_application_list_update_root_action (app->list);
- g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id);
+ g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, action_name);
+}
+
+static void
+im_application_list_message_removed (Application *app,
+ const gchar *id)
+{
+ gchar *action_name;
+
+ action_name = escape_action_name (id);
+
+ im_application_list_message_removed_action(app, action_name);
+
+ g_free (action_name);
}
static void
@@ -345,9 +435,11 @@ im_application_list_message_activated (GSimpleAction *action,
gpointer user_data)
{
Application *app = user_data;
- const gchar *message_id;
+ const gchar *action_name;
+ gchar *message_id;
- message_id = g_action_get_name (G_ACTION (action));
+ action_name = g_action_get_name (G_ACTION (action));
+ message_id = unescape_action_name (action_name);
if (g_variant_get_boolean (parameter))
{
@@ -366,7 +458,9 @@ im_application_list_message_activated (GSimpleAction *action,
app->cancellable, NULL, NULL);
}
- im_application_list_message_removed (app, message_id);
+ im_application_list_message_removed_action (app, action_name);
+
+ g_free (message_id);
}
static void
@@ -376,11 +470,11 @@ im_application_list_sub_message_activated (GSimpleAction *action,
{
Application *app = user_data;
const gchar *message_id;
- const gchar *action_id;
+ gchar *action_id;
GVariantBuilder builder;
message_id = g_object_get_data (G_OBJECT (action), "message");
- action_id = g_action_get_name (G_ACTION (action));
+ action_id = unescape_action_name (g_action_get_name (G_ACTION (action)));
g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
if (parameter)
@@ -394,6 +488,8 @@ im_application_list_sub_message_activated (GSimpleAction *action,
NULL, NULL);
im_application_list_message_removed (app, message_id);
+
+ g_free (action_id);
}
static void
@@ -418,11 +514,11 @@ im_application_list_remove_all (GSimpleAction *action,
source_actions = g_action_group_list_actions (G_ACTION_GROUP (app->source_actions));
for (it = source_actions; *it; it++)
- im_application_list_source_removed (app, *it);
+ im_application_list_source_removed_action (app, *it);
message_actions = g_action_group_list_actions (G_ACTION_GROUP (app->message_actions));
for (it = message_actions; *it; it++)
- im_application_list_message_removed (app, *it);
+ im_application_list_message_removed_action (app, *it);
if (app->proxy != NULL) /* If it is remote, we tell the app we've cleared */
{
@@ -451,6 +547,8 @@ im_application_list_dispose (GObject *object)
g_clear_pointer (&list->applications, g_hash_table_unref);
g_clear_object (&list->muxer);
+ g_clear_object (&list->as);
+
G_OBJECT_CLASS (im_application_list_parent_class)->dispose (object);
}
@@ -602,6 +700,8 @@ im_application_list_init (ImApplicationList *list)
list->muxer = g_action_muxer_new ();
g_action_muxer_insert (list->muxer, NULL, G_ACTION_GROUP (list->globalactions));
+ list->as = im_accounts_service_ref_default();
+
im_application_list_update_root_action (list);
}
@@ -792,6 +892,7 @@ im_application_list_source_added (Application *app,
GVariant *serialized_icon = NULL;
GVariant *state;
GSimpleAction *action;
+ gchar *action_name;
g_variant_get (source, "(&s&s@avux&sb)",
&id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention);
@@ -802,12 +903,13 @@ im_application_list_source_added (Application *app,
visible = count > 0 || time != 0 || (string != NULL && string[0] != '\0');
state = g_variant_new ("(uxsb)", count, time, string, draws_attention);
- action = g_simple_action_new_stateful (id, G_VARIANT_TYPE_BOOLEAN, state);
+ action_name = escape_action_name (id);
+ action = g_simple_action_new_stateful (action_name, G_VARIANT_TYPE_BOOLEAN, state);
g_signal_connect (action, "activate", G_CALLBACK (im_application_list_source_activated), app);
g_action_map_add_action (G_ACTION_MAP(app->source_actions), G_ACTION (action));
- g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, id, label, serialized_icon, visible);
+ g_signal_emit (app->list, signals[SOURCE_ADDED], 0, app->id, action_name, label, serialized_icon, visible);
if (visible && draws_attention && app->draws_attention == FALSE)
{
@@ -815,6 +917,7 @@ im_application_list_source_added (Application *app,
im_application_list_update_root_action (app->list);
}
+ g_free (action_name);
g_object_unref (action);
if (serialized_icon)
g_variant_unref (serialized_icon);
@@ -834,6 +937,7 @@ im_application_list_source_changed (Application *app,
gboolean draws_attention;
GVariant *serialized_icon = NULL;
gboolean visible;
+ gchar *action_name;
g_variant_get (source, "(&s&s@avux&sb)",
&id, &label, &maybe_serialized_icon, &count, &time, &string, &draws_attention);
@@ -841,12 +945,14 @@ im_application_list_source_changed (Application *app,
if (g_variant_n_children (maybe_serialized_icon) == 1)
g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon);
- g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), id,
+ action_name = escape_action_name (id);
+
+ g_action_group_change_action_state (G_ACTION_GROUP (app->source_actions), action_name,
g_variant_new ("(uxsb)", count, time, string, draws_attention));
visible = count > 0 || time != 0 || (string != NULL && string[0] != '\0');
- g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, id, label, serialized_icon, visible);
+ g_signal_emit (app->list, signals[SOURCE_CHANGED], 0, app->id, action_name, label, serialized_icon, visible);
if (application_update_draws_attention (app))
im_application_list_update_root_action (app->list);
@@ -854,6 +960,7 @@ im_application_list_source_changed (Application *app,
if (serialized_icon)
g_variant_unref (serialized_icon);
g_variant_unref (maybe_serialized_icon);
+ g_free (action_name);
}
static void
@@ -958,6 +1065,7 @@ im_application_list_message_added (Application *app,
GSimpleAction *action;
GIcon *app_icon;
GVariant *actions = NULL;
+ gchar *action_name;
g_variant_get (message, "(&s@av&s&s&sxaa{sv}b)",
&id, &maybe_serialized_icon, &title, &subtitle, &body, &time, &action_iter, &draws_attention);
@@ -965,7 +1073,8 @@ im_application_list_message_added (Application *app,
if (g_variant_n_children (maybe_serialized_icon) == 1)
g_variant_get_child (maybe_serialized_icon, 0, "v", &serialized_icon);
- action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN);
+ action_name = escape_action_name (id);
+ action = g_simple_action_new (action_name, G_VARIANT_TYPE_BOOLEAN);
g_object_set_qdata(G_OBJECT(action), message_action_draws_attention_quark(), GINT_TO_POINTER(draws_attention));
g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app);
g_action_map_add_action (G_ACTION_MAP(app->message_actions), G_ACTION (action));
@@ -987,6 +1096,7 @@ im_application_list_message_added (Application *app,
GVariant *hint;
GVariantBuilder dict_builder;
gchar *prefixed_name;
+ gchar *escaped_name;
if (!g_variant_lookup (entry, "name", "&s", &name))
{
@@ -998,14 +1108,15 @@ im_application_list_message_added (Application *app,
g_variant_lookup (entry, "parameter-type", "&g", &type);
hint = g_variant_lookup_value (entry, "parameter-hint", NULL);
- action = g_simple_action_new (name, type ? G_VARIANT_TYPE (type) : NULL);
+ escaped_name = escape_action_name (name);
+ action = g_simple_action_new (escaped_name, type ? G_VARIANT_TYPE (type) : NULL);
g_object_set_data_full (G_OBJECT (action), "message", g_strdup (id), g_free);
g_signal_connect (action, "activate", G_CALLBACK (im_application_list_sub_message_activated), app);
g_action_map_add_action (G_ACTION_MAP(action_group), G_ACTION (action));
g_variant_builder_init (&dict_builder, G_VARIANT_TYPE ("a{sv}"));
- prefixed_name = g_strjoin (".", app->id, "msg-actions", id, name, NULL);
+ prefixed_name = g_strjoin (".", app->id, "msg-actions", action_name, escaped_name, NULL);
g_variant_builder_add (&dict_builder, "{sv}", "name", g_variant_new_string (prefixed_name));
if (label)
@@ -1028,9 +1139,10 @@ im_application_list_message_added (Application *app,
g_object_unref (action);
g_variant_unref (entry);
g_free (prefixed_name);
+ g_free (escaped_name);
}
- g_action_muxer_insert (app->message_sub_actions, id, G_ACTION_GROUP (action_group));
+ g_action_muxer_insert (app->message_sub_actions, action_name, G_ACTION_GROUP (action_group));
actions = g_variant_builder_end (&actions_builder);
g_object_unref (action_group);
@@ -1045,9 +1157,10 @@ im_application_list_message_added (Application *app,
app_icon = get_symbolic_app_icon (app->info);
g_signal_emit (app->list, signals[MESSAGE_ADDED], 0,
- app->id, app_icon, id, serialized_icon, title,
+ app->id, app_icon, action_name, serialized_icon, title,
subtitle, body, actions, time, draws_attention);
+ g_free (action_name);
g_variant_iter_free (action_iter);
g_object_unref (action);
if (serialized_icon)
diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c
index 137e222..c762735 100644
--- a/src/im-desktop-menu.c
+++ b/src/im-desktop-menu.c
@@ -81,12 +81,15 @@ g_app_info_is_default_for_uri_scheme (GAppInfo *info,
const gchar *uri_scheme)
{
GAppInfo *default_info;
- gboolean is_default;
+ gboolean is_default = FALSE;
default_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
- is_default = g_app_info_equal (info, default_info);
+ if (default_info)
+ {
+ is_default = g_app_info_equal (info, default_info);
+ g_object_unref (default_info);
+ }
- g_object_unref (default_info);
return is_default;
}
diff --git a/src/im-menu.c b/src/im-menu.c
index 55d4685..0c39b97 100644
--- a/src/im-menu.c
+++ b/src/im-menu.c
@@ -18,12 +18,15 @@
*/
#include "im-menu.h"
+#include "im-accounts-service.h"
struct _ImMenuPrivate
{
GMenu *toplevel_menu;
GMenu *menu;
ImApplicationList *applist;
+ gboolean on_greeter;
+ ImAccountsService *as;
};
G_DEFINE_TYPE_WITH_PRIVATE (ImMenu, im_menu, G_TYPE_OBJECT)
@@ -32,6 +35,7 @@ enum
{
PROP_0,
PROP_APPLICATION_LIST,
+ PROP_ON_GREETER,
NUM_PROPERTIES
};
@@ -43,6 +47,7 @@ im_menu_finalize (GObject *object)
g_object_unref (priv->toplevel_menu);
g_object_unref (priv->menu);
g_object_unref (priv->applist);
+ g_object_unref (priv->as);
G_OBJECT_CLASS (im_menu_parent_class)->finalize (object);
}
@@ -60,6 +65,9 @@ im_menu_get_property (GObject *object,
case PROP_APPLICATION_LIST:
g_value_set_object (value, priv->applist);
break;
+ case PROP_ON_GREETER:
+ g_value_set_boolean (value, priv->on_greeter);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -79,6 +87,9 @@ im_menu_set_property (GObject *object,
case PROP_APPLICATION_LIST: /* construct only */
priv->applist = g_value_dup_object (value);
break;
+ case PROP_ON_GREETER:
+ priv->on_greeter = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -100,6 +111,12 @@ im_menu_class_init (ImMenuClass *class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_ON_GREETER,
+ g_param_spec_boolean ("on-greeter", "", "",
+ FALSE,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -110,6 +127,8 @@ im_menu_init (ImMenu *menu)
priv->toplevel_menu = g_menu_new ();
priv->menu = g_menu_new ();
+ priv->on_greeter = FALSE;
+ priv->as = im_accounts_service_ref_default();
root = g_menu_item_new (NULL, "indicator.messages");
g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root");
@@ -225,3 +244,17 @@ im_menu_insert_item_sorted (ImMenu *menu,
g_menu_insert_item (priv->menu, position, item);
}
+
+/* Whether the menu should show extra data on it. Depends on the greeter
+ status and user settings */
+gboolean
+im_menu_show_data (ImMenu *menu)
+{
+ g_return_val_if_fail (IM_IS_MENU (menu), FALSE);
+ ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (menu));
+
+ if (!priv->on_greeter)
+ return TRUE;
+
+ return im_accounts_service_get_show_on_greeter(priv->as);
+}
diff --git a/src/im-menu.h b/src/im-menu.h
index f67abc8..b76d616 100644
--- a/src/im-menu.h
+++ b/src/im-menu.h
@@ -64,4 +64,6 @@ void im_menu_insert_item_sorted (ImMenu
gint first,
gint last);
+gboolean im_menu_show_data (ImMenu *menu);
+
#endif
diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c
index 754fc2b..58a23ff 100644
--- a/src/im-phone-menu.c
+++ b/src/im-phone-menu.c
@@ -142,12 +142,13 @@ im_phone_menu_init (ImPhoneMenu *menu)
}
ImPhoneMenu *
-im_phone_menu_new (ImApplicationList *applist)
+im_phone_menu_new (ImApplicationList *applist, gboolean greeter)
{
g_return_val_if_fail (IM_IS_APPLICATION_LIST (applist), NULL);
return g_object_new (IM_TYPE_PHONE_MENU,
"application-list", applist,
+ "on-greeter", greeter,
NULL);
}
@@ -179,10 +180,12 @@ im_phone_menu_add_message (ImPhoneMenu *menu,
gint n_messages;
gint pos;
GVariant *serialized_app_icon;
+ gboolean show_data;
g_return_if_fail (IM_IS_PHONE_MENU (menu));
g_return_if_fail (app_id);
+ show_data = im_menu_show_data(IM_MENU (menu));
action_name = g_strconcat (app_id, ".msg.", id, NULL);
item = g_menu_item_new (title, NULL);
@@ -190,8 +193,10 @@ im_phone_menu_add_message (ImPhoneMenu *menu,
g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem");
g_menu_item_set_attribute (item, "x-canonical-message-id", "s", id);
- g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle);
- g_menu_item_set_attribute (item, "x-canonical-text", "s", body);
+ if (show_data)
+ g_menu_item_set_attribute (item, "x-canonical-subtitle", "s", subtitle);
+ if (show_data)
+ g_menu_item_set_attribute (item, "x-canonical-text", "s", body);
g_menu_item_set_attribute (item, "x-canonical-time", "x", time);
if (serialized_icon)
@@ -203,7 +208,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu,
g_variant_unref (serialized_app_icon);
}
- if (actions)
+ if (actions && show_data)
g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions);
n_messages = g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section));
diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h
index 4f96c8c..813634d 100644
--- a/src/im-phone-menu.h
+++ b/src/im-phone-menu.h
@@ -33,7 +33,8 @@ typedef struct _ImPhoneMenu ImPhoneMenu;
GType im_phone_menu_get_type (void);
-ImPhoneMenu * im_phone_menu_new (ImApplicationList *applist);
+ImPhoneMenu * im_phone_menu_new (ImApplicationList *applist,
+ gboolean greeter);
void im_phone_menu_add_message (ImPhoneMenu *menu,
const gchar *app_id,
diff --git a/src/messages-service.c b/src/messages-service.c
index d1ccbbc..d2c7e92 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -273,8 +273,10 @@ main (int argc, char ** argv)
}
menus = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
- g_hash_table_insert (menus, "phone", im_phone_menu_new (applications));
+ g_hash_table_insert (menus, "phone", im_phone_menu_new (applications, FALSE));
+ g_hash_table_insert (menus, "phone_greeter", im_phone_menu_new (applications, TRUE));
g_hash_table_insert (menus, "desktop", im_desktop_menu_new (applications));
+ g_hash_table_insert (menus, "desktop_greeter", im_desktop_menu_new (applications));
g_unix_signal_add(SIGTERM, sig_term_handler, mainloop);