From f5a9f9ed89bf205b7b2bccea9e6af25156721860 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 5 Apr 2010 09:13:45 +0100 Subject: [PATCH] Update Image thumbnail if original has changed --- openlp/core/lib/mediamanageritem.py | 19 +++++++++++++++++++ openlp/plugins/images/lib/mediaitem.py | 7 +++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index f678bed7a..6ed2775f1 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -352,6 +352,25 @@ 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: + print "rebuild" + self.icon_from_file(file, thumb) + + def icon_from_file(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') diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index becf2be9f..072b4924e 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -121,15 +121,14 @@ class ImageMediaItem(MediaManagerItem): def loadList(self, list): for file in list: + print file (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.icon_from_file(file, thumb) item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(icon) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))