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"
29 #include <QStringList>
33 #include <QSignalMapper>
38 SHARD_PIDL = 0x00000001,
39 SHARD_PATHA = 0x00000002,
40 SHARD_PATHW = 0x00000003,
41 SHARD_APPIDINFO = 0x00000004,
42 SHARD_APPIDINFOIDLIST = 0x00000005,
43 SHARD_LINK = 0x00000006,
44 SHARD_APPIDINFOLINK = 0x00000007,
45 SHARD_SHELLITEM = 0x00000008
47 #define SHARD_PATHW 0x00000003
51 RecentsMRL* RecentsMRL::instance = NULL;
53 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
55 stack = new QStringList;
57 signalMapper = new QSignalMapper( this );
58 CONNECT( signalMapper,
59 mapped(const QString & ),
60 DialogsProvider::getInstance( p_intf ),
61 playMRL( const QString & ) );
63 /* Load the filter psz */
64 char* psz_tmp = var_InheritString( p_intf, "qt-recentplay-filter" );
65 if( psz_tmp && *psz_tmp )
66 filter = new QRegExp( psz_tmp, Qt::CaseInsensitive );
72 isActive = var_InheritBool( p_intf, "qt-recentplay" );
73 if( !isActive ) clear();
76 RecentsMRL::~RecentsMRL()
82 void RecentsMRL::addRecent( const QString &mrl )
84 if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
87 msg_Dbg( p_intf, "Adding a new MRL to recent ones: %s", qtu( mrl ) );
90 /* Add to the Windows 7 default list in taskbar */
91 char* path = make_path( qtu( mrl ) );
94 SHAddToRecentDocs( SHARD_PATHW, mrl.utf16() );
99 int i_index = stack->indexOf( mrl );
102 /* move to the front */
103 stack->move( i_index, 0 );
107 stack->prepend( mrl );
108 if( stack->count() > RECENTS_LIST_SIZE )
111 VLCMenuBar::updateRecents( p_intf );
115 void RecentsMRL::clear()
117 if ( stack->isEmpty() )
121 if( isActive ) VLCMenuBar::updateRecents( p_intf );
125 QStringList RecentsMRL::recents()
130 void RecentsMRL::load()
132 /* Load from the settings */
133 QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
135 /* And filter the regexp on the list */
136 for( int i = 0; i < list.count(); ++i )
138 if ( !filter || filter->indexIn( list.at(i) ) == -1 )
139 stack->append( list.at(i) );
143 void RecentsMRL::save()
145 getSettings()->setValue( "RecentsMRL/list", *stack );