From 01c381d152073c8b995f402d6518e18f1bed472f Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvittie@collabora.co.uk>
Date: Mon, 16 Apr 2012 19:36:31 +0100
Subject: [PATCH 10/14] tp_account_channel_request_new_file_transfer: add

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
---
 docs/reference/telepathy-glib-sections.txt |    1 +
 telepathy-glib/account-channel-request.c   |   63 ++++++++++++++++++++++++++++
 telepathy-glib/account-channel-request.h   |    9 ++++
 3 files changed, 73 insertions(+)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 9ae02a6..b105594 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -6030,6 +6030,7 @@ tp_account_channel_request_set_request_property
 tp_account_channel_request_new_text
 tp_account_channel_request_new_audio_call
 tp_account_channel_request_new_audio_video_call
+tp_account_channel_request_new_file_transfer
 tp_account_channel_request_create_and_handle_channel_async
 tp_account_channel_request_create_and_handle_channel_finish
 tp_account_channel_request_ensure_and_handle_channel_async
diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c
index 66e1c79..e2ef20d 100644
--- a/telepathy-glib/account-channel-request.c
+++ b/telepathy-glib/account-channel-request.c
@@ -2001,3 +2001,66 @@ tp_account_channel_request_new_audio_video_call (
   g_hash_table_unref (request);
   return self;
 }
+
+/**
+ * tp_account_channel_request_new_file_transfer:
+ * @account: a #TpAccount
+ * @filename: a suggested name for the file, which should not contain
+ *  directories or directory separators (for example, if you are sending
+ * a file called /home/user/monkey.pdf, set this to monkey.pdf)
+ * @mime_type: (allow-none): the MIME type (content-type) of the file;
+ *  a %NULL value is allowed, and is treated as
+ *  "application/octet-stream"
+ * @size: the file's size in bytes
+ * @user_action_time: the time of the user action that caused this request,
+ *  or one of the special values %TP_USER_ACTION_TIME_NOT_USER_ACTION or
+ *  %TP_USER_ACTION_TIME_CURRENT_TIME (see
+ *  #TpAccountChannelRequest:user-action-time)
+ *
+ * Convenience function to create a new #TpAccountChannelRequest object,
+ * which will yield a FileTransfer channel to send a file to a contact.
+ *
+ * After creating the request, you will also need to set the "target"
+ * of the channel by calling one of the following functions:
+ *
+ * * tp_account_channel_request_set_target_contact()
+ * * tp_account_channel_request_set_target_id()
+ *
+ * Returns: a new #TpAccountChannelRequest object
+ *
+ * Since: 0.19.UNRELEASED
+ */
+TpAccountChannelRequest *
+tp_account_channel_request_new_file_transfer (
+    TpAccount *account,
+    const gchar *filename,
+    const gchar *mime_type,
+    guint64 size,
+    gint64 user_action_time)
+{
+  TpAccountChannelRequest *self;
+  GHashTable *request;
+
+  g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
+  g_return_val_if_fail (!tp_str_empty (filename), NULL);
+  g_return_val_if_fail (mime_type == NULL || mime_type[0] != '\0', NULL);
+
+  if (mime_type == NULL)
+    mime_type = "application/octet-stream";
+
+  request = tp_asv_new (
+      TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
+          TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME, G_TYPE_STRING, filename,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE, G_TYPE_STRING, mime_type,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE, G_TYPE_UINT64, size,
+      NULL);
+
+  self = g_object_new (TP_TYPE_ACCOUNT_CHANNEL_REQUEST,
+      "account", account,
+      "request", request,
+      "user-action-time", user_action_time,
+      NULL);
+  g_hash_table_unref (request);
+  return self;
+}
diff --git a/telepathy-glib/account-channel-request.h b/telepathy-glib/account-channel-request.h
index 913739e..1de6dd5 100644
--- a/telepathy-glib/account-channel-request.h
+++ b/telepathy-glib/account-channel-request.h
@@ -102,6 +102,15 @@ TpAccountChannelRequest *tp_account_channel_request_new_audio_video_call (
     TpAccount *account,
     gint64 user_action_time) G_GNUC_WARN_UNUSED_RESULT;
 
+/* File transfer */
+
+TpAccountChannelRequest *tp_account_channel_request_new_file_transfer (
+    TpAccount *account,
+    const gchar *filename,
+    const gchar *mime_type,
+    guint64 size,
+    gint64 user_action_time) G_GNUC_WARN_UNUSED_RESULT;
+
 /* Channel target (shared between all channel types) */
 
 void tp_account_channel_request_set_target_contact (
-- 
1.7.10