From ee151cde2a7bd04b574c6892432b33e2873b71bc Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 31 May 2011 12:59:05 +0200 Subject: [PATCH 1/7] Fixed bug #790382 by using the Mako template engine to pass Python variables into the template. --- openlp/plugins/remotes/html/index.html | 60 ++++++++++++------------ openlp/plugins/remotes/html/stage.html | 4 +- openlp/plugins/remotes/lib/httpserver.py | 38 +++++++++++++-- 3 files changed, 65 insertions(+), 37 deletions(-) diff --git a/openlp/plugins/remotes/html/index.html b/openlp/plugins/remotes/html/index.html index 6390b9446..b370d589e 100644 --- a/openlp/plugins/remotes/html/index.html +++ b/openlp/plugins/remotes/html/index.html @@ -27,7 +27,7 @@ --> - OpenLP 2.0 Remote + ${app_title} @@ -37,81 +37,81 @@
-

OpenLP 2.0 Remote

+

${app_title}

- Service Manager - Slide Controller - Alerts - Search + ${service_manager} + ${slide_controller} + ${alerts} + ${search}
- Back -

Service Manager

- Refresh + ${back} +

${service_manager}

+ ${refresh}
- Back -

Slide Controller

- Refresh + ${back} +

${slide_controller}

+ ${refresh}
- Back -

Alerts

+ ${back} +

${alerts}

- +
- Show Alert + ${show_alert}
- + \ No newline at end of file diff --git a/openlp/plugins/remotes/html/stage.html b/openlp/plugins/remotes/html/stage.html index b67f0ccd6..c002ea68b 100644 --- a/openlp/plugins/remotes/html/stage.html +++ b/openlp/plugins/remotes/html/stage.html @@ -6,8 +6,8 @@ # --------------------------------------------------------------------------- # # Copyright (c) 2008-2011 Raoul Snyman # # Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # -# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, # -# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, # +# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, # +# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, # # Jeffrey Smith, Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode # # Woldsund # # --------------------------------------------------------------------------- # diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 9d29156f7..d9cae42d0 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -115,7 +115,6 @@ import logging import os import urlparse import re -from pprint import pformat try: import json @@ -123,10 +122,11 @@ except ImportError: import simplejson as json from PyQt4 import QtCore, QtNetwork +from mako.template import Template from openlp.core.lib import Receiver, PluginStatus from openlp.core.ui import HideMode -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, translate log = logging.getLogger(__name__) @@ -261,6 +261,7 @@ class HttpConnection(object): self.ready_read) QtCore.QObject.connect(self.socket, QtCore.SIGNAL(u'disconnected()'), self.disconnected) + self.translate() def _get_service_items(self): service_items = [] @@ -280,6 +281,27 @@ class HttpConnection(object): }) return service_items + def translate(self): + """ + Translate various strings in the mobile app. + """ + self.template_vars = { + 'app_title': translate('RemotePlugin.Mobile', 'OpenLP 2.0 Remote'), + 'stage_title': translate('RemotePlugin.Mobile', 'OpenLP 2.0 Stage View'), + 'service_manager': translate('RemotePlugin.Mobile', 'Service Manager'), + 'slide_controller': translate('RemotePlugin.Mobile', 'Slide Controller'), + 'alerts': translate('RemotePlugin.Mobile', 'Alerts'), + 'search': translate('RemotePlugin.Mobile', 'Search'), + 'back': translate('RemotePlugin.Mobile', 'Back'), + 'refresh': translate('RemotePlugin.Mobile', 'Refresh'), + 'blank': translate('RemotePlugin.Mobile', 'Blank'), + 'show': translate('RemotePlugin.Mobile', 'Show'), + 'prev': translate('RemotePlugin.Mobile', 'Prev'), + 'next': translate('RemotePlugin.Mobile', 'Next'), + 'text': translate('RemotePlugin.Mobile', 'Text'), + 'show_alert': translate('RemotePlugin.Mobile', 'Show Alert') + } + def ready_read(self): """ Data has been sent from the client. Respond to it @@ -327,8 +349,11 @@ class HttpConnection(object): if not path.startswith(self.parent.html_dir): return HttpResponse(code=u'404 Not Found') ext = os.path.splitext(filename)[1] + html = None if ext == u'.html': mimetype = u'text/html' + variables = self.template_vars + html = Template(filename=path, input_encoding=u'utf-8', output_encoding=u'utf-8').render(**variables) elif ext == u'.css': mimetype = u'text/css' elif ext == u'.js': @@ -343,9 +368,12 @@ class HttpConnection(object): mimetype = u'text/plain' file_handle = None try: - file_handle = open(path, u'rb') - log.debug(u'Opened %s' % path) - content = file_handle.read() + if html: + content = html + else: + file_handle = open(path, u'rb') + log.debug(u'Opened %s' % path) + content = file_handle.read() except IOError: log.exception(u'Failed to open %s' % path) return HttpResponse(code=u'404 Not Found') From 9f7a96c31514b9dc31c6d766c95b611e3d321c6a Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 31 May 2011 13:25:35 +0200 Subject: [PATCH 2/7] Fixed up some missing translations. --- openlp/plugins/remotes/html/stage.html | 3 ++- openlp/plugins/remotes/html/stage.js | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/remotes/html/stage.html b/openlp/plugins/remotes/html/stage.html index c002ea68b..c5d0872d0 100644 --- a/openlp/plugins/remotes/html/stage.html +++ b/openlp/plugins/remotes/html/stage.html @@ -27,12 +27,13 @@ --> - OpenLP 2.0 Stage View + ${stage_title} +