1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
/*****************************************************************************
* recents.cpp : Recents MRL (menu)
*****************************************************************************
* Copyright © 2008-2014 VideoLAN and VLC authors
* $Id: d2294a91003abcf7462fc2247cef4d4861bb39f1 $
*
* Authors: Ludovic Fauvet <etix@l0cal.com>
* Jean-baptiste Kempf <jb@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* ( at your option ) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "qt4.hpp"
#include "recents.hpp"
#include "dialogs_provider.hpp"
#include "menus.hpp"
#include "util/qt_dirs.hpp"
#include <QStringList>
#include <QRegExp>
#include <QSignalMapper>
#ifdef _WIN32
#include <shlobj.h>
/* typedef enum {
SHARD_PIDL = 0x00000001,
SHARD_PATHA = 0x00000002,
SHARD_PATHW = 0x00000003,
SHARD_APPIDINFO = 0x00000004,
SHARD_APPIDINFOIDLIST = 0x00000005,
SHARD_LINK = 0x00000006,
SHARD_APPIDINFOLINK = 0x00000007,
SHARD_SHELLITEM = 0x00000008
} SHARD; */
#define SHARD_PATHW 0x00000003
#include <vlc_charset.h>
#endif
RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
{
recents = QStringList();
times = QStringList();
signalMapper = new QSignalMapper( this );
CONNECT( signalMapper,
mapped(const QString & ),
this,
playMRL( const QString & ) );
/* Load the filter psz */
char* psz_tmp = var_InheritString( p_intf, "qt-recentplay-filter" );
if( psz_tmp && *psz_tmp )
filter = new QRegExp( psz_tmp, Qt::CaseInsensitive );
else
filter = NULL;
free( psz_tmp );
load();
isActive = var_InheritBool( p_intf, "qt-recentplay" );
if( !isActive ) clear();
}
RecentsMRL::~RecentsMRL()
{
save();
delete filter;
}
void RecentsMRL::addRecent( const QString &mrl )
{
if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
return;
#ifdef _WIN32
/* Add to the Windows 7 default list in taskbar */
char* path = make_path( qtu( mrl ) );
if( path )
{
wchar_t *wmrl = ToWide( path );
SHAddToRecentDocs( SHARD_PATHW, wmrl );
free( wmrl );
free( path );
}
#endif
int i_index = recents.indexOf( mrl );
if( 0 <= i_index )
{
/* move to the front */
recents.move( i_index, 0 );
times.move( i_index, 0 );
}
else
{
recents.prepend( mrl );
times.prepend( "-1" );
if( recents.count() > RECENTS_LIST_SIZE ) {
recents.takeLast();
times.takeLast();
}
}
VLCMenuBar::updateRecents( p_intf );
save();
}
void RecentsMRL::clear()
{
if ( recents.isEmpty() )
return;
recents.clear();
times.clear();
if( isActive ) VLCMenuBar::updateRecents( p_intf );
save();
}
QStringList RecentsMRL::recentList()
{
return recents;
}
void RecentsMRL::load()
{
/* Load from the settings */
QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
QStringList list2 = getSettings()->value( "RecentsMRL/times" ).toStringList();
/* And filter the regexp on the list */
for( int i = 0; i < list.count(); ++i )
{
if ( !filter || filter->indexIn( list.at(i) ) == -1 ) {
recents.append( list.at(i) );
times.append( list2.value(i, "-1" ) );
}
}
}
void RecentsMRL::save()
{
getSettings()->setValue( "RecentsMRL/list", recents );
getSettings()->setValue( "RecentsMRL/times", times );
}
playlist_item_t *RecentsMRL::toPlaylist(int length)
{
playlist_item_t *p_node_recent = playlist_NodeCreate(THEPL, _("Recently Played"), THEPL->p_root, PLAYLIST_END, PLAYLIST_RO_FLAG, NULL);
if ( p_node_recent == NULL ) return NULL;
if (length == 0 || recents.count() < length)
length = recents.count();
for (int i = 0; i < length; i++)
{
input_item_t *p_input = input_item_New(qtu(recents.at(i)), NULL);
playlist_NodeAddInput(THEPL, p_input, p_node_recent, PLAYLIST_APPEND, PLAYLIST_END, false);
}
return p_node_recent;
}
void RecentsMRL::playMRL( const QString &mrl )
{
Open::openMRL( p_intf, mrl );
}
int RecentsMRL::time( const QString &mrl )
{
if( !isActive )
return -1;
int i_index = recents.indexOf( mrl );
if( i_index != -1 )
return times.value(i_index, "-1").toInt();
else
return -1;
}
void RecentsMRL::setTime( const QString &mrl, const int64_t time )
{
int i_index = recents.indexOf( mrl );
if( i_index != -1 )
times[i_index] = QString::number( time / 1000 );
}
int Open::openMRL( intf_thread_t *p_intf,
const QString &mrl,
bool b_start,
bool b_playlist)
{
return openMRLwithOptions( p_intf, mrl, NULL, b_start, b_playlist );
}
int Open::openMRLwithOptions( intf_thread_t* p_intf,
const QString &mrl,
QStringList *options,
bool b_start,
bool b_playlist,
const char *title)
{
/* Options */
const char **ppsz_options = NULL;
int i_options = 0;
if( options != NULL && options->count() > 0 )
{
ppsz_options = new const char *[options->count()];
for( int j = 0; j < options->count(); j++ ) {
QString option = colon_unescape( options->at(j) );
if( !option.isEmpty() ) {
ppsz_options[i_options] = strdup(qtu(option));
i_options++;
}
}
}
/* Add to playlist */
int i_ret = playlist_AddExt( THEPL,
qtu(mrl), title,
PLAYLIST_APPEND | (b_start ? PLAYLIST_GO : PLAYLIST_PREPARSE),
PLAYLIST_END,
-1,
i_options, ppsz_options, VLC_INPUT_OPTION_TRUSTED,
b_playlist,
pl_Unlocked );
/* Add to recent items, only if played */
if( i_ret == VLC_SUCCESS && b_start && b_playlist )
RecentsMRL::getInstance( p_intf )->addRecent( mrl );
/* Free options */
if ( ppsz_options != NULL )
{
for ( int i = 0; i < i_options; ++i )
free( (char*)ppsz_options[i] );
delete[] ppsz_options;
}
return i_ret;
}
|