]> git.sesse.net Git - vlc/blob - modules/gui/qt4/recents.cpp
Qt4: remove useless alive check on input
[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     char* path = make_path( qtu( mrl ) );
92     if( path )
93     {
94         SHAddToRecentDocs( SHARD_PATHW, mrl.utf16() );
95         free( path );
96     }
97 #endif
98
99     int i_index = stack->indexOf( mrl );
100     if( 0 <= i_index )
101     {
102         /* move to the front */
103         stack->move( i_index, 0 );
104     }
105     else
106     {
107         stack->prepend( mrl );
108         if( stack->count() > RECENTS_LIST_SIZE )
109             stack->takeLast();
110     }
111     VLCMenuBar::updateRecents( p_intf );
112     save();
113 }
114
115 void RecentsMRL::clear()
116 {
117     if ( stack->isEmpty() )
118         return;
119
120     stack->clear();
121     if( isActive ) VLCMenuBar::updateRecents( p_intf );
122     save();
123 }
124
125 QStringList RecentsMRL::recents()
126 {
127     return *stack;
128 }
129
130 void RecentsMRL::load()
131 {
132     /* Load from the settings */
133     QStringList list = getSettings()->value( "RecentsMRL/list" ).toStringList();
134
135     /* And filter the regexp on the list */
136     for( int i = 0; i < list.count(); ++i )
137     {
138         if ( !filter || filter->indexIn( list.at(i) ) == -1 )
139             stack->append( list.at(i) );
140     }
141 }
142
143 void RecentsMRL::save()
144 {
145     getSettings()->setValue( "RecentsMRL/list", *stack );
146 }
147