Commit 4c856458 authored by Frank Praznik's avatar Frank Praznik Committed by Jean-Baptiste Kempf

Use QT file browser functions which return URLs when possible.

The getOpenFileNames() and getSaveFileName() methods of QFileDialog only work
on local paths and return a blank string if the dialog is used to select a
remote file (e.g., on a Samba share).  As of Qt 5.2 the QFileDialog class
provides the methods getOpenFileUrls() and getSaveFileUrl() that return QUrl
objects which can contain URLs to remote paths.  Use these methods when an
appropriate version of the Qt libraries are available so that the paths to
remote files are returned correctly when selected via the various file
selection dialogs.
Signed-off-by: default avatarFrank Praznik <frank.praznik@gmail.com>
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 5bf3ee01
......@@ -220,7 +220,7 @@ void FileOpenPanel::dropEvent( QDropEvent *event )
void FileOpenPanel::browseFile()
{
QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath) ;
QStringList files = DialogsProvider::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath );
foreach( const QString &file, files )
{
QListWidgetItem *item =
......@@ -273,9 +273,15 @@ void FileOpenPanel::updateMRL()
}
else
{
#if HAS_QT52
QList<QUrl> urls = dialogBox->selectedUrls();
foreach( const QUrl &url, urls )
fileList.append( url.toEncoded() );
#else
fileList = dialogBox->selectedFiles();
for( int i = 0; i < fileList.count(); i++ )
fileList[i] = toURI( fileList[i] );
#endif
}
/* Options */
......
......@@ -110,6 +110,40 @@ DialogsProvider::~DialogsProvider()
delete miscPopupMenu;
}
QStringList DialogsProvider::getOpenFileNames( QWidget *parent,
const QString &caption,
const QString &dir,
const QString &filter,
QString *selectedFilter )
{
QStringList files;
#if HAS_QT52
QList<QUrl> urls = QFileDialog::getOpenFileUrls( parent, caption, QUrl::fromUserInput( dir ), filter, selectedFilter );
foreach( const QUrl url, urls )
files.append( url.toEncoded() );
#else
files = QFileDialog::getOpenFileNames( parent, caption, dir, filter, selectedFilter );
#endif
return files;
}
QString DialogsProvider::getSaveFileName( QWidget *parent,
const QString &caption,
const QString &dir,
const QString &filter,
QString *selectedFilter )
{
#if HAS_QT52
QUrl url = QFileDialog::getSaveFileUrl( parent, caption, QUrl::fromUserInput( dir ), filter, selectedFilter );
return QString( url.toEncoded() );
#else
return QFileDialog::getSaveFileName( parent, caption, dir, filter, selectedFilter );
#endif
}
void DialogsProvider::quit()
{
b_isDying = true;
......@@ -349,7 +383,7 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
/* Save */
if( p_arg->b_save )
{
QString file = QFileDialog::getSaveFileName( NULL,
QString file = getSaveFileName( NULL,
qfu( p_arg->psz_title ),
p_intf->p_sys->filepath, extensions );
if( !file.isEmpty() )
......@@ -363,7 +397,7 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
}
else /* non-save mode */
{
QStringList files = QFileDialog::getOpenFileNames( NULL,
QStringList files = getOpenFileNames( NULL,
qfu( p_arg->psz_title ), p_intf->p_sys->filepath,
extensions );
p_arg->i_results = files.count();
......@@ -462,7 +496,7 @@ QStringList DialogsProvider::showSimpleOpen( const QString& help,
ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
fileTypes.replace( ";*", " *");
QStringList files = QFileDialog::getOpenFileNames( NULL,
QStringList files = getOpenFileNames( NULL,
help.isEmpty() ? qtr(I_OP_SEL_FILES ) : help,
path.isEmpty() ? p_intf->p_sys->filepath : path,
fileTypes );
......@@ -616,7 +650,7 @@ void DialogsProvider::saveAPlaylist(playlist_t *p_playlist, playlist_item_t *p_n
}
QString selected;
QString file = QFileDialog::getSaveFileName( NULL,
QString file = getSaveFileName( NULL,
qtr( "Save playlist as..." ),
p_intf->p_sys->filepath, filters.join( ";;" ),
&selected );
......
......@@ -91,6 +91,16 @@ public:
const QString& path = QString() );
bool isDying() { return b_isDying; }
static QString getDirectoryDialog( intf_thread_t *p_intf);
static QStringList getOpenFileNames( QWidget *parent = Q_NULLPTR,
const QString &caption = QString(),
const QString &dir = QString(),
const QString &filter = QString(),
QString *selectedFilter = Q_NULLPTR );
static QString getSaveFileName( QWidget *parent = Q_NULLPTR,
const QString &caption = QString(),
const QString &dir = QString(),
const QString &filter = QString(),
QString *selectedFilter = Q_NULLPTR );
protected:
QSignalMapper *menusMapper;
......
......@@ -47,6 +47,7 @@
#endif
#define HAS_QT5 ( QT_VERSION >= 0x050000 )
#define HAS_QT52 ( QT_VERSION >= 0x050200 )
#define HAS_QT56 ( QT_VERSION >= 0x050600 )
/* Q_DECL_OVERRIDE is a Qt5 feature, add empty define to not break with Qt4 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment