← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/b1 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/b1 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #774853 in OpenLP: "Color formatting tag displays incorrect color"
  https://bugs.launchpad.net/openlp/+bug/774853

For more details, see:
https://code.launchpad.net/~trb143/openlp/b1/+merge/61032

This sort of works but I need help to finish it.

Allow duplicate files with the same name for images and media files by not using the file name but a hash of the file name and path.  This works for Images and media.
Have tested with old and new service files.

I am unable to test with presentations (I do not have Powerpoint or PPTViewer).
I also have a problem with Impress as it will not create thumbnails.  This is a bug in trunk for me as well.  

Help with testing and presentations will be appreciated.
-- 
https://code.launchpad.net/~trb143/openlp/b1/+merge/61032
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/b1 into lp:openlp.
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py	2011-05-15 12:11:08 +0000
+++ openlp/core/lib/__init__.py	2011-05-15 17:39:35 +0000
@@ -169,8 +169,7 @@
 
 def image_to_byte(image):
     """
-    Resize an image to fit on the current screen for the web and returns
-    it as a byte stream.
+    Convert an Image to a Base64 array.
 
     ``image``
         The image to converted.
@@ -273,6 +272,20 @@
     except IOError:
         pass
 
+def generate_hash_for_file(full_path, filename):
+    """
+    Convert a file path into a hash with correct file type
+
+    ``full_path``
+        Path to the file including the file name
+
+    ``filename``
+        The name of the file.
+    """
+    file_type = os.path.splitext(filename)[1]
+    hash_name = unicode(abs(hash(unicode(full_path))))
+    return u'%s%s' %(hash_name, file_type)
+
 from listwidgetwithdnd import ListWidgetWithDnD
 from displaytags import DisplayTags
 from eventreceiver import Receiver

=== modified file 'openlp/core/lib/serviceitem.py'
--- openlp/core/lib/serviceitem.py	2011-05-11 22:32:25 +0000
+++ openlp/core/lib/serviceitem.py	2011-05-15 17:39:35 +0000
@@ -33,7 +33,8 @@
 import os
 import uuid
 
-from openlp.core.lib import build_icon, clean_tags, expand_tags
+from openlp.core.lib import build_icon, clean_tags, expand_tags, \
+    generate_hash_for_file
 from openlp.core.lib.ui import UiStrings
 
 log = logging.getLogger(__name__)
@@ -205,8 +206,13 @@
             A title for the slide in the service item.
         """
         self.service_item_type = ServiceItemType.Image
-        self._raw_frames.append({u'title': title, u'path': path})
-        self.renderer.image_manager.add_image(title, path)
+        reference = generate_hash_for_file(path, title)
+        # Fix the path if generated from a service load
+        if self.from_service:
+            path = os.path.join( os.path.split(path)[0], reference)
+        self._raw_frames.append({u'title': title, u'path': path,
+            u'reference': reference})
+        self.renderer.image_manager.add_image(reference, path)
         self._new_item()
 
     def add_from_text(self, title, raw_slide, verse_tag=None):
@@ -241,6 +247,13 @@
             The command of/for the slide.
         """
         self.service_item_type = ServiceItemType.Command
+        # Fix the path if generated from a service load
+        if self.from_service:
+            full_path = os.path.join(path, file_name)
+            reference = generate_hash_for_file(full_path, file_name)
+            path = os.path.join(path, reference)
+        else:
+            path = os.path.join(path, file_name)
         self._raw_frames.append(
             {u'title': file_name, u'image': image, u'path': path})
         self._new_item()
@@ -413,6 +426,10 @@
         if self.service_item_type == ServiceItemType.Text:
             return self._display_frames[row][u'html'].split(u'\n')[0]
         elif self.service_item_type == ServiceItemType.Image:
+            if u'reference' in self._raw_frames[row]:
+                return self._raw_frames[row][u'reference']
+            else:
+                return self._raw_frames[row][u'title']
             return self._raw_frames[row][u'title']
         else:
             return self._raw_frames[row][u'image']
@@ -455,4 +472,3 @@
             return end
         else:
             return u'%s : %s' % (start, end)
-

=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2011-05-13 13:58:17 +0000
+++ openlp/core/ui/servicemanager.py	2011-05-15 17:39:35 +0000
@@ -33,7 +33,7 @@
 from PyQt4 import QtCore, QtGui
 
 from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, \
-    ItemCapabilities, SettingsManager, translate
+    ItemCapabilities, SettingsManager, translate, generate_hash_for_file
 from openlp.core.lib.theme import ThemeLevel
 from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
     context_menu_action, context_menu_separator, find_and_set_in_combo_box
@@ -575,6 +575,10 @@
                 osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile))
                 filePath = os.path.join(self.servicePath,
                     os.path.split(osfile)[1])
+                # Need to double process as the first call sets up the path
+                # correctly otherwise the hash value is wrong.
+                filePath = os.path.join(self.servicePath,
+                    generate_hash_for_file(filePath, os.path.split(osfile)[1]))
                 fileTo = open(filePath, u'wb')
                 fileTo.write(zip.read(file))
                 fileTo.flush()
@@ -1108,6 +1112,7 @@
         """
         Send the current item to the Preview slide controller
         """
+        Receiver.send_message(u'cursor_busy')
         item, child = self.findServiceItem()
         if self.serviceItems[item][u'service_item'].is_valid:
             self.mainwindow.previewController.addServiceManagerItem(
@@ -1117,6 +1122,7 @@
                 translate('OpenLP.ServiceManager', 'Missing Display Handler'),
                 translate('OpenLP.ServiceManager', 'Your item cannot be '
                 'displayed as there is no handler to display it'))
+        Receiver.send_message(u'cursor_normal')
 
     def getServiceItem(self):
         """
@@ -1149,6 +1155,7 @@
             return
         if row != -1:
             child = row
+        Receiver.send_message(u'cursor_busy')
         if self.serviceItems[item][u'service_item'].is_valid:
             self.mainwindow.liveController.addServiceManagerItem(
                 self.serviceItems[item][u'service_item'], child)
@@ -1168,6 +1175,7 @@
                 translate('OpenLP.ServiceManager', 'Your item cannot be '
                 'displayed as the plugin required to display it is missing '
                 'or inactive'))
+        Receiver.send_message(u'cursor_normal')
 
     def remoteEdit(self):
         """

=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py	2011-05-15 10:38:11 +0000
+++ openlp/core/ui/slidecontroller.py	2011-05-15 17:39:35 +0000
@@ -628,10 +628,11 @@
                         self.parent.renderer.height)
                 else:
                     # If current slide set background to image
+                    reference = self.serviceItem.get_rendered_frame(framenumber)
+                    image = self.image_manager.get_image(reference)
                     if framenumber == slideno:
-                        self.serviceItem.bg_image_bytes = \
-                            self.image_manager.get_image_bytes(frame[u'title'])
-                    image = self.image_manager.get_image(frame[u'title'])
+                        self.serviceItem.bg_image_bytes = self.image_manager. \
+                            get_image_bytes(reference)
                 label.setPixmap(QtGui.QPixmap.fromImage(image))
                 self.previewListWidget.setCellWidget(framenumber, 0, label)
                 slideHeight = width * self.parent.renderer.screen_ratio
@@ -1070,7 +1071,7 @@
         Respond to the arrival of a media service item
         """
         log.debug(u'SlideController onMediaStart')
-        file = os.path.join(item.get_frame_path(), item.get_frame_title())
+        file = item.get_frame_path()
         if self.isLive:
             self.display.video(file, self.volume)
             self.volumeSlider.setValue(self.volume)

=== modified file 'openlp/plugins/images/lib/mediaitem.py'
--- openlp/plugins/images/lib/mediaitem.py	2011-04-30 17:36:13 +0000
+++ openlp/plugins/images/lib/mediaitem.py	2011-05-15 17:39:35 +0000
@@ -31,7 +31,7 @@
 
 from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
     SettingsManager, translate, check_item_selected, check_directory_exists, \
-    Receiver
+    Receiver, generate_hash_for_file
 from openlp.core.lib.ui import UiStrings, critical_error_message_box
 from openlp.core.utils import AppLocation, delete_file, get_images_filter
 
@@ -107,24 +107,25 @@
             SettingsManager.set_list(self.settingsSection,
                 self.settingsSection, self.getFileList())
 
-    def loadList(self, list, initialLoad=False):
+    def loadList(self, filelist, initialLoad=False):
         if not initialLoad:
-            self.parent.formparent.displayProgressBar(len(list))
-        for imageFile in list:
+            self.parent.formparent.displayProgressBar(len(filelist))
+        for image_file in filelist:
             if not initialLoad:
                 self.parent.formparent.incrementProgressBar()
-            filename = os.path.split(unicode(imageFile))[1]
-            thumb = os.path.join(self.servicePath, filename)
+            filename = os.path.split(unicode(image_file))[1]
+            thumb_file = generate_hash_for_file(image_file, filename)
+            thumb = os.path.join(self.servicePath, thumb_file)
             if os.path.exists(thumb):
-                if self.validate(imageFile, thumb):
+                if self.validate(image_file, thumb):
                     icon = build_icon(thumb)
                 else:
                     icon = build_icon(u':/general/general_delete.png')
             else:
-                icon = self.iconFromFile(imageFile, thumb)
+                icon = self.iconFromFile(image_file, thumb)
             item_name = QtGui.QListWidgetItem(filename)
             item_name.setIcon(icon)
-            item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(imageFile))
+            item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(image_file))
             self.listView.addItem(item_name)
         if not initialLoad:
             self.parent.formparent.finishedProgressBar()
@@ -201,7 +202,9 @@
             filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
             if os.path.exists(filename):
                 (path, name) = os.path.split(filename)
-                self.parent.liveController.display.directImage(name, filename)
+                reference = generate_hash_for_file(filename, name)
+                self.parent.liveController.display.directImage(reference,
+                    filename)
                 self.resetAction.setVisible(True)
             else:
                 critical_error_message_box(UiStrings().LiveBGError,

=== modified file 'openlp/plugins/presentations/lib/impresscontroller.py'
--- openlp/plugins/presentations/lib/impresscontroller.py	2011-05-13 20:59:14 +0000
+++ openlp/plugins/presentations/lib/impresscontroller.py	2011-05-15 17:39:35 +0000
@@ -262,6 +262,7 @@
         Create thumbnail images for presentation
         """
         log.debug(u'create thumbnails OpenOffice')
+        from com.sun.star.io import IOException
         if self.check_thumbnails():
             return
         if os.name == u'nt':

=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
--- openlp/plugins/presentations/lib/mediaitem.py	2011-04-30 17:36:28 +0000
+++ openlp/plugins/presentations/lib/mediaitem.py	2011-05-15 17:39:35 +0000
@@ -30,7 +30,8 @@
 from PyQt4 import QtCore, QtGui
 
 from openlp.core.lib import MediaManagerItem, build_icon, SettingsManager, \
-    translate, check_item_selected, Receiver, ItemCapabilities
+    translate, check_item_selected, Receiver, ItemCapabilities, \
+    generate_hash_for_file
 from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
     media_item_combo_box
 from openlp.plugins.presentations.lib import MessageListener

=== modified file 'openlp/plugins/presentations/lib/presentationcontroller.py'
--- openlp/plugins/presentations/lib/presentationcontroller.py	2011-04-03 17:51:10 +0000
+++ openlp/plugins/presentations/lib/presentationcontroller.py	2011-05-15 17:39:35 +0000
@@ -30,7 +30,7 @@
 
 from PyQt4 import QtCore
 
-from openlp.core.lib import Receiver, resize_image
+from openlp.core.lib import Receiver, resize_image, generate_hash_for_file
 from openlp.core.utils import AppLocation
 
 log = logging.getLogger(__name__)
@@ -132,8 +132,9 @@
         """
         The location where thumbnail images will be stored
         """
-        return os.path.join(
-            self.controller.thumbnail_folder, self.get_file_name())
+        hash_name = generate_hash_for_file(self.controller.thumbnail_folder,
+            self.get_file_name())
+        return os.path.join(self.controller.thumbnail_folder, hash_name)
 
     def get_temp_folder(self):
         """


Follow ups