]> git.sesse.net Git - vlc/blob - modules/gui/skins/src/dialogs.cpp
38b65247cb43a7c0f09c19c236747f88ffa99800
[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.14 2003/09/05 15:55:30 asmax 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, VLC_OBJECT_INTF );
59     if( p_provider == NULL )
60     {
61         msg_Err( p_intf, "out of memory" );
62         return;
63     }
64
65     p_module = module_Need( p_provider, "dialogs provider", NULL );
66     if( p_module == NULL )
67     {
68         msg_Err( p_intf, "no suitable dialogs provider found" );
69         vlc_object_destroy( p_provider );
70         p_provider = NULL;
71         return;
72     }
73
74     /* Initialize dialogs provider
75      * (returns as soon as initialization is done) */
76     if( p_provider->pf_run ) p_provider->pf_run( p_provider );
77
78     /* Register callback for the intf-popupmenu variable */
79     playlist_t *p_playlist =
80         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
81                                        FIND_ANYWHERE );
82     if( p_playlist != NULL )
83     {
84         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,
85                          p_intf->p_sys->p_dialogs );
86         vlc_object_release( p_playlist );
87     }
88 }
89
90 Dialogs::~Dialogs()
91 {
92     if( p_provider && p_module )
93     {
94         module_Unneed( p_provider, p_module );
95         vlc_object_destroy( p_provider );
96     }
97 }
98
99 void Dialogs::ShowOpen( bool b_play )
100 {
101     if( p_provider && p_provider->pf_show_dialog )
102         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE,
103                                     (int)b_play, 0 );
104 }
105
106 void Dialogs::ShowNet()
107 {
108     if( p_provider && p_provider->pf_show_dialog )
109         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_NET, 0, 0 );
110 }
111
112
113 static void ShowOpenSkinCallback( intf_dialog_args_t *p_arg )
114 {
115     if( p_arg->i_results )
116     {
117         intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
118         p_intf->p_sys->p_new_theme_file = strdup( p_arg->psz_results[0] );
119
120         if( !p_arg->b_blocking )
121         {
122             // Tell vlc to change skin after hiding interface
123             OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
124         }
125     }
126 }
127
128 void Dialogs::ShowOpenSkin( bool b_block )
129 {
130     if( p_provider && p_provider->pf_show_dialog )
131     {
132         intf_dialog_args_t *p_arg =
133             (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
134         memset( p_arg, 0, sizeof(intf_dialog_args_t) );
135
136         p_arg->b_blocking = b_block;
137         if( b_block )
138         {
139             vlc_mutex_init( p_intf, &p_arg->lock );
140             vlc_cond_init( p_intf, &p_arg->wait );
141         }
142
143         p_arg->psz_title = strdup( _("Open a skin file") );
144         p_arg->psz_extensions =
145             strdup( "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|" );
146
147         p_arg->p_arg = p_intf;
148         p_arg->pf_callback = ShowOpenSkinCallback;
149
150         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE_GENERIC,
151                                     0, p_arg );
152
153         if( b_block )
154         {
155             vlc_mutex_lock( &p_arg->lock );
156             if( !p_arg->b_ready )
157             {
158                 vlc_cond_wait( &p_arg->wait, &p_arg->lock );
159             }
160             vlc_mutex_unlock( &p_arg->lock );
161         }
162     }
163 }
164
165 void Dialogs::ShowMessages()
166 {
167     if( p_provider && p_provider->pf_show_dialog )
168         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_MESSAGES, 0, 0 );
169 }
170
171 void Dialogs::ShowPrefs()
172 {
173     if( p_provider && p_provider->pf_show_dialog )
174         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_PREFS, 0, 0 );
175 }
176
177 void Dialogs::ShowFileInfo()
178 {
179     if( p_provider && p_provider->pf_show_dialog )
180         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILEINFO, 0, 0 );
181 }
182
183 void Dialogs::ShowPopup( bool b_show )
184 {
185     if( p_provider && p_provider->pf_show_dialog )
186         p_provider->pf_show_dialog( p_provider, INTF_DIALOG_POPUPMENU,
187                                     b_show, 0 );
188 }
189
190 /*****************************************************************************
191  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
192  *  We don't show the menu directly here because we don't want the
193  *  caller to block for a too long time.
194  *****************************************************************************/
195 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
196                         vlc_value_t old_val, vlc_value_t new_val, void *param )
197 {
198     Dialogs *p_dialogs = (Dialogs *)param;
199     p_dialogs->ShowPopup( new_val.b_bool );
200
201     return VLC_SUCCESS;
202 }