From 465ce8c7f78f9a0108a00f1b83bbe42bad416821 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Mon, 3 May 2010 22:49:42 +0100 Subject: [PATCH 1/2] web fixes, allow more file types. Slidecontroller_hide event --- openlp/core/ui/slidecontroller.py | 18 +++++++- .../presentations/lib/messagelistener.py | 17 ++++++++ openlp/plugins/remotes/html/index.html | 4 +- openlp/plugins/remotes/lib/httpserver.py | 43 +++++++++++++------ 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index c0d0d915f..4fa09d9ce 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -674,10 +674,10 @@ class SlideController(QtGui.QWidget): self.themeButton.setChecked(False) if checked: Receiver.send_message(u'maindisplay_hide', HideMode.Screen) - self.blankPlugin(True) + self.hidePlugin(True) else: Receiver.send_message(u'maindisplay_show') - self.blankPlugin(False) + self.hidePlugin(False) def blankPlugin(self, blank): """ @@ -693,6 +693,20 @@ class SlideController(QtGui.QWidget): % self.serviceItem.name.lower(), [self.serviceItem, self.isLive]) + def hidePlugin(self, hide): + """ + Blank the display screen. + """ + if self.serviceItem is not None: + if hide: + Receiver.send_message(u'%s_hide' + % self.serviceItem.name.lower(), + [self.serviceItem, self.isLive]) + else: + Receiver.send_message(u'%s_unblank' + % self.serviceItem.name.lower(), + [self.serviceItem, self.isLive]) + def onSlideSelected(self): """ Generate the preview when you click on a slide. diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index b15f25642..b5b6b6879 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -160,6 +160,16 @@ class Controller(object): return self.doc.blank_screen() + def stop(self): + log.debug(u'Live = %s, stop' % self.isLive) + if not self.isLive: + return + if not self.doc.is_loaded(): + return + if not self.doc.is_active(): + return + self.doc.stop_presentation() + def unblank(self): log.debug(u'Live = %s, unblank' % self.isLive) if not self.isLive: @@ -190,6 +200,8 @@ class MessageListener(object): QtCore.SIGNAL(u'presentations_start'), self.startup) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'presentations_stop'), self.shutdown) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'presentations_hide'), self.hide) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'presentations_first'), self.first) QtCore.QObject.connect(Receiver.get_receiver(), @@ -279,6 +291,11 @@ class MessageListener(object): else: self.previewHandler.shutdown() + def hide(self, message): + isLive, item = self.decode_message(message) + if isLive: + self.liveHandler.stop() + def blank(self, message): isLive, item = self.decode_message(message) if isLive: diff --git a/openlp/plugins/remotes/html/index.html b/openlp/plugins/remotes/html/index.html index 25b08fd43..13fc6d094 100644 --- a/openlp/plugins/remotes/html/index.html +++ b/openlp/plugins/remotes/html/index.html @@ -63,7 +63,7 @@ function response(eventname, req){ html += ' style="font-weight: bold"'; html += '>'; html += '' + data[row]['tag'] + ''; - html += '' + data[row]['text'].replace(/\\n/g, '
'); + html += '' + data[row]['text'].replace(/\n/g, '
'); html += ''; } html += ''; @@ -105,10 +105,12 @@ send_event("remotes_poll_request");
+ (Click service item to go live.)

+ (Click verse to display.)

OpenLP website diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 8808f880d..89cc6f191 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -152,43 +152,59 @@ class HttpConnection(object): log.debug(u'received: ' + data) words = data.split(u' ') html = None + mimetype = None if words[0] == u'GET': url = urlparse.urlparse(words[1]) params = self.load_params(url.query) folders = url.path.split(u'/') if folders[1] == u'': - html = self.serve_file(u'') + mimetype, html = self.serve_file(u'') elif folders[1] == u'files': - html = self.serve_file(folders[2]) + mimetype, html = self.serve_file(folders[2]) elif folders[1] == u'send': html = self.process_event(folders[2], params) elif folders[1] == u'request': if self.process_request(folders[2], params): return if html: - html = self.get_200_ok() + html + u'\n' + if mimetype: + self.socket.write(self.get_200_ok(mimetype)) + else: + self.socket.write(self.get_200_ok()) + self.socket.write(html) else: - html = self.get_404_not_found() - self.socket.write(html) + self.socket.write(self.get_404_not_found()) self.close() def serve_file(self, filename): """ - Send a file to the socket. For now, just .html files + Send a file to the socket. For now, just a subset of file types and must be top level inside the html folder. If subfolders requested return 404, easier for security for the present. Ultimately for i18n, this could first look for xx/file.html before falling back to file.html... where xx is the language, e.g. 'en' """ - log.debug(u'serve file request %s' % filename) + log.debug(u'serve file request %s' % filename) if not filename: filename = u'index.html' if os.path.basename(filename) != filename: return None (fileroot, ext) = os.path.splitext(filename) - if ext != u'.html': - return None + if ext == u'.html': + mimetype = u'text/html' + elif ext == u'.css': + mimetype = u'text/css' + elif ext == u'.js': + mimetype = u'application/x-javascript' + elif ext == u'.jpg': + mimetype = u'image/jpeg' + elif ext == u'.gif': + mimetype = u'image/gif' + elif ext == u'.png': + mimetype = u'image/png' + else: + return (None, None) path = os.path.join(self.parent.html_dir, filename) try: f = open(path, u'rb') @@ -198,8 +214,8 @@ class HttpConnection(object): log.debug(u'Opened %s' % path) html = f.read() f.close() - return html - + return (mimetype, html) + def load_params(self, query): """ Decode the query string parameters sent from the browser @@ -270,13 +286,12 @@ class HttpConnection(object): self.socket.write(html) self.close() - def get_200_ok(self): + def get_200_ok(self, mimetype='text/html; charset="utf-8"'): """ Successful request. Send OK headers. Assume html for now. """ return u'HTTP/1.1 200 OK\r\n' + \ - u'Content-Type: text/html; charset="utf-8"\r\n' + \ - u'\r\n' + u'Content-Type: %s\r\n\r\n' % mimetype def get_404_not_found(self): """ From 4f8d0589286507f4402869bcbdd82df4fa35038c Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Tue, 4 May 2010 22:49:02 +0100 Subject: [PATCH 2/2] rename get to send and allow webpages to be served from subfolders --- openlp/plugins/remotes/lib/httpserver.py | 33 ++++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 89cc6f191..b66f0e215 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -160,7 +160,7 @@ class HttpConnection(object): if folders[1] == u'': mimetype, html = self.serve_file(u'') elif folders[1] == u'files': - mimetype, html = self.serve_file(folders[2]) + mimetype, html = self.serve_file(os.sep.join(folders[2:])) elif folders[1] == u'send': html = self.process_event(folders[2], params) elif folders[1] == u'request': @@ -168,12 +168,12 @@ class HttpConnection(object): return if html: if mimetype: - self.socket.write(self.get_200_ok(mimetype)) + self.send_200_ok(mimetype) else: - self.socket.write(self.get_200_ok()) + self.send_200_ok() self.socket.write(html) else: - self.socket.write(self.get_404_not_found()) + self.send_404_not_found() self.close() def serve_file(self, filename): @@ -188,7 +188,8 @@ class HttpConnection(object): log.debug(u'serve file request %s' % filename) if not filename: filename = u'index.html' - if os.path.basename(filename) != filename: + path = os.path.normpath(os.path.join(self.parent.html_dir, filename)) + if not path.startswith(self.parent.html_dir): return None (fileroot, ext) = os.path.splitext(filename) if ext == u'.html': @@ -205,7 +206,6 @@ class HttpConnection(object): mimetype = u'image/png' else: return (None, None) - path = os.path.join(self.parent.html_dir, filename) try: f = open(path, u'rb') except: @@ -282,31 +282,31 @@ class HttpConnection(object): return self.timer.stop() html = json.dumps(data) - html = self.get_200_ok() + html + u'\n' + self.send_200_ok() self.socket.write(html) self.close() - def get_200_ok(self, mimetype='text/html; charset="utf-8"'): + def send_200_ok(self, mimetype='text/html; charset="utf-8"'): """ Successful request. Send OK headers. Assume html for now. """ - return u'HTTP/1.1 200 OK\r\n' + \ - u'Content-Type: %s\r\n\r\n' % mimetype + self.socket.write(u'HTTP/1.1 200 OK\r\n' + \ + u'Content-Type: %s\r\n\r\n' % mimetype) - def get_404_not_found(self): + def send_404_not_found(self): """ Invalid url. Say so """ - return u'HTTP/1.1 404 Not Found\r\n'+ \ + self.socket.write(u'HTTP/1.1 404 Not Found\r\n'+ \ u'Content-Type: text/html; charset="utf-8"\r\n' + \ - u'\r\n' + u'\r\n') - def get_408_timeout(self): + def send_408_timeout(self): """ A _request hasn't returned anything in the timeout period. Return timeout """ - return u'HTTP/1.1 408 Request Timeout\r\n' + self.socket.write(u'HTTP/1.1 408 Request Timeout\r\n') def timeout(self): """ @@ -314,8 +314,7 @@ class HttpConnection(object): """ if not self.socket: return - html = self.get_408_timeout() - self.socket.write(html) + html = self.send_408_timeout() self.close() def disconnected(self):