1 /*****************************************************************************
2 * recents.cpp : Recents MRL (menu)
3 *****************************************************************************
4 * Copyright © 2006-2008 the VideoLAN team
7 * Authors: Ludovic Fauvet <etix@l0cal.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * ( at your option ) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include "recents.hpp"
26 #include "dialogs_provider.hpp"
34 #include <QSignalMapper>
36 RecentsMRL* RecentsMRL::instance = NULL;
38 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
40 stack = new QList<QString>;
41 signalMapper = new QSignalMapper(this);
42 CONNECT( signalMapper,
43 mapped(const QString & ),
44 DialogsProvider::getInstance( p_intf ),
45 playMRL( const QString & ) );
47 isActive = config_GetInt( p_intf, "qt-recentplay" );
48 char* psz_tmp = config_GetPsz( p_intf, "qt-recentplay-filter" );
49 filter = new QRegExp( psz_tmp, Qt::CaseInsensitive );
53 if ( !isActive ) clear();
56 RecentsMRL::~RecentsMRL()
62 void RecentsMRL::addRecent( const QString &mrl )
64 if ( !isActive || filter->indexIn( mrl ) >= 0 )
67 msg_Dbg( p_intf, "Adding a new MRL to recent ones: %s", qtu( mrl ) );
68 int i_index = stack->indexOf( mrl );
71 /* move to the front */
72 stack->move( i_index, 0 );
76 stack->prepend( mrl );
77 if( stack->size() > RECENTS_LIST_SIZE )
80 QVLCMenu::updateRecents( p_intf );
84 void RecentsMRL::clear()
86 if ( stack->isEmpty() )
89 QVLCMenu::updateRecents( p_intf );
93 QList<QString> RecentsMRL::recents()
95 return QList<QString>(*stack);
98 void RecentsMRL::load()
100 QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
102 for( int i = 0; i < list.size(); ++i )
104 if (filter->indexIn( list.at(i) ) == -1)
105 stack->append( list.at(i) );
109 void RecentsMRL::save()
113 for( int i = 0; i < stack->size(); ++i )
114 list << stack->at(i);
116 getSettings()->setValue( "RecentsMRL/list", list );