[vlc-devel] [PATCH] [Qt] Some fix and enhancements in the 'recently played' code.

Ludovic Fauvet etix at l0cal.com
Sun Oct 19 22:58:15 CEST 2008


 * Fix a possible crash when sender is null
 * All inputs are now handled (stream, directory, drag & drop, ...)
 * Added into the preferences with filters (regexp)
 * Code cleanup
---
 modules/gui/qt4/components/simple_preferences.cpp |   22 ++++++++++
 modules/gui/qt4/components/simple_preferences.hpp |    2 +-
 modules/gui/qt4/dialogs_provider.cpp              |   31 ++++++++++++--
 modules/gui/qt4/dialogs_provider.hpp              |    1 +
 modules/gui/qt4/main_interface.cpp                |    1 +
 modules/gui/qt4/menus.cpp                         |    4 +-
 modules/gui/qt4/recents.cpp                       |   47 ++++++++++-----------
 modules/gui/qt4/recents.hpp                       |    5 +-
 modules/gui/qt4/ui/sprefs_interface.ui            |   44 +++++++++++++++++--
 9 files changed, 120 insertions(+), 37 deletions(-)

diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp
index ca1c776..fef556a 100644
--- a/modules/gui/qt4/components/simple_preferences.cpp
+++ b/modules/gui/qt4/components/simple_preferences.cpp
@@ -38,6 +38,7 @@
 #include <QToolButton>
 #include <QButtonGroup>
 #include <QVBoxLayout>
+#include <QSettings>
 
 #include <QtAlgorithms>
 
@@ -511,6 +512,20 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
 #else
             ui.OneInterfaceBox->hide();
 #endif
+            /* RECENTLY PLAYED options */
+            CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
+                     ui.recentlyPlayedFilters, setEnabled( bool ) );
+            ui.recentlyPlayedFilters->setEnabled( false );
+            getSettings()->beginGroup( "RecentsMRL" );
+            ui.saveRecentlyPlayed->setChecked(
+                    getSettings()->value( "isActive", false).toBool() );
+            ui.recentlyPlayedFilters->setText(
+                    getSettings()->value( "filter" ).toString() );
+            getSettings()->endGroup();
+
+            optionWidgets.append( ui.saveRecentlyPlayed );
+            optionWidgets.append( ui.recentlyPlayedFilters );
+
         END_SPREFS_CAT;
 
         START_SPREFS_CAT( Subtitles, qtr("Subtitles & On Screen Display Settings") );
@@ -672,6 +687,13 @@ void SPrefsPanel::apply()
             config_PutPsz( p_intf, "intf", "skins2" );
         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
             config_PutPsz( p_intf, "intf", "qt4" );
+        
+        getSettings()->beginGroup( "RecentsMRL" );
+        getSettings()->setValue( "isActive", qobject_cast<QCheckBox *>(
+                    optionWidgets[recentlyPlayedChB])->isChecked() );
+        getSettings()->setValue( "filter", qobject_cast<QLineEdit *>(
+                    optionWidgets[recentlyPlayedFilterLE])->text() );
+        getSettings()->endGroup();
         break;
     }
 
diff --git a/modules/gui/qt4/components/simple_preferences.hpp b/modules/gui/qt4/components/simple_preferences.hpp
index e3414ab..c145dba 100644
--- a/modules/gui/qt4/components/simple_preferences.hpp
+++ b/modules/gui/qt4/components/simple_preferences.hpp
@@ -73,7 +73,7 @@ enum {
        normalizerChB,
        volLW };
 enum { dumpChB, bandwidthChB, timeshiftChB, inputLE, cachingCoB };
-enum { skinRB, qtRB };
+enum { skinRB, qtRB, recentlyPlayedChB, recentlyPlayedFilterLE };
 
 class ConfigControl;
 class QComboBox;
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index 27dcf6e..f36b053 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -37,6 +37,7 @@
 #include "menus.hpp"
 #include <vlc_intf_strings.h>
 #include "input_manager.hpp"
+#include "recents.hpp"
 
 /* The dialogs */
 #include "dialogs/playlist.hpp"
@@ -389,6 +390,8 @@ void DialogsProvider::addFromSimple( bool pl, bool go)
                          : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
                       PLAYLIST_END,
                       pl ? true : false, false );
+        RecentsMRL::getInstance( p_intf )->addRecent(
+                toNativeSeparators( file ) );
         i++;
     }
 }
@@ -420,17 +423,17 @@ static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
 
     if (!dir.isEmpty() )
     {
+        QString mrl = dir.endsWith( "VIDEO_TS", Qt::CaseInsensitive )
+            ? "dvd://" : "directory://" + toNativeSeparators( dir );
         msg_Dbg( p_intf, "Directory opening: %s", qtu( dir ) );
-        input_item_t *p_input = input_item_NewExt( THEPL, qtu(
-                dir.endsWith( "VIDEO_TS", Qt::CaseInsensitive ) ? "dvd://"
-                                                                :"directory://"
-                                          + toNativeSeparators(dir) ),
+        input_item_t *p_input = input_item_NewExt( THEPL, qtu( mrl ),
                               NULL, 0, NULL, -1 );
 
         /* FIXME: playlist_AddInput() can fail */
         playlist_AddInput( THEPL, p_input,
                        go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
                        PLAYLIST_END, pl, pl_Unlocked );
+        RecentsMRL::getInstance( p_intf )->addRecent( mrl );
         if( !go )
             input_Read( THEPL, p_input, true );
         vlc_gc_decref( p_input );
@@ -529,6 +532,7 @@ void DialogsProvider::streamingDialog( QWidget *parent, QString mrl,
         playlist_AddExt( THEPL, qtu( mrl ), "Streaming",
                          PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
                         -1, &psz_option, 1, true, pl_Unlocked );
+        RecentsMRL::getInstance( p_intf )->addRecent( mrl );
     }
 }
 
@@ -641,3 +645,22 @@ void DialogsProvider::loadSubtitlesFile()
                       qtu( qsFile ) );
     }
 }
+
+/**
+ * Play the MRL contained in the Recently played menu.
+ **/
+void DialogsProvider::playRecentItem()
+{
+    if( !sender() || !dynamic_cast<QAction*>( sender() ) )
+        return;
+
+    QAction* action = static_cast<QAction*>( sender() );
+    
+    input_item_t *p_input = input_item_New( p_intf, 
+            qtu( action->text() ), NULL );
+    playlist_AddInput( THEPL, p_input, PLAYLIST_GO,
+            PLAYLIST_END, true, pl_Unlocked );
+    vlc_gc_decref( p_input );
+
+    RecentsMRL::getInstance( p_intf )->addRecent( action->text() );
+}
diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp
index 5a1b6c0..bf8ce8e 100644
--- a/modules/gui/qt4/dialogs_provider.hpp
+++ b/modules/gui/qt4/dialogs_provider.hpp
@@ -133,6 +133,7 @@ public slots:
     void menuAction( QObject *);
     void menuUpdateAction( QObject * );
     void SDMenuAction( QString );
+    void playRecentItem();
 
     void playlistDialog();
     void bookmarksDialog();
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 95127b3..dd29bc6 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -1050,6 +1050,7 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
                           PLAYLIST_END, true, false );
             first = false;
+            RecentsMRL::getInstance( p_intf )->addRecent( s );
         }
      }
      event->acceptProposedAction();
diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index c0b0093..2bf6e38 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -1315,7 +1315,9 @@ void QVLCMenu::updateRecents( intf_thread_t *p_intf )
         {
 
             for( int i = 0; i < l.size(); ++i )
-                recentsMenu->addAction( l.at( i ), rmrl, SLOT( play() ) );
+                recentsMenu->addAction( l.at( i ),
+                        DialogsProvider::getInstance( p_intf ),
+                        SLOT( playRecentItem() ) );
             recentsMenu->addSeparator();
             recentsMenu->addAction( "Clear", rmrl, SLOT( clear() ) );
         }
diff --git a/modules/gui/qt4/recents.cpp b/modules/gui/qt4/recents.cpp
index aa0e70d..c09d2b9 100644
--- a/modules/gui/qt4/recents.cpp
+++ b/modules/gui/qt4/recents.cpp
@@ -28,15 +28,21 @@
 #include <QString>
 #include <QAction>
 #include <QSettings>
+#include <QRegExp>
 
 
 RecentsMRL* RecentsMRL::instance = NULL;
 
 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
 {
-    settings = getSettings();
     stack = new QList<QString>;
-    load();
+
+    getSettings()->beginGroup( "RecentsMRL" );
+    isActive = getSettings()->value( "isActive", false ).toBool();
+    filter = new QRegExp( getSettings()->value( "filter" ).toString(), Qt::CaseInsensitive );
+    getSettings()->endGroup();
+
+    isActive ? load() : clear();
 }
 
 RecentsMRL::~RecentsMRL()
@@ -46,6 +52,9 @@ RecentsMRL::~RecentsMRL()
 
 void RecentsMRL::addRecent( const QString &mrl )
 {
+    if ( !isActive || filter->indexIn( mrl ) >= 0 )
+        return;
+    
     if( stack->contains( mrl ) )
     {
         stack->removeOne( mrl );
@@ -63,6 +72,8 @@ void RecentsMRL::addRecent( const QString &mrl )
 
 void RecentsMRL::clear()
 {
+    if ( stack->isEmpty() )
+        return;
     stack->clear();
     emit updated();
     save();
@@ -73,31 +84,19 @@ QList<QString> RecentsMRL::recents()
     return QList<QString>(*stack);
 }
 
-void RecentsMRL::play()
-{
-    if( !dynamic_cast<QAction*>( sender() ) )
-        return;
-
-    QAction* action = static_cast<QAction*>( sender() );
-    
-    input_item_t *p_input = input_item_New( p_intf, qtu( action->text() ), NULL );
-    playlist_AddInput( THEPL, p_input, PLAYLIST_GO,
-            PLAYLIST_END, true, pl_Unlocked );
-    vlc_gc_decref( p_input );
-
-    addRecent( action->text() );
-}
-
 void RecentsMRL::load()
 {
     QStringList list;
     
-    settings->beginGroup( "RecentsMRL" );
-    list = settings->value( "list" ).toStringList();
-    settings->endGroup();
+    getSettings()->beginGroup( "RecentsMRL" );
+    list = getSettings()->value( "list" ).toStringList();
+    getSettings()->endGroup();
 
     for( int i = 0; i < list.size(); ++i )
-        stack->append( list.at(i) );
+    {
+        if (filter->indexIn( list.at(i) ) == -1)
+            stack->append( list.at(i) );
+    }
 }
 
 void RecentsMRL::save()
@@ -107,7 +106,7 @@ void RecentsMRL::save()
     for( int i = 0; i < stack->size(); ++i )
         list << stack->at(i);
 
-    settings->beginGroup( "RecentsMRL" );
-    settings->setValue( "list", list );
-    settings->endGroup();
+    getSettings()->beginGroup( "RecentsMRL" );
+    getSettings()->setValue( "list", list );
+    getSettings()->endGroup();
 }
diff --git a/modules/gui/qt4/recents.hpp b/modules/gui/qt4/recents.hpp
index 66edf38..2a60f7b 100644
--- a/modules/gui/qt4/recents.hpp
+++ b/modules/gui/qt4/recents.hpp
@@ -29,6 +29,7 @@
 #include <QObject>
 #include <QList>
 #include <QString>
+#include <QRegExp>
 
 #define RECENTS_LIST_SIZE 8
 
@@ -63,11 +64,11 @@ private:
     static RecentsMRL *instance;
     intf_thread_t* p_intf;
     QList<QString> *stack;
-    QSettings *settings;
+    bool isActive;
+    QRegExp *filter;
 
 public slots:
     void clear();
-    void play();
 };
 
 #endif
diff --git a/modules/gui/qt4/ui/sprefs_interface.ui b/modules/gui/qt4/ui/sprefs_interface.ui
index 3f92d56..8ae6255 100644
--- a/modules/gui/qt4/ui/sprefs_interface.ui
+++ b/modules/gui/qt4/ui/sprefs_interface.ui
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>629</width>
-    <height>576</height>
+    <width>654</width>
+    <height>578</height>
    </rect>
   </property>
   <property name="sizePolicy" >
@@ -276,9 +276,6 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="1" colspan="2" >
-       <widget class="QComboBox" name="artFetcher" />
-      </item>
       <item row="1" column="0" >
        <widget class="QCheckBox" name="updatesBox" >
         <property name="text" >
@@ -296,6 +293,43 @@
         </property>
        </widget>
       </item>
+      <item row="2" column="0" >
+       <widget class="QCheckBox" name="saveRecentlyPlayed" >
+        <property name="text" >
+         <string>_("Save recently played items")</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1" colspan="2" >
+       <widget class="QComboBox" name="artFetcher" />
+      </item>
+      <item row="2" column="1" colspan="2" >
+       <layout class="QHBoxLayout" name="horizontalLayout" >
+        <item>
+         <widget class="QLabel" name="label_2" >
+          <property name="text" >
+           <string>_("Filter")</string>
+          </property>
+          <property name="alignment" >
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="recentlyPlayedFilters" >
+          <property name="sizePolicy" >
+           <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="toolTip" >
+           <string>_("Separate words by | (without space)")</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
    </item>
-- 
1.5.6.4




More information about the vlc-devel mailing list