1 /*****************************************************************************
2 * dialogs.cpp: Handles all the different dialog boxes we provide.
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: dialogs.cpp,v 1.12 2003/07/20 10:38:49 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111,
23 *****************************************************************************/
25 //--- VLC -------------------------------------------------------------------
29 //--- SKIN ------------------------------------------------------------------
30 #include "../os_api.h"
34 #include "../os_theme.h"
35 #include "themeloader.h"
38 #include "skin_common.h"
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 );
45 //---------------------------------------------------------------------------
46 // Implementation of Dialogs class
47 //---------------------------------------------------------------------------
48 Dialogs::Dialogs( intf_thread_t *_p_intf )
50 /* Errors while loading the dialogs provider are not fatal.
51 * Dialogs just won't be available. */
54 p_intf->p_sys->p_dialogs = this;
55 b_popup_change = VLC_FALSE;
57 /* Allocate descriptor */
58 p_provider = (intf_thread_t *)vlc_object_create( p_intf, VLC_OBJECT_INTF );
59 if( p_provider == NULL )
61 msg_Err( p_intf, "out of memory" );
65 p_module = module_Need( p_provider, "dialogs provider", NULL );
66 if( p_module == NULL )
68 msg_Err( p_intf, "no suitable dialogs provider found" );
69 vlc_object_destroy( p_provider );
74 /* Initialize dialogs provider
75 * (returns as soon as initialization is done) */
76 if( p_provider->pf_run ) p_provider->pf_run( p_provider );
78 /* Register callback for the intf-popupmenu variable */
79 playlist_t *p_playlist =
80 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
82 if( p_playlist != NULL )
84 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,
85 p_intf->p_sys->p_dialogs );
86 vlc_object_release( p_playlist );
92 if( p_provider && p_module )
94 module_Unneed( p_provider, p_module );
95 vlc_object_destroy( p_provider );
99 void Dialogs::ShowOpen( bool b_play )
101 if( p_provider && p_provider->pf_show_dialog )
102 p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE,
106 static void ShowOpenSkinCallback( intf_dialog_args_t *p_arg )
108 if( p_arg->i_results )
110 intf_thread_t *p_intf = (intf_thread_t *)p_arg->p_arg;
111 p_intf->p_sys->p_new_theme_file = strdup( p_arg->psz_results[0] );
113 if( !p_arg->b_blocking )
115 // Tell vlc to change skin after hiding interface
116 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
121 void Dialogs::ShowOpenSkin( bool b_block )
123 if( p_provider && p_provider->pf_show_dialog )
125 intf_dialog_args_t *p_arg =
126 (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
127 memset( p_arg, 0, sizeof(intf_dialog_args_t) );
129 p_arg->b_blocking = b_block;
132 vlc_mutex_init( p_intf, &p_arg->lock );
133 vlc_cond_init( p_intf, &p_arg->wait );
136 p_arg->psz_title = strdup( _("Open a skin file") );
137 p_arg->psz_extensions =
138 strdup( "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|" );
140 p_arg->p_arg = p_intf;
141 p_arg->pf_callback = ShowOpenSkinCallback;
143 p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE_GENERIC,
148 vlc_mutex_lock( &p_arg->lock );
149 if( !p_arg->b_ready )
151 vlc_cond_wait( &p_arg->wait, &p_arg->lock );
153 vlc_mutex_unlock( &p_arg->lock );
158 void Dialogs::ShowMessages()
160 if( p_provider && p_provider->pf_show_dialog )
161 p_provider->pf_show_dialog( p_provider, INTF_DIALOG_MESSAGES, 0, 0 );
164 void Dialogs::ShowPrefs()
166 if( p_provider && p_provider->pf_show_dialog )
167 p_provider->pf_show_dialog( p_provider, INTF_DIALOG_PREFS, 0, 0 );
170 void Dialogs::ShowFileInfo()
172 if( p_provider && p_provider->pf_show_dialog )
173 p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILEINFO, 0, 0 );
176 void Dialogs::ShowPopup()
178 if( p_provider && p_provider->pf_show_dialog )
179 p_provider->pf_show_dialog( p_provider, INTF_DIALOG_POPUPMENU, 0, 0 );
182 /*****************************************************************************
183 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
184 * We don't show the menu directly here because we don't want the
185 * caller to block for a too long time.
186 *****************************************************************************/
187 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
188 vlc_value_t old_val, vlc_value_t new_val, void *param )
190 Dialogs *p_dialogs = (Dialogs *)param;
191 p_dialogs->ShowPopup();