Fix error in previous merge for ThemeManager

Get Custom Working with remote editing
This commit is contained in:
Tim Bentley 2009-11-06 18:50:46 +00:00
parent b6602e67d4
commit 38e3ca66cb
3 changed files with 49 additions and 23 deletions

View File

@ -276,7 +276,7 @@ class ThemeManager(QtGui.QWidget):
xml = file_to_xml(xml_file) xml = file_to_xml(xml_file)
if not xml: if not xml:
xml = self.baseTheme() xml = self.baseTheme()
return createThemeFromXml(xml, self.path) return self.createThemeFromXml(xml, self.path)
def checkThemesExists(self, dir): def checkThemesExists(self, dir):
log.debug(u'check themes') log.debug(u'check themes')

View File

@ -81,7 +81,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
def onPreview(self, button): def onPreview(self, button):
log.debug(u'onPreview') log.debug(u'onPreview')
if button.text() == unicode(self.trUtf8(u'Save && Preview')) \ if button.text() == unicode(self.trUtf8(u'Save && Preview')) \
and self.saveSong(): and self.saveCustom():
Receiver().send_message(u'preview_custom') Receiver().send_message(u'preview_custom')
def initialise(self): def initialise(self):
@ -105,7 +105,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
for themename in themelist: for themename in themelist:
self.ThemeComboBox.addItem(themename) self.ThemeComboBox.addItem(themename)
def loadCustom(self, id): def loadCustom(self, id, preview):
self.customSlide = CustomSlide() self.customSlide = CustomSlide()
self.initialise() self.initialise()
if id != 0: if id != 0:
@ -124,17 +124,27 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
self.ThemeComboBox.setCurrentIndex(id) self.ThemeComboBox.setCurrentIndex(id)
else: else:
self.ThemeComboBox.setCurrentIndex(0) self.ThemeComboBox.setCurrentIndex(0)
#if not preview hide the preview button
self.previewButton.setVisible(False)
if preview:
self.previewButton.setVisible(True)
def closePressed(self): def closePressed(self):
Receiver().send_message(u'remote_edit_clear') Receiver().send_message(u'remote_edit_clear')
self.close() self.close()
def accept(self): def accept(self):
log.debug(u'accept')
if self.saveCustom():
Receiver().send_message(u'load_custom_list')
self.close()
def saveCustom(self):
valid, message = self._validate() valid, message = self._validate()
if not valid: if not valid:
QtGui.QMessageBox.critical(self, self.trUtf8(u'Error'), message, QtGui.QMessageBox.critical(self, self.trUtf8(u'Error'), message,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return return False
sxml = SongXMLBuilder() sxml = SongXMLBuilder()
sxml.new_document() sxml.new_document()
sxml.add_lyrics_to_song() sxml.add_lyrics_to_song()
@ -148,8 +158,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
self.customSlide.credits = unicode(self.CreditEdit.displayText()) self.customSlide.credits = unicode(self.CreditEdit.displayText())
self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText()) self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText())
self.custommanager.save_slide(self.customSlide) self.custommanager.save_slide(self.customSlide)
Receiver().send_message(u'load_custom_list') return True
self.close()
def onUpButtonPressed(self): def onUpButtonPressed(self):
selectedRow = self.VerseListView.currentRow() selectedRow = self.VerseListView.currentRow()

View File

@ -50,7 +50,9 @@ class CustomMediaItem(MediaManagerItem):
self.ListViewWithDnD_class = CustomListView self.ListViewWithDnD_class = CustomListView
self.servicePath = None self.servicePath = None
MediaManagerItem.__init__(self, parent, icon, title) MediaManagerItem.__init__(self, parent, icon, title)
self.fromServiceManager = -1 # Holds information about whether the edit is remotly triggered and
# which Custom is required.
self.remoteCustom = -1
def addEndHeaderBar(self): def addEndHeaderBar(self):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
@ -59,6 +61,8 @@ class CustomMediaItem(MediaManagerItem):
QtCore.SIGNAL(u'remote_edit_clear' ), self.onRemoteEditClear) QtCore.SIGNAL(u'remote_edit_clear' ), self.onRemoteEditClear)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'load_custom_list'), self.initialise) QtCore.SIGNAL(u'load_custom_list'), self.initialise)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'preview_custom'), self.onPreviewClick)
def initPluginNameVisible(self): def initPluginNameVisible(self):
self.PluginNameVisible = self.trUtf8(u'Custom') self.PluginNameVisible = self.trUtf8(u'Custom')
@ -69,6 +73,14 @@ class CustomMediaItem(MediaManagerItem):
def initialise(self): def initialise(self):
self.loadCustomListView(self.parent.custommanager.get_all_slides()) self.loadCustomListView(self.parent.custommanager.get_all_slides())
#Called to redisplay the song list screen edith 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()
self.onRemoteEditClear()
def loadCustomListView(self, list): def loadCustomListView(self, list):
self.ListView.clear() self.ListView.clear()
@ -77,8 +89,6 @@ class CustomMediaItem(MediaManagerItem):
custom_name.setData( custom_name.setData(
QtCore.Qt.UserRole, QtCore.QVariant(CustomSlide.id)) QtCore.Qt.UserRole, QtCore.QVariant(CustomSlide.id))
self.ListView.addItem(custom_name) self.ListView.addItem(custom_name)
if CustomSlide.id == self.fromServiceManager:
self.onAddClick()
def onNewClick(self): def onNewClick(self):
self.parent.edit_custom_form.loadCustom(0) self.parent.edit_custom_form.loadCustom(0)
@ -86,20 +96,29 @@ class CustomMediaItem(MediaManagerItem):
self.initialise() self.initialise()
def onRemoteEditClear(self): def onRemoteEditClear(self):
self.fromServiceManager = -1 self.remoteTriggered = None
self.remoteCustom = -1
def onRemoteEdit(self, item_id): def onRemoteEdit(self, customid):
valid = self.parent.custommanager.get_custom(item_id) """
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.
"""
fields = customid.split(u':')
valid = self.parent.custommanager.get_custom(fields[1])
if valid: if valid:
self.fromServiceManager = item_id self.remoteCustom = fields[1]
self.parent.edit_custom_form.loadCustom(item_id) self.remoteTriggered = fields[0]
self.parent.edit_custom_form.loadCustom(fields[1],
(fields[0] == u'P'))
self.parent.edit_custom_form.exec_() self.parent.edit_custom_form.exec_()
def onEditClick(self): def onEditClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.edit_custom_form.loadCustom(item_id) self.parent.edit_custom_form.loadCustom(item_id, False)
self.parent.edit_custom_form.exec_() self.parent.edit_custom_form.exec_()
self.initialise() self.initialise()
@ -116,14 +135,13 @@ class CustomMediaItem(MediaManagerItem):
raw_footer = [] raw_footer = []
slide = None slide = None
theme = None theme = None
if self.fromServiceManager == -1: if self.remoteTriggered is None:
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is None: if item is None:
return False return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
else: else:
item_id = self.fromServiceManager item_id = self.remoteCustom
self.fromServiceManager = -1
customSlide = self.parent.custommanager.get_custom(item_id) customSlide = self.parent.custommanager.get_custom(item_id)
title = customSlide.title title = customSlide.title
credit = customSlide.credits credit = customSlide.credits
@ -137,9 +155,8 @@ class CustomMediaItem(MediaManagerItem):
for verse in verseList: for verse in verseList:
raw_slides.append(verse[1]) raw_slides.append(verse[1])
raw_footer.append(title + u' '+ credit) raw_footer.append(title + u' '+ credit)
if theme: service_item.title = title
service_item.title = title for slide in raw_slides:
for slide in raw_slides: service_item.add_from_text(slide[:30], slide)
service_item.add_from_text(slide[:30], slide) service_item.raw_footer = raw_footer
service_item.raw_footer = raw_footer
return True return True