migrate settings

This commit is contained in:
Tim Bentley 2016-07-09 12:21:25 +01:00
parent cd3d809610
commit 3a7aff9c0e
9 changed files with 40 additions and 32 deletions

View File

@ -69,8 +69,8 @@ def check_auth(auth):
:param auth: the authorisation object which needs to be tested
:return Whether authentication have been successful
"""
auth_code = "{user}:{password}".format(user=Settings().value('remotes/user id'),
password=Settings().value('remotes/password'))
auth_code = "{user}:{password}".format(user=Settings().value('api/user id'),
password=Settings().value('api/password'))
try:
auth_base = base64.b64encode(auth_code)
except TypeError:
@ -99,7 +99,7 @@ def requires_auth(f):
"""
@wraps(f)
def decorated(*args, **kwargs):
if not Settings().value('remotes/authentication enabled'):
if not Settings().value('api/authentication enabled'):
return f(*args, **kwargs)
req = args[0]
if not hasattr(req, 'authorization'):

View File

@ -60,7 +60,7 @@ def controller_text(request):
item['text'] = str(frame['text'])
item['html'] = str(frame['html'])
# Handle images, unless a custom thumbnail is given or if thumbnails is disabled
elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'):
elif current_item.is_image() and not frame.get('image', '') and Settings().value('api/thumbnails'):
item['tag'] = str(index + 1)
thumbnail_path = os.path.join('images', 'thumbnails', frame['title'])
full_thumbnail_path = os.path.join(AppLocation.get_data_path(), thumbnail_path)
@ -79,7 +79,7 @@ def controller_text(request):
if current_item.is_capable(ItemCapabilities.HasNotes):
item['slide_notes'] = str(frame['notes'])
if current_item.is_capable(ItemCapabilities.HasThumbnails) and \
Settings().value('remotes/thumbnails'):
Settings().value('api/thumbnails'):
# If the file is under our app directory tree send the portion after the match
data_path = AppLocation.get_data_path()
if frame['image'][0:len(data_path)] == data_path:

View File

@ -31,7 +31,7 @@ from PyQt5 import QtCore
from waitress import serve
from openlp.core.api.http import application
from openlp.core.common import RegistryProperties, OpenLPMixin
from openlp.core.common import RegistryProperties, OpenLPMixin, Settings
log = logging.getLogger(__name__)
@ -52,7 +52,9 @@ class HttpWorker(QtCore.QObject):
"""
Run the thread.
"""
serve(application, host='0.0.0.0', port=4316)
address = Settings().value('api/ip address')
port = Settings().value('api/port')
serve(application, host=address, port=port)
def stop(self):
pass

View File

@ -40,12 +40,12 @@ class Poller(RegistryProperties):
'service': self.service_manager.service_id,
'slide': self.live_controller.selected_row or 0,
'item': self.live_controller.service_item.unique_identifier if self.live_controller.service_item else '',
'twelve': Settings().value('remotes/twelve hour'),
'twelve': Settings().value('api/twelve hour'),
'blank': self.live_controller.blank_screen.isChecked(),
'theme': self.live_controller.theme_screen.isChecked(),
'display': self.live_controller.desktop_screen.isChecked(),
'version': 3,
'isSecure': Settings().value('remotes/authentication enabled'),
'isSecure': Settings().value('api/authentication enabled'),
'isAuthorised': False
}

View File

@ -35,7 +35,7 @@ class ApiTab(SettingsTab):
def __init__(self, parent):
self.icon_path = ':/plugins/plugin_remote.png'
advanced_translated = translate('OpenLP.AdvancedTab', 'Advanced')
super(ApiTab, self).__init__(parent, 'remotes', advanced_translated)
super(ApiTab, self).__init__(parent, 'api', advanced_translated)
self.define_main_window_icon()
self.generate_icon()

View File

@ -69,7 +69,7 @@ class WebSocketServer(RegistryProperties, OpenLPMixin):
Initialise and start the WebSockets server
"""
super(WebSocketServer, self).__init__()
self.settings_section = 'remotes'
self.settings_section = 'api'
self.worker = WebSocketWorker(self)
self.thread = QtCore.QThread()
self.worker.moveToThread(self.thread)
@ -81,7 +81,7 @@ class WebSocketServer(RegistryProperties, OpenLPMixin):
Start the correct server and save the handler
"""
address = Settings().value(self.settings_section + '/ip address')
port = '4317'
port = Settings().value(self.settings_section + '/websocket port')
self.start_websocket_instance(address, port)
# If web socket server start listening
if hasattr(self, 'ws_server') and self.ws_server:

View File

@ -134,16 +134,14 @@ class Settings(QtCore.QSettings):
'advanced/single click service preview': False,
'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
'advanced/search as type': True,
'remotes/twelve hour': True,
'remotes/port': 4316,
'remotes/websocket port': 4317,
'remotes/user id': 'openlp',
'remotes/password': 'password',
'remotes/authentication enabled': False,
'remotes/ip address': '0.0.0.0',
'remotes/thumbnails': True,
'api/twelve hour': True,
'api/port': 4316,
'api/websocket port': 4317,
'api/user id': 'openlp',
'api/password': 'password',
'api/authentication enabled': False,
'api/ip address': '0.0.0.0',
'api/thumbnails': True,
'crashreport/last directory': '',
'formattingTags/html_tags': '',
'core/audio repeat list': False,
@ -225,7 +223,17 @@ class Settings(QtCore.QSettings):
('advanced/default color', 'core/logo background color', []), # Default image renamed + moved to general > 2.4.
('advanced/default image', '/core/logo file', []), # Default image renamed + moved to general after 2.4.
('remotes/https enabled', '', []),
('remotes/https port', '', [])
('remotes/https port', '', []),
('remotes/twelve hour', 'api/twelve hour', []),
('remotes/port', 'api/port', []),
('remotes/websocket port', 'api/websocket port', []),
('remotes/user id', 'api/user id', []),
('remotes/password', 'api/password', []),
('remotes/authentication enabled', 'api/authentication enabled', []),
('remotes/ip address', 'api/ip address', []),
('remotes/thumbnails', 'api/thumbnails', [])
]
@staticmethod

View File

@ -215,7 +215,6 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
self.presentation_check_box.setChecked(self.plugin_manager.get_plugin_by_name('presentations').is_active())
self.image_check_box.setChecked(self.plugin_manager.get_plugin_by_name('images').is_active())
self.media_check_box.setChecked(self.plugin_manager.get_plugin_by_name('media').is_active())
self.remote_check_box.setChecked(self.plugin_manager.get_plugin_by_name('remotes').is_active())
self.custom_check_box.setChecked(self.plugin_manager.get_plugin_by_name('custom').is_active())
self.song_usage_check_box.setChecked(self.plugin_manager.get_plugin_by_name('songusage').is_active())
self.alert_check_box.setChecked(self.plugin_manager.get_plugin_by_name('alerts').is_active())
@ -600,7 +599,6 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
self._set_plugin_status(self.presentation_check_box, 'presentations/status')
self._set_plugin_status(self.image_check_box, 'images/status')
self._set_plugin_status(self.media_check_box, 'media/status')
self._set_plugin_status(self.remote_check_box, 'remotes/status')
self._set_plugin_status(self.custom_check_box, 'custom/status')
self._set_plugin_status(self.song_usage_check_box, 'songusage/status')
self._set_plugin_status(self.alert_check_box, 'alerts/status')

View File

@ -32,13 +32,13 @@ from tests.functional import MagicMock, patch
from tests.helpers.testmixin import TestMixin
__default_settings__ = {
'remotes/twelve hour': True,
'remotes/port': 4316,
'remotes/user id': 'openlp',
'remotes/password': 'password',
'remotes/authentication enabled': False,
'remotes/ip address': '0.0.0.0',
'remotes/thumbnails': True
'api/twelve hour': True,
'api/port': 4316,
'api/user id': 'openlp',
'api/password': 'password',
'api/authentication enabled': False,
'api/ip address': '0.0.0.0',
'api/thumbnails': True
}