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 <libempathy/empathy-tp-contact-factory.h>
32 #include <libempathy/empathy-camera-monitor.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-request-util.h>
36 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
37 #include <libempathy/empathy-debug.h>
39 #include <libempathy-gtk/empathy-contact-chooser.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
41 #include <libempathy-gtk/empathy-images.h>
43 #include "empathy-new-call-dialog.h"
44 #include "empathy-account-chooser.h"
45 #include "empathy-call-utils.h"
47 static EmpathyNewCallDialog *dialog_singleton = NULL;
49 G_DEFINE_TYPE(EmpathyNewCallDialog, empathy_new_call_dialog,
52 struct _EmpathyNewCallDialogPriv {
54 GtkWidget *button_audio;
55 GtkWidget *button_video;
57 EmpathyCameraMonitor *monitor;
60 /* Re-use the accept and ok Gtk response so we are sure they won't be used
61 * when the dialog window is closed for example */
64 RESPONSE_AUDIO = GTK_RESPONSE_ACCEPT,
65 RESPONSE_VIDEO = GTK_RESPONSE_OK,
69 * SECTION:empathy-new-call-dialog
70 * @title: EmpathyNewCallDialog
71 * @short_description: A dialog to show a new call
72 * @include: libempathy-gtk/empathy-new-call-dialog.h
74 * #EmpathyNewCallDialog is a dialog which allows a call
75 * to be started with any contact on any enabled account.
79 empathy_new_call_dialog_response (GtkDialog *dialog,
82 EmpathyNewCallDialog *self = (EmpathyNewCallDialog *) dialog;
83 FolksIndividual *individual;
84 EmpathyContact *contact;
86 if (response_id != RESPONSE_AUDIO &&
87 response_id != RESPONSE_VIDEO)
90 individual = empathy_contact_chooser_dup_selected (
91 EMPATHY_CONTACT_CHOOSER (self->priv->chooser));
92 if (individual == NULL) goto out;
94 empathy_individual_can_audio_video_call (individual, NULL, NULL, &contact);
95 g_assert (contact != NULL);
97 empathy_call_new_with_streams (empathy_contact_get_id (contact),
98 empathy_contact_get_account (contact), TRUE,
99 response_id == RESPONSE_VIDEO, empathy_get_current_action_time ());
101 g_object_unref (individual);
102 g_object_unref (contact);
105 gtk_widget_destroy (GTK_WIDGET (dialog));
109 empathy_new_call_dialog_dispose (GObject *object)
111 EmpathyNewCallDialog *self = (EmpathyNewCallDialog *) object;
113 tp_clear_object (&self->priv->monitor);
115 G_OBJECT_CLASS (empathy_new_call_dialog_parent_class)->dispose (object);
119 empathy_new_call_dialog_constructor (GType type,
121 GObjectConstructParam *props)
125 if (dialog_singleton)
127 retval = G_OBJECT (dialog_singleton);
128 g_object_ref (retval);
132 retval = G_OBJECT_CLASS (
133 empathy_new_call_dialog_parent_class)->constructor (type,
136 dialog_singleton = EMPATHY_NEW_CALL_DIALOG (retval);
137 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
144 filter_individual (EmpathyContactChooser *chooser,
145 FolksIndividual *individual,
150 gboolean can_audio_call, can_video_call;
152 empathy_individual_can_audio_video_call (individual, &can_audio_call,
153 &can_video_call, NULL);
155 return can_audio_call || can_video_call;
159 selection_changed_cb (GtkWidget *chooser,
160 FolksIndividual *selected,
161 EmpathyNewCallDialog *self)
163 gboolean can_audio_call, can_video_call;
165 if (selected == NULL)
167 can_audio_call = can_video_call = FALSE;
171 empathy_individual_can_audio_video_call (selected, &can_audio_call,
172 &can_video_call, NULL);
175 gtk_widget_set_sensitive (self->priv->button_audio, can_audio_call);
176 gtk_widget_set_sensitive (self->priv->button_video, can_video_call);
180 selection_activate_cb (GtkWidget *chooser,
181 EmpathyNewCallDialog *self)
183 gtk_dialog_response (GTK_DIALOG (self), RESPONSE_AUDIO);
187 empathy_new_call_dialog_init (EmpathyNewCallDialog *self)
193 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
194 EMPATHY_TYPE_NEW_CALL_DIALOG, EmpathyNewCallDialogPriv);
196 self->priv->monitor = empathy_camera_monitor_dup_singleton ();
198 content = gtk_dialog_get_content_area (GTK_DIALOG (self));
200 label = gtk_label_new (_("Enter a contact identifier or phone number:"));
201 gtk_box_pack_start (GTK_BOX (content), label, FALSE, FALSE, 0);
202 gtk_widget_show (label);
204 /* contact chooser */
205 self->priv->chooser = empathy_contact_chooser_new ();
207 empathy_contact_chooser_set_filter_func (
208 EMPATHY_CONTACT_CHOOSER (self->priv->chooser), filter_individual, self);
210 gtk_box_pack_start (GTK_BOX (content), self->priv->chooser, TRUE, TRUE, 6);
211 gtk_widget_show (self->priv->chooser);
213 g_signal_connect (self->priv->chooser, "selection-changed",
214 G_CALLBACK (selection_changed_cb), self);
215 g_signal_connect (self->priv->chooser, "activate",
216 G_CALLBACK (selection_activate_cb), self);
219 gtk_dialog_add_button (GTK_DIALOG (self),
220 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
222 /* add video button */
223 self->priv->button_video = gtk_button_new_with_mnemonic (_("_Video Call"));
224 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
225 GTK_ICON_SIZE_BUTTON);
226 gtk_button_set_image (GTK_BUTTON (self->priv->button_video), image);
228 gtk_dialog_add_action_widget (GTK_DIALOG (self), self->priv->button_video,
230 gtk_widget_show (self->priv->button_video);
232 /* add audio button */
233 self->priv->button_audio = gtk_button_new_with_mnemonic (_("_Audio Call"));
234 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
235 GTK_ICON_SIZE_BUTTON);
236 gtk_button_set_image (GTK_BUTTON (self->priv->button_audio), image);
238 gtk_dialog_add_action_widget (GTK_DIALOG (self), self->priv->button_audio,
240 gtk_widget_show (self->priv->button_audio);
242 /* Tweak the dialog */
243 gtk_window_set_title (GTK_WINDOW (self), _("New Call"));
244 gtk_window_set_role (GTK_WINDOW (self), "new_call");
246 /* Set a default height so a few contacts are displayed */
247 gtk_window_set_default_size (GTK_WINDOW (self), -1, 400);
249 gtk_widget_set_sensitive (self->priv->button_audio, FALSE);
250 gtk_widget_set_sensitive (self->priv->button_video, FALSE);
254 empathy_new_call_dialog_class_init (
255 EmpathyNewCallDialogClass *class)
257 GObjectClass *object_class = G_OBJECT_CLASS (class);
258 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
260 g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
262 object_class->constructor = empathy_new_call_dialog_constructor;
263 object_class->dispose = empathy_new_call_dialog_dispose;
265 dialog_class->response = empathy_new_call_dialog_response;
269 * empathy_new_call_dialog_new:
270 * @parent: parent #GtkWindow of the dialog
272 * Create a new #EmpathyNewCallDialog it.
274 * Return value: the new #EmpathyNewCallDialog
277 empathy_new_call_dialog_show (GtkWindow *parent)
281 dialog = g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG, NULL);
285 gtk_window_set_transient_for (GTK_WINDOW (dialog),
286 GTK_WINDOW (parent));
289 gtk_widget_show (dialog);