[Pkg-telepathy-commits] [empathy] 27/39: Create one single GAction to join rooms
Simon McVittie
smcv at debian.org
Wed Jan 29 12:53:14 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian
in repository empathy.
commit 2e22420b7abfbce1c764bafc5c6ce4877561ad5d
Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date: Wed Sep 11 11:09:15 2013 +0200
Create one single GAction to join rooms
The proper way to handle multi menu items having the same semantic is to have
one single GAction associated with different GMenuItem having specific
parameters instead of having one action per menu item.
Fix bgo#707885 as we no longer have spaces in GMenuItem action names.
---
src/empathy-roster-window.c | 80 ++++++++++++++++++++++++++-------------------
1 file changed, 46 insertions(+), 34 deletions(-)
diff --git a/src/empathy-roster-window.c b/src/empathy-roster-window.c
index 05d2a1f..8280861 100644
--- a/src/empathy-roster-window.c
+++ b/src/empathy-roster-window.c
@@ -33,6 +33,7 @@
#include <libempathy/empathy-gsettings.h>
#include <libempathy/empathy-status-presets.h>
#include <libempathy/empathy-presence-manager.h>
+#include <libempathy/empathy-client-factory.h>
#include <libempathy-gtk/empathy-contact-blocking-dialog.h>
#include <libempathy-gtk/empathy-contact-search-dialog.h>
@@ -1259,19 +1260,44 @@ roster_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
}
static void
-roster_window_favorite_chatroom_menu_activate_cb (GAction *action,
+roster_window_join_chatroom_menu_activate_cb (GSimpleAction *action,
GVariant *parameter,
- EmpathyChatroom *chatroom)
+ gpointer user_data)
{
+ EmpathyRosterWindow *self = user_data;
+ const gchar *room, *path;
+ EmpathyClientFactory *factory;
+ TpAccount *account;
+ GError *error = NULL;
+ EmpathyChatroom *chatroom;
+
+ g_variant_get (parameter, "(&s&s)", &room, &path);
+
+ factory = empathy_client_factory_dup ();
+
+ account = tp_simple_client_factory_ensure_account (
+ TP_SIMPLE_CLIENT_FACTORY (factory), path, NULL, &error);
+ if (account == NULL)
+ {
+ DEBUG ("Failed to get account '%s': %s", path, error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ chatroom = empathy_chatroom_manager_find (self->priv->chatroom_manager,
+ account, room);
+ if (chatroom == NULL)
+ {
+ DEBUG ("Failed to get chatroom '%s' on '%s': %s",
+ room, path, error->message);
+ g_error_free (error);
+ goto out;
+ }
+
roster_window_favorite_chatroom_join (chatroom);
-}
-static gchar *
-dup_join_action_name (EmpathyChatroom *chatroom,
- gboolean prefix)
-{
- return g_strconcat (prefix ? "win." : "", "join-",
- empathy_chatroom_get_name (chatroom), NULL);
+out:
+ g_object_unref (factory);
}
static void
@@ -1279,35 +1305,25 @@ roster_window_favorite_chatroom_menu_add (EmpathyRosterWindow *self,
EmpathyChatroom *chatroom)
{
GMenuItem *item;
- const gchar *name, *account_name;
- gchar *label, *action_name;
- GAction *action;
+ const gchar *name, *account_name, *account_path;
+ TpAccount *account;
+ gchar *label;
+
+ account = empathy_chatroom_get_account (chatroom);
name = empathy_chatroom_get_name (chatroom);
- account_name = tp_account_get_display_name (
- empathy_chatroom_get_account (chatroom));
+ account_name = tp_account_get_display_name (account);
+ account_path = tp_proxy_get_object_path (account);
label = g_strdup_printf ("%s (%s)", name, account_name);
- action_name = dup_join_action_name (chatroom, FALSE);
-
- action = (GAction *) g_simple_action_new (action_name, NULL);
- g_free (action_name);
-
- g_signal_connect (action, "activate",
- G_CALLBACK (roster_window_favorite_chatroom_menu_activate_cb),
- chatroom);
-
- g_action_map_add_action (G_ACTION_MAP (self), action);
- action_name = dup_join_action_name (chatroom, TRUE);
-
- item = g_menu_item_new (label, action_name);
+ item = g_menu_item_new (label, NULL);
+ g_menu_item_set_action_and_target (item, "win.join", "(ss)",
+ name, account_path);
g_menu_item_set_attribute (item, "room-name", "s", name);
g_menu_append_item (self->priv->rooms_section, item);
g_free (label);
- g_free (action_name);
- g_object_unref (action);
}
static void
@@ -1325,13 +1341,8 @@ roster_window_favorite_chatroom_menu_removed_cb (
EmpathyRosterWindow *self)
{
GList *chatrooms;
- gchar *act;
gint i;
- act = dup_join_action_name (chatroom, TRUE);
-
- g_action_map_remove_action (G_ACTION_MAP (self), act);
-
for (i = 0; i < g_menu_model_get_n_items (
G_MENU_MODEL (self->priv->rooms_section)); i++)
{
@@ -1832,6 +1843,7 @@ static GActionEntry menubar_entries[] = {
{ "room_join_new", roster_window_room_join_new_cb, NULL, NULL, NULL },
{ "room_join_favorites", roster_window_room_join_favorites_cb, NULL, NULL, NULL },
+ { "join", roster_window_join_chatroom_menu_activate_cb, "(ss)", NULL, NULL },
{ "room_manage_favorites", roster_window_room_manage_favorites_cb, NULL, NULL, NULL },
{ "help_contents", roster_window_help_contents_cb, NULL, NULL, NULL },
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/empathy.git
More information about the Pkg-telepathy-commits
mailing list