]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-new-call-dialog.c
Updated Polish 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
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include <gtk/gtk.h>
27 #include <glib/gi18n-lib.h>
28
29 #include <telepathy-glib/interfaces.h>
30
31 #include <libempathy/empathy-tp-contact-factory.h>
32 #include <libempathy/empathy-contact-manager.h>
33 #include <libempathy/empathy-call-factory.h>
34 #include <libempathy/empathy-dispatcher.h>
35 #include <libempathy/empathy-utils.h>
36
37 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
38 #include <libempathy/empathy-debug.h>
39
40 #include <libempathy-gtk/empathy-ui-utils.h>
41 #include <libempathy-gtk/empathy-images.h>
42
43 #include "empathy-new-call-dialog.h"
44 #include "empathy-account-chooser.h"
45
46 static EmpathyNewCallDialog *dialog_singleton = NULL;
47
48 G_DEFINE_TYPE(EmpathyNewCallDialog, empathy_new_call_dialog,
49                EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG)
50
51 typedef struct _EmpathyNewCallDialogPriv EmpathyNewCallDialogPriv;
52
53 struct _EmpathyNewCallDialogPriv {
54   GtkWidget *check_video;
55 };
56
57 #define GET_PRIV(o) \
58   (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_NEW_CALL_DIALOG, \
59     EmpathyNewCallDialogPriv))
60
61 /**
62  * SECTION:empathy-new-call-dialog
63  * @title: EmpathyNewCallDialog
64  * @short_description: A dialog to show a new call
65  * @include: libempathy-gtk/empathy-new-call-dialog.h
66  *
67  * #EmpathyNewCallDialog is a dialog which allows a call
68  * to be started with any contact on any enabled account.
69  */
70
71 static void
72 got_contact_cb (EmpathyTpContactFactory *factory,
73     EmpathyContact *contact,
74     const GError *error,
75     gpointer user_data,
76     GObject *object)
77 {
78   EmpathyCallFactory *call_factory;
79   gboolean video = GPOINTER_TO_UINT (user_data);
80
81   if (error != NULL)
82     {
83       DEBUG ("Failed: %s", error->message);
84       return;
85     }
86
87   call_factory = empathy_call_factory_get ();
88   empathy_call_factory_new_call_with_streams (call_factory, contact, TRUE,
89       video);
90 }
91
92 static void
93 empathy_new_call_dialog_response (GtkDialog *dialog, int response_id)
94 {
95   EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
96   EmpathyTpContactFactory *factory;
97   gboolean video;
98   TpConnection *connection;
99   const gchar *contact_id;
100
101   if (response_id != GTK_RESPONSE_ACCEPT) goto out;
102
103   contact_id = empathy_contact_selector_dialog_get_selected (
104       EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), &connection);
105
106   if (EMP_STR_EMPTY (contact_id) || connection == NULL) goto out;
107
108   /* check if video is enabled now because the dialog will be destroyed once
109    * we return from this function. */
110   video = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->check_video));
111
112   factory = empathy_tp_contact_factory_dup_singleton (connection);
113   empathy_tp_contact_factory_get_from_id (factory, contact_id,
114       got_contact_cb, GUINT_TO_POINTER (video), NULL, NULL);
115
116   g_object_unref (factory);
117
118 out:
119   gtk_widget_destroy (GTK_WIDGET (dialog));
120 }
121
122 static gboolean
123 empathy_new_call_dialog_account_filter (EmpathyContactSelectorDialog *dialog,
124     TpAccount *account)
125 {
126   TpConnection *connection;
127   EmpathyDispatcher *dispatcher;
128   GList *classes;
129
130   if (tp_account_get_connection_status (account, NULL) !=
131       TP_CONNECTION_STATUS_CONNECTED)
132     return FALSE;
133
134   /* check if CM supports calls */
135   connection = tp_account_get_connection (account);
136   if (connection == NULL)
137     return FALSE;
138
139   dispatcher = empathy_dispatcher_dup_singleton ();
140
141   classes = empathy_dispatcher_find_requestable_channel_classes
142     (dispatcher, connection, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
143      TP_HANDLE_TYPE_CONTACT, NULL);
144
145   g_object_unref (dispatcher);
146
147   if (classes == NULL)
148     return FALSE;
149
150   g_list_free (classes);
151   return TRUE;
152 }
153
154 static GObject *
155 empathy_new_call_dialog_constructor (GType type,
156     guint n_props,
157     GObjectConstructParam *props)
158 {
159   GObject *retval;
160
161   if (dialog_singleton)
162     {
163       retval = G_OBJECT (dialog_singleton);
164       g_object_ref (retval);
165     }
166   else
167     {
168       retval = G_OBJECT_CLASS (
169       empathy_new_call_dialog_parent_class)->constructor (type,
170         n_props, props);
171
172       dialog_singleton = EMPATHY_NEW_CALL_DIALOG (retval);
173       g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
174     }
175
176   return retval;
177 }
178
179 static void
180 empathy_new_call_dialog_init (EmpathyNewCallDialog *dialog)
181 {
182   EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
183         dialog);
184   EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
185   GtkWidget *image;
186
187   /* add video toggle */
188   priv->check_video = gtk_check_button_new_with_mnemonic (_("Send _Video"));
189
190   gtk_box_pack_end (GTK_BOX (parent->vbox), priv->check_video,
191       FALSE, TRUE, 0);
192
193   gtk_widget_show (priv->check_video);
194
195   /* add chat button */
196   parent->button_action = gtk_button_new_with_mnemonic (_("_Call"));
197   image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
198       GTK_ICON_SIZE_BUTTON);
199   gtk_button_set_image (GTK_BUTTON (parent->button_action), image);
200
201   gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
202       GTK_RESPONSE_ACCEPT);
203   gtk_widget_show (parent->button_action);
204
205   /* Tweak the dialog */
206   gtk_window_set_title (GTK_WINDOW (dialog), _("New Call"));
207   gtk_window_set_role (GTK_WINDOW (dialog), "new_call");
208
209   gtk_widget_set_sensitive (parent->button_action, FALSE);
210 }
211
212 static void
213 empathy_new_call_dialog_class_init (
214   EmpathyNewCallDialogClass *class)
215 {
216   GObjectClass *object_class = G_OBJECT_CLASS (class);
217   GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
218   EmpathyContactSelectorDialogClass *selector_dialog_class = \
219     EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
220
221   g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
222
223   object_class->constructor = empathy_new_call_dialog_constructor;
224
225   dialog_class->response = empathy_new_call_dialog_response;
226
227   selector_dialog_class->account_filter = empathy_new_call_dialog_account_filter;
228 }
229
230 /**
231  * empathy_new_call_dialog_new:
232  * @parent: parent #GtkWindow of the dialog
233  *
234  * Create a new #EmpathyNewCallDialog it.
235  *
236  * Return value: the new #EmpathyNewCallDialog
237  */
238 GtkWidget *
239 empathy_new_call_dialog_show (GtkWindow *parent)
240 {
241   GtkWidget *dialog;
242
243   dialog = g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG, NULL);
244
245   if (parent)
246     {
247       gtk_window_set_transient_for (GTK_WINDOW (dialog),
248                   GTK_WINDOW (parent));
249     }
250
251   gtk_widget_show (dialog);
252   return dialog;
253 }