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., 59 Temple Place - Suite 330, Boston, MA 02111, 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"
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, pArg->psz_results[0] );
46 // Push the command in the asynchronous command queue
47 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
48 pQueue->remove( "change skin" );
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 ) );
62 void Dialogs::showPlaylistLoadCB( intf_dialog_args_t *pArg )
64 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
66 if( pArg->i_results && pArg->psz_results[0] )
68 // Create a Playlist Load command
69 CmdPlaylistLoad *pCmd =
70 new CmdPlaylistLoad( pIntf, pArg->psz_results[0] );
72 // Push the command in the asynchronous command queue
73 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
74 pQueue->remove( "load playlist" );
75 pQueue->remove( "load playtree" );
76 pQueue->push( CmdGenericPtr( pCmd ) );
81 void Dialogs::showPlaylistSaveCB( intf_dialog_args_t *pArg )
83 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
85 if( pArg->i_results && pArg->psz_results[0] )
87 // Create a Playlist Save command
88 CmdPlaylistSave *pCmd =
89 new CmdPlaylistSave( pIntf, pArg->psz_results[0] );
91 // Push the command in the asynchronous command queue
92 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
93 pQueue->remove( "load playlist" );
94 pQueue->remove( "load playtree" );
95 pQueue->push( CmdGenericPtr( pCmd ) );
100 /// Callback called when the popup menu is requested
101 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
102 vlc_value_t old_val, vlc_value_t new_val, void *param )
104 Dialogs *p_dialogs = (Dialogs *)param;
105 p_dialogs->showPopupMenu( new_val.b_bool != 0 );
111 Dialogs::Dialogs( intf_thread_t *pIntf ):
112 SkinObject( pIntf ), m_pProvider( NULL ), m_pModule( NULL )
119 if( m_pProvider && m_pModule )
121 // Detach the dialogs provider from its parent interface
122 vlc_object_detach( m_pProvider );
124 module_Unneed( m_pProvider, m_pModule );
125 vlc_object_destroy( m_pProvider );
128 /* Unregister callbacks */
129 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
134 Dialogs *Dialogs::instance( intf_thread_t *pIntf )
136 if( ! pIntf->p_sys->p_dialogs )
138 Dialogs *pDialogs = new Dialogs( pIntf );
139 if( pDialogs->init() )
141 // Initialization succeeded
142 pIntf->p_sys->p_dialogs = pDialogs;
146 // Initialization failed
150 return pIntf->p_sys->p_dialogs;
154 void Dialogs::destroy( intf_thread_t *pIntf )
156 if( pIntf->p_sys->p_dialogs )
158 delete pIntf->p_sys->p_dialogs;
159 pIntf->p_sys->p_dialogs = NULL;
166 // Allocate descriptor
167 m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
168 VLC_OBJECT_DIALOGS );
169 if( m_pProvider == NULL )
171 msg_Err( getIntf(), "out of memory" );
175 m_pModule = module_Need( m_pProvider, "dialogs provider", NULL, 0 );
176 if( m_pModule == NULL )
178 msg_Err( getIntf(), "No suitable dialogs provider found" );
179 vlc_object_destroy( m_pProvider );
184 // Attach the dialogs provider to its parent interface
185 vlc_object_attach( m_pProvider, getIntf() );
187 // Initialize dialogs provider
188 // (returns as soon as initialization is done)
189 if( m_pProvider->pf_run )
191 m_pProvider->pf_run( m_pProvider );
194 /* Register callback for the intf-popupmenu variable */
195 var_AddCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
202 void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
203 DlgCallback callback, int flags )
205 if( m_pProvider && m_pProvider->pf_show_dialog )
207 intf_dialog_args_t *p_arg =
208 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
209 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
211 p_arg->psz_title = strdup( rTitle.c_str() );
212 p_arg->psz_extensions = strdup( rExtensions.c_str() );
214 p_arg->b_save = flags & kSAVE;
215 p_arg->b_multiple = flags & kMULTIPLE;
217 p_arg->p_arg = getIntf();
218 p_arg->pf_callback = callback;
220 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
226 void Dialogs::showChangeSkin()
228 showFileGeneric( _("Open a skin file"),
229 _("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml"),
230 showChangeSkinCB, kOPEN );
234 void Dialogs::showPlaylistLoad()
236 showFileGeneric( _("Open playlist"),
237 _("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"),
238 showPlaylistLoadCB, kOPEN );
242 void Dialogs::showPlaylistSave()
244 showFileGeneric( _("Save playlist"), _("M3U file|*.m3u"),
245 showPlaylistSaveCB, kSAVE );
249 void Dialogs::showFileSimple( bool play )
251 if( m_pProvider && m_pProvider->pf_show_dialog )
253 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_SIMPLE,
259 void Dialogs::showFile( bool play )
261 if( m_pProvider && m_pProvider->pf_show_dialog )
263 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE,
269 void Dialogs::showDirectory( bool play )
271 if( m_pProvider && m_pProvider->pf_show_dialog )
273 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DIRECTORY,
279 void Dialogs::showDisc( bool play )
281 if( m_pProvider && m_pProvider->pf_show_dialog )
283 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DISC,
289 void Dialogs::showNet( bool play )
291 if( m_pProvider && m_pProvider->pf_show_dialog )
293 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_NET,
299 void Dialogs::showMessages()
301 if( m_pProvider && m_pProvider->pf_show_dialog )
303 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_MESSAGES, 0, 0 );
308 void Dialogs::showPrefs()
310 if( m_pProvider && m_pProvider->pf_show_dialog )
312 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PREFS, 0, 0 );
317 void Dialogs::showFileInfo()
319 if( m_pProvider && m_pProvider->pf_show_dialog )
321 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILEINFO, 0, 0 );
326 void Dialogs::showStreamingWizard()
328 if( m_pProvider && m_pProvider->pf_show_dialog )
330 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_WIZARD, 0, 0 );
335 void Dialogs::showPopupMenu( bool bShow )
337 if( m_pProvider && m_pProvider->pf_show_dialog )
339 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_POPUPMENU,