]> git.sesse.net Git - vlc/blob - modules/gui/skins/src/dialogs.cpp
* modules/gui/wxwindows/*: don't forget to delete the timer.
[vlc] / modules / gui / skins / src / dialogs.cpp
1 /*****************************************************************************
2  * dialogs.cpp: Handles all the different dialog boxes we provide.
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: dialogs.cpp,v 1.15 2003/10/14 22:41:41 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111,
22  * USA.
23  *****************************************************************************/
24
25 //--- VLC -------------------------------------------------------------------
26 #include <vlc/vlc.h>
27 #include <vlc/intf.h>
28
29 //--- SKIN ------------------------------------------------------------------
30 #include "../os_api.h"
31 #include "event.h"
32 #include "banks.h"
33 #include "theme.h"
34 #include "../os_theme.h"
35 #include "themeloader.h"
36 #include "window.h"
37 #include "vlcproc.h"
38 #include "skin_common.h"
39 #include "dialogs.h"
40
41 /* Callback prototype */
42 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
43                        vlc_value_t old_val, vlc_value_t new_val, void *param );
44
45 //---------------------------------------------------------------------------
46 // Implementation of Dialogs class
47 //---------------------------------------------------------------------------
48 Dialogs::Dialogs( intf_thread_t *_p_intf )
49 {
50     /* Errors while loading the dialogs provider are not fatal.
51      * Dialogs just won't be available. */
52
53     p_intf = _p_intf;
54     p_intf->p_sys->p_dialogs = this;
55     b_popup_change = VLC_FALSE;
56
57     /* Allocate descriptor */
58     p_provider = (intf_thread_t *)vlc_object_create( p_intf,
59                                                      VLC_OBJECT_DIALOGS );
60     if( p_provider == NULL )
61     {
62         msg_Err( p_intf, "out of memory" );
63         return;
64     }
65
66     p_module = module_Need( p_provider, "dialogs provider", NULL );
67     if( p_module == NULL )
68     {
69         msg_Err( p_intf, "no suitable dialogs provider found" );
70         vlc_object_destroy( p_provider );
71         p_provider = NULL;
72         return;
73     }
74
75     /* Attach the dialogs provider to its parent interface */
76     vlc_object_attach( p_provider, p_intf );
77
78     /* Initialize dialogs provider
79      * (returns as soon as initialization is done) */
80     if( p_provider->pf_run ) p_provider->pf_run( p_provider );
81
82     /* Register callback for the intf-popupmenu variable */
83     playlist_t *p_playlist =
84         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
85                                        FIND_ANYWHERE );
86     if( p_playlist != NULL )
87     {
88         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,
89                          p_intf->p_sys->p_dialogs );
90         vlc_object_release( p_playlist );
91     }
92 }
93
94 Dialogs::~Dialogs()
95 {
96     if( p_provider && p_module )
97     {
98         /* Detach the dialogs provider from its parent interface */
99         vlc_object_detach( p_provider );
100
101         module_Unneed( p_provider, p_module );
102         vlc_object_destroy( p_provider );
103     }
104 }
105
106 void Dialogs::ShowOpen( bool b_play )
107 {
108     if( p_provider && p_provider->pf_show_dialog )
109         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE,
110                                     (int)b_play, 0 );
111 }
112
113 void Dialogs::ShowNet()
114 {
115     if( p_provider && p_provider->pf_show_dialog )
116         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_NET, 0, 0 );
117 }
118
119
120 static void ShowOpenSkinCallback( intf_dialog_args_t *p_arg )
121 {
122     if( p_arg->i_results )
123     {
124         intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
125         p_intf->p_sys->p_new_theme_file = strdup( p_arg->psz_results[0] );
126
127         if( !p_arg->b_blocking )
128         {
129             // Tell vlc to change skin after hiding interface
130             OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
131         }
132     }
133 }
134
135 void Dialogs::ShowOpenSkin( bool b_block )
136 {
137     if( p_provider && p_provider->pf_show_dialog )
138     {
139         intf_dialog_args_t *p_arg =
140             (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
141         memset( p_arg, 0, sizeof(intf_dialog_args_t) );
142
143         p_arg->b_blocking = b_block;
144         if( b_block )
145         {
146             vlc_mutex_init( p_intf, &p_arg->lock );
147             vlc_cond_init( p_intf, &p_arg->wait );
148         }
149
150         p_arg->psz_title = strdup( _("Open a skin file") );
151         p_arg->psz_extensions =
152             strdup( "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|" );
153
154         p_arg->p_arg = p_intf;
155         p_arg->pf_callback = ShowOpenSkinCallback;
156
157         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE_GENERIC,
158                                     0, p_arg );
159
160         if( b_block )
161         {
162             vlc_mutex_lock( &p_arg->lock );
163             if( !p_arg->b_ready )
164             {
165                 vlc_cond_wait( &p_arg->wait, &p_arg->lock );
166             }
167             vlc_mutex_unlock( &p_arg->lock );
168         }
169     }
170 }
171
172 void Dialogs::ShowMessages()
173 {
174     if( p_provider && p_provider->pf_show_dialog )
175         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_MESSAGES, 0, 0 );
176 }
177
178 void Dialogs::ShowPrefs()
179 {
180     if( p_provider && p_provider->pf_show_dialog )
181         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_PREFS, 0, 0 );
182 }
183
184 void Dialogs::ShowFileInfo()
185 {
186     if( p_provider && p_provider->pf_show_dialog )
187         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILEINFO, 0, 0 );
188 }
189
190 void Dialogs::ShowPopup( bool b_show )
191 {
192     if( p_provider && p_provider->pf_show_dialog )
193         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_POPUPMENU,
194                                     b_show, 0 );
195 }
196
197 /*****************************************************************************
198  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
199  *  We don't show the menu directly here because we don't want the
200  *  caller to block for a too long time.
201  *****************************************************************************/
202 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
203                         vlc_value_t old_val, vlc_value_t new_val, void *param )
204 {
205     Dialogs *p_dialogs = (Dialogs *)param;
206     p_dialogs->ShowPopup( new_val.b_bool );
207
208     return VLC_SUCCESS;
209 }