diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-06 18:46:37 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-18 21:40:09 +0800 |
commit | 08ba02749235ae95a586fa930690f921e74bda35 (patch) | |
tree | 7f9d29596090ce127566119479066a69bdfed010 /src | |
parent | 9999bf6834a4c2e592a39dcbc9b8dffc5bee9bd5 (diff) | |
download | gsoc2013-empathy-08ba02749235ae95a586fa930690f921e74bda35.tar gsoc2013-empathy-08ba02749235ae95a586fa930690f921e74bda35.tar.gz gsoc2013-empathy-08ba02749235ae95a586fa930690f921e74bda35.tar.bz2 gsoc2013-empathy-08ba02749235ae95a586fa930690f921e74bda35.tar.lz gsoc2013-empathy-08ba02749235ae95a586fa930690f921e74bda35.tar.xz gsoc2013-empathy-08ba02749235ae95a586fa930690f921e74bda35.tar.zst gsoc2013-empathy-08ba02749235ae95a586fa930690f921e74bda35.zip |
invite-dialog: display a individual view rather than forcing user to type the full ID of the contact (#646705)
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-chat-window.c | 39 | ||||
-rw-r--r-- | src/empathy-invite-participant-dialog.c | 191 | ||||
-rw-r--r-- | src/empathy-invite-participant-dialog.h | 19 |
3 files changed, 204 insertions, 45 deletions
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index d8a75cb0c..e96be3831 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -976,24 +976,6 @@ chat_window_contacts_toggled_cb (GtkToggleAction *toggle_action, } static void -got_contact_cb (TpConnection *connection, - EmpathyContact *contact, - const GError *error, - gpointer user_data, - GObject *object) -{ - EmpathyTpChat *tp_chat = EMPATHY_TP_CHAT (user_data); - - if (error != NULL) { - DEBUG ("Failed: %s", error->message); - return; - } else { - empathy_contact_list_add (EMPATHY_CONTACT_LIST (tp_chat), - contact, _("Inviting you to this room")); - } -} - -static void chat_window_invite_participant_activate_cb (GtkAction *action, EmpathyChatWindow *window) { @@ -1013,22 +995,25 @@ chat_window_invite_participant_activate_cb (GtkAction *action, account = empathy_chat_get_account (priv->current_chat); dialog = empathy_invite_participant_dialog_new ( - GTK_WINDOW (priv->dialog), account); + GTK_WINDOW (priv->dialog), tp_chat); gtk_widget_show (dialog); response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response == GTK_RESPONSE_ACCEPT) { - TpConnection *connection; - const char *id; + TpContact *tp_contact; + EmpathyContact *contact; + + tp_contact = empathy_invite_participant_dialog_get_selected ( + EMPATHY_INVITE_PARTICIPANT_DIALOG (dialog)); + if (tp_contact == NULL) goto out; - id = empathy_contact_selector_dialog_get_selected ( - EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL, NULL); - if (EMP_STR_EMPTY (id)) goto out; + contact = empathy_contact_dup_from_tp_contact (tp_contact); + + empathy_contact_list_add (EMPATHY_CONTACT_LIST (tp_chat), + contact, _("Inviting you to this room")); - connection = tp_channel_borrow_connection (channel); - empathy_tp_contact_factory_get_from_id (connection, id, - got_contact_cb, tp_chat, NULL, NULL); + g_object_unref (contact); } out: diff --git a/src/empathy-invite-participant-dialog.c b/src/empathy-invite-participant-dialog.c index da75e72cd..d88d7232d 100644 --- a/src/empathy-invite-participant-dialog.c +++ b/src/empathy-invite-participant-dialog.c @@ -10,23 +10,133 @@ */ #include <glib/gi18n.h> +#include <folks/folks-telepathy.h> #include "empathy-invite-participant-dialog.h" +#include "libempathy-gtk/empathy-individual-view.h" + G_DEFINE_TYPE (EmpathyInviteParticipantDialog, - empathy_invite_participant_dialog, EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG); + empathy_invite_participant_dialog, GTK_TYPE_DIALOG); + +enum +{ + PROP_TP_CHAT = 1 +}; + +struct _EmpathyInviteParticipantDialogPrivate +{ + EmpathyTpChat *tp_chat; + + EmpathyIndividualStore *store; + EmpathyIndividualView *view; + + GtkWidget *invite_button; +}; static void -empathy_invite_participant_dialog_class_init (EmpathyInviteParticipantDialogClass *klass) +invite_participant_dialog_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) { + EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *) + object; + + switch (param_id) + { + case PROP_TP_CHAT: + g_value_set_object (value, self->priv->tp_chat); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +invite_participant_dialog_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *) + object; + + switch (param_id) + { + case PROP_TP_CHAT: + g_assert (self->priv->tp_chat == NULL); /* construct-only */ + self->priv->tp_chat = g_value_dup_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +invite_participant_dialog_dispose (GObject *object) +{ + EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *) + object; + + tp_clear_object (&self->priv->tp_chat); + tp_clear_object (&self->priv->store); + + G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose ( + object); +} + +static void +empathy_invite_participant_dialog_class_init ( + EmpathyInviteParticipantDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = invite_participant_dialog_get_property; + object_class->set_property = invite_participant_dialog_set_property; + object_class->dispose = invite_participant_dialog_dispose; + + g_type_class_add_private (object_class, + sizeof (EmpathyInviteParticipantDialogPrivate)); + + g_object_class_install_property (object_class, + PROP_TP_CHAT, + g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat", + EMPATHY_TYPE_TP_CHAT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); +} + +static void +view_selection_changed_cb (GtkWidget *treeview, + EmpathyInviteParticipantDialog *self) +{ + FolksIndividual *individual; + + individual = empathy_individual_view_dup_selected (self->priv->view); + + gtk_widget_set_sensitive (self->priv->invite_button, individual != NULL); + + g_object_unref (individual); } static void empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self) { - EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (self); + EmpathyInviteParticipantDialogPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE ( + self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG, + EmpathyInviteParticipantDialogPrivate); + GtkDialog *dialog = GTK_DIALOG (self); GtkWidget *label; char *str; + GtkWidget *content; + EmpathyIndividualManager *mgr; + GtkTreeSelection *selection; + + self->priv = priv; + + content = gtk_dialog_get_content_area (dialog); label = gtk_label_new (NULL); str = g_strdup_printf ( @@ -36,27 +146,44 @@ empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self) gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); - 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_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 0); gtk_widget_show (label); - parent->button_action = gtk_dialog_add_button (GTK_DIALOG (self), - _("Invite"), GTK_RESPONSE_ACCEPT); - gtk_widget_set_sensitive (parent->button_action, FALSE); + gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + + /* Add the treeview */ + mgr = empathy_individual_manager_dup_singleton (); + self->priv->store = empathy_individual_store_new (mgr); + g_object_unref (mgr); + + empathy_individual_store_set_show_groups (self->priv->store, FALSE); + + self->priv->view = empathy_individual_view_new (self->priv->store, + EMPATHY_INDIVIDUAL_VIEW_FEATURE_NONE , EMPATHY_INDIVIDUAL_FEATURE_NONE); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->view)); + + g_signal_connect (selection, "changed", + G_CALLBACK (view_selection_changed_cb), self); + + gtk_box_pack_start (GTK_BOX (content), GTK_WIDGET (self->priv->view), + TRUE, TRUE, 0); + gtk_widget_show (GTK_WIDGET (self->priv->view)); + + self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"), + GTK_RESPONSE_ACCEPT); + gtk_widget_set_sensitive (self->priv->invite_button, FALSE); 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 * empathy_invite_participant_dialog_new (GtkWindow *parent, - TpAccount *account) + EmpathyTpChat *tp_chat) { GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG, - "filter-account", account, + "tp-chat", tp_chat, NULL); if (parent != NULL) @@ -66,3 +193,41 @@ empathy_invite_participant_dialog_new (GtkWindow *parent, return self; } + +TpContact * +empathy_invite_participant_dialog_get_selected ( + EmpathyInviteParticipantDialog *self) +{ + FolksIndividual *individual; + GList *personas, *l; + TpContact *contact = NULL; + + individual = empathy_individual_view_dup_selected (self->priv->view); + if (individual == NULL) + return NULL; + + personas = folks_individual_get_personas (individual); + + for (l = personas; l != NULL; l = g_list_next (l)) + { + TpfPersona *persona = l->data; + TpConnection *contact_conn, *chat_conn; + + if (!TPF_IS_PERSONA (persona)) + continue; + + contact = tpf_persona_get_contact (persona); + if (contact == NULL) + continue; + + contact_conn = tp_contact_get_connection (contact); + chat_conn = empathy_tp_chat_get_connection (self->priv->tp_chat); + + if (!tp_strdiff (tp_proxy_get_object_path (contact_conn), + tp_proxy_get_object_path (chat_conn))) + break; + } + + g_object_unref (individual); + return contact; +} diff --git a/src/empathy-invite-participant-dialog.h b/src/empathy-invite-participant-dialog.h index daacf5192..7d32bdd8f 100644 --- a/src/empathy-invite-participant-dialog.h +++ b/src/empathy-invite-participant-dialog.h @@ -14,7 +14,9 @@ #include <gtk/gtk.h> -#include <libempathy-gtk/empathy-contact-selector-dialog.h> +#include <telepathy-glib/account.h> + +#include "libempathy/empathy-tp-chat.h" G_BEGIN_DECLS @@ -27,20 +29,27 @@ G_BEGIN_DECLS typedef struct _EmpathyInviteParticipantDialog EmpathyInviteParticipantDialog; typedef struct _EmpathyInviteParticipantDialogClass EmpathyInviteParticipantDialogClass; +typedef struct _EmpathyInviteParticipantDialogPrivate EmpathyInviteParticipantDialogPrivate; struct _EmpathyInviteParticipantDialog { - EmpathyContactSelectorDialog parent; + GtkDialog parent; + + EmpathyInviteParticipantDialogPrivate *priv; }; struct _EmpathyInviteParticipantDialogClass { - EmpathyContactSelectorDialogClass parent_class; + GtkDialogClass parent_class; }; GType empathy_invite_participant_dialog_get_type (void); -GtkWidget *empathy_invite_participant_dialog_new (GtkWindow *parent, - TpAccount *account); + +GtkWidget * empathy_invite_participant_dialog_new (GtkWindow *parent, + EmpathyTpChat *tp_chat); + +TpContact * empathy_invite_participant_dialog_get_selected ( + EmpathyInviteParticipantDialog *self); G_END_DECLS |