From a293be51e8911d3fd022b609916b992698994393 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sun, 8 May 2011 20:26:32 +0100 Subject: [PATCH] Local hostname fix. remote now returns just text. New html element to return html --- openlp/plugins/remotes/html/openlp.js | 4 +++- openlp/plugins/remotes/html/stage.js | 13 +++++++---- openlp/plugins/remotes/lib/httpserver.py | 6 ++++- openlp/plugins/remotes/lib/remotetab.py | 29 ++++++++++++------------ 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index 811ce0cac..74463ffbc 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -63,8 +63,10 @@ window.OpenLP = { var ul = $("#slide-controller > div[data-role=content] > ul[data-role=listview]"); ul.html(""); for (idx in data.results.slides) { + var text = data.results.slides[idx]["text"]; + text = text.replace(/\n/g, '
'); var li = $("
  • ").append( - $("").attr("value", parseInt(idx, 10)).html(data.results.slides[idx]["text"])); + $("").attr("value", parseInt(idx, 10)).html(text)); if (data.results.slides[idx]["selected"]) { li.attr("data-theme", "e"); } diff --git a/openlp/plugins/remotes/html/stage.js b/openlp/plugins/remotes/html/stage.js index 8b8a83f6a..96e4c5a14 100644 --- a/openlp/plugins/remotes/html/stage.js +++ b/openlp/plugins/remotes/html/stage.js @@ -65,10 +65,15 @@ window.OpenLP = { updateSlide: function() { $("#verseorder span").removeClass("currenttag"); $("#tag" + OpenLP.currentSlide).addClass("currenttag"); - $("#currentslide").html(OpenLP.currentSlides[OpenLP.currentSlide]["text"]); - if (OpenLP.currentSlide < OpenLP.currentSlides.length - 1) - $("#nextslide").html(OpenLP.currentSlides[OpenLP.currentSlide + 1]["text"]); - else + var text = OpenLP.currentSlides[OpenLP.currentSlide]["text"]; + text = text.replace(/\n/g, '
    '); + $("#currentslide").html(text); + if (OpenLP.currentSlide < OpenLP.currentSlides.length - 1) { + text = OpenLP.currentSlides[OpenLP.currentSlide + 1]["text"]; + text = text.replace(/\n/g, '
    '); + $("#nextslide").html(text); + } + else $("#nextslide").html("Next: " + OpenLP.nextSong); }, updateClock: function() { diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 70f02ff36..790175965 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -115,6 +115,7 @@ import os import urlparse import re from pprint import pformat +from lxml import html try: import json @@ -402,10 +403,13 @@ class HttpConnection(object): item = {} if current_item.is_text(): item[u'tag'] = unicode(frame[u'verseTag']) - item[u'text'] = unicode(frame[u'html']) + text = unicode(frame[u'html'].replace('
    ', '\n')) + item[u'text'] = html.fromstring(text).text_content() + item[u'html'] = unicode(frame[u'html']) else: item[u'tag'] = unicode(index) item[u'text'] = u'' + item[u'html'] = u'' item[u'selected'] = (self.parent.current_slide == index) data.append(item) json_data = {u'results': {u'slides': data}} diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index bfb05d486..9bcf6eb88 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -93,24 +93,23 @@ class RemoteTab(SettingsTab): 'Stage view URL:')) def setUrls(self): - ipAddress = None + ipAddress = 'localhost' if self.addressEdit.text() == ZERO_URL: - for ip in QtNetwork.QNetworkInterface.allAddresses(): - if ip.protocol() == 0 and ip != QtNetwork.QHostAddress.LocalHost: - ipAddress = ip.toString() - break + ifaces = QtNetwork.QNetworkInterface.allInterfaces() + for iface in ifaces: + if not iface.isValid(): + continue + if not (iface.flags() & (QtNetwork.QNetworkInterface.IsUp | + QtNetwork.QNetworkInterface.IsRunning)): + continue + for addr in iface.addressEntries(): + ip = addr.ip() + if ip.protocol() == 0 and \ + ip != QtNetwork.QHostAddress.LocalHost: + ipAddress = ip.toString() + break else: ipAddress = self.addressEdit.text() - if not ipAddress: - self.remoteUrlLabel.setVisible(False) - self.remoteUrl.setVisible(False) - self.stageUrlLabel.setVisible(False) - self.stageUrl.setVisible(False) - return - self.remoteUrlLabel.setVisible(True) - self.remoteUrl.setVisible(True) - self.stageUrlLabel.setVisible(True) - self.stageUrl.setVisible(True) url = u'http://%s:%s/' % (ipAddress, self.portSpinBox.value()) self.remoteUrl.setText(u'
    %s' % (url, url)) url = url + u'stage'