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