diff options
author | dknn <yoann.blein@free.fr> | 2012-08-04 09:25:47 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:15:48 (GMT) |
commit | 343f88e3048887e83cc91bb710510b3aa618f779 (patch) | |
tree | c9a5d4cd3b9804c31074ffeec9f2953eedd45042 /Swift/Controllers/ScreenSharing | |
parent | 5ed2b62239eda07de84142e63fad31ccc194d379 (diff) | |
download | swift-contrib-343f88e3048887e83cc91bb710510b3aa618f779.zip swift-contrib-343f88e3048887e83cc91bb710510b3aa618f779.tar.bz2 |
Add basic UI for viewing remote screen
Diffstat (limited to 'Swift/Controllers/ScreenSharing')
3 files changed, 162 insertions, 0 deletions
diff --git a/Swift/Controllers/ScreenSharing/DesktopScreenGrabber.h b/Swift/Controllers/ScreenSharing/DesktopScreenGrabber.h new file mode 100644 index 0000000..4fac6fe --- /dev/null +++ b/Swift/Controllers/ScreenSharing/DesktopScreenGrabber.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +namespace Swift { + class Image; + + class DesktopScreenGrabber { + public: + virtual ~DesktopScreenGrabber() {} + + virtual Image grab() const = 0; + }; +} diff --git a/Swift/Controllers/ScreenSharing/ScreenSharingController.cpp b/Swift/Controllers/ScreenSharing/ScreenSharingController.cpp new file mode 100644 index 0000000..fd3357d --- /dev/null +++ b/Swift/Controllers/ScreenSharing/ScreenSharingController.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "ScreenSharingController.h" + +#include <Swiften/ScreenSharing/ScreenSharingManager.h> +#include <Swiften/ScreenSharing/IncomingScreenSharing.h> +#include <Swiften/ScreenSharing/OutgoingScreenSharing.h> +#include <Swiften/ScreenSharing/Image.h> +#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Network/Timer.h> +#include "Swift/QtUI/ScreenSharing/QtDesktopScreenGrabber.h" +#include "Swift/Controllers/UIInterfaces/RemoteScreenWindowFactory.h" +#include "Swift/Controllers/UIInterfaces/RemoteScreenWindow.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) +{ + 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<OutgoingScreenSharing> 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<OutgoingScreenSharing>(); +} + +void ScreenSharingController::handleIncomingScreenSharing(boost::shared_ptr<IncomingScreenSharing> 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(); +} + +} diff --git a/Swift/Controllers/ScreenSharing/ScreenSharingController.h b/Swift/Controllers/ScreenSharing/ScreenSharingController.h new file mode 100644 index 0000000..6bae132 --- /dev/null +++ b/Swift/Controllers/ScreenSharing/ScreenSharingController.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Base/boost_bsignals.h> + +#include <boost/shared_ptr.hpp> + +namespace Swift { + class ScreenSharingManager; + class IncomingScreenSharing; + class OutgoingScreenSharing; + class Timer; + class TimerFactory; + class DesktopScreenGrabber; + class RemoteScreenWindowFactory; + class RemoteScreenWindow; + class JID; + + class ScreenSharingController { + public: + ScreenSharingController(ScreenSharingManager* screenSharingManager, RemoteScreenWindowFactory* remoteScreenWindowFactory, TimerFactory* timerFactory); + ~ScreenSharingController(); + + boost::shared_ptr<OutgoingScreenSharing> createOugoingScreenSharing(const JID& to); + + public: + boost::signal<void (boost::shared_ptr<IncomingScreenSharing>)> onNewIncomingScreenSharing; + + private: + void handleIncomingScreenSharing(boost::shared_ptr<IncomingScreenSharing> incomingScreenSharing); + void handleGrabTimerTick(); + void handleOssReady(); + void handleIncomingFinished(); + void handleOutgoingFinished(); + + private: + ScreenSharingManager* screenSharingManager; + RemoteScreenWindowFactory* remoteScreenWindowFactory; + + RemoteScreenWindow* remoteScreenWindow; + boost::shared_ptr<Timer> grabTimer; + DesktopScreenGrabber* screenGrabber; + boost::shared_ptr<IncomingScreenSharing> iss; + boost::shared_ptr<OutgoingScreenSharing> oss; + }; +} |