diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/im-application-list.c | 94 | ||||
-rw-r--r-- | src/im-phone-menu.c | 11 | ||||
-rw-r--r-- | src/im-phone-menu.h | 1 |
3 files changed, 100 insertions, 6 deletions
diff --git a/src/im-application-list.c b/src/im-application-list.c index f0bf362..d4c5687 100644 --- a/src/im-application-list.c +++ b/src/im-application-list.c @@ -59,6 +59,7 @@ typedef struct GActionMuxer *actions; GSimpleActionGroup *source_actions; GSimpleActionGroup *message_actions; + GActionMuxer *message_sub_actions; GCancellable *cancellable; } Application; @@ -87,6 +88,7 @@ application_free (gpointer data) g_object_unref (app->actions); g_object_unref (app->source_actions); g_object_unref (app->message_actions); + g_object_unref (app->message_sub_actions); } g_slice_free (Application, app); @@ -134,6 +136,7 @@ im_application_list_message_removed (Application *app, const gchar *id) { g_simple_action_group_remove (app->message_actions, id); + g_action_muxer_remove (app->message_sub_actions, id); g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id); } @@ -152,6 +155,8 @@ im_application_list_message_activated (GSimpleAction *action, { indicator_messages_application_call_activate_message (app->proxy, message_id, + "", + g_variant_new_array (G_VARIANT_TYPE_VARIANT, NULL, 0), app->cancellable, NULL, NULL); } @@ -167,6 +172,34 @@ im_application_list_message_activated (GSimpleAction *action, } static void +im_application_list_sub_message_activated (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + Application *app = user_data; + const gchar *message_id; + const gchar *action_id; + GVariantBuilder builder; + + message_id = g_object_get_data (G_OBJECT (action), "message"); + action_id = g_action_get_name (G_ACTION (action)); + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("av")); + if (parameter) + g_variant_builder_add (&builder, "v", parameter); + + indicator_messages_application_call_activate_message (app->proxy, + message_id, + action_id, + g_variant_builder_end (&builder), + app->cancellable, + NULL, NULL); + + im_application_list_message_removed (app, message_id); +} + + +static void im_application_list_remove_all (GSimpleAction *action, GVariant *parameter, gpointer user_data) @@ -269,7 +302,7 @@ im_application_list_class_init (ImApplicationListClass *klass) NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, - 9, + 10, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -277,6 +310,7 @@ im_application_list_class_init (ImApplicationListClass *klass) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_VARIANT, G_TYPE_INT64, G_TYPE_BOOLEAN); @@ -391,9 +425,11 @@ im_application_list_add (ImApplicationList *list, app->actions = g_action_muxer_new (); app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); + app->message_sub_actions = g_action_muxer_new (); g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); + g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); g_hash_table_insert (list->applications, (gpointer) app->id, app); g_action_muxer_insert (list->muxer, app->id, G_ACTION_GROUP (app->actions)); @@ -509,25 +545,70 @@ im_application_list_message_added (Application *app, const gchar *subtitle; const gchar *body; gint64 time; + GVariant *actions; gboolean draws_attention; GSimpleAction *action; GIcon *app_icon; gchar *app_iconstr; - g_variant_get (message, "(&s&s&s&s&sxb)", - &id, &iconstr, &title, &subtitle, &body, &time, &draws_attention); + g_variant_get (message, "(&s&s&s&s&sx@aa{sv}b)", + &id, &iconstr, &title, &subtitle, &body, &time, &actions, &draws_attention); app_icon = g_app_info_get_icon (G_APP_INFO (app->info)); app_iconstr = app_icon ? g_icon_to_string (app_icon) : NULL; action = g_simple_action_new (id, G_VARIANT_TYPE_BOOLEAN); g_signal_connect (action, "activate", G_CALLBACK (im_application_list_message_activated), app); - g_simple_action_group_insert (app->message_actions, G_ACTION (action)); + { + GVariantIter iter; + GVariant *entry; + GSimpleActionGroup *action_group; + + action_group = g_simple_action_group_new (); + + g_variant_iter_init (&iter, actions); + while ((entry = g_variant_iter_next_value (&iter))) + { + const gchar *name; + GSimpleAction *action; + GVariant *label; + const gchar *type = NULL; + GVariant *hint; + + if (!g_variant_lookup (entry, "name", "&s", &name)) + { + g_warning ("action dictionary for message '%s' is missing 'name' key", id); + continue; + } + + label = g_variant_lookup_value (entry, "label", G_VARIANT_TYPE_STRING); + 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); + 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_simple_action_group_insert (action_group, G_ACTION (action)); + + g_object_unref (action); + if (label) + g_variant_unref (label); + if (hint) + g_variant_unref (hint); + g_variant_unref (entry); + } + + g_action_muxer_insert (app->message_sub_actions, id, G_ACTION_GROUP (action_group)); + + g_object_unref (action_group); + } + g_signal_emit (app->list, signals[MESSAGE_ADDED], 0, - app->id, app_iconstr, id, iconstr, title, subtitle, body, time, draws_attention); + app->id, app_iconstr, id, iconstr, title, subtitle, body, actions, time, draws_attention); + g_variant_unref (actions); g_free (app_iconstr); g_object_unref (action); } @@ -580,10 +661,13 @@ im_application_list_unset_remote (Application *app) * the muxer */ g_object_unref (app->source_actions); g_object_unref (app->message_actions); + g_object_unref (app->message_sub_actions); app->source_actions = g_simple_action_group_new (); app->message_actions = g_simple_action_group_new (); + app->message_sub_actions = g_action_muxer_new (); g_action_muxer_insert (app->actions, "src", G_ACTION_GROUP (app->source_actions)); g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions)); + g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions)); if (was_running) g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id); diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c index 728c08b..6e511ac 100644 --- a/src/im-phone-menu.c +++ b/src/im-phone-menu.c @@ -151,6 +151,7 @@ im_phone_menu_add_message (ImPhoneMenu *menu, const gchar *title, const gchar *subtitle, const gchar *body, + GVariant *actions, gint64 time) { GMenuItem *item; @@ -162,7 +163,15 @@ im_phone_menu_add_message (ImPhoneMenu *menu, action_name = g_strconcat (app_id, ".msg.", id, NULL); item = g_menu_item_new (title, action_name); - g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem"); + + if (g_variant_n_children (actions)) + { + g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.snapdecision"); + g_menu_item_set_attribute (item, "x-canonical-message-actions", "v", actions); + } + else + 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); diff --git a/src/im-phone-menu.h b/src/im-phone-menu.h index f6a6118..84908e2 100644 --- a/src/im-phone-menu.h +++ b/src/im-phone-menu.h @@ -45,6 +45,7 @@ void im_phone_menu_add_message (ImPhoneMenu *men const gchar *title, const gchar *subtitle, const gchar *body, + GVariant *actions, gint64 time); void im_phone_menu_remove_message (ImPhoneMenu *menu, |