[vlc-devel] [PATCH 2/2] Fixing recents not updating with cli
Gal Vinograd
bl3nderb at aol.com
Fri Nov 22 04:37:05 CET 2013
Recents playlist is now updating with command line arguments,
and decoupled from the qt4 module
---
.../gui/qt4/components/playlist/standardpanel.cpp | 4 +-
modules/gui/qt4/dialogs/open.cpp | 2 +-
modules/gui/qt4/dialogs_provider.cpp | 23 ++---
modules/gui/qt4/main_interface.cpp | 2 +-
modules/gui/qt4/recents.cpp | 101 +++++++++------------
modules/gui/qt4/recents.hpp | 4 +
6 files changed, 59 insertions(+), 77 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index 9642722..9cabb26 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -351,7 +351,7 @@ void StandardPLPanel::popupAction( QAction *action )
action->setData( QVariant::fromValue( a ) );
if ( model->action( action, list ) )
foreach( const QString &file, a.uris )
- RecentsMRL::getInstance( p_intf )->addRecent( file );
+ RecentsMRL::getInstance( p_intf )->refresh();
break;
case VLCModelSubInterface::ACTION_ENQUEUEDIR:
@@ -372,7 +372,7 @@ void StandardPLPanel::popupAction( QAction *action )
action->setData( QVariant::fromValue( a ) );
if ( model->action( action, list ) )
foreach( const QString &file, a.uris )
- RecentsMRL::getInstance( p_intf )->addRecent( file );
+ RecentsMRL::getInstance( p_intf )->refresh();
break;
default:
diff --git a/modules/gui/qt4/dialogs/open.cpp b/modules/gui/qt4/dialogs/open.cpp
index a10dfac..65da1cd 100644
--- a/modules/gui/qt4/dialogs/open.cpp
+++ b/modules/gui/qt4/dialogs/open.cpp
@@ -405,7 +405,7 @@ void OpenDialog::enqueue( bool b_enqueue )
vlc_gc_decref( p_input_item );
/* Do not add the current MRL if playlist_AddInput fail */
- RecentsMRL::getInstance( p_intf )->addRecent( itemsMRL[i] );
+ RecentsMRL::getInstance( p_intf )->refresh();
}
}
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index cc68160..6e8d724 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -448,7 +448,7 @@ void DialogsProvider::addFromSimple( bool pl, bool go)
QString url = toURI( toNativeSeparators( file ) );
playlist_Add( THEPL, qtu( url ), NULL, PLAYLIST_APPEND | mode,
PLAYLIST_END, pl, pl_Unlocked );
- RecentsMRL::getInstance( p_intf )->addRecent( url );
+ RecentsMRL::getInstance( p_intf )->refresh();
mode = PLAYLIST_PREPARSE;
}
}
@@ -485,7 +485,7 @@ void DialogsProvider::openUrlDialog()
!oud.shouldEnqueue() ? ( PLAYLIST_APPEND | PLAYLIST_GO )
: ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
PLAYLIST_END, true, false );
- RecentsMRL::getInstance( p_intf )->addRecent( url );
+ RecentsMRL::getInstance( p_intf )->refresh();
}
/* Directory */
@@ -516,7 +516,7 @@ static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
if( unlikely(uri == NULL) )
return;
- RecentsMRL::getInstance( p_intf )->addRecent( qfu(uri) );
+ RecentsMRL::getInstance( p_intf )->refresh();
input_item_t *p_input = input_item_New( uri, NULL );
free( uri );
@@ -552,7 +552,7 @@ QString DialogsProvider::getDirectoryDialog()
dir = qfu( uri );
free( uri );
- RecentsMRL::getInstance( p_intf )->addRecent( dir );
+ RecentsMRL::getInstance( p_intf )->refresh();
return dir;
}
@@ -659,16 +659,7 @@ void DialogsProvider::savePlayingToPlaylist()
void DialogsProvider::saveRecentsToPlaylist()
{
- playlist_item_t *p_node_recents = RecentsMRL::getInstance(p_intf)->toPlaylist(0);
-
- if (p_node_recents == NULL)
- {
- msg_Warn(p_intf, "cannot create playlist from recents");
- return;
- }
-
- saveAPlaylist(THEPL, p_node_recents);
- playlist_NodeDelete(THEPL, p_node_recents, true, false);
+ saveAPlaylist( THEPL, THEPL->p_recents );
}
/****************************************************************************
@@ -738,7 +729,7 @@ void DialogsProvider::streamingDialog( QWidget *parent,
PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true, pl_Unlocked );
vlc_gc_decref( p_input );
- RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+ RecentsMRL::getInstance( p_intf )->refresh();
}
}
@@ -820,5 +811,5 @@ void DialogsProvider::playMRL( const QString &mrl )
{
playlist_Add( THEPL, qtu(mrl), NULL,
PLAYLIST_APPEND | PLAYLIST_GO , PLAYLIST_END, true, false );
- RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+ RecentsMRL::getInstance( p_intf )->refresh();
}
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index cab3433..3574d2b 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -1306,7 +1306,7 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play, bool b_playli
PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
PLAYLIST_END, b_playlist, pl_Unlocked );
first = false;
- RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+ RecentsMRL::getInstance( p_intf )->refresh();
}
}
}
diff --git a/modules/gui/qt4/recents.cpp b/modules/gui/qt4/recents.cpp
index 316b6ee..4d83fda 100755
--- a/modules/gui/qt4/recents.cpp
+++ b/modules/gui/qt4/recents.cpp
@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#include "qt4.hpp"
#include "recents.hpp"
#include "dialogs_provider.hpp"
@@ -81,49 +82,17 @@ RecentsMRL::~RecentsMRL()
delete stack;
}
-void RecentsMRL::addRecent( const QString &mrl )
+void RecentsMRL::clear()
{
- 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 ) );
- if( path )
+ if( isActive )
{
- wchar_t *wmrl = ToWide( path );
- SHAddToRecentDocs( SHARD_PATHW, wmrl );
- free( wmrl );
- free( path );
- }
-#endif
+ if ( stack->isEmpty() )
+ return;
- int i_index = stack->indexOf( mrl );
- if( 0 <= i_index )
- {
- /* move to the front */
- stack->move( i_index, 0 );
+ stack->clear();
+ save();
+ refresh();
}
- else
- {
- stack->prepend( mrl );
- if( stack->count() > RECENTS_LIST_SIZE )
- stack->takeLast();
- }
- VLCMenuBar::updateRecents( p_intf );
- save();
-}
-
-void RecentsMRL::clear()
-{
- if ( stack->isEmpty() )
- return;
-
- stack->clear();
- if( isActive ) VLCMenuBar::updateRecents( p_intf );
- save();
}
QStringList RecentsMRL::recents()
@@ -133,36 +102,54 @@ QStringList RecentsMRL::recents()
void RecentsMRL::load()
{
- /* Load from the settings */
- QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
+ stack->clear();
- /* And filter the regexp on the list */
- for( int i = 0; i < list.count(); ++i )
+ for( int i = 0; i < THEPL->p_recents->i_children; i++ )
{
- if ( !filter || filter->indexIn( list.at(i) ) == -1 )
- stack->append( list.at(i) );
+ playlist_item_t *currentItem = THEPL->p_recents->pp_children[i];
+ QString currentItemQString = qfu( currentItem->p_input->psz_uri );
+ if ( !filter || filter->indexIn( currentItemQString ) == -1 )
+ stack->append( currentItemQString );
}
+
}
-void RecentsMRL::save()
+void RecentsMRL::refresh()
{
- getSettings()->setValue( "RecentsMRL/list", *stack );
+ load();
+ VLCMenuBar::updateRecents( p_intf );
}
-playlist_item_t *RecentsMRL::toPlaylist(int length)
+void RecentsMRL::save()
{
- playlist_item_t *p_node_recent = playlist_NodeCreate(THEPL, _("Recently Played"), THEPL->p_root, PLAYLIST_END, PLAYLIST_RO_FLAG, NULL);
+ int minlength = fmin( stack->count(), THEPL->p_recents->i_children );
+ int length = fmax( stack->count(), THEPL->p_recents->i_children );
+
+ for ( int i = 0; i < length; i++ )
+ {
+ bool cmpitems = minlength > i && strcmp( qtu(stack->at(i)), THEPL->p_recents->pp_children[i]->p_input->psz_uri );
- if ( p_node_recent == NULL ) return NULL;
+ if ( !cmpitems )
+ {
+ playlist_NodeRemoveItem( THEPL, THEPL->p_recents->pp_children[i], THEPL->p_recents );
+ i--;
- if (length == 0 || stack->count() < length)
- length = stack->count();
+ if ( THEPL->p_recents->i_children < i && stack->count() >= i )
+ {
+ input_item_t *p_input;
+ playlist_item_t *p_item;
+
+ p_input = input_item_New( qtu(stack->at(i)), NULL );
+ playlist_NodeAddInput( THEPL, p_input, THEPL->p_recents, PLAYLIST_APPEND, PLAYLIST_END, false );
+
+ i++;
+ }
+
+ minlength = fmin( stack->count(), THEPL->p_recents->i_children );
+ length = fmax( stack->count(), THEPL->p_recents->i_children );
+ }
- for (int i = 0; i < length; i++)
- {
- input_item_t *p_input = input_item_New(qtu(stack->at(i)), NULL);
- playlist_NodeAddInput(THEPL, p_input, p_node_recent, PLAYLIST_APPEND, PLAYLIST_END, false);
}
- return p_node_recent;
+ playlist_RecentsDump( THEPL );
}
diff --git a/modules/gui/qt4/recents.hpp b/modules/gui/qt4/recents.hpp
index ebcf747..8bc9716 100644
--- a/modules/gui/qt4/recents.hpp
+++ b/modules/gui/qt4/recents.hpp
@@ -24,6 +24,8 @@
#ifndef QVLC_RECENTS_H_
#define QVLC_RECENTS_H_
+#include <math.h>
+
#include "qt4.hpp"
#include <QObject>
@@ -51,6 +53,8 @@ public:
}
void addRecent( const QString & );
+ void refresh();
+
QStringList recents();
playlist_item_t *toPlaylist(int length);
QSignalMapper *signalMapper;
--
1.8.3.2
More information about the vlc-devel
mailing list