Commit 7c446cb7 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: recents factorization.

parent dc92e9b3
...@@ -1416,11 +1416,11 @@ void QVLCMenu::DoAction( QObject *data ) ...@@ -1416,11 +1416,11 @@ void QVLCMenu::DoAction( QObject *data )
void QVLCMenu::updateRecents( intf_thread_t *p_intf ) void QVLCMenu::updateRecents( intf_thread_t *p_intf )
{ {
if (recentsMenu) if( recentsMenu )
{ {
QAction* action; QAction* action;
RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf ); RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
QList<QString> l = rmrl->recents(); QStringList l = rmrl->recents();
recentsMenu->clear(); recentsMenu->clear();
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
#include "dialogs_provider.hpp" #include "dialogs_provider.hpp"
#include "menus.hpp" #include "menus.hpp"
#include <QList> #include <QStringList>
#include <QString>
#include <QAction> #include <QAction>
#include <QSettings> #include <QSettings>
#include <QRegExp> #include <QRegExp>
...@@ -41,14 +40,15 @@ RecentsMRL* RecentsMRL::instance = NULL; ...@@ -41,14 +40,15 @@ RecentsMRL* RecentsMRL::instance = NULL;
RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf ) RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
{ {
stack = new QList<QString>; stack = new QStringList;
signalMapper = new QSignalMapper(this);
signalMapper = new QSignalMapper( this );
CONNECT( signalMapper, CONNECT( signalMapper,
mapped(const QString & ), mapped(const QString & ),
DialogsProvider::getInstance( p_intf ), DialogsProvider::getInstance( p_intf ),
playMRL( const QString & ) ); playMRL( const QString & ) );
isActive = config_GetInt( p_intf, "qt-recentplay" ); /* Load the filter psz */
char* psz_tmp = config_GetPsz( p_intf, "qt-recentplay-filter" ); char* psz_tmp = config_GetPsz( p_intf, "qt-recentplay-filter" );
if( psz_tmp && *psz_tmp ) if( psz_tmp && *psz_tmp )
filter = new QRegExp( psz_tmp, Qt::CaseInsensitive ); filter = new QRegExp( psz_tmp, Qt::CaseInsensitive );
...@@ -57,6 +57,7 @@ RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf ) ...@@ -57,6 +57,7 @@ RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
free( psz_tmp ); free( psz_tmp );
load(); load();
isActive = config_GetInt( p_intf, "qt-recentplay" );
if( !isActive ) clear(); if( !isActive ) clear();
} }
...@@ -98,20 +99,23 @@ void RecentsMRL::clear() ...@@ -98,20 +99,23 @@ void RecentsMRL::clear()
{ {
if ( stack->isEmpty() ) if ( stack->isEmpty() )
return; return;
stack->clear(); stack->clear();
if( isActive ) QVLCMenu::updateRecents( p_intf ); if( isActive ) QVLCMenu::updateRecents( p_intf );
save(); save();
} }
QList<QString> RecentsMRL::recents() QStringList RecentsMRL::recents()
{ {
return QList<QString>(*stack); return *stack;
} }
void RecentsMRL::load() void RecentsMRL::load()
{ {
/* Load from the settings */
QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList(); QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
/* And filter the regexp on the list */
for( int i = 0; i < list.size(); ++i ) for( int i = 0; i < list.size(); ++i )
{ {
if ( !filter || filter->indexIn( list.at(i) ) == -1 ) if ( !filter || filter->indexIn( list.at(i) ) == -1 )
...@@ -121,11 +125,6 @@ void RecentsMRL::load() ...@@ -121,11 +125,6 @@ void RecentsMRL::load()
void RecentsMRL::save() void RecentsMRL::save()
{ {
QStringList list; getSettings()->setValue( "RecentsMRL/list", *stack );
for( int i = 0; i < stack->size(); ++i )
list << stack->at(i);
getSettings()->setValue( "RecentsMRL/list", list );
} }
...@@ -27,10 +27,9 @@ ...@@ -27,10 +27,9 @@
#include "qt4.hpp" #include "qt4.hpp"
#include <QObject> #include <QObject>
#include <QList> class QStringList;
#include <QString> class QRegExp;
#include <QRegExp> class QSignalMapper;
#include <QSignalMapper>
#define RECENTS_LIST_SIZE 10 #define RECENTS_LIST_SIZE 10
...@@ -52,7 +51,8 @@ public: ...@@ -52,7 +51,8 @@ public:
} }
void addRecent( const QString & ); void addRecent( const QString & );
QList<QString> recents(); QStringList recents();
QSignalMapper *signalMapper; QSignalMapper *signalMapper;
private: private:
...@@ -61,13 +61,13 @@ private: ...@@ -61,13 +61,13 @@ private:
static RecentsMRL *instance; static RecentsMRL *instance;
void load(); intf_thread_t *p_intf;
void save(); QStringList *stack;
intf_thread_t* p_intf;
QList<QString> *stack;
bool isActive;
QRegExp *filter; QRegExp *filter;
bool isActive;
void load();
void save();
public slots: public slots:
void clear(); void clear();
}; };
......
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