/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include "ScreenSharingController.h" #include #include #include #include #include #include #include "Swift/QtUI/ScreenSharing/QtDesktopScreenGrabber.h" #include "Swift/Controllers/UIInterfaces/RemoteScreenWindowFactory.h" #include "Swift/Controllers/UIInterfaces/RemoteScreenWindow.h" #include namespace Swift { ScreenSharingController::ScreenSharingController(ScreenSharingManager *screenSharingManager, RemoteScreenWindowFactory* remoteScreenViewerFactory, TimerFactory* timerFactory) : screenSharingManager(screenSharingManager), remoteScreenWindowFactory(remoteScreenViewerFactory), remoteScreenWindow(0), grabTimer(timerFactory->createTimer(500)), screenGrabber(new QtDesktopScreenGrabber) { screenSharingManager->onIncomingScreenSharing.connect(boost::bind(&ScreenSharingController::handleIncomingScreenSharing, this, _1)); grabTimer->onTick.connect(boost::bind(&ScreenSharingController::handleGrabTimerTick, this)); } ScreenSharingController::~ScreenSharingController() { grabTimer->onTick.disconnect(boost::bind(&ScreenSharingController::handleGrabTimerTick, this)); delete remoteScreenWindow; } boost::shared_ptr ScreenSharingController::createOugoingScreenSharing(const JID& to) { 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 oss; } return boost::shared_ptr(); } void ScreenSharingController::handleIncomingScreenSharing(boost::shared_ptr incomingScreenSharing) { if (iss) { incomingScreenSharing->cancel(); } else { iss = incomingScreenSharing; iss->accept(); iss->onFinished.connect(boost::bind(&ScreenSharingController::handleIncomingFinished, this)); remoteScreenWindow = remoteScreenWindowFactory->createRemoteScreenViewer(iss); // onNewIncomingScreenSharing(iss); } } void ScreenSharingController::handleGrabTimerTick() { if (oss) { grabTimer->start(); oss->addImage(screenGrabber->grab()); } } void ScreenSharingController::handleOssReady() { handleGrabTimerTick(); } void ScreenSharingController::handleIncomingFinished() { iss->onFinished.disconnect(boost::bind(&ScreenSharingController::handleIncomingFinished, this)); iss.reset(); delete remoteScreenWindow; remoteScreenWindow = 0; } void ScreenSharingController::handleOutgoingFinished() { oss->onReady.disconnect(boost::bind(&ScreenSharingController::handleOssReady, this)); oss->onFinished.disconnect(boost::bind(&ScreenSharingController::handleOutgoingFinished, this)); oss.reset(); } }