mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-11 06:17:40 +08:00
Feature to drag a file from Mac (client) to Windows (server):
- temporarily drop dragging file to desktop (specified by command line arg --filetransfer-des) - on Mac side, fake an esc key while dragging off the screen does not seem to work
This commit is contained in:
@@ -76,6 +76,9 @@ CClientProxy1_5::parseMessage(const UInt8* code)
|
||||
if (memcmp(code, kMsgDFileTransfer, 4) == 0) {
|
||||
fileChunkReceived();
|
||||
}
|
||||
else if (memcmp(code, kMsgDDragInfo, 4) == 0) {
|
||||
dragInfoReceived();
|
||||
}
|
||||
else {
|
||||
return CClientProxy1_4::parseMessage(code);
|
||||
}
|
||||
@@ -133,3 +136,14 @@ CClientProxy1_5::fileChunkReceived()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CClientProxy1_5::dragInfoReceived()
|
||||
{
|
||||
// parse
|
||||
UInt32 fileNum = 0;
|
||||
CString content;
|
||||
CProtocolUtil::readf(getStream(), kMsgDDragInfo + 4, &fileNum, &content);
|
||||
|
||||
m_server->dragInfoReceived(fileNum, content);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
virtual void fileChunkSending(UInt8 mark, char* data, size_t dataSize);
|
||||
virtual bool parseMessage(const UInt8* code);
|
||||
void fileChunkReceived();
|
||||
void dragInfoReceived();
|
||||
|
||||
private:
|
||||
IEventQueue* m_events;
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include "CThread.h"
|
||||
#include "TMethodJob.h"
|
||||
#include "CFileChunker.h"
|
||||
#include "CDragInformation.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
@@ -75,7 +74,8 @@ CServer::CServer(CConfig& config, CPrimaryClient* primaryClient, CScreen* screen
|
||||
m_relativeMoves(false),
|
||||
m_keyboardBroadcasting(false),
|
||||
m_lockedToScreen(false),
|
||||
m_screen(screen)
|
||||
m_screen(screen),
|
||||
m_sendFileThread(NULL)
|
||||
{
|
||||
// must have a primary client and it must have a canonical name
|
||||
assert(m_primaryClient != NULL);
|
||||
@@ -243,6 +243,8 @@ CServer::~CServer()
|
||||
// disable and disconnect primary client
|
||||
m_primaryClient->disable();
|
||||
removeClient(m_primaryClient);
|
||||
|
||||
delete m_sendFileThread;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -1950,9 +1952,11 @@ void
|
||||
CServer::onFileRecieveCompleted()
|
||||
{
|
||||
if (isReceivedFileSizeValid()) {
|
||||
if (!m_fileTransferDes.empty()) {
|
||||
if (!m_fileTransferDes.empty() && m_dragFileList.size() > 0) {
|
||||
std::fstream file;
|
||||
file.open(m_fileTransferDes.c_str(), std::ios::out | std::ios::binary);
|
||||
CString dropTarget = m_fileTransferDes;
|
||||
dropTarget.append("/").append(m_dragFileList.at(0));
|
||||
file.open(dropTarget.c_str(), std::ios::out | std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
// TODO: file open failed
|
||||
}
|
||||
@@ -1960,6 +1964,9 @@ CServer::onFileRecieveCompleted()
|
||||
file.write(m_receivedFileData.c_str(), m_receivedFileData.size());
|
||||
file.close();
|
||||
}
|
||||
else {
|
||||
LOG((CLOG_ERR "drop file failed: drop target is empty"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2262,7 +2269,7 @@ CServer::isReceivedFileSizeValid()
|
||||
void
|
||||
CServer::sendFileToClient(const char* filename)
|
||||
{
|
||||
CThread* thread = new CThread(
|
||||
m_sendFileThread = new CThread(
|
||||
new TMethodJob<CServer>(
|
||||
this, &CServer::sendFileThread,
|
||||
reinterpret_cast<void*>(const_cast<char*>(filename))));
|
||||
@@ -2279,4 +2286,23 @@ CServer::sendFileThread(void* filename)
|
||||
catch (std::runtime_error error) {
|
||||
LOG((CLOG_ERR "failed sending file chunks: %s", error.what()));
|
||||
}
|
||||
|
||||
delete m_sendFileThread;
|
||||
m_sendFileThread = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
CServer::dragInfoReceived(UInt32 fileNum, CString content)
|
||||
{
|
||||
CDragInformation::parseDragInfo(m_dragFileList, fileNum, content);
|
||||
LOG((CLOG_INFO "drag information received"));
|
||||
LOG((CLOG_INFO "total drag file number: %i", m_dragFileList.size()));
|
||||
|
||||
for(int i = 0; i < m_dragFileList.size(); ++i) {
|
||||
LOG((CLOG_INFO "dragging file %i name: %s", i + 1, m_dragFileList.at(i).c_str()));
|
||||
}
|
||||
|
||||
if (m_dragFileList.size() != 0) {
|
||||
//TODO: fake a dragging operation
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "stdvector.h"
|
||||
#include "INode.h"
|
||||
#include "CEventTypes.h"
|
||||
#include "CDragInformation.h"
|
||||
|
||||
class CBaseClientProxy;
|
||||
class CEventQueueTimer;
|
||||
@@ -38,6 +39,7 @@ class CPrimaryClient;
|
||||
class CInputFilter;
|
||||
class CScreen;
|
||||
class IEventQueue;
|
||||
class CThread;
|
||||
|
||||
//! Synergy server
|
||||
/*!
|
||||
@@ -153,6 +155,9 @@ public:
|
||||
//! Create a new thread and use it to send file to client
|
||||
void sendFileToClient(const char* filename);
|
||||
|
||||
//! Received dragging information from client
|
||||
void dragInfoReceived(UInt32 fileNum, CString content);
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
//@{
|
||||
@@ -456,6 +461,8 @@ private:
|
||||
CString m_receivedFileData;
|
||||
CString m_fileTransferSrc;
|
||||
CString m_fileTransferDes;
|
||||
CDragFileList m_dragFileList;
|
||||
CThread* m_sendFileThread;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user