2 * Copyright (C) 2009 Collabora Ltd.
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.
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.
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
18 * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
27 #include <glib/gi18n-lib.h>
29 #include <telepathy-glib/interfaces.h>
31 #include <telepathy-yell/telepathy-yell.h>
33 #include <libempathy/empathy-tp-contact-factory.h>
34 #include <libempathy/empathy-camera-monitor.h>
35 #include <libempathy/empathy-contact-manager.h>
36 #include <libempathy/empathy-utils.h>
37 #include <libempathy/empathy-request-util.h>
39 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
40 #include <libempathy/empathy-debug.h>
42 #include <libempathy-gtk/empathy-contact-chooser.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
44 #include <libempathy-gtk/empathy-images.h>
46 #include "empathy-new-call-dialog.h"
47 #include "empathy-account-chooser.h"
48 #include "empathy-call-utils.h"
50 static EmpathyNewCallDialog *dialog_singleton = NULL;
52 G_DEFINE_TYPE(EmpathyNewCallDialog, empathy_new_call_dialog,
55 struct _EmpathyNewCallDialogPriv {
57 GtkWidget *button_audio;
58 GtkWidget *button_video;
60 EmpathyCameraMonitor *monitor;
63 /* Re-use the accept and ok Gtk response so we are sure they won't be used
64 * when the dialog window is closed for example */
67 RESPONSE_AUDIO = GTK_RESPONSE_ACCEPT,
68 RESPONSE_VIDEO = GTK_RESPONSE_OK,
72 * SECTION:empathy-new-call-dialog
73 * @title: EmpathyNewCallDialog
74 * @short_description: A dialog to show a new call
75 * @include: libempathy-gtk/empathy-new-call-dialog.h
77 * #EmpathyNewCallDialog is a dialog which allows a call
78 * to be started with any contact on any enabled account.
82 empathy_new_call_dialog_response (GtkDialog *dialog,
85 EmpathyNewCallDialog *self = (EmpathyNewCallDialog *) dialog;
86 FolksIndividual *individual;
87 EmpathyContact *contact;
89 if (response_id != RESPONSE_AUDIO &&
90 response_id != RESPONSE_VIDEO)
93 individual = empathy_contact_chooser_dup_selected (
94 EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
95 if (individual == NULL) goto out;
97 empathy_individual_can_audio_video_call (individual, NULL, NULL, &contact);
98 g_assert (contact != NULL);
100 empathy_call_new_with_streams (empathy_contact_get_id (contact),
101 empathy_contact_get_account (contact), TRUE,
102 response_id == RESPONSE_VIDEO, empathy_get_current_action_time ());
104 g_object_unref (individual);
105 g_object_unref (contact);
108 gtk_widget_destroy (GTK_WIDGET (dialog));
112 empathy_new_call_dialog_dispose (GObject *object)
114 EmpathyNewCallDialog *self = (EmpathyNewCallDialog *) object;
116 tp_clear_object (&self->priv->monitor);
118 G_OBJECT_CLASS (empathy_new_call_dialog_parent_class)->dispose (object);
122 empathy_new_call_dialog_constructor (GType type,
124 GObjectConstructParam *props)
128 if (dialog_singleton)
130 retval = G_OBJECT (dialog_singleton);
131 g_object_ref (retval);
135 retval = G_OBJECT_CLASS (
136 empathy_new_call_dialog_parent_class)->constructor (type,
139 dialog_singleton = EMPATHY_NEW_CALL_DIALOG (retval);
140 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
147 filter_individual (EmpathyContactChooser *chooser,
148 FolksIndividual *individual,
153 gboolean can_audio_call, can_video_call;
155 empathy_individual_can_audio_video_call (individual, &can_audio_call,
156 &can_video_call, NULL);
158 return can_audio_call || can_video_call;
162 selection_changed_cb (GtkWidget *chooser,
163 FolksIndividual *selected,
164 EmpathyNewCallDialog *self)
166 gboolean can_audio_call, can_video_call;
168 if (selected == NULL)
170 can_audio_call = can_video_call = FALSE;
174 empathy_individual_can_audio_video_call (selected, &can_audio_call,
175 &can_video_call, NULL);
178 gtk_widget_set_sensitive (self->priv->button_audio, can_audio_call);
179 gtk_widget_set_sensitive (self->priv->button_video, can_video_call);
183 selection_activate_cb (GtkWidget *chooser,
184 EmpathyNewCallDialog *self)
186 gtk_dialog_response (GTK_DIALOG (self), RESPONSE_AUDIO);
190 empathy_new_call_dialog_init (EmpathyNewCallDialog *self)
196 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
197 EMPATHY_TYPE_NEW_CALL_DIALOG, EmpathyNewCallDialogPriv);
199 self->priv->monitor = empathy_camera_monitor_dup_singleton ();
201 content = gtk_dialog_get_content_area (GTK_DIALOG (self));
203 label = gtk_label_new (_("Enter a contact identifier or phone number:"));
204 gtk_box_pack_start (GTK_BOX (content), label, FALSE, FALSE, 0);
205 gtk_widget_show (label);
207 /* contact chooser */
208 self->priv->chooser = empathy_contact_chooser_new ();
210 empathy_contact_chooser_set_filter_func (
211 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
213 gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
214 gtk_widget_show (self->priv->chooser);
216 g_signal_connect (self->priv->chooser, "selection-changed",
217 G_CALLBACK (selection_changed_cb), self);
218 g_signal_connect (self->priv->chooser, "activate",
219 G_CALLBACK (selection_activate_cb), self);
222 gtk_dialog_add_button (GTK_DIALOG (self),
223 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
225 /* add video button */
226 self->priv->button_video = gtk_button_new_with_mnemonic (_("_Video Call"));
227 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
228 GTK_ICON_SIZE_BUTTON);
229 gtk_button_set_image (GTK_BUTTON (self->priv->button_video), image);
231 gtk_dialog_add_action_widget (GTK_DIALOG (self), self->priv->button_video,
233 gtk_widget_show (self->priv->button_video);
235 /* add audio button */
236 self->priv->button_audio = gtk_button_new_with_mnemonic (_("_Audio Call"));
237 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
238 GTK_ICON_SIZE_BUTTON);
239 gtk_button_set_image (GTK_BUTTON (self->priv->button_audio), image);
241 gtk_dialog_add_action_widget (GTK_DIALOG (self), self->priv->button_audio,
243 gtk_widget_show (self->priv->button_audio);
245 /* Tweak the dialog */
246 gtk_window_set_title (GTK_WINDOW (self), _("New Call"));
247 gtk_window_set_role (GTK_WINDOW (self), "new_call");
249 /* Set a default height so a few contacts are displayed */
250 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
252 gtk_widget_set_sensitive (self->priv->button_audio, FALSE);
253 gtk_widget_set_sensitive (self->priv->button_video, FALSE);
257 empathy_new_call_dialog_class_init (
258 EmpathyNewCallDialogClass *class)
260 GObjectClass *object_class = G_OBJECT_CLASS (class);
261 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
263 g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
265 object_class->constructor = empathy_new_call_dialog_constructor;
266 object_class->dispose = empathy_new_call_dialog_dispose;
268 dialog_class->response = empathy_new_call_dialog_response;
272 * empathy_new_call_dialog_new:
273 * @parent: parent #GtkWindow of the dialog
275 * Create a new #EmpathyNewCallDialog it.
277 * Return value: the new #EmpathyNewCallDialog
280 empathy_new_call_dialog_show (GtkWindow *parent)
284 dialog = g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG, NULL);
288 gtk_window_set_transient_for (GTK_WINDOW (dialog),
289 GTK_WINDOW (parent));
292 gtk_widget_show (dialog);