1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "dialogs.hpp"
26 #include "../commands/async_queue.hpp"
27 #include "../commands/cmd_change_skin.hpp"
28 #include "../commands/cmd_quit.hpp"
29 #include "../commands/cmd_playlist.hpp"
30 #include "../commands/cmd_playtree.hpp"
31 #include <vlc_playlist.h>
33 /// Callback called when a new skin is chosen
34 void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg )
36 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
40 if( pArg->psz_results[0] )
42 // Create a change skin command
44 new CmdChangeSkin( pIntf, sFromLocale( pArg->psz_results[0] ) );
46 // Push the command in the asynchronous command queue
47 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
48 pQueue->push( CmdGenericPtr( pCmd ) );
51 else if( !pIntf->p_sys->p_theme )
53 // If no theme is already loaded, it's time to quit!
54 CmdQuit *pCmd = new CmdQuit( pIntf );
55 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
56 pQueue->push( CmdGenericPtr( pCmd ) );
60 void Dialogs::showPlaylistLoadCB( intf_dialog_args_t *pArg )
62 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
64 if( pArg->i_results && pArg->psz_results[0] )
66 // Create a Playlist Load command
67 CmdPlaylistLoad *pCmd =
68 new CmdPlaylistLoad( pIntf, sFromLocale( pArg->psz_results[0] ) );
70 // Push the command in the asynchronous command queue
71 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
72 pQueue->push( CmdGenericPtr( pCmd ) );
77 void Dialogs::showPlaylistSaveCB( intf_dialog_args_t *pArg )
79 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
81 if( pArg->i_results && pArg->psz_results[0] )
83 // Create a Playlist Save command
84 CmdPlaylistSave *pCmd =
85 new CmdPlaylistSave( pIntf, pArg->psz_results[0] );
87 // Push the command in the asynchronous command queue
88 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
89 pQueue->push( CmdGenericPtr( pCmd ) );
94 /// Callback called when the popup menu is requested
95 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
96 vlc_value_t old_val, vlc_value_t new_val, void *param )
98 Dialogs *p_dialogs = (Dialogs *)param;
99 p_dialogs->showPopupMenu( new_val.b_bool != 0, INTF_DIALOG_POPUPMENU );
105 Dialogs::Dialogs( intf_thread_t *pIntf ):
106 SkinObject( pIntf ), m_pProvider( NULL ), m_pModule( NULL )
113 if( m_pProvider && m_pModule )
115 // Detach the dialogs provider from its parent interface
116 vlc_object_detach( m_pProvider );
118 module_unneed( m_pProvider, m_pModule );
119 vlc_object_release( m_pProvider );
122 /* Unregister callbacks */
123 var_DelCallback( getIntf()->p_libvlc, "intf-popupmenu",
128 Dialogs *Dialogs::instance( intf_thread_t *pIntf )
130 if( ! pIntf->p_sys->p_dialogs )
132 Dialogs *pDialogs = new Dialogs( pIntf );
133 if( pDialogs->init() )
135 // Initialization succeeded
136 pIntf->p_sys->p_dialogs = pDialogs;
140 // Initialization failed
144 return pIntf->p_sys->p_dialogs;
148 void Dialogs::destroy( intf_thread_t *pIntf )
150 delete pIntf->p_sys->p_dialogs;
151 pIntf->p_sys->p_dialogs = NULL;
157 // Allocate descriptor
158 m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
159 sizeof( intf_thread_t ) );
160 if( m_pProvider == NULL )
163 m_pModule = module_need( m_pProvider, "dialogs provider", NULL, false );
164 if( m_pModule == NULL )
166 msg_Err( getIntf(), "no suitable dialogs provider found (hint: compile the qt4 plugin, and make sure it is loaded properly)" );
167 vlc_object_release( m_pProvider );
172 // Attach the dialogs provider to its parent interface
173 vlc_object_attach( m_pProvider, getIntf() );
175 // Initialize dialogs provider
176 // (returns as soon as initialization is done)
177 if( m_pProvider->pf_run )
179 m_pProvider->pf_run( m_pProvider );
182 /* Register callback for the intf-popupmenu variable */
183 var_AddCallback( getIntf()->p_libvlc, "intf-popupmenu",
190 void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
191 DlgCallback callback, int flags )
193 if( m_pProvider && m_pProvider->pf_show_dialog )
195 intf_dialog_args_t *p_arg = (intf_dialog_args_t*)
196 calloc( 1, sizeof( intf_dialog_args_t ) );
198 p_arg->psz_title = strdup( rTitle.c_str() );
199 p_arg->psz_extensions = strdup( rExtensions.c_str() );
201 p_arg->b_save = flags & kSAVE;
202 p_arg->b_multiple = flags & kMULTIPLE;
204 p_arg->p_arg = getIntf();
205 p_arg->pf_callback = callback;
207 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
213 void Dialogs::showChangeSkin()
215 showFileGeneric( _("Open a skin file"),
216 _("Skin files |*.vlt;*.wsz;*.xml"),
217 showChangeSkinCB, kOPEN );
221 void Dialogs::showPlaylistLoad()
223 showFileGeneric( _("Open playlist"),
224 _("Playlist Files|"EXTENSIONS_PLAYLIST"|"
226 showPlaylistLoadCB, kOPEN );
230 void Dialogs::showPlaylistSave()
232 showFileGeneric( _("Save playlist"), _("XSPF playlist|*.xspf|"
234 "HTML playlist|*.html"),
235 showPlaylistSaveCB, kSAVE );
238 void Dialogs::showPlaylist()
240 if( m_pProvider && m_pProvider->pf_show_dialog )
242 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PLAYLIST,
247 void Dialogs::showFileSimple( bool play )
249 if( m_pProvider && m_pProvider->pf_show_dialog )
251 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_SIMPLE,
257 void Dialogs::showFile( bool play )
259 if( m_pProvider && m_pProvider->pf_show_dialog )
261 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE,
267 void Dialogs::showDirectory( bool play )
269 if( m_pProvider && m_pProvider->pf_show_dialog )
271 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DIRECTORY,
277 void Dialogs::showDisc( bool play )
279 if( m_pProvider && m_pProvider->pf_show_dialog )
281 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DISC,
287 void Dialogs::showNet( bool play )
289 if( m_pProvider && m_pProvider->pf_show_dialog )
291 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_NET,
297 void Dialogs::showMessages()
299 if( m_pProvider && m_pProvider->pf_show_dialog )
301 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_MESSAGES, 0, NULL );
306 void Dialogs::showPrefs()
308 if( m_pProvider && m_pProvider->pf_show_dialog )
310 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PREFS, 0, NULL );
315 void Dialogs::showFileInfo()
317 if( m_pProvider && m_pProvider->pf_show_dialog )
319 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILEINFO, 0, NULL );
324 void Dialogs::showStreamingWizard()
326 if( m_pProvider && m_pProvider->pf_show_dialog )
328 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_WIZARD, 0, NULL );
333 void Dialogs::showPopupMenu( bool bShow, int popupType = INTF_DIALOG_POPUPMENU )
335 if( m_pProvider && m_pProvider->pf_show_dialog )
337 m_pProvider->pf_show_dialog( m_pProvider, popupType,
342 void Dialogs::showInteraction( interaction_dialog_t *p_dialog )
344 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)
345 calloc( 1, sizeof(intf_dialog_args_t) );
347 p_arg->p_dialog = p_dialog;
348 p_arg->p_intf = getIntf();
350 if( m_pProvider && m_pProvider->pf_show_dialog )
352 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_INTERACTION,