[vlc-devel] [PATCH] Qt: fix "last folder used" not remembered correctly
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Tue Mar 6 10:18:01 CET 2018
On Fri, Mar 2, 2018, at 7:11 PM, Pierre Lamot wrote:
> On windows last used folder was stored by its URL, which cannot by
> used QFileDialog::getXXXFileName.
>
> This patch will store last used folder by its URL systematically and
> use QFileDialog::getXXXURL. This allows to store non file location (ie: smb)
> ---
> modules/gui/qt/components/extended_panels.cpp | 12 ++++++++----
> modules/gui/qt/components/interface_widgets.cpp | 8 +++-----
> modules/gui/qt/components/open_panels.cpp | 8 +++++---
> modules/gui/qt/components/open_panels.hpp | 6 ++++--
> modules/gui/qt/components/sout/sout_widgets.cpp | 6 ++++--
> modules/gui/qt/dialogs_provider.cpp | 24 ++++++++++++++----------
> modules/gui/qt/dialogs_provider.hpp | 8 ++++----
> modules/gui/qt/qt.hpp | 3 ++-
> modules/gui/qt/util/qt_dirs.hpp | 1 -
> 9 files changed, 44 insertions(+), 32 deletions(-)
>
> diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/
> gui/qt/components/extended_panels.cpp
> index 2433833a0b..bdd8bf1608 100644
> --- a/modules/gui/qt/components/extended_panels.cpp
> +++ b/modules/gui/qt/components/extended_panels.cpp
> @@ -358,22 +358,26 @@ void ExtVideo::updateFilters()
>
> void ExtVideo::browseLogo()
> {
> + const QStringList schemes = QStringList(QStringLiteral("file"));
> QString filter = QString( "%1 (*.png *.jpg);;%2 (*)" )
> .arg( qtr("Image Files") )
> .arg( TITLE_EXTENSIONS_ALL );
> - QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
> - p_intf->p_sys->filepath, filter );
> + QString file = QFileDialog::getOpenFileUrl( NULL, qtr( "Logo filenames" ),
> + p_intf->p_sys->filepath, filter,
> + NULL, QFileDialog::Options(), schemes ).toLocalFile();
>
> UPDATE_AND_APPLY_TEXT( logoFileText, file );
> }
>
> void ExtVideo::browseEraseFile()
> {
> + const QStringList schemes = QStringList(QStringLiteral("file"));
> QString filter = QString( "%1 (*.png *.jpg);;%2 (*)" )
> .arg( qtr("Image Files") )
> .arg( TITLE_EXTENSIONS_ALL );
> - QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
> - p_intf->p_sys->filepath, filter );
> + QString file = QFileDialog::getOpenFileUrl( NULL, qtr( "Image mask" ),
> + p_intf->p_sys->filepath, filter,
> + NULL, QFileDialog::Options(), schemes ).toLocalFile();
>
> UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
> }
> diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/
> gui/qt/components/interface_widgets.cpp
> index 9f67e30ebe..575970c1b8 100644
> --- a/modules/gui/qt/components/interface_widgets.cpp
> +++ b/modules/gui/qt/components/interface_widgets.cpp
> @@ -885,15 +885,13 @@ void CoverArtLabel::setArtFromFile()
> if( !p_item )
> return;
>
> - QString filePath = QFileDialog::getOpenFileName( this, qtr( "Choose
> Cover Art" ),
> + QUrl fileUrl = QFileDialog::getOpenFileUrl( this, qtr( "Choose
> Cover Art" ),
> p_intf->p_sys->filepath, qtr( "Image Files (*.gif *.jpg *.jpeg
> *.png)" ) );
>
> - if( filePath.isEmpty() )
> + if( fileUrl.isEmpty() )
> return;
>
> - QString fileUrl = QUrl::fromLocalFile( filePath ).toString();
> -
> - THEMIM->getIM()->setArt( p_item, fileUrl );
> + THEMIM->getIM()->setArt( p_item, fileUrl.toString() );
> }
>
> void CoverArtLabel::clear()
> diff --git a/modules/gui/qt/components/open_panels.cpp b/modules/gui/qt/
> components/open_panels.cpp
> index ef52b8e52e..cb720dc5e4 100644
> --- a/modules/gui/qt/components/open_panels.cpp
> +++ b/modules/gui/qt/components/open_panels.cpp
> @@ -233,7 +233,7 @@ void FileOpenPanel::browseFile()
> );
> item->setFlags( Qt::ItemIsEnabled );
> ui.fileListWidg->addItem( item );
> - savedirpathFromFile( file );
> + p_intf->p_sys->filepath = url;
> }
> updateButtons();
> updateMRL();
> @@ -633,8 +633,10 @@ void DiscOpenPanel::updateMRL()
>
> void DiscOpenPanel::browseDevice()
> {
> - QString dir = QFileDialog::getExistingDirectory( this,
> - qtr( I_DEVICE_TOOLTIP ), p_intf->p_sys->filepath );
> + const QStringList schemes = QStringList(QStringLiteral("file"));
> + QString dir = QFileDialog::getExistingDirectoryUrl( this,
> + qtr( I_DEVICE_TOOLTIP ), p_intf->p_sys->filepath,
> + QFileDialog::ShowDirsOnly, schemes ).toLocalFile();
> if( !dir.isEmpty() )
> {
> ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) );
> diff --git a/modules/gui/qt/components/open_panels.hpp b/modules/gui/qt/
> components/open_panels.hpp
> index 71a983141d..48044383a5 100644
> --- a/modules/gui/qt/components/open_panels.hpp
> +++ b/modules/gui/qt/components/open_panels.hpp
> @@ -96,8 +96,10 @@ class FileOpenBox: public QFileDialog
> Q_OBJECT
> public:
> FileOpenBox( QWidget *parent, const QString &caption,
> - const QString &directory, const QString &filter ):
> - QFileDialog( parent, caption, directory, filter ) {}
> + const QUrl &directory, const QString &filter ):
> + QFileDialog( parent, caption, "", filter ) {
> + setDirectoryUrl(directory);
> + }
> public slots:
> void accept(){}
> void reject(){}
> diff --git a/modules/gui/qt/components/sout/sout_widgets.cpp b/modules/
> gui/qt/components/sout/sout_widgets.cpp
> index 19b54f55a7..8fb1b993dd 100644
> --- a/modules/gui/qt/components/sout/sout_widgets.cpp
> +++ b/modules/gui/qt/components/sout/sout_widgets.cpp
> @@ -169,8 +169,10 @@ QString FileDestBox::getMRL( const QString& mux )
>
> void FileDestBox::fileBrowse()
> {
> - QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save
> file..." ),
> - p_intf->p_sys->filepath, qtr( "Containers (*.ps *.ts *.mpg
> *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv *.webm)" ) );
> + const QStringList schemes = QStringList(QStringLiteral("file"));
> + QString fileName = QFileDialog::getSaveFileUrl( this, qtr( "Save
> file..." ),
> + p_intf->p_sys->filepath, qtr( "Containers (*.ps *.ts *.mpg
> *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv *.webm)" ),
> + nullptr, QFileDialog::Options(), schemes).toLocalFile();
> fileEdit->setText( toNativeSeparators( fileName ) );
> emit mrlUpdated();
> }
> diff --git a/modules/gui/qt/dialogs_provider.cpp b/modules/gui/qt/
> dialogs_provider.cpp
> index edf42665aa..0484af8c59 100644
> --- a/modules/gui/qt/dialogs_provider.cpp
> +++ b/modules/gui/qt/dialogs_provider.cpp
> @@ -116,12 +116,12 @@ DialogsProvider::~DialogsProvider()
>
> QStringList DialogsProvider::getOpenURL( QWidget *parent,
> const QString &caption,
> - const QString &dir,
> + const QUrl &dir,
> const QString &filter,
> QString *selectedFilter )
> {
> QStringList res;
> - QList<QUrl> urls = QFileDialog::getOpenFileUrls( parent, caption,
> QUrl::fromUserInput( dir ), filter, selectedFilter );
> + QList<QUrl> urls = QFileDialog::getOpenFileUrls( parent, caption,
> dir, filter, selectedFilter );
>
> foreach( const QUrl& url, urls )
> res.append( url.toEncoded() );
> @@ -131,11 +131,12 @@ QStringList DialogsProvider::getOpenURL( QWidget *parent,
>
> QString DialogsProvider::getSaveFileName( QWidget *parent,
> const QString &caption,
> - const QString &dir,
> + const QUrl &dir,
> const QString &filter,
> QString *selectedFilter )
> {
> - return QFileDialog::getSaveFileName( parent, caption, dir, filter,
> selectedFilter );
> + const QStringList schemes = QStringList(QStringLiteral("file"));
> + return QFileDialog::getSaveFileUrl( parent, caption, dir, filter,
> selectedFilter, QFileDialog::Options(), schemes).toLocalFile();
> }
>
> void DialogsProvider::quit()
> @@ -404,9 +405,9 @@ void
> DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
> foreach( const QString &uri, urls )
> p_arg->psz_results[i++] = strdup( qtu( uri ) );
> if(i == 0)
> - p_intf->p_sys->filepath = QString::fromLatin1("");
> + p_intf->p_sys->filepath = "";
> else
> - p_intf->p_sys->filepath = qfu( p_arg->psz_results[i-1] );
> + p_intf->p_sys->filepath = QUrl::fromEncoded(p_arg-
> >psz_results[i-1]);
> }
>
> /* Callback */
> @@ -473,7 +474,7 @@ void DialogsProvider::MLAppendDialog( int tab )
> ***/
> QStringList DialogsProvider::showSimpleOpen( const QString& help,
> int filters,
> - const QString& path )
> + const QUrl& path )
> {
> QString fileTypes = "";
> if( filters & EXT_FILTER_MEDIA ) {
> @@ -500,7 +501,8 @@ QStringList DialogsProvider::showSimpleOpen( const
> QString& help,
> path.isEmpty() ? p_intf->p_sys->filepath : path,
> fileTypes );
>
> - if( !urls.isEmpty() ) savedirpathFromFile( urls.last() );
> + if( !urls.isEmpty() )
> + p_intf->p_sys->filepath = QUrl( urls.last() );
>
> return urls;
> }
> @@ -570,8 +572,10 @@ static void openDirectory( intf_thread_t *p_intf,
> bool pl, bool go )
>
> QString DialogsProvider::getDirectoryDialog( intf_thread_t *p_intf )
> {
> - QString dir = QFileDialog::getExistingDirectory( NULL,
> - qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
> + const QStringList schemes = QStringList(QStringLiteral("file"));
> + QString dir = QFileDialog::getExistingDirectoryUrl( NULL,
> + qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath,
> + QFileDialog::ShowDirsOnly, schemes ).toLocalFile();
>
> if( dir.isEmpty() ) return QString();
>
> diff --git a/modules/gui/qt/dialogs_provider.hpp b/modules/gui/qt/
> dialogs_provider.hpp
> index 4d65c7a599..6476dbe124 100644
> --- a/modules/gui/qt/dialogs_provider.hpp
> +++ b/modules/gui/qt/dialogs_provider.hpp
> @@ -88,17 +88,17 @@ public:
> int filters = EXT_FILTER_MEDIA |
> EXT_FILTER_VIDEO | EXT_FILTER_AUDIO |
> EXT_FILTER_PLAYLIST,
> - const QString& path = QString() );
> + const QUrl& path = QUrl() );
> bool isDying() { return b_isDying; }
> static QString getDirectoryDialog( intf_thread_t *p_intf);
> static QStringList getOpenURL(QWidget *parent = NULL,
> const QString &caption = QString(),
> - const QString &dir = QString(),
> + const QUrl &dir = QUrl(),
> const QString &filter = QString(),
> QString *selectedFilter = NULL );
> - static QString getSaveFileName( QWidget *parent = NULL,
> + static QString getSaveFileName(QWidget *parent = NULL,
> const QString &caption = QString(),
> - const QString &dir = QString(),
> + const QUrl &dir = QUrl(),
> const QString &filter = QString(),
> QString *selectedFilter = NULL );
>
> diff --git a/modules/gui/qt/qt.hpp b/modules/gui/qt/qt.hpp
> index 727ca8cf6a..e59583ab71 100644
> --- a/modules/gui/qt/qt.hpp
> +++ b/modules/gui/qt/qt.hpp
> @@ -41,6 +41,7 @@
>
> #define QT_NO_CAST_TO_ASCII
> #include <QString>
> +#include <QUrl>
>
> #if ( QT_VERSION < 0x050500 )
> # error Update your Qt version to at least 5.5.0
> @@ -71,7 +72,7 @@ struct intf_sys_t
> class QSettings *mainSettings; /* Qt State settings not messing
> main VLC ones */
> class PLModel *pl_model;
>
> - QString filepath; /* Last path used in dialogs */
> + QUrl filepath; /* Last path used in dialogs */
>
> unsigned voutWindowType; /* Type of vout_window_t provided */
> bool b_isDialogProvider; /* Qt mode or Skins mode */
> diff --git a/modules/gui/qt/util/qt_dirs.hpp b/modules/gui/qt/util/qt_dirs.hpp
> index 641ed4d885..a10cc0d186 100644
> --- a/modules/gui/qt/util/qt_dirs.hpp
> +++ b/modules/gui/qt/util/qt_dirs.hpp
> @@ -36,7 +36,6 @@ static inline QString removeTrailingSlash( QString s )
> return s;
> }
>
> -#define savedirpathFromFile( a ) p_intf->p_sys->filepath =
> toNativeSeparators( QFileInfo( a ).path() )
> #define toNativeSepNoSlash( a )
> toNativeSeparators( removeTrailingSlash( a ) )
>
> static inline QString colon_escape( QString s )
> --
> 2.14.1
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
According to Qt's documentation, you don't need to bother specifying "file" scheme as it's «implicit and always enabled»
Could you also specify that is fixes #19905?
Otherwise, LGTM.
--
Hugo Beauzée-Luyssen
hugo at beauzee.fr
More information about the vlc-devel
mailing list