]> git.0d.be Git - empathy.git/blobdiff - src/empathy-roster-window.c
roster-window: fix crash if empathy_chatroom_manager_find() failed
[empathy.git] / src / empathy-roster-window.c
index 74d9c42c1f8fb1503d177fac07adcbb2a4efcc2b..b953e0e8307b32c851a59fa6dc7175b8627b273c 100644 (file)
@@ -34,6 +34,7 @@
 #include "empathy-chat-manager.h"
 #include "empathy-chatroom-manager.h"
 #include "empathy-chatrooms-window.h"
+#include "empathy-client-factory.h"
 #include "empathy-contact-blocking-dialog.h"
 #include "empathy-contact-search-dialog.h"
 #include "empathy-event-manager.h"
@@ -333,7 +334,7 @@ roster_window_load_events_idle_cb (gpointer user_data)
 static void
 hide_search_bar (EmpathyRosterWindow *roster_window)
 {
-  if (EMPATHY_IS_LIVE_SEARCH (roster_window->priv->search_bar) &&
+  if (TPAW_IS_LIVE_SEARCH (roster_window->priv->search_bar) &&
       gtk_widget_is_visible (roster_window->priv->search_bar))
     gtk_widget_hide (roster_window->priv->search_bar);
 }
@@ -744,7 +745,7 @@ roster_window_error_display (EmpathyRosterWindow *self,
        tp_account_get_detailed_error (account, NULL)))
     {
       roster_window_error_add_stock_button (GTK_INFO_BAR (info_bar),
-          GTK_STOCK_REFRESH, _("Update software..."),
+          GTK_STOCK_REFRESH, _("Update software"),
           ERROR_RESPONSE_RETRY);
     }
   else
@@ -1272,19 +1273,43 @@ 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'",
+          room, path);
+      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
@@ -1292,35 +1317,26 @@ 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_item_set_attribute (item, "account-path", "s", account_path);
   g_menu_append_item (self->priv->rooms_section, item);
 
   g_free (label);
-  g_free (action_name);
-  g_object_unref (action);
 }
 
 static void
@@ -1338,26 +1354,46 @@ roster_window_favorite_chatroom_menu_removed_cb (
     EmpathyRosterWindow *self)
 {
   GList *chatrooms;
-  gchar *act;
-  gint i;
+  guint i, n;
+  TpAccount *account;
+  const gchar *account_path;
 
-  act = dup_join_action_name (chatroom, TRUE);
+  account = empathy_chatroom_get_account (chatroom);
+  account_path = tp_proxy_get_object_path (account);
 
-  g_action_map_remove_action (G_ACTION_MAP (self), act);
+  n = g_menu_model_get_n_items (G_MENU_MODEL (self->priv->rooms_section));
 
-  for (i = 0; i < g_menu_model_get_n_items (
-        G_MENU_MODEL (self->priv->rooms_section)); i++)
+  for (i = 0; i < n; i++)
     {
-      const gchar *name;
+      gchar *tmp;
+
+      if (!g_menu_model_get_item_attribute (
+            G_MENU_MODEL (self->priv->rooms_section), i,
+            "room-name", "s", &tmp))
+        continue;
 
-      if (g_menu_model_get_item_attribute (
-            G_MENU_MODEL (self->priv->rooms_section), i, "room-name",
-            "s", &name)
-          && !tp_strdiff (name, empathy_chatroom_get_name (chatroom)))
+      if (tp_strdiff (tmp, empathy_chatroom_get_name (chatroom)))
         {
-          g_menu_remove (self->priv->rooms_section, i);
-          break;
+          g_free (tmp);
+          continue;
         }
+
+      g_free (tmp);
+
+      if (!g_menu_model_get_item_attribute (
+            G_MENU_MODEL (self->priv->rooms_section), i,
+            "account-path", "s", &tmp))
+        continue;
+
+      if (tp_strdiff (tmp, account_path))
+        {
+          g_free (tmp);
+          continue;
+        }
+
+      g_menu_remove (self->priv->rooms_section, i);
+      g_free (tmp);
+      break;
     }
 
   chatrooms = empathy_chatroom_manager_get_chatrooms (
@@ -1689,7 +1725,7 @@ set_notebook_page (EmpathyRosterWindow *self)
         {
           if (g_settings_get_boolean (self->priv->gsettings_ui,
                 EMPATHY_PREFS_UI_SHOW_OFFLINE))
-            display_page_message (self, _("You haven't added any contact yet"),
+            display_page_message (self, _("You haven't added any contacts yet"),
                 PAGE_MESSAGE_FLAG_ADD_CONTACT);
           else
             display_page_message (self, _("No online contacts"),
@@ -1855,6 +1891,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 },
@@ -1962,6 +1999,15 @@ menu_deactivate_cb (GtkMenuShell *menushell,
   gtk_menu_detach (GTK_MENU (menushell));
 }
 
+static void
+menu_item_activated_cb (GtkMenuShell *menushell,
+    gpointer user_data)
+{
+    EmpathyRosterWindow *roster_window = EMPATHY_ROSTER_WINDOW (user_data);
+
+    hide_search_bar (roster_window);
+}
+
 static void
 popup_individual_menu_cb (EmpathyRosterView *view,
     const gchar *active_group,
@@ -1992,6 +2038,8 @@ popup_individual_menu_cb (EmpathyRosterView *view,
    * during the whole lifetime of Empathy. */
   g_signal_connect (menu, "deactivate", G_CALLBACK (menu_deactivate_cb),
       NULL);
+  g_signal_connect (menu, "menu-item-activated",
+      G_CALLBACK (menu_item_activated_cb), user_data);
 
   gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (view), NULL);
   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time);
@@ -2126,22 +2174,22 @@ view_drag_motion_cb (GtkWidget *widget,
     {
       /* Check if contact supports FT */
       FolksIndividual *individual;
-      GtkWidget *child;
+      GtkListBoxRow *row;
 
       individual = empathy_roster_view_get_individual_at_y (self->priv->view,
-          y, &child);
+          y, &row);
       if (individual == NULL)
         goto no_hl;
 
       if (!individual_supports_ft (individual))
         goto no_hl;
 
-      egg_list_box_drag_highlight_widget (EGG_LIST_BOX (widget), child);
+      gtk_list_box_drag_highlight_row (GTK_LIST_BOX (widget), row);
       return FALSE;
     }
 
 no_hl:
-  egg_list_box_drag_unhighlight_widget (EGG_LIST_BOX (widget));
+  gtk_list_box_drag_unhighlight_row (GTK_LIST_BOX (widget));
   return FALSE;
 }
 
@@ -2355,8 +2403,7 @@ empathy_roster_window_init (EmpathyRosterWindow *self)
 
   gtk_widget_show (GTK_WIDGET (self->priv->view));
 
-  egg_list_box_add_to_scrolled (EGG_LIST_BOX (self->priv->view),
-      GTK_SCROLLED_WINDOW (sw));
+  gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (self->priv->view));
 
   g_signal_connect (self->priv->view, "individual-activated",
       G_CALLBACK (individual_activated_cb), self);