1 /*****************************************************************************
2 * recents.cpp : Recents MRL (menu)
3 *****************************************************************************
4 * Copyright © 2008-2014 VideoLAN and VLC authors
7 * Authors: Ludovic Fauvet <etix@l0cal.com>
8 * Jean-baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 #include "recents.hpp"
27 #include "dialogs_provider.hpp"
29 #include "util/qt_dirs.hpp"
31 #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>
52 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
54 stack = new QStringList;
56 signalMapper = new QSignalMapper( this );
57 CONNECT( signalMapper,
58 mapped(const QString & ),
60 playMRL( const QString & ) );
62 /* Load the filter psz */
63 char* psz_tmp = var_InheritString( p_intf, "qt-recentplay-filter" );
64 if( psz_tmp && *psz_tmp )
65 filter = new QRegExp( psz_tmp, Qt::CaseInsensitive );
71 isActive = var_InheritBool( p_intf, "qt-recentplay" );
72 if( !isActive ) clear();
75 RecentsMRL::~RecentsMRL()
82 void RecentsMRL::addRecent( const QString &mrl )
84 if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
88 /* Add to the Windows 7 default list in taskbar */
89 char* path = make_path( qtu( mrl ) );
92 wchar_t *wmrl = ToWide( path );
93 SHAddToRecentDocs( SHARD_PATHW, wmrl );
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 );
148 playlist_item_t *RecentsMRL::toPlaylist(int length)
150 playlist_item_t *p_node_recent = playlist_NodeCreate(THEPL, _("Recently Played"), THEPL->p_root, PLAYLIST_END, PLAYLIST_RO_FLAG, NULL);
152 if ( p_node_recent == NULL ) return NULL;
154 if (length == 0 || stack->count() < length)
155 length = stack->count();
157 for (int i = 0; i < length; i++)
159 input_item_t *p_input = input_item_New(qtu(stack->at(i)), NULL);
160 playlist_NodeAddInput(THEPL, p_input, p_node_recent, PLAYLIST_APPEND, PLAYLIST_END, false);
163 return p_node_recent;
166 void RecentsMRL::playMRL( const QString &mrl )
168 Open::openMRL( p_intf, mrl );
171 int Open::openMRL( intf_thread_t *p_intf,
176 return openMRLwithOptions( p_intf, mrl, NULL, b_start, b_playlist );
179 int Open::openMRLwithOptions( intf_thread_t* p_intf,
181 QStringList *options,
187 const char **ppsz_options = NULL;
190 if( options != NULL && options->count() > 0 )
192 ppsz_options = (const char **)malloc( options->count() );
194 for( int j = 0; j < options->count(); j++ ) {
195 QString option = colon_unescape( options->at(j) );
196 if( !option.isEmpty() ) {
197 ppsz_options[j] = qtu(option);
204 /* Add to playlist */
205 int i_ret = playlist_AddExt( THEPL,
207 PLAYLIST_APPEND | (b_start ? PLAYLIST_GO : PLAYLIST_PREPARSE),
210 i_options, ppsz_options, VLC_INPUT_OPTION_TRUSTED,
214 /* Add to recent items, only if played */
215 if( i_ret == VLC_SUCCESS && b_start && b_playlist )
216 RecentsMRL::getInstance( p_intf )->addRecent( mrl );