Commit 7a6f006d authored by Pierre Lamot's avatar Pierre Lamot Committed by Hugo Beauzée-Luyssen

Qt: fix "last folder used" not remembered correctly

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)

Fix #19905
Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 960c66f6
...@@ -358,22 +358,26 @@ void ExtVideo::updateFilters() ...@@ -358,22 +358,26 @@ void ExtVideo::updateFilters()
void ExtVideo::browseLogo() void ExtVideo::browseLogo()
{ {
const QStringList schemes = QStringList(QStringLiteral("file"));
QString filter = QString( "%1 (*.png *.jpg);;%2 (*)" ) QString filter = QString( "%1 (*.png *.jpg);;%2 (*)" )
.arg( qtr("Image Files") ) .arg( qtr("Image Files") )
.arg( TITLE_EXTENSIONS_ALL ); .arg( TITLE_EXTENSIONS_ALL );
QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ), QString file = QFileDialog::getOpenFileUrl( NULL, qtr( "Logo filenames" ),
p_intf->p_sys->filepath, filter ); p_intf->p_sys->filepath, filter,
NULL, QFileDialog::Options(), schemes ).toLocalFile();
UPDATE_AND_APPLY_TEXT( logoFileText, file ); UPDATE_AND_APPLY_TEXT( logoFileText, file );
} }
void ExtVideo::browseEraseFile() void ExtVideo::browseEraseFile()
{ {
const QStringList schemes = QStringList(QStringLiteral("file"));
QString filter = QString( "%1 (*.png *.jpg);;%2 (*)" ) QString filter = QString( "%1 (*.png *.jpg);;%2 (*)" )
.arg( qtr("Image Files") ) .arg( qtr("Image Files") )
.arg( TITLE_EXTENSIONS_ALL ); .arg( TITLE_EXTENSIONS_ALL );
QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ), QString file = QFileDialog::getOpenFileUrl( NULL, qtr( "Image mask" ),
p_intf->p_sys->filepath, filter ); p_intf->p_sys->filepath, filter,
NULL, QFileDialog::Options(), schemes ).toLocalFile();
UPDATE_AND_APPLY_TEXT( eraseMaskText, file ); UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
} }
......
...@@ -885,15 +885,13 @@ void CoverArtLabel::setArtFromFile() ...@@ -885,15 +885,13 @@ void CoverArtLabel::setArtFromFile()
if( !p_item ) if( !p_item )
return; 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)" ) ); p_intf->p_sys->filepath, qtr( "Image Files (*.gif *.jpg *.jpeg *.png)" ) );
if( filePath.isEmpty() ) if( fileUrl.isEmpty() )
return; return;
QString fileUrl = QUrl::fromLocalFile( filePath ).toString(); THEMIM->getIM()->setArt( p_item, fileUrl.toString() );
THEMIM->getIM()->setArt( p_item, fileUrl );
} }
void CoverArtLabel::clear() void CoverArtLabel::clear()
......
...@@ -233,7 +233,7 @@ void FileOpenPanel::browseFile() ...@@ -233,7 +233,7 @@ void FileOpenPanel::browseFile()
); );
item->setFlags( Qt::ItemIsEnabled ); item->setFlags( Qt::ItemIsEnabled );
ui.fileListWidg->addItem( item ); ui.fileListWidg->addItem( item );
savedirpathFromFile( file ); p_intf->p_sys->filepath = url;
} }
updateButtons(); updateButtons();
updateMRL(); updateMRL();
...@@ -634,8 +634,10 @@ void DiscOpenPanel::updateMRL() ...@@ -634,8 +634,10 @@ void DiscOpenPanel::updateMRL()
void DiscOpenPanel::browseDevice() void DiscOpenPanel::browseDevice()
{ {
QString dir = QFileDialog::getExistingDirectory( this, const QStringList schemes = QStringList(QStringLiteral("file"));
qtr( I_DEVICE_TOOLTIP ), p_intf->p_sys->filepath ); QString dir = QFileDialog::getExistingDirectoryUrl( this,
qtr( I_DEVICE_TOOLTIP ), p_intf->p_sys->filepath,
QFileDialog::ShowDirsOnly, schemes ).toLocalFile();
if( !dir.isEmpty() ) if( !dir.isEmpty() )
{ {
ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) ); ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) );
......
...@@ -96,8 +96,10 @@ class FileOpenBox: public QFileDialog ...@@ -96,8 +96,10 @@ class FileOpenBox: public QFileDialog
Q_OBJECT Q_OBJECT
public: public:
FileOpenBox( QWidget *parent, const QString &caption, FileOpenBox( QWidget *parent, const QString &caption,
const QString &directory, const QString &filter ): const QUrl &directory, const QString &filter ):
QFileDialog( parent, caption, directory, filter ) {} QFileDialog( parent, caption, "", filter ) {
setDirectoryUrl(directory);
}
public slots: public slots:
void accept(){} void accept(){}
void reject(){} void reject(){}
......
...@@ -169,8 +169,10 @@ QString FileDestBox::getMRL( const QString& mux ) ...@@ -169,8 +169,10 @@ QString FileDestBox::getMRL( const QString& mux )
void FileDestBox::fileBrowse() void FileDestBox::fileBrowse()
{ {
QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ), const QStringList schemes = QStringList(QStringLiteral("file"));
p_intf->p_sys->filepath, qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv *.webm)" ) ); 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 ) ); fileEdit->setText( toNativeSeparators( fileName ) );
emit mrlUpdated(); emit mrlUpdated();
} }
......
...@@ -116,12 +116,12 @@ DialogsProvider::~DialogsProvider() ...@@ -116,12 +116,12 @@ DialogsProvider::~DialogsProvider()
QStringList DialogsProvider::getOpenURL( QWidget *parent, QStringList DialogsProvider::getOpenURL( QWidget *parent,
const QString &caption, const QString &caption,
const QString &dir, const QUrl &dir,
const QString &filter, const QString &filter,
QString *selectedFilter ) QString *selectedFilter )
{ {
QStringList res; 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 ) foreach( const QUrl& url, urls )
res.append( url.toEncoded() ); res.append( url.toEncoded() );
...@@ -131,11 +131,12 @@ QStringList DialogsProvider::getOpenURL( QWidget *parent, ...@@ -131,11 +131,12 @@ QStringList DialogsProvider::getOpenURL( QWidget *parent,
QString DialogsProvider::getSaveFileName( QWidget *parent, QString DialogsProvider::getSaveFileName( QWidget *parent,
const QString &caption, const QString &caption,
const QString &dir, const QUrl &dir,
const QString &filter, const QString &filter,
QString *selectedFilter ) 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() void DialogsProvider::quit()
...@@ -404,9 +405,9 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg ) ...@@ -404,9 +405,9 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
foreach( const QString &uri, urls ) foreach( const QString &uri, urls )
p_arg->psz_results[i++] = strdup( qtu( uri ) ); p_arg->psz_results[i++] = strdup( qtu( uri ) );
if(i == 0) if(i == 0)
p_intf->p_sys->filepath = QString::fromLatin1(""); p_intf->p_sys->filepath = "";
else 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 */ /* Callback */
...@@ -473,7 +474,7 @@ void DialogsProvider::MLAppendDialog( int tab ) ...@@ -473,7 +474,7 @@ void DialogsProvider::MLAppendDialog( int tab )
***/ ***/
QStringList DialogsProvider::showSimpleOpen( const QString& help, QStringList DialogsProvider::showSimpleOpen( const QString& help,
int filters, int filters,
const QString& path ) const QUrl& path )
{ {
QString fileTypes = ""; QString fileTypes = "";
if( filters & EXT_FILTER_MEDIA ) { if( filters & EXT_FILTER_MEDIA ) {
...@@ -500,7 +501,8 @@ QStringList DialogsProvider::showSimpleOpen( const QString& help, ...@@ -500,7 +501,8 @@ QStringList DialogsProvider::showSimpleOpen( const QString& help,
path.isEmpty() ? p_intf->p_sys->filepath : path, path.isEmpty() ? p_intf->p_sys->filepath : path,
fileTypes ); fileTypes );
if( !urls.isEmpty() ) savedirpathFromFile( urls.last() ); if( !urls.isEmpty() )
p_intf->p_sys->filepath = QUrl( urls.last() );
return urls; return urls;
} }
...@@ -570,8 +572,10 @@ static void openDirectory( intf_thread_t *p_intf, bool pl, bool go ) ...@@ -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 DialogsProvider::getDirectoryDialog( intf_thread_t *p_intf )
{ {
QString dir = QFileDialog::getExistingDirectory( NULL, const QStringList schemes = QStringList(QStringLiteral("file"));
qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath ); QString dir = QFileDialog::getExistingDirectoryUrl( NULL,
qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath,
QFileDialog::ShowDirsOnly, schemes ).toLocalFile();
if( dir.isEmpty() ) return QString(); if( dir.isEmpty() ) return QString();
......
...@@ -88,17 +88,17 @@ public: ...@@ -88,17 +88,17 @@ public:
int filters = EXT_FILTER_MEDIA | int filters = EXT_FILTER_MEDIA |
EXT_FILTER_VIDEO | EXT_FILTER_AUDIO | EXT_FILTER_VIDEO | EXT_FILTER_AUDIO |
EXT_FILTER_PLAYLIST, EXT_FILTER_PLAYLIST,
const QString& path = QString() ); const QUrl& path = QUrl() );
bool isDying() { return b_isDying; } bool isDying() { return b_isDying; }
static QString getDirectoryDialog( intf_thread_t *p_intf); static QString getDirectoryDialog( intf_thread_t *p_intf);
static QStringList getOpenURL(QWidget *parent = NULL, static QStringList getOpenURL(QWidget *parent = NULL,
const QString &caption = QString(), const QString &caption = QString(),
const QString &dir = QString(), const QUrl &dir = QUrl(),
const QString &filter = QString(), const QString &filter = QString(),
QString *selectedFilter = NULL ); QString *selectedFilter = NULL );
static QString getSaveFileName( QWidget *parent = NULL, static QString getSaveFileName(QWidget *parent = NULL,
const QString &caption = QString(), const QString &caption = QString(),
const QString &dir = QString(), const QUrl &dir = QUrl(),
const QString &filter = QString(), const QString &filter = QString(),
QString *selectedFilter = NULL ); QString *selectedFilter = NULL );
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#define QT_NO_CAST_TO_ASCII #define QT_NO_CAST_TO_ASCII
#include <QString> #include <QString>
#include <QUrl>
#if ( QT_VERSION < 0x050500 ) #if ( QT_VERSION < 0x050500 )
# error Update your Qt version to at least 5.5.0 # error Update your Qt version to at least 5.5.0
...@@ -71,7 +72,7 @@ struct intf_sys_t ...@@ -71,7 +72,7 @@ struct intf_sys_t
class QSettings *mainSettings; /* Qt State settings not messing main VLC ones */ class QSettings *mainSettings; /* Qt State settings not messing main VLC ones */
class PLModel *pl_model; 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 */ unsigned voutWindowType; /* Type of vout_window_t provided */
bool b_isDialogProvider; /* Qt mode or Skins mode */ bool b_isDialogProvider; /* Qt mode or Skins mode */
......
...@@ -36,7 +36,6 @@ static inline QString removeTrailingSlash( QString s ) ...@@ -36,7 +36,6 @@ static inline QString removeTrailingSlash( QString s )
return s; return s;
} }
#define savedirpathFromFile( a ) p_intf->p_sys->filepath = toNativeSeparators( QFileInfo( a ).path() )
#define toNativeSepNoSlash( a ) toNativeSeparators( removeTrailingSlash( a ) ) #define toNativeSepNoSlash( a ) toNativeSeparators( removeTrailingSlash( a ) )
static inline QString colon_escape( QString s ) static inline QString colon_escape( QString s )
......
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