2 * © 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: Arnaud Maillet <arnaud.maillet@collabora.co.uk>
23 #include <dbus/dbus-glib.h>
24 #include <telepathy-glib/util.h>
25 #include <telepathy-glib/contact.h>
26 #include <telepathy-glib/channel.h>
27 #include <telepathy-glib/interfaces.h>
28 #define DEBUG_FLAG EMPATHY_DEBUG_SHARE_DESKTOP
29 #include <libempathy/empathy-debug.h>
31 #include "empathy-share-my-desktop.h"
33 #define DBUS_SERVICE "org.gnome.Vino"
34 #define DBUS_INTERFACE "org.gnome.VinoScreen"
39 gulong signal_invalidated_id
;
40 } EmpathyShareMyDesktopPrivate
;
44 empathy_share_my_desktop_tube_invalidated (TpProxy
*channel
,
50 EmpathyShareMyDesktopPrivate
*data
= (EmpathyShareMyDesktopPrivate
*) object
;
52 DEBUG ("Tube is invalidated");
54 g_signal_handler_disconnect (G_OBJECT (data
->channel
),
55 data
->signal_invalidated_id
);
57 if (data
->channel
!= NULL
)
59 g_object_unref (data
->channel
);
63 g_slice_free (EmpathyShareMyDesktopPrivate
, data
);
67 empathy_share_my_desktop_channel_ready (TpChannel
*channel
,
68 const GError
*error_failed
,
71 EmpathyShareMyDesktopPrivate
*data
= (EmpathyShareMyDesktopPrivate
*) object
;
72 TpConnection
*connection
;
73 gchar
* connection_path
;
75 DBusGConnection
*dbus_g_connection
;
76 GHashTable
*channel_properties
;
85 DEBUG ("The channel is not ready: %s", error_failed
->message
);
89 data
->channel
= channel
;
91 data
->signal_invalidated_id
= g_signal_connect (G_OBJECT (channel
),
92 "invalidated", G_CALLBACK (empathy_share_my_desktop_tube_invalidated
),
95 dbus_g_connection
= dbus_g_bus_get (DBUS_BUS_SESSION
, &error
);
97 if (dbus_g_connection
== NULL
)
99 DEBUG ("Failed to open connection to bus: %s", error
->message
);
100 g_clear_error (&error
);
104 screen
= gdk_screen_get_default ();
105 obj_path
= g_strdup_printf ("/org/gnome/vino/screens/%d",
106 gdk_screen_get_number (screen
));
108 proxy
= dbus_g_proxy_new_for_name (dbus_g_connection
, DBUS_SERVICE
,
109 obj_path
, DBUS_INTERFACE
);
111 connection
= tp_channel_borrow_connection (channel
);
113 g_object_get (connection
, "object-path", &connection_path
, NULL
);
115 DEBUG ("connection path : %s", connection_path
);
117 g_object_get (channel
, "object-path", &tube_path
, "channel-properties",
118 &channel_properties
, NULL
);
120 DEBUG ("tube path : %s", tube_path
);
122 if (!dbus_g_proxy_call (proxy
, "ShareWithTube", &error
,
123 DBUS_TYPE_G_OBJECT_PATH
, connection_path
,
124 DBUS_TYPE_G_OBJECT_PATH
, tube_path
,
125 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING
, G_TYPE_VALUE
),
127 G_TYPE_INVALID
, G_TYPE_INVALID
))
129 window
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
130 GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
131 "Vino doesn't support telepathy");
132 gtk_dialog_run (GTK_DIALOG (window
));
133 gtk_widget_destroy (window
);
134 DEBUG ("Failed to request name: %s",
135 error
? error
->message
: "No error given");
136 g_clear_error (&error
);
139 g_hash_table_unref (channel_properties
);
140 g_free (connection_path
);
143 g_object_unref (proxy
);
147 empathy_share_my_desktop_create_channel_cb (TpConnection
*connection
,
148 const gchar
*object_path
,
149 GHashTable
*channel_properties
,
150 const GError
*error_failed
,
154 EmpathyShareMyDesktopPrivate
*data
= (EmpathyShareMyDesktopPrivate
*)
158 GError
*error
= NULL
;
160 if (object_path
== NULL
)
162 DEBUG ("CreateChannel failed: %s", error_failed
->message
);
166 DEBUG ("Offering a new stream tube");
168 channel
= tp_channel_new_from_properties (connection
, object_path
,
169 channel_properties
, &error
);
173 DEBUG ("Error requesting channel: %s", error
->message
);
174 g_clear_error (&error
);
178 tp_channel_call_when_ready (channel
,
179 empathy_share_my_desktop_channel_ready
, data
);
183 empathy_share_my_desktop_connection_ready (TpConnection
*connection
,
187 EmpathyShareMyDesktopPrivate
*data
= (EmpathyShareMyDesktopPrivate
*) object
;
191 if (connection
== NULL
)
193 DEBUG ("The connection is not ready: %s", error
->message
);
197 request
= g_hash_table_new_full (g_str_hash
, g_str_equal
, NULL
,
198 (GDestroyNotify
) tp_g_value_slice_free
);
200 /* org.freedesktop.Telepathy.Channel.ChannelType */
201 value
= tp_g_value_slice_new_static_string
202 (TP_IFACE_CHANNEL_TYPE_STREAM_TUBE
);
203 g_hash_table_insert (request
, TP_IFACE_CHANNEL
".ChannelType", value
);
205 /* org.freedesktop.Telepathy.Channel.TargetHandleType */
206 value
= tp_g_value_slice_new_uint (TP_HANDLE_TYPE_CONTACT
);
207 g_hash_table_insert (request
, TP_IFACE_CHANNEL
".TargetHandleType", value
);
209 /* org.freedesktop.Telepathy.Channel.TargetHandleType */
210 value
= tp_g_value_slice_new_uint (tp_contact_get_handle
212 g_hash_table_insert (request
, TP_IFACE_CHANNEL
".TargetHandle", value
);
214 /* org.freedesktop.Telepathy.Channel.Type.StreamTube.Service */
215 value
= tp_g_value_slice_new_static_string ("rfb");
216 g_hash_table_insert (request
,
217 TP_IFACE_CHANNEL_TYPE_STREAM_TUBE
".Service",
220 tp_cli_connection_interface_requests_call_create_channel
221 (connection
, -1, request
, empathy_share_my_desktop_create_channel_cb
,
224 g_hash_table_destroy (request
);
228 empathy_share_my_desktop_share_with_contact (EmpathyContact
*contact
)
230 TpConnection
*connection
;
231 EmpathyShareMyDesktopPrivate
*data
;
232 data
= g_slice_new (EmpathyShareMyDesktopPrivate
);
233 data
->contact
= empathy_contact_get_tp_contact (contact
);
235 DEBUG ("Creation of ShareMyDesktop");
237 if (!TP_IS_CONTACT (data
->contact
))
239 DEBUG ("It's not a tp contact");
243 connection
= tp_contact_get_connection (data
->contact
);
245 tp_connection_call_when_ready (connection
,
246 empathy_share_my_desktop_connection_ready
, data
);