Remote Edit cleanup and simplification

This commit is contained in:
Tim Bentley 2013-01-27 09:57:03 +00:00
parent bdb9089409
commit eb3e5b8642
8 changed files with 49 additions and 74 deletions

View File

@ -200,12 +200,6 @@ class EventReceiver(QtCore.QObject):
``{plugin}_unblank``
Requests a plugin to handle an unblank screen event.
``{plugin}_edit``
Requests a plugin edit a database item with the key as the payload.
``{plugin}_edit_clear``
Editing has been completed.
``{plugin}_load_list``
Tells the the plugin to reload the media manager list.

View File

@ -99,7 +99,7 @@ class MediaManagerItem(QtGui.QWidget):
self.plugin = plugin
visible_title = self.plugin.getString(StringContent.VisibleName)
self.title = unicode(visible_title[u'title'])
Registry().register(self.title, self)
Registry().register(self.plugin.name, self)
self.settingsSection = self.plugin.name
self.icon = None
if icon:
@ -436,8 +436,8 @@ class MediaManagerItem(QtGui.QWidget):
"""
pass
def generateSlideData(self, serviceItem, item=None, xmlVersion=False,
remote=False, context=ServiceItemContext.Live):
def generateSlideData(self, serviceItem, item=None, xmlVersion=False, remote=False,
context=ServiceItemContext.Live):
raise NotImplementedError(u'MediaManagerItem.generateSlideData needs to be defined by the plugin')
def onDoubleClicked(self):
@ -507,13 +507,13 @@ class MediaManagerItem(QtGui.QWidget):
"""
Add a selected item to the current service
"""
if not self.listView.selectedIndexes() and not self.remoteTriggered:
if not self.listView.selectedIndexes():
QtGui.QMessageBox.information(self, UiStrings().NISp,
translate('OpenLP.MediaManagerItem', 'You must select one or more items to add.'))
else:
# Is it possible to process multiple list items to generate
# multiple service items?
if self.singleServiceItem or self.remoteTriggered:
if self.singleServiceItem:
log.debug(u'%s Add requested', self.plugin.name)
self.addToService(replace=self.remoteTriggered)
else:
@ -554,8 +554,7 @@ class MediaManagerItem(QtGui.QWidget):
"""
serviceItem = ServiceItem(self.plugin)
serviceItem.add_icon(self.plugin.iconPath)
if self.generateSlideData(serviceItem, item, xmlVersion, remote,
context):
if self.generateSlideData(serviceItem, item, xmlVersion, remote, context):
return serviceItem
else:
return None

View File

@ -1400,12 +1400,14 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
def remote_edit(self):
"""
Posts a remote edit message to a plugin to allow item to be edited.
Triggers a remote edit to a plugin to allow item to be edited.
"""
item = self.find_service_item()[0]
item, child = self.find_service_item()
if self.service_items[item][u'service_item'].is_capable(ItemCapabilities.CanEdit):
Receiver.send_message(u'%s_edit' % self.service_items[item][u'service_item'].name.lower(),
u'L:%s' % self.service_items[item][u'service_item'].edit_id)
new_item = Registry().get(self.service_items[item][u'service_item'].name). \
onRemoteEdit(self.service_items[item][u'service_item'].edit_id)
if new_item:
self.addServiceItem(new_item, replace=True)
def create_custom(self):
"""

View File

@ -1183,7 +1183,9 @@ class SlideController(DisplayController):
From the preview display requires the service Item to be editied
"""
self.songEdit = True
Receiver.send_message(u'%s_edit' % self.serviceItem.name.lower(), u'P:%s' % self.serviceItem.edit_id)
new_item = Registry().get(self.serviceItem.name).onRemoteEdit(self.serviceItem.edit_id, True)
if new_item:
self.addServiceItem(new_item)
def onPreviewAddToService(self):
"""

View File

@ -102,10 +102,6 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
# If not preview hide the preview button.
self.previewButton.setVisible(preview)
def reject(self):
Receiver.send_message(u'custom_edit_clear')
QtGui.QDialog.reject(self)
def accept(self):
log.debug(u'accept')
if self.saveCustom():

View File

@ -73,8 +73,6 @@ class CustomMediaItem(MediaManagerItem):
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick)
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'searchTypeChanged(int)'),
self.onSearchTextButtonClicked)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_edit'), self.onRemoteEdit)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_edit_clear'), self.onRemoteEditClear)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_load_list'), self.loadList)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.config_updated)
@ -115,11 +113,6 @@ class CustomMediaItem(MediaManagerItem):
# Called to redisplay the custom list screen edith from a search
# or from the exit of the Custom edit dialog. If remote editing is
# active trigger it and clean up so it will not update again.
if self.remoteTriggered == u'L':
self.onAddClick()
if self.remoteTriggered == u'P':
self.onPreviewClick()
self.onRemoteEditClear()
def onNewClick(self):
self.edit_custom_form.loadCustom(0)
@ -127,26 +120,27 @@ class CustomMediaItem(MediaManagerItem):
self.onClearTextButtonClick()
self.onSelectionChange()
def onRemoteEditClear(self):
self.remoteTriggered = None
self.remoteCustom = -1
def onRemoteEdit(self, message):
def onRemoteEdit(self, custom_id, preview=False):
"""
Called by ServiceManager or SlideController by event passing
the custom Id in the payload along with an indicator to say which
type of display is required.
"""
remote_type, custom_id = message.split(u':')
custom_id = int(custom_id)
valid = self.manager.get_object(CustomSlide, custom_id)
if valid:
self.remoteCustom = custom_id
self.remoteTriggered = remote_type
self.edit_custom_form.loadCustom(custom_id, (remote_type == u'P'))
self.edit_custom_form.exec_()
self.autoSelectId = -1
self.onSearchTextButtonClicked()
self.edit_custom_form.loadCustom(custom_id, preview)
if self.edit_custom_form.exec_() == QtGui.QDialog.Accepted:
self.remoteTriggered = True
self.remoteCustom = custom_id
self.autoSelectId = -1
self.onSearchTextButtonClicked()
item = self.buildServiceItem(remote=True)
self.remoteTriggered = None
self.remoteCustom =1
if item:
return item
return None
def onEditClick(self):
"""

View File

@ -775,7 +775,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
Exit Dialog and do not save
"""
log.debug (u'SongEditForm.reject')
Receiver.send_message(u'songs_edit_clear')
self.clearCaches()
QtGui.QDialog.reject(self)

View File

@ -35,15 +35,12 @@ import shutil
from PyQt4 import QtCore, QtGui
from sqlalchemy.sql import or_
from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
translate, check_item_selected, PluginStatus, create_separated_list, \
check_directory_exists, ServiceItemContext, Settings, UiStrings
from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, translate, check_item_selected, \
PluginStatus, create_separated_list, check_directory_exists, ServiceItemContext, Settings, UiStrings
from openlp.core.lib.ui import create_widget_action
from openlp.core.utils import AppLocation
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
SongImportForm, SongExportForm
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
clean_string, natcmp
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, SongImportForm, SongExportForm
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, clean_string, natcmp
from openlp.plugins.songs.lib.db import Author, Song, Book, MediaFile
from openlp.plugins.songs.lib.ui import SongStrings
@ -105,8 +102,6 @@ class SongMediaItem(MediaManagerItem):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_load_list'), self.onSongListLoad)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configUpdated)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_preview'), self.onPreviewClick)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_edit'), self.onRemoteEdit)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_edit_clear'), self.onRemoteEditClear)
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick)
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'searchTypeChanged(int)'),
self.onSearchTextButtonClicked)
@ -212,15 +207,10 @@ class SongMediaItem(MediaManagerItem):
# Called to redisplay the song list screen edit from a search
# or from the exit of the Song edit dialog. If remote editing is active
# Trigger it and clean up so it will not update again.
if self.remoteTriggered == u'L':
self.onAddClick()
if self.remoteTriggered == u'P':
self.onPreviewClick()
# Push edits to the service manager to update items
if self.editItem and self.updateServiceOnEdit and not self.remoteTriggered:
item = self.buildServiceItem(self.editItem)
self.plugin.serviceManager.replaceServiceItem(item)
self.onRemoteEditClear()
self.service_manager.replaceServiceItem(item)
self.onSearchTextButtonClicked()
log.debug(u'onSongListLoad - finished')
@ -321,28 +311,28 @@ class SongMediaItem(MediaManagerItem):
def onSongMaintenanceClick(self):
self.songMaintenanceForm.exec_()
def onRemoteEditClear(self):
log.debug(u'onRemoteEditClear')
self.remoteTriggered = None
self.remoteSong = -1
def onRemoteEdit(self, message):
def onRemoteEdit(self, song_id, preview=False):
"""
Called by ServiceManager or SlideController by event passing
the Song Id in the payload along with an indicator to say which
type of display is required.
"""
log.debug(u'onRemoteEdit %s' % message)
remote_type, song_id = message.split(u':')
log.debug(u'onRemoteEdit for song %s' % song_id)
song_id = int(song_id)
valid = self.plugin.manager.get_object(Song, song_id)
if valid:
self.remoteSong = song_id
self.remoteTriggered = remote_type
self.editSongForm.loadSong(song_id, remote_type == u'P')
self.editSongForm.exec_()
self.autoSelectId = -1
self.onSongListLoad()
self.editSongForm.loadSong(song_id, preview)
if self.editSongForm.exec_() == QtGui.QDialog.Accepted:
self.autoSelectId = -1
self.onSongListLoad()
self.remoteSong = song_id
self.remoteTriggered = True
item = self.buildServiceItem(remote=True)
self.remoteSong = -1
self.remoteTriggered = None
if item:
return item
return None
def onEditClick(self):
"""
@ -410,7 +400,7 @@ class SongMediaItem(MediaManagerItem):
self.onSongListLoad()
def generateSlideData(self, service_item, item=None, xmlVersion=False,
remote=False, context=ServiceItemContext.Service):
remote=False, context=ServiceItemContext.Service):
log.debug(u'generateSlideData: %s, %s, %s' % (service_item, item, self.remoteSong))
item_id = self._getIdOfItemToGenerate(item, self.remoteSong)
service_item.add_capability(ItemCapabilities.CanEdit)
@ -426,8 +416,7 @@ class SongMediaItem(MediaManagerItem):
verse_list = SongXML().get_verses(song.lyrics)
# no verse list or only 1 space (in error)
verse_tags_translated = False
if VerseType.from_translated_string(unicode(
verse_list[0][0][u'type'])) is not None:
if VerseType.from_translated_string(unicode(verse_list[0][0][u'type'])) is not None:
verse_tags_translated = True
if not song.verse_order.strip():
for verse in verse_list: