From 03638ddea608878c9a78126ee2c031572b513287 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Aug 2013 11:16:15 +0100 Subject: [PATCH 1/7] Fixes #1209515 by subclassing QFileDialog and attempting to urldecode any files not found --- openlp/core/lib/__init__.py | 1 + openlp/core/lib/filedialog.py | 59 ++++++++++++++++++++ openlp/core/lib/mediamanageritem.py | 4 +- openlp/core/lib/ui.py | 6 +- openlp/core/ui/thememanager.py | 4 +- openlp/core/utils/__init__.py | 1 - openlp/plugins/songs/forms/editsongform.py | 4 +- openlp/plugins/songs/forms/songimportform.py | 4 +- 8 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 openlp/core/lib/filedialog.py diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 4f0f78cd9..93d2dd953 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -384,6 +384,7 @@ def create_separated_list(stringlist): from eventreceiver import Receiver +from filedialog import FileDialog from listwidgetwithdnd import ListWidgetWithDnD from formattingtags import FormattingTags from spelltextedit import SpellTextEdit diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py new file mode 100644 index 000000000..ffc8ec96d --- /dev/null +++ b/openlp/core/lib/filedialog.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### + +""" +Provide a work around for a bug in QFileDialog (#1209515) +""" +import logging +import os +import urllib + +from PyQt4 import QtCore, QtGui + +from openlp.core.lib.ui import UiStrings + +log = logging.getLogger(__name__) + +class FileDialog(QtGui.QFileDialog): + def __init__(self): + QtGui.QFileDialog.__init__(self) + + def getOpenFileNames(self, parent, title, path, filters): + files = QtGui.QFileDialog.getOpenFileNames(parent, title, path, filters) + file_list = QtCore.QStringList() + for file in files: + if not os.path.exists(file): + file = urllib.unquote(unicode(file)) + if not os.path.exists(file): + QtGui.QMessageBox.information(self, + UiStrings().FNFT, + UiStrings().FNF % file) + continue + file_list.append(QtCore.QString(file)) + return file_list \ No newline at end of file diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 541206828..e31c3692c 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -35,7 +35,7 @@ import re from PyQt4 import QtCore, QtGui -from openlp.core.lib import SettingsManager, OpenLPToolbar, ServiceItem, \ +from openlp.core.lib import FileDialog, SettingsManager, OpenLPToolbar, ServiceItem, \ StringContent, build_icon, translate, Receiver, ListWidgetWithDnD from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import UiStrings, create_widget_action, \ @@ -337,7 +337,7 @@ class MediaManagerItem(QtGui.QWidget): """ Add a file to the list widget to make it available for showing """ - files = QtGui.QFileDialog.getOpenFileNames( + files = FileDialog().getOpenFileNames( self, self.onNewPrompt, SettingsManager.get_last_dir(self.settingsSection), self.onNewFileMasks) diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 5353d12f6..7d835998f 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -77,8 +77,12 @@ class UiStrings(object): self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') + self.FNFT = unicode(translate('OpenLP.Ui', + 'File Not Found')) + self.FNF = unicode(translate('OpenLP.Ui', + 'File %s not found.\nPlease try selecting it individually.')) self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', - 'Abbreviated font pointsize unit') + 'Abbreviated font pointsize unit')ad self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 9804b3eca..84e7cb518 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -36,7 +36,7 @@ import re from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, get_text_file_string, build_icon, \ +from openlp.core.lib import FileDialog, OpenLPToolbar, get_text_file_string, build_icon, \ Receiver, SettingsManager, translate, check_item_selected, \ check_directory_exists, create_thumb, validate_thumb, ImageSource from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, \ @@ -420,7 +420,7 @@ class ThemeManager(QtGui.QWidget): attempting to extract OpenLP themes from those files. This process will load both OpenLP version 1 and version 2 themes. """ - files = QtGui.QFileDialog.getOpenFileNames(self, + files = FileDialog().getOpenFileNames(self, translate('OpenLP.ThemeManager', 'Select Theme Import File'), SettingsManager.get_last_dir(self.settingsSection), unicode(translate('OpenLP.ThemeManager', diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index a33cd2604..031a0f1b3 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -150,7 +150,6 @@ class AppLocation(object): check_directory_exists(path) return path - def _get_os_dir_path(dir_type): """ Return a path based on which OS and environment we are running in. diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 7593e4a95..0803ee4e9 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -34,7 +34,7 @@ import shutil from PyQt4 import QtCore, QtGui -from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, \ +from openlp.core.lib import FileDialog, PluginStatus, Receiver, MediaType, translate, \ create_separated_list, check_directory_exists from openlp.core.lib.ui import UiStrings, set_case_insensitive_completer, \ critical_error_message_box, find_and_set_in_combo_box @@ -757,7 +757,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): Loads file(s) from the filesystem. """ filters = u'%s (*)' % UiStrings().AllFiles - filenames = QtGui.QFileDialog.getOpenFileNames(self, + filenames = FileDialog().getOpenFileNames(self, translate('SongsPlugin.EditSongForm', 'Open File(s)'), QtCore.QString(), filters) for filename in filenames: diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index e58137903..21e0b43fd 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -35,7 +35,7 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.lib import Receiver, SettingsManager, translate +from openlp.core.lib import FileDialog, Receiver, SettingsManager, translate from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.lib.settings import Settings from openlp.core.ui.wizard import OpenLPWizard, WizardStrings @@ -281,7 +281,7 @@ class SongImportForm(OpenLPWizard): if filters: filters += u';;' filters += u'%s (*)' % UiStrings().AllFiles - filenames = QtGui.QFileDialog.getOpenFileNames(self, title, + filenames = FileDialog().getOpenFileNames(self, title, SettingsManager.get_last_dir(self.plugin.settingsSection, 1), filters) if filenames: From 0e155daaf644463bc987225e689a6ab1f4b443c0 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 10 Aug 2013 21:40:12 +0100 Subject: [PATCH 2/7] removed __init__ as its not needed --- openlp/core/lib/filedialog.py | 3 --- openlp/core/lib/ui.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index ffc8ec96d..36efb841b 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -41,9 +41,6 @@ from openlp.core.lib.ui import UiStrings log = logging.getLogger(__name__) class FileDialog(QtGui.QFileDialog): - def __init__(self): - QtGui.QFileDialog.__init__(self) - def getOpenFileNames(self, parent, title, path, filters): files = QtGui.QFileDialog.getOpenFileNames(parent, title, path, filters) file_list = QtCore.QStringList() diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 7d835998f..65b720787 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -82,7 +82,7 @@ class UiStrings(object): self.FNF = unicode(translate('OpenLP.Ui', 'File %s not found.\nPlease try selecting it individually.')) self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', - 'Abbreviated font pointsize unit')ad + 'Abbreviated font pointsize unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') From d42364671eb576b2a4ad80b84525867b5209bda7 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sun, 11 Aug 2013 21:16:27 +0100 Subject: [PATCH 3/7] Changed to static metod --- openlp/core/lib/filedialog.py | 3 ++- openlp/core/lib/mediamanageritem.py | 2 +- openlp/core/ui/thememanager.py | 2 +- openlp/plugins/songs/forms/editsongform.py | 2 +- openlp/plugins/songs/forms/songimportform.py | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index 36efb841b..ba9f6661e 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -41,7 +41,8 @@ from openlp.core.lib.ui import UiStrings log = logging.getLogger(__name__) class FileDialog(QtGui.QFileDialog): - def getOpenFileNames(self, parent, title, path, filters): + @staticmethod + def getOpenFileNames(parent, title, path, filters): files = QtGui.QFileDialog.getOpenFileNames(parent, title, path, filters) file_list = QtCore.QStringList() for file in files: diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index e31c3692c..9fd589a12 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -337,7 +337,7 @@ class MediaManagerItem(QtGui.QWidget): """ Add a file to the list widget to make it available for showing """ - files = FileDialog().getOpenFileNames( + files = FileDialog.getOpenFileNames( self, self.onNewPrompt, SettingsManager.get_last_dir(self.settingsSection), self.onNewFileMasks) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 84e7cb518..9d53230a1 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -420,7 +420,7 @@ class ThemeManager(QtGui.QWidget): attempting to extract OpenLP themes from those files. This process will load both OpenLP version 1 and version 2 themes. """ - files = FileDialog().getOpenFileNames(self, + files = FileDialog.getOpenFileNames(self, translate('OpenLP.ThemeManager', 'Select Theme Import File'), SettingsManager.get_last_dir(self.settingsSection), unicode(translate('OpenLP.ThemeManager', diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 0803ee4e9..4774dab6b 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -757,7 +757,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): Loads file(s) from the filesystem. """ filters = u'%s (*)' % UiStrings().AllFiles - filenames = FileDialog().getOpenFileNames(self, + filenames = FileDialog.getOpenFileNames(self, translate('SongsPlugin.EditSongForm', 'Open File(s)'), QtCore.QString(), filters) for filename in filenames: diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 21e0b43fd..2db16abc5 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -281,7 +281,7 @@ class SongImportForm(OpenLPWizard): if filters: filters += u';;' filters += u'%s (*)' % UiStrings().AllFiles - filenames = FileDialog().getOpenFileNames(self, title, + filenames = FileDialog.getOpenFileNames(self, title, SettingsManager.get_last_dir(self.plugin.settingsSection, 1), filters) if filenames: From 12fb5ebd463456b6a9c1e40c9bea911c44a43bd9 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 13 Aug 2013 18:57:18 +0100 Subject: [PATCH 4/7] Need to encode filename to unicode --- openlp/core/lib/filedialog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index ba9f6661e..0c2bd1005 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -46,8 +46,9 @@ class FileDialog(QtGui.QFileDialog): files = QtGui.QFileDialog.getOpenFileNames(parent, title, path, filters) file_list = QtCore.QStringList() for file in files: + file = unicode(file) if not os.path.exists(file): - file = urllib.unquote(unicode(file)) + file = urllib.unquote(file) if not os.path.exists(file): QtGui.QMessageBox.information(self, UiStrings().FNFT, From 6a0771392d0efcfcca13d2e9da9baf29a93a4452 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Fri, 16 Aug 2013 06:20:21 +0100 Subject: [PATCH 5/7] renamed strings, remove unused logger import --- openlp/core/lib/filedialog.py | 11 ++++------- openlp/core/lib/ui.py | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index 0c2bd1005..5e0c7539b 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -28,9 +28,8 @@ ############################################################################### """ -Provide a work around for a bug in QFileDialog (#1209515) +Provide a work around for a bug in QFileDialog """ -import logging import os import urllib @@ -38,8 +37,6 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib.ui import UiStrings -log = logging.getLogger(__name__) - class FileDialog(QtGui.QFileDialog): @staticmethod def getOpenFileNames(parent, title, path, filters): @@ -50,9 +47,9 @@ class FileDialog(QtGui.QFileDialog): if not os.path.exists(file): file = urllib.unquote(file) if not os.path.exists(file): - QtGui.QMessageBox.information(self, - UiStrings().FNFT, - UiStrings().FNF % file) + QtGui.QMessageBox.information(parent, + UiStrings().FileNotFound, + UiStrings().FileNotFoundMessage % file) continue file_list.append(QtCore.QString(file)) return file_list \ No newline at end of file diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 65b720787..03403816a 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -77,9 +77,9 @@ class UiStrings(object): self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') - self.FNFT = unicode(translate('OpenLP.Ui', + self.FileNotFound = unicode(translate('OpenLP.Ui', 'File Not Found')) - self.FNF = unicode(translate('OpenLP.Ui', + self.FileNotFoundMessage = unicode(translate('OpenLP.Ui', 'File %s not found.\nPlease try selecting it individually.')) self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') From 3a551d08c05c20fa3d5d89dde795b26326c5dcdf Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 17 Aug 2013 08:51:08 +0000 Subject: [PATCH 6/7] Space reinstated as per PEP8 --- openlp/core/utils/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 031a0f1b3..a33cd2604 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -150,6 +150,7 @@ class AppLocation(object): check_directory_exists(path) return path + def _get_os_dir_path(dir_type): """ Return a path based on which OS and environment we are running in. From 647331c00cf9175ef721843d61ab6715a85f94f2 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 20 Aug 2013 19:38:50 +0000 Subject: [PATCH 7/7] added doc strings --- openlp/core/lib/filedialog.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index 5e0c7539b..d1a5bd69a 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -28,7 +28,8 @@ ############################################################################### """ -Provide a work around for a bug in QFileDialog +Provide a work around for a bug in QFileDialog + """ import os import urllib @@ -38,8 +39,15 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib.ui import UiStrings class FileDialog(QtGui.QFileDialog): + """ + Subclass QFileDialog to work round a bug + """ @staticmethod def getOpenFileNames(parent, title, path, filters): + """ + Reimplement getOpenFileNames to fix the way it returns some file + names that url encoded when selecting multiple files/ + """ files = QtGui.QFileDialog.getOpenFileNames(parent, title, path, filters) file_list = QtCore.QStringList() for file in files: