Commit 8fc62fef authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: store time besides MRL for recent items

Ref #5315
parent cbe150c9
...@@ -1595,7 +1595,7 @@ void VLCMenuBar::updateRecents( intf_thread_t *p_intf ) ...@@ -1595,7 +1595,7 @@ void VLCMenuBar::updateRecents( intf_thread_t *p_intf )
{ {
QAction* action; QAction* action;
RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf ); RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
QStringList l = rmrl->recents(); QStringList l = rmrl->recentList();
recentsMenu->clear(); recentsMenu->clear();
......
...@@ -51,7 +51,8 @@ ...@@ -51,7 +51,8 @@
RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf ) RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
{ {
stack = new QStringList; recents = QStringList();
times = QStringList();
signalMapper = new QSignalMapper( this ); signalMapper = new QSignalMapper( this );
CONNECT( signalMapper, CONNECT( signalMapper,
...@@ -76,7 +77,6 @@ RecentsMRL::~RecentsMRL() ...@@ -76,7 +77,6 @@ RecentsMRL::~RecentsMRL()
{ {
save(); save();
delete filter; delete filter;
delete stack;
} }
void RecentsMRL::addRecent( const QString &mrl ) void RecentsMRL::addRecent( const QString &mrl )
...@@ -96,17 +96,21 @@ void RecentsMRL::addRecent( const QString &mrl ) ...@@ -96,17 +96,21 @@ void RecentsMRL::addRecent( const QString &mrl )
} }
#endif #endif
int i_index = stack->indexOf( mrl ); int i_index = recents.indexOf( mrl );
if( 0 <= i_index ) if( 0 <= i_index )
{ {
/* move to the front */ /* move to the front */
stack->move( i_index, 0 ); recents.move( i_index, 0 );
times.move( i_index, 0 );
} }
else else
{ {
stack->prepend( mrl ); recents.prepend( mrl );
if( stack->count() > RECENTS_LIST_SIZE ) times.prepend( "-1" );
stack->takeLast(); if( recents.count() > RECENTS_LIST_SIZE ) {
recents.takeLast();
times.takeLast();
}
} }
VLCMenuBar::updateRecents( p_intf ); VLCMenuBar::updateRecents( p_intf );
save(); save();
...@@ -114,35 +118,40 @@ void RecentsMRL::addRecent( const QString &mrl ) ...@@ -114,35 +118,40 @@ void RecentsMRL::addRecent( const QString &mrl )
void RecentsMRL::clear() void RecentsMRL::clear()
{ {
if ( stack->isEmpty() ) if ( recents.isEmpty() )
return; return;
stack->clear(); recents.clear();
times.clear();
if( isActive ) VLCMenuBar::updateRecents( p_intf ); if( isActive ) VLCMenuBar::updateRecents( p_intf );
save(); save();
} }
QStringList RecentsMRL::recents() QStringList RecentsMRL::recentList()
{ {
return *stack; return recents;
} }
void RecentsMRL::load() void RecentsMRL::load()
{ {
/* Load from the settings */ /* Load from the settings */
QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList(); QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
QStringList list2 = getSettings()->value( "RecentsMRL/times" ).toStringList();
/* And filter the regexp on the list */ /* And filter the regexp on the list */
for( int i = 0; i < list.count(); ++i ) for( int i = 0; i < list.count(); ++i )
{ {
if ( !filter || filter->indexIn( list.at(i) ) == -1 ) if ( !filter || filter->indexIn( list.at(i) ) == -1 ) {
stack->append( list.at(i) ); recents.append( list.at(i) );
times.append( list2.value(i, "-1" ) );
}
} }
} }
void RecentsMRL::save() void RecentsMRL::save()
{ {
getSettings()->setValue( "RecentsMRL/list", *stack ); getSettings()->setValue( "RecentsMRL/list", recents );
getSettings()->setValue( "RecentsMRL/times", times );
} }
playlist_item_t *RecentsMRL::toPlaylist(int length) playlist_item_t *RecentsMRL::toPlaylist(int length)
...@@ -151,12 +160,12 @@ playlist_item_t *RecentsMRL::toPlaylist(int length) ...@@ -151,12 +160,12 @@ playlist_item_t *RecentsMRL::toPlaylist(int length)
if ( p_node_recent == NULL ) return NULL; if ( p_node_recent == NULL ) return NULL;
if (length == 0 || stack->count() < length) if (length == 0 || recents.count() < length)
length = stack->count(); length = recents.count();
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
input_item_t *p_input = input_item_New(qtu(stack->at(i)), NULL); input_item_t *p_input = input_item_New(qtu(recents.at(i)), NULL);
playlist_NodeAddInput(THEPL, p_input, p_node_recent, PLAYLIST_APPEND, PLAYLIST_END, false); playlist_NodeAddInput(THEPL, p_input, p_node_recent, PLAYLIST_APPEND, PLAYLIST_END, false);
} }
...@@ -168,6 +177,25 @@ void RecentsMRL::playMRL( const QString &mrl ) ...@@ -168,6 +177,25 @@ void RecentsMRL::playMRL( const QString &mrl )
Open::openMRL( p_intf, mrl ); Open::openMRL( p_intf, mrl );
} }
int RecentsMRL::time( const QString &mrl )
{
if( !isActive )
return -1;
int i_index = recents.indexOf( mrl );
if( i_index != -1 )
return times.value(i_index, "-1").toInt();
else
return -1;
}
void RecentsMRL::setTime( const QString &mrl, const int64_t time )
{
int i_index = recents.indexOf( mrl );
if( i_index != -1 )
times[i_index] = QString::number( time / 1000 );
}
int Open::openMRL( intf_thread_t *p_intf, int Open::openMRL( intf_thread_t *p_intf,
const QString &mrl, const QString &mrl,
bool b_start, bool b_start,
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "util/singleton.hpp" #include "util/singleton.hpp"
#include <QObject> #include <QObject>
class QStringList; #include <QStringList>
class QRegExp; class QRegExp;
class QSignalMapper; class QSignalMapper;
...@@ -58,16 +58,21 @@ class RecentsMRL : public QObject, public Singleton<RecentsMRL> ...@@ -58,16 +58,21 @@ class RecentsMRL : public QObject, public Singleton<RecentsMRL>
public: public:
void addRecent( const QString & ); void addRecent( const QString & );
QStringList recents(); QStringList recentList();
playlist_item_t *toPlaylist(int length); playlist_item_t *toPlaylist(int length);
QSignalMapper *signalMapper; QSignalMapper *signalMapper;
int time( const QString &mrl );
void setTime( const QString &mrl, const int64_t time );
private: private:
RecentsMRL( intf_thread_t* _p_intf ); RecentsMRL( intf_thread_t* _p_intf );
virtual ~RecentsMRL(); virtual ~RecentsMRL();
intf_thread_t *p_intf; intf_thread_t *p_intf;
QStringList *stack;
QStringList recents;
QStringList times;
QRegExp *filter; QRegExp *filter;
bool isActive; bool isActive;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment