diff --git a/openlp/core/lib/api/apicontroller.py b/openlp/core/lib/api/apicontroller.py new file mode 100644 index 000000000..514c1d66a --- /dev/null +++ b/openlp/core/lib/api/apicontroller.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2016 OpenLP Developers # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +import logging + +from openlp.core.common import OpenLPMixin, Registry, RegistryMixin, RegistryProperties +from openlp.core.lib.api import OpenWSServer, OpenLPPoll, OpenLPHttpServer + +log = logging.getLogger(__name__) + + +class ApiController(RegistryMixin, OpenLPMixin, RegistryProperties): + """ + The implementation of the Media Controller. The Media Controller adds an own class for every Player. + Currently these are QtWebkit, Phonon and Vlc. display_controllers are an array of controllers keyed on the + slidecontroller or plugin which built them. + + ControllerType is the class containing the key values. + + media_players are an array of media players keyed on player name. + + current_media_players is an array of player instances keyed on ControllerType. + + """ + def __init__(self, parent=None): + """ + Constructor + """ + super(ApiController, self).__init__(parent) + # Registry().register_function('playbackPlay', self.media_play_msg) + + def bootstrap_post_set_up(self): + """ + process the bootstrap post setup request + """ + self.poll = OpenLPPoll() + Registry().register('OpenLPPoll', self.poll) + self.wsserver = OpenWSServer() + self.httpserver = OpenLPHttpServer() diff --git a/openlp/core/lib/api/httpserver.py b/openlp/core/lib/api/httpserver.py index c9f5b933d..2830229ac 100644 --- a/openlp/core/lib/api/httpserver.py +++ b/openlp/core/lib/api/httpserver.py @@ -35,20 +35,19 @@ from openlp.core.common import RegistryProperties, OpenLPMixin log = logging.getLogger(__name__) -class HttpThread(QtCore.QThread): +class HttpThread(QtCore.QObject): """ A special Qt thread class to allow the HTTP server to run at the same time as the UI. """ - def __init__(self, server): + def __init__(self): """ Constructor for the thread class. :param server: The http server class. """ - super(HttpThread, self).__init__(None) - self.http_server = server + super().__init__() - def run(self): + def start(self): """ Run the thread. """ @@ -56,17 +55,20 @@ class HttpThread(QtCore.QThread): serve(wsgiapp, host='0.0.0.0', port=4317) def stop(self): - self.http_server.stop = True + pass class OpenLPHttpServer(RegistryProperties, OpenLPMixin): """ Wrapper round a server instance """ - def __init__(self, secure=False): + def __init__(self): """ Initialise the http server, and start the server of the correct type http / https """ super(OpenLPHttpServer, self).__init__() - self.http_thread = HttpThread(self) - self.http_thread.start() + self.thread = QtCore.QThread() + self.worker = HttpThread() + self.worker.moveToThread(self.thread) + self.thread.started.connect(self.worker.start) + self.thread.start() diff --git a/openlp/core/lib/api/wsserver.py b/openlp/core/lib/api/wsserver.py index 3f63a5c0a..9a2559471 100644 --- a/openlp/core/lib/api/wsserver.py +++ b/openlp/core/lib/api/wsserver.py @@ -37,7 +37,7 @@ from openlp.core.common import Settings, RegistryProperties, OpenLPMixin, Regist log = logging.getLogger(__name__) -class HttpThread(QtCore.QThread): +class WSThread(QtCore.QObject): """ A special Qt thread class to allow the HTTP server to run at the same time as the UI. """ @@ -47,32 +47,34 @@ class HttpThread(QtCore.QThread): :param server: The http server class. """ - super(HttpThread, self).__init__(None) - self.http_server = server + super().__init__() + self.ws_server = server - def run(self): + def start(self): """ Run the thread. """ - self.http_server.start_server() + self.ws_server.start_server() def stop(self): - self.http_server.stop = True + self.ws_server.stop = True class OpenWSServer(RegistryProperties, OpenLPMixin): """ Wrapper round a server instance """ - def __init__(self, secure=False): + def __init__(self): """ Initialise the http server, and start the server of the correct type http / https """ super(OpenWSServer, self).__init__() self.settings_section = 'remotes' - self.secure = secure - self.http_thread = HttpThread(self) - self.http_thread.start() + self.thread = QtCore.QThread() + self.worker = WSThread(self) + self.worker.moveToThread(self.thread) + self.thread.started.connect(self.worker.start) + self.thread.start() def start_server(self): """