From 40de8647cf36dab6c14c8201777cc3a9df44d9b7 Mon Sep 17 00:00:00 2001
From: Andreas Preikschat
Date: Thu, 28 Feb 2013 21:47:59 +0100
Subject: [PATCH 01/37] renamed general settings to core
Fixes: https://launchpad.net/bugs/1133237
---
openlp/core/__init__.py | 10 +--
openlp/core/lib/screen.py | 12 +--
openlp/core/lib/settings.py | 73 +++++++++++++------
openlp/core/ui/firsttimeform.py | 6 +-
openlp/core/ui/generaltab.py | 2 +-
openlp/core/ui/maindisplay.py | 8 +-
openlp/core/ui/mainwindow.py | 2 +-
openlp/core/ui/media/mediacontroller.py | 2 +-
openlp/core/utils/languagemanager.py | 4 +-
openlp/plugins/songs/lib/mediaitem.py | 4 +-
.../openlp_core_lib/test_settings.py | 6 +-
11 files changed, 78 insertions(+), 51 deletions(-)
diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py
index 3ad0e1348..176fa059a 100644
--- a/openlp/core/__init__.py
+++ b/openlp/core/__init__.py
@@ -113,10 +113,10 @@ class OpenLP(QtGui.QApplication):
# Decide how many screens we have and their size
screens = ScreenList.create(self.desktop())
# First time checks in settings
- has_run_wizard = Settings().value(u'general/has run wizard')
+ has_run_wizard = Settings().value(u'core/has run wizard')
if not has_run_wizard:
if FirstTimeForm(screens).exec_() == QtGui.QDialog.Accepted:
- Settings().setValue(u'general/has run wizard', True)
+ Settings().setValue(u'core/has run wizard', True)
# Correct stylesheet bugs
application_stylesheet = u''
if not Settings().value(u'advanced/alternate rows'):
@@ -128,7 +128,7 @@ class OpenLP(QtGui.QApplication):
application_stylesheet += nt_repair_stylesheet
if application_stylesheet:
self.setStyleSheet(application_stylesheet)
- show_splash = Settings().value(u'general/show splash')
+ show_splash = Settings().value(u'core/show splash')
if show_splash:
self.splash = SplashScreen()
self.splash.show()
@@ -147,7 +147,7 @@ class OpenLP(QtGui.QApplication):
self.processEvents()
if not has_run_wizard:
self.main_window.first_time()
- update_check = Settings().value(u'general/update check')
+ update_check = Settings().value(u'core/update check')
if update_check:
VersionThread(self.main_window).start()
self.main_window.is_display_blank()
@@ -309,7 +309,7 @@ def main(args=None):
if application.is_already_running():
sys.exit()
# First time checks in settings
- if not Settings().value(u'general/has run wizard'):
+ if not Settings().value(u'core/has run wizard'):
if not FirstTimeLanguageForm().exec_():
# if cancel then stop processing
sys.exit()
diff --git a/openlp/core/lib/screen.py b/openlp/core/lib/screen.py
index 913ad539c..149f07ce1 100644
--- a/openlp/core/lib/screen.py
+++ b/openlp/core/lib/screen.py
@@ -247,15 +247,15 @@ class ScreenList(object):
# Add the screen settings to the settings dict. This has to be done here due to cyclic dependency.
# Do not do this anywhere else.
screen_settings = {
- u'general/x position': self.current[u'size'].x(),
- u'general/y position': self.current[u'size'].y(),
- u'general/monitor': self.display_count - 1,
- u'general/height': self.current[u'size'].height(),
- u'general/width': self.current[u'size'].width()
+ u'core/x position': self.current[u'size'].x(),
+ u'core/y position': self.current[u'size'].y(),
+ u'core/monitor': self.display_count - 1,
+ u'core/height': self.current[u'size'].height(),
+ u'core/width': self.current[u'size'].width()
}
Settings.extend_default_settings(screen_settings)
settings = Settings()
- settings.beginGroup(u'general')
+ settings.beginGroup(u'core')
monitor = settings.value(u'monitor')
self.set_current_display(monitor)
self.display = settings.value(u'display on monitor')
diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py
index be869ade6..e067242dc 100644
--- a/openlp/core/lib/settings.py
+++ b/openlp/core/lib/settings.py
@@ -116,30 +116,30 @@ class Settings(QtCore.QSettings):
u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
u'crashreport/last directory': u'',
u'displayTags/html_tags': u'',
- u'general/audio repeat list': False,
- u'general/auto open': False,
- u'general/auto preview': False,
- u'general/audio start paused': True,
- u'general/auto unblank': False,
- u'general/blank warning': False,
- u'general/ccli number': u'',
- u'general/has run wizard': False,
- u'general/language': u'[en]',
+ u'core/audio repeat list': False,
+ u'core/auto open': False,
+ u'core/auto preview': False,
+ u'core/audio start paused': True,
+ u'core/auto unblank': False,
+ u'core/blank warning': False,
+ u'core/ccli number': u'',
+ u'core/has run wizard': False,
+ u'core/language': u'[en]',
# This defaults to yesterday in order to force the update check to run when you've never run it before.
- u'general/last version test': datetime.datetime.now().date() - datetime.timedelta(days=1),
- u'general/loop delay': 5,
- u'general/recent files': [],
- u'general/save prompt': False,
- u'general/screen blank': False,
- u'general/show splash': True,
- u'general/songselect password': u'',
- u'general/songselect username': u'',
- u'general/update check': True,
- u'general/view mode': u'default',
+ u'core/last version test': datetime.datetime.now().date() - datetime.timedelta(days=1),
+ u'core/loop delay': 5,
+ u'core/recent files': [],
+ u'core/save prompt': False,
+ u'core/screen blank': False,
+ u'core/show splash': True,
+ u'core/songselect password': u'',
+ u'core/songselect username': u'',
+ u'core/update check': True,
+ u'core/view mode': u'default',
# The other display settings (display position and dimensions) are defined in the ScreenList class due to a
# circular dependency.
- u'general/display on monitor': True,
- u'general/override position': False,
+ u'core/display on monitor': True,
+ u'core/override position': False,
u'images/background color': u'#000000',
u'media/players': u'webkit',
u'media/override player': QtCore.Qt.Unchecked,
@@ -304,7 +304,7 @@ class Settings(QtCore.QSettings):
# Changed during 1.9.x development.
(u'bibles/bookname language', u'bibles/book name language', []),
(u'general/enable slide loop', u'advanced/slide limits', [(SlideLimits.Wrap, True), (SlideLimits.End, False)]),
- (u'songs/ccli number', u'general/ccli number', []),
+ (u'songs/ccli number', u'core/ccli number', []),
# Changed during 2.1.x development.
(u'advanced/stylesheet fix', u'', []),
(u'bibles/last directory 1', u'bibles/last directory import', []),
@@ -314,7 +314,34 @@ class Settings(QtCore.QSettings):
(u'songs/last directory 1', u'songs/last directory import', []),
(u'songusage/last directory 1', u'songusage/last directory export', []),
(u'user interface/mainwindow splitter geometry', u'user interface/main window splitter geometry', []),
- (u'shortcuts/makeLive', u'shortcuts/make_live', [])
+ (u'shortcuts/makeLive', u'shortcuts/make_live', []),
+ (u'general/audio repeat list', u'core/audio repeat list', []),
+ (u'general/auto open', u'core/auto open', []),
+ (u'general/auto preview', u'core/auto preview', []),
+ (u'general/audio start paused', u'core/audio start paused', []),
+ (u'general/auto unblank', u'core/auto unblank', []),
+ (u'general/blank warning', u'core/blank warning', []),
+ (u'general/ccli number', u'core/ccli number', []),
+ (u'general/has run wizard', u'core/has run wizard', []),
+ (u'general/language', u'core/language', []),
+ (u'general/last version test', u'core/last version test', []),
+ (u'general/loop delay', u'core/loop delay', []),
+ (u'general/recent files', u'core/recent files', []),
+ (u'general/save prompt', u'core/save prompt', []),
+ (u'general/screen blank', u'core/screen blank', []),
+ (u'general/show splash', u'core/show splash', []),
+ (u'general/songselect password', u'core/songselect password', []),
+ (u'general/songselect username', u'core/songselect username', []),
+ (u'general/update check', u'core/update check', []),
+ (u'general/view mode', u'core/view mode', []),
+ (u'general/display on monitor', u'core/display on monitor', []),
+ (u'general/override position', u'core/override position', []),
+ (u'general/x position', u'core/x position', []),
+ (u'general/y position', u'core/y position', []),
+ (u'general/monitor', u'core/monitor', []),
+ (u'general/height', u'core/height', []),
+ (u'general/monitor', u'core/monitor', []),
+ (u'general/width', u'core/width', [])
]
@staticmethod
diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py
index 188bc3c02..0d749176b 100644
--- a/openlp/core/ui/firsttimeform.py
+++ b/openlp/core/ui/firsttimeform.py
@@ -120,7 +120,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
check_directory_exists(os.path.join(unicode(gettempdir(), get_filesystem_encoding()), u'openlp'))
self.noInternetFinishButton.setVisible(False)
# Check if this is a re-run of the wizard.
- self.hasRunWizard = Settings().value(u'general/has run wizard')
+ self.hasRunWizard = Settings().value(u'core/has run wizard')
# Sort out internet access for downloads
if self.web_access:
songs = self.config.get(u'songs', u'languages')
@@ -254,7 +254,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.application.set_busy_cursor()
self._performWizard()
self.application.set_normal_cursor()
- Settings().setValue(u'general/has run wizard', True)
+ Settings().setValue(u'core/has run wizard', True)
self.close()
def urlGetFile(self, url, fpath):
@@ -461,7 +461,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.urlGetFile(u'%s%s' % (self.web, theme), os.path.join(themes_destination, theme))
# Set Default Display
if self.displayComboBox.currentIndex() != -1:
- Settings().setValue(u'General/monitor', self.displayComboBox.currentIndex())
+ Settings().setValue(u'core/monitor', self.displayComboBox.currentIndex())
self.screens.set_current_display(self.displayComboBox.currentIndex())
# Set Global Theme
if self.themeComboBox.currentIndex() != -1:
diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py
index a20206f9b..af99c3271 100644
--- a/openlp/core/ui/generaltab.py
+++ b/openlp/core/ui/generaltab.py
@@ -49,7 +49,7 @@ class GeneralTab(SettingsTab):
self.screens = ScreenList()
self.iconPath = u':/icon/openlp-logo-16x16.png'
generalTranslated = translate('OpenLP.GeneralTab', 'General')
- SettingsTab.__init__(self, parent, u'General', generalTranslated)
+ SettingsTab.__init__(self, parent, u'Core', generalTranslated)
def setupUi(self):
"""
diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py
index 58d832101..41413b503 100644
--- a/openlp/core/ui/maindisplay.py
+++ b/openlp/core/ui/maindisplay.py
@@ -367,7 +367,7 @@ class MainDisplay(Display):
# Single screen active
if self.screens.display_count == 1:
# Only make visible if setting enabled.
- if Settings().value(u'general/display on monitor'):
+ if Settings().value(u'core/display on monitor'):
self.setVisible(True)
else:
self.setVisible(True)
@@ -416,7 +416,7 @@ class MainDisplay(Display):
self.footer(serviceItem.foot_text)
# if was hidden keep it hidden
if self.hideMode and self.isLive and not serviceItem.is_media():
- if Settings().value(u'general/auto unblank'):
+ if Settings().value(u'core/auto unblank'):
Registry().execute(u'slidecontroller_live_unblank')
else:
self.hide_display(self.hideMode)
@@ -438,7 +438,7 @@ class MainDisplay(Display):
log.debug(u'hide_display mode = %d', mode)
if self.screens.display_count == 1:
# Only make visible if setting enabled.
- if not Settings().value(u'general/display on monitor'):
+ if not Settings().value(u'core/display on monitor'):
return
if mode == HideMode.Screen:
self.frame.evaluateJavaScript(u'show_blank("desktop");')
@@ -462,7 +462,7 @@ class MainDisplay(Display):
log.debug(u'show_display')
if self.screens.display_count == 1:
# Only make visible if setting enabled.
- if not Settings().value(u'general/display on monitor'):
+ if not Settings().value(u'core/display on monitor'):
return
self.frame.evaluateJavaScript('show_blank("show");')
if self.isHidden():
diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py
index 14186cf78..0d77da403 100644
--- a/openlp/core/ui/mainwindow.py
+++ b/openlp/core/ui/mainwindow.py
@@ -469,7 +469,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.arguments = self.application.args
# Set up settings sections for the main application (not for use by plugins).
self.uiSettingsSection = u'user interface'
- self.generalSettingsSection = u'general'
+ self.generalSettingsSection = u'core'
self.advancedSettingsSection = u'advanced'
self.shortcutsSettingsSection = u'shortcuts'
self.serviceManagerSettingsSection = u'servicemanager'
diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py
index 048fb5f4d..60c09ca21 100644
--- a/openlp/core/ui/media/mediacontroller.py
+++ b/openlp/core/ui/media/mediacontroller.py
@@ -417,7 +417,7 @@ class MediaController(object):
elif not hidden or controller.media_info.is_background or serviceItem.will_auto_start:
autoplay = True
# Unblank on load set
- elif Settings().value(u'general/auto unblank'):
+ elif Settings().value(u'core/auto unblank'):
autoplay = True
if autoplay:
if not self.media_play(controller):
diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py
index 00a0d0079..6dc18c1ad 100644
--- a/openlp/core/utils/languagemanager.py
+++ b/openlp/core/utils/languagemanager.py
@@ -98,7 +98,7 @@ class LanguageManager(object):
"""
Retrieve a saved language to use from settings
"""
- language = Settings().value(u'general/language')
+ language = Settings().value(u'core/language')
language = str(language)
log.info(u'Language file: \'%s\' Loaded from conf file' % language)
if re.match(r'[[].*[]]', language):
@@ -128,7 +128,7 @@ class LanguageManager(object):
language = unicode(qm_list[action_name])
if LanguageManager.auto_language:
language = u'[%s]' % language
- Settings().setValue(u'general/language', language)
+ Settings().setValue(u'core/language', language)
log.info(u'Language file: \'%s\' written to conf file' % language)
if message:
QtGui.QMessageBox.information(None,
diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py
index da706bdcb..e3860aeda 100644
--- a/openlp/plugins/songs/lib/mediaitem.py
+++ b/openlp/plugins/songs/lib/mediaitem.py
@@ -457,9 +457,9 @@ class SongMediaItem(MediaManagerItem):
service_item.raw_footer.append(song.title)
service_item.raw_footer.append(create_separated_list(author_list))
service_item.raw_footer.append(song.copyright)
- if Settings().value(u'general/ccli number'):
+ if Settings().value(u'core/ccli number'):
service_item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') +
- Settings().value(u'general/ccli number'))
+ Settings().value(u'core/ccli number'))
service_item.audit = [
song.title, author_list, song.copyright, unicode(song.ccli_number)
]
diff --git a/tests/functional/openlp_core_lib/test_settings.py b/tests/functional/openlp_core_lib/test_settings.py
index 827bfa156..2cd15a16f 100644
--- a/tests/functional/openlp_core_lib/test_settings.py
+++ b/tests/functional/openlp_core_lib/test_settings.py
@@ -35,16 +35,16 @@ class TestSettings(TestCase):
# GIVEN: A new Settings setup
# WHEN reading a setting for the first time
- default_value = Settings().value(u'general/has run wizard')
+ default_value = Settings().value(u'core/has run wizard')
# THEN the default value is returned
assert default_value is False, u'The default value should be False'
# WHEN a new value is saved into config
- Settings().setValue(u'general/has run wizard', True)
+ Settings().setValue(u'core/has run wizard', True)
# THEN the new value is returned when re-read
- assert Settings().value(u'general/has run wizard') is True, u'The saved value should have been returned'
+ assert Settings().value(u'core/has run wizard') is True, u'The saved value should have been returned'
def settings_override_test(self):
"""
From f1aadde13cd30ecf89afb8d8bd07ad9f4e0b5210 Mon Sep 17 00:00:00 2001
From: Tim Bentley
Date: Wed, 6 Mar 2013 21:53:29 +0000
Subject: [PATCH 02/37] Initial Cherrypy implementation
---
openlp/core/ui/exceptionform.py | 6 +
openlp/core/ui/slidecontroller.py | 7 +-
openlp/core/utils/__init__.py | 7 +-
openlp/plugins/remotes/html/stage.js | 6 +-
openlp/plugins/remotes/lib/httpauth.py | 192 ++++++++++++++++
openlp/plugins/remotes/lib/httpserver.py | 281 +++++++++++------------
openlp/plugins/remotes/lib/remotetab.py | 271 ++++++++++++++--------
openlp/plugins/remotes/remoteplugin.py | 5 +
scripts/check_dependencies.py | 1 +
9 files changed, 534 insertions(+), 242 deletions(-)
create mode 100644 openlp/plugins/remotes/lib/httpauth.py
diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py
index 50885b15b..c10f98d9b 100644
--- a/openlp/core/ui/exceptionform.py
+++ b/openlp/core/ui/exceptionform.py
@@ -69,6 +69,11 @@ try:
MAKO_VERSION = mako.__version__
except ImportError:
MAKO_VERSION = u'-'
+try:
+ import cherrypy
+ CHERRYPY_VERSION = cherrypy.__version__
+except ImportError:
+ CHERRYPY_VERSION = u'-'
try:
import uno
arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue')
@@ -138,6 +143,7 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog):
u'PyEnchant: %s\n' % ENCHANT_VERSION + \
u'PySQLite: %s\n' % SQLITE_VERSION + \
u'Mako: %s\n' % MAKO_VERSION + \
+ u'CherryPy: %s\n' % CHERRYPY_VERSION + \
u'pyUNO bridge: %s\n' % UNO_VERSION
if platform.system() == u'Linux':
if os.environ.get(u'KDE_FULL_SESSION') == u'true':
diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py
index 84ea296d2..3a2c0b582 100644
--- a/openlp/core/ui/slidecontroller.py
+++ b/openlp/core/ui/slidecontroller.py
@@ -362,8 +362,9 @@ class SlideController(DisplayController):
# Signals
QtCore.QObject.connect(self.previewListWidget, QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected)
if self.isLive:
+ # Need to use event as called across threads and UI is updated
+ QtCore.QObject.connect(self, QtCore.SIGNAL(u'slidecontroller_toggle_display'), self.toggle_display)
Registry().register_function(u'slidecontroller_live_spin_delay', self.receive_spin_delay)
- Registry().register_function(u'slidecontroller_toggle_display', self.toggle_display)
self.toolbar.setWidgetVisible(self.loopList, False)
self.toolbar.setWidgetVisible(self.wideMenu, False)
else:
@@ -867,9 +868,9 @@ class SlideController(DisplayController):
"""
Go to the requested slide
"""
- index = int(message[0])
- if not self.serviceItem:
+ if not self.serviceItem or not message[0]:
return
+ index = int(message[0])
if self.serviceItem.is_command():
Registry().execute(u'%s_slide' % self.serviceItem.name.lower(), [self.serviceItem, self.isLive, index])
self.updatePreview()
diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py
index 104567039..dd611d303 100644
--- a/openlp/core/utils/__init__.py
+++ b/openlp/core/utils/__init__.py
@@ -90,6 +90,7 @@ class AppLocation(object):
VersionDir = 5
CacheDir = 6
LanguageDir = 7
+ SharedData = 8
# Base path where data/config/cache dir is located
BaseDir = None
@@ -150,18 +151,18 @@ def _get_os_dir_path(dir_type):
if sys.platform == u'win32':
if dir_type == AppLocation.DataDir:
return os.path.join(unicode(os.getenv(u'APPDATA'), encoding), u'openlp', u'data')
- elif dir_type == AppLocation.LanguageDir:
+ elif dir_type == AppLocation.LanguageDir or dir_type == AppLocation.SharedData:
return os.path.split(openlp.__file__)[0]
return os.path.join(unicode(os.getenv(u'APPDATA'), encoding), u'openlp')
elif sys.platform == u'darwin':
if dir_type == AppLocation.DataDir:
return os.path.join(unicode(os.getenv(u'HOME'), encoding),
u'Library', u'Application Support', u'openlp', u'Data')
- elif dir_type == AppLocation.LanguageDir:
+ elif dir_type == AppLocation.LanguageDir or dir_type == AppLocation.SharedData:
return os.path.split(openlp.__file__)[0]
return os.path.join(unicode(os.getenv(u'HOME'), encoding), u'Library', u'Application Support', u'openlp')
else:
- if dir_type == AppLocation.LanguageDir:
+ if dir_type == AppLocation.LanguageDir or dir_type == AppLocation.SharedData:
prefixes = [u'/usr/local', u'/usr']
for prefix in prefixes:
directory = os.path.join(prefix, u'share', u'openlp')
diff --git a/openlp/plugins/remotes/html/stage.js b/openlp/plugins/remotes/html/stage.js
index dcc2e4b70..dff51537c 100644
--- a/openlp/plugins/remotes/html/stage.js
+++ b/openlp/plugins/remotes/html/stage.js
@@ -26,7 +26,7 @@
window.OpenLP = {
loadService: function (event) {
$.getJSON(
- "/api/service/list",
+ "/stage/api/service/list",
function (data, status) {
OpenLP.nextSong = "";
$("#notes").html("");
@@ -46,7 +46,7 @@ window.OpenLP = {
},
loadSlides: function (event) {
$.getJSON(
- "/api/controller/live/text",
+ "/stage/api/controller/live/text",
function (data, status) {
OpenLP.currentSlides = data.results.slides;
OpenLP.currentSlide = 0;
@@ -137,7 +137,7 @@ window.OpenLP = {
},
pollServer: function () {
$.getJSON(
- "/api/poll",
+ "/stage/api/poll",
function (data, status) {
OpenLP.updateClock(data);
if (OpenLP.currentItem != data.results.item ||
diff --git a/openlp/plugins/remotes/lib/httpauth.py b/openlp/plugins/remotes/lib/httpauth.py
new file mode 100644
index 000000000..ce3ea091e
--- /dev/null
+++ b/openlp/plugins/remotes/lib/httpauth.py
@@ -0,0 +1,192 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# 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 #
+###############################################################################
+
+"""
+The :mod:`http` module manages the HTTP authorisation logic. This code originates from
+http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions
+
+"""
+
+import cherrypy
+import urlparse
+
+SESSION_KEY = '_cp_openlp'
+
+
+def check_credentials(user_name, password):
+ """
+ Verifies credentials for username and password.
+ Returns None on success or a string describing the error on failure
+ """
+ # @todo make from config
+ if user_name == 'openlp' and password == 'openlp':
+ return None
+ else:
+ return u"Incorrect username or password."
+ # if u.password != md5.new(password).hexdigest():
+ # return u"Incorrect password"
+
+
+def check_auth(*args, **kwargs):
+ """
+ A tool that looks in config for 'auth.require'. If found and it
+ is not None, a login is required and the entry is evaluated as a list of
+ conditions that the user must fulfill
+ """
+ print "check"
+ conditions = cherrypy.request.config.get('auth.require', None)
+ print conditions
+ print args, kwargs
+ print urlparse.urlparse(cherrypy.url())
+ url = urlparse.urlparse(cherrypy.url())
+ print urlparse.parse_qs(url.query)
+ if conditions is not None:
+ username = cherrypy.session.get(SESSION_KEY)
+ if username:
+ cherrypy.request.login = username
+ for condition in conditions:
+ # A condition is just a callable that returns true or false
+ if not condition():
+ raise cherrypy.HTTPRedirect("/auth/login")
+ else:
+ raise cherrypy.HTTPRedirect("/auth/login")
+
+cherrypy.tools.auth = cherrypy.Tool('before_handler', check_auth)
+
+
+def require_auth(*conditions):
+ """
+ A decorator that appends conditions to the auth.require config variable.
+ """
+ print conditions
+ def decorate(f):
+ if not hasattr(f, '_cp_config'):
+ f._cp_config = dict()
+ if 'auth.require' not in f._cp_config:
+ f._cp_config['auth.require'] = []
+ f._cp_config['auth.require'].extend(conditions)
+ print "a ", [f]
+ return f
+ return decorate
+
+
+# Conditions are callables that return True
+# if the user fulfills the conditions they define, False otherwise
+#
+# They can access the current username as cherrypy.request.login
+#
+# Define those at will however suits the application.
+
+#def member_of(groupname):
+# def check():
+# # replace with actual check if is in
+# return cherrypy.request.login == 'joe' and groupname == 'admin'
+# return check
+
+
+#def name_is(reqd_username):
+# return lambda: reqd_username == cherrypy.request.login
+
+#def any_of(*conditions):
+# """
+# Returns True if any of the conditions match
+# """
+# def check():
+# for c in conditions:
+# if c():
+# return True
+# return False
+# return check
+
+# By default all conditions are required, but this might still be
+# needed if you want to use it inside of an any_of(...) condition
+#def all_of(*conditions):
+# """
+# Returns True if all of the conditions match
+# """
+# def check():
+# for c in conditions:
+# if not c():
+# return False
+# return True
+# return check
+# Controller to provide login and logout actions
+
+
+class AuthController(object):
+
+ def on_login(self, username):
+ """
+ Called on successful login
+ """
+
+ def on_logout(self, username):
+ """
+ Called on logout
+ """
+
+ def get_loginform(self, username, msg="Enter login information", from_page="/"):
+ """
+ Provides a login form
+ """
+ return """
+
+ User name:
+ Password:
+
+
+
\ No newline at end of file
diff --git a/openlp/plugins/remotes/html/openlp.css b/openlp/plugins/remotes/html/openlp.css
index 4bc1bf907..60a8fe625 100644
--- a/openlp/plugins/remotes/html/openlp.css
+++ b/openlp/plugins/remotes/html/openlp.css
@@ -36,3 +36,11 @@
.ui-li .ui-btn-text a.ui-link-inherit{
white-space: normal;
}
+
+.ui-page{
+ padding: 100px 100px 100px 100px;
+ width: 300px;
+}
+.ui-input-text{
+ width: 30px;
+}
\ No newline at end of file
diff --git a/openlp/plugins/remotes/lib/httpauth.py b/openlp/plugins/remotes/lib/httpauth.py
index 7e0e2ebe5..d46620855 100644
--- a/openlp/plugins/remotes/lib/httpauth.py
+++ b/openlp/plugins/remotes/lib/httpauth.py
@@ -35,8 +35,12 @@ http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions
import cherrypy
import logging
+import os
+
+from mako.template import Template
from openlp.core.lib import Settings
+from openlp.core.utils import AppLocation, translate
SESSION_KEY = '_cp_openlp'
@@ -48,6 +52,7 @@ def check_credentials(user_name, password):
Verifies credentials for username and password.
Returns None on success or a string describing the error on failure
"""
+ print "check"
if user_name == Settings().value(u'remotes/user id') and password == Settings().value(u'remotes/password'):
return None
else:
@@ -70,9 +75,12 @@ def check_auth(*args, **kwargs):
for condition in conditions:
# A condition is just a callable that returns true or false
if not condition():
+ print "r1"
raise cherrypy.HTTPRedirect("/auth/login")
else:
+ print "r2"
raise cherrypy.HTTPRedirect("/auth/login")
+ print "r3"
cherrypy.tools.auth = cherrypy.Tool('before_handler', check_auth)
@@ -100,36 +108,31 @@ class AuthController(object):
"""
Called on successful login
"""
+ pass
def on_logout(self, username):
"""
Called on logout
"""
+ pass
- def get_loginform(self, username, msg="Enter login information", from_page="/"):
+ def get_login_form(self, username, message=None, from_page="/"):
"""
Provides a login form
"""
- return """
-
-
-
- User Login
-
-
-
-
-
-
-
-
-
-