[vlc-devel] [PATCH] [Qt] Minimalist recently played menu item (see #1639)

Ludovic Fauvet etix at l0cal.com
Sun Oct 19 17:40:49 CEST 2008


---
 .../cmake/CMakeLists/qt4_CMakeLists.txt            |    3 +-
 modules/gui/qt4/Modules.am                         |    3 +
 modules/gui/qt4/dialogs/open.cpp                   |    5 +
 modules/gui/qt4/main_interface.cpp                 |   13 +++
 modules/gui/qt4/main_interface.hpp                 |    1 +
 modules/gui/qt4/menus.cpp                          |   35 ++++++-
 modules/gui/qt4/menus.hpp                          |    5 +-
 modules/gui/qt4/qt4.cpp                            |    4 +
 modules/gui/qt4/recents.cpp                        |  113 ++++++++++++++++++++
 modules/gui/qt4/recents.hpp                        |   73 +++++++++++++
 10 files changed, 251 insertions(+), 4 deletions(-)
 create mode 100644 modules/gui/qt4/recents.cpp
 create mode 100644 modules/gui/qt4/recents.hpp

diff --git a/extras/buildsystem/cmake/CMakeLists/qt4_CMakeLists.txt b/extras/buildsystem/cmake/CMakeLists/qt4_CMakeLists.txt
index dc9566f..7ba4019 100644
--- a/extras/buildsystem/cmake/CMakeLists/qt4_CMakeLists.txt
+++ b/extras/buildsystem/cmake/CMakeLists/qt4_CMakeLists.txt
@@ -1,4 +1,4 @@
-set(qt4_SOURCES qt4.cpp menus.cpp main_interface.cpp dialogs_provider.cpp input_manager.cpp dialogs/playlist.cpp dialogs/bookmarks.cpp dialogs/preferences.cpp dialogs/mediainfo.cpp dialogs/extended.cpp dialogs/messages.cpp dialogs/errors.cpp dialogs/interaction.cpp dialogs/sout.cpp dialogs/help.cpp dialogs/gototime.cpp dialogs/open.cpp dialogs/vlm.cpp dialogs/podcast_configuration.cpp components/extended_panels.cpp components/info_panels.cpp components/preferences_widgets.cpp components/complete_preferences.cpp components/simple_preferences.cpp components/open_panels.cpp components/interface_widgets.cpp components/playlist/playlist_model.cpp components/playlist/playlist_item.cpp components/playlist/standardpanel.cpp components/playlist/playlist.cpp components/playlist/selector.cpp util/input_slider.cpp util/customwidgets.cpp util/registry.cpp )
+set(qt4_SOURCES qt4.cpp menus.cpp main_interface.cpp dialogs_provider.cpp input_manager.cpp recents.cpp dialogs/playlist.cpp dialogs/bookmarks.cpp dialogs/preferences.cpp dialogs/mediainfo.cpp dialogs/extended.cpp dialogs/messages.cpp dialogs/errors.cpp dialogs/interaction.cpp dialogs/sout.cpp dialogs/help.cpp dialogs/gototime.cpp dialogs/open.cpp dialogs/vlm.cpp dialogs/podcast_configuration.cpp components/extended_panels.cpp components/info_panels.cpp components/preferences_widgets.cpp components/complete_preferences.cpp components/simple_preferences.cpp components/open_panels.cpp components/interface_widgets.cpp components/playlist/playlist_model.cpp components/playlist/playlist_item.cpp components/playlist/standardpanel.cpp components/playlist/playlist.cpp components/playlist/selector.cpp util/input_slider.cpp util/customwidgets.cpp util/registry.cpp )
 set(qt4_UIS ui/equalizer.ui ui/v4l2.ui ui/video_effects.ui ui/open_file.ui ui/open_disk.ui ui/open_net.ui ui/open_capture.ui ui/open.ui ui/podcast_configuration.ui ui/sprefs_audio.ui ui/sprefs_input.ui ui/sprefs_interface.ui ui/sprefs_subtitles.ui ui/sprefs_video.ui ui/streampanel.ui ui/sout.ui ui/vlm.ui ) 
 set(qt4_HEADERS
     components/complete_preferences.hpp
@@ -32,6 +32,7 @@ set(qt4_HEADERS
     main_interface.hpp
     menus.hpp
     qt4.hpp
+    recents.hpp
     util/customwidgets.hpp
     util/input_slider.hpp
     util/qvlcframe.hpp
diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am
index a715e40..1f43ac2 100644
--- a/modules/gui/qt4/Modules.am
+++ b/modules/gui/qt4/Modules.am
@@ -17,6 +17,7 @@ nodist_SOURCES_qt4 = \
 		menus.moc.cpp \
 		dialogs_provider.moc.cpp \
 		input_manager.moc.cpp \
+		recents.moc.cpp \
 		dialogs/playlist.moc.cpp \
 		dialogs/bookmarks.moc.cpp \
 		dialogs/mediainfo.moc.cpp \
@@ -171,6 +172,7 @@ SOURCES_qt4 = 	qt4.cpp \
 		main_interface.cpp \
 		dialogs_provider.cpp \
 		input_manager.cpp \
+		recents.cpp \
 		dialogs/playlist.cpp \
 		dialogs/bookmarks.cpp \
 		dialogs/preferences.cpp \
@@ -208,6 +210,7 @@ noinst_HEADERS = \
 	main_interface.hpp \
 	dialogs_provider.hpp \
 	input_manager.hpp \
+	recents.hpp \
 	dialogs/playlist.hpp \
 	dialogs/bookmarks.hpp \
 	dialogs/mediainfo.hpp \
diff --git a/modules/gui/qt4/dialogs/open.cpp b/modules/gui/qt4/dialogs/open.cpp
index 9e803ef..dbbbfde 100644
--- a/modules/gui/qt4/dialogs/open.cpp
+++ b/modules/gui/qt4/dialogs/open.cpp
@@ -28,6 +28,8 @@
 
 #include "dialogs/open.hpp"
 
+#include "recents.hpp"
+
 #include <QTabWidget>
 #include <QGridLayout>
 #include <QRegExp>
@@ -337,6 +339,9 @@ void OpenDialog::finish( bool b_enqueue = false )
                 PLAYLIST_APPEND | ( b_start ? PLAYLIST_GO : PLAYLIST_PREPARSE ),
                 PLAYLIST_END, b_pl ? true : false, pl_Unlocked );
             vlc_gc_decref( p_input );
+
+            /* Do not add the current MRL if playlist_AddInput fail */
+            RecentsMRL::getInstance( p_intf )->addRecent( tempMRL[i] );
         }
     }
     else
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 3ac08fc..95127b3 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -39,6 +39,7 @@
 #include "dialogs/extended.hpp"
 #include "dialogs/playlist.hpp"
 #include "menus.hpp"
+#include "recents.hpp"
 
 #include <QMenuBar>
 #include <QCloseEvent>
@@ -132,9 +133,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
      * Menu Bar and Status Bar
      **************************/
     QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
+    
     /* StatusBar Creation */
     createStatusBar();
 
+    /* Recents menu updates */
+    CONNECT( RecentsMRL::getInstance( p_intf ), updated(), this, updateRecentsMenu() ); 
 
     /********************
      * Input Manager    *
@@ -1178,3 +1182,12 @@ static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
     /* Show event */
      return VLC_SUCCESS;
 }
+
+/*****************************************************************************
+ * updateRecentsMenu: event called by RecentsMRL
+ *****************************************************************************/
+
+void MainInterface::updateRecentsMenu()
+{
+    QVLCMenu::updateRecents( p_intf );
+}
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index 8be4405..75932aa 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -176,6 +176,7 @@ private slots:
     void updateSystrayTooltipName( QString );
     void updateSystrayTooltipStatus( int );
     void showSpeedMenu( QPoint );
+    void updateRecentsMenu();
 signals:
     void askReleaseVideo( void * );
     void askVideoToResize( unsigned int, unsigned int );
diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index a2fc50d..c0b0093 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -39,6 +39,7 @@
 #include "menus.hpp"
 #include "dialogs_provider.hpp"
 #include "input_manager.hpp"
+#include "recents.hpp"
 
 #include <QMenu>
 #include <QMenuBar>
@@ -46,6 +47,7 @@
 #include <QActionGroup>
 #include <QSignalMapper>
 #include <QSystemTrayIcon>
+#include <QList>
 
 /*
   This file defines the main menus and the pop-up menu (right-click menu)
@@ -76,6 +78,8 @@ static QActionGroup *currentGroup;
  * that doesn't update the QAction checked state when QMenu is hidden */
 QAction *QVLCMenu::minimalViewAction = NULL;
 
+QMenu *QVLCMenu::recentsMenu = NULL;
+
 // Add static entries to menus
 void addDPStaticEntry( QMenu *menu,
                        const QString text,
@@ -273,7 +277,7 @@ void QVLCMenu::createMenuBar( MainInterface *mi,
        gives the QProcess::destroyed timeout issue on Cleanlooks style with
        setDesktopAware set to false */
     QMenuBar *bar = mi->menuBar();
-    BAR_ADD( FileMenu(), qtr( "&Media" ) );
+    BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
 
     BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
     BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
@@ -292,7 +296,7 @@ void QVLCMenu::createMenuBar( MainInterface *mi,
  * Media ( File ) Menu
  * Opening, streaming and quit
  **/
-QMenu *QVLCMenu::FileMenu()
+QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
 {
     QMenu *menu = new QMenu();
 
@@ -313,6 +317,9 @@ QMenu *QVLCMenu::FileMenu()
     addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
         ":/capture-card", SLOT( openCaptureDialog() ),
         "Ctrl+C" );
+    recentsMenu = new QMenu( qtr( "Recently played" ), menu );
+    updateRecents( p_intf );
+    menu->addMenu( recentsMenu );
     menu->addSeparator();
 
     addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
@@ -1290,3 +1297,27 @@ void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
     var_Set( p_object, itemData->psz_var, itemData->val );
 }
 
+void QVLCMenu::updateRecents( intf_thread_t *p_intf )
+{
+    if (recentsMenu)
+    {
+        QAction* action;
+        RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
+        QList<QString> l = rmrl->recents();
+
+        recentsMenu->clear();
+        if( !l.size() )
+        {
+            action = recentsMenu->addAction( " - Empty - " );
+            action->setEnabled( false );
+        }
+        else
+        {
+
+            for( int i = 0; i < l.size(); ++i )
+                recentsMenu->addAction( l.at( i ), rmrl, SLOT( play() ) );
+            recentsMenu->addSeparator();
+            recentsMenu->addAction( "Clear", rmrl, SLOT( clear() ) );
+        }
+    }
+}
diff --git a/modules/gui/qt4/menus.hpp b/modules/gui/qt4/menus.hpp
index 177397c..e9f9076 100644
--- a/modules/gui/qt4/menus.hpp
+++ b/modules/gui/qt4/menus.hpp
@@ -76,7 +76,7 @@ public:
     static void createMenuBar( MainInterface *mi, intf_thread_t *, bool );
 
     /* Menus */
-    static QMenu *FileMenu();
+    static QMenu *FileMenu( intf_thread_t * );
     static QMenu *SDMenu( intf_thread_t * );
     static QMenu *PlaylistMenu( intf_thread_t *, MainInterface * );
     static QMenu *ToolsMenu( intf_thread_t *, QMenu *, MainInterface *,
@@ -115,6 +115,9 @@ private:
     static void UpdateItem( intf_thread_t *, QMenu *, const char *,
                             vlc_object_t *, bool );
     static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
+    static QMenu *recentsMenu;
+public slots:
+    static void updateRecents( intf_thread_t * ); 
 };
 
 class MenuFunc : public QObject
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 26a9d2e..83a7b22 100755
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -39,6 +39,7 @@
 #include "input_manager.hpp"
 #include "main_interface.hpp"
 #include "dialogs/help.hpp" /* update */
+#include "recents.hpp"
 
 #ifdef HAVE_X11_XLIB_H
 #include <X11/Xlib.h>
@@ -486,6 +487,9 @@ static void *Init( vlc_object_t *obj )
      */
     DialogsProvider::killInstance();
 
+    /* Delete the recentsMRL object before the configuration */
+    RecentsMRL::killInstance();
+
     /* Delete the configuration. Application has to be deleted after that. */
     delete p_intf->p_sys->mainSettings;
 
diff --git a/modules/gui/qt4/recents.cpp b/modules/gui/qt4/recents.cpp
new file mode 100644
index 0000000..aa0e70d
--- /dev/null
+++ b/modules/gui/qt4/recents.cpp
@@ -0,0 +1,113 @@
+/*****************************************************************************
+ * recents.cpp : Recents MRL (menu)
+ *****************************************************************************
+ * Copyright © 2006-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Ludovic Fauvet <etix at l0cal.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+
+#include "recents.hpp"
+
+#include <QList>
+#include <QString>
+#include <QAction>
+#include <QSettings>
+
+
+RecentsMRL* RecentsMRL::instance = NULL;
+
+RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
+{
+    settings = getSettings();
+    stack = new QList<QString>;
+    load();
+}
+
+RecentsMRL::~RecentsMRL()
+{
+    delete stack;
+}
+
+void RecentsMRL::addRecent( const QString &mrl )
+{
+    if( stack->contains( mrl ) )
+    {
+        stack->removeOne( mrl );
+        stack->prepend( mrl );
+    }
+    else
+    {
+        stack->prepend( mrl );
+        if( stack->size() > RECENTS_LIST_SIZE )
+            stack->takeLast();
+    }
+    emit updated();
+    save();
+}
+
+void RecentsMRL::clear()
+{
+    stack->clear();
+    emit updated();
+    save();
+}
+
+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();
+
+    for( int i = 0; i < list.size(); ++i )
+        stack->append( list.at(i) );
+}
+
+void RecentsMRL::save()
+{
+    QStringList list;
+
+    for( int i = 0; i < stack->size(); ++i )
+        list << stack->at(i);
+
+    settings->beginGroup( "RecentsMRL" );
+    settings->setValue( "list", list );
+    settings->endGroup();
+}
diff --git a/modules/gui/qt4/recents.hpp b/modules/gui/qt4/recents.hpp
new file mode 100644
index 0000000..66edf38
--- /dev/null
+++ b/modules/gui/qt4/recents.hpp
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * recents.cpp : Recents MRL (menu)
+ *****************************************************************************
+ * Copyright © 2006-2008 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Ludovic Fauvet <etix at l0cal.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef _RECENTS_H_
+#define _RECENTS_H_
+
+#include "qt4.hpp"
+
+#include <QObject>
+#include <QList>
+#include <QString>
+
+#define RECENTS_LIST_SIZE 8
+
+class RecentsMRL : public QObject
+{
+    Q_OBJECT
+
+signals:
+    void updated();
+
+public:
+    static RecentsMRL* getInstance( intf_thread_t* p_intf )
+    {
+        if(!instance)
+            instance = new RecentsMRL( p_intf );
+        return instance;
+    }
+    static void killInstance()
+    {
+        if( instance ) delete instance;
+        instance = NULL;
+    }
+    virtual ~RecentsMRL();
+
+    void addRecent( const QString & );
+    QList<QString> recents(); 
+
+private:
+    RecentsMRL( intf_thread_t* _p_intf );
+    void load();
+    void save();
+    static RecentsMRL *instance;
+    intf_thread_t* p_intf;
+    QList<QString> *stack;
+    QSettings *settings;
+
+public slots:
+    void clear();
+    void play();
+};
+
+#endif
-- 
1.5.6.4




More information about the vlc-devel mailing list