]> git.0d.be Git - empathy.git/blob - src/empathy-invite-participant-dialog.c
Add EmpathyContactChooser
[empathy.git] / src / empathy-invite-participant-dialog.c
1 /*
2  * empathy-invite-participant-dialog.c
3  *
4  * EmpathyInviteParticipantDialog
5  *
6  * (c) 2009, Collabora Ltd.
7  *
8  * Authors:
9  *    Danielle Madeley <danielle.madeley@collabora.co.uk>
10  */
11
12 #include <glib/gi18n.h>
13 #include <folks/folks-telepathy.h>
14
15 #include "empathy-invite-participant-dialog.h"
16
17 #include <libempathy-gtk/empathy-contact-chooser.h>
18 #include <libempathy-gtk/empathy-individual-view.h>
19 #include <libempathy-gtk/empathy-ui-utils.h>
20
21 G_DEFINE_TYPE (EmpathyInviteParticipantDialog,
22     empathy_invite_participant_dialog, GTK_TYPE_DIALOG);
23
24 enum
25 {
26   PROP_TP_CHAT = 1
27 };
28
29 struct _EmpathyInviteParticipantDialogPrivate
30 {
31   EmpathyTpChat *tp_chat;
32
33   GtkWidget *chooser;
34   GtkWidget *invite_button;
35 };
36
37 static void
38 invite_participant_dialog_get_property (GObject *object,
39     guint param_id,
40     GValue *value,
41     GParamSpec *pspec)
42 {
43   EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
44     object;
45
46   switch (param_id)
47     {
48     case PROP_TP_CHAT:
49       g_value_set_object (value, self->priv->tp_chat);
50       break;
51     default:
52       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
53       break;
54     };
55 }
56
57 static void
58 invite_participant_dialog_set_property (GObject *object,
59     guint param_id,
60     const GValue *value,
61     GParamSpec *pspec)
62 {
63   EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
64     object;
65
66   switch (param_id)
67     {
68     case PROP_TP_CHAT:
69       g_assert (self->priv->tp_chat == NULL); /* construct-only */
70       self->priv->tp_chat = g_value_dup_object (value);
71       break;
72     default:
73       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
74       break;
75     };
76 }
77
78 static void
79 invite_participant_dialog_dispose (GObject *object)
80 {
81   EmpathyInviteParticipantDialog *self = (EmpathyInviteParticipantDialog *)
82     object;
83
84   tp_clear_object (&self->priv->tp_chat);
85
86   G_OBJECT_CLASS (empathy_invite_participant_dialog_parent_class)->dispose (
87       object);
88 }
89
90 static void
91 selection_changed_cb (GtkWidget *treeview,
92     FolksIndividual *selected,
93     EmpathyInviteParticipantDialog *self)
94 {
95   gtk_widget_set_sensitive (self->priv->invite_button, selected != NULL);
96 }
97
98 static void
99 invite_participant_dialog_constructed (GObject *object)
100 {
101   EmpathyInviteParticipantDialog *self =
102     (EmpathyInviteParticipantDialog *) object;
103   GtkDialog *dialog = GTK_DIALOG (self);
104   GtkWidget *label;
105   char *str;
106   GtkWidget *content;
107
108   content = gtk_dialog_get_content_area (dialog);
109
110   label = gtk_label_new (NULL);
111   str = g_strdup_printf (
112       "<span size=\"x-large\" weight=\"bold\">%s</span>\n\n%s",
113       _("Invite Participant"),
114       _("Choose a contact to invite into the conversation:"));
115   gtk_label_set_markup (GTK_LABEL (label), str);
116   g_free (str);
117
118   gtk_box_pack_start (GTK_BOX (content), label, FALSE, TRUE, 6);
119   gtk_widget_show (label);
120
121   gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
122
123   /* contact chooser */
124   self->priv->chooser = empathy_contact_chooser_new (self->priv->tp_chat);
125   gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
126   gtk_widget_show (self->priv->chooser);
127
128   g_signal_connect (self->priv->chooser, "selection-changed",
129       G_CALLBACK (selection_changed_cb), self);
130
131   self->priv->invite_button = gtk_dialog_add_button (dialog, _("Invite"),
132       GTK_RESPONSE_ACCEPT);
133   gtk_widget_set_sensitive (self->priv->invite_button, FALSE);
134
135   gtk_window_set_title (GTK_WINDOW (self), _("Invite Participant"));
136   gtk_window_set_role (GTK_WINDOW (self), "invite_participant");
137
138   /* Set a default height so a few contacts are displayed */
139   gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
140 }
141
142 static void
143 empathy_invite_participant_dialog_class_init (
144     EmpathyInviteParticipantDialogClass *klass)
145 {
146   GObjectClass *object_class = G_OBJECT_CLASS (klass);
147
148   object_class->get_property = invite_participant_dialog_get_property;
149   object_class->set_property = invite_participant_dialog_set_property;
150   object_class->constructed = invite_participant_dialog_constructed;
151   object_class->dispose = invite_participant_dialog_dispose;
152
153   g_type_class_add_private (object_class,
154       sizeof (EmpathyInviteParticipantDialogPrivate));
155
156   g_object_class_install_property (object_class,
157       PROP_TP_CHAT,
158       g_param_spec_object ("tp-chat", "EmpathyTpChat", "EmpathyTpChat",
159           EMPATHY_TYPE_TP_CHAT,
160           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
161 }
162
163 static void
164 empathy_invite_participant_dialog_init (EmpathyInviteParticipantDialog *self)
165 {
166   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (
167       self, EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
168       EmpathyInviteParticipantDialogPrivate);
169 }
170
171 GtkWidget *
172 empathy_invite_participant_dialog_new (GtkWindow *parent,
173     EmpathyTpChat *tp_chat)
174 {
175   GtkWidget *self = g_object_new (EMPATHY_TYPE_INVITE_PARTICIPANT_DIALOG,
176       "tp-chat", tp_chat,
177       NULL);
178
179   if (parent != NULL)
180     {
181       gtk_window_set_transient_for (GTK_WINDOW (self), parent);
182     }
183
184   return self;
185 }
186
187 TpContact *
188 empathy_invite_participant_dialog_get_selected (
189     EmpathyInviteParticipantDialog *self)
190 {
191   return empathy_contact_chooser_get_selected (
192       EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
193 }