From a7838c2b6220b9171ecb5926622c7730761c51dd Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Kempf <jb@videolan.org>
Date: Mon, 21 Jan 2008 20:50:43 +0000
Subject: [PATCH] Qt4 - unification of the common used path for QFileDialogs...

---
 modules/gui/qt4/components/open_panels.cpp | 21 +++++----------------
 modules/gui/qt4/dialogs_provider.cpp       |  4 ++--
 modules/gui/qt4/qt4.cpp                    |  8 ++++++++
 modules/gui/qt4/qt4.hpp                    |  2 +-
 4 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/modules/gui/qt4/components/open_panels.cpp b/modules/gui/qt4/components/open_panels.cpp
index dfca117d57..ae42c7d0b9 100644
--- a/modules/gui/qt4/components/open_panels.cpp
+++ b/modules/gui/qt4/components/open_panels.cpp
@@ -65,14 +65,9 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     ADD_FILTER_ALL( fileTypes );
     fileTypes.replace( QString(";*"), QString(" *"));
 
-    /* retrieve last known path used in file browsing */
-    char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
-
     // Make this QFileDialog a child of tempWidget from the ui.
     dialogBox = new FileOpenBox( ui.tempWidget, NULL,
-            qfu( EMPTY_STR( psz_filepath ) ?
-                 psz_filepath : p_intf->p_libvlc->psz_homedir ), fileTypes );
-    delete psz_filepath;
+            qfu( p_intf->p_sys->psz_filepath ), fileTypes );
 
     dialogBox->setFileMode( QFileDialog::ExistingFiles );
     dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
@@ -138,7 +133,9 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
 }
 
-FileOpenPanel::~FileOpenPanel(){}
+FileOpenPanel::~FileOpenPanel()
+{
+}
 
 /* Show a fileBrowser to select a subtitle */
 void FileOpenPanel::browseFileSub()
@@ -178,15 +175,7 @@ void FileOpenPanel::updateMRL()
 void FileOpenPanel::accept()
 {
     //TODO set the completer
-    const char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
-    if( ( NULL == psz_filepath )
-      || strcmp( psz_filepath, qtu( dialogBox->directory().absolutePath() )) )
-    {
-        /* set dialog box current directory as last known path */
-        config_PutPsz( p_intf, "qt-filedialog-path",
-                       qtu( dialogBox->directory().absolutePath() ) );
-    }
-    delete psz_filepath;
+    p_intf->p_sys->psz_filepath = qtu( dialogBox->directory().absolutePath() );
 }
 
 void FileOpenBox::accept()
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index aaecaba67a..5de8158792 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -284,7 +284,7 @@ QStringList DialogsProvider::showSimpleOpen( QString help,
     fileTypes.replace(QString(";*"), QString(" *"));
     return QFileDialog::getOpenFileNames( NULL,
         help.isNull() ? qfu(I_OP_SEL_FILES ) : help,
-        path.isNull() ? qfu( p_intf->p_libvlc->psz_homedir ) : path,
+        path.isNull() ? qfu( p_intf->p_sys->psz_filepath ) : path,
         fileTypes );
 }
 
@@ -373,7 +373,7 @@ void DialogsProvider::saveAPlaylist()
 {
     QFileDialog *qfd = new QFileDialog( NULL,
                                    qtr( "Choose a filename to save playlist" ),
-                                   qfu( p_intf->p_libvlc->psz_homedir ),
+                                   qfu( p_intf->p_sys->psz_filepath ),
                                    qtr( "XSPF playlist (*.xspf);; " ) +
                                    qtr( "M3U playlist (*.m3u);; Any (*.*) " ) );
     qfd->setFileMode( QFileDialog::AnyFile );
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 2ad0d0e8c4..d647ba15be 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -331,6 +331,12 @@ static void Init( intf_thread_t *p_intf )
     /* Last settings */
     app->setQuitOnLastWindowClosed( false );
 
+    /*        retrieve last known path used in file browsing */
+    char *psz_path = config_GetPsz( p_intf, "qt-filedialog-path" );
+    p_intf->p_sys->psz_filepath = EMPTY_STR( psz_path ) ? psz_path
+                           : p_intf->p_libvlc->psz_homedir;
+    delete psz_path;
+
     /* Launch */
     app->exec();
 
@@ -347,6 +353,8 @@ static void Init( intf_thread_t *p_intf )
     /* Destroy the MainInputManager */
     MainInputManager::killInstance();
 
+    delete p_intf->p_sys->psz_filepath;
+
     delete app;
 }
 
diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp
index 7670514801..5f0f7123da 100644
--- a/modules/gui/qt4/qt4.hpp
+++ b/modules/gui/qt4/qt4.hpp
@@ -51,8 +51,8 @@ struct intf_sys_t
     msg_subscription_t *p_sub; ///< Subscription to the message bank
 
     VideoWidget *p_video;
-    int i_saved_height, i_saved_width;
 
+    char *psz_filepath;
     QMenu * p_popup_menu;
 };
 
-- 
2.25.4