]> git.sesse.net Git - vlc/blob - modules/gui/qt4/recents.cpp
Qt: correctly handle Unicode in Win7 jump lists
[vlc] / modules / gui / qt4 / recents.cpp
1 /*****************************************************************************
2  * recents.cpp : Recents MRL (menu)
3  *****************************************************************************
4  * Copyright © 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Ludovic Fauvet <etix@l0cal.com>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24
25 #include "recents.hpp"
26 #include "dialogs_provider.hpp"
27 #include "menus.hpp"
28
29 #include <QStringList>
30 #include <QAction>
31 #include <QSettings>
32 #include <QRegExp>
33 #include <QSignalMapper>
34
35 #ifdef WIN32
36     #include <shlobj.h>
37     /* typedef enum  {
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 
46     } SHARD; */
47     #define SHARD_PATHW 0x00000003
48 #endif
49
50
51 RecentsMRL* RecentsMRL::instance = NULL;
52
53 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
54 {
55     stack = new QStringList;
56
57     signalMapper = new QSignalMapper( this );
58     CONNECT( signalMapper,
59             mapped(const QString & ),
60             DialogsProvider::getInstance( p_intf ),
61             playMRL( const QString & ) );
62
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 );
67     else
68         filter = NULL;
69     free( psz_tmp );
70
71     load();
72     isActive = var_InheritBool( p_intf, "qt-recentplay" );
73     if( !isActive ) clear();
74 }
75
76 RecentsMRL::~RecentsMRL()
77 {
78     delete filter;
79     delete stack;
80 }
81
82 void RecentsMRL::addRecent( const QString &mrl )
83 {
84     if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
85         return;
86
87     msg_Dbg( p_intf, "Adding a new MRL to recent ones: %s", qtu( mrl ) );
88
89 #ifdef WIN32
90     /* Add to the Windows 7 default list in taskbar */
91     SHAddToRecentDocs( SHARD_PATHW, qtu( mrl ) );
92 #endif
93
94     int i_index = stack->indexOf( mrl );
95     if( 0 <= i_index )
96     {
97         /* move to the front */
98         stack->move( i_index, 0 );
99     }
100     else
101     {
102         stack->prepend( mrl );
103         if( stack->size() > RECENTS_LIST_SIZE )
104             stack->takeLast();
105     }
106     QVLCMenu::updateRecents( p_intf );
107     save();
108 }
109
110 void RecentsMRL::clear()
111 {
112     if ( stack->isEmpty() )
113         return;
114
115     stack->clear();
116     if( isActive ) QVLCMenu::updateRecents( p_intf );
117     save();
118 }
119
120 QStringList RecentsMRL::recents()
121 {
122     return *stack;
123 }
124
125 void RecentsMRL::load()
126 {
127     /* Load from the settings */
128     QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
129
130     /* And filter the regexp on the list */
131     for( int i = 0; i < list.size(); ++i )
132     {
133         if ( !filter || filter->indexIn( list.at(i) ) == -1 )
134             stack->append( list.at(i) );
135     }
136 }
137
138 void RecentsMRL::save()
139 {
140     getSettings()->setValue( "RecentsMRL/list", *stack );
141 }
142