[vlc-devel] [PATCH] Fixing recents not updating with cli
Gal Vinograd
bl3nderb at aol.com
Tue Nov 19 19:56:24 CET 2013
Recents playlist is now updating with command line arguments,
and decoupled from the qt4 module
---
include/vlc_playlist.h | 12 +++
.../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 +
src/libvlccore.sym | 2 +
src/playlist/engine.c | 13 +++
src/playlist/item.c | 6 ++
src/playlist/loadsave.c | 37 ++++----
src/playlist/playlist_internal.h | 4 -
src/playlist/tree.c | 28 ++++++
13 files changed, 140 insertions(+), 98 deletions(-)
diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index 10108cb..2455a44 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -173,6 +173,7 @@ struct playlist_t
playlist_item_t * p_root;
playlist_item_t * p_playing;
playlist_item_t * p_media_library;
+ playlist_item_t * p_recents;
//Phony ones, point to those above;
playlist_item_t * p_root_category; /**< Root of category tree */
@@ -262,6 +263,12 @@ VLC_API playlist_t * pl_Get( vlc_object_t * );
#define playlist_Prev(p) playlist_Control(p,PLAYLIST_SKIP, pl_Unlocked, -1)
#define playlist_Skip(p,i) playlist_Control(p,PLAYLIST_SKIP, pl_Unlocked, (i) )
+#define playlist_MLDump(p) playlist_PlaylistDump( p, p->p_media_library, "ml.xspf", _("Media Library") )
+#define playlist_RecentsDump(p) playlist_PlaylistDump( p, p->p_recents, "recents.xspf", _("Recents") )
+
+#define playlist_MLLoad(p) playlist_PlaylistLoad( p, p->p_media_library, "ml.xspf", _("Media Library") )
+#define playlist_RecentsLoad(p) playlist_PlaylistLoad( p, p->p_recents, "recents.xspf", _("Recents") )
+
VLC_API void playlist_Lock( playlist_t * );
VLC_API void playlist_Unlock( playlist_t * );
VLC_API void playlist_AssertLocked( playlist_t * );
@@ -321,6 +328,10 @@ VLC_API int playlist_Export( playlist_t *p_playlist, const char *psz_name, playl
*/
VLC_API int playlist_Import( playlist_t *p_playlist, const char *psz_file );
+VLC_API int playlist_PlaylistDump( playlist_t *p_playlist, playlist_item_t *p_node, char *psz_filename, char *psz_name );
+VLC_API int playlist_PlaylistLoad( playlist_t *p_playlist, playlist_item_t *p_node, char *psz_filename, char *psz_name );
+
+
/********************** Services discovery ***********************/
/** Add a list of comma-separated service discovery modules */
@@ -347,6 +358,7 @@ VLC_API int playlist_AddExt( playlist_t *, const char *, const char *, int, int,
VLC_API int playlist_AddInput( playlist_t *, input_item_t *, int, int, bool, bool );
VLC_API playlist_item_t * playlist_NodeAddInput( playlist_t *, input_item_t *, playlist_item_t *, int, int, bool );
VLC_API int playlist_NodeAddCopy( playlist_t *, playlist_item_t *, playlist_item_t *, int );
+VLC_API int playlist_NodeAppendOrMove( playlist_t *p_playlist, playlist_item_t *p_item, playlist_item_t *p_parent );
/********************************** Item search *************************/
VLC_API playlist_item_t * playlist_ItemGetById(playlist_t *, int ) VLC_USED;
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;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 5efc67e..2d82546 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -347,6 +347,8 @@ playlist_VolumeSet
playlist_VolumeUp
playlist_MuteSet
playlist_MuteGet
+playlist_PlaylistLoad
+playlist_PlaylistDump
pl_Get
resolve_xml_special_chars
sdp_AddAttribute
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 8207c79..f492329 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -260,6 +260,19 @@ static playlist_t *playlist_Create( vlc_object_t *p_parent )
if( !p_playlist->p_playing ) return NULL;
+ /* Create currently playing items node */
+ PL_LOCK;
+ p_playlist->p_recents = playlist_NodeCreate(
+ p_playlist, _( "Recents" ), p_playlist->p_root,
+ PLAYLIST_END, PLAYLIST_RO_FLAG, NULL );
+
+
+ PL_UNLOCK;
+
+ if( !p_playlist->p_recents ) return NULL;
+
+ playlist_RecentsLoad( p_playlist );
+
/* Create media library node */
const bool b_ml = var_InheritBool( p_parent, "media-library");
if( b_ml )
diff --git a/src/playlist/item.c b/src/playlist/item.c
index e902063..ccce67f 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -464,6 +464,9 @@ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
PL_UNLOCK_IF( !b_locked );
return VLC_ENOMEM;
}
+
+ playlist_NodeAppendOrMove( p_playlist, p_item, p_playlist->p_recents );
+
AddItem( p_playlist, p_item,
b_playlist ? p_playlist->p_playing :
p_playlist->p_media_library , i_mode, i_pos );
@@ -471,6 +474,9 @@ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
GoAndPreparse( p_playlist, i_mode, p_item );
PL_UNLOCK_IF( !b_locked );
+
+ playlist_RecentsDump( p_playlist );
+
return VLC_SUCCESS;
}
diff --git a/src/playlist/loadsave.c b/src/playlist/loadsave.c
index 85a3e9e..c49d1c7 100644
--- a/src/playlist/loadsave.c
+++ b/src/playlist/loadsave.c
@@ -105,35 +105,37 @@ int playlist_Import( playlist_t *p_playlist, const char *psz_file )
static void input_item_subitem_tree_added( const vlc_event_t * p_event,
void * user_data )
{
- playlist_t *p_playlist = user_data;
+ playlist_item_t *p_node = user_data;
+ playlist_t *p_playlist = p_node->p_playlist;
input_item_node_t *p_root =
p_event->u.input_item_subitem_tree_added.p_root;
PL_LOCK;
- playlist_InsertInputItemTree ( p_playlist, p_playlist->p_media_library,
+ playlist_InsertInputItemTree ( p_playlist, p_node,
p_root, 0, false );
PL_UNLOCK;
}
-int playlist_MLLoad( playlist_t *p_playlist )
+int playlist_PlaylistLoad( playlist_t *p_playlist, playlist_item_t *p_node, char *psz_filename, char *psz_name )
{
input_item_t *p_input;
char *psz_datadir = config_GetUserDir( VLC_DATA_DIR );
if( !psz_datadir ) /* XXX: This should never happen */
{
- msg_Err( p_playlist, "no data directory, cannot load media library") ;
+ msg_Err( p_playlist, "no data directory, cannot load %s", psz_name );
return VLC_EGENERIC;
}
char *psz_file;
- if( asprintf( &psz_file, "%s" DIR_SEP "ml.xspf", psz_datadir ) == -1 )
+
+ if( asprintf( &psz_file, "%s" DIR_SEP "%s", psz_datadir, psz_filename ) == -1 )
psz_file = NULL;
free( psz_datadir );
if( psz_file == NULL )
return VLC_ENOMEM;
- /* lousy check for media library file */
+ /* lousy check for the file */
struct stat st;
if( vlc_stat( psz_file, &st ) )
{
@@ -149,20 +151,20 @@ int playlist_MLLoad( playlist_t *p_playlist )
const char *const options[1] = { "meta-file", };
/* that option has to be cleaned in input_item_subitem_tree_added() */
/* vlc_gc_decref() in the same function */
- p_input = input_item_NewExt( psz_uri, _("Media Library"),
+ p_input = input_item_NewExt( psz_uri, _(psz_name),
1, options, VLC_INPUT_OPTION_TRUSTED, -1 );
free( psz_uri );
if( p_input == NULL )
return VLC_EGENERIC;
PL_LOCK;
- if( p_playlist->p_media_library->p_input )
- vlc_gc_decref( p_playlist->p_media_library->p_input );
+ if( p_node->p_input )
+ vlc_gc_decref( p_node->p_input );
- p_playlist->p_media_library->p_input = p_input;
+ p_node->p_input = p_input;
vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded,
- input_item_subitem_tree_added, p_playlist );
+ input_item_subitem_tree_added, p_node );
pl_priv(p_playlist)->b_doing_ml = true;
PL_UNLOCK;
@@ -174,12 +176,12 @@ int playlist_MLLoad( playlist_t *p_playlist )
PL_UNLOCK;
vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded,
- input_item_subitem_tree_added, p_playlist );
+ input_item_subitem_tree_added, p_node );
return VLC_SUCCESS;
}
-int playlist_MLDump( playlist_t *p_playlist )
+int playlist_PlaylistDump( playlist_t *p_playlist, playlist_item_t *p_node, char *psz_filename, char *psz_name )
{
char *psz_datadir;
@@ -187,11 +189,11 @@ int playlist_MLDump( playlist_t *p_playlist )
if( !psz_datadir ) /* XXX: This should never happen */
{
- msg_Err( p_playlist, "no data directory, cannot save media library") ;
+ msg_Err( p_playlist, "no data directory, cannot save" );
return VLC_EGENERIC;
}
- char psz_dirname[ strlen( psz_datadir ) + sizeof( DIR_SEP "ml.xspf")];
+ char psz_dirname[ strlen( psz_datadir ) + sizeof( DIR_SEP ) + strlen( psz_filename ) ];
strcpy( psz_dirname, psz_datadir );
free( psz_datadir );
if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) )
@@ -199,9 +201,10 @@ int playlist_MLDump( playlist_t *p_playlist )
return VLC_EGENERIC;
}
- strcat( psz_dirname, DIR_SEP "ml.xspf" );
+ strcat( psz_dirname, DIR_SEP );
+ strcat( psz_dirname, psz_filename );
- playlist_Export( p_playlist, psz_dirname, p_playlist->p_media_library,
+ playlist_Export( p_playlist, psz_dirname, p_node,
"export-xspf" );
return VLC_SUCCESS;
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 9b6c000..5e430d5 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -112,10 +112,6 @@ playlist_item_t * get_current_status_node( playlist_t * p_playlist );
void set_current_status_item( playlist_t *, playlist_item_t * );
void set_current_status_node( playlist_t *, playlist_item_t * );
-/* Load/Save */
-int playlist_MLLoad( playlist_t *p_playlist );
-int playlist_MLDump( playlist_t *p_playlist );
-
/**********************************************************************
* Item management
**********************************************************************/
diff --git a/src/playlist/tree.c b/src/playlist/tree.c
index eca12b1..a468c80 100644
--- a/src/playlist/tree.c
+++ b/src/playlist/tree.c
@@ -226,6 +226,34 @@ int playlist_NodeInsert( playlist_t *p_playlist,
}
/**
+ * Append item to a node or move an existing to the top
+ *
+ * \param p_playlist the playlist
+ * \param p_item the item to append or move
+ * \param p_parent the parent nove
+ * \return VLC_SUCCESS or an error
+ */
+int playlist_NodeAppendOrMove( playlist_t *p_playlist,
+ playlist_item_t *p_item,
+ playlist_item_t *p_parent )
+{
+ for ( int i = 0; i < p_parent->i_children; i++ )
+ {
+ if ( !strcmp( p_parent->pp_children[i]->p_input->psz_uri, p_item->p_input->psz_uri ) )
+ {
+ playlist_item_t *old_item = p_parent->pp_children[i];
+
+ if ( playlist_NodeRemoveItem( p_playlist, old_item, p_parent ) != NULL )
+ return NULL;
+
+ return playlist_NodeInsert( p_playlist, old_item, p_parent, -1 );
+ }
+ }
+
+ return playlist_NodeInsert( p_playlist, p_item, p_parent, -1 );
+}
+
+/**
* Deletes an item from the children of a node
*
* \param p_playlist the playlist
--
1.8.3.2
More information about the vlc-devel
mailing list