Merge lp:~phill-ridout/openlp/1209515_2.0 into lp:openlp/2.0

Proposed by Phill
Status: Merged
Approved by: Raoul Snyman
Approved revision: 2158
Merged at revision: 2163
Proposed branch: lp:~phill-ridout/openlp/1209515_2.0
Merge into: lp:openlp/2.0
Diff against target: 183 lines (+76/-8)
7 files modified
openlp/core/lib/__init__.py (+1/-0)
openlp/core/lib/filedialog.py (+63/-0)
openlp/core/lib/mediamanageritem.py (+2/-2)
openlp/core/lib/ui.py (+4/-0)
openlp/core/ui/thememanager.py (+2/-2)
openlp/plugins/songs/forms/editsongform.py (+2/-2)
openlp/plugins/songs/forms/songimportform.py (+2/-2)
To merge this branch: bzr merge lp:~phill-ridout/openlp/1209515_2.0
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Andreas Preikschat Pending
Phill Pending
Review via email: mp+181144@code.launchpad.net

This proposal supersedes a proposal from 2013-08-17.

Description of the change

Fixes #1209515 by subclassing QFileDialog and attempting to urldecode any files not found

To post a comment you must log in.
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal

No need to add a constructor.

Make the getOpenFileNames method static

review: Needs Fixing
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal

113 + 'Abbreviated font pointsize unit')ad

review: Needs Fixing
Revision history for this message
Phill (phill-ridout) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

Andreas,
How do I make it static?

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

Its asking me to review, presumably because I set it to need fixing before!

review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

47 +Provide a work around for a bug in QFileDialog (#1209515)

Can you just be specific and say this is for a Launchpad bug (I might think it is a PyQt4 bug).

63 + file_list = QtCore.QStringList()
73 + file_list.append(QtCore.QString(file))

Why? This is Python, use Python objects.

106 + self.FNFT = unicode(translate('OpenLP.Ui',
108 + self.FNF = unicode(translate('OpenLP.Ui',

What does FNFT and FNF mean? I would prefer self.FileNotFound and self.FileNotFoundMessage

109 + 'File %s not found.\nPlease try selecting it individually.'))

This is horrible. Is there truly no way we can fix this problem?

review: Needs Fixing
Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

> 63      + file_list = QtCore.QStringList()
> 73      + file_list.append(QtCore.QString(file))
>
> Why? This is Python, use Python objects.
As I was reimplementing and creating a "slot in" method I wanted to keep the same return type. But if you'd rather I'd use python objects I can. Also should I change the method name from camel case?

Note in the trunk version I have used python objects as we use PyQt API v2 (which automatically casts to python objects)

>
> 106     + self.FNFT = unicode(translate('OpenLP.Ui',
> 108     + self.FNF = unicode(translate('OpenLP.Ui',
>
> What does FNFT and FNF mean? I would prefer self.FileNotFound and self.FileNotFoundMessage

Sure, I was just following convention of the other variables.

> 109     + 'File %s not found.\nPlease try selecting it individually.'))
>
> This is horrible. Is there truly no way we can fix this problem?

Agreed, I included this as a belt and braces approach. I have tested this code with around 2000 files and have not seen this dialogue. I just added it because o wasn't 100% sure we might not have other encoding issues.

The bug is in Qt, select a single file and its fine, but select multiple files and it seems to URL encode the names. I don't see any other way round this!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

OK, this is fine. Just change the names of the strings please.

Revision history for this message
Phill (phill-ridout) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

Line 140 should be in there. PEP8 says that there should be 2 blank lines between statements on the module level.

Oh, and even if it says you need to review yourself, please don't.

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal

No comments/doc strings. Why this class? Why this method? Please explain it!

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/lib/__init__.py'
2--- openlp/core/lib/__init__.py 2013-01-20 18:46:41 +0000
3+++ openlp/core/lib/__init__.py 2013-08-20 19:40:44 +0000
4@@ -384,6 +384,7 @@
5
6
7 from eventreceiver import Receiver
8+from filedialog import FileDialog
9 from listwidgetwithdnd import ListWidgetWithDnD
10 from formattingtags import FormattingTags
11 from spelltextedit import SpellTextEdit
12
13=== added file 'openlp/core/lib/filedialog.py'
14--- openlp/core/lib/filedialog.py 1970-01-01 00:00:00 +0000
15+++ openlp/core/lib/filedialog.py 2013-08-20 19:40:44 +0000
16@@ -0,0 +1,63 @@
17+# -*- coding: utf-8 -*-
18+# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
19+
20+###############################################################################
21+# OpenLP - Open Source Lyrics Projection #
22+# --------------------------------------------------------------------------- #
23+# Copyright (c) 2008-2013 Raoul Snyman #
24+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
25+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
26+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
27+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
28+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
29+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
30+# Frode Woldsund, Martin Zibricky #
31+# --------------------------------------------------------------------------- #
32+# This program is free software; you can redistribute it and/or modify it #
33+# under the terms of the GNU General Public License as published by the Free #
34+# Software Foundation; version 2 of the License. #
35+# #
36+# This program is distributed in the hope that it will be useful, but WITHOUT #
37+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
38+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
39+# more details. #
40+# #
41+# You should have received a copy of the GNU General Public License along #
42+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
43+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
44+###############################################################################
45+
46+"""
47+Provide a work around for a bug in QFileDialog
48+<https://bugs.launchpad.net/openlp/+bug/1209515>
49+"""
50+import os
51+import urllib
52+
53+from PyQt4 import QtCore, QtGui
54+
55+from openlp.core.lib.ui import UiStrings
56+
57+class FileDialog(QtGui.QFileDialog):
58+ """
59+ Subclass QFileDialog to work round a bug
60+ """
61+ @staticmethod
62+ def getOpenFileNames(parent, title, path, filters):
63+ """
64+ Reimplement getOpenFileNames to fix the way it returns some file
65+ names that url encoded when selecting multiple files/
66+ """
67+ files = QtGui.QFileDialog.getOpenFileNames(parent, title, path, filters)
68+ file_list = QtCore.QStringList()
69+ for file in files:
70+ file = unicode(file)
71+ if not os.path.exists(file):
72+ file = urllib.unquote(file)
73+ if not os.path.exists(file):
74+ QtGui.QMessageBox.information(parent,
75+ UiStrings().FileNotFound,
76+ UiStrings().FileNotFoundMessage % file)
77+ continue
78+ file_list.append(QtCore.QString(file))
79+ return file_list
80\ No newline at end of file
81
82=== modified file 'openlp/core/lib/mediamanageritem.py'
83--- openlp/core/lib/mediamanageritem.py 2013-01-05 11:31:02 +0000
84+++ openlp/core/lib/mediamanageritem.py 2013-08-20 19:40:44 +0000
85@@ -35,7 +35,7 @@
86
87 from PyQt4 import QtCore, QtGui
88
89-from openlp.core.lib import SettingsManager, OpenLPToolbar, ServiceItem, \
90+from openlp.core.lib import FileDialog, SettingsManager, OpenLPToolbar, ServiceItem, \
91 StringContent, build_icon, translate, Receiver, ListWidgetWithDnD
92 from openlp.core.lib.searchedit import SearchEdit
93 from openlp.core.lib.ui import UiStrings, create_widget_action, \
94@@ -337,7 +337,7 @@
95 """
96 Add a file to the list widget to make it available for showing
97 """
98- files = QtGui.QFileDialog.getOpenFileNames(
99+ files = FileDialog.getOpenFileNames(
100 self, self.onNewPrompt,
101 SettingsManager.get_last_dir(self.settingsSection),
102 self.onNewFileMasks)
103
104=== modified file 'openlp/core/lib/ui.py'
105--- openlp/core/lib/ui.py 2012-12-30 19:41:24 +0000
106+++ openlp/core/lib/ui.py 2013-08-20 19:40:44 +0000
107@@ -77,6 +77,10 @@
108 self.Error = translate('OpenLP.Ui', 'Error')
109 self.Export = translate('OpenLP.Ui', 'Export')
110 self.File = translate('OpenLP.Ui', 'File')
111+ self.FileNotFound = unicode(translate('OpenLP.Ui',
112+ 'File Not Found'))
113+ self.FileNotFoundMessage = unicode(translate('OpenLP.Ui',
114+ 'File %s not found.\nPlease try selecting it individually.'))
115 self.FontSizePtUnit = translate('OpenLP.Ui', 'pt',
116 'Abbreviated font pointsize unit')
117 self.Help = translate('OpenLP.Ui', 'Help')
118
119=== modified file 'openlp/core/ui/thememanager.py'
120--- openlp/core/ui/thememanager.py 2012-12-30 19:41:24 +0000
121+++ openlp/core/ui/thememanager.py 2013-08-20 19:40:44 +0000
122@@ -36,7 +36,7 @@
123 from xml.etree.ElementTree import ElementTree, XML
124 from PyQt4 import QtCore, QtGui
125
126-from openlp.core.lib import OpenLPToolbar, get_text_file_string, build_icon, \
127+from openlp.core.lib import FileDialog, OpenLPToolbar, get_text_file_string, build_icon, \
128 Receiver, SettingsManager, translate, check_item_selected, \
129 check_directory_exists, create_thumb, validate_thumb, ImageSource
130 from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, \
131@@ -420,7 +420,7 @@
132 attempting to extract OpenLP themes from those files. This process
133 will load both OpenLP version 1 and version 2 themes.
134 """
135- files = QtGui.QFileDialog.getOpenFileNames(self,
136+ files = FileDialog.getOpenFileNames(self,
137 translate('OpenLP.ThemeManager', 'Select Theme Import File'),
138 SettingsManager.get_last_dir(self.settingsSection),
139 unicode(translate('OpenLP.ThemeManager',
140
141=== modified file 'openlp/plugins/songs/forms/editsongform.py'
142--- openlp/plugins/songs/forms/editsongform.py 2013-06-16 17:19:32 +0000
143+++ openlp/plugins/songs/forms/editsongform.py 2013-08-20 19:40:44 +0000
144@@ -34,7 +34,7 @@
145
146 from PyQt4 import QtCore, QtGui
147
148-from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, \
149+from openlp.core.lib import FileDialog, PluginStatus, Receiver, MediaType, translate, \
150 create_separated_list, check_directory_exists
151 from openlp.core.lib.ui import UiStrings, set_case_insensitive_completer, \
152 critical_error_message_box, find_and_set_in_combo_box
153@@ -757,7 +757,7 @@
154 Loads file(s) from the filesystem.
155 """
156 filters = u'%s (*)' % UiStrings().AllFiles
157- filenames = QtGui.QFileDialog.getOpenFileNames(self,
158+ filenames = FileDialog.getOpenFileNames(self,
159 translate('SongsPlugin.EditSongForm', 'Open File(s)'),
160 QtCore.QString(), filters)
161 for filename in filenames:
162
163=== modified file 'openlp/plugins/songs/forms/songimportform.py'
164--- openlp/plugins/songs/forms/songimportform.py 2012-12-30 19:41:24 +0000
165+++ openlp/plugins/songs/forms/songimportform.py 2013-08-20 19:40:44 +0000
166@@ -35,7 +35,7 @@
167
168 from PyQt4 import QtCore, QtGui
169
170-from openlp.core.lib import Receiver, SettingsManager, translate
171+from openlp.core.lib import FileDialog, Receiver, SettingsManager, translate
172 from openlp.core.lib.ui import UiStrings, critical_error_message_box
173 from openlp.core.lib.settings import Settings
174 from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
175@@ -281,7 +281,7 @@
176 if filters:
177 filters += u';;'
178 filters += u'%s (*)' % UiStrings().AllFiles
179- filenames = QtGui.QFileDialog.getOpenFileNames(self, title,
180+ filenames = FileDialog.getOpenFileNames(self, title,
181 SettingsManager.get_last_dir(self.plugin.settingsSection, 1),
182 filters)
183 if filenames:

Subscribers

People subscribed via source and target branches