- Allow dragging one file from Windows (server) to Mac (client), --filetransfer-des needs to be specified in client side's command line.

This commit is contained in:
jerry 2013-08-23 15:36:23 +00:00
parent 012fe6ddd8
commit 031a84ca84
17 changed files with 95 additions and 23 deletions

View File

@ -85,6 +85,10 @@ CClient::CClient(IEventQueue* events,
this, this,
new TMethodEventJob<CClient>(this, new TMethodEventJob<CClient>(this,
&CClient::handleFileChunkSending)); &CClient::handleFileChunkSending));
m_events->adoptHandler(m_events->forIScreen().fileRecieveComplete(),
this,
new TMethodEventJob<CClient>(this,
&CClient::handleFileRecieveComplete));
} }
CClient::~CClient() CClient::~CClient()
@ -706,6 +710,29 @@ CClient::handleFileChunkSending(const CEvent& event, void*)
sendFileChunk(event.getData()); 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 void
CClient::clearReceivedFileData() CClient::clearReceivedFileData()
{ {

View File

@ -104,6 +104,9 @@ public:
//! Create a new thread and use it to send file to Server //! Create a new thread and use it to send file to Server
void sendFileToServer(const char* filename); void sendFileToServer(const char* filename);
//! Set file transder destination
void setFileTransferDes(CString& des) { m_fileTransferDes = des; }
//@} //@}
//! @name accessors //! @name accessors
//@{ //@{
@ -190,6 +193,8 @@ private:
void handleSuspend(const CEvent& event, void*); void handleSuspend(const CEvent& event, void*);
void handleResume(const CEvent& event, void*); void handleResume(const CEvent& event, void*);
void handleFileChunkSending(const CEvent&, void*); void handleFileChunkSending(const CEvent&, void*);
void handleFileRecieveComplete(const CEvent&, void*);
void onFileRecieveComplete();
public: public:
bool m_mock; bool m_mock;
@ -216,6 +221,8 @@ private:
CCryptoOptions m_crypto; CCryptoOptions m_crypto;
std::size_t m_expectedFileSize; std::size_t m_expectedFileSize;
CString m_receivedFileData; CString m_receivedFileData;
CString m_fileTransferSrc;
CString m_fileTransferDes;
}; };
#endif #endif

View File

@ -114,7 +114,6 @@ CMSWindowsScreen::CMSWindowsScreen(
m_keyState(NULL), m_keyState(NULL),
m_hasMouse(GetSystemMetrics(SM_MOUSEPRESENT) != 0), m_hasMouse(GetSystemMetrics(SM_MOUSEPRESENT) != 0),
m_showingMouse(false), m_showingMouse(false),
m_startDragging(false),
m_events(events) m_events(events)
{ {
assert(s_windowInstance != NULL); assert(s_windowInstance != NULL);
@ -664,7 +663,7 @@ CMSWindowsScreen::getJumpZoneSize() const
} }
bool bool
CMSWindowsScreen::isAnyMouseButtonDown() const CMSWindowsScreen::isAnyMouseButtonDown(UInt32& buttonID) const
{ {
static const char* buttonToName[] = { static const char* buttonToName[] = {
"<invalid>", "<invalid>",
@ -677,6 +676,7 @@ CMSWindowsScreen::isAnyMouseButtonDown() const
for (UInt32 i = 1; i < sizeof(m_buttons) / sizeof(m_buttons[0]); ++i) { for (UInt32 i = 1; i < sizeof(m_buttons) / sizeof(m_buttons[0]); ++i) {
if (m_buttons[i]) { if (m_buttons[i]) {
buttonID = i;
LOG((CLOG_DEBUG "locked by \"%s\"", buttonToName[i])); LOG((CLOG_DEBUG "locked by \"%s\"", buttonToName[i]));
return true; return true;
} }
@ -1273,11 +1273,15 @@ CMSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
if (button >= kButtonLeft && button <= kButtonExtra0 + 1) { if (button >= kButtonLeft && button <= kButtonExtra0 + 1) {
if (pressed) { if (pressed) {
m_buttons[button] = true; m_buttons[button] = true;
if (button == kButtonLeft) {
m_draggingFileDir.clear();
LOG((CLOG_DEBUG "dragging file directory is cleared"));
}
} }
else { else {
m_buttons[button] = false; m_buttons[button] = false;
if (m_startDragging && button == kButtonLeft) { if (m_draggingStarted && button == kButtonLeft) {
m_startDragging = false; m_draggingStarted = false;
} }
} }
} }
@ -1340,13 +1344,14 @@ CMSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
m_events->forIPrimaryScreen().motionOnPrimary(), m_events->forIPrimaryScreen().motionOnPrimary(),
CMotionInfo::alloc(m_xCursor, m_yCursor)); 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 // temporarily log out dragging file directory
char dir[MAX_PATH]; char dir[MAX_PATH];
m_hookLibraryLoader.m_getDraggingFileDir(dir); 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 else

View File

@ -83,7 +83,7 @@ public:
virtual void fakeInputBegin(); virtual void fakeInputBegin();
virtual void fakeInputEnd(); virtual void fakeInputEnd();
virtual SInt32 getJumpZoneSize() const; virtual SInt32 getJumpZoneSize() const;
virtual bool isAnyMouseButtonDown() const; virtual bool isAnyMouseButtonDown(UInt32& buttonID) const;
virtual void getCursorCenter(SInt32& x, SInt32& y) const; virtual void getCursorCenter(SInt32& x, SInt32& y) const;
// ISecondaryScreen overrides // ISecondaryScreen overrides
@ -325,8 +325,6 @@ private:
s_screen; s_screen;
IEventQueue* m_events; IEventQueue* m_events;
bool m_startDragging;
}; };
#endif #endif

View File

@ -308,7 +308,7 @@ COSXScreen::getJumpZoneSize() const
} }
bool bool
COSXScreen::isAnyMouseButtonDown() const COSXScreen::isAnyMouseButtonDown(UInt32& buttonID) const
{ {
return (GetCurrentButtonState() != 0); return (GetCurrentButtonState() != 0);
} }

View File

@ -74,7 +74,7 @@ public:
virtual void fakeInputBegin(); virtual void fakeInputBegin();
virtual void fakeInputEnd(); virtual void fakeInputEnd();
virtual SInt32 getJumpZoneSize() const; virtual SInt32 getJumpZoneSize() const;
virtual bool isAnyMouseButtonDown() const; virtual bool isAnyMouseButtonDown(UInt32& buttonID) const;
virtual void getCursorCenter(SInt32& x, SInt32& y) const; virtual void getCursorCenter(SInt32& x, SInt32& y) const;
// ISecondaryScreen overrides // ISecondaryScreen overrides

View File

@ -798,7 +798,7 @@ CXWindowsScreen::getJumpZoneSize() const
} }
bool bool
CXWindowsScreen::isAnyMouseButtonDown() const CXWindowsScreen::isAnyMouseButtonDown(UInt32& buttonID) const
{ {
// query the pointer to get the button state // query the pointer to get the button state
Window root, window; Window root, window;

View File

@ -61,7 +61,7 @@ public:
virtual void fakeInputBegin(); virtual void fakeInputBegin();
virtual void fakeInputEnd(); virtual void fakeInputEnd();
virtual SInt32 getJumpZoneSize() const; virtual SInt32 getJumpZoneSize() const;
virtual bool isAnyMouseButtonDown() const; virtual bool isAnyMouseButtonDown(UInt32& buttonID) const;
virtual void getCursorCenter(SInt32& x, SInt32& y) const; virtual void getCursorCenter(SInt32& x, SInt32& y) const;
// ISecondaryScreen overrides // ISecondaryScreen overrides

View File

@ -41,7 +41,6 @@
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <sstream>
#include <stdexcept> #include <stdexcept>
// //
@ -1656,6 +1655,14 @@ CServer::onMouseUp(ButtonID id)
// relay // relay
m_active->mouseUp(id); 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 bool
@ -2249,6 +2256,7 @@ CServer::sendFileThread(void* filename)
{ {
try { try {
char* name = reinterpret_cast<char*>(filename); char* name = reinterpret_cast<char*>(filename);
LOG((CLOG_DEBUG "sendFileChunks: %s", name));
CFileChunker::sendFileChunks(name, m_events, this); CFileChunker::sendFileChunks(name, m_events, this);
} }
catch (std::runtime_error error) { catch (std::runtime_error error) {

View File

@ -144,7 +144,7 @@ public:
//! Set the expected size of receiving file //! Set the expected size of receiving file
void setExpectedFileSize(CString data); void setExpectedFileSize(CString data);
//! Set //! Set file transder destination
void setFileTransferDes(CString& des) { m_fileTransferDes = des; } void setFileTransferDes(CString& des) { m_fileTransferDes = des; }
//! Received a chunk of file data //! Received a chunk of file data

View File

@ -465,6 +465,7 @@ CClientApp::startClient()
s_client->connect(); s_client->connect();
s_client->setFileTransferDes(getFileTransferDes());
updateStatus(); updateStatus();
return true; return true;
} }

View File

@ -19,7 +19,8 @@
#include "CPlatformScreen.h" #include "CPlatformScreen.h"
CPlatformScreen::CPlatformScreen(IEventQueue* events) : CPlatformScreen::CPlatformScreen(IEventQueue* events) :
IPlatformScreen(events) IPlatformScreen(events),
m_draggingStarted(false)
{ {
} }

View File

@ -48,7 +48,7 @@ public:
virtual void fakeInputBegin() = 0; virtual void fakeInputBegin() = 0;
virtual void fakeInputEnd() = 0; virtual void fakeInputEnd() = 0;
virtual SInt32 getJumpZoneSize() const = 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; virtual void getCursorCenter(SInt32& x, SInt32& y) const = 0;
// ISecondaryScreen overrides // ISecondaryScreen overrides
@ -76,6 +76,8 @@ public:
virtual SInt32 pollActiveGroup() const; virtual SInt32 pollActiveGroup() const;
virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const; virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const;
virtual CString& getDraggingFileDir() { return m_draggingFileDir; }
// IPlatformScreen overrides // IPlatformScreen overrides
virtual void enable() = 0; virtual void enable() = 0;
virtual void disable() = 0; virtual void disable() = 0;
@ -108,6 +110,10 @@ protected:
// IPlatformScreen overrides // IPlatformScreen overrides
virtual void handleSystemEvent(const CEvent& event, void*) = 0; virtual void handleSystemEvent(const CEvent& event, void*) = 0;
protected:
CString m_draggingFileDir;
bool m_draggingStarted;
}; };
#endif #endif

View File

@ -371,9 +371,15 @@ bool
CScreen::isLockedToScreen() const CScreen::isLockedToScreen() const
{ {
// check for pressed mouse buttons // check for pressed mouse buttons
if (m_screen->isAnyMouseButtonDown()) { UInt32 buttonID = 0;
LOG((CLOG_DEBUG "locked by mouse button")); if (m_screen->isAnyMouseButtonDown(buttonID)) {
return true; 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 // not locked
@ -409,6 +415,12 @@ CScreen::pollActiveModifiers() const
return m_screen->pollActiveModifiers(); return m_screen->pollActiveModifiers();
} }
CString&
CScreen::getDraggingFileDir() const
{
return m_screen->getDraggingFileDir();
}
void* void*
CScreen::getEventTarget() const CScreen::getEventTarget() const
{ {

View File

@ -24,6 +24,7 @@
#include "KeyTypes.h" #include "KeyTypes.h"
#include "MouseTypes.h" #include "MouseTypes.h"
#include "OptionTypes.h" #include "OptionTypes.h"
#include "CString.h"
class IClipboard; class IClipboard;
class IPlatformScreen; class IPlatformScreen;
@ -266,6 +267,10 @@ public:
*/ */
KeyModifierMask pollActiveModifiers() const; KeyModifierMask pollActiveModifiers() const;
//! Get dragging file's directory.
CString& getDraggingFileDir() const;
//@} //@}
// IScreen overrides // IScreen overrides

View File

@ -157,7 +157,7 @@ public:
virtual void fakeInputBegin() = 0; virtual void fakeInputBegin() = 0;
virtual void fakeInputEnd() = 0; virtual void fakeInputEnd() = 0;
virtual SInt32 getJumpZoneSize() const = 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; virtual void getCursorCenter(SInt32& x, SInt32& y) const = 0;
// ISecondaryScreen overrides // ISecondaryScreen overrides
@ -185,6 +185,8 @@ public:
virtual SInt32 pollActiveGroup() const = 0; virtual SInt32 pollActiveGroup() const = 0;
virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const = 0; virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const = 0;
virtual CString& getDraggingFileDir() = 0;
protected: protected:
//! Handle system event //! Handle system event
/*! /*!

View File

@ -152,7 +152,7 @@ public:
"current" means up to the last processed event but it can mean "current" means up to the last processed event but it can mean
the current physical mouse button state. the current physical mouse button state.
*/ */
virtual bool isAnyMouseButtonDown() const = 0; virtual bool isAnyMouseButtonDown(UInt32& buttonID) const = 0;
//! Get cursor center position //! Get cursor center position
/*! /*!