]> git.sesse.net Git - vlc/blob - modules/gui/qt4/recents.cpp
Qt: different call to SHAddToRecentDocs
[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
49     #include <vlc_charset.h>
50 #endif
51
52
53 RecentsMRL* RecentsMRL::instance = NULL;
54
55 RecentsMRL::RecentsMRL( intf_thread_t *_p_intf ) : p_intf( _p_intf )
56 {
57     stack = new QStringList;
58
59     signalMapper = new QSignalMapper( this );
60     CONNECT( signalMapper,
61             mapped(const QString & ),
62             DialogsProvider::getInstance( p_intf ),
63             playMRL( const QString & ) );
64
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 );
69     else
70         filter = NULL;
71     free( psz_tmp );
72
73     load();
74     isActive = var_InheritBool( p_intf, "qt-recentplay" );
75     if( !isActive ) clear();
76 }
77
78 RecentsMRL::~RecentsMRL()
79 {
80     delete filter;
81     delete stack;
82 }
83
84 void RecentsMRL::addRecent( const QString &mrl )
85 {
86     if ( !isActive || ( filter && filter->indexIn( mrl ) >= 0 ) )
87         return;
88
89     msg_Dbg( p_intf, "Adding a new MRL to recent ones: %s", qtu( mrl ) );
90
91 #ifdef WIN32
92     /* Add to the Windows 7 default list in taskbar */
93     char* path = make_path( qtu( mrl ) );
94     if( path )
95     {
96         wchar_t *wmrl = ToWide( path );
97         SHAddToRecentDocs( SHARD_PATHW, wmrl );
98         free( wmrl );
99         free( path );
100     }
101 #endif
102
103     int i_index = stack->indexOf( mrl );
104     if( 0 <= i_index )
105     {
106         /* move to the front */
107         stack->move( i_index, 0 );
108     }
109     else
110     {
111         stack->prepend( mrl );
112         if( stack->count() > RECENTS_LIST_SIZE )
113             stack->takeLast();
114     }
115     VLCMenuBar::updateRecents( p_intf );
116     save();
117 }
118
119 void RecentsMRL::clear()
120 {
121     if ( stack->isEmpty() )
122         return;
123
124     stack->clear();
125     if( isActive ) VLCMenuBar::updateRecents( p_intf );
126     save();
127 }
128
129 QStringList RecentsMRL::recents()
130 {
131     return *stack;
132 }
133
134 void RecentsMRL::load()
135 {
136     /* Load from the settings */
137     QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
138
139     /* And filter the regexp on the list */
140     for( int i = 0; i < list.count(); ++i )
141     {
142         if ( !filter || filter->indexIn( list.at(i) ) == -1 )
143             stack->append( list.at(i) );
144     }
145 }
146
147 void RecentsMRL::save()
148 {
149     getSettings()->setValue( "RecentsMRL/list", *stack );
150 }
151