1 /*****************************************************************************
2 * skin-main.cpp: skins plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: skin_main.cpp,v 1.6 2003/04/12 21:43:27 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 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
32 //--- SKIN ------------------------------------------------------------------
36 #include "os_dialog.h"
41 #include "themeloader.h"
43 #include "skin_common.h"
46 //---------------------------------------------------------------------------
48 // It is a global variable because we have C code for the parser, and we
49 // need to access C++ objects from there
50 //---------------------------------------------------------------------------
51 intf_thread_t *g_pIntf;
53 //---------------------------------------------------------------------------
54 // Exported interface functions.
55 //---------------------------------------------------------------------------
57 extern "C" __declspec( dllexport )
58 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
61 //---------------------------------------------------------------------------
63 //---------------------------------------------------------------------------
64 static int Open ( vlc_object_t * );
65 static void Close ( vlc_object_t * );
66 static void Run ( intf_thread_t * );
68 int SkinManage( intf_thread_t *p_intf );
69 void OSRun( intf_thread_t *p_intf );
71 //---------------------------------------------------------------------------
72 // Open: initialize interface
73 //---------------------------------------------------------------------------
74 static int Open ( vlc_object_t *p_this )
76 intf_thread_t *p_intf = (intf_thread_t *)p_this;
79 // Allocate instance and initialize some members
80 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
81 if( p_intf->p_sys == NULL )
83 msg_Err( p_intf, "out of memory" );
90 // Suscribe to messages bank
91 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
93 // Set no new theme when opening file
94 p_intf->p_sys->p_new_theme_file = NULL;
96 // Initialize Win32 thread
97 p_intf->p_sys->i_index = -1;
98 p_intf->p_sys->i_size = 0;
101 p_intf->p_sys->i_close_status = VLC_NOTHING;
103 p_intf->p_sys->p_input = NULL;
104 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
105 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
107 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
112 //---------------------------------------------------------------------------
113 // Close: destroy interface
114 //---------------------------------------------------------------------------
115 static void Close ( vlc_object_t *p_this )
117 intf_thread_t *p_intf = (intf_thread_t *)p_this;
120 if( p_intf->p_sys->p_input )
122 vlc_object_release( p_intf->p_sys->p_input );
125 if( p_intf->p_sys->p_playlist )
127 vlc_object_release( p_intf->p_sys->p_playlist );
130 // Delete theme, it's important to do it correctly
131 delete (OSTheme *)p_intf->p_sys->p_theme;
133 // Unsuscribe to messages bank
134 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
139 free( p_intf->p_sys );
143 //---------------------------------------------------------------------------
145 //---------------------------------------------------------------------------
146 static void Run( intf_thread_t *p_intf )
148 int a = OSAPI_GetTime();
151 char *skin_last = config_GetPsz( p_intf, "skin_last" );
152 ThemeLoader *Loader = new ThemeLoader( p_intf );
154 if( skin_last == NULL || ! Loader->Load( skin_last ) )
156 // Too bad, it failed. Let's try with the default theme
158 if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
161 string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
162 DIRECTORY_SEPARATOR + "skins" +
163 DIRECTORY_SEPARATOR + "default" +
164 DIRECTORY_SEPARATOR + "theme.xml";
166 /* FIXME: find VLC directory */
167 string default_dir = (string)"." +
168 DIRECTORY_SEPARATOR + "skins" +
169 DIRECTORY_SEPARATOR + "default" +
170 DIRECTORY_SEPARATOR + "theme.xml";
172 if( ! Loader->Load( default_dir ) )
175 // Last chance: the user can select a new theme file
177 // Initialize file structure
178 OpenFileDialog *OpenFile;
179 OpenFile = (OpenFileDialog *)new OSOpenFileDialog( NULL,
180 _("Open skin"), false );
181 OpenFile->AddFilter( _("Skin files"), "*.vlt" );
182 OpenFile->AddFilter( _("Skin files"), "*.xml" );
183 OpenFile->AddFilter( _("All files"), "*.*" );
186 if( OpenFile->Open() )
188 // try to load selected file
189 if( ! Loader->Load( OpenFile->FileList.front() ) )
191 // He, he, what the hell is he doing ?
209 p_intf->p_sys->p_theme->InitTheme();
210 p_intf->p_sys->p_theme->ShowTheme();
214 msg_Err( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
216 // Refresh the whole interface
217 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (int)true );
219 // Run interface message loop
223 //---------------------------------------------------------------------------
225 //---------------------------------------------------------------------------
226 #define DEFAULT_SKIN N_("Last skin actually used")
227 #define DEFAULT_SKIN_LONG N_("Last skin actually used")
228 #define SKIN_CONFIG N_("Config of last used skin")
229 #define SKIN_CONFIG_LONG N_("Config of last used skin")
230 #define SKIN_TRAY N_("Show application in system tray")
231 #define SKIN_TRAY_LONG N_("Show application in system tray")
232 #define SKIN_TASKBAR N_("Show application in taskbar")
233 #define SKIN_TASKBAR_LONG N_("Show application in taskbar")
236 add_string( "skin_last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
238 add_string( "skin_config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG,
240 add_bool( "show_in_tray", VLC_FALSE, NULL, SKIN_TRAY, SKIN_TRAY_LONG,
242 add_bool( "show_in_taskbar", VLC_TRUE, NULL, SKIN_TASKBAR,
243 SKIN_TASKBAR_LONG, VLC_FALSE );
244 set_description( _("Skinnable Interface") );
245 set_capability( "interface", 30 );
246 set_callbacks( Open, Close );
247 add_shortcut( "skins" );
251 //---------------------------------------------------------------------------
253 //---------------------------------------------------------------------------
254 int SkinManage( intf_thread_t *p_intf )
256 vlc_mutex_lock( &p_intf->change_lock );
259 if( p_intf->p_sys->p_input == NULL )
261 p_intf->p_sys->p_input = (input_thread_t *)
262 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
264 else if( p_intf->p_sys->p_input->b_dead )
266 vlc_object_release( p_intf->p_sys->p_input );
267 p_intf->p_sys->p_input = NULL;
270 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (long)false );
272 // Update the log window
273 //p_intf->p_sys->p_theme->UpdateLog( p_intf->p_sys->p_sub );
275 //-------------------------------------------------------------------------
276 if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
278 input_thread_t * p_input = p_intf->p_sys->p_input;
280 vlc_mutex_lock( &p_input->stream.stream_lock );
282 // Refresh sound volume
283 audio_volume_t volume;
285 // Get sound volume from VLC
286 aout_VolumeGet( p_intf, &volume);
289 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER,
291 p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
292 (long)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
296 //if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
298 #define p_area p_input->stream.p_selected_area
300 // Set value of sliders
301 long Value = SLIDER_RANGE *
302 p_input->stream.p_selected_area->i_tell /
303 p_input->stream.p_selected_area->i_size;
306 OSAPI_PostMessage( NULL, CTRL_SET_SLIDER, (unsigned int)
307 p_intf->p_sys->p_theme->EvtBank->Get( "time" ), (long)Value );
309 // Text char * for updating text controls
310 char *text = new char[OFFSETTOTIME_MAX_SIZE];
312 // Create end time text
313 input_OffsetToTime( p_intf->p_sys->p_input, &text[1],
314 p_area->i_size - p_area->i_tell );
316 p_intf->p_sys->p_theme->EvtBank->Get( "left_time" )
317 ->PostTextMessage( text );
319 // Create time text and update
320 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_tell );
321 p_intf->p_sys->p_theme->EvtBank->Get( "time" )
322 ->PostTextMessage( text );
324 // Create total time text
325 input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_size );
326 p_intf->p_sys->p_theme->EvtBank->Get( "total_time" )
327 ->PostTextMessage( text );
334 vlc_mutex_unlock( &p_input->stream.stream_lock );
336 //-------------------------------------------------------------------------
337 vlc_mutex_unlock( &p_intf->change_lock );
341 //---------------------------------------------------------------------------