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>
32 #include <vlc_modules.h>
34 /// Callback called when a new skin is chosen
35 void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg )
37 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
41 if( pArg->psz_results[0] )
43 // Create a change skin command
45 new CmdChangeSkin( pIntf, sFromLocale( pArg->psz_results[0] ) );
47 // Push the command in the asynchronous command queue
48 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
49 pQueue->push( CmdGenericPtr( pCmd ) );
52 else if( !pIntf->p_sys->p_theme )
54 // If no theme is already loaded, it's time to quit!
55 CmdQuit *pCmd = new CmdQuit( pIntf );
56 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
57 pQueue->push( CmdGenericPtr( pCmd ) );
61 void Dialogs::showPlaylistLoadCB( intf_dialog_args_t *pArg )
63 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
65 if( pArg->i_results && pArg->psz_results[0] )
67 // Create a Playlist Load command
68 CmdPlaylistLoad *pCmd =
69 new CmdPlaylistLoad( pIntf, sFromLocale( pArg->psz_results[0] ) );
71 // Push the command in the asynchronous command queue
72 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
73 pQueue->push( CmdGenericPtr( pCmd ) );
78 void Dialogs::showPlaylistSaveCB( intf_dialog_args_t *pArg )
80 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
82 if( pArg->i_results && pArg->psz_results[0] )
84 // Create a Playlist Save command
85 CmdPlaylistSave *pCmd =
86 new CmdPlaylistSave( pIntf, pArg->psz_results[0] );
88 // Push the command in the asynchronous command queue
89 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
90 pQueue->push( CmdGenericPtr( pCmd ) );
95 /// Callback called when the popup menu is requested
96 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
97 vlc_value_t old_val, vlc_value_t new_val, void *param )
99 (void)p_this; (void)psz_variable; (void)old_val;
101 Dialogs *p_dialogs = (Dialogs *)param;
102 p_dialogs->showPopupMenu( new_val.b_bool != 0, INTF_DIALOG_POPUPMENU );
108 Dialogs::Dialogs( intf_thread_t *pIntf ):
109 SkinObject( pIntf ), m_pProvider( NULL ), m_pModule( NULL )
116 if( m_pProvider && m_pModule )
118 // Detach the dialogs provider from its parent interface
119 module_unneed( m_pProvider, m_pModule );
120 vlc_object_release( m_pProvider );
122 /* Unregister callbacks */
123 var_DelCallback( getIntf()->p_libvlc, "intf-popupmenu",
129 Dialogs *Dialogs::instance( intf_thread_t *pIntf )
131 if( ! pIntf->p_sys->p_dialogs )
133 Dialogs *pDialogs = new Dialogs( pIntf );
134 if( pDialogs->init() )
136 // Initialization succeeded
137 pIntf->p_sys->p_dialogs = pDialogs;
141 // Initialization failed
145 return pIntf->p_sys->p_dialogs;
149 void Dialogs::destroy( intf_thread_t *pIntf )
151 delete pIntf->p_sys->p_dialogs;
152 pIntf->p_sys->p_dialogs = NULL;
158 // Allocate descriptor
159 m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
160 sizeof( intf_thread_t ) );
161 if( m_pProvider == NULL )
164 m_pModule = module_need( m_pProvider, "dialogs provider", NULL, false );
165 if( m_pModule == NULL )
167 msg_Err( getIntf(), "no suitable dialogs provider found (hint: compile the qt4 plugin, and make sure it is loaded properly)" );
168 vlc_object_release( m_pProvider );
173 /* Register callback for the intf-popupmenu variable */
174 var_AddCallback( getIntf()->p_libvlc, "intf-popupmenu",
181 void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
182 DlgCallback callback, int flags )
184 if( m_pProvider && m_pProvider->pf_show_dialog )
186 intf_dialog_args_t *p_arg = (intf_dialog_args_t*)
187 calloc( 1, sizeof( intf_dialog_args_t ) );
189 p_arg->psz_title = strdup( rTitle.c_str() );
190 p_arg->psz_extensions = strdup( rExtensions.c_str() );
192 p_arg->b_save = flags & kSAVE;
193 p_arg->b_multiple = flags & kMULTIPLE;
195 p_arg->p_arg = getIntf();
196 p_arg->pf_callback = callback;
198 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
204 void Dialogs::showChangeSkin()
206 showFileGeneric( _("Open a skin file"),
207 _("Skin files |*.vlt;*.wsz;*.xml"),
208 showChangeSkinCB, kOPEN );
212 void Dialogs::showPlaylistLoad()
214 showFileGeneric( _("Open playlist"),
215 _("Playlist Files|"EXTENSIONS_PLAYLIST"|"
217 showPlaylistLoadCB, kOPEN );
221 void Dialogs::showPlaylistSave()
223 showFileGeneric( _("Save playlist"), _("XSPF playlist|*.xspf|"
225 "HTML playlist|*.html"),
226 showPlaylistSaveCB, kSAVE );
229 void Dialogs::showPlaylist()
231 if( m_pProvider && m_pProvider->pf_show_dialog )
233 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PLAYLIST,
238 void Dialogs::showFileSimple( bool play )
240 if( m_pProvider && m_pProvider->pf_show_dialog )
242 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_SIMPLE,
248 void Dialogs::showFile( bool play )
250 if( m_pProvider && m_pProvider->pf_show_dialog )
252 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE,
258 void Dialogs::showDirectory( bool play )
260 if( m_pProvider && m_pProvider->pf_show_dialog )
262 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DIRECTORY,
268 void Dialogs::showDisc( bool play )
270 if( m_pProvider && m_pProvider->pf_show_dialog )
272 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DISC,
278 void Dialogs::showNet( bool play )
280 if( m_pProvider && m_pProvider->pf_show_dialog )
282 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_NET,
288 void Dialogs::showMessages()
290 if( m_pProvider && m_pProvider->pf_show_dialog )
292 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_MESSAGES, 0, NULL );
297 void Dialogs::showPrefs()
299 if( m_pProvider && m_pProvider->pf_show_dialog )
301 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PREFS, 0, NULL );
306 void Dialogs::showFileInfo()
308 if( m_pProvider && m_pProvider->pf_show_dialog )
310 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILEINFO, 0, NULL );
315 void Dialogs::showStreamingWizard()
317 if( m_pProvider && m_pProvider->pf_show_dialog )
319 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_WIZARD, 0, NULL );
324 void Dialogs::showPopupMenu( bool bShow, int popupType = INTF_DIALOG_POPUPMENU )
326 if( m_pProvider && m_pProvider->pf_show_dialog )
328 m_pProvider->pf_show_dialog( m_pProvider, popupType,
333 void Dialogs::showInteraction( interaction_dialog_t *p_dialog )
335 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)
336 calloc( 1, sizeof(intf_dialog_args_t) );
338 p_arg->p_dialog = p_dialog;
339 p_arg->p_intf = getIntf();
341 if( m_pProvider && m_pProvider->pf_show_dialog )
343 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_INTERACTION,