]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/dialogs.cpp
lower case the module_* functions
[vlc] / modules / gui / skins2 / src / dialogs.cpp
1 /*****************************************************************************
2  * dialogs.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
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
33 /// Callback called when a new skin is chosen
34 void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg )
35 {
36     intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
37
38     if( pArg->i_results )
39     {
40         if( pArg->psz_results[0] )
41         {
42             // Create a change skin command
43             CmdChangeSkin *pCmd =
44                 new CmdChangeSkin( pIntf, sFromLocale( pArg->psz_results[0] ) );
45
46             // Push the command in the asynchronous command queue
47             AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
48             pQueue->push( CmdGenericPtr( pCmd ) );
49         }
50     }
51     else if( !pIntf->p_sys->p_theme )
52     {
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 ) );
57     }
58 }
59
60 void Dialogs::showPlaylistLoadCB( intf_dialog_args_t *pArg )
61 {
62     intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
63
64     if( pArg->i_results && pArg->psz_results[0] )
65     {
66         // Create a Playlist Load command
67         CmdPlaylistLoad *pCmd =
68             new CmdPlaylistLoad( pIntf, sFromLocale( pArg->psz_results[0] ) );
69
70         // Push the command in the asynchronous command queue
71         AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
72         pQueue->push( CmdGenericPtr( pCmd ) );
73     }
74 }
75
76
77 void Dialogs::showPlaylistSaveCB( intf_dialog_args_t *pArg )
78 {
79     intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
80
81     if( pArg->i_results && pArg->psz_results[0] )
82     {
83         // Create a Playlist Save command
84         CmdPlaylistSave *pCmd =
85             new CmdPlaylistSave( pIntf, pArg->psz_results[0] );
86
87         // Push the command in the asynchronous command queue
88         AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
89         pQueue->push( CmdGenericPtr( pCmd ) );
90     }
91 }
92
93
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 )
97 {
98     Dialogs *p_dialogs = (Dialogs *)param;
99     p_dialogs->showPopupMenu( new_val.b_bool != 0, INTF_DIALOG_POPUPMENU );
100
101     return VLC_SUCCESS;
102 }
103
104
105 Dialogs::Dialogs( intf_thread_t *pIntf ):
106     SkinObject( pIntf ), m_pProvider( NULL ), m_pModule( NULL )
107 {
108 }
109
110
111 Dialogs::~Dialogs()
112 {
113     if( m_pProvider && m_pModule )
114     {
115         // Detach the dialogs provider from its parent interface
116         vlc_object_detach( m_pProvider );
117
118         module_unneed( m_pProvider, m_pModule );
119         vlc_object_release( m_pProvider );
120     }
121
122     /* Unregister callbacks */
123     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
124                      PopupMenuCB, this );
125 }
126
127
128 Dialogs *Dialogs::instance( intf_thread_t *pIntf )
129 {
130     if( ! pIntf->p_sys->p_dialogs )
131     {
132         Dialogs *pDialogs = new Dialogs( pIntf );
133         if( pDialogs->init() )
134         {
135             // Initialization succeeded
136             pIntf->p_sys->p_dialogs = pDialogs;
137         }
138         else
139         {
140             // Initialization failed
141             delete pDialogs;
142         }
143     }
144     return pIntf->p_sys->p_dialogs;
145 }
146
147
148 void Dialogs::destroy( intf_thread_t *pIntf )
149 {
150     if( pIntf->p_sys->p_dialogs )
151     {
152         delete pIntf->p_sys->p_dialogs;
153         pIntf->p_sys->p_dialogs = NULL;
154     }
155 }
156
157
158 bool Dialogs::init()
159 {
160     // Allocate descriptor
161     m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
162                                                     sizeof( intf_thread_t ) );
163     if( m_pProvider == NULL )
164     {
165         msg_Err( getIntf(), "out of memory" );
166         return false;
167     }
168
169     m_pModule = module_need( m_pProvider, "dialogs provider", NULL, 0 );
170     if( m_pModule == NULL )
171     {
172         msg_Err( getIntf(), "no suitable dialogs provider found (hint: compile the qt4 plugin, and make sure it is loaded properly)" );
173         vlc_object_release( m_pProvider );
174         m_pProvider = NULL;
175         return false;
176     }
177
178     // Attach the dialogs provider to its parent interface
179     vlc_object_attach( m_pProvider, getIntf() );
180
181     // Initialize dialogs provider
182     // (returns as soon as initialization is done)
183     if( m_pProvider->pf_run )
184     {
185         m_pProvider->pf_run( m_pProvider );
186     }
187
188     /* Register callback for the intf-popupmenu variable */
189     var_AddCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
190                      PopupMenuCB, this );
191
192     return true;
193 }
194
195
196 void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
197                                DlgCallback callback, int flags )
198 {
199     if( m_pProvider && m_pProvider->pf_show_dialog )
200     {
201         intf_dialog_args_t *p_arg =
202             (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
203         memset( p_arg, 0, sizeof(intf_dialog_args_t) );
204
205         p_arg->psz_title = strdup( rTitle.c_str() );
206         p_arg->psz_extensions = strdup( rExtensions.c_str() );
207
208         p_arg->b_save = flags & kSAVE;
209         p_arg->b_multiple = flags & kMULTIPLE;
210
211         p_arg->p_arg = getIntf();
212         p_arg->pf_callback = callback;
213
214         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
215                                      0, p_arg );
216     }
217 }
218
219
220 void Dialogs::showChangeSkin()
221 {
222     showFileGeneric( _("Open a skin file"),
223                      _("Skin files (*.vlt;*.wsz)|*.vlt;*.wsz|Skin files (*.xml)|*.xml"),
224                      showChangeSkinCB, kOPEN );
225 }
226
227
228 void Dialogs::showPlaylistLoad()
229 {
230     showFileGeneric( _("Open playlist"),
231                      _("All playlists|*.pls;*.m3u;*.asx;*.b4s;*.xspf|"
232                        "M3U files|*.m3u|"
233                        "XSPF playlist|*.xspf"),
234                      showPlaylistLoadCB, kOPEN );
235 }
236
237
238 void Dialogs::showPlaylistSave()
239 {
240     showFileGeneric( _("Save playlist"), _("XSPF playlist|*.xspf|M3U file|*.m3u"),
241                      showPlaylistSaveCB, kSAVE );
242 }
243
244 void Dialogs::showPlaylist()
245 {
246     if( m_pProvider && m_pProvider->pf_show_dialog )
247     {
248         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PLAYLIST,
249                                      0, 0 );
250     }
251 }
252
253 void Dialogs::showFileSimple( bool play )
254 {
255     if( m_pProvider && m_pProvider->pf_show_dialog )
256     {
257         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_SIMPLE,
258                                      (int)play, 0 );
259     }
260 }
261
262
263 void Dialogs::showFile( bool play )
264 {
265     if( m_pProvider && m_pProvider->pf_show_dialog )
266     {
267         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE,
268                                      (int)play, 0 );
269     }
270 }
271
272
273 void Dialogs::showDirectory( bool play )
274 {
275     if( m_pProvider && m_pProvider->pf_show_dialog )
276     {
277         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DIRECTORY,
278                                      (int)play, 0 );
279     }
280 }
281
282
283 void Dialogs::showDisc( bool play )
284 {
285     if( m_pProvider && m_pProvider->pf_show_dialog )
286     {
287         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DISC,
288                                      (int)play, 0 );
289     }
290 }
291
292
293 void Dialogs::showNet( bool play )
294 {
295     if( m_pProvider && m_pProvider->pf_show_dialog )
296     {
297         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_NET,
298                                      (int)play, 0 );
299     }
300 }
301
302
303 void Dialogs::showMessages()
304 {
305     if( m_pProvider && m_pProvider->pf_show_dialog )
306     {
307         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_MESSAGES, 0, 0 );
308     }
309 }
310
311
312 void Dialogs::showPrefs()
313 {
314     if( m_pProvider && m_pProvider->pf_show_dialog )
315     {
316         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PREFS, 0, 0 );
317     }
318 }
319
320
321 void Dialogs::showFileInfo()
322 {
323     if( m_pProvider && m_pProvider->pf_show_dialog )
324     {
325         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILEINFO, 0, 0 );
326     }
327 }
328
329
330 void Dialogs::showStreamingWizard()
331 {
332     if( m_pProvider && m_pProvider->pf_show_dialog )
333     {
334         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_WIZARD, 0, 0 );
335     }
336 }
337
338
339 void Dialogs::showPopupMenu( bool bShow, int popupType = INTF_DIALOG_POPUPMENU )
340 {
341     if( m_pProvider && m_pProvider->pf_show_dialog )
342     {
343         m_pProvider->pf_show_dialog( m_pProvider, popupType,
344                                      (int)bShow, 0 );
345     }
346 }
347
348 void Dialogs::showInteraction( interaction_dialog_t *p_dialog )
349 {
350     intf_dialog_args_t *p_arg =
351             (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
352     memset( p_arg, 0, sizeof(intf_dialog_args_t) );
353
354     p_arg->p_dialog = p_dialog;
355     p_arg->p_intf = getIntf();
356
357     if( m_pProvider && m_pProvider->pf_show_dialog )
358     {
359         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_INTERACTION,
360                                      0, p_arg );
361     }
362 }