diff options
Diffstat (limited to 'Swift/Controllers/ScreenSharing/ScreenSharingController.cpp')
| -rw-r--r-- | Swift/Controllers/ScreenSharing/ScreenSharingController.cpp | 114 | 
1 files changed, 75 insertions, 39 deletions
diff --git a/Swift/Controllers/ScreenSharing/ScreenSharingController.cpp b/Swift/Controllers/ScreenSharing/ScreenSharingController.cpp index fd3357d..b932765 100644 --- a/Swift/Controllers/ScreenSharing/ScreenSharingController.cpp +++ b/Swift/Controllers/ScreenSharing/ScreenSharingController.cpp @@ -12,82 +12,118 @@  #include <Swiften/ScreenSharing/Image.h>  #include <Swiften/Network/TimerFactory.h>  #include <Swiften/Network/Timer.h> -#include "Swift/QtUI/ScreenSharing/QtDesktopScreenGrabber.h" +#include "Swift/Controllers/ScreenSharing/DesktopScreenGrabber.h"  #include "Swift/Controllers/UIInterfaces/RemoteScreenWindowFactory.h"  #include "Swift/Controllers/UIInterfaces/RemoteScreenWindow.h" +#include "Swift/Controllers/UIInterfaces/ChatWindow.h" +#include "Swift/Controllers/Intl.h"  #include <boost/bind.hpp>  namespace Swift { -ScreenSharingController::ScreenSharingController(ScreenSharingManager *screenSharingManager, RemoteScreenWindowFactory* remoteScreenViewerFactory, TimerFactory* timerFactory) -	: screenSharingManager(screenSharingManager), remoteScreenWindowFactory(remoteScreenViewerFactory), remoteScreenWindow(0), -	  grabTimer(timerFactory->createTimer(500)), screenGrabber(new QtDesktopScreenGrabber) +ScreenSharingController::ScreenSharingController(ScreenSharingManager* screenSharingManager, TimerFactory* timerFactory, DesktopScreenGrabber* desktopScreenGrabber, const JID& to) +	: screenGrabber(desktopScreenGrabber), grabTimer(timerFactory->createTimer(500)), remoteScreenWindowFactory(0), +	  remoteScreenWindow(0), otherParty(to), incoming(false), chatWindow(0)  { -	screenSharingManager->onIncomingScreenSharing.connect(boost::bind(&ScreenSharingController::handleIncomingScreenSharing, this, _1)); -	grabTimer->onTick.connect(boost::bind(&ScreenSharingController::handleGrabTimerTick, this)); +	OutgoingScreenSharing::ref oss = screenSharingManager->createOutgoingScreenSharing(to); +	if (oss) { +		oss->onReady.connect(boost::bind(&ScreenSharingController::handleReady, this)); +		oss->onFinished.connect(boost::bind(&ScreenSharingController::handleFinished, this)); +		oss->onStateChange.connect(boost::bind(&ScreenSharingController::handleStateChange, this, _1)); +		const Image& image = screenGrabber->grab(); +		oss->start(image.width, image.height); +		screenSharing = oss; +	} else { +		std::cerr << "Screen sharing not supported!" << std::endl; +	} +} + +ScreenSharingController::ScreenSharingController(boost::shared_ptr<IncomingScreenSharing> screenSharing, RemoteScreenWindowFactory* remoteScreenWindowFactory) +	: screenGrabber(0), remoteScreenWindowFactory(remoteScreenWindowFactory), remoteScreenWindow(0), +	  screenSharing(screenSharing), otherParty(screenSharing->getSender()), incoming(true), chatWindow(0) +{ +	screenSharing->onFinished.connect(boost::bind(&ScreenSharingController::handleFinished, this)); +	screenSharing->onStateChange.connect(boost::bind(&ScreenSharingController::handleStateChange, this, _1));  }  ScreenSharingController::~ScreenSharingController()  { -	grabTimer->onTick.disconnect(boost::bind(&ScreenSharingController::handleGrabTimerTick, this)); +	screenSharing->onStateChange.disconnect(boost::bind(&ScreenSharingController::handleStateChange, this, _1));  	delete remoteScreenWindow;  } -boost::shared_ptr<OutgoingScreenSharing> ScreenSharingController::createOugoingScreenSharing(const JID& to) +const JID& ScreenSharingController::getOtherParty() const  { -	if (!oss) { -		oss = screenSharingManager->createOutgoingScreenSharing(to); -		if (oss) { -			oss->onReady.connect(boost::bind(&ScreenSharingController::handleOssReady, this)); -			oss->onFinished.connect(boost::bind(&ScreenSharingController::handleOutgoingFinished, this)); -			const Image& image = screenGrabber->grab(); -			oss->start(image.width, image.height); +	return otherParty; +} + +std::string ScreenSharingController::setChatWindow(ChatWindow* wnd, std::string nickname) { +	chatWindow = wnd; +	uiID = wnd->addScreenSharing((incoming ? nickname : QT_TRANSLATE_NOOP("", "me")), incoming); +	return uiID; +} + +void ScreenSharingController::accept() +{ +	if (incoming) { +		if (IncomingScreenSharing::ref iss = boost::dynamic_pointer_cast<IncomingScreenSharing>(screenSharing)) { +			iss->accept(); +			remoteScreenWindow = remoteScreenWindowFactory->createRemoteScreenViewer(iss); +			remoteScreenWindow->onStopRequest.connect(boost::bind(&ScreenSharingController::handleWindowStopRequest, this));  		} -		return oss;  	} -	return boost::shared_ptr<OutgoingScreenSharing>();  } -void ScreenSharingController::handleIncomingScreenSharing(boost::shared_ptr<IncomingScreenSharing> incomingScreenSharing) +void ScreenSharingController::cancel()  { -	if (iss) { -		incomingScreenSharing->cancel(); -	} else { -		iss = incomingScreenSharing; -		iss->accept(); -		iss->onFinished.connect(boost::bind(&ScreenSharingController::handleIncomingFinished, this)); -		remoteScreenWindow = remoteScreenWindowFactory->createRemoteScreenViewer(iss); -//		onNewIncomingScreenSharing(iss); -	} +	screenSharing->cancel(); +} + +void ScreenSharingController::stop() +{ +	screenSharing->stop();  }  void ScreenSharingController::handleGrabTimerTick()  { -	if (oss) { -		grabTimer->start(); -		oss->addImage(screenGrabber->grab()); +	if (screenSharing) { +		if (OutgoingScreenSharing::ref oss = boost::dynamic_pointer_cast<OutgoingScreenSharing>(screenSharing)) { +			grabTimer->start(); +			oss->addImage(screenGrabber->grab()); +		} +	} else { +		grabTimer->onTick.disconnect(boost::bind(&ScreenSharingController::handleGrabTimerTick, this));  	}  } -void ScreenSharingController::handleOssReady() +void ScreenSharingController::handleReady()  { -	handleGrabTimerTick(); +	if (OutgoingScreenSharing::ref oss = boost::dynamic_pointer_cast<OutgoingScreenSharing>(screenSharing)) { +		oss->onReady.disconnect(boost::bind(&ScreenSharingController::handleReady, this)); +		grabTimer->onTick.connect(boost::bind(&ScreenSharingController::handleGrabTimerTick, this)); +		handleGrabTimerTick(); +	}  } -void ScreenSharingController::handleIncomingFinished() +void ScreenSharingController::handleFinished()  { -	iss->onFinished.disconnect(boost::bind(&ScreenSharingController::handleIncomingFinished, this)); -	iss.reset(); +	screenSharing->onFinished.disconnect(boost::bind(&ScreenSharingController::handleFinished, this)); +	screenSharing.reset();  	delete remoteScreenWindow;  	remoteScreenWindow = 0;  } -void ScreenSharingController::handleOutgoingFinished() +void ScreenSharingController::handleStateChange(ScreenSharing::SCState state) +{ +	if (chatWindow) +		chatWindow->setScreenSharingStatus(uiID, state); +} + +void ScreenSharingController::handleWindowStopRequest()  { -	oss->onReady.disconnect(boost::bind(&ScreenSharingController::handleOssReady, this)); -	oss->onFinished.disconnect(boost::bind(&ScreenSharingController::handleOutgoingFinished, this)); -	oss.reset(); +	remoteScreenWindow->onStopRequest.disconnect(boost::bind(&ScreenSharingController::handleWindowStopRequest, this)); +	screenSharing->stop();  }  }  | 
 Swift