1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
31 #include <vlc_input.h>
32 #include <vlc_demux.h>
33 #include <vlc_playlist.h>
34 #include <vlc_threads.h>
35 #include <vlc_window.h>
37 #include "dialogs.hpp"
38 #include "os_factory.hpp"
39 #include "os_loop.hpp"
40 #include "var_manager.hpp"
41 #include "vlcproc.hpp"
42 #include "theme_loader.hpp"
44 #include "theme_repository.hpp"
45 #include "../parser/interpreter.hpp"
46 #include "../commands/async_queue.hpp"
47 #include "../commands/cmd_quit.hpp"
48 #include "../commands/cmd_dialogs.hpp"
49 #include "../commands/cmd_minimize.hpp"
51 //---------------------------------------------------------------------------
52 // Exported interface functions.
53 //---------------------------------------------------------------------------
55 extern "C" __declspec( dllexport )
56 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
60 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
63 static int Open ( vlc_object_t * );
64 static void Close ( vlc_object_t * );
65 static void Run ( intf_thread_t * );
67 static int DemuxOpen( vlc_object_t * );
68 static int Demux( demux_t * );
69 static int DemuxControl( demux_t *, int, va_list );
71 //---------------------------------------------------------------------------
72 // Prototypes for configuration callbacks
73 //---------------------------------------------------------------------------
74 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
75 vlc_value_t oldVal, vlc_value_t newVal,
77 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
78 vlc_value_t oldVal, vlc_value_t newVal,
86 } skin_load = { NULL, VLC_STATIC_MUTEX };
88 //---------------------------------------------------------------------------
89 // Open: initialize interface
90 //---------------------------------------------------------------------------
91 static int Open( vlc_object_t *p_this )
93 intf_thread_t *p_intf = (intf_thread_t *)p_this;
95 // Allocate instance and initialize some members
96 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
97 if( p_intf->p_sys == NULL )
100 p_intf->pf_run = Run;
102 // Suscribe to messages bank
104 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
107 p_intf->p_sys->p_input = NULL;
108 p_intf->p_sys->p_playlist = pl_Hold( p_intf );
110 // Initialize "singleton" objects
111 p_intf->p_sys->p_logger = NULL;
112 p_intf->p_sys->p_queue = NULL;
113 p_intf->p_sys->p_dialogs = NULL;
114 p_intf->p_sys->p_interpreter = NULL;
115 p_intf->p_sys->p_osFactory = NULL;
116 p_intf->p_sys->p_osLoop = NULL;
117 p_intf->p_sys->p_varManager = NULL;
118 p_intf->p_sys->p_vlcProc = NULL;
119 p_intf->p_sys->p_repository = NULL;
122 p_intf->p_sys->p_theme = NULL;
124 // Create a variable to be notified of skins to be loaded
125 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
127 // Initialize singletons
128 if( OSFactory::instance( p_intf ) == NULL )
130 msg_Err( p_intf, "cannot initialize OSFactory" );
131 vlc_object_release( p_intf->p_sys->p_playlist );
133 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
137 if( AsyncQueue::instance( p_intf ) == NULL )
139 msg_Err( p_intf, "cannot initialize AsyncQueue" );
140 vlc_object_release( p_intf->p_sys->p_playlist );
142 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
146 if( Interpreter::instance( p_intf ) == NULL )
148 msg_Err( p_intf, "cannot instanciate Interpreter" );
149 vlc_object_release( p_intf->p_sys->p_playlist );
151 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
155 if( VarManager::instance( p_intf ) == NULL )
157 msg_Err( p_intf, "cannot instanciate VarManager" );
158 vlc_object_release( p_intf->p_sys->p_playlist );
160 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
164 if( VlcProc::instance( p_intf ) == NULL )
166 msg_Err( p_intf, "cannot initialize VLCProc" );
167 vlc_object_release( p_intf->p_sys->p_playlist );
169 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
173 vlc_mutex_lock( &skin_load.mutex );
174 skin_load.intf = p_intf;
175 vlc_mutex_unlock( &skin_load.mutex );
177 Dialogs::instance( p_intf );
178 ThemeRepository::instance( p_intf );
181 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
183 ThemeLoader *pLoader = new ThemeLoader( p_intf );
185 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
187 // Get the resource path and try to load the default skin
188 OSFactory *pOSFactory = OSFactory::instance( p_intf );
189 const list<string> &resPath = pOSFactory->getResourcePath();
190 const string &sep = pOSFactory->getDirSeparator();
192 list<string>::const_iterator it;
193 for( it = resPath.begin(); it != resPath.end(); it++ )
195 string path = (*it) + sep + "default.vlt";
196 if( pLoader->load( path ) )
198 // Theme loaded successfully
202 if( it == resPath.end() )
204 // Last chance: the user can select a new theme file
205 if( Dialogs::instance( p_intf ) )
207 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
208 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
209 pQueue->push( CmdGenericPtr( pCmd ) );
213 // No dialogs provider, just quit...
214 CmdQuit *pCmd = new CmdQuit( p_intf );
215 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
216 pQueue->push( CmdGenericPtr( pCmd ) );
218 "cannot show the \"open skin\" dialog: exiting...");
227 p_intf->b_should_run_on_first_thread = true;
230 return( VLC_SUCCESS );
233 //---------------------------------------------------------------------------
234 // Close: destroy interface
235 //---------------------------------------------------------------------------
236 static void Close( vlc_object_t *p_this )
238 intf_thread_t *p_intf = (intf_thread_t *)p_this;
240 vlc_mutex_lock( &skin_load.mutex );
241 skin_load.intf = NULL;
242 vlc_mutex_unlock( &skin_load.mutex);
244 // Destroy "singleton" objects
245 OSFactory::instance( p_intf )->destroyOSLoop();
246 ThemeRepository::destroy( p_intf );
247 Dialogs::destroy( p_intf );
248 Interpreter::destroy( p_intf );
249 AsyncQueue::destroy( p_intf );
250 VarManager::destroy( p_intf );
251 VlcProc::destroy( p_intf );
252 OSFactory::destroy( p_intf );
254 if( p_intf->p_sys->p_playlist )
256 vlc_object_release( p_intf->p_sys->p_playlist );
259 // Unsubscribe from messages bank
261 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
265 free( p_intf->p_sys );
269 //---------------------------------------------------------------------------
271 //---------------------------------------------------------------------------
272 static void Run( intf_thread_t *p_intf )
274 int canc = vlc_savecancel();
276 // Get the instance of OSLoop
277 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
279 // Enter the main event loop
282 // Delete the theme and save the configuration of the windows
283 if( p_intf->p_sys->p_theme )
285 p_intf->p_sys->p_theme->saveConfig();
286 delete p_intf->p_sys->p_theme;
287 p_intf->p_sys->p_theme = NULL;
289 vlc_restorecancel(canc);
293 // Callbacks for vout requests
294 static int WindowOpen( vlc_object_t *p_this )
296 vout_window_t *pWnd = (vout_window_t *)p_this;
297 intf_thread_t *pIntf = (intf_thread_t *)
298 vlc_object_find_name( p_this, "skins2", FIND_ANYWHERE );
303 /* FIXME: most probably not thread-safe,
304 * albeit no worse than ever before */
305 pWnd->handle = VlcProc::getWindow( pIntf, pWnd->vout,
306 &pWnd->pos_x, &pWnd->pos_y,
307 &pWnd->width, &pWnd->height );
308 pWnd->p_private = pIntf;
309 pWnd->control = &VlcProc::controlWindow;
314 static void WindowClose( vlc_object_t *p_this )
316 vout_window_t *pWnd = (vout_window_t *)p_this;
317 intf_thread_t *pIntf = (intf_thread_t *)p_this->p_private;
319 VlcProc::releaseWindow( pIntf, pWnd->handle );
322 //---------------------------------------------------------------------------
323 // DemuxOpen: initialize demux
324 //---------------------------------------------------------------------------
325 static int DemuxOpen( vlc_object_t *p_this )
327 demux_t *p_demux = (demux_t*)p_this;
328 intf_thread_t *p_intf;
332 p_demux->pf_demux = Demux;
333 p_demux->pf_control = DemuxControl;
335 // Test that we have a valid .vlt or .wsz file, based on the extension
336 // TODO: an actual check of the contents would be better...
337 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
338 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
343 vlc_mutex_lock( &skin_load.mutex );
344 p_intf = skin_load.intf;
346 vlc_object_hold( p_intf );
347 vlc_mutex_unlock( &skin_load.mutex );
351 playlist_t *p_playlist = pl_Hold( p_this );
352 // Make sure the item is deleted afterwards
353 /// \bug does not always work
354 playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
355 vlc_object_release( p_playlist );
357 var_SetString( p_intf, "skin-to-load", p_demux->psz_path );
358 vlc_object_release( p_intf );
363 "skin could not be loaded (not using skins2 intf)" );
370 //---------------------------------------------------------------------------
372 //---------------------------------------------------------------------------
373 static int Demux( demux_t *p_demux )
379 //---------------------------------------------------------------------------
381 //---------------------------------------------------------------------------
382 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
384 return demux_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
388 //---------------------------------------------------------------------------
390 //---------------------------------------------------------------------------
392 /// Callback for the systray configuration option
393 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
394 vlc_value_t oldVal, vlc_value_t newVal,
397 intf_thread_t *pIntf;
399 vlc_mutex_lock( &skin_load.mutex );
400 pIntf = skin_load.intf;
402 vlc_object_hold( pIntf );
403 vlc_mutex_unlock( &skin_load.mutex );
410 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
413 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
414 pQueue->push( CmdGenericPtr( pCmd ) );
418 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
419 pQueue->push( CmdGenericPtr( pCmd ) );
422 vlc_object_release( pIntf );
427 /// Callback for the systray configuration option
428 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
429 vlc_value_t oldVal, vlc_value_t newVal,
432 intf_thread_t *pIntf;
434 vlc_mutex_lock( &skin_load.mutex );
435 pIntf = skin_load.intf;
437 vlc_object_hold( pIntf );
438 vlc_mutex_unlock( &skin_load.mutex );
445 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
448 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
449 pQueue->push( CmdGenericPtr( pCmd ) );
453 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
454 pQueue->push( CmdGenericPtr( pCmd ) );
457 vlc_object_release( pIntf );
462 //---------------------------------------------------------------------------
464 //---------------------------------------------------------------------------
465 #define SKINS2_LAST N_("Skin to use")
466 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
467 #define SKINS2_CONFIG N_("Config of last used skin")
468 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
469 "This option is updated automatically, do not touch it." )
470 #define SKINS2_SYSTRAY N_("Systray icon")
471 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
472 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
473 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
474 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
475 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
476 " if you want. This is mainly useful when moving windows does not behave" \
478 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
479 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
482 set_category( CAT_INTERFACE )
483 set_subcategory( SUBCAT_INTERFACE_MAIN )
484 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
487 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
492 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
493 SKINS2_SYSTRAY_LONG, false );
494 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
495 SKINS2_TASKBAR_LONG, false );
496 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
497 SKINS2_TRANSPARENCY_LONG, false );
500 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
501 SKINS2_PLAYLIST_LONG, false );
502 set_shortname( N_("Skins"))
503 set_description( N_("Skinnable Interface") )
504 set_capability( "interface", 30 )
505 set_callbacks( Open, Close )
506 add_shortcut( "skins" )
509 set_capability( "vout_window", 51 )
510 set_callbacks( WindowOpen, WindowClose )
513 set_description( N_("Skins loader demux") )
514 set_capability( "demux", 5 )
515 set_callbacks( DemuxOpen, NULL )