From c45d6915c7d1502e62110b088e09b742c31b3254 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 19 Dec 2012 13:37:40 +0100 Subject: [PATCH 1/4] Convert QStringList to Python list. This fixes importing when the path name contains non-ascii chars. --- openlp/core/lib/mediamanageritem.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 8e1107f1a..6027225e2 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -341,6 +341,8 @@ class MediaManagerItem(QtGui.QWidget): self, self.onNewPrompt, SettingsManager.get_last_dir(self.settingsSection), self.onNewFileMasks) + # Convert QStringList containing QStrings to a Python list containing unicode strings + files = [unicode(f) for f in files] log.info(u'New files(s) %s', unicode(files)) if files: Receiver.send_message(u'cursor_busy') From 1e53bd37a64139273df3a29688deb3961c59b67e Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 19 Dec 2012 23:05:48 +0100 Subject: [PATCH 2/4] Fix import of files that contain non-ascii chars. QStringList containing QStrings is converted to std list containing unicode strings. Thus, we don't need these unicode() calls on the contents of the list anymore. --- openlp/core/lib/mediamanageritem.py | 4 ++-- openlp/plugins/images/lib/mediaitem.py | 10 +++++----- openlp/plugins/media/lib/mediaitem.py | 8 ++++---- openlp/plugins/presentations/lib/mediaitem.py | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 6027225e2..6e177b7cf 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -342,8 +342,8 @@ class MediaManagerItem(QtGui.QWidget): SettingsManager.get_last_dir(self.settingsSection), self.onNewFileMasks) # Convert QStringList containing QStrings to a Python list containing unicode strings - files = [unicode(f) for f in files] - log.info(u'New files(s) %s', unicode(files)) + files = map(unicode, files) + log.info(u'New files(s) %s', files) if files: Receiver.send_message(u'cursor_busy') self.validateAndLoad(files) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index a9087a731..7ea13e9af 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -130,17 +130,17 @@ class ImageMediaItem(MediaManagerItem): # Sort the images by its filename considering language specific # characters. images.sort(cmp=locale_compare, - key=lambda filename: os.path.split(unicode(filename))[1]) + key=lambda filename: os.path.split(filename)[1]) for imageFile in images: - filename = os.path.split(unicode(imageFile))[1] + filename = os.path.split(imageFile)[1] thumb = os.path.join(self.servicePath, filename) - if not os.path.exists(unicode(imageFile)): + if not os.path.exists(imageFile): icon = build_icon(u':/general/general_delete.png') else: - if validate_thumb(unicode(imageFile), thumb): + if validate_thumb(imageFile, thumb): icon = build_icon(thumb) else: - icon = create_thumb(unicode(imageFile), thumb) + icon = create_thumb(imageFile, thumb) item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(icon) item_name.setToolTip(imageFile) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 032b09694..5fbd81448 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -299,21 +299,21 @@ class MediaMediaItem(MediaManagerItem): # Sort the media by its filename considering language specific # characters. media.sort(cmp=locale_compare, - key=lambda filename: os.path.split(unicode(filename))[1]) + key=lambda filename: os.path.split(filename)[1]) for track in media: track_info = QtCore.QFileInfo(track) if not os.path.exists(track): - filename = os.path.split(unicode(track))[1] + filename = os.path.split(track)[1] item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(build_icon(ERROR)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(track)) elif track_info.isFile(): - filename = os.path.split(unicode(track))[1] + filename = os.path.split(track)[1] item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(build_icon(VIDEO)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(track)) else: - filename = os.path.split(unicode(track))[1] + filename = os.path.split(track)[1] item_name = QtGui.QListWidgetItem(filename) #TODO: add the appropriate Icon #item_name.setIcon(build_icon(DVD_ICON)) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index cc0ab992c..a9bd8bce9 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -175,13 +175,13 @@ class PresentationMediaItem(MediaManagerItem): # Sort the presentations by its filename considering language specific # characters. files.sort(cmp=locale_compare, - key=lambda filename: os.path.split(unicode(filename))[1]) + key=lambda filename: os.path.split(filename)[1]) for file in files: if not initialLoad: self.plugin.formParent.incrementProgressBar() if currlist.count(file) > 0: continue - filename = os.path.split(unicode(file))[1] + filename = os.path.split(file)[1] if not os.path.exists(file): item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(build_icon(ERROR)) @@ -201,7 +201,7 @@ class PresentationMediaItem(MediaManagerItem): controller_name = self.findControllerByType(filename) if controller_name: controller = self.controllers[controller_name] - doc = controller.add_document(unicode(file)) + doc = controller.add_document(file) thumb = os.path.join(doc.get_thumbnail_folder(), u'icon.png') preview = doc.get_thumbnail_path(1, True) From 908a56586d38a43371335e2e5fc182fb12e339c0 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 3 Jan 2013 23:11:28 +0100 Subject: [PATCH 3/4] Revert cleanups for this branch, only the bugfix Fixes: https://launchpad.net/bugs/1093184 --- openlp/core/lib/mediamanageritem.py | 4 ++-- openlp/plugins/images/lib/mediaitem.py | 10 +++++----- openlp/plugins/media/lib/mediaitem.py | 8 ++++---- openlp/plugins/presentations/lib/mediaitem.py | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 6e177b7cf..2b2d10999 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -341,9 +341,9 @@ class MediaManagerItem(QtGui.QWidget): self, self.onNewPrompt, SettingsManager.get_last_dir(self.settingsSection), self.onNewFileMasks) - # Convert QStringList containing QStrings to a Python list containing unicode strings + files = map(unicode, files) - log.info(u'New files(s) %s', files) + log.info(u'New files(s) %s', unicode(files)) if files: Receiver.send_message(u'cursor_busy') self.validateAndLoad(files) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 7ea13e9af..a9087a731 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -130,17 +130,17 @@ class ImageMediaItem(MediaManagerItem): # Sort the images by its filename considering language specific # characters. images.sort(cmp=locale_compare, - key=lambda filename: os.path.split(filename)[1]) + key=lambda filename: os.path.split(unicode(filename))[1]) for imageFile in images: - filename = os.path.split(imageFile)[1] + filename = os.path.split(unicode(imageFile))[1] thumb = os.path.join(self.servicePath, filename) - if not os.path.exists(imageFile): + if not os.path.exists(unicode(imageFile)): icon = build_icon(u':/general/general_delete.png') else: - if validate_thumb(imageFile, thumb): + if validate_thumb(unicode(imageFile), thumb): icon = build_icon(thumb) else: - icon = create_thumb(imageFile, thumb) + icon = create_thumb(unicode(imageFile), thumb) item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(icon) item_name.setToolTip(imageFile) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 5fbd81448..032b09694 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -299,21 +299,21 @@ class MediaMediaItem(MediaManagerItem): # Sort the media by its filename considering language specific # characters. media.sort(cmp=locale_compare, - key=lambda filename: os.path.split(filename)[1]) + key=lambda filename: os.path.split(unicode(filename))[1]) for track in media: track_info = QtCore.QFileInfo(track) if not os.path.exists(track): - filename = os.path.split(track)[1] + filename = os.path.split(unicode(track))[1] item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(build_icon(ERROR)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(track)) elif track_info.isFile(): - filename = os.path.split(track)[1] + filename = os.path.split(unicode(track))[1] item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(build_icon(VIDEO)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(track)) else: - filename = os.path.split(track)[1] + filename = os.path.split(unicode(track))[1] item_name = QtGui.QListWidgetItem(filename) #TODO: add the appropriate Icon #item_name.setIcon(build_icon(DVD_ICON)) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index a9bd8bce9..cc0ab992c 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -175,13 +175,13 @@ class PresentationMediaItem(MediaManagerItem): # Sort the presentations by its filename considering language specific # characters. files.sort(cmp=locale_compare, - key=lambda filename: os.path.split(filename)[1]) + key=lambda filename: os.path.split(unicode(filename))[1]) for file in files: if not initialLoad: self.plugin.formParent.incrementProgressBar() if currlist.count(file) > 0: continue - filename = os.path.split(file)[1] + filename = os.path.split(unicode(file))[1] if not os.path.exists(file): item_name = QtGui.QListWidgetItem(filename) item_name.setIcon(build_icon(ERROR)) @@ -201,7 +201,7 @@ class PresentationMediaItem(MediaManagerItem): controller_name = self.findControllerByType(filename) if controller_name: controller = self.controllers[controller_name] - doc = controller.add_document(file) + doc = controller.add_document(unicode(file)) thumb = os.path.join(doc.get_thumbnail_folder(), u'icon.png') preview = doc.get_thumbnail_path(1, True) From f37482dec5a53b3a887c5d349fa1469d136bf081 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 4 Jan 2013 12:03:03 +0100 Subject: [PATCH 4/4] Remove blank line --- openlp/core/lib/mediamanageritem.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 2b2d10999..4235cba62 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -341,7 +341,6 @@ class MediaManagerItem(QtGui.QWidget): self, self.onNewPrompt, SettingsManager.get_last_dir(self.settingsSection), self.onNewFileMasks) - files = map(unicode, files) log.info(u'New files(s) %s', unicode(files)) if files: