]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-share-my-desktop.c
Updated Oriya Translation
[empathy.git] / libempathy-gtk / empathy-share-my-desktop.c
1 /*
2  * © 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: Arnaud Maillet <arnaud.maillet@collabora.co.uk>
19  */
20
21 #include <gtk/gtk.h>
22
23 #include <dbus/dbus-glib.h>
24 #include <telepathy-glib/util.h>
25 #include <telepathy-glib/contact.h>
26 #define DEBUG_FLAG EMPATHY_DEBUG_SHARE_DESKTOP
27 #include <libempathy/empathy-debug.h>
28
29 #include "empathy-share-my-desktop.h"
30
31 #define DBUS_SERVICE "org.gnome.Vino"
32 #define DBUS_INTERFACE "org.gnome.VinoScreen"
33
34 typedef struct  {
35   TpContact *contact;
36   TpChannel *channel;
37   gulong signal_invalidated_id;
38 } EmpathyShareMyDesktopPrivate;
39
40
41 static void
42 empathy_share_my_desktop_tube_invalidated (TpProxy *channel,
43     guint domain,
44     gint code,
45     gchar *message,
46     gpointer object)
47 {
48   EmpathyShareMyDesktopPrivate *data = (EmpathyShareMyDesktopPrivate *) object;
49
50   DEBUG ("Tube is invalidated");
51
52   g_signal_handler_disconnect (G_OBJECT (data->channel),
53                data->signal_invalidated_id);
54
55   if (data->channel != NULL)
56     {
57       g_object_unref (data->channel);
58       data->channel = NULL;
59     }
60
61   g_slice_free (EmpathyShareMyDesktopPrivate, data);
62 }
63
64 static void
65 empathy_share_my_desktop_channel_ready (TpChannel *channel,
66     const GError *error_failed,
67     gpointer object)
68 {
69   EmpathyShareMyDesktopPrivate *data = (EmpathyShareMyDesktopPrivate *) object;
70   TpConnection *connection;
71   gchar * connection_path;
72   gchar * tube_path;
73   DBusGConnection *dbus_g_connection;
74   GHashTable *channel_properties;
75   DBusGProxy *proxy;
76   GError *error = NULL;
77   GdkScreen *screen;
78   gchar *obj_path;
79   GtkWidget *window;
80
81   if (channel == NULL)
82   {
83       DEBUG ("The channel is not ready: %s", error_failed->message);
84       return;
85   }
86
87   data->channel = channel;
88
89   data->signal_invalidated_id = g_signal_connect (G_OBJECT (channel),
90       "invalidated", G_CALLBACK (empathy_share_my_desktop_tube_invalidated),
91       data);
92
93   dbus_g_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
94
95   if (dbus_g_connection == NULL)
96     {
97       DEBUG ("Failed to open connection to bus: %s", error->message);
98       g_clear_error (&error);
99       return;
100     }
101
102   screen = gdk_screen_get_default ();
103   obj_path = g_strdup_printf ("/org/gnome/vino/screens/%d",
104       gdk_screen_get_number (screen));
105
106   proxy = dbus_g_proxy_new_for_name (dbus_g_connection, DBUS_SERVICE,
107       obj_path, DBUS_INTERFACE);
108
109   connection = tp_channel_borrow_connection (channel);
110
111   g_object_get (connection, "object-path", &connection_path, NULL);
112
113   DEBUG ("connection path : %s", connection_path);
114
115   g_object_get (channel, "object-path", &tube_path, "channel-properties",
116       &channel_properties, NULL);
117
118   DEBUG ("tube path : %s", tube_path);
119
120   if (!dbus_g_proxy_call (proxy, "ShareWithTube", &error,
121       DBUS_TYPE_G_OBJECT_PATH, connection_path,
122       DBUS_TYPE_G_OBJECT_PATH, tube_path,
123       dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
124       channel_properties,
125       G_TYPE_INVALID, G_TYPE_INVALID))
126     {
127       window = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
128           GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
129           "Vino doesn't support telepathy");
130       gtk_dialog_run (GTK_DIALOG (window));
131       gtk_widget_destroy (window);
132       DEBUG ("Failed to request name: %s",
133           error ? error->message : "No error given");
134       g_clear_error (&error);
135     }
136
137   g_hash_table_unref (channel_properties);
138   g_free (connection_path);
139   g_free (tube_path);
140   g_free (obj_path);
141   g_object_unref (proxy);
142 }
143
144 static void
145 empathy_share_my_desktop_create_channel_cb (TpConnection *connection,
146     const gchar *object_path,
147     GHashTable *channel_properties,
148     const GError *error_failed,
149     gpointer user_data,
150     GObject *object)
151 {
152   EmpathyShareMyDesktopPrivate *data = (EmpathyShareMyDesktopPrivate *)
153       user_data;
154
155   TpChannel *channel;
156   GError *error = NULL;
157
158   if (object_path == NULL)
159   {
160       DEBUG ("CreateChannel failed: %s", error_failed->message);
161       return;
162   }
163
164   DEBUG ("Offering a new stream tube");
165
166   channel = tp_channel_new_from_properties (connection, object_path,
167       channel_properties, &error);
168
169   if (channel == NULL)
170     {
171       DEBUG ("Error requesting channel: %s", error->message);
172       g_clear_error (&error);
173       return;
174     }
175
176   tp_channel_call_when_ready (channel,
177       empathy_share_my_desktop_channel_ready, data);
178 }
179
180 static void
181 empathy_share_my_desktop_connection_ready (TpConnection *connection,
182     const GError *error,
183     gpointer object)
184 {
185   EmpathyShareMyDesktopPrivate *data = (EmpathyShareMyDesktopPrivate *) object;
186   GHashTable *request;
187   GValue *value;
188
189   if (connection == NULL)
190     {
191       DEBUG ("The connection is not ready: %s", error->message);
192       return;
193     }
194
195   request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
196       (GDestroyNotify) tp_g_value_slice_free);
197
198   /* org.freedesktop.Telepathy.Channel.ChannelType */
199   value = tp_g_value_slice_new_static_string
200       (TP_IFACE_CHANNEL_TYPE_STREAM_TUBE);
201   g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType", value);
202
203   /* org.freedesktop.Telepathy.Channel.TargetHandleType */
204   value = tp_g_value_slice_new_uint (TP_HANDLE_TYPE_CONTACT);
205   g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType", value);
206
207   /* org.freedesktop.Telepathy.Channel.TargetHandleType */
208   value = tp_g_value_slice_new_uint (tp_contact_get_handle
209       (data->contact));
210   g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value);
211
212   /* org.freedesktop.Telepathy.Channel.Type.StreamTube.Service */
213   value = tp_g_value_slice_new_static_string ("rfb");
214   g_hash_table_insert (request,
215       TP_IFACE_CHANNEL_TYPE_STREAM_TUBE  ".Service",
216       value);
217
218   tp_cli_connection_interface_requests_call_create_channel
219       (connection, -1, request, empathy_share_my_desktop_create_channel_cb,
220       data, NULL, NULL);
221
222   g_hash_table_destroy (request);
223 }
224
225 void
226 empathy_share_my_desktop_share_with_contact (EmpathyContact *contact)
227 {
228   TpConnection *connection;
229   EmpathyShareMyDesktopPrivate *data;
230   data = g_slice_new (EmpathyShareMyDesktopPrivate);
231   data->contact = empathy_contact_get_tp_contact (contact);
232
233   DEBUG ("Creation of ShareMyDesktop");
234
235   if (!TP_IS_CONTACT (data->contact))
236     {
237       DEBUG ("It's not a tp contact");
238       return;
239     }
240
241   connection = tp_contact_get_connection (data->contact);
242
243   tp_connection_call_when_ready (connection,
244       empathy_share_my_desktop_connection_ready, data);
245 }