]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/recents.cpp
Qt forced default value is different than libvlc's saved
[vlc] / modules / gui / qt4 / recents.cpp
index 9109989434fa1b0955e090927b6a3ef906d70192..99fb82749607a237ad16cc7bc6b6abb8fcd8a7b5 100644 (file)
 
 
 #include "recents.hpp"
+#include "dialogs_provider.hpp"
+#include "menus.hpp"
 
-#include <QList>
-#include <QString>
+#include <QStringList>
 #include <QAction>
 #include <QSettings>
 #include <QRegExp>
 #include <QSignalMapper>
 
+#ifdef WIN32
+#include <shlobj.h>
+#endif
+
 RecentsMRL* RecentsMRL::instance = NULL;
 
 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
 {
-    stack = new QList<QString>;
-    signalMapper = new QSignalMapper(this);
-
-    isActive = config_GetInt( p_intf, "qt-recentplay" );
-    filter = new QRegExp(
-            qfu( config_GetPsz( p_intf, "qt-recentplay-filter" ) ),
-            Qt::CaseInsensitive );
+    stack = new QStringList;
+
+    signalMapper = new QSignalMapper( this );
+    CONNECT( signalMapper,
+            mapped(const QString & ),
+            DialogsProvider::getInstance( p_intf ),
+            playMRL( const QString & ) );
+
+    /* Load the filter psz */
+    char* psz_tmp = var_InheritString( p_intf, "qt-recentplay-filter" );
+    if( psz_tmp && *psz_tmp )
+        filter = new QRegExp( psz_tmp, Qt::CaseInsensitive );
+    else
+        filter = NULL;
+    free( psz_tmp );
 
     load();
-    if ( !isActive ) clear();
+    isActive = var_InheritBool( p_intf, "qt-recentplay" );
+    if( !isActive ) clear();
 }
 
 RecentsMRL::~RecentsMRL()
 {
+    delete filter;
     delete stack;
 }
 
 void RecentsMRL::addRecent( const QString &mrl )
 {
-    if ( !isActive || filter->indexIn( mrl ) >= 0 )
+    if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
         return;
 
     msg_Dbg( p_intf, "Adding a new MRL to recent ones: %s", qtu( mrl ) );
-    if( stack->contains( mrl ) )
+
+#ifdef WIN32
+    /* Add to the Windows 7 default list in taskbar */
+    SHAddToRecentDocs( 0x00000002 , qtu( mrl ) );
+#endif
+
+    int i_index = stack->indexOf( mrl );
+    if( 0 <= i_index )
     {
-        stack->removeOne( mrl );
-        stack->prepend( mrl );
+        /* move to the front */
+        stack->move( i_index, 0 );
     }
     else
     {
@@ -69,7 +91,7 @@ void RecentsMRL::addRecent( const QString &mrl )
         if( stack->size() > RECENTS_LIST_SIZE )
             stack->takeLast();
     }
-    emit updated();
+    QVLCMenu::updateRecents( p_intf );
     save();
 }
 
@@ -77,34 +99,32 @@ void RecentsMRL::clear()
 {
     if ( stack->isEmpty() )
         return;
+
     stack->clear();
-    emit updated();
+    if( isActive ) QVLCMenu::updateRecents( p_intf );
     save();
 }
 
-QList<QString> RecentsMRL::recents()
+QStringList RecentsMRL::recents()
 {
-    return QList<QString>(*stack);
+    return *stack;
 }
 
 void RecentsMRL::load()
 {
+    /* Load from the settings */
     QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
 
+    /* And filter the regexp on the list */
     for( int i = 0; i < list.size(); ++i )
     {
-        if (filter->indexIn( list.at(i) ) == -1)
+        if ( !filter || filter->indexIn( list.at(i) ) == -1 )
             stack->append( list.at(i) );
     }
 }
 
 void RecentsMRL::save()
 {
-    QStringList list;
-
-    for( int i = 0; i < stack->size(); ++i )
-        list << stack->at(i);
-
-    getSettings()->setValue( "RecentsMRL/list", list );
+    getSettings()->setValue( "RecentsMRL/list", *stack );
 }