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 if( pIntf->p_sys->p_dialogs )
152 delete pIntf->p_sys->p_dialogs;
153 pIntf->p_sys->p_dialogs = NULL;
160 // Allocate descriptor
161 m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
162 sizeof( intf_thread_t ) );
163 if( m_pProvider == NULL )
166 m_pModule = module_need( m_pProvider, "dialogs provider", NULL, false );
167 if( m_pModule == NULL )
169 msg_Err( getIntf(), "no suitable dialogs provider found (hint: compile the qt4 plugin, and make sure it is loaded properly)" );
170 vlc_object_release( m_pProvider );
175 // Attach the dialogs provider to its parent interface
176 vlc_object_attach( m_pProvider, getIntf() );
178 // Initialize dialogs provider
179 // (returns as soon as initialization is done)
180 if( m_pProvider->pf_run )
182 m_pProvider->pf_run( m_pProvider );
185 /* Register callback for the intf-popupmenu variable */
186 var_AddCallback( getIntf()->p_libvlc, "intf-popupmenu",
193 void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
194 DlgCallback callback, int flags )
196 if( m_pProvider && m_pProvider->pf_show_dialog )
198 intf_dialog_args_t *p_arg = (intf_dialog_args_t*)
199 calloc( 1, sizeof( intf_dialog_args_t ) );
201 p_arg->psz_title = strdup( rTitle.c_str() );
202 p_arg->psz_extensions = strdup( rExtensions.c_str() );
204 p_arg->b_save = flags & kSAVE;
205 p_arg->b_multiple = flags & kMULTIPLE;
207 p_arg->p_arg = getIntf();
208 p_arg->pf_callback = callback;
210 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
216 void Dialogs::showChangeSkin()
218 showFileGeneric( _("Open a skin file"),
219 _("Skin files |*.vlt;*.wsz;*.xml"),
220 showChangeSkinCB, kOPEN );
224 void Dialogs::showPlaylistLoad()
226 showFileGeneric( _("Open playlist"),
227 _("Playlist Files|"EXTENSIONS_PLAYLIST"|"
229 showPlaylistLoadCB, kOPEN );
233 void Dialogs::showPlaylistSave()
235 showFileGeneric( _("Save playlist"), _("XSPF playlist|*.xspf|"
237 "HTML playlist|*.html"),
238 showPlaylistSaveCB, kSAVE );
241 void Dialogs::showPlaylist()
243 if( m_pProvider && m_pProvider->pf_show_dialog )
245 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PLAYLIST,
250 void Dialogs::showFileSimple( bool play )
252 if( m_pProvider && m_pProvider->pf_show_dialog )
254 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_SIMPLE,
260 void Dialogs::showFile( bool play )
262 if( m_pProvider && m_pProvider->pf_show_dialog )
264 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE,
270 void Dialogs::showDirectory( bool play )
272 if( m_pProvider && m_pProvider->pf_show_dialog )
274 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DIRECTORY,
280 void Dialogs::showDisc( bool play )
282 if( m_pProvider && m_pProvider->pf_show_dialog )
284 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DISC,
290 void Dialogs::showNet( bool play )
292 if( m_pProvider && m_pProvider->pf_show_dialog )
294 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_NET,
300 void Dialogs::showMessages()
302 if( m_pProvider && m_pProvider->pf_show_dialog )
304 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_MESSAGES, 0, NULL );
309 void Dialogs::showPrefs()
311 if( m_pProvider && m_pProvider->pf_show_dialog )
313 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PREFS, 0, NULL );
318 void Dialogs::showFileInfo()
320 if( m_pProvider && m_pProvider->pf_show_dialog )
322 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILEINFO, 0, NULL );
327 void Dialogs::showStreamingWizard()
329 if( m_pProvider && m_pProvider->pf_show_dialog )
331 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_WIZARD, 0, NULL );
336 void Dialogs::showPopupMenu( bool bShow, int popupType = INTF_DIALOG_POPUPMENU )
338 if( m_pProvider && m_pProvider->pf_show_dialog )
340 m_pProvider->pf_show_dialog( m_pProvider, popupType,
345 void Dialogs::showInteraction( interaction_dialog_t *p_dialog )
347 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)
348 calloc( 1, sizeof(intf_dialog_args_t) );
350 p_arg->p_dialog = p_dialog;
351 p_arg->p_intf = getIntf();
353 if( m_pProvider && m_pProvider->pf_show_dialog )
355 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_INTERACTION,