1 /*****************************************************************************
2 * recents.cpp : Recents MRL (menu)
3 *****************************************************************************
4 * Copyright © 2008-2014 VideoLAN and VLC authors
6 * Authors: Ludovic Fauvet <etix@l0cal.com>
7 * Jean-baptiste Kempf <jb@videolan.org>
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"
28 #include "util/qt_dirs.hpp"
30 #include <QStringList>
32 #include <QSignalMapper>
37 SHARD_PIDL = 0x00000001,
38 SHARD_PATHA = 0x00000002,
39 SHARD_PATHW = 0x00000003,
40 SHARD_APPIDINFO = 0x00000004,
41 SHARD_APPIDINFOIDLIST = 0x00000005,
42 SHARD_LINK = 0x00000006,
43 SHARD_APPIDINFOLINK = 0x00000007,
44 SHARD_SHELLITEM = 0x00000008
46 #define SHARD_PATHW 0x00000003
48 #include <vlc_charset.h>
51 #include <vlc_input_item.h>
53 RecentsMRL::RecentsMRL( intf_thread_t
*_p_intf
) : p_intf( _p_intf
)
55 recents
= QStringList();
56 times
= QStringList();
58 signalMapper
= new QSignalMapper( this );
59 CONNECT( signalMapper
,
60 mapped(const QString
& ),
62 playMRL( const QString
& ) );
64 /* Load the filter psz */
65 char* psz_tmp
= var_InheritString( p_intf
, "qt-recentplay-filter" );
66 if( psz_tmp
&& *psz_tmp
)
67 filter
= new QRegExp( psz_tmp
, Qt::CaseInsensitive
);
73 isActive
= var_InheritBool( p_intf
, "qt-recentplay" );
74 if( !isActive
) clear();
77 RecentsMRL::~RecentsMRL()
83 void RecentsMRL::addRecent( const QString
&mrl
)
85 if ( !isActive
|| ( filter
&& filter
->indexIn( mrl
) >= 0 ) )
89 /* Add to the Windows 7 default list in taskbar */
90 char* path
= vlc_uri2path( qtu( mrl
) );
93 wchar_t *wmrl
= ToWide( path
);
94 SHAddToRecentDocs( SHARD_PATHW
, wmrl
);
100 int i_index
= recents
.indexOf( mrl
);
103 /* move to the front */
104 recents
.move( i_index
, 0 );
105 times
.move( i_index
, 0 );
109 recents
.prepend( mrl
);
110 times
.prepend( "-1" );
111 if( recents
.count() > RECENTS_LIST_SIZE
) {
116 VLCMenuBar::updateRecents( p_intf
);
120 void RecentsMRL::clear()
122 if ( recents
.isEmpty() )
127 if( isActive
) VLCMenuBar::updateRecents( p_intf
);
131 QStringList
RecentsMRL::recentList()
136 void RecentsMRL::load()
138 /* Load from the settings */
139 QStringList list
= getSettings()->value( "RecentsMRL/list" ).toStringList();
140 QStringList list2
= getSettings()->value( "RecentsMRL/times" ).toStringList();
142 /* And filter the regexp on the list */
143 for( int i
= 0; i
< list
.count(); ++i
)
145 if ( !filter
|| filter
->indexIn( list
.at(i
) ) == -1 ) {
146 recents
.append( list
.at(i
) );
147 times
.append( list2
.value(i
, "-1" ) );
152 void RecentsMRL::save()
154 getSettings()->setValue( "RecentsMRL/list", recents
);
155 getSettings()->setValue( "RecentsMRL/times", times
);
158 void RecentsMRL::playMRL( const QString
&mrl
)
160 Open::openMRL( p_intf
, mrl
);
163 vlc_tick_t
RecentsMRL::time( const QString
&mrl
)
168 int i_index
= recents
.indexOf( mrl
);
170 return VLC_TICK_FROM_MS(times
.value(i_index
, "-1").toInt());
175 void RecentsMRL::setTime( const QString
&mrl
, const vlc_tick_t time
)
177 int i_index
= recents
.indexOf( mrl
);
179 times
[i_index
] = QString::number( MS_FROM_VLC_TICK( time
) );
182 int Open::openMRL( intf_thread_t
*p_intf
,
186 return openMRLwithOptions( p_intf
, mrl
, NULL
, b_start
);
189 int Open::openMRLwithOptions( intf_thread_t
* p_intf
,
191 QStringList
*options
,
196 const char **ppsz_options
= NULL
;
199 if( options
!= NULL
&& options
->count() > 0 )
201 ppsz_options
= new const char *[options
->count()];
202 for( int j
= 0; j
< options
->count(); j
++ ) {
203 QString option
= colon_unescape( options
->at(j
) );
204 if( !option
.isEmpty() ) {
205 ppsz_options
[i_options
] = strdup(qtu(option
));
211 /* Add to playlist */
212 int i_ret
= playlist_AddExt( THEPL
, qtu(mrl
), title
, b_start
,
213 i_options
, ppsz_options
, VLC_INPUT_OPTION_TRUSTED
);
215 /* Add to recent items, only if played */
216 if( i_ret
== VLC_SUCCESS
&& b_start
)
217 RecentsMRL::getInstance( p_intf
)->addRecent( mrl
);
220 if ( ppsz_options
!= NULL
)
222 for ( int i
= 0; i
< i_options
; ++i
)
223 free( (char*)ppsz_options
[i
] );
224 delete[] ppsz_options
;