summaryrefslogtreecommitdiff
path: root/tubes/source/conference.cxx
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-03-22 16:47:55 +0000
committerMatúš Kukan <matus.kukan@gmail.com>2012-07-17 16:39:35 +0200
commitc9f27f64c853870dc45b09dba7d4a5e2370fd4e1 (patch)
tree42f5845c16aa10c475ea8be05d3ca011460460a7 /tubes/source/conference.cxx
parent9bcf81c5645b1fffe6c0253533fe92ee488e60ad (diff)
tubes: Add preliminary API for sending a file
Crashes if the file transfer fails. file-transfer-helper.[ch] are, as their license headers state, LGPL v2.1+. They come from Empathy. I am in the process of refactoring them so they can live in a future version of telepathy-glib (which is itself LGPL v2.1+), so their presence here is temporary.
Diffstat (limited to 'tubes/source/conference.cxx')
-rw-r--r--tubes/source/conference.cxx76
1 files changed, 76 insertions, 0 deletions
diff --git a/tubes/source/conference.cxx b/tubes/source/conference.cxx
index 823a9a93f69c..9a35c70e9a19 100644
--- a/tubes/source/conference.cxx
+++ b/tubes/source/conference.cxx
@@ -445,6 +445,82 @@ void TeleConference::queue( const char* pDBusSender, const char* pPacketData, in
}
+class SendFileRequest {
+public:
+ SendFileRequest( TeleConference *pSelf,
+ TeleConference::FileSentCallback pCallback, void* pUserData)
+ : mpSelf(pSelf)
+ , mpCallback(pCallback)
+ , mpUserData(pUserData) {};
+
+ /* FIXME: make a shared pointer? */
+ TeleConference* mpSelf;
+ TeleConference::FileSentCallback mpCallback;
+ void* mpUserData;
+};
+
+static void TeleConference_TransferDone( EmpathyFTHandler *handler, TpFileTransferChannel *, gpointer user_data)
+{
+ SendFileRequest *request = reinterpret_cast<SendFileRequest *>(user_data);
+
+ request->mpCallback(true, request->mpUserData);
+ delete request;
+ g_object_unref (handler);
+}
+
+static void TeleConference_TransferError( EmpathyFTHandler *handler, const GError *error, gpointer user_data)
+{
+ SendFileRequest *request = reinterpret_cast<SendFileRequest *>(user_data);
+
+ SAL_INFO( "tubes", "TeleConference_TransferError: " << error->message);
+
+ request->mpCallback(false, request->mpUserData);
+ delete request;
+ g_object_unref (handler);
+}
+
+static void TeleConference_FTReady( EmpathyFTHandler *handler, GError *error, gpointer user_data)
+{
+ SendFileRequest *request = reinterpret_cast<SendFileRequest *>(user_data);
+
+ if ( error != 0 )
+ {
+ request->mpCallback(error == 0, request->mpUserData);
+ delete request;
+ g_object_unref (handler);
+ }
+ else
+ {
+ g_signal_connect(handler, "transfer-done",
+ G_CALLBACK (TeleConference_TransferDone), request);
+ g_signal_connect(handler, "transfer-error",
+ G_CALLBACK (TeleConference_TransferError), request);
+ empathy_ft_handler_start_transfer(handler);
+ }
+}
+
+
+void TeleConference::sendFile( rtl::OUString &localUri, FileSentCallback pCallback, void* pUserData)
+{
+ INFO_LOGGER( "TeleConference::sendFile");
+
+ SAL_WARN_IF( ( !mpAccount || !mpChannel), "tubes",
+ "can't send a file before the tube is set up");
+ if ( !mpAccount || !mpChannel)
+ return;
+
+ GFile *pSource = g_file_new_for_uri(
+ OUStringToOString( localUri, RTL_TEXTENCODING_UTF8).getStr() );
+ SendFileRequest *pReq = new SendFileRequest( this, pCallback, pUserData);
+
+ empathy_ft_handler_new_outgoing( mpAccount,
+ tp_channel_get_target_contact( mpChannel),
+ pSource,
+ 0,
+ &TeleConference_FTReady, pReq);
+}
+
+
bool TeleConference::popPacket( TelePacket& rPacket )
{
INFO_LOGGER( "TeleConference::popPacket");