]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/playlist.cpp
Some more cleanup and macros
[vlc] / modules / gui / qt4 / dialogs / playlist.cpp
1 /*****************************************************************************
2  * playlist.cpp : Playlist dialog
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
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 #include "dialogs/playlist.hpp"
25 #include "util/qvlcframe.hpp"
26 #include "qt4.hpp"
27 #include "components/playlist/panels.hpp"
28 #include "components/playlist/selector.hpp"
29 #include <QHBoxLayout>
30 #include <QSignalMapper>
31 #include <QMenu>
32 #include <QAction>
33 #include <QMenuBar>
34 #include "dialogs_provider.hpp"
35
36 PlaylistDialog *PlaylistDialog::instance = NULL;
37
38 PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
39 {
40     QWidget *main = new QWidget( this );
41     setCentralWidget( main );
42     setWindowTitle( qtr( "Playlist" ) );
43
44     SDMapper = new QSignalMapper();
45     CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
46     createPlMenuBar( menuBar(), p_intf );
47
48     selector = new PLSelector( centralWidget(), p_intf, THEPL );
49     selector->setMaximumWidth( 130 );
50
51     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
52                                                 THEPL->p_local_category );
53
54     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( centralWidget(),
55                               p_intf, THEPL, p_root ) );
56     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
57
58     QHBoxLayout *layout = new QHBoxLayout();
59     layout->addWidget( selector, 0 );
60     layout->addWidget( rightPanel, 10 );
61     centralWidget()->setLayout( layout );
62     readSettings( "playlist", QSize( 600,700 ) );
63 }
64
65 PlaylistDialog::~PlaylistDialog()
66 {
67     writeSettings( "playlist" );
68 }
69
70 void PlaylistDialog::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
71 {
72     QMenu *manageMenu = new QMenu();
73     manageMenu->setTitle( qtr("Add") );
74
75     QMenu *subPlaylist = new QMenu();
76     subPlaylist->setTitle( qtr("Add to current playlist") );
77     subPlaylist->addAction( "&File...", THEDP,
78                            SLOT( simplePLAppendDialog() ) );
79     subPlaylist->addAction( "&Advanced add...", THEDP,
80                            SLOT( PLAppendDialog() ) );
81     manageMenu->addMenu( subPlaylist );
82     manageMenu->addSeparator();
83
84     QMenu *subML = new QMenu();
85     subML->setTitle( qtr("Add to Media library") );
86     subML->addAction( "&File...", THEDP,
87                            SLOT( simpleMLAppendDialog() ) );
88     subML->addAction( "Directory", THEDP, SLOT( openMLDirectory() ));
89     subML->addAction( "&Advanced add...", THEDP,
90                            SLOT( MLAppendDialog() ) );
91     manageMenu->addMenu( subML );
92     manageMenu->addAction( "Open playlist file", THEDP, SLOT( openPlaylist() ));
93
94     bar->addMenu( manageMenu );
95     bar->addMenu( SDMenu() );
96 }
97
98 QMenu *PlaylistDialog::SDMenu()
99 {
100     QMenu *menu = new QMenu();
101     menu->setTitle( qtr( "Additional sources" ) );
102     vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
103                                         FIND_ANYWHERE );
104     int i_num = 0;
105     for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
106     {
107         module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
108         if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
109             i_num++;
110     }
111     for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
112     {
113         module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
114         if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
115         {
116             QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
117             a->setCheckable( true );
118             /* hack to handle submodules properly */
119             int i = -1;
120             while( p_parser->pp_shortcuts[++i] != NULL );
121             i--;
122             if( playlist_IsServicesDiscoveryLoaded( THEPL,
123                  i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
124             {
125                 a->setChecked( true );
126             }
127             CONNECT( a , trigerred(), SDMapper, map() );
128             SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
129                                             p_parser->psz_object_name );
130             menu->addAction( a );
131         }
132     }
133     vlc_list_release( p_list );
134     return menu;
135 }
136
137 void PlaylistDialog::SDMenuAction( QString data )
138 {
139     char *psz_sd = data.toUtf8().data();
140     if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
141         playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
142     else
143         playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
144 }