]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-call-dialog.c
Updated Kannada translation
[empathy.git] / libempathy-gtk / empathy-new-call-dialog.c
1 /*
2  * Copyright (C) 2009 Collabora Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
19  */
20
21 #include "config.h"
22 #include "empathy-new-call-dialog.h"
23
24 #include <glib/gi18n-lib.h>
25 #include <tp-account-widgets/tpaw-camera-monitor.h>
26
27 #include "empathy-call-utils.h"
28 #include "empathy-contact-chooser.h"
29 #include "empathy-images.h"
30 #include "empathy-ui-utils.h"
31 #include "empathy-utils.h"
32
33 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
34 #include "empathy-debug.h"
35
36 static EmpathyNewCallDialog *dialog_singleton = NULL;
37
38 G_DEFINE_TYPE(EmpathyNewCallDialog, empathy_new_call_dialog,
39                GTK_TYPE_DIALOG)
40
41 struct _EmpathyNewCallDialogPriv {
42   GtkWidget *chooser;
43   GtkWidget *button_audio;
44   GtkWidget *button_video;
45
46   TpawCameraMonitor *monitor;
47 };
48
49 /* Re-use the accept and ok Gtk response so we are sure they won't be used
50  * when the dialog window is closed for example */
51 enum
52 {
53   RESPONSE_AUDIO = GTK_RESPONSE_ACCEPT,
54   RESPONSE_VIDEO = GTK_RESPONSE_OK,
55 };
56
57 /**
58  * SECTION:empathy-new-call-dialog
59  * @title: EmpathyNewCallDialog
60  * @short_description: A dialog to show a new call
61  * @include: libempathy-gtk/empathy-new-call-dialog.h
62  *
63  * #EmpathyNewCallDialog is a dialog which allows a call
64  * to be started with any contact on any enabled account.
65  */
66
67 static void
68 empathy_new_call_dialog_response (GtkDialog *dialog,
69     int response_id)
70 {
71   EmpathyNewCallDialog *self = (EmpathyNewCallDialog *) dialog;
72   FolksIndividual *individual;
73   EmpathyContact *contact;
74
75   if (response_id != RESPONSE_AUDIO &&
76       response_id != RESPONSE_VIDEO)
77     goto out;
78
79   individual = empathy_contact_chooser_dup_selected (
80       EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
81   if (individual == NULL) goto out;
82
83   empathy_individual_can_audio_video_call (individual, NULL, NULL, &contact);
84   g_assert (contact != NULL);
85
86   empathy_call_new_with_streams (empathy_contact_get_id (contact),
87       empathy_contact_get_account (contact),
88       response_id == RESPONSE_VIDEO, empathy_get_current_action_time ());
89
90   g_object_unref (individual);
91   g_object_unref (contact);
92
93 out:
94   gtk_widget_destroy (GTK_WIDGET (dialog));
95 }
96
97 static void
98 empathy_new_call_dialog_dispose (GObject *object)
99 {
100   EmpathyNewCallDialog *self = (EmpathyNewCallDialog *) object;
101
102   tp_clear_object (&self->priv->monitor);
103
104   G_OBJECT_CLASS (empathy_new_call_dialog_parent_class)->dispose (object);
105 }
106
107 static GObject *
108 empathy_new_call_dialog_constructor (GType type,
109     guint n_props,
110     GObjectConstructParam *props)
111 {
112   GObject *retval;
113
114   if (dialog_singleton)
115     {
116       retval = G_OBJECT (dialog_singleton);
117       g_object_ref (retval);
118     }
119   else
120     {
121       retval = G_OBJECT_CLASS (
122       empathy_new_call_dialog_parent_class)->constructor (type,
123         n_props, props);
124
125       dialog_singleton = EMPATHY_NEW_CALL_DIALOG (retval);
126       g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
127     }
128
129   return retval;
130 }
131
132 static gboolean
133 filter_individual (EmpathyContactChooser *chooser,
134     FolksIndividual *individual,
135     gboolean is_online,
136     gboolean searching,
137     gpointer user_data)
138 {
139   gboolean can_audio_call, can_video_call;
140
141   empathy_individual_can_audio_video_call (individual, &can_audio_call,
142       &can_video_call, NULL);
143
144   return can_audio_call || can_video_call;
145 }
146
147 static void
148 selection_changed_cb (GtkWidget *chooser,
149     FolksIndividual *selected,
150     EmpathyNewCallDialog *self)
151 {
152   gboolean can_audio_call, can_video_call;
153
154   if (selected == NULL)
155     {
156       can_audio_call = can_video_call = FALSE;
157     }
158   else
159     {
160       empathy_individual_can_audio_video_call (selected, &can_audio_call,
161           &can_video_call, NULL);
162     }
163
164   gtk_widget_set_sensitive (self->priv->button_audio, can_audio_call);
165   gtk_widget_set_sensitive (self->priv->button_video, can_video_call);
166 }
167
168 static void
169 selection_activate_cb (GtkWidget *chooser,
170     EmpathyNewCallDialog *self)
171 {
172   gtk_dialog_response (GTK_DIALOG (self), RESPONSE_AUDIO);
173 }
174
175 static void
176 empathy_new_call_dialog_init (EmpathyNewCallDialog *self)
177 {
178   GtkWidget *label;
179   GtkWidget *image;
180   GtkWidget *content;
181
182   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
183       EMPATHY_TYPE_NEW_CALL_DIALOG, EmpathyNewCallDialogPriv);
184
185   self->priv->monitor = tpaw_camera_monitor_dup_singleton ();
186
187   content = gtk_dialog_get_content_area (GTK_DIALOG (self));
188
189   label = gtk_label_new (_("Enter a contact identifier or phone number:"));
190   gtk_box_pack_start (GTK_BOX (content), label, FALSE, FALSE, 0);
191   gtk_widget_show (label);
192
193   /* contact chooser */
194   self->priv->chooser = empathy_contact_chooser_new ();
195
196   empathy_contact_chooser_set_filter_func (
197       EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
198
199   gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
200   gtk_widget_show (self->priv->chooser);
201
202   g_signal_connect (self->priv->chooser, "selection-changed",
203       G_CALLBACK (selection_changed_cb), self);
204   g_signal_connect (self->priv->chooser, "activate",
205       G_CALLBACK (selection_activate_cb), self);
206
207   /* close button */
208   gtk_dialog_add_button (GTK_DIALOG (self),
209       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
210
211   /* add video button */
212   self->priv->button_video = gtk_button_new_with_mnemonic (_("_Video Call"));
213   image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
214       GTK_ICON_SIZE_BUTTON);
215   gtk_button_set_image (GTK_BUTTON (self->priv->button_video), image);
216
217   gtk_dialog_add_action_widget (GTK_DIALOG (self), self->priv->button_video,
218       RESPONSE_VIDEO);
219   gtk_widget_show (self->priv->button_video);
220
221   /* add audio button */
222   self->priv->button_audio = gtk_button_new_with_mnemonic (_("_Audio Call"));
223   image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
224       GTK_ICON_SIZE_BUTTON);
225   gtk_button_set_image (GTK_BUTTON (self->priv->button_audio), image);
226
227   gtk_dialog_add_action_widget (GTK_DIALOG (self), self->priv->button_audio,
228       RESPONSE_AUDIO);
229   gtk_widget_show (self->priv->button_audio);
230
231   /* Tweak the dialog */
232   gtk_window_set_title (GTK_WINDOW (self), _("New Call"));
233   gtk_window_set_role (GTK_WINDOW (self), "new_call");
234
235   /* Set a default height so a few contacts are displayed */
236   gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
237
238   gtk_widget_set_sensitive (self->priv->button_audio, FALSE);
239   gtk_widget_set_sensitive (self->priv->button_video, FALSE);
240 }
241
242 static void
243 empathy_new_call_dialog_class_init (
244   EmpathyNewCallDialogClass *class)
245 {
246   GObjectClass *object_class = G_OBJECT_CLASS (class);
247   GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
248
249   g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
250
251   object_class->constructor = empathy_new_call_dialog_constructor;
252   object_class->dispose = empathy_new_call_dialog_dispose;
253
254   dialog_class->response = empathy_new_call_dialog_response;
255 }
256
257 /**
258  * empathy_new_call_dialog_new:
259  * @parent: parent #GtkWindow of the dialog
260  *
261  * Create a new #EmpathyNewCallDialog it.
262  *
263  * Return value: the new #EmpathyNewCallDialog
264  */
265 GtkWidget *
266 empathy_new_call_dialog_show (GtkWindow *parent)
267 {
268   GtkWidget *dialog;
269
270   dialog = g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG, NULL);
271
272   if (parent)
273     {
274       gtk_window_set_transient_for (GTK_WINDOW (dialog),
275                   GTK_WINDOW (parent));
276     }
277
278   gtk_widget_show (dialog);
279   return dialog;
280 }