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 *****************************************************************************/
26 #include <vlc/input.h>
27 #include "dialogs.hpp"
28 #include "os_factory.hpp"
29 #include "os_loop.hpp"
30 #include "var_manager.hpp"
31 #include "vlcproc.hpp"
32 #include "theme_loader.hpp"
34 #include "theme_repository.hpp"
35 #include "../parser/interpreter.hpp"
36 #include "../commands/async_queue.hpp"
37 #include "../commands/cmd_quit.hpp"
38 #include "../commands/cmd_dialogs.hpp"
39 #include "../commands/cmd_minimize.hpp"
42 //---------------------------------------------------------------------------
43 // Exported interface functions.
44 //---------------------------------------------------------------------------
46 extern "C" __declspec( dllexport )
47 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
51 //---------------------------------------------------------------------------
53 //---------------------------------------------------------------------------
54 static int Open ( vlc_object_t * );
55 static void Close ( vlc_object_t * );
56 static void Run ( intf_thread_t * );
58 static int DemuxOpen( vlc_object_t * );
59 static int Demux( demux_t * );
60 static int DemuxControl( demux_t *, int, va_list );
62 //---------------------------------------------------------------------------
63 // Prototypes for configuration callbacks
64 //---------------------------------------------------------------------------
65 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
66 vlc_value_t oldVal, vlc_value_t newVal,
68 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
69 vlc_value_t oldVal, vlc_value_t newVal,
73 //---------------------------------------------------------------------------
74 // Open: initialize interface
75 //---------------------------------------------------------------------------
76 static int Open( vlc_object_t *p_this )
78 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" );
90 // Suscribe to messages bank
91 p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
93 p_intf->p_sys->p_input = NULL;
94 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
95 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
96 if( p_intf->p_sys->p_playlist == NULL )
98 msg_Err( p_intf, "No playlist object found" );
99 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
103 // Initialize "singleton" objects
104 p_intf->p_sys->p_logger = NULL;
105 p_intf->p_sys->p_queue = NULL;
106 p_intf->p_sys->p_dialogs = NULL;
107 p_intf->p_sys->p_interpreter = NULL;
108 p_intf->p_sys->p_osFactory = NULL;
109 p_intf->p_sys->p_osLoop = NULL;
110 p_intf->p_sys->p_varManager = NULL;
111 p_intf->p_sys->p_vlcProc = NULL;
112 p_intf->p_sys->p_repository = NULL;
115 p_intf->p_sys->p_theme = NULL;
117 // Create a variable to be notified of skins to be loaded
118 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
120 // Initialize singletons
121 if( OSFactory::instance( p_intf ) == NULL )
123 msg_Err( p_intf, "cannot initialize OSFactory" );
124 vlc_object_release( p_intf->p_sys->p_playlist );
125 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
128 if( AsyncQueue::instance( p_intf ) == NULL )
130 msg_Err( p_intf, "cannot initialize AsyncQueue" );
131 vlc_object_release( p_intf->p_sys->p_playlist );
132 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
135 if( Interpreter::instance( p_intf ) == NULL )
137 msg_Err( p_intf, "cannot instanciate Interpreter" );
138 vlc_object_release( p_intf->p_sys->p_playlist );
139 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
142 if( VarManager::instance( p_intf ) == NULL )
144 msg_Err( p_intf, "cannot instanciate VarManager" );
145 vlc_object_release( p_intf->p_sys->p_playlist );
146 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
149 if( VlcProc::instance( p_intf ) == NULL )
151 msg_Err( p_intf, "cannot initialize VLCProc" );
152 vlc_object_release( p_intf->p_sys->p_playlist );
153 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
156 Dialogs::instance( p_intf );
157 ThemeRepository::instance( p_intf );
159 // We support play on start
160 p_intf->b_play = VLC_TRUE;
162 return( VLC_SUCCESS );
165 //---------------------------------------------------------------------------
166 // Close: destroy interface
167 //---------------------------------------------------------------------------
168 static void Close( vlc_object_t *p_this )
170 intf_thread_t *p_intf = (intf_thread_t *)p_this;
172 // Destroy "singleton" objects
173 OSFactory::instance( p_intf )->destroyOSLoop();
174 ThemeRepository::destroy( p_intf );
175 Dialogs::destroy( p_intf );
176 Interpreter::destroy( p_intf );
177 AsyncQueue::destroy( p_intf );
178 VarManager::destroy( p_intf );
179 VlcProc::destroy( p_intf );
180 OSFactory::destroy( p_intf );
182 if( p_intf->p_sys->p_playlist )
184 vlc_object_release( p_intf->p_sys->p_playlist );
187 // Unsubscribe from messages bank
188 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
191 free( p_intf->p_sys );
195 //---------------------------------------------------------------------------
197 //---------------------------------------------------------------------------
198 static void Run( intf_thread_t *p_intf )
201 ThemeLoader *pLoader = new ThemeLoader( p_intf );
202 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
204 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
206 // Get the resource path and try to load the default skin
207 OSFactory *pOSFactory = OSFactory::instance( p_intf );
208 const list<string> &resPath = pOSFactory->getResourcePath();
209 const string &sep = pOSFactory->getDirSeparator();
211 list<string>::const_iterator it;
212 for( it = resPath.begin(); it != resPath.end(); it++ )
214 string path = (*it) + sep + "default.vlt";
215 if( pLoader->load( path ) )
217 // Theme loaded successfully
221 if( it == resPath.end() )
223 // Last chance: the user can select a new theme file
224 if( Dialogs::instance( p_intf ) )
226 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
227 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
228 pQueue->push( CmdGenericPtr( pCmd ) );
232 // No dialogs provider, just quit...
233 CmdQuit *pCmd = new CmdQuit( p_intf );
234 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
235 pQueue->push( CmdGenericPtr( pCmd ) );
237 "cannot show the \"open skin\" dialog: exiting...");
248 // Get the instance of OSLoop
249 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
251 // Check if we need to start playing
254 playlist_t *p_playlist =
255 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
259 playlist_LockControl( p_playlist, PLAYLIST_AUTOPLAY );
260 vlc_object_release( p_playlist );
264 // Enter the main event loop
267 // Delete the theme and save the configuration of the windows
268 if( p_intf->p_sys->p_theme )
270 p_intf->p_sys->p_theme->saveConfig();
271 delete p_intf->p_sys->p_theme;
272 p_intf->p_sys->p_theme = NULL;
277 //---------------------------------------------------------------------------
278 // DemuxOpen: initialize demux
279 //---------------------------------------------------------------------------
280 static int DemuxOpen( vlc_object_t *p_this )
282 demux_t *p_demux = (demux_t*)p_this;
283 intf_thread_t *p_intf;
287 p_demux->pf_demux = Demux;
288 p_demux->pf_control = DemuxControl;
290 // Test that we have a valid .vlt or .wsz file, based on the extension
291 // TODO: an actual check of the contents would be better...
292 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
293 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
298 p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
302 // Do nothing is skins2 is not the main interface
303 if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING )
305 playlist_t *p_playlist =
306 (playlist_t *) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
308 if( p_playlist != NULL )
310 // Make sure the item is deleted afterwards
311 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion =
313 vlc_object_release( p_playlist );
317 val.psz_string = p_demux->psz_path;
318 var_Set( p_intf, "skin-to-load", val );
323 "skin could not be loaded (not using skins2 intf)" );
326 vlc_object_release( p_intf );
333 //---------------------------------------------------------------------------
335 //---------------------------------------------------------------------------
336 static int Demux( demux_t *p_demux )
342 //---------------------------------------------------------------------------
344 //---------------------------------------------------------------------------
345 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
347 return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
351 //---------------------------------------------------------------------------
353 //---------------------------------------------------------------------------
355 /// Callback for the systray configuration option
356 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
357 vlc_value_t oldVal, vlc_value_t newVal,
360 intf_thread_t *pIntf =
361 (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
368 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
371 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
372 pQueue->push( CmdGenericPtr( pCmd ) );
376 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
377 pQueue->push( CmdGenericPtr( pCmd ) );
380 vlc_object_release( pIntf );
384 /// Callback for the systray configuration option
385 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
386 vlc_value_t oldVal, vlc_value_t newVal,
389 intf_thread_t *pIntf =
390 (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
397 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
400 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
401 pQueue->push( CmdGenericPtr( pCmd ) );
405 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
406 pQueue->push( CmdGenericPtr( pCmd ) );
409 vlc_object_release( pIntf );
413 //---------------------------------------------------------------------------
415 //---------------------------------------------------------------------------
416 #define SKINS2_LAST N_("Skin to use")
417 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
418 #define SKINS2_CONFIG N_("Config of last used skin")
419 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
420 "This option is updated automatically, do not touch it." )
421 #define SKINS2_SYSTRAY N_("Systray icon")
422 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
423 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
424 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
425 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
426 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
427 " if you want. This is mainly useful when moving windows does not behave" \
431 set_category( CAT_INTERFACE );
432 set_subcategory( SUBCAT_INTERFACE_MAIN );
433 add_string( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
436 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
440 add_bool( "skins2-systray", VLC_FALSE, onSystrayChange, SKINS2_SYSTRAY,
441 SKINS2_SYSTRAY_LONG, VLC_FALSE );
442 add_bool( "skins2-taskbar", VLC_TRUE, onTaskBarChange, SKINS2_TASKBAR,
443 SKINS2_TASKBAR_LONG, VLC_FALSE );
444 add_bool( "skins2-transparency", VLC_FALSE, NULL, SKINS2_TRANSPARENCY,
445 SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
448 add_bool( "skinned-playlist", VLC_TRUE, NULL, SKINS2_TRANSPARENCY,
449 SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
450 set_shortname( _("Skins"));
451 set_description( _("Skinnable Interface") );
452 set_capability( "interface", 30 );
453 set_callbacks( Open, Close );
454 add_shortcut( "skins" );
455 set_program( "svlc" );
458 set_description( _("Skins loader demux") );
459 set_capability( "demux2", 5 );
460 set_callbacks( DemuxOpen, NULL );