1 /*****************************************************************************
2 * skin-main.cpp: skins plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: skin_main.cpp,v 1.18 2003/04/23 10:29:52 asmax Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
26 //--- GENERAL ---------------------------------------------------------------
29 //--- VLC -------------------------------------------------------------------
34 //--- SKIN ------------------------------------------------------------------
35 #include "../os_api.h"
40 #include "../os_theme.h"
41 #include "themeloader.h"
43 #include "skin_common.h"
44 #include "wxdialogs.h"
47 //---------------------------------------------------------------------------
49 // It is a global variable because we have C code for the parser, and we
50 // need to access C++ objects from there
51 //---------------------------------------------------------------------------
52 intf_thread_t *g_pIntf;
54 //---------------------------------------------------------------------------
55 // Exported interface functions.
56 //---------------------------------------------------------------------------
58 extern "C" __declspec( dllexport )
59 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
62 //---------------------------------------------------------------------------
64 //---------------------------------------------------------------------------
65 static int Open ( vlc_object_t * );
66 static void Close ( vlc_object_t * );
67 static void Run ( intf_thread_t * );
69 int SkinManage( intf_thread_t *p_intf );
70 void OSRun( intf_thread_t *p_intf );
72 //---------------------------------------------------------------------------
73 // Open: initialize interface
74 //---------------------------------------------------------------------------
75 static int Open ( vlc_object_t *p_this )
77 intf_thread_t *p_intf = (intf_thread_t *)p_this;
80 // Allocate instance and initialize some members
81 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
82 if( p_intf->p_sys == NULL )
84 msg_Err( p_intf, "out of memory" );
91 // Suscribe to messages bank
92 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
94 // Set no new theme when opening file
95 p_intf->p_sys->p_new_theme_file = NULL;
97 // Initialize Win32 thread
98 p_intf->p_sys->i_index = -1;
99 p_intf->p_sys->i_size = 0;
102 p_intf->p_sys->i_close_status = VLC_NOTHING;
104 p_intf->p_sys->p_input = NULL;
105 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
106 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
111 char *p_args[] = { "", "", "--sync", NULL };
112 char **pp_args = p_args;
114 gdk_init( &i_args, &pp_args );
117 // Initialize conditions and mutexes
118 vlc_mutex_init( p_intf, &p_intf->p_sys->init_lock );
119 vlc_cond_init( p_intf, &p_intf->p_sys->init_cond );
121 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
126 //---------------------------------------------------------------------------
127 // Close: destroy interface
128 //---------------------------------------------------------------------------
129 static void Close ( vlc_object_t *p_this )
131 intf_thread_t *p_intf = (intf_thread_t *)p_this;
134 if( p_intf->p_sys->p_input )
136 vlc_object_release( p_intf->p_sys->p_input );
139 if( p_intf->p_sys->p_playlist )
141 vlc_object_release( p_intf->p_sys->p_playlist );
144 // Delete theme, it's important to do it correctly
145 delete (OSTheme *)p_intf->p_sys->p_theme;
147 // Unsuscribe to messages bank
148 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
150 // Destroy conditions and mutexes
151 vlc_cond_destroy( &p_intf->p_sys->init_cond );
152 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
155 free( p_intf->p_sys );
159 //---------------------------------------------------------------------------
161 //---------------------------------------------------------------------------
162 static void Run( intf_thread_t *p_intf )
165 int a = OSAPI_GetTime();
168 char *skin_last = config_GetPsz( p_intf, "skin_last" );
169 ThemeLoader *Loader = new ThemeLoader( p_intf );
171 if( skin_last == NULL || ! Loader->Load( skin_last ) )
173 // Too bad, it failed. Let's try with the default theme
175 if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
178 string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
179 DIRECTORY_SEPARATOR + "skins" +
180 DIRECTORY_SEPARATOR + "default" +
181 DIRECTORY_SEPARATOR + "theme.xml";
183 // FIXME: find VLC directory
184 string default_dir = (string)"./share" +
185 DIRECTORY_SEPARATOR + "skins" +
186 DIRECTORY_SEPARATOR + "default" +
187 DIRECTORY_SEPARATOR + "theme.xml";
189 if( ! Loader->Load( default_dir ) )
192 // Last chance: the user can select a new theme file
193 wxFileDialog dialog( NULL, _("Open a skin file"), "", "",
194 "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
195 "All files|*.*", wxOPEN );
197 if( dialog.ShowModal() == wxID_OK )
199 // try to load selected file
200 if( ! Loader->Load( dialog.GetPath().c_str() ) )
202 // He, he, what the hell is he doing ?
216 p_intf->p_sys->p_theme->InitTheme();
217 p_intf->p_sys->p_theme->ShowTheme();
221 msg_Err( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
223 // Refresh the whole interface
224 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (int)true );
229 //---------------------------------------------------------------------------
231 //---------------------------------------------------------------------------
232 #define DEFAULT_SKIN N_("Last skin actually used")
233 #define DEFAULT_SKIN_LONG N_("Last skin actually used")
234 #define SKIN_CONFIG N_("Config of last used skin")
235 #define SKIN_CONFIG_LONG N_("Config of last used skin")
236 #define SKIN_TRAY N_("Show application in system tray")
237 #define SKIN_TRAY_LONG N_("Show application in system tray")
238 #define SKIN_TASKBAR N_("Show application in taskbar")
239 #define SKIN_TASKBAR_LONG N_("Show application in taskbar")
242 add_string( "skin_last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
244 add_string( "skin_config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG,
246 add_bool( "show_in_tray", VLC_FALSE, NULL, SKIN_TRAY, SKIN_TRAY_LONG,
248 add_bool( "show_in_taskbar", VLC_TRUE, NULL, SKIN_TASKBAR,
249 SKIN_TASKBAR_LONG, VLC_FALSE );
250 set_description( _("Skinnable Interface") );
251 set_capability( "interface", 30 );
252 set_callbacks( Open, Close );
253 add_shortcut( "skins" );
257 //---------------------------------------------------------------------------
259 //---------------------------------------------------------------------------
260 int SkinManage( intf_thread_t *p_intf )
262 vlc_mutex_lock( &p_intf->change_lock );
265 if( p_intf->p_sys->p_input == NULL )
267 p_intf->p_sys->p_input = (input_thread_t *)
268 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
270 else if( p_intf->p_sys->p_input->b_dead )
272 vlc_object_release( p_intf->p_sys->p_input );
273 p_intf->p_sys->p_input = NULL;
276 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (long)false );
278 // Update the log window
279 p_intf->p_sys->MessagesDlg->UpdateLog();
281 // Update the file info window
282 p_intf->p_sys->InfoDlg->UpdateFileInfo();
284 //-------------------------------------------------------------------------
285 if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
287 input_thread_t * p_input = p_intf->p_sys->p_input;
289 vlc_mutex_lock( &p_input->stream.stream_lock );
291 // Refresh sound volume
292 audio_volume_t volume;
294 // Get sound volume from VLC
295 aout_VolumeGet( p_intf, &volume);
298 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER,
300 p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
301 (long)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
305 // if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
306 if( p_input->stream.b_seekable )
308 #define p_area p_input->stream.p_selected_area
310 // Set value of sliders
311 long Value = SLIDER_RANGE *
312 p_input->stream.p_selected_area->i_tell /
313 p_input->stream.p_selected_area->i_size;
316 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER, (unsigned int)
317 p_intf->p_sys->p_theme->EvtBank->Get( "time" ), (long)Value );
319 // Text char * for updating text controls
320 char *text = new char[OFFSETTOTIME_MAX_SIZE];
322 // Create end time text
323 input_OffsetToTime( p_intf->p_sys->p_input, &text[1],
324 p_area->i_size - p_area->i_tell );
326 p_intf->p_sys->p_theme->EvtBank->Get( "left_time" )
327 ->PostTextMessage( text );
329 // Create time text and update
330 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_tell );
331 p_intf->p_sys->p_theme->EvtBank->Get( "time" )
332 ->PostTextMessage( text );
334 // Create total time text
335 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_size );
336 p_intf->p_sys->p_theme->EvtBank->Get( "total_time" )
337 ->PostTextMessage( text );
344 vlc_mutex_unlock( &p_input->stream.stream_lock );
346 //-------------------------------------------------------------------------
347 vlc_mutex_unlock( &p_intf->change_lock );