1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
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"
32 /// Callback called when a new skin is chosen
33 void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg )
35 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
39 if( pArg->psz_results[0] )
41 // Create a change skin command
43 new CmdChangeSkin( pIntf, pArg->psz_results[0] );
45 // Push the command in the asynchronous command queue
46 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
47 pQueue->remove( "change skin" );
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 ) );
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, pArg->psz_results[0] );
71 // Push the command in the asynchronous command queue
72 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
73 pQueue->remove( "load playlist" );
74 pQueue->push( CmdGenericPtr( pCmd ) );
79 void Dialogs::showPlaylistSaveCB( intf_dialog_args_t *pArg )
81 intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
83 if( pArg->i_results && pArg->psz_results[0] )
85 // Create a Playlist Save command
86 CmdPlaylistSave *pCmd =
87 new CmdPlaylistSave( pIntf, pArg->psz_results[0] );
89 // Push the command in the asynchronous command queue
90 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
91 pQueue->remove( "load playlist" );
92 pQueue->push( CmdGenericPtr( pCmd ) );
97 /// Callback called when the popup menu is requested
98 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
99 vlc_value_t old_val, vlc_value_t new_val, void *param )
101 Dialogs *p_dialogs = (Dialogs *)param;
102 p_dialogs->showPopupMenu( new_val.b_bool );
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 vlc_object_detach( m_pProvider );
121 module_Unneed( m_pProvider, m_pModule );
122 vlc_object_destroy( m_pProvider );
125 /* Unregister callbacks */
126 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
131 Dialogs *Dialogs::instance( intf_thread_t *pIntf )
133 if( ! pIntf->p_sys->p_dialogs )
135 Dialogs *pDialogs = new Dialogs( pIntf );
136 if( pDialogs->init() )
138 // Initialization succeeded
139 pIntf->p_sys->p_dialogs = pDialogs;
143 // Initialization failed
147 return pIntf->p_sys->p_dialogs;
151 void Dialogs::destroy( intf_thread_t *pIntf )
153 if( pIntf->p_sys->p_dialogs )
155 delete pIntf->p_sys->p_dialogs;
156 pIntf->p_sys->p_dialogs = NULL;
163 // Allocate descriptor
164 m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
165 VLC_OBJECT_DIALOGS );
166 if( m_pProvider == NULL )
168 msg_Err( getIntf(), "out of memory" );
172 m_pModule = module_Need( m_pProvider, "dialogs provider", NULL, 0 );
173 if( m_pModule == NULL )
175 msg_Err( getIntf(), "No suitable dialogs provider found" );
176 vlc_object_destroy( m_pProvider );
181 // Attach the dialogs provider to its parent interface
182 vlc_object_attach( m_pProvider, getIntf() );
184 // Initialize dialogs provider
185 // (returns as soon as initialization is done)
186 if( m_pProvider->pf_run )
188 m_pProvider->pf_run( m_pProvider );
191 /* Register callback for the intf-popupmenu variable */
192 var_AddCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
199 void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
200 DlgCallback callback, int flags )
202 if( m_pProvider && m_pProvider->pf_show_dialog )
204 intf_dialog_args_t *p_arg =
205 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
206 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
208 p_arg->psz_title = strdup( rTitle.c_str() );
209 p_arg->psz_extensions = strdup( rExtensions.c_str() );
211 p_arg->b_save = flags & kSAVE;
212 p_arg->b_multiple = flags & kMULTIPLE;
214 p_arg->p_arg = getIntf();
215 p_arg->pf_callback = callback;
217 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
223 void Dialogs::showChangeSkin()
225 showFileGeneric( _("Open a skin file"),
226 _("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"),
227 showChangeSkinCB, kOPEN );
231 void Dialogs::showPlaylistLoad()
233 showFileGeneric( _("Open playlist"),
234 _("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"),
235 showPlaylistLoadCB, kOPEN );
239 void Dialogs::showPlaylistSave()
241 showFileGeneric( _("Save playlist"), _("M3U file|*.m3u"),
242 showPlaylistSaveCB, kSAVE );
246 void Dialogs::showFileSimple( bool play )
248 if( m_pProvider && m_pProvider->pf_show_dialog )
250 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_SIMPLE,
256 void Dialogs::showFile( bool play )
258 if( m_pProvider && m_pProvider->pf_show_dialog )
260 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE,
266 void Dialogs::showDisc( bool play )
268 if( m_pProvider && m_pProvider->pf_show_dialog )
270 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DISC,
276 void Dialogs::showNet( bool play )
278 if( m_pProvider && m_pProvider->pf_show_dialog )
280 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_NET,
286 void Dialogs::showMessages()
288 if( m_pProvider && m_pProvider->pf_show_dialog )
290 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_MESSAGES, 0, 0 );
295 void Dialogs::showPrefs()
297 if( m_pProvider && m_pProvider->pf_show_dialog )
299 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PREFS, 0, 0 );
304 void Dialogs::showFileInfo()
306 if( m_pProvider && m_pProvider->pf_show_dialog )
308 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILEINFO, 0, 0 );
313 void Dialogs::showPopupMenu( bool bShow )
315 if( m_pProvider && m_pProvider->pf_show_dialog )
317 m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_POPUPMENU,