]> git.0d.be Git - empathy.git/blobdiff - src/empathy-new-chatroom-dialog.c
update gnome-contacts's desktop file
[empathy.git] / src / empathy-new-chatroom-dialog.c
index 66d38da72a78acbb9317f57ecdb683fac883fc32..7f46cb4f1d303b861ee0ac95ef799fcd0201eec7 100644 (file)
  *          Xavier Claessens <xclaesse@gmail.com>
  */
 
-#include <config.h>
-
-#include <string.h>
+#include "config.h"
+#include "empathy-new-chatroom-dialog.h"
 
-#include <gtk/gtk.h>
-#include <glib.h>
 #include <glib/gi18n.h>
-#include <glib/gprintf.h>
-
-#include <telepathy-glib/interfaces.h>
-
-#include <libempathy/empathy-tp-roomlist.h>
-#include <libempathy/empathy-chatroom.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-gsettings.h>
-
-#include <libempathy-gtk/empathy-account-chooser.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
+#include <tp-account-widgets/tpaw-builder.h>
+#include <tp-account-widgets/tpaw-utils.h>
 
-#include "empathy-new-chatroom-dialog.h"
+#include "empathy-account-chooser.h"
+#include "empathy-gsettings.h"
+#include "empathy-request-util.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 G_DEFINE_TYPE (EmpathyNewChatroomDialog, empathy_new_chatroom_dialog,
     GTK_TYPE_DIALOG)
 
 struct _EmpathyNewChatroomDialogPriv
 {
-  EmpathyTpRoomlist *room_list;
+  TpRoomList *room_list;
   /* Currently selected account */
   TpAccount *account;
   /* Signal id of the "status-changed" signal connected on the currently
@@ -124,7 +115,7 @@ new_chatroom_dialog_join (EmpathyNewChatroomDialog *self)
   account_chooser = EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
   account = empathy_account_chooser_get_account (account_chooser);
 
-  if (!EMP_STR_EMPTY (server))
+  if (!TPAW_STR_EMPTY (server))
     room_name = g_strconcat (room, "@", server, NULL);
   else
     room_name = g_strdup (room);
@@ -159,7 +150,7 @@ new_chatroom_dialog_model_add_columns (EmpathyNewChatroomDialog *self)
 {
   GtkTreeView *view;
   GtkTreeViewColumn *column;
-  GtkCellRenderer*cell;
+  GtkCellRenderer *cell;
   gint width, height;
 
   gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
@@ -265,8 +256,8 @@ new_chatroom_dialog_model_setup (EmpathyNewChatroomDialog *self)
 
   /* Store/Model */
   store = gtk_list_store_new (COL_COUNT,
-      G_TYPE_STRING,       /* Invite */
-      G_TYPE_STRING,       /* Password */
+      G_TYPE_STRING,       /* Need password */
+      G_TYPE_STRING,       /* Invite only */
       G_TYPE_STRING,       /* Name */
       G_TYPE_STRING,       /* Room */
       G_TYPE_STRING,       /* Member count */
@@ -298,8 +289,8 @@ update_join_button_sensitivity (EmpathyNewChatroomDialog *self)
   gboolean sensitive = FALSE;
 
   room = gtk_entry_get_text (GTK_ENTRY (self->priv->entry_room));
-  protocol = tp_account_get_protocol (self->priv->account);
-  if (EMP_STR_EMPTY (room))
+  protocol = tp_account_get_protocol_name (self->priv->account);
+  if (TPAW_STR_EMPTY (room))
     goto out;
 
   if (!tp_strdiff (protocol, "irc") &&
@@ -327,7 +318,7 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *self)
   if (self->priv->account == NULL)
     return;
 
-  protocol = tp_account_get_protocol (self->priv->account);
+  protocol = tp_account_get_protocol_name (self->priv->account);
 
   gtk_entry_set_text (GTK_ENTRY (self->priv->entry_server), "");
 
@@ -403,16 +394,19 @@ new_chatroom_dialog_account_ready_cb (EmpathyAccountChooser *combobox,
 }
 
 static void
-new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist *room_list,
+listing_failed_cb (TpRoomList *room_list,
+    GError *error,
     EmpathyNewChatroomDialog *self)
 {
-  g_object_unref (self->priv->room_list);
-  self->priv->room_list = NULL;
+  gtk_label_set_text (GTK_LABEL (self->priv->label_error_message),
+      _("Failed to list rooms"));
+  gtk_widget_show_all (self->priv->viewport_error);
+  gtk_widget_set_sensitive (self->priv->treeview, FALSE);
 }
 
 static void
-new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist *room_list,
-    EmpathyChatroom *chatroom,
+new_chatroom_dialog_got_room_cb (TpRoomList *room_list,
+    TpRoomInfo *room,
     EmpathyNewChatroomDialog *self)
 {
   GtkListStore *store;
@@ -422,35 +416,43 @@ new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist *room_list,
   const gchar *invite_only;
   gchar *tmp;
 
-  DEBUG ("New chatroom listed: %s (%s)", empathy_chatroom_get_name (chatroom),
-      empathy_chatroom_get_room (chatroom));
+  if (tp_str_empty (tp_room_info_get_handle_name (room)))
+    {
+      DEBUG ("Room handle name is empty - Broken CM");
+      return;
+    }
+
+  DEBUG ("New room listed: %s (%s)", tp_room_info_get_name (room),
+      tp_room_info_get_handle_name (room));
 
   /* Add to model */
   store = GTK_LIST_STORE (self->priv->model);
-  members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (
-        chatroom));
-  tmp = g_strdup_printf ("<b>%s</b>", empathy_chatroom_get_name (chatroom));
+  members = g_strdup_printf ("%d", tp_room_info_get_members_count (
+        room, NULL));
+  tmp = g_strdup_printf ("<b>%s</b>", tp_room_info_get_name (room));
+
   /* Translators: Room/Join's roomlist tooltip. Parameters are a channel name,
   yes/no, yes/no and a number. */
   tooltip = g_strdup_printf (
       _("%s\nInvite required: %s\nPassword required: %s\nMembers: %s"),
       tmp,
-      empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
-      empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
+      tp_room_info_get_invite_only (room, NULL) ? _("Yes") : _("No"),
+      tp_room_info_get_requires_password (room, NULL) ? _("Yes") : _("No"),
       members);
   g_free (tmp);
-  invite_only = (empathy_chatroom_get_invite_only (chatroom) ?
+
+  invite_only = (tp_room_info_get_invite_only (room, NULL) ?
     GTK_STOCK_INDEX : NULL);
-  need_password = (empathy_chatroom_get_need_password (chatroom) ?
+  need_password = (tp_room_info_get_requires_password (room, NULL) ?
     GTK_STOCK_DIALOG_AUTHENTICATION : NULL);
 
   gtk_list_store_insert_with_values (store, NULL, -1,
       COL_NEED_PASSWORD, need_password,
       COL_INVITE_ONLY, invite_only,
-      COL_NAME, empathy_chatroom_get_name (chatroom),
-      COL_ROOM, empathy_chatroom_get_room (chatroom),
+      COL_NAME, tp_room_info_get_name (room),
+      COL_ROOM, tp_room_info_get_handle_name (room),
       COL_MEMBERS, members,
-      COL_MEMBERS_INT, empathy_chatroom_get_members_count (chatroom),
+      COL_MEMBERS_INT, tp_room_info_get_members_count (room, NULL),
       COL_TOOLTIP, tooltip,
       -1);
 
@@ -459,16 +461,12 @@ new_chatroom_dialog_new_room_cb (EmpathyTpRoomlist *room_list,
 }
 
 static void
-new_chatroom_dialog_listing_cb (EmpathyTpRoomlist *room_list,
-    gpointer unused,
+new_chatroom_dialog_listing_cb (TpRoomList *room_list,
+    GParamSpec *spec,
     EmpathyNewChatroomDialog *self)
 {
-  gboolean listing;
-
-  listing = empathy_tp_roomlist_is_listing (room_list);
-
   /* Update the throbber */
-  if (listing)
+  if (tp_room_list_is_listing (room_list))
     {
       gtk_spinner_start (GTK_SPINNER (self->priv->throbber));
       gtk_widget_show (self->priv->throbber);
@@ -480,28 +478,6 @@ new_chatroom_dialog_listing_cb (EmpathyTpRoomlist *room_list,
     }
 }
 
-static void
-start_listing_error_cb (EmpathyTpRoomlist *room_list,
-    GError *error,
-    EmpathyNewChatroomDialog *self)
-{
-  gtk_label_set_text (GTK_LABEL (self->priv->label_error_message),
-      _("Could not start room listing"));
-  gtk_widget_show_all (self->priv->viewport_error);
-  gtk_widget_set_sensitive (self->priv->treeview, FALSE);
-}
-
-static void
-stop_listing_error_cb (EmpathyTpRoomlist *room_list,
-    GError *error,
-    EmpathyNewChatroomDialog *self)
-{
-  gtk_label_set_text (GTK_LABEL (self->priv->label_error_message),
-      _("Could not stop room listing"));
-  gtk_widget_show_all (self->priv->viewport_error);
-  gtk_widget_set_sensitive (self->priv->treeview, FALSE);
-}
-
 static void
 new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog *self)
 {
@@ -515,8 +491,60 @@ static void
 new_chatroom_dialog_browse_start (EmpathyNewChatroomDialog *self)
 {
   new_chatroom_dialog_model_clear (self);
-  if (self->priv->room_list)
-    empathy_tp_roomlist_start (self->priv->room_list);
+
+  if (self->priv->room_list != NULL)
+    tp_room_list_start (self->priv->room_list);
+}
+
+static void
+new_room_list_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  EmpathyNewChatroomDialog *self = user_data;
+  TpRoomList *room_list;
+  GError *error = NULL;
+
+  room_list = tp_room_list_new_finish (result, &error);
+  if (room_list == NULL)
+    {
+      DEBUG ("Failed to create TpRoomList: %s\n", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  if (tp_room_list_get_account (room_list) != self->priv->account)
+    {
+      /* Account changed while we were creating this TpRoomList */
+      g_object_unref (room_list);
+      return;
+    }
+
+  self->priv->room_list = room_list;
+
+  tp_g_signal_connect_object (self->priv->room_list, "got-room",
+      G_CALLBACK (new_chatroom_dialog_got_room_cb), self, 0);
+  tp_g_signal_connect_object (self->priv->room_list, "failed",
+      G_CALLBACK (listing_failed_cb), self, 0);
+  tp_g_signal_connect_object (self->priv->room_list, "notify::listing",
+      G_CALLBACK (new_chatroom_dialog_listing_cb), self, 0);
+
+  if (gtk_expander_get_expanded (GTK_EXPANDER (self->priv->expander_browse)))
+    {
+      gtk_widget_hide (self->priv->viewport_error);
+      gtk_widget_set_sensitive (self->priv->treeview, TRUE);
+      new_chatroom_dialog_browse_start (self);
+    }
+
+  if (tp_room_list_is_listing (self->priv->room_list))
+    {
+      gtk_spinner_start (GTK_SPINNER (self->priv->throbber));
+      gtk_widget_show (self->priv->throbber);
+    }
+
+  gtk_widget_set_sensitive (self->priv->expander_browse, TRUE);
+
+  new_chatroom_dialog_update_widgets (self);
 }
 
 static void
@@ -524,16 +552,10 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox *combobox,
     EmpathyNewChatroomDialog *self)
 {
   EmpathyAccountChooser *account_chooser;
-  gboolean listing = FALSE;
-  gboolean expanded = FALSE;
   TpConnection *connection;
   TpCapabilities *caps;
 
-  if (self->priv->room_list)
-    {
-      g_object_unref (self->priv->room_list);
-      self->priv->room_list = NULL;
-    }
+  g_clear_object (&self->priv->room_list);
 
   gtk_spinner_stop (GTK_SPINNER (self->priv->throbber));
   gtk_widget_hide (self->priv->throbber);
@@ -565,45 +587,11 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox *combobox,
   if (tp_capabilities_supports_room_list (caps, NULL))
     {
       /* Roomlist channels are supported */
-      self->priv->room_list = empathy_tp_roomlist_new (self->priv->account);
-    }
-  else
-    {
-      self->priv->room_list = NULL;
+      tp_room_list_new_async (self->priv->account, NULL, new_room_list_cb,
+          self);
     }
 
-  if (self->priv->room_list)
-    {
-      g_signal_connect (self->priv->room_list, "destroy",
-          G_CALLBACK (new_chatroom_dialog_roomlist_destroy_cb), self);
-      g_signal_connect (self->priv->room_list, "new-room",
-          G_CALLBACK (new_chatroom_dialog_new_room_cb), self);
-      g_signal_connect (self->priv->room_list, "notify::is-listing",
-          G_CALLBACK (new_chatroom_dialog_listing_cb), self);
-      g_signal_connect (self->priv->room_list, "error::start",
-          G_CALLBACK (start_listing_error_cb), self);
-      g_signal_connect (self->priv->room_list, "error::stop",
-          G_CALLBACK (stop_listing_error_cb), self);
-
-      expanded = gtk_expander_get_expanded (
-          GTK_EXPANDER (self->priv->expander_browse));
-      if (expanded)
-        {
-          gtk_widget_hide (self->priv->viewport_error);
-          gtk_widget_set_sensitive (self->priv->treeview, TRUE);
-          new_chatroom_dialog_browse_start (self);
-        }
-
-      listing = empathy_tp_roomlist_is_listing (self->priv->room_list);
-      if (listing)
-        {
-          gtk_spinner_start (GTK_SPINNER (self->priv->throbber));
-          gtk_widget_show (self->priv->throbber);
-        }
-    }
-
-  gtk_widget_set_sensitive (self->priv->expander_browse,
-      self->priv->room_list != NULL);
+  gtk_widget_set_sensitive (self->priv->expander_browse, FALSE);
 
 out:
   new_chatroom_dialog_update_widgets (self);
@@ -628,13 +616,6 @@ new_chatroom_dialog_entry_changed_cb (GtkWidget *entry,
     }
 }
 
-static void
-new_chatroom_dialog_browse_stop (EmpathyNewChatroomDialog *self)
-{
-  if (self->priv->room_list)
-    empathy_tp_roomlist_stop (self->priv->room_list);
-}
-
 static void
 new_chatroom_dialog_entry_server_activate_cb (GtkWidget *widget,
     EmpathyNewChatroomDialog *self)
@@ -651,7 +632,6 @@ new_chatroom_dialog_expander_browse_activate_cb (GtkWidget *widget,
   expanded = gtk_expander_get_expanded (GTK_EXPANDER (widget));
   if (expanded)
     {
-      new_chatroom_dialog_browse_stop (self);
       gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
     }
   else
@@ -769,7 +749,7 @@ empathy_new_chatroom_dialog_init (EmpathyNewChatroomDialog *self)
       EMPATHY_TYPE_NEW_CHATROOM_DIALOG, EmpathyNewChatroomDialogPriv);
 
   filename = empathy_file_lookup ("empathy-new-chatroom-dialog.ui", "src");
-  gui = empathy_builder_get_file (filename,
+  gui = tpaw_builder_get_file (filename,
       "vbox_new_chatroom", &vbox,
       "table_grid", &self->priv->table_grid,
       "label_account", &self->priv->label_account,
@@ -785,7 +765,7 @@ empathy_new_chatroom_dialog_init (EmpathyNewChatroomDialog *self)
       NULL);
   g_free (filename);
 
-  empathy_builder_connect (gui, self,
+  tpaw_builder_connect (gui, self,
       "entry_server", "changed", new_chatroom_dialog_entry_changed_cb,
       "entry_server", "activate", new_chatroom_dialog_entry_server_activate_cb,
       "entry_server", "focus-out-event",
@@ -806,6 +786,8 @@ empathy_new_chatroom_dialog_init (EmpathyNewChatroomDialog *self)
   self->priv->button_join = gtk_dialog_add_button (GTK_DIALOG (self),
       _("Join"), GTK_RESPONSE_OK);
 
+  gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
+
   gtk_window_set_title (GTK_WINDOW (self), _("Join Room"));
   gtk_window_set_role (GTK_WINDOW (self), "join_new_chatroom");