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()
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 );
}
......
......@@ -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()
......
......@@ -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();
......@@ -634,8 +634,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 ) );
......
......@@ -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(){}
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -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 );
......
......@@ -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 */
......
......@@ -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 )
......
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