This commit is contained in:
rimach 2010-04-09 21:27:32 +02:00
commit 1a57939c73
13 changed files with 116 additions and 74 deletions

View File

@ -114,6 +114,7 @@ class MediaManagerItem(QtGui.QWidget):
self.Toolbar = None
self.remoteTriggered = None
self.ServiceItemIconName = None
self.singleServiceItem = True
self.addToServiceItem = False
self.PageLayout = QtGui.QVBoxLayout(self)
self.PageLayout.setSpacing(0)
@ -351,6 +352,24 @@ class MediaManagerItem(QtGui.QWidget):
count += 1
return filelist
def validate(self, file, thumb):
"""
Validates to see if the file still exists or
thumbnail is up to date
"""
filedate = os.stat(file).st_mtime
thumbdate = os.stat(thumb).st_mtime
#if file updated rebuild icon
if filedate > thumbdate:
self.IconFromFile(file, thumb)
def IconFromFile(self, file, thumb):
icon = build_icon(unicode(file))
pixmap = icon.pixmap(QtCore.QSize(88,50))
ext = os.path.splitext(thumb)[1].lower()
pixmap.save(thumb, ext[1:])
return icon
def loadList(self, list):
raise NotImplementedError(u'MediaManagerItem.loadList needs to be '
u'defined by the plugin')
@ -367,7 +386,7 @@ class MediaManagerItem(QtGui.QWidget):
raise NotImplementedError(u'MediaManagerItem.onDeleteClick needs to '
u'be defined by the plugin')
def generateSlideData(self, item):
def generateSlideData(self, service_item, item):
raise NotImplementedError(u'MediaManagerItem.generateSlideData needs '
u'to be defined by the plugin')
@ -401,11 +420,21 @@ class MediaManagerItem(QtGui.QWidget):
self.trUtf8('No Items Selected'),
self.trUtf8('You must select one or more items.'))
else:
log.debug(self.PluginNameShort + u' Add requested')
service_item = self.buildServiceItem()
if service_item:
service_item.from_plugin = False
self.parent.service_manager.addServiceItem(service_item)
#Is it posssible to process multiple list items to generate multiple
#service items?
if self.singleServiceItem:
log.debug(self.PluginNameShort + u' Add requested')
service_item = self.buildServiceItem()
if service_item:
service_item.from_plugin = False
self.parent.service_manager.addServiceItem(service_item)
else:
items = self.ListView.selectedIndexes()
for item in items:
service_item = self.buildServiceItem(item)
if service_item:
service_item.from_plugin = False
self.parent.service_manager.addServiceItem(service_item)
def onAddEditClick(self):
if not self.ListView.selectedIndexes() and not self.remoteTriggered:
@ -429,7 +458,7 @@ class MediaManagerItem(QtGui.QWidget):
self.trUtf8('Invalid Service Item'),
self.trUtf8(unicode('You must select a %s service item.' % self.title)))
def buildServiceItem(self):
def buildServiceItem(self, item=None):
"""
Common method for generating a service item
"""
@ -439,7 +468,7 @@ class MediaManagerItem(QtGui.QWidget):
else:
service_item.addIcon(
u':/media/media_' + self.PluginNameShort.lower() + u'.png')
if self.generateSlideData(service_item):
if self.generateSlideData(service_item, item):
return service_item
else:
return None
return None

View File

@ -235,7 +235,8 @@ class ServiceManager(QtGui.QWidget):
self.notesAction.setVisible(False)
if serviceItem[u'service_item'].is_capable(ItemCapabilities.AllowsEdit):
self.editAction.setVisible(True)
if serviceItem[u'service_item'].is_capable(ItemCapabilities.AllowsMaintain):
if serviceItem[u'service_item']\
.is_capable(ItemCapabilities.AllowsMaintain):
self.maintainAction.setVisible(True)
if item.parent() is None:
self.notesAction.setVisible(True)
@ -713,7 +714,7 @@ class ServiceManager(QtGui.QWidget):
get_config(u'auto preview', u'False')):
item += 1
if self.serviceItems and item < len(self.serviceItems) and \
serviceItem[u'service_item'].is_capable(ItemCapabilities.AllowsPreview):
self.serviceItems[item][u'service_item'].is_capable(ItemCapabilities.AllowsPreview):
self.parent.PreviewController.addServiceManagerItem(
self.serviceItems[item][u'service_item'], 0)
@ -722,8 +723,8 @@ class ServiceManager(QtGui.QWidget):
Posts a remote edit message to a plugin to allow item to be edited.
"""
item, count = self.findServiceItem()
if self.serviceItems[item][u'service_item'].\
is_capable(ItemCapabilities.AllowsEdit):
if self.serviceItems[item][u'service_item']\
.is_capable(ItemCapabilities.AllowsEdit):
self.remoteEditTriggered = True
Receiver.send_message(u'%s_edit' %
self.serviceItems[item][u'service_item'].name, u'L:%s' %

View File

@ -57,7 +57,6 @@ class BibleMediaItem(MediaManagerItem):
self.ConfigSection = title
self.IconPath = u'songs/song'
self.ListViewWithDnD_class = BibleListView
self.servicePath = None
self.lastReference = []
self.addToServiceItem = True
MediaManagerItem.__init__(self, parent, icon, title)
@ -440,7 +439,7 @@ class BibleMediaItem(MediaManagerItem):
if self.search_results:
self.displayResults(bible)
def generateSlideData(self, service_item):
def generateSlideData(self, service_item, item=None):
log.debug(u'generating slide data')
items = self.ListView.selectedIndexes()
if len(items) == 0:

View File

@ -50,8 +50,8 @@ class CustomMediaItem(MediaManagerItem):
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = CustomListView
self.servicePath = None
MediaManagerItem.__init__(self, parent, icon, title)
self.singleServiceItem = False
# Holds information about whether the edit is remotly triggered and
# which Custom is required.
self.remoteCustom = -1
@ -132,18 +132,21 @@ class CustomMediaItem(MediaManagerItem):
row = self.ListView.row(item)
self.ListView.takeItem(row)
def generateSlideData(self, service_item):
def generateSlideData(self, service_item, item=None):
raw_slides =[]
raw_footer = []
slide = None
theme = None
if self.remoteTriggered is None:
item = self.ListView.currentItem()
if item is None:
return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
if item is None:
if self.remoteTriggered is None:
item = self.ListView.currentItem()
if item is None:
return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
else:
item_id = self.remoteCustom
else:
item_id = self.remoteCustom
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
service_item.add_capability(ItemCapabilities.AllowsEdit)
service_item.add_capability(ItemCapabilities.AllowsPreview)
customSlide = self.parent.custommanager.get_custom(item_id)
@ -166,4 +169,4 @@ class CustomMediaItem(MediaManagerItem):
else:
raw_footer.append(u'')
service_item.raw_footer = raw_footer
return True
return True

View File

@ -52,7 +52,6 @@ class ImageMediaItem(MediaManagerItem):
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = ImageListView
self.servicePath = None
MediaManagerItem.__init__(self, parent, icon, title)
def initPluginNameVisible(self):
@ -125,18 +124,16 @@ class ImageMediaItem(MediaManagerItem):
(path, filename) = os.path.split(unicode(file))
thumb = os.path.join(self.servicePath, filename)
if os.path.exists(thumb):
self.validate(file, thumb)
icon = build_icon(thumb)
else:
icon = build_icon(unicode(file))
pixmap = icon.pixmap(QtCore.QSize(88,50))
ext = os.path.splitext(thumb)[1].lower()
pixmap.save(thumb, ext[1:])
icon = self.IconFromFile(file, thumb)
item_name = QtGui.QListWidgetItem(filename)
item_name.setIcon(icon)
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
self.ListView.addItem(item_name)
def generateSlideData(self, service_item):
def generateSlideData(self, service_item, item=None):
items = self.ListView.selectedIndexes()
if items:
service_item.title = self.trUtf8('Image(s)')
@ -165,4 +162,4 @@ class ImageMediaItem(MediaManagerItem):
self.parent.maindisplay.addImageWithText(frame)
def onPreviewClick(self):
MediaManagerItem.onPreviewClick(self)
MediaManagerItem.onPreviewClick(self)

View File

@ -52,10 +52,10 @@ class MediaMediaItem(MediaManagerItem):
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = MediaListView
self.PreviewFunction = self.video_get_preview
self.PreviewFunction = QtGui.QPixmap(u':/media/media_video.png').toImage()
MediaManagerItem.__init__(self, parent, icon, title)
self.singleServiceItem = False
self.ServiceItemIconName = u':/media/media_video.png'
self.MainDisplay = self.parent.maindisplay
def initPluginNameVisible(self):
self.PluginNameVisible = self.trUtf8('Media')
@ -72,24 +72,17 @@ class MediaMediaItem(MediaManagerItem):
self.hasNewIcon = False
self.hasEditIcon = False
def video_get_preview(self):
# For now cross platform is an icon. Phonon does not support
# individual frame access (yet?) and GStreamer is not available
# on Windows
return QtGui.QPixmap(u':/media/media_video.png').toImage()
def generateSlideData(self, service_item):
items = self.ListView.selectedIndexes()
if len(items) > 1:
return False
def generateSlideData(self, service_item, item=None):
if item is None:
item = self.ListView.currentItem()
if item is None:
return False
filename = unicode((item.data(QtCore.Qt.UserRole)).toString())
service_item.title = unicode(self.trUtf8('Media'))
service_item.add_capability(ItemCapabilities.RequiresMedia)
for item in items:
bitem = self.ListView.item(item.row())
filename = unicode((bitem.data(QtCore.Qt.UserRole)).toString())
frame = u':/media/image_clapperboard.png'
(path, name) = os.path.split(filename)
service_item.add_from_command(path, name, frame)
frame = u':/media/image_clapperboard.png'
(path, name) = os.path.split(filename)
service_item.add_from_command(path, name, frame)
return True
def initialise(self):
@ -110,7 +103,7 @@ class MediaMediaItem(MediaManagerItem):
for file in list:
(path, filename) = os.path.split(unicode(file))
item_name = QtGui.QListWidgetItem(filename)
img = self.video_get_preview()
img = QtGui.QPixmap(u':/media/media_video.png').toImage()
item_name.setIcon(build_icon(img))
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
self.ListView.addItem(item_name)
self.ListView.addItem(item_name)

View File

@ -37,6 +37,8 @@ import logging
import os
import time
from openlp.core.lib import resize_image
if os.name == u'nt':
from win32com.client import Dispatch
else:
@ -239,17 +241,22 @@ class ImpressDocument(PresentationDocument):
for idx in range(pages.getCount()):
page = pages.getByIndex(idx)
doc.getCurrentController().setCurrentPage(page)
path = u'%s/%s%s.png'% (thumbdir, self.controller.thumbnailprefix,
path = u'%s/%s%s.png' % (thumbdir, self.controller.thumbnailprefix,
unicode(idx + 1))
try:
doc.storeToURL(path , props)
preview = resize_image(path, 640, 480)
if os.path.exists(path):
os.remove(path)
preview.save(path, u'png')
except:
log.exception(u'%s\nUnable to store preview' % path)
log.exception(u'%s - Unable to store openoffice preview' % path)
def create_property(self, name, value):
log.debug(u'create property OpenOffice')
if os.name == u'nt':
prop = self.controller.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
prop = self.controller.manager.\
Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
else:
prop = PropertyValue()
prop.Name = name
@ -356,7 +363,8 @@ class ImpressDocument(PresentationDocument):
def get_slide_preview_file(self, slide_no):
"""
Returns an image path containing a preview for the requested slide
Returns an image path containing a preview for the
requested slide
``slide_no``
The slide an image is required for, starting at 1

View File

@ -140,12 +140,14 @@ class PresentationMediaItem(MediaManagerItem):
self.parent.config.set_list(
self.ConfigSection, self.getFileList())
filepath = unicode((item.data(QtCore.Qt.UserRole)).toString())
#not sure of this has errors
#John please can you look at .
for cidx in self.controllers:
doc = self.controllers[cidx].add_doc(filepath)
doc.presentation_deleted()
doc.close_presentation()
def generateSlideData(self, service_item):
def generateSlideData(self, service_item, item=None):
items = self.ListView.selectedIndexes()
if len(items) > 1:
return False

View File

@ -115,7 +115,6 @@ class PresentationController(object):
"""
return False
def start_process(self):
"""
Loads a running version of the presentation application in the background.
@ -138,13 +137,18 @@ class PresentationController(object):
self.docs.append(doc)
return doc
def remove_doc(self, doc):
def remove_doc(self, doc=None):
"""
Called to remove an open document from the collection
"""
log.debug(u'remove_doc Presentation')
self.docs.remove(doc)
if doc is None:
return
if doc in self.docs:
self.docs.remove(doc)
def close_presentation(self):
pass
class PresentationDocument(object):
"""
@ -256,7 +260,7 @@ class PresentationDocument(object):
Close presentation and clean up objects
Triggered by new object being added to SlideController
"""
self.controller.delete_doc(self)
self.controller.close_presentation()
def is_active(self):
"""

View File

@ -148,7 +148,7 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
def getVerseAll(self):
text = self.VerseTextEdit.toPlainText()
if not text.startsWith(u'---['):
text = u'---[%s:1]---\n%s' % (self.trUtf8('Verse'), text)
text = u'---[Verse:1]---\n%s' % text
return text
def onVerseComboChanged(self, id):

View File

@ -49,8 +49,8 @@ class SongMediaItem(MediaManagerItem):
self.ConfigSection = title
self.IconPath = u'songs/song'
self.ListViewWithDnD_class = SongListView
self.servicePath = None
MediaManagerItem.__init__(self, parent, icon, title)
self.singleServiceItem = False
self.edit_song_form = EditSongForm(self.parent.songmanager, self)
self.song_maintenance_form = SongMaintenanceForm(
self.parent.songmanager, self)
@ -276,31 +276,34 @@ class SongMediaItem(MediaManagerItem):
if len(items) == 1:
del_message = self.trUtf8('Delete song?')
else:
del_message = unicode(self.trUtf8('Delete %d song?')) % len(items)
del_message = unicode(self.trUtf8('Delete %d songs?')) % len(items)
ans = QtGui.QMessageBox.question(self,
self.trUtf8('Delete Confirmation'), del_message,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok|
QtGui.QMessageBox.Cancel),
QtGui.QMessageBox.Ok)
if ans == QtGui.QMessageBox.Cancel:
return
return
for item in items:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.songmanager.delete_song(item_id)
self.onSearchTextButtonClick()
def generateSlideData(self, service_item):
def generateSlideData(self, service_item, item=None):
raw_footer = []
author_list = u''
author_audit = []
ccli = u''
if self.remoteTriggered is None:
item = self.ListView.currentItem()
if item is None:
return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
if item is None:
if self.remoteTriggered is None:
item = self.ListView.currentItem()
if item is None:
return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
else:
item_id = self.remoteSong
else:
item_id = self.remoteSong
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
service_item.add_capability(ItemCapabilities.AllowsEdit)
service_item.add_capability(ItemCapabilities.AllowsPreview)
song = self.parent.songmanager.get_song(item_id)
@ -358,4 +361,4 @@ class SongMediaItem(MediaManagerItem):
service_item.audit = [
song.title, author_audit, song.copyright, song.ccli_number
]
return True
return True

Binary file not shown.

View File

@ -58,6 +58,7 @@ create_statements = [
id INTEGER NOT NULL,
song_book_id INTEGER,
title VARCHAR(255) NOT NULL,
alternate_title VARCHAR(255),
lyrics TEXT NOT NULL,
verse_order VARCHAR(128),
copyright VARCHAR(255),
@ -183,16 +184,18 @@ def import_songs():
xml_verse_template = u'<verse label="%d" type="Verse"><![CDATA[%s]]></verse>'
for row in rows:
clean_title = unicode(row[1], u'cp1252')
clean_lyrics = unicode(row[2], u'cp1252')
clean_lyrics = unicode(row[2], u'cp1252').replace(u'\r\n', u'\n')
clean_copyright = unicode(row[3], u'cp1252')
verse_order = u''
text_lyrics = clean_lyrics.split(u'\n\n')
xml_verse = u''
verses = []
for line, verse in enumerate(text_lyrics):
if not verse:
continue
xml_verse += (xml_verse_template % (line + 1, verse))
verse_order += '%d ' % (line + 1)
verses.append(u'V%d' % (line + 1))
verse_order = u' '.join(verses)
xml_lyrics = xml_lyrics_template % xml_verse
search_title = prepare_string(clean_title)
search_lyrics = prepare_string(clean_lyrics)