1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
6 * Authors: Cyril Deguet <asmax@via.ecp.fr>
7 * Olivier Teulière <ipkiss@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
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_legacy.h>
32 #include <vlc_modules.h>
35 /// Callback called when a new skin is chosen
36 void Dialogs::showChangeSkinCB( intf_dialog_args_t
*pArg
)
38 intf_thread_t
*pIntf
= (intf_thread_t
*)pArg
->p_arg
;
42 if( pArg
->psz_results
[0] )
44 char* psz_path
= vlc_uri2path( pArg
->psz_results
[0] );
47 // Create a change skin command
49 new CmdChangeSkin( pIntf
, psz_path
);
52 // Push the command in the asynchronous command queue
53 AsyncQueue
*pQueue
= AsyncQueue::instance( pIntf
);
54 pQueue
->push( CmdGenericPtr( pCmd
) );
58 else if( !pIntf
->p_sys
->p_theme
)
60 // If no theme is already loaded, it's time to quit!
61 CmdQuit
*pCmd
= new CmdQuit( pIntf
);
62 AsyncQueue
*pQueue
= AsyncQueue::instance( pIntf
);
63 pQueue
->push( CmdGenericPtr( pCmd
) );
67 void Dialogs::showPlaylistLoadCB( intf_dialog_args_t
*pArg
)
69 intf_thread_t
*pIntf
= (intf_thread_t
*)pArg
->p_arg
;
71 if( pArg
->i_results
&& pArg
->psz_results
[0] )
73 // Create a Playlist Load command
74 CmdPlaylistLoad
*pCmd
=
75 new CmdPlaylistLoad( pIntf
, pArg
->psz_results
[0] );
77 // Push the command in the asynchronous command queue
78 AsyncQueue
*pQueue
= AsyncQueue::instance( pIntf
);
79 pQueue
->push( CmdGenericPtr( pCmd
) );
84 void Dialogs::showPlaylistSaveCB( intf_dialog_args_t
*pArg
)
86 intf_thread_t
*pIntf
= (intf_thread_t
*)pArg
->p_arg
;
88 if( pArg
->i_results
&& pArg
->psz_results
[0] )
90 // Create a Playlist Save command
91 CmdPlaylistSave
*pCmd
=
92 new CmdPlaylistSave( pIntf
, pArg
->psz_results
[0] );
94 // Push the command in the asynchronous command queue
95 AsyncQueue
*pQueue
= AsyncQueue::instance( pIntf
);
96 pQueue
->push( CmdGenericPtr( pCmd
) );
101 /// Callback called when the popup menu is requested
102 static int PopupMenuCB( vlc_object_t
*p_this
, const char *psz_variable
,
103 vlc_value_t old_val
, vlc_value_t new_val
, void *param
)
105 (void)p_this
; (void)psz_variable
; (void)old_val
;
107 Dialogs
*p_dialogs
= (Dialogs
*)param
;
108 p_dialogs
->showPopupMenu( new_val
.b_bool
!= 0, INTF_DIALOG_POPUPMENU
);
114 Dialogs::Dialogs( intf_thread_t
*pIntf
):
115 SkinObject( pIntf
), m_pProvider( NULL
), m_pModule( NULL
)
122 if( m_pProvider
&& m_pModule
)
124 // Detach the dialogs provider from its parent interface
125 module_unneed( m_pProvider
, m_pModule
);
126 vlc_object_release( m_pProvider
);
128 /* Unregister callbacks */
129 var_DelCallback( pl_Get(getIntf()), "intf-popupmenu",
135 Dialogs
*Dialogs::instance( intf_thread_t
*pIntf
)
137 if( ! pIntf
->p_sys
->p_dialogs
)
139 Dialogs
*pDialogs
= new Dialogs( pIntf
);
140 if( pDialogs
->init() )
142 // Initialization succeeded
143 pIntf
->p_sys
->p_dialogs
= pDialogs
;
147 // Initialization failed
151 return pIntf
->p_sys
->p_dialogs
;
155 void Dialogs::destroy( intf_thread_t
*pIntf
)
157 delete pIntf
->p_sys
->p_dialogs
;
158 pIntf
->p_sys
->p_dialogs
= NULL
;
164 // Allocate descriptor
165 m_pProvider
= (intf_thread_t
*)vlc_object_create( getIntf(),
166 sizeof( intf_thread_t
) );
167 if( m_pProvider
== NULL
)
170 m_pModule
= module_need( m_pProvider
, "dialogs provider", NULL
, false );
171 if( m_pModule
== NULL
)
173 vlc_object_release( m_pProvider
);
178 /* Register callback for the intf-popupmenu variable */
179 var_AddCallback( pl_Get(getIntf()), "intf-popupmenu",
186 void Dialogs::showFileGeneric( const std::string
&rTitle
, const std::string
&rExtensions
,
187 DlgCallback callback
, int flags
)
189 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
191 intf_dialog_args_t
*p_arg
= (intf_dialog_args_t
*)
192 calloc( 1, sizeof( intf_dialog_args_t
) );
194 p_arg
->psz_title
= strdup( rTitle
.c_str() );
195 p_arg
->psz_extensions
= strdup( rExtensions
.c_str() );
197 p_arg
->b_save
= flags
& kSAVE
;
198 p_arg
->b_multiple
= flags
& kMULTIPLE
;
200 p_arg
->p_arg
= getIntf();
201 p_arg
->pf_callback
= callback
;
203 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_FILE_GENERIC
,
209 void Dialogs::showChangeSkin()
211 showFileGeneric( _("Open a skin file"),
212 _("Skin files |*.vlt;*.wsz;*.xml"),
213 showChangeSkinCB
, kOPEN
);
217 void Dialogs::showPlaylistLoad()
219 std::stringstream fileTypes
;
220 fileTypes
<< _("Playlist Files |") << EXTENSIONS_PLAYLIST
<< _("|All Files |*");
221 showFileGeneric( _("Open playlist"),
223 showPlaylistLoadCB
, kOPEN
);
227 void Dialogs::showPlaylistSave()
229 showFileGeneric( _("Save playlist"), _("XSPF playlist |*.xspf|"
231 "HTML playlist |*.html"),
232 showPlaylistSaveCB
, kSAVE
);
235 void Dialogs::showPlaylist()
237 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
239 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_PLAYLIST
,
244 void Dialogs::showFileSimple( bool play
)
246 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
248 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_FILE_SIMPLE
,
254 void Dialogs::showFile( bool play
)
256 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
258 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_FILE
,
264 void Dialogs::showDirectory( bool play
)
266 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
268 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_DIRECTORY
,
274 void Dialogs::showDisc( bool play
)
276 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
278 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_DISC
,
284 void Dialogs::showNet( bool play
)
286 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
288 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_NET
,
294 void Dialogs::showMessages()
296 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
298 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_MESSAGES
, 0, NULL
);
303 void Dialogs::showPrefs()
305 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
307 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_PREFS
, 0, NULL
);
312 void Dialogs::showFileInfo()
314 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
316 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_FILEINFO
, 0, NULL
);
321 void Dialogs::showStreamingWizard()
323 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
325 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_WIZARD
, 0, NULL
);
330 void Dialogs::showPopupMenu( bool bShow
, int popupType
= INTF_DIALOG_POPUPMENU
)
332 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
334 m_pProvider
->pf_show_dialog( m_pProvider
, popupType
,
339 void Dialogs::showInteraction( interaction_dialog_t
*p_dialog
)
341 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
343 intf_dialog_args_t
*p_arg
= (intf_dialog_args_t
*)
344 calloc( 1, sizeof(intf_dialog_args_t
) );
346 p_arg
->p_dialog
= p_dialog
;
347 p_arg
->p_intf
= getIntf();
349 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_INTERACTION
,
354 void Dialogs::sendKey( int key
)
356 if( m_pProvider
&& m_pProvider
->pf_show_dialog
)
358 m_pProvider
->pf_show_dialog( m_pProvider
, INTF_DIALOG_SENDKEY
,