- 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);
+ EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton();
+ EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+ McAccount *account = empathy_contact_get_account (contact);
+ TpConnection *connection = g_hash_table_lookup (priv->accounts, account);
+ ConnectionData *connection_data =
+ g_hash_table_lookup (priv->connections, connection);
+ DispatcherRequestData *request_data;
+ GValue *value;
+ GHashTable *request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+ (GDestroyNotify) tp_g_value_slice_free);
+
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+ g_return_if_fail (!EMP_STR_EMPTY (filename));
+ g_return_if_fail (!EMP_STR_EMPTY (content_type));
+
+ /* 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 (request, 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 (request, TP_IFACE_CHANNEL ".TargetHandleType", value);
+
+ /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentType */
+ value = tp_g_value_slice_new (G_TYPE_STRING);
+ g_value_set_string (value, content_type);
+ g_hash_table_insert (request,
+ 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, filename);
+ g_hash_table_insert (request,
+ 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, size);
+ g_hash_table_insert (request,
+ EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Size", value);
+
+ /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Date */
+ value = tp_g_value_slice_new (G_TYPE_UINT64);
+ g_value_set_uint64 (value, date);
+ g_hash_table_insert (request,
+ EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Date", value);
+
+
+ /* The contact handle might not be known yet */
+ request_data = new_dispatcher_request_data (dispatcher, connection,
+ EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT, 0, request,
+ contact, callback, user_data);
+ connection_data->outstanding_requests = g_list_prepend
+ (connection_data->outstanding_requests, request_data);
+
+ tp_connection_call_when_ready (connection,
+ dispatcher_send_file_connection_ready_cb, (gpointer) request_data);
+
+ g_object_unref (dispatcher);
+}
+
+GStrv
+empathy_dispatcher_find_channel_class (EmpathyDispatcher *dispatcher,
+ McAccount *account,
+ const gchar *channel_type,
+ guint handle_type)
+{
+ EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
+ ConnectionData *cd;
+ TpConnection *connection;
+ int i;
+ GPtrArray *classes;
+
+ g_return_val_if_fail (channel_type != NULL, NULL);
+ g_return_val_if_fail (handle_type != 0, NULL);
+
+ connection = g_hash_table_lookup (priv->accounts, account);
+
+ if (connection == NULL)
+ return NULL;
+
+ cd = g_hash_table_lookup (priv->connections, connection);
+
+ if (cd == NULL)
+ return NULL;
+
+
+ classes = cd->requestable_channels;
+ if (classes == NULL)
+ return NULL;
+
+ for (i = 0; i < classes->len; i++)
+ {
+ GValueArray *class;
+ GValue *fixed;
+ GValue *allowed;
+ GHashTable *fprops;
+ const gchar *c_type;
+ guint32 h_type;
+ gboolean valid;
+
+ class = g_ptr_array_index (classes, i);
+ fixed = g_value_array_get_nth (class, 0);
+
+ fprops = g_value_get_boxed (fixed);
+ c_type = tp_asv_get_string (fprops, TP_IFACE_CHANNEL ".ChannelType");
+
+ if (tp_strdiff (channel_type, c_type))
+ continue;
+
+ h_type = tp_asv_get_uint32 (fprops,
+ TP_IFACE_CHANNEL ".TargetHandleType", &valid);
+
+ if (!valid || handle_type != h_type)
+ continue;
+
+ allowed = g_value_array_get_nth (class, 1);
+
+ return g_value_get_boxed (allowed);
+ }
+
+ return NULL;