1 /*****************************************************************************
2 * playlist.cpp : Playlist dialog
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 ******************************************************************************/
24 #include "dialogs/playlist.hpp"
25 #include "util/qvlcframe.hpp"
27 #include "components/playlist/panels.hpp"
28 #include "components/playlist/selector.hpp"
29 #include <QHBoxLayout>
30 #include <QSignalMapper>
34 #include "dialogs_provider.hpp"
36 PlaylistDialog *PlaylistDialog::instance = NULL;
38 PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
40 QWidget *main = new QWidget( this );
41 setCentralWidget( main );
42 setWindowTitle( qtr( "Playlist" ) );
44 SDMapper = new QSignalMapper();
45 CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
46 createPlMenuBar( menuBar(), p_intf );
48 selector = new PLSelector( centralWidget(), p_intf, THEPL );
49 selector->setMaximumWidth( 130 );
51 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
52 THEPL->p_local_category );
54 rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( centralWidget(),
55 p_intf, THEPL, p_root ) );
56 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
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 ) );
65 PlaylistDialog::~PlaylistDialog()
67 writeSettings( "playlist" );
70 void PlaylistDialog::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
72 QMenu *manageMenu = new QMenu();
73 manageMenu->setTitle( qtr("Add") );
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();
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() ));
94 bar->addMenu( manageMenu );
95 bar->addMenu( SDMenu() );
98 QMenu *PlaylistDialog::SDMenu()
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,
105 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
107 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
108 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
111 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
113 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
114 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
116 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
117 a->setCheckable( true );
118 /* hack to handle submodules properly */
120 while( p_parser->pp_shortcuts[++i] != NULL );
122 if( playlist_IsServicesDiscoveryLoaded( THEPL,
123 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
125 a->setChecked( true );
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 );
133 vlc_list_release( p_list );
137 void PlaylistDialog::SDMenuAction( QString data )
139 char *psz_sd = data.toUtf8().data();
140 if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
141 playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
143 playlist_ServicesDiscoveryRemove( THEPL, psz_sd );