]> git.0d.be Git - empathy.git/commitdiff
Port EmpathyInviteParticipantDialog over to EmpathyContactSelectorDialog
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Sat, 19 Dec 2009 02:16:02 +0000 (13:16 +1100)
committerDanielle Madeley <danielle.madeley@collabora.co.uk>
Mon, 21 Dec 2009 09:55:03 +0000 (20:55 +1100)
src/empathy-chat-window.c
src/empathy-invite-participant-dialog.c
src/empathy-invite-participant-dialog.h

index 2dbe09d5d5710e4a4302f2d7c9abfb783f5c1af1..240dc4b688d76dfce2a7ec7ef8a6106008fc2ce6 100644 (file)
@@ -42,6 +42,7 @@
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-tp-contact-factory.h>
 
 #include <libempathy-gtk/empathy-images.h>
 #include <libempathy-gtk/empathy-conf.h>
@@ -821,8 +822,8 @@ chat_window_contacts_toggled_cb (GtkToggleAction   *toggle_action,
 }
 
 static void
-chat_window_upgrade_to_muc (EmpathyChat    *chat,
-                            EmpathyContact *invitee)
+chat_window_upgrade_to_muc (EmpathyChat *chat,
+                            const char  *id)
 {
        EmpathyDispatcher     *dispatcher = empathy_dispatcher_dup_singleton ();
        EmpathyTpChat         *tp_chat;
@@ -841,7 +842,7 @@ chat_window_upgrade_to_muc (EmpathyChat    *chat,
        g_ptr_array_add (channels, (char *) tp_proxy_get_object_path (channel));
 
        invitees[0] = (char *) tp_channel_get_identifier (channel);
-       invitees[1] = (char *) empathy_contact_get_id (invitee);
+       invitees[1] = (char *) id;
 
        props = tp_asv_new (
            TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
@@ -865,6 +866,32 @@ chat_window_upgrade_to_muc (EmpathyChat    *chat,
        g_object_unref (dispatcher);
 }
 
+static void
+got_contact_cb (EmpathyTpContactFactory *factory,
+                EmpathyContact          *contact,
+                const GError            *error,
+                gpointer                 user_data,
+                GObject                 *object)
+{
+       TpChannel *channel = TP_CHANNEL (user_data);
+
+       if (error != NULL)
+       {
+               DEBUG ("Failed: %s", error->message);
+               return;
+       }
+       else
+       {
+               TpHandle handle = empathy_contact_get_handle (contact);
+               GArray handles = {(gchar *) &handle, 1};
+
+               tp_cli_channel_interface_group_call_add_members (
+                               channel, -1, &handles,
+                               _("Inviting to this room"),
+                               NULL, NULL, NULL, NULL);
+       }
+}
+
 static void
 chat_window_invite_participant_activate_cb (GtkAction         *action,
                                            EmpathyChatWindow *window)
@@ -890,33 +917,38 @@ chat_window_invite_participant_activate_cb (GtkAction         *action,
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
 
-       if (response == GTK_RESPONSE_OK)
+       if (response == GTK_RESPONSE_ACCEPT)
        {
-               EmpathyContact *contact;
+               const char *id;
                TpHandleType handle_type;
 
-               contact = empathy_invite_participant_dialog_dup_selected_contact (EMPATHY_INVITE_PARTICIPANT_DIALOG (dialog));
+               id = empathy_contact_selector_dialog_get_selected (
+                               EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL);
+               if (EMP_STR_EMPTY (id)) goto out;
+
                tp_channel_get_handle (channel, &handle_type);
 
                if (handle_type == TP_HANDLE_TYPE_CONTACT)
                {
-                       chat_window_upgrade_to_muc (priv->current_chat,
-                                       contact);
+                       chat_window_upgrade_to_muc (priv->current_chat, id);
                }
                else
                {
-                       TpHandle handle = empathy_contact_get_handle (contact);
-                       GArray handles = {(gchar *) &handle, 1};
+                       TpConnection *connection;
+                       EmpathyTpContactFactory *factory;
 
-                       tp_cli_channel_interface_group_call_add_members (
-                                       channel, -1, &handles,
-                                       _("Inviting to this room"),
-                                       NULL, NULL, NULL, NULL);
-               }
+                       connection = tp_channel_borrow_connection (channel);
+                       factory = empathy_tp_contact_factory_dup_singleton (connection);
+
+                       empathy_tp_contact_factory_get_from_id (factory, id,
+                                       got_contact_cb, channel,  NULL, NULL);
 
-               g_object_unref (contact);
+
+                       g_object_unref (factory);
+               }
        }
 
+out:
        gtk_widget_destroy (dialog);
 }
 
index 07c12c9b0e5a24d2610c3b6c47e707d2954600b7..f67a7feded4448f1d0f0310413bd347ac3ff5ae6 100644 (file)
 
 #include <glib/gi18n.h>
 
-#include <libempathy/empathy-contact-manager.h>
-
-#include <libempathy-gtk/empathy-contact-selector.h>
-
 #include "empathy-invite-participant-dialog.h"
 
 #define GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG, EmpathyInviteParticipantDialogPrivate))
 
-G_DEFINE_TYPE (EmpathyInviteParticipantDialog, empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
+G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
+    empathy_invite_participant_dialog, EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG);
 
 typedef struct _EmpathyInviteParticipantDialogPrivate EmpathyInviteParticipantDialogPrivate;
 struct _EmpathyInviteParticipantDialogPrivate
 {
-  GtkWidget *selector;
+  int dum;
 };
 
-static void
-invite_participant_enable_join (GtkComboBox *selector,
-                                GtkWidget   *button)
-{
-  gtk_widget_set_sensitive (button, TRUE);
-}
-
 static void
 empathy_invite_participant_dialog_class_init (EmpathyInviteParticipantDialogClass *klass)
 {
@@ -45,13 +35,12 @@ empathy_invite_participant_dialog_class_init (EmpathyInviteParticipantDialogClas
 static void
 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
 {
-  EmpathyInviteParticipantDialogPrivate *priv = GET_PRIVATE (self);
-  EmpathyContactManager *manager = empathy_contact_manager_dup_singleton ();
-  GtkWidget *vbox = gtk_vbox_new (FALSE, 6);
-  GtkWidget *label = gtk_label_new (NULL);
-  GtkWidget *join_button;
+  EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (self);
+  // EmpathyInviteParticipantDialogPrivate *priv = GET_PRIVATE (self);
+  GtkWidget *label;
   char *str;
 
+  label = gtk_label_new (NULL);
   str = g_strdup_printf (
       "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
       _("Invite Participant"),
@@ -59,42 +48,19 @@ empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
   gtk_label_set_markup (GTK_LABEL (label), str);
   g_free (str);
 
-  priv->selector = empathy_contact_selector_new (
-      EMPATHY_CONTACT_LIST (manager));
-
-  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (vbox), priv->selector, FALSE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))),
-        vbox, TRUE, TRUE, 6);
-
-  gtk_widget_show_all (vbox);
-
-  gtk_dialog_add_button (GTK_DIALOG (self),
-      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
-  join_button = gtk_dialog_add_button (GTK_DIALOG (self),
-      "Invite", GTK_RESPONSE_OK);
-
-  gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
-
-  gtk_widget_set_sensitive (join_button, FALSE);
-  g_signal_connect (priv->selector, "changed",
-      G_CALLBACK (invite_participant_enable_join), join_button);
-
-  g_object_unref (manager);
-}
-
-EmpathyContact *
-empathy_invite_participant_dialog_dup_selected_contact (
-    EmpathyInviteParticipantDialog *self)
-{
-  EmpathyInviteParticipantDialogPrivate *priv;
-
-  g_return_val_if_fail (EMPATHY_IS_INVITE_PARTICIPANT_DIALOG (self), NULL);
+  gtk_box_pack_start (GTK_BOX (parent->vbox), label, FALSE, TRUE, 0);
+  /* move to the top -- wish there was a better way to do this */
+  gtk_box_reorder_child (GTK_BOX (parent->vbox), label, 0);
+  gtk_widget_show (label);
 
-  priv = GET_PRIVATE (self);
+  parent->button_action = gtk_dialog_add_button (GTK_DIALOG (self),
+      "Invite", GTK_RESPONSE_ACCEPT);
+  gtk_widget_set_sensitive (parent->button_action, FALSE);
 
-  return empathy_contact_selector_dup_selected (
-      EMPATHY_CONTACT_SELECTOR (priv->selector));
+  gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
+  gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
+  empathy_contact_selector_dialog_set_show_account_chooser (
+      EMPATHY_CONTACT_SELECTOR_DIALOG (self), FALSE);
 }
 
 GtkWidget *
index 642733871aad0cc661a0996c25cc3a9e6551b253..561e1073829cb761b8f8a9baea3f076dec0e45d0 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <gtk/gtk.h>
 
+#include <libempathy-gtk/empathy-contact-selector-dialog.h>
+
 G_BEGIN_DECLS
 
 #define EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG (empathy_invite_participant_dialog_get_type ())
@@ -28,18 +30,16 @@ typedef struct _EmpathyInviteParticipantDialogClass EmpathyInviteParticipantDial
 
 struct _EmpathyInviteParticipantDialog
 {
-  GtkDialog parent;
+  EmpathyContactSelectorDialog parent;
 };
 
 struct _EmpathyInviteParticipantDialogClass
 {
-  GtkDialogClass parent_class;
+  EmpathyContactSelectorDialogClass parent_class;
 };
 
 GType empathy_invite_participant_dialog_get_type (void);
 GtkWidget *empathy_invite_participant_dialog_new (GtkWindow *parent);
-EmpathyContact *empathy_invite_participant_dialog_dup_selected_contact (EmpathyInviteParticipantDialog *self);
-
 
 G_END_DECLS