openlp/openlp/core/lib/filedialog.py

67 lines
3.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2014-06-09 08:59:52 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2013-12-24 08:56:50 +00:00
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 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 #
###############################################################################
"""
2013-08-22 05:33:19 +00:00
Provide a work around for a bug in QFileDialog <https://bugs.launchpad.net/openlp/+bug/1209515>
"""
import logging
import os
2013-09-15 19:27:40 +00:00
from urllib import parse
from PyQt4 import QtGui
2013-11-16 21:04:16 +00:00
from openlp.core.common import UiStrings
log = logging.getLogger(__name__)
2013-12-24 08:56:50 +00:00
class FileDialog(QtGui.QFileDialog):
"""
2013-08-22 05:33:19 +00:00
Subclass QFileDialog to work round a bug
"""
@staticmethod
def getOpenFileNames(parent, *args, **kwargs):
"""
Reimplement getOpenFileNames to fix the way it returns some file names that url encoded when selecting multiple
files
"""
files = QtGui.QFileDialog.getOpenFileNames(parent, *args, **kwargs)
file_list = []
for file in files:
if not os.path.exists(file):
2013-12-24 08:56:50 +00:00
log.info('File not found. Attempting to unquote.')
2013-09-15 19:27:40 +00:00
file = parse.unquote(file)
if not os.path.exists(file):
2013-09-15 19:27:40 +00:00
log.error('File %s not found.' % file)
2013-08-22 05:33:19 +00:00
QtGui.QMessageBox.information(parent, UiStrings().FileNotFound,
2013-12-24 08:56:50 +00:00
UiStrings().FileNotFoundMessage % file)
continue
file_list.append(file)
2014-03-20 19:10:31 +00:00
return file_list