- 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,
new TMethodEventJob<CClient>(this,
&CClient::handleFileChunkSending));
m_events->adoptHandler(m_events->forIScreen().fileRecieveComplete(),
this,
new TMethodEventJob<CClient>(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()
{

View File

@ -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

View File

@ -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[] = {
"<invalid>",
@ -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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -41,7 +41,6 @@
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <sstream>
#include <stdexcept>
//
@ -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<char*>(filename);
LOG((CLOG_DEBUG "sendFileChunks: %s", name));
CFileChunker::sendFileChunks(name, m_events, this);
}
catch (std::runtime_error error) {

View File

@ -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

View File

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

View File

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

View File

@ -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

View File

@ -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
{

View File

@ -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

View File

@ -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
/*!

View File

@ -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
/*!