From 031a84ca8489fa40b223535dcfcbc92f6dc6ccba Mon Sep 17 00:00:00 2001 From: jerry Date: Fri, 23 Aug 2013 15:36:23 +0000 Subject: [PATCH] - Allow dragging one file from Windows (server) to Mac (client), --filetransfer-des needs to be specified in client side's command line. --- src/lib/client/CClient.cpp | 27 +++++++++++++++++++++++++++ src/lib/client/CClient.h | 7 +++++++ src/lib/platform/CMSWindowsScreen.cpp | 19 ++++++++++++------- src/lib/platform/CMSWindowsScreen.h | 4 +--- src/lib/platform/COSXScreen.cpp | 2 +- src/lib/platform/COSXScreen.h | 2 +- src/lib/platform/CXWindowsScreen.cpp | 2 +- src/lib/platform/CXWindowsScreen.h | 2 +- src/lib/server/CServer.cpp | 10 +++++++++- src/lib/server/CServer.h | 2 +- src/lib/synergy/CClientApp.cpp | 1 + src/lib/synergy/CPlatformScreen.cpp | 3 ++- src/lib/synergy/CPlatformScreen.h | 8 +++++++- src/lib/synergy/CScreen.cpp | 18 +++++++++++++++--- src/lib/synergy/CScreen.h | 5 +++++ src/lib/synergy/IPlatformScreen.h | 4 +++- src/lib/synergy/IPrimaryScreen.h | 2 +- 17 files changed, 95 insertions(+), 23 deletions(-) diff --git a/src/lib/client/CClient.cpp b/src/lib/client/CClient.cpp index d137c2b3..fe49bc6e 100644 --- a/src/lib/client/CClient.cpp +++ b/src/lib/client/CClient.cpp @@ -85,6 +85,10 @@ CClient::CClient(IEventQueue* events, this, new TMethodEventJob(this, &CClient::handleFileChunkSending)); + m_events->adoptHandler(m_events->forIScreen().fileRecieveComplete(), + this, + new TMethodEventJob(this, + &CClient::handleFileRecieveComplete)); } CClient::~CClient() @@ -706,6 +710,29 @@ CClient::handleFileChunkSending(const CEvent& event, void*) sendFileChunk(event.getData()); } +void +CClient::handleFileRecieveComplete(const CEvent& event, void*) +{ + onFileRecieveComplete(); +} + +void +CClient::onFileRecieveComplete() +{ + if (isReceivedFileSizeValid()) { + if (!m_fileTransferDes.empty()) { + std::fstream file; + file.open(m_fileTransferDes.c_str(), std::ios::out | std::ios::binary); + if (!file.is_open()) { + // TODO: file open failed + } + + file.write(m_receivedFileData.c_str(), m_receivedFileData.size()); + file.close(); + } + } +} + void CClient::clearReceivedFileData() { diff --git a/src/lib/client/CClient.h b/src/lib/client/CClient.h index e9bab8dd..525a6b19 100644 --- a/src/lib/client/CClient.h +++ b/src/lib/client/CClient.h @@ -104,6 +104,9 @@ public: //! Create a new thread and use it to send file to Server void sendFileToServer(const char* filename); + //! Set file transder destination + void setFileTransferDes(CString& des) { m_fileTransferDes = des; } + //@} //! @name accessors //@{ @@ -190,6 +193,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(); public: bool m_mock; @@ -216,6 +221,8 @@ private: CCryptoOptions m_crypto; std::size_t m_expectedFileSize; CString m_receivedFileData; + CString m_fileTransferSrc; + CString m_fileTransferDes; }; #endif diff --git a/src/lib/platform/CMSWindowsScreen.cpp b/src/lib/platform/CMSWindowsScreen.cpp index 432d86e0..19e40504 100644 --- a/src/lib/platform/CMSWindowsScreen.cpp +++ b/src/lib/platform/CMSWindowsScreen.cpp @@ -114,7 +114,6 @@ CMSWindowsScreen::CMSWindowsScreen( m_keyState(NULL), m_hasMouse(GetSystemMetrics(SM_MOUSEPRESENT) != 0), m_showingMouse(false), - m_startDragging(false), m_events(events) { assert(s_windowInstance != NULL); @@ -664,7 +663,7 @@ CMSWindowsScreen::getJumpZoneSize() const } bool -CMSWindowsScreen::isAnyMouseButtonDown() const +CMSWindowsScreen::isAnyMouseButtonDown(UInt32& buttonID) const { static const char* buttonToName[] = { "", @@ -677,6 +676,7 @@ CMSWindowsScreen::isAnyMouseButtonDown() const for (UInt32 i = 1; i < sizeof(m_buttons) / sizeof(m_buttons[0]); ++i) { if (m_buttons[i]) { + buttonID = i; LOG((CLOG_DEBUG "locked by \"%s\"", buttonToName[i])); return true; } @@ -1273,11 +1273,15 @@ CMSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam) if (button >= kButtonLeft && button <= kButtonExtra0 + 1) { if (pressed) { m_buttons[button] = true; + if (button == kButtonLeft) { + m_draggingFileDir.clear(); + LOG((CLOG_DEBUG "dragging file directory is cleared")); + } } else { m_buttons[button] = false; - if (m_startDragging && button == kButtonLeft) { - m_startDragging = false; + if (m_draggingStarted && button == kButtonLeft) { + m_draggingStarted = false; } } } @@ -1340,13 +1344,14 @@ CMSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my) m_events->forIPrimaryScreen().motionOnPrimary(), CMotionInfo::alloc(m_xCursor, m_yCursor)); - if (m_buttons[kButtonLeft] == true && m_startDragging == false) { + if (m_buttons[kButtonLeft] == true && m_draggingStarted == false) { // temporarily log out dragging file directory char dir[MAX_PATH]; m_hookLibraryLoader.m_getDraggingFileDir(dir); - LOG((CLOG_DEBUG "dragging file: %s", dir)); + m_draggingFileDir.append(dir); + LOG((CLOG_DEBUG "dragging file directory: %s", m_draggingFileDir.c_str())); - m_startDragging = true; + m_draggingStarted = true; } } else diff --git a/src/lib/platform/CMSWindowsScreen.h b/src/lib/platform/CMSWindowsScreen.h index b32ab54f..656c147c 100644 --- a/src/lib/platform/CMSWindowsScreen.h +++ b/src/lib/platform/CMSWindowsScreen.h @@ -83,7 +83,7 @@ public: virtual void fakeInputBegin(); virtual void fakeInputEnd(); virtual SInt32 getJumpZoneSize() const; - virtual bool isAnyMouseButtonDown() const; + virtual bool isAnyMouseButtonDown(UInt32& buttonID) const; virtual void getCursorCenter(SInt32& x, SInt32& y) const; // ISecondaryScreen overrides @@ -325,8 +325,6 @@ private: s_screen; IEventQueue* m_events; - - bool m_startDragging; }; #endif diff --git a/src/lib/platform/COSXScreen.cpp b/src/lib/platform/COSXScreen.cpp index e60a3a9e..447f7661 100644 --- a/src/lib/platform/COSXScreen.cpp +++ b/src/lib/platform/COSXScreen.cpp @@ -308,7 +308,7 @@ COSXScreen::getJumpZoneSize() const } bool -COSXScreen::isAnyMouseButtonDown() const +COSXScreen::isAnyMouseButtonDown(UInt32& buttonID) const { return (GetCurrentButtonState() != 0); } diff --git a/src/lib/platform/COSXScreen.h b/src/lib/platform/COSXScreen.h index 9b3259e1..5d8eb196 100644 --- a/src/lib/platform/COSXScreen.h +++ b/src/lib/platform/COSXScreen.h @@ -74,7 +74,7 @@ public: virtual void fakeInputBegin(); virtual void fakeInputEnd(); virtual SInt32 getJumpZoneSize() const; - virtual bool isAnyMouseButtonDown() const; + virtual bool isAnyMouseButtonDown(UInt32& buttonID) const; virtual void getCursorCenter(SInt32& x, SInt32& y) const; // ISecondaryScreen overrides diff --git a/src/lib/platform/CXWindowsScreen.cpp b/src/lib/platform/CXWindowsScreen.cpp index 99ca61e0..0b8d8c11 100644 --- a/src/lib/platform/CXWindowsScreen.cpp +++ b/src/lib/platform/CXWindowsScreen.cpp @@ -798,7 +798,7 @@ CXWindowsScreen::getJumpZoneSize() const } bool -CXWindowsScreen::isAnyMouseButtonDown() const +CXWindowsScreen::isAnyMouseButtonDown(UInt32& buttonID) const { // query the pointer to get the button state Window root, window; diff --git a/src/lib/platform/CXWindowsScreen.h b/src/lib/platform/CXWindowsScreen.h index 91261877..3dd2850e 100644 --- a/src/lib/platform/CXWindowsScreen.h +++ b/src/lib/platform/CXWindowsScreen.h @@ -61,7 +61,7 @@ public: virtual void fakeInputBegin(); virtual void fakeInputEnd(); virtual SInt32 getJumpZoneSize() const; - virtual bool isAnyMouseButtonDown() const; + virtual bool isAnyMouseButtonDown(UInt32& buttonID) const; virtual void getCursorCenter(SInt32& x, SInt32& y) const; // ISecondaryScreen overrides diff --git a/src/lib/server/CServer.cpp b/src/lib/server/CServer.cpp index 882a8892..41c144e2 100644 --- a/src/lib/server/CServer.cpp +++ b/src/lib/server/CServer.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include // @@ -1656,6 +1655,14 @@ CServer::onMouseUp(ButtonID id) // relay m_active->mouseUp(id); + + if (!m_screen->isOnScreen()) { + CString& dir = m_screen->getDraggingFileDir(); + if (!dir.empty()) { + LOG((CLOG_DEBUG "drop file to client: %s", dir.c_str())); + sendFileToClient(dir.c_str()); + } + } } bool @@ -2249,6 +2256,7 @@ CServer::sendFileThread(void* filename) { try { char* name = reinterpret_cast(filename); + LOG((CLOG_DEBUG "sendFileChunks: %s", name)); CFileChunker::sendFileChunks(name, m_events, this); } catch (std::runtime_error error) { diff --git a/src/lib/server/CServer.h b/src/lib/server/CServer.h index 6b24062a..ccc9a098 100644 --- a/src/lib/server/CServer.h +++ b/src/lib/server/CServer.h @@ -144,7 +144,7 @@ public: //! Set the expected size of receiving file void setExpectedFileSize(CString data); - //! Set + //! Set file transder destination void setFileTransferDes(CString& des) { m_fileTransferDes = des; } //! Received a chunk of file data diff --git a/src/lib/synergy/CClientApp.cpp b/src/lib/synergy/CClientApp.cpp index 27d0ff16..bea5c962 100644 --- a/src/lib/synergy/CClientApp.cpp +++ b/src/lib/synergy/CClientApp.cpp @@ -465,6 +465,7 @@ CClientApp::startClient() s_client->connect(); + s_client->setFileTransferDes(getFileTransferDes()); updateStatus(); return true; } diff --git a/src/lib/synergy/CPlatformScreen.cpp b/src/lib/synergy/CPlatformScreen.cpp index 0423424a..41be16c7 100644 --- a/src/lib/synergy/CPlatformScreen.cpp +++ b/src/lib/synergy/CPlatformScreen.cpp @@ -19,7 +19,8 @@ #include "CPlatformScreen.h" CPlatformScreen::CPlatformScreen(IEventQueue* events) : - IPlatformScreen(events) + IPlatformScreen(events), + m_draggingStarted(false) { } diff --git a/src/lib/synergy/CPlatformScreen.h b/src/lib/synergy/CPlatformScreen.h index 9ef393b9..ccbbf34f 100644 --- a/src/lib/synergy/CPlatformScreen.h +++ b/src/lib/synergy/CPlatformScreen.h @@ -48,7 +48,7 @@ public: virtual void fakeInputBegin() = 0; virtual void fakeInputEnd() = 0; virtual SInt32 getJumpZoneSize() const = 0; - virtual bool isAnyMouseButtonDown() const = 0; + virtual bool isAnyMouseButtonDown(UInt32& buttonID) const = 0; virtual void getCursorCenter(SInt32& x, SInt32& y) const = 0; // ISecondaryScreen overrides @@ -76,6 +76,8 @@ public: virtual SInt32 pollActiveGroup() const; virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const; + virtual CString& getDraggingFileDir() { return m_draggingFileDir; } + // IPlatformScreen overrides virtual void enable() = 0; virtual void disable() = 0; @@ -108,6 +110,10 @@ protected: // IPlatformScreen overrides virtual void handleSystemEvent(const CEvent& event, void*) = 0; + +protected: + CString m_draggingFileDir; + bool m_draggingStarted; }; #endif diff --git a/src/lib/synergy/CScreen.cpp b/src/lib/synergy/CScreen.cpp index 823b0ced..bf07ae67 100644 --- a/src/lib/synergy/CScreen.cpp +++ b/src/lib/synergy/CScreen.cpp @@ -371,9 +371,15 @@ bool CScreen::isLockedToScreen() const { // check for pressed mouse buttons - if (m_screen->isAnyMouseButtonDown()) { - LOG((CLOG_DEBUG "locked by mouse button")); - return true; + UInt32 buttonID = 0; + if (m_screen->isAnyMouseButtonDown(buttonID)) { + LOG((CLOG_DEBUG "locked by mouse buttonID: %d", buttonID)); + if (buttonID == kButtonLeft) { + // this should fake an esc pressed + m_screen->fakeMouseButton(buttonID, false); + } + + return (buttonID == kButtonLeft) ? false : true; } // not locked @@ -409,6 +415,12 @@ CScreen::pollActiveModifiers() const return m_screen->pollActiveModifiers(); } +CString& +CScreen::getDraggingFileDir() const +{ + return m_screen->getDraggingFileDir(); +} + void* CScreen::getEventTarget() const { diff --git a/src/lib/synergy/CScreen.h b/src/lib/synergy/CScreen.h index f5972253..e4e38100 100644 --- a/src/lib/synergy/CScreen.h +++ b/src/lib/synergy/CScreen.h @@ -24,6 +24,7 @@ #include "KeyTypes.h" #include "MouseTypes.h" #include "OptionTypes.h" +#include "CString.h" class IClipboard; class IPlatformScreen; @@ -266,6 +267,10 @@ public: */ KeyModifierMask pollActiveModifiers() const; + //! Get dragging file's directory. + + CString& getDraggingFileDir() const; + //@} // IScreen overrides diff --git a/src/lib/synergy/IPlatformScreen.h b/src/lib/synergy/IPlatformScreen.h index 1e4bea9d..b21fb077 100644 --- a/src/lib/synergy/IPlatformScreen.h +++ b/src/lib/synergy/IPlatformScreen.h @@ -157,7 +157,7 @@ public: virtual void fakeInputBegin() = 0; virtual void fakeInputEnd() = 0; virtual SInt32 getJumpZoneSize() const = 0; - virtual bool isAnyMouseButtonDown() const = 0; + virtual bool isAnyMouseButtonDown(UInt32& buttonID) const = 0; virtual void getCursorCenter(SInt32& x, SInt32& y) const = 0; // ISecondaryScreen overrides @@ -185,6 +185,8 @@ public: virtual SInt32 pollActiveGroup() const = 0; virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const = 0; + virtual CString& getDraggingFileDir() = 0; + protected: //! Handle system event /*! diff --git a/src/lib/synergy/IPrimaryScreen.h b/src/lib/synergy/IPrimaryScreen.h index 74a865bc..c8fbfd74 100644 --- a/src/lib/synergy/IPrimaryScreen.h +++ b/src/lib/synergy/IPrimaryScreen.h @@ -152,7 +152,7 @@ public: "current" means up to the last processed event but it can mean the current physical mouse button state. */ - virtual bool isAnyMouseButtonDown() const = 0; + virtual bool isAnyMouseButtonDown(UInt32& buttonID) const = 0; //! Get cursor center position /*!