Feature to drag a file from Windows to Mac:

- On Mac client main thread is used for cocoa application in order to simulate drag.
- Send dragging file dir from Windows server to Mac client while dragging after switching screen.
- Dragging information sending is immature now (need to support multi files dragging in the future).
- Used Cocoa function to monitor dragg pasteboard.
- Changed Mac client to use another thread for event queue instead of the main thread.
- Change fileRecieveComplete to fileRecieveCompleted.
This commit is contained in:
jerry
2013-08-30 14:38:43 +00:00
parent 031a84ca84
commit ce1b62db14
52 changed files with 875 additions and 184 deletions

View File

@@ -85,10 +85,10 @@ CClient::CClient(IEventQueue* events,
this,
new TMethodEventJob<CClient>(this,
&CClient::handleFileChunkSending));
m_events->adoptHandler(m_events->forIScreen().fileRecieveComplete(),
m_events->adoptHandler(m_events->forIScreen().fileRecieveCompleted(),
this,
new TMethodEventJob<CClient>(this,
&CClient::handleFileRecieveComplete));
&CClient::handleFileRecieveCompleted));
}
CClient::~CClient()
@@ -711,17 +711,19 @@ CClient::handleFileChunkSending(const CEvent& event, void*)
}
void
CClient::handleFileRecieveComplete(const CEvent& event, void*)
CClient::handleFileRecieveCompleted(const CEvent& event, void*)
{
onFileRecieveComplete();
onFileRecieveCompleted();
}
void
CClient::onFileRecieveComplete()
CClient::onFileRecieveCompleted()
{
if (isReceivedFileSizeValid()) {
m_fileTransferDes = m_screen->getDropTarget();
if (!m_fileTransferDes.empty()) {
std::fstream file;
m_fileTransferDes.append("/").append(m_dragFileList.at(0));
file.open(m_fileTransferDes.c_str(), std::ios::out | std::ios::binary);
if (!file.is_open()) {
// TODO: file open failed
@@ -730,6 +732,9 @@ CClient::onFileRecieveComplete()
file.write(m_receivedFileData.c_str(), m_receivedFileData.size());
file.close();
}
else {
LOG((CLOG_ERR "drop file failed: drop target is empty"));
}
}
}
@@ -752,6 +757,30 @@ CClient::fileChunkReceived(CString data)
m_receivedFileData += data;
}
void
CClient::dragInfoReceived(UInt32 fileNum, CString data)
{
CDragInformation::parseDragInfo(m_dragFileList, fileNum, data);
LOG((CLOG_DEBUG "drag information received"));
LOG((CLOG_DEBUG "total drag file number: %i", m_dragFileList.size()));
for(int i = 0; i < m_dragFileList.size(); ++i) {
LOG((CLOG_DEBUG2 "dragging file %i name: %s", i + 1, m_dragFileList.at(i).c_str()));
}
if (m_dragFileList.size() == 1) {
m_dragFileExt = CDragInformation::getDragFileExtension(m_dragFileList.at(0));
}
else if (m_dragFileList.size() > 1) {
m_dragFileExt.clear();
}
else {
return;
}
m_screen->startDraggingFiles(m_dragFileExt);
}
bool
CClient::isReceivedFileSizeValid()
{

View File

@@ -25,6 +25,7 @@
#include "INode.h"
#include "CCryptoOptions.h"
#include "CEventTypes.h"
#include "CDragInformation.h"
class CEventQueueTimer;
class CScreen;
@@ -100,7 +101,10 @@ public:
//! Received a chunk of file data
void fileChunkReceived(CString data);
//! Received drag information
void dragInfoReceived(UInt32 fileNum, CString data);
//! Create a new thread and use it to send file to Server
void sendFileToServer(const char* filename);
@@ -193,8 +197,8 @@ private:
void handleSuspend(const CEvent& event, void*);
void handleResume(const CEvent& event, void*);
void handleFileChunkSending(const CEvent&, void*);
void handleFileRecieveComplete(const CEvent&, void*);
void onFileRecieveComplete();
void handleFileRecieveCompleted(const CEvent&, void*);
void onFileRecieveCompleted();
public:
bool m_mock;
@@ -223,6 +227,8 @@ private:
CString m_receivedFileData;
CString m_fileTransferSrc;
CString m_fileTransferDes;
CDragFileList m_dragFileList;
CString m_dragFileExt;
};
#endif

View File

@@ -301,6 +301,9 @@ CServerProxy::parseMessage(const UInt8* code)
else if (memcmp(code, kMsgDFileTransfer, 4) == 0) {
fileChunkReceived();
}
else if (memcmp(code, kMsgDDragInfo, 4) == 0) {
dragInfoReceived();
}
else if (memcmp(code, kMsgCClose, 4) == 0) {
// server wants us to hangup
@@ -865,7 +868,7 @@ void
CServerProxy::fileChunkReceived()
{
// parse
UInt8 mark;
UInt8 mark = 0;
CString content;
CProtocolUtil::readf(m_stream, kMsgDFileTransfer + 4, &mark, &content);
@@ -898,7 +901,7 @@ CServerProxy::fileChunkReceived()
break;
case kFileEnd:
m_events->addEvent(CEvent(m_events->forIScreen().fileRecieveComplete(), m_client));
m_events->addEvent(CEvent(m_events->forIScreen().fileRecieveCompleted(), m_client));
if (CLOG->getFilter() >= kDEBUG2) {
LOG((CLOG_DEBUG2 "file data transfer finished"));
m_elapsedTime += m_stopwatch.getTime();
@@ -911,6 +914,17 @@ CServerProxy::fileChunkReceived()
}
}
void
CServerProxy::dragInfoReceived()
{
// parse
UInt32 fileNum = 0;
CString content;
CProtocolUtil::readf(m_stream, kMsgDDragInfo + 4, &fileNum, &content);
m_client->dragInfoReceived(fileNum, content);
}
void
CServerProxy::fileChunkSending(UInt8 mark, char* data, size_t dataSize)
{

View File

@@ -103,6 +103,7 @@ private:
void queryInfo();
void infoAcknowledgment();
void fileChunkReceived();
void dragInfoReceived();
private:
typedef EResult (CServerProxy::*MessageParser)(const UInt8*);