]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/recents.cpp
Qt: save recents on quit()
[vlc] / modules / gui / qt4 / recents.cpp
index 3bb088fe8872159b3d5f2dbd32bfc5b333ba8793..c85fa961bcc779db5d72b98e767625bda71a480d 100755 (executable)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#include "qt4.hpp"
 #include "recents.hpp"
 #include "dialogs_provider.hpp"
 #include "menus.hpp"
+#include "util/qt_dirs.hpp"
 
 #include <QStringList>
 #include <QRegExp>
@@ -54,7 +56,7 @@ RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
     signalMapper = new QSignalMapper( this );
     CONNECT( signalMapper,
             mapped(const QString & ),
-            DialogsProvider::getInstance( p_intf ),
+            this,
             playMRL( const QString & ) );
 
     /* Load the filter psz */
@@ -72,6 +74,7 @@ RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
 
 RecentsMRL::~RecentsMRL()
 {
+    save();
     delete filter;
     delete stack;
 }
@@ -81,8 +84,6 @@ void RecentsMRL::addRecent( const QString &mrl )
     if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
         return;
 
-    msg_Dbg( p_intf, "Adding a new MRL to recent ones: %s", qtu( mrl ) );
-
 #ifdef _WIN32
     /* Add to the Windows 7 default list in taskbar */
     char* path = make_path( qtu( mrl ) );
@@ -161,3 +162,60 @@ playlist_item_t *RecentsMRL::toPlaylist(int length)
 
     return p_node_recent;
 }
+
+void RecentsMRL::playMRL( const QString &mrl )
+{
+    Open::openMRL( p_intf, mrl );
+}
+
+int Open::openMRL( intf_thread_t *p_intf,
+                    const QString &mrl,
+                    bool b_start,
+                    bool b_playlist)
+{
+    return openMRLwithOptions( p_intf, mrl, NULL, b_start, b_playlist );
+}
+
+int Open::openMRLwithOptions( intf_thread_t* p_intf,
+                     const QString &mrl,
+                     QStringList *options,
+                     bool b_start,
+                     bool b_playlist,
+                     const char *title)
+{
+    /* Options */
+    const char **ppsz_options = NULL;
+    int i_options = 0;
+
+    if( options != NULL && options->count() > 0 )
+    {
+        ppsz_options = (const char **)malloc( options->count() );
+        if( ppsz_options ) {
+            for( int j = 0; j < options->count(); j++ ) {
+                QString option = colon_unescape( options->at(j) );
+                if( !option.isEmpty() ) {
+                    ppsz_options[j] = qtu(option);
+                    i_options++;
+                }
+            }
+        }
+    }
+
+    /* Add to playlist */
+    int i_ret = playlist_AddExt( THEPL,
+                  qtu(mrl), title,
+                  PLAYLIST_APPEND | (b_start ? PLAYLIST_GO : PLAYLIST_PREPARSE),
+                  PLAYLIST_END,
+                  -1,
+                  i_options, ppsz_options, VLC_INPUT_OPTION_TRUSTED,
+                  b_playlist,
+                  pl_Unlocked );
+
+    /* Add to recent items, only if played */
+    if( i_ret == VLC_SUCCESS && b_start && b_playlist )
+        RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+
+    return i_ret;
+}
+
+