]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/recents.cpp
Fix a little bug in recents media menu.
[vlc] / modules / gui / qt4 / recents.cpp
index 9109989434fa1b0955e090927b6a3ef906d70192..82a20e137cb78b74a9a339af9438130f44765403 100644 (file)
@@ -23,6 +23,8 @@
 
 
 #include "recents.hpp"
+#include "dialogs_provider.hpp"
+#include "menus.hpp"
 
 #include <QList>
 #include <QString>
@@ -37,31 +39,40 @@ RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
 {
     stack = new QList<QString>;
     signalMapper = new QSignalMapper(this);
+    CONNECT( signalMapper,
+            mapped(const QString & ),
+            DialogsProvider::getInstance( p_intf ),
+            playMRL( const QString & ) );
 
     isActive = config_GetInt( p_intf, "qt-recentplay" );
-    filter = new QRegExp(
-            qfu( config_GetPsz( p_intf, "qt-recentplay-filter" ) ),
-            Qt::CaseInsensitive );
+    char* psz_tmp = config_GetPsz( 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();
+    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 ) )
+    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 +80,7 @@ void RecentsMRL::addRecent( const QString &mrl )
         if( stack->size() > RECENTS_LIST_SIZE )
             stack->takeLast();
     }
-    emit updated();
+    QVLCMenu::updateRecents( p_intf );
     save();
 }
 
@@ -78,7 +89,7 @@ void RecentsMRL::clear()
     if ( stack->isEmpty() )
         return;
     stack->clear();
-    emit updated();
+    if( isActive ) QVLCMenu::updateRecents( p_intf );
     save();
 }
 
@@ -93,7 +104,7 @@ void RecentsMRL::load()
 
     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) );
     }
 }