2 wlmtransfermanager.cpp - Kopete Wlm Protocol
4 Copyright (c) 2008 by Tiago Salem Herrmann <tiagosh@gmail.com>
5 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
7 *************************************************************************
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2 of the License, or (at your option) any later version. *
14 *************************************************************************
17 #include "wlmtransfermanager.h"
18 #include "wlmcontact.h"
19 #include "kopetecontact.h"
20 #include "kopeteuiglobal.h"
23 #include <kmessagebox.h>
29 WlmTransferManager::WlmTransferManager (WlmAccount
* account1
) :
33 QObject::connect (&account ()->server ()->cb
,
34 SIGNAL (incomingFileTransfer
35 (MSN::SwitchboardServerConnection
*,
36 const MSN::fileTransferInvite
&)), this,
37 SLOT (incomingFileTransfer
38 (MSN::SwitchboardServerConnection
*,
39 const MSN::fileTransferInvite
&)));
41 QObject::connect (&account ()->server ()->cb
,
42 SIGNAL (gotFileTransferProgress
43 (MSN::SwitchboardServerConnection
*,
45 const unsigned long long &)), this,
46 SLOT (gotFileTransferProgress
47 (MSN::SwitchboardServerConnection
*,
49 const unsigned long long &)));
51 QObject::connect (&account ()->server ()->cb
,
52 SIGNAL (gotFileTransferFailed (MSN::SwitchboardServerConnection
*,
53 const unsigned int &, const MSN::fileTransferError
&)),
55 SLOT (gotFileTransferFailed (MSN::SwitchboardServerConnection
*,
56 const unsigned int &, const MSN::fileTransferError
&)));
58 QObject::connect (&account ()->server ()->cb
,
59 SIGNAL (gotFileTransferSucceeded
60 (MSN::SwitchboardServerConnection
*,
61 const unsigned int &)), this,
62 SLOT (gotFileTransferSucceeded (MSN::SwitchboardServerConnection
*,
63 const unsigned int &)));
65 QObject::connect (&account ()->server ()->cb
,
66 SIGNAL (slotfileTransferInviteResponse
67 (MSN::SwitchboardServerConnection
*,
68 const unsigned int &, const bool &)), this,
69 SLOT (fileTransferInviteResponse
70 (MSN::SwitchboardServerConnection
* ,
71 const unsigned int &, const bool &)));
73 connect (Kopete::TransferManager::transferManager (),
74 SIGNAL (accepted (Kopete::Transfer
*, const QString
&)),
75 this, SLOT (slotAccepted (Kopete::Transfer
*, const QString
&)));
76 connect (Kopete::TransferManager::transferManager (),
77 SIGNAL (refused (const Kopete::FileTransferInfo
&)),
78 this, SLOT (slotRefused (const Kopete::FileTransferInfo
&)));
82 WlmTransferManager::fileTransferInviteResponse (MSN::SwitchboardServerConnection
* conn
,
83 const unsigned int &sessionID
,
84 const bool & response
)
86 if(!transferSessions
.count(sessionID
))
91 transferSessionData tfd
= transferSessions
[sessionID
];
92 Kopete::ContactPtrList chatmembers
;
93 chatmembers
.append (account ()->contacts ()[tfd
.to
]);
94 WlmChatSession
*_manager
=
95 qobject_cast
<WlmChatSession
*>(Kopete::ChatSessionManager::self ()->
96 findChatSession (account ()->myself (), chatmembers
,
97 account ()->protocol ()));
101 new WlmChatSession (account ()->protocol (),
102 account ()->myself (), chatmembers
);
107 transferSessionData tfd
= transferSessions
[sessionID
];
109 Kopete::TransferManager::transferManager()->
110 cancelIncomingTransfer(tfd
.internalID
);
112 tfd
.ft
->slotError(KIO::ERR_ABORTED
, i18n("File transfer cancelled."));
116 WlmTransferManager::~WlmTransferManager ()
121 WlmTransferManager::incomingFileTransfer (MSN::SwitchboardServerConnection
* conn
,
122 const MSN::fileTransferInvite
& ft
)
124 Kopete::Contact
* contact
=
125 account ()->contacts ()[ft
.userPassport
.c_str ()];
130 if (ft
.type
== MSN::FILE_TRANSFER_WITH_PREVIEW
131 || ft
.type
== MSN::FILE_TRANSFER_WITHOUT_PREVIEW
)
134 if (ft
.type
== MSN::FILE_TRANSFER_WITH_PREVIEW
)
137 loadFromData (KCodecs::
138 base64Decode (QString (ft
.preview
.c_str ()).
141 transferSessionData tsd
;
142 tsd
.from
= ft
.userPassport
.c_str ();
143 tsd
.to
= account ()->myself ()->contactId ();
146 account ()->chatManager ()->createChat (conn
);
147 WlmChatSession
*chat
= account ()->chatManager ()->chatSessions
[conn
];
149 chat
->setCanBeDeleted (false);
152 Kopete::TransferManager::transferManager ()->
153 askIncomingTransfer (contact
,
154 ft
.filename
.c_str (),
157 QString::number (ft
.sessionId
),
159 transferSessions
[ft
.sessionId
] = tsd
;
164 WlmTransferManager::gotFileTransferProgress (MSN::SwitchboardServerConnection
* conn
,
165 const unsigned int &sessionID
,
166 const unsigned long long
169 if(!transferSessions
.count(sessionID
))
172 Kopete::Transfer
* transfer
= transferSessions
[sessionID
].ft
;
174 transfer
->slotProcessed (transferred
);
178 WlmTransferManager::slotAccepted (Kopete::Transfer
* ft
,
179 const QString
& filename
)
181 Kopete::ContactPtrList chatmembers
;
183 // grab contactId from the sender
184 unsigned int sessionID
= ft
->info ().internalId ().toUInt ();
186 if(!transferSessions
.count(sessionID
))
189 QString from
= transferSessions
[sessionID
].from
;
194 // find an existent session, or create a new one
195 chatmembers
.append (account ()->contacts ()[from
]);
196 WlmChatSession
*_manager
= qobject_cast
<WlmChatSession
*>
197 (Kopete::ChatSessionManager::self ()->
198 findChatSession (account ()->myself (), chatmembers
,
199 account ()->protocol ()));
204 new WlmChatSession (account ()->protocol (),
205 account ()->myself (), chatmembers
);
208 MSN::SwitchboardServerConnection
* conn
= _manager
->getChatService ();
212 _manager
->setCanBeDeleted (false);
213 transferSessions
[sessionID
].ft
= ft
;
215 connect (ft
, SIGNAL (transferCanceled ()), this, SLOT (slotCanceled ()));
217 conn
->fileTransferResponse (sessionID
, filename
.toLatin1 ().data (),
222 WlmTransferManager::slotRefused (const Kopete::FileTransferInfo
& fti
)
224 Kopete::ContactPtrList chatmembers
;
225 chatmembers
.append (fti
.contact ());
226 WlmChatSession
*_manager
= qobject_cast
<WlmChatSession
*>
227 (Kopete::ChatSessionManager::self ()->
228 findChatSession (account ()->myself (), chatmembers
,
229 account ()->protocol ()));
234 MSN::SwitchboardServerConnection
* conn
= _manager
->getChatService ();
238 conn
->fileTransferResponse (fti
.internalId ().toUInt (), "", false);
242 WlmTransferManager::gotFileTransferFailed (MSN::SwitchboardServerConnection
* conn
,
243 const unsigned int &sessionID
,
244 const MSN::fileTransferError
& error
)
246 if(!transferSessions
.count(sessionID
))
249 transferSessionData tsd
= transferSessions
[sessionID
];
252 Kopete::TransferManager::transferManager ()->
253 cancelIncomingTransfer(tsd
.internalID
);
255 tsd
.ft
->slotError(KIO::ERR_ABORTED
, i18n("File transfer cancelled."));
261 tsd
.ft
->slotError(KIO::ERR_ABORTED
, i18n("File transfer cancelled."));
264 transferSessions
.remove (sessionID
);
269 WlmTransferManager::gotFileTransferSucceeded (MSN::SwitchboardServerConnection
* conn
,
270 const unsigned int &sessionID
)
272 Kopete::Transfer
* transfer
= transferSessions
[sessionID
].ft
;
275 Kopete::ContactPtrList chatmembers
;
276 if (transfer
->info ().direction () ==
277 Kopete::FileTransferInfo::Incoming
)
278 chatmembers
.append (account ()->
279 contacts ()[transferSessions
[sessionID
].
282 chatmembers
.append (account ()->
283 contacts ()[transferSessions
[sessionID
].to
]);
285 WlmChatSession
*_manager
= qobject_cast
<WlmChatSession
*>
286 (Kopete::ChatSessionManager::self ()->
287 findChatSession (account ()->myself (), chatmembers
,
288 account ()->protocol ()));
290 _manager
->raiseView ();
291 transfer
->slotComplete ();
292 transferSessions
.remove (sessionID
);
297 WlmTransferManager::slotCanceled ()
299 kDebug (14210) << k_funcinfo
;
300 Kopete::Transfer
* ft
= qobject_cast
< Kopete::Transfer
* >(sender ());
303 unsigned int sessionID
= 0;
304 QMap
< unsigned int, transferSessionData
>::iterator i
=
305 transferSessions
.begin ();
306 for (; i
!= transferSessions
.end (); ++i
)
307 if (i
.value ().ft
== ft
)
308 sessionID
= i
.key ();
313 transferSessionData session
= transferSessions
[sessionID
];
315 Kopete::ContactPtrList chatmembers
;
316 if (ft
->info ().direction () == Kopete::FileTransferInfo::Incoming
)
317 chatmembers
.append (account ()->contacts ()[session
.from
]);
319 chatmembers
.append (account ()->contacts ()[session
.to
]);
321 WlmChatSession
*_manager
= qobject_cast
<WlmChatSession
*>
322 (Kopete::ChatSessionManager::self ()->
323 findChatSession (account ()->myself (), chatmembers
,
324 account ()->protocol ()));
328 _manager
->raiseView ();
330 MSN::SwitchboardServerConnection
* conn
= _manager
->getChatService ();
337 transferSessions
.remove (sessionID
);
338 conn
->cancelFileTransfer (sessionID
);
342 #include "wlmtransfermanager.moc"