diff options
-rw-r--r-- | libempathy/empathy-dispatcher.c | 588 | ||||
-rw-r--r-- | src/empathy-event-manager.c | 85 |
2 files changed, 0 insertions, 673 deletions
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 119de9adf..986213cd8 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -206,303 +206,6 @@ free_connection_data (ConnectionData *cd) } } -#if 0 -GType -empathy_dispatcher_tube_get_type (void) -{ - static GType type_id = 0; - - if (!type_id) { - type_id = g_boxed_type_register_static ("EmpathyDispatcherTube", - (GBoxedCopyFunc) empathy_dispatcher_tube_ref, - (GBoxedFreeFunc) empathy_dispatcher_tube_unref); - } - - return type_id; -} - -EmpathyDispatcherTube * -empathy_dispatcher_tube_ref (EmpathyDispatcherTube *data) -{ - DispatcherTube *tube = (DispatcherTube*) data; - - g_return_val_if_fail (tube != NULL, NULL); - - tube->ref_count++; - - return data; -} - -void -empathy_dispatcher_tube_unref (EmpathyDispatcherTube *data) -{ - DispatcherTube *tube = (DispatcherTube*) data; - - g_return_if_fail (tube != NULL); - - if (--tube->ref_count == 0) { - if (!tube->handled) { - DEBUG ("Tube can't be handled, closing"); - tp_cli_channel_type_tubes_call_close_tube (tube->public.channel, -1, - tube->public.id, - NULL, NULL, NULL, - NULL); - } - - g_free (tube->bus_name); - g_free (tube->object_path); - g_object_unref (tube->factory); - g_object_unref (tube->public.channel); - g_object_unref (tube->public.initiator); - g_slice_free (DispatcherTube, tube); - } -} - -static void -dispatcher_tubes_handle_tube_cb (TpProxy *channel, - const GError *error, - gpointer user_data, - GObject *dispatcher) -{ - DispatcherTube *tube = user_data; - - if (error) { - DEBUG ("Error: %s", error->message); - } else { - tube->handled = TRUE; - } -} - - -void -empathy_dispatcher_tube_process (EmpathyDispatcher *dispatcher, - EmpathyDispatcherTube *etube) -{ - DispatcherTube *tube = (DispatcherTube*) etube; - - if (tube->public.activatable) { - TpProxy *connection; - TpProxy *thandler; - gchar *object_path; - guint handle_type; - guint handle; - - /* Create the proxy for the tube handler */ - thandler = g_object_new (TP_TYPE_PROXY, - "dbus-connection", tp_get_bus (), - "bus-name", tube->bus_name, - "object-path", tube->object_path, - NULL); - tp_proxy_add_interface_by_id (thandler, EMP_IFACE_QUARK_TUBE_HANDLER); - - /* Give the tube to the handler */ - g_object_get (tube->public.channel, - "connection", &connection, - "object-path", &object_path, - "handle_type", &handle_type, - "handle", &handle, - NULL); - - DEBUG ("Dispatching tube"); - emp_cli_tube_handler_call_handle_tube (thandler, -1, - connection->bus_name, - connection->object_path, - object_path, handle_type, - handle, tube->public.id, - dispatcher_tubes_handle_tube_cb, - empathy_dispatcher_tube_ref (etube), - (GDestroyNotify) empathy_dispatcher_tube_unref, - G_OBJECT (dispatcher)); - - g_object_unref (thandler); - g_object_unref (connection); - g_free (object_path); - } -} - -static void -dispatcher_tubes_new_tube_cb (TpChannel *channel, - guint id, - guint initiator, - guint type, - const gchar *service, - GHashTable *parameters, - guint state, - gpointer user_data, - GObject *dispatcher) -{ - static TpDBusDaemon *daemon = NULL; - DispatcherTube *tube; - McAccount *account; - guint number; - gchar **names; - gboolean running = FALSE; - GError *error = NULL; - - /* Increase tube count */ - number = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (channel), "tube-count")); - g_object_set_data (G_OBJECT (channel), "tube-count", GUINT_TO_POINTER (++number)); - DEBUG ("Increased tube count for channel %p: %d", channel, number); - - /* We dispatch only local pending tubes */ - if (state != TP_TUBE_STATE_LOCAL_PENDING) { - return; - } - - if (!daemon) { - daemon = tp_dbus_daemon_new (tp_get_bus ()); - } - - account = empathy_channel_get_account (channel); - tube = g_slice_new (DispatcherTube); - tube->ref_count = 1; - tube->handled = FALSE; - tube->factory = empathy_contact_factory_dup_singleton (); - tube->bus_name = empathy_tube_handler_build_bus_name (type, service); - tube->object_path = empathy_tube_handler_build_object_path (type, service); - tube->public.activatable = FALSE; - tube->public.id = id; - tube->public.channel = g_object_ref (channel); - tube->public.initiator = empathy_contact_factory_get_from_handle (tube->factory, - account, - initiator); - g_object_unref (account); - - DEBUG ("Looking for tube handler: %s", tube->bus_name); - /* Check if that bus-name has an owner, if it has one that means the - * app is already running and we can directly give the channel. */ - tp_cli_dbus_daemon_run_name_has_owner (daemon, -1, tube->bus_name, - &running, NULL, NULL); - if (running) { - DEBUG ("Tube handler running"); - tube->public.activatable = TRUE; - empathy_dispatcher_tube_process (EMPATHY_DISPATCHER (dispatcher), - (EmpathyDispatcherTube*) tube); - empathy_dispatcher_tube_unref ((EmpathyDispatcherTube*) tube); - return; - } - - DEBUG ("Tube handler is not running. Try to activate it"); - /* Check if that bus-name is activatable, if not that means the - * application needed to handle this tube isn't installed. */ - if (!tp_cli_dbus_daemon_run_list_activatable_names (daemon, -1, - &names, &error, - NULL)) { - DEBUG ("Error listing activatable names: %s", error->message); - g_clear_error (&error); - } else { - gchar **name; - - for (name = names; *name; name++) { - if (!tp_strdiff (*name, tube->bus_name)) { - DEBUG ("Found tube handler"); - tube->public.activatable = TRUE; - break; - } - } - g_strfreev (names); - } - - if (!tube->public.activatable) - DEBUG ("Didn't find tube handler"); - - g_signal_emit (dispatcher, signals[FILTER_TUBE], 0, tube); - empathy_dispatcher_tube_unref ((EmpathyDispatcherTube*) tube); -} - -static void -dispatcher_tubes_list_tubes_cb (TpChannel *channel, - const GPtrArray *tubes, - const GError *error, - gpointer user_data, - GObject *dispatcher) -{ - guint i; - - if (error) { - DEBUG ("Error: %s", error->message); - return; - } - - for (i = 0; i < tubes->len; i++) { - GValueArray *values; - - values = g_ptr_array_index (tubes, i); - dispatcher_tubes_new_tube_cb (channel, - g_value_get_uint (g_value_array_get_nth (values, 0)), - g_value_get_uint (g_value_array_get_nth (values, 1)), - g_value_get_uint (g_value_array_get_nth (values, 2)), - g_value_get_string (g_value_array_get_nth (values, 3)), - g_value_get_boxed (g_value_array_get_nth (values, 4)), - g_value_get_uint (g_value_array_get_nth (values, 5)), - user_data, dispatcher); - } -} - -static void -dispatcher_tubes_channel_invalidated_cb (TpProxy *proxy, - guint domain, - gint code, - gchar *message, - EmpathyDispatcher *dispatcher) -{ - EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); - - DEBUG ("%s", message); - - priv->tubes = g_slist_remove (priv->tubes, proxy); - g_object_unref (proxy); -} - -static void -dispatcher_tubes_tube_closed_cb (TpChannel *channel, - guint id, - gpointer user_data, - GObject *dispatcher) -{ - guint number; - - number = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (channel), "tube-count")); - if (number == 1) { - DEBUG ("No more tube, closing channel"); - tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL); - } - else if (number > 1) { - DEBUG ("Decrease tube count: %d", number); - g_object_set_data (G_OBJECT (channel), "tube-count", GUINT_TO_POINTER (--number)); - } -} - - -static void -dispatcher_tubes_handle_channel (EmpathyDispatcher *dispatcher, - TpChannel *channel) -{ - EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); - - DEBUG ("Called"); - - priv->tubes = g_slist_prepend (priv->tubes, g_object_ref (channel)); - g_signal_connect (channel, "invalidated", - G_CALLBACK (dispatcher_tubes_channel_invalidated_cb), - dispatcher); - - tp_cli_channel_type_tubes_connect_to_tube_closed (channel, - dispatcher_tubes_tube_closed_cb, - NULL, NULL, - G_OBJECT (dispatcher), NULL); - tp_cli_channel_type_tubes_connect_to_new_tube (channel, - dispatcher_tubes_new_tube_cb, - NULL, NULL, - G_OBJECT (dispatcher), NULL); - tp_cli_channel_type_tubes_call_list_tubes (channel, -1, - dispatcher_tubes_list_tubes_cb, - NULL, NULL, - G_OBJECT (dispatcher)); -} - -#endif - static void dispatcher_connection_invalidated_cb (TpConnection *connection, guint domain, gint code, gchar *message, @@ -518,65 +221,6 @@ dispatcher_connection_invalidated_cb (TpConnection *connection, g_hash_table_remove (priv->connections, connection); } -#if 0 - -typedef struct -{ - EmpathyDispatcher *self; - EmpathyChatroom *chatroom; -} dispatcher_connection_invalidated_cb_ctx; - -static dispatcher_connection_invalidated_cb_ctx * -dispatcher_connection_invalidated_cb_ctx_new (EmpathyDispatcher *dispatcher, - EmpathyChatroom *chatroom) -{ - dispatcher_connection_invalidated_cb_ctx *ctx; - - ctx = g_slice_new (dispatcher_connection_invalidated_cb_ctx); - - ctx->self = g_object_ref (dispatcher); - ctx->chatroom = g_object_ref (chatroom); - - return ctx; -} - -static void -dispatcher_connection_invalidated_cb_ctx_free ( - dispatcher_connection_invalidated_cb_ctx *ctx) -{ - g_object_unref (ctx->self); - g_object_unref (ctx->chatroom); - - g_slice_free (dispatcher_connection_invalidated_cb_ctx, ctx); -} - -static void dispatcher_chatroom_invalidated_cb ( - TpProxy *channel, - guint domain, - gint code, - gchar *message, - dispatcher_connection_invalidated_cb_ctx *ctx) -{ - EmpathyDispatcherPriv *priv = GET_PRIV (ctx->self); - gboolean favorite; - - g_object_get (ctx->chatroom, "favorite", &favorite, NULL); - - if (favorite) - { - /* Chatroom is in favorites so don't remove it from the manager */ - g_object_set (ctx->chatroom, "tp-channel", NULL, NULL); - } - else - { - empathy_chatroom_manager_remove (priv->chatroom_mgr, ctx->chatroom); - } -} - -#endif - - -/********************* Sanity from here at some point *********/ static gboolean dispatcher_operation_can_start (EmpathyDispatcher *self, EmpathyDispatchOperation *operation, ConnectionData *cd) @@ -986,77 +630,6 @@ dispatcher_connection_new_channels_cb ( } } -#if 0 /* old dispatching */ - channel = tp_channel_new (connection, object_path, channel_type, - handle_type, handle, NULL); - tp_channel_run_until_ready (channel, NULL, NULL); - - if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TUBES)) { - dispatcher_tubes_handle_channel (dispatcher, channel); - } - - if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT) && - handle_type == TP_HANDLE_TYPE_ROOM) - { - /* Add the chatroom to the chatroom manager */ - EmpathyChatroom *chatroom; - GArray *handles; - gchar **room_ids; - MissionControl *mc; - McAccount *account; - dispatcher_connection_invalidated_cb_ctx *ctx; - - handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1); - g_array_append_val (handles, handle); - - tp_cli_connection_run_inspect_handles (connection, -1, - TP_HANDLE_TYPE_ROOM, handles, &room_ids, NULL, NULL); - - mc = empathy_mission_control_new (); - account = mission_control_get_account_for_tpconnection (mc, connection, - NULL); - - chatroom = empathy_chatroom_manager_find (priv->chatroom_mgr, account, - room_ids[0]); - if (chatroom == NULL) - { - chatroom = empathy_chatroom_new (account); - empathy_chatroom_set_name (chatroom, room_ids[0]); - empathy_chatroom_set_room (chatroom, room_ids[0]); - empathy_chatroom_manager_add (priv->chatroom_mgr, chatroom); - } - else - { - g_object_ref (chatroom); - } - - g_object_set (chatroom, "tp-channel", channel, NULL); - - ctx = dispatcher_connection_invalidated_cb_ctx_new (dispatcher, chatroom); - - g_signal_connect_data (channel, "invalidated", - G_CALLBACK (dispatcher_chatroom_invalidated_cb), ctx, - (GClosureNotify) dispatcher_connection_invalidated_cb_ctx_free, 0); - - g_free (room_ids[0]); - g_free (room_ids); - g_array_free (handles, TRUE); - g_object_unref (mc); - g_object_unref (account); - g_object_unref (chatroom); - } - - if (suppress_handler) { - g_signal_emit (dispatcher, signals[DISPATCH_CHANNEL], 0, channel); - } else { - g_signal_emit (dispatcher, signals[FILTER_CHANNEL], 0, channel); - } - - g_object_unref (channel); - -} -#endif - static void dispatcher_connection_got_channels_property (TpProxy *proxy, const GValue *channels_prop, const GError *error, gpointer user_data, @@ -1573,65 +1146,6 @@ empathy_dispatcher_join_muc (McAccount *account, const gchar *roomname, g_object_unref (dispatcher); } -#if 0 -typedef struct { - GFile *gfile; - TpHandle handle; -} FileChannelRequest; - -static void -tp_file_state_notify_cb (EmpathyTpFile *tp_file) -{ - EmpFileTransferState state; - - state = empathy_tp_file_get_state (tp_file, NULL); - if (state == EMP_FILE_TRANSFER_STATE_COMPLETED || - state == EMP_FILE_TRANSFER_STATE_CANCELLED) { - DEBUG ("Transfer is done, unref the object"); - g_object_unref (tp_file); - } -} - -static void -file_channel_create_cb (TpConnection *connection, - const gchar *object_path, - GHashTable *properties, - const GError *error, - gpointer user_data, - GObject *weak_object) -{ - TpChannel *channel; - EmpathyTpFile *tp_file; - FileChannelRequest *request = (FileChannelRequest *) user_data; - - if (error) { - DEBUG ("Couldn't request channel: %s", error->message); - return; - } - - channel = tp_channel_new (connection, - object_path, - EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, - TP_HANDLE_TYPE_CONTACT, - request->handle, - NULL); - - /* We give the ref to the callback, it is responsible to unref the - * object once the transfer is done. */ - tp_file = empathy_tp_file_new (channel); - empathy_tp_file_offer (tp_file, request->gfile, NULL); - g_signal_connect (tp_file, "notify::state", - G_CALLBACK (tp_file_state_notify_cb), - NULL); - - g_object_unref (request->gfile); - g_slice_free (FileChannelRequest, request); - g_object_unref (channel); -} - -#endif - - static void dispatcher_create_channel_cb (TpConnection *connect, const gchar *object_path, GHashTable *properties, const GError *error, @@ -1732,105 +1246,3 @@ empathy_dispatcher_send_file_to_contact (EmpathyContact *contact, g_object_unref (dispatcher); } - -#if 0 - MissionControl *mc; - McAccount *account; - TpConnection *connection; - guint handle; - FileChannelRequest *request; - GHashTable *args; - GValue *value; - GFileInfo *info; - gchar *filename; - GTimeVal last_modif; - GError *error = NULL; - - g_return_if_fail (EMPATHY_IS_CONTACT (contact)); - g_return_if_fail (G_IS_FILE (gfile)); - - info = g_file_query_info (gfile, - G_FILE_ATTRIBUTE_STANDARD_SIZE "," - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," - G_FILE_ATTRIBUTE_TIME_MODIFIED, - 0, NULL, &error); - - if (error) { - DEBUG ("Can't get info about the file: %s", error->message); - g_clear_error (&error); - return; - } - - mc = empathy_mission_control_new (); - account = empathy_contact_get_account (contact); - connection = mission_control_get_tpconnection (mc, account, NULL); - handle = empathy_contact_get_handle (contact); - - request = g_slice_new0 (FileChannelRequest); - request->gfile = g_object_ref (gfile); - request->handle = handle; - - filename = g_file_get_basename (request->gfile); - tp_connection_run_until_ready (connection, FALSE, NULL, NULL); - - DEBUG ("Sending %s from a stream to %s (size %"G_GINT64_FORMAT", content-type %s)", - filename, empathy_contact_get_name (contact), - g_file_info_get_size (info), - g_file_info_get_content_type (info)); - - args = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, - (GDestroyNotify) tp_g_value_slice_free); - - /* org.freedesktop.Telepathy.Channel.ChannelType */ - value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (value, EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER); - g_hash_table_insert (args, TP_IFACE_CHANNEL ".ChannelType", value); - - /* org.freedesktop.Telepathy.Channel.TargetHandleType */ - value = tp_g_value_slice_new (G_TYPE_UINT); - g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT); - g_hash_table_insert (args, TP_IFACE_CHANNEL ".TargetHandleType", value); - - /* org.freedesktop.Telepathy.Channel.TargetHandle */ - value = tp_g_value_slice_new (G_TYPE_UINT); - g_value_set_uint (value, handle); - g_hash_table_insert (args, TP_IFACE_CHANNEL ".TargetHandle", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentType */ - value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (value, g_file_info_get_content_type (info)); - g_hash_table_insert (args, - EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentType", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Filename */ - value = tp_g_value_slice_new (G_TYPE_STRING); - g_value_set_string (value, g_filename_display_basename (filename)); - g_hash_table_insert (args, - EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Filename", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Size */ - value = tp_g_value_slice_new (G_TYPE_UINT64); - g_value_set_uint64 (value, g_file_info_get_size (info)); - g_hash_table_insert (args, - EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Size", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Date */ - g_file_info_get_modification_time (info, &last_modif); - value = tp_g_value_slice_new (G_TYPE_UINT64); - g_value_set_uint64 (value, last_modif.tv_sec); - g_hash_table_insert (args, - EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Date", value); - - /* FIXME: Description ? */ - /* FIXME: ContentHashType and ContentHash ? */ - - tp_cli_connection_interface_requests_call_create_channel (connection, -1, - args, file_channel_create_cb, request, NULL, NULL); - - g_hash_table_destroy (args); - g_free (filename); - g_object_unref (mc); - g_object_unref (connection); -} - -#endif diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c index 514b8b21c..7ac18123f 100644 --- a/src/empathy-event-manager.c +++ b/src/empathy-event-manager.c @@ -167,11 +167,6 @@ event_manager_add (EmpathyEventManager *manager, if (approval) { event->approval = approval; -#if 0 /* FIXME */ - g_signal_connect_swapped (channel, "invalidated", - G_CALLBACK (event_remove), - event); -#endif } DEBUG ("Adding event %p", event); @@ -479,77 +474,6 @@ event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher, } } -#if 0 /* FIXME dispatcher */ - -#define TUBE_NO_APP_MESSAGE _("%s is offering you an invitation, but " \ - "you don't have the needed external " \ - "application to handle it.") - - -static void -event_tube_process_func (EventPriv *event) -{ - EmpathyEventManagerPriv *priv = GET_PRIV (event->manager); - EmpathyDispatcherTube *tube = (EmpathyDispatcherTube*) event->user_data; - - if (tube->activatable) { - empathy_dispatcher_tube_process (priv->dispatcher, tube); - } else { - GtkWidget *dialog; - gchar *str; - - /* Tell the user that the tube can't be handled */ - str = g_strdup_printf (TUBE_NO_APP_MESSAGE, - empathy_contact_get_name (tube->initiator)); - - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "%s", str); - gtk_window_set_title (GTK_WINDOW (dialog), - _("Invitation Error")); - g_free (str); - - gtk_widget_show (dialog); - g_signal_connect (dialog, "response", - G_CALLBACK (gtk_widget_destroy), - NULL); - } - - empathy_dispatcher_tube_unref (tube); - event_remove (event); -} - -static void -event_manager_filter_tube_cb (EmpathyDispatcher *dispatcher, - EmpathyDispatcherTube *tube, - EmpathyEventManager *manager) -{ - const gchar *icon_name; - gchar *msg; - - empathy_contact_run_until_ready (tube->initiator, - EMPATHY_CONTACT_READY_NAME, NULL); - - if (tube->activatable) { - icon_name = GTK_STOCK_EXECUTE; - msg = g_strdup_printf (_("%s is offering you an invitation. An external " - "application will be started to handle it."), - empathy_contact_get_name (tube->initiator)); - } else { - icon_name = GTK_STOCK_DIALOG_ERROR; - msg = g_strdup_printf (TUBE_NO_APP_MESSAGE, - empathy_contact_get_name (tube->initiator)); - } - - event_manager_add (manager, tube->initiator, icon_name, msg, - tube->channel, event_tube_process_func, - empathy_dispatcher_tube_ref (tube)); - - g_free (msg); -} -#endif - static void event_pending_subscribe_func (EventPriv *event) { @@ -678,15 +602,6 @@ empathy_event_manager_init (EmpathyEventManager *manager) g_signal_connect (priv->dispatcher, "approve", G_CALLBACK (event_manager_approve_channel_cb), manager); - /*g_signal_connect (priv->dispatcher, "dispatch-channel", - G_CALLBACK (event_manager_dispatch_channel_cb), - manager); - */ -#if 0 /* FIXME dispatcher */ - g_signal_connect (priv->dispatcher, "filter-tube", - G_CALLBACK (event_manager_filter_tube_cb), - manager); -#endif g_signal_connect (priv->contact_manager, "pendings-changed", G_CALLBACK (event_manager_pendings_changed_cb), manager); |