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
49 #include <vlc_charset.h>
53 RecentsMRL* RecentsMRL::instance = NULL;
55 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
57 stack = new QStringList;
59 signalMapper = new QSignalMapper( this );
60 CONNECT( signalMapper,
61 mapped(const QString & ),
62 DialogsProvider::getInstance( p_intf ),
63 playMRL( const QString & ) );
65 /* Load the filter psz */
66 char* psz_tmp = var_InheritString( p_intf, "qt-recentplay-filter" );
67 if( psz_tmp && *psz_tmp )
68 filter = new QRegExp( psz_tmp, Qt::CaseInsensitive );
74 isActive = var_InheritBool( p_intf, "qt-recentplay" );
75 if( !isActive ) clear();
78 RecentsMRL::~RecentsMRL()
84 void RecentsMRL::addRecent( const QString &mrl )
86 if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
89 msg_Dbg( p_intf, "Adding a new MRL to recent ones: %s", qtu( mrl ) );
92 /* Add to the Windows 7 default list in taskbar */
93 char* path = make_path( qtu( mrl ) );
96 wchar_t *wmrl = ToWide( path );
97 SHAddToRecentDocs( SHARD_PATHW, wmrl );
103 int i_index = stack->indexOf( mrl );
106 /* move to the front */
107 stack->move( i_index, 0 );
111 stack->prepend( mrl );
112 if( stack->count() > RECENTS_LIST_SIZE )
115 VLCMenuBar::updateRecents( p_intf );
119 void RecentsMRL::clear()
121 if ( stack->isEmpty() )
125 if( isActive ) VLCMenuBar::updateRecents( p_intf );
129 QStringList RecentsMRL::recents()
134 void RecentsMRL::load()
136 /* Load from the settings */
137 QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
139 /* And filter the regexp on the list */
140 for( int i = 0; i < list.count(); ++i )
142 if ( !filter || filter->indexIn( list.at(i) ) == -1 )
143 stack->append( list.at(i) );
147 void RecentsMRL::save()
149 getSettings()->setValue( "RecentsMRL/list", *stack );