From 6876bbd5316bb91222ce45a52afaf9b7bccd3d85 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 16 May 2020 06:11:21 +0000 Subject: [PATCH] Clean up Apis and remove duplicate files. Add new API to help testings --- openlp/core/api/versions/v1/__init__.py | 2 + .../api/versions/v1/plugins.py} | 75 ++++------- openlp/core/api/versions/v2/__init__.py | 2 + .../api/versions/v2/plugins.py} | 73 ++++------- openlp/core/api/versions/v2/service.py | 10 +- openlp/core/lib/serviceitem.py | 8 +- openlp/core/ui/servicemanager.py | 5 +- openlp/plugins/bibles/bibleplugin.py | 2 - openlp/plugins/custom/customplugin.py | 2 - openlp/plugins/custom/remote.py | 116 ------------------ openlp/plugins/images/imageplugin.py | 2 - openlp/plugins/images/remote.py | 116 ------------------ openlp/plugins/media/mediaplugin.py | 2 - openlp/plugins/presentations/lib/mediaitem.py | 5 +- .../presentations/presentationplugin.py | 2 - openlp/plugins/presentations/remote.py | 116 ------------------ openlp/plugins/songs/songsplugin.py | 2 - 17 files changed, 69 insertions(+), 471 deletions(-) rename openlp/{plugins/bibles/remote.py => core/api/versions/v1/plugins.py} (63%) rename openlp/{plugins/songs/remote.py => core/api/versions/v2/plugins.py} (66%) delete mode 100644 openlp/plugins/custom/remote.py delete mode 100644 openlp/plugins/images/remote.py delete mode 100644 openlp/plugins/presentations/remote.py diff --git a/openlp/core/api/versions/v1/__init__.py b/openlp/core/api/versions/v1/__init__.py index e10750971..4a0a2aa16 100644 --- a/openlp/core/api/versions/v1/__init__.py +++ b/openlp/core/api/versions/v1/__init__.py @@ -22,9 +22,11 @@ from openlp.core.api.versions.v1.controller import controller_views from openlp.core.api.versions.v1.core import core_views from openlp.core.api.versions.v1.service import service_views +from openlp.core.api.versions.v1.plugins import plugins def register_blueprints(app): app.register_blueprint(controller_views) app.register_blueprint(core_views) app.register_blueprint(service_views) + app.register_blueprint(plugins) diff --git a/openlp/plugins/bibles/remote.py b/openlp/core/api/versions/v1/plugins.py similarity index 63% rename from openlp/plugins/bibles/remote.py rename to openlp/core/api/versions/v1/plugins.py index 41d1c8d19..238841e6f 100644 --- a/openlp/plugins/bibles/remote.py +++ b/openlp/core/api/versions/v1/plugins.py @@ -20,91 +20,58 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### import logging -from flask import request, jsonify, Blueprint -from openlp.core.api import app -from openlp.core.api.lib import login_required, extract_request, old_auth +from flask import request, Blueprint, jsonify + +from openlp.core.api.lib import extract_request, old_auth from openlp.core.lib.plugin import PluginStatus from openlp.core.common.registry import Registry - log = logging.getLogger(__name__) -v1_views = Blueprint('v1-bibles-plugin', __name__) -v2_views = Blueprint('v2-bibles-plugin', __name__) +plugins = Blueprint('v1-plugins', __name__) -def search(text): - plugin = Registry().get('plugin_manager').get_plugin_by_name('bibles') +def search(plugin_name, text): + plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search: results = plugin.media_item.search(text, False) return results return None -def live(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('bibles') +def live(plugin_name, id): + plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) if plugin.status == PluginStatus.Active and plugin.media_item: - plugin.media_item.bibles_go_live.emit([id, True]) + getattr(plugin.media_item, '{action}_go_live'.format(action=plugin_name)).emit([id, True]) -def add(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('bibles') +def add(plugin_name, id): + plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) if plugin.status == PluginStatus.Active and plugin.media_item: item_id = plugin.media_item.create_item_from_id(id) - plugin.media_item.bibles_add_to_service.emit([item_id, True]) + getattr(plugin.media_item, '{action}_add_to_service'.format(action=plugin_name)).emit([item_id, True]) -@v2_views.route('/search') -@login_required -def search_bible(): - text = request.args.get('text', '') - result = search(text) - return jsonify(result) - - -@v2_views.route('/live', methods=['POST']) -@login_required -def send_live(): - id = request.json.get('id', -1) - live(id) - return '', 204 - - -@v2_views.route('/add', methods=['POST']) -@login_required -def add_to_service(): - id = request.json.get('id', -1) - add(id) - return '', 204 - - -# ---------------- DEPRECATED REMOVE AFTER RELEASE -------------- -@v1_views.route('/search') +@plugins.route('/api//search') @old_auth -def old_search_bible(): +def old_search(plugin): text = extract_request(request.args.get('data', ''), 'text') - return jsonify({'results': {'items': search(text)}}) + return jsonify({'results': {'items': search(plugin, text)}}) -@v1_views.route('/live') +@plugins.route('/api//add') @old_auth -def old_send_live(): +def old_add(plugin): id = extract_request(request.args.get('data', ''), 'id') - live(id) + add(plugin, id) return '', 204 -@v1_views.route('/add') +@plugins.route('/api//live') @old_auth -def old_add_to_service(): +def old_live(plugin): id = extract_request(request.args.get('data', ''), 'id') - add(id) + live(plugin, id) return '', 204 -# ------------ END DEPRECATED ---------------------------------- - - -def register_views(): - app.register_blueprint(v2_views, url_prefix='/api/v2/plugins/bibles') - app.register_blueprint(v1_views, url_prefix='/api/bibles') diff --git a/openlp/core/api/versions/v2/__init__.py b/openlp/core/api/versions/v2/__init__.py index f19e68f80..c5a7a1440 100644 --- a/openlp/core/api/versions/v2/__init__.py +++ b/openlp/core/api/versions/v2/__init__.py @@ -22,9 +22,11 @@ from openlp.core.api.versions.v2.controller import controller_views from openlp.core.api.versions.v2.core import core from openlp.core.api.versions.v2.service import service_views +from openlp.core.api.versions.v2.plugins import plugins def register_blueprints(app): app.register_blueprint(controller_views, url_prefix='/api/v2/controller/') app.register_blueprint(core, url_prefix='/api/v2/core/') app.register_blueprint(service_views, url_prefix='/api/v2/service/') + app.register_blueprint(plugins, url_prefix='/api/v2/plugins/') diff --git a/openlp/plugins/songs/remote.py b/openlp/core/api/versions/v2/plugins.py similarity index 66% rename from openlp/plugins/songs/remote.py rename to openlp/core/api/versions/v2/plugins.py index 98ce1dd82..237fa838d 100644 --- a/openlp/plugins/songs/remote.py +++ b/openlp/core/api/versions/v2/plugins.py @@ -23,94 +23,65 @@ import logging from flask import abort, request, Blueprint, jsonify -from openlp.core.api import app -from openlp.core.api.lib import login_required, extract_request, old_auth +from openlp.core.api.lib import login_required from openlp.core.lib.plugin import PluginStatus from openlp.core.common.registry import Registry log = logging.getLogger(__name__) -v1_songs = Blueprint('v1-songs-plugin', __name__) -v2_songs = Blueprint('v2-songs-plugin', __name__) +plugins = Blueprint('v2-plugins', __name__) -def search(text): - plugin = Registry().get('plugin_manager').get_plugin_by_name('songs') +def search(plugin_name, text): + plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search: results = plugin.media_item.search(text, False) return results return None -def live(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('songs') +def live(plugin_name, id): + plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) if plugin.status == PluginStatus.Active and plugin.media_item: - plugin.media_item.songs_go_live.emit([id, True]) + getattr(plugin.media_item, '{action}_go_live'.format(action=plugin_name)).emit([id, True]) -def add(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('songs') +def add(plugin_name, id): + plugin = Registry().get('plugin_manager').get_plugin_by_name(plugin_name) if plugin.status == PluginStatus.Active and plugin.media_item: item_id = plugin.media_item.create_item_from_id(id) - plugin.media_item.songs_add_to_service.emit([item_id, True]) + getattr(plugin.media_item, '{action}_add_to_service'.format(action=plugin_name)).emit([item_id, True]) -@v2_songs.route('/search') +@plugins.route('//search') @login_required -def search_view(): +def search_view(plugin): + log.debug(f'{plugin}/search search called') text = request.args.get('text', '') - result = search(text) + result = search(plugin, text) return jsonify(result) -@v2_songs.route('/add', methods=['POST']) +@plugins.route('//add', methods=['POST']) @login_required -def add_view(): +def add_view(plugin): + log.debug(f'{plugin}/add search called') data = request.json if not data: abort(400) id = data.get('id', -1) - add(id) + add(plugin, id) return '', 204 -@v2_songs.route('/live', methods=['POST']) +@plugins.route('//live', methods=['POST']) @login_required -def live_view(): +def live_view(plugin): + log.debug(f'{plugin}/live search called') data = request.json if not data: abort(400) id = data.get('id', -1) - live(id) + live(plugin, id) return '', 204 - - -# ----------------- DEPRECATED -------------- -@v1_songs.route('/search') -@old_auth -def old_search(): - text = extract_request(request.args.get('data', ''), 'text') - return jsonify({'results': {'items': search(text)}}) - - -@v1_songs.route('/add') -@old_auth -def old_add(): - id = extract_request(request.args.get('data', ''), 'id') - add(id) - return '', 204 - - -@v1_songs.route('/live') -@old_auth -def old_live(): - id = extract_request(request.args.get('data', ''), 'id') - live(id) - return '', 204 -# ---------------- END DEPRECATED ---------------- - - -def register_views(): - app.register_blueprint(v2_songs, url_prefix='/api/v2/plugins/songs/') - app.register_blueprint(v1_songs, url_prefix='/api/songs/') diff --git a/openlp/core/api/versions/v2/service.py b/openlp/core/api/versions/v2/service.py index ce576a46c..057984e29 100644 --- a/openlp/core/api/versions/v2/service.py +++ b/openlp/core/api/versions/v2/service.py @@ -50,7 +50,8 @@ def service_items(): 'plugin': str(service_item.name), 'ccli_number': str(ccli_number), 'notes': str(service_item.notes), - 'selected': (service_item.unique_identifier == current_unique_identifier) + 'selected': (service_item.unique_identifier == current_unique_identifier), + 'is_valid': str(service_item.is_valid) }) return jsonify(service_items) @@ -101,3 +102,10 @@ def service_direction(): abort(400) getattr(Registry().get('service_manager'), 'servicemanager_{action}_item'.format(action=action)).emit() return '', 204 + + +@service_views.route('/new', methods=['GET']) +@login_required +def new_service(): + getattr(Registry().get('service_manager'), 'servicemanager_new_file').emit() + return '', 204 diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 2237e6b6a..b995ae500 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -630,14 +630,18 @@ class ServiceItem(RegistryProperties): else: return self.slides - def get_rendered_frame(self, row): + def get_rendered_frame(self, row, clean=False): """ Returns the correct frame for a given list and renders it if required. :param row: The service item slide to be returned + :param clean: do I want HTML tags or not """ if self.service_item_type == ServiceItemType.Text: - return self.rendered_slides[row]['text'] + if clean: + return self.display_slides[row]['text'] + else: + return self.rendered_slides[row]['text'] elif self.service_item_type == ServiceItemType.Image: return self.slides[row]['path'] else: diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index d16eef846..a1dedabbf 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -316,6 +316,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi servicemanager_set_item_by_uuid = QtCore.pyqtSignal(str) servicemanager_next_item = QtCore.pyqtSignal() servicemanager_previous_item = QtCore.pyqtSignal() + servicemanager_new_file = QtCore.pyqtSignal() def __init__(self, parent=None): """ @@ -344,6 +345,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi self.servicemanager_set_item_by_uuid.connect(self.set_item_by_uuid) self.servicemanager_next_item.connect(self.next_item) self.servicemanager_previous_item.connect(self.previous_item) + self.servicemanager_new_file.connect(self.new_file) def bootstrap_post_set_up(self): """ @@ -511,6 +513,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi self.set_modified(False) self.settings.setValue('servicemanager/last file', None) self.plugin_manager.new_service_created() + self.live_controller.slide_count = 0 def create_basic_service(self): """ @@ -1324,7 +1327,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi service_item_from_item.service_item_type is not ServiceItemType.Text: text = slide['title'].replace('\n', ' ') else: - text = service_item_from_item.get_rendered_frame(slide_index) + text = service_item_from_item.get_rendered_frame(slide_index, clean=True) child.setText(0, text[:40]) child.setData(0, QtCore.Qt.UserRole, slide_index) if service_item == item_index: diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 0c2126c95..23a735962 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -27,7 +27,6 @@ from openlp.core.common.i18n import UiStrings, translate from openlp.core.ui.icons import UiIcons from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.lib.ui import create_action -from openlp.plugins.bibles.remote import register_views from openlp.plugins.bibles.lib.biblestab import BiblesTab from openlp.plugins.bibles.lib.manager import BibleManager from openlp.plugins.bibles.lib.mediaitem import BibleMediaItem @@ -48,7 +47,6 @@ class BiblePlugin(Plugin): self.icon_path = UiIcons().bible self.icon = UiIcons().bible self.manager = BibleManager(self) - register_views() State().add_service('bible', self.weight, is_plugin=True) State().update_pre_conditions('bible', self.check_pre_conditions()) diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index 2efd7c65c..2598754c4 100644 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -31,7 +31,6 @@ from openlp.core.lib import build_icon from openlp.core.lib.db import Manager from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.ui.icons import UiIcons -from openlp.plugins.custom.remote import register_views from openlp.plugins.custom.lib.db import CustomSlide, init_schema from openlp.plugins.custom.lib.mediaitem import CustomMediaItem from openlp.plugins.custom.lib.customtab import CustomTab @@ -55,7 +54,6 @@ class CustomPlugin(Plugin): self.db_manager = Manager('custom', init_schema) self.icon_path = UiIcons().clone self.icon = build_icon(self.icon_path) - register_views() State().add_service(self.name, self.weight, is_plugin=True) State().update_pre_conditions(self.name, self.check_pre_conditions()) diff --git a/openlp/plugins/custom/remote.py b/openlp/plugins/custom/remote.py deleted file mode 100644 index d49d4dca3..000000000 --- a/openlp/plugins/custom/remote.py +++ /dev/null @@ -1,116 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2020 OpenLP Developers # -# --------------------------------------------------------------------------- # -# 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 # -############################################################################### -import logging - -from flask import abort, request, Blueprint, jsonify - -from openlp.core.api import app -from openlp.core.api.lib import login_required, extract_request, old_auth -from openlp.core.lib.plugin import PluginStatus -from openlp.core.common.registry import Registry - -log = logging.getLogger(__name__) - - -v1_custom = Blueprint('v1-custom-plugin', __name__) -v2_custom = Blueprint('v2-custom-plugin', __name__) - - -def search(text): - plugin = Registry().get('plugin_manager').get_plugin_by_name('custom') - if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search: - results = plugin.media_item.search(text, False) - return results - return None - - -def live(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('custom') - if plugin.status == PluginStatus.Active and plugin.media_item: - plugin.media_item.custom_go_live.emit([id, True]) - - -def add(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('custom') - if plugin.status == PluginStatus.Active and plugin.media_item: - item_id = plugin.media_item.create_item_from_id(id) - plugin.media_item.custom_add_to_service.emit([item_id, True]) - - -@v2_custom.route('/search') -@login_required -def search_view(): - text = request.args.get('text', '') - result = search(text) - return jsonify(result) - - -@v2_custom.route('/add', methods=['POST']) -@login_required -def add_view(): - data = request.json - if not data: - abort(400) - id = data.get('id', -1) - add(id) - return '', 204 - - -@v2_custom.route('/live', methods=['POST']) -@login_required -def live_view(): - data = request.json - if not data: - abort(400) - id = data.get('id', -1) - live(id) - return '', 204 - - -# ----------------- DEPRECATED -------------- -@v1_custom.route('/search') -@old_auth -def old_search(): - text = extract_request(request.args.get('data', ''), 'text') - return jsonify({'results': {'items': search(text)}}) - - -@v1_custom.route('/add') -@old_auth -def old_add(): - id = extract_request(request.args.get('data', ''), 'id') - add(id) - return '', 204 - - -@v1_custom.route('/live') -@old_auth -def old_live(): - id = extract_request(request.args.get('data', ''), 'id') - live(id) - return '', 204 -# ---------------- END DEPRECATED ---------------- - - -def register_views(): - app.register_blueprint(v2_custom, url_prefix='/api/v2/plugins/custom/') - app.register_blueprint(v1_custom, url_prefix='/api/custom/') diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 214fe4c89..8900311fa 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -27,7 +27,6 @@ from openlp.core.lib import build_icon from openlp.core.lib.db import Manager from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.ui.icons import UiIcons -from openlp.plugins.images.remote import register_views from openlp.plugins.images.lib import upgrade from openlp.plugins.images.lib.mediaitem import ImageMediaItem from openlp.plugins.images.lib.imagetab import ImageTab @@ -46,7 +45,6 @@ class ImagePlugin(Plugin): self.weight = -7 self.icon_path = UiIcons().picture self.icon = build_icon(self.icon_path) - register_views() State().add_service('image', self.weight, is_plugin=True) State().update_pre_conditions('image', self.check_pre_conditions()) diff --git a/openlp/plugins/images/remote.py b/openlp/plugins/images/remote.py deleted file mode 100644 index 46065effc..000000000 --- a/openlp/plugins/images/remote.py +++ /dev/null @@ -1,116 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2020 OpenLP Developers # -# --------------------------------------------------------------------------- # -# 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 # -############################################################################### -import logging - -from flask import abort, request, Blueprint, jsonify - -from openlp.core.api import app -from openlp.core.api.lib import login_required, extract_request, old_auth -from openlp.core.lib.plugin import PluginStatus -from openlp.core.common.registry import Registry - -log = logging.getLogger(__name__) - - -v1_images = Blueprint('v1-images-plugin', __name__) -v2_images = Blueprint('v2-images-plugin', __name__) - - -def search(text): - plugin = Registry().get('plugin_manager').get_plugin_by_name('images') - if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search: - results = plugin.media_item.search(text, False) - return results - return None - - -def live(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('images') - if plugin.status == PluginStatus.Active and plugin.media_item: - plugin.media_item.images_go_live.emit([id, True]) - - -def add(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('images') - if plugin.status == PluginStatus.Active and plugin.media_item: - item_id = plugin.media_item.create_item_from_id(id) - plugin.media_item.images_add_to_service.emit([item_id, True]) - - -@v2_images.route('/search') -@login_required -def search_view(): - text = request.args.get('text', '') - result = search(text) - return jsonify(result) - - -@v2_images.route('/add', methods=['POST']) -@login_required -def add_view(): - data = request.json - if not data: - abort(400) - id = data.get('id', -1) - add(id) - return '', 204 - - -@v2_images.route('/live', methods=['POST']) -@login_required -def live_view(): - data = request.json - if not data: - abort(400) - id = data.get('id', -1) - live(id) - return '', 204 - - -# ----------------- DEPRECATED -------------- -@v1_images.route('/search') -@old_auth -def old_search(): - text = extract_request(request.args.get('data', ''), 'text') - return jsonify({'results': {'items': search(text)}}) - - -@v1_images.route('/add') -@old_auth -def old_add(): - id = extract_request(request.args.get('data', ''), 'id') - add(id) - return '', 204 - - -@v1_images.route('/live') -@old_auth -def old_live(): - id = extract_request(request.args.get('data', ''), 'id') - live(id) - return '', 204 -# ---------------- END DEPRECATED ---------------- - - -def register_views(): - app.register_blueprint(v2_images, url_prefix='/api/v2/plugins/images/') - app.register_blueprint(v1_images, url_prefix='/api/images/') diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index db50db733..dda5fce32 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -28,7 +28,6 @@ from openlp.core.common.i18n import translate from openlp.core.ui.icons import UiIcons from openlp.core.lib import build_icon from openlp.core.lib.plugin import Plugin, StringContent -from openlp.plugins.media.remote import register_views from openlp.plugins.media.lib.mediaitem import MediaMediaItem @@ -50,7 +49,6 @@ class MediaPlugin(Plugin): self.icon = build_icon(self.icon_path) # passed with drag and drop messages self.dnd_id = 'Media' - register_views() State().add_service(self.name, self.weight, requires='mediacontroller', is_plugin=True) State().update_pre_conditions(self.name, self.check_pre_conditions()) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 54a444b46..a2a05a84c 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -304,6 +304,7 @@ class PresentationMediaItem(MediaManagerItem): :param item: The Song item to be used :param remote: Triggered from remote :param context: Why is it being generated + :param file_path: Path for the file to be processes :param kwargs: Consume other unused args specified by the base implementation, but not use by this one. """ if item: @@ -313,7 +314,7 @@ class PresentationMediaItem(MediaManagerItem): if len(items) > 1: return False if file_path is None: - file_path = items[0].data(QtCore.Qt.UserRole) + file_path = Path(items[0].data(QtCore.Qt.UserRole)) file_type = file_path.suffix.lower()[1:] if not self.display_type_combo_box.currentText(): return False @@ -365,7 +366,7 @@ class PresentationMediaItem(MediaManagerItem): service_item.processor = self.display_type_combo_box.currentText() service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay) for bitem in items: - file_path = bitem.data(QtCore.Qt.UserRole) + file_path = Path(bitem.data(QtCore.Qt.UserRole)) path, file_name = file_path.parent, file_path.name service_item.title = file_name if file_path.exists(): diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 46df4580b..bbfe5cd62 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -32,7 +32,6 @@ from openlp.core.lib import build_icon from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.state import State from openlp.core.ui.icons import UiIcons -from openlp.plugins.presentations.remote import register_views from openlp.plugins.presentations.lib.presentationcontroller import PresentationController from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem from openlp.plugins.presentations.lib.presentationtab import PresentationTab @@ -58,7 +57,6 @@ class PresentationPlugin(Plugin): self.weight = -8 self.icon_path = UiIcons().presentation self.icon = build_icon(self.icon_path) - register_views() State().add_service('presentation', self.weight, is_plugin=True) State().update_pre_conditions('presentation', self.check_pre_conditions()) diff --git a/openlp/plugins/presentations/remote.py b/openlp/plugins/presentations/remote.py deleted file mode 100644 index 1e67b0ad9..000000000 --- a/openlp/plugins/presentations/remote.py +++ /dev/null @@ -1,116 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2020 OpenLP Developers # -# --------------------------------------------------------------------------- # -# 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 # -############################################################################### -import logging - -from flask import abort, request, Blueprint, jsonify - -from openlp.core.api import app -from openlp.core.api.lib import login_required, extract_request, old_auth -from openlp.core.lib.plugin import PluginStatus -from openlp.core.common.registry import Registry - -log = logging.getLogger(__name__) - - -v1_presentations = Blueprint('v1-presentations-plugin', __name__) -v2_presentations = Blueprint('v2-presentations-plugin', __name__) - - -def search(text): - plugin = Registry().get('plugin_manager').get_plugin_by_name('presentations') - if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search: - results = plugin.media_item.search(text, False) - return results - return None - - -def live(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('presentations') - if plugin.status == PluginStatus.Active and plugin.media_item: - plugin.media_item.presentations_go_live.emit([id, True]) - - -def add(id): - plugin = Registry().get('plugin_manager').get_plugin_by_name('presentations') - if plugin.status == PluginStatus.Active and plugin.media_item: - item_id = plugin.media_item.create_item_from_id(id) - plugin.media_item.presentations_add_to_service.emit([item_id, True]) - - -@v2_presentations.route('/search') -@login_required -def search_view(): - text = request.args.get('text', '') - result = search(text) - return jsonify(result) - - -@v2_presentations.route('/add', methods=['POST']) -@login_required -def add_view(): - data = request.json - if not data: - abort(400) - id = data.get('id', -1) - add(id) - return '', 204 - - -@v2_presentations.route('/live', methods=['POST']) -@login_required -def live_view(): - data = request.json - if not data: - abort(400) - id = data.get('id', -1) - live(id) - return '', 204 - - -# ----------------- DEPRECATED -------------- -@v1_presentations.route('/search') -@old_auth -def old_search(): - text = extract_request(request.args.get('data', ''), 'text') - return jsonify({'results': {'items': search(text)}}) - - -@v1_presentations.route('/add') -@old_auth -def old_add(): - id = extract_request(request.args.get('data', ''), 'id') - add(id) - return '', 204 - - -@v1_presentations.route('/live') -@old_auth -def old_live(): - id = extract_request(request.args.get('data', ''), 'id') - live(id) - return '', 204 -# ---------------- END DEPRECATED ---------------- - - -def register_views(): - app.register_blueprint(v2_presentations, url_prefix='/api/v2/plugins/presentations/') - app.register_blueprint(v1_presentations, url_prefix='/api/presentations/') diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index ba9cf0bc6..ad63f044a 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -40,7 +40,6 @@ from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.lib.ui import create_action from openlp.core.ui.icons import UiIcons from openlp.plugins.songs import reporting -from openlp.plugins.songs.remote import register_views from openlp.plugins.songs.forms.duplicatesongremovalform import DuplicateSongRemovalForm from openlp.plugins.songs.forms.songselectform import SongSelectForm from openlp.plugins.songs.lib import clean_song, upgrade @@ -127,7 +126,6 @@ class SongsPlugin(Plugin): self.icon = build_icon(self.icon_path) self.songselect_form = None self.settings.extend_default_settings(song_footer) - register_views() State().add_service(self.name, self.weight, is_plugin=True) State().update_pre_conditions(self.name, self.check_pre_conditions()) if not self.settings.value('songs/last import type'):