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>
35 #include "dialogs.hpp"
36 #include "os_factory.hpp"
37 #include "os_loop.hpp"
38 #include "var_manager.hpp"
39 #include "vlcproc.hpp"
40 #include "theme_loader.hpp"
42 #include "theme_repository.hpp"
43 #include "../parser/interpreter.hpp"
44 #include "../commands/async_queue.hpp"
45 #include "../commands/cmd_quit.hpp"
46 #include "../commands/cmd_dialogs.hpp"
47 #include "../commands/cmd_minimize.hpp"
49 //---------------------------------------------------------------------------
50 // Exported interface functions.
51 //---------------------------------------------------------------------------
53 extern "C" __declspec( dllexport )
54 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
58 //---------------------------------------------------------------------------
60 //---------------------------------------------------------------------------
61 static int Open ( vlc_object_t * );
62 static void Close ( vlc_object_t * );
63 static void Run ( intf_thread_t * );
65 static int DemuxOpen( vlc_object_t * );
66 static int Demux( demux_t * );
67 static int DemuxControl( demux_t *, int, va_list );
69 //---------------------------------------------------------------------------
70 // Prototypes for configuration callbacks
71 //---------------------------------------------------------------------------
72 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
73 vlc_value_t oldVal, vlc_value_t newVal,
75 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
76 vlc_value_t oldVal, vlc_value_t newVal,
80 //---------------------------------------------------------------------------
81 // Open: initialize interface
82 //---------------------------------------------------------------------------
83 static int Open( vlc_object_t *p_this )
85 intf_thread_t *p_intf = (intf_thread_t *)p_this;
87 // Allocate instance and initialize some members
88 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
89 if( p_intf->p_sys == NULL )
91 msg_Err( p_intf, "out of memory" );
97 // Suscribe to messages bank
98 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
100 p_intf->p_sys->p_input = NULL;
101 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
102 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
103 if( p_intf->p_sys->p_playlist == NULL )
105 msg_Err( p_intf, "No playlist object found" );
106 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
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 );
132 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
135 if( AsyncQueue::instance( p_intf ) == NULL )
137 msg_Err( p_intf, "cannot initialize AsyncQueue" );
138 vlc_object_release( p_intf->p_sys->p_playlist );
139 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
142 if( Interpreter::instance( p_intf ) == NULL )
144 msg_Err( p_intf, "cannot instanciate Interpreter" );
145 vlc_object_release( p_intf->p_sys->p_playlist );
146 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
149 if( VarManager::instance( p_intf ) == NULL )
151 msg_Err( p_intf, "cannot instanciate VarManager" );
152 vlc_object_release( p_intf->p_sys->p_playlist );
153 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
156 if( VlcProc::instance( p_intf ) == NULL )
158 msg_Err( p_intf, "cannot initialize VLCProc" );
159 vlc_object_release( p_intf->p_sys->p_playlist );
160 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
163 Dialogs::instance( p_intf );
164 ThemeRepository::instance( p_intf );
166 return( VLC_SUCCESS );
169 //---------------------------------------------------------------------------
170 // Close: destroy interface
171 //---------------------------------------------------------------------------
172 static void Close( vlc_object_t *p_this )
174 intf_thread_t *p_intf = (intf_thread_t *)p_this;
176 // Destroy "singleton" objects
177 OSFactory::instance( p_intf )->destroyOSLoop();
178 ThemeRepository::destroy( p_intf );
179 Dialogs::destroy( p_intf );
180 Interpreter::destroy( p_intf );
181 AsyncQueue::destroy( p_intf );
182 VarManager::destroy( p_intf );
183 VlcProc::destroy( p_intf );
184 OSFactory::destroy( p_intf );
186 if( p_intf->p_sys->p_playlist )
188 vlc_object_release( p_intf->p_sys->p_playlist );
191 // Unsubscribe from messages bank
192 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
195 free( p_intf->p_sys );
199 //---------------------------------------------------------------------------
201 //---------------------------------------------------------------------------
202 static void Run( intf_thread_t *p_intf )
205 ThemeLoader *pLoader = new ThemeLoader( p_intf );
206 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
208 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
210 // Get the resource path and try to load the default skin
211 OSFactory *pOSFactory = OSFactory::instance( p_intf );
212 const list<string> &resPath = pOSFactory->getResourcePath();
213 const string &sep = pOSFactory->getDirSeparator();
215 list<string>::const_iterator it;
216 for( it = resPath.begin(); it != resPath.end(); it++ )
218 string path = (*it) + sep + "default.vlt";
219 if( pLoader->load( path ) )
221 // Theme loaded successfully
225 if( it == resPath.end() )
227 // Last chance: the user can select a new theme file
228 if( Dialogs::instance( p_intf ) )
230 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
231 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
232 pQueue->push( CmdGenericPtr( pCmd ) );
236 // No dialogs provider, just quit...
237 CmdQuit *pCmd = new CmdQuit( p_intf );
238 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
239 pQueue->push( CmdGenericPtr( pCmd ) );
241 "cannot show the \"open skin\" dialog: exiting...");
249 // Get the instance of OSLoop
250 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
252 // Enter the main event loop
255 // Delete the theme and save the configuration of the windows
256 if( p_intf->p_sys->p_theme )
258 p_intf->p_sys->p_theme->saveConfig();
259 delete p_intf->p_sys->p_theme;
260 p_intf->p_sys->p_theme = NULL;
265 //---------------------------------------------------------------------------
266 // DemuxOpen: initialize demux
267 //---------------------------------------------------------------------------
268 static int DemuxOpen( vlc_object_t *p_this )
270 demux_t *p_demux = (demux_t*)p_this;
271 intf_thread_t *p_intf;
275 p_demux->pf_demux = Demux;
276 p_demux->pf_control = DemuxControl;
278 // Test that we have a valid .vlt or .wsz file, based on the extension
279 // TODO: an actual check of the contents would be better...
280 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
281 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
286 p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
290 // Do nothing is skins2 is not the main interface
291 if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING )
293 playlist_t *p_playlist =
294 (playlist_t *) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
296 if( p_playlist != NULL )
298 // Make sure the item is deleted afterwards
299 /// \bug does not always work
300 p_playlist->status.p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
301 vlc_object_release( p_playlist );
305 val.psz_string = p_demux->psz_path;
306 var_Set( p_intf, "skin-to-load", val );
311 "skin could not be loaded (not using skins2 intf)" );
314 vlc_object_release( p_intf );
321 //---------------------------------------------------------------------------
323 //---------------------------------------------------------------------------
324 static int Demux( demux_t *p_demux )
330 //---------------------------------------------------------------------------
332 //---------------------------------------------------------------------------
333 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
335 return demux_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
339 //---------------------------------------------------------------------------
341 //---------------------------------------------------------------------------
343 /// Callback for the systray configuration option
344 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
345 vlc_value_t oldVal, vlc_value_t newVal,
348 intf_thread_t *pIntf =
349 (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
356 // Check that we found the correct interface (same check as for the demux)
357 if( var_Type( pIntf, "skin-to-load" ) == VLC_VAR_STRING )
359 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
362 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
363 pQueue->push( CmdGenericPtr( pCmd ) );
367 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
368 pQueue->push( CmdGenericPtr( pCmd ) );
372 vlc_object_release( pIntf );
377 /// Callback for the systray configuration option
378 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
379 vlc_value_t oldVal, vlc_value_t newVal,
382 intf_thread_t *pIntf =
383 (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
390 // Check that we found the correct interface (same check as for the demux)
391 if( var_Type( pIntf, "skin-to-load" ) == VLC_VAR_STRING )
393 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
396 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
397 pQueue->push( CmdGenericPtr( pCmd ) );
401 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
402 pQueue->push( CmdGenericPtr( pCmd ) );
406 vlc_object_release( pIntf );
411 //---------------------------------------------------------------------------
413 //---------------------------------------------------------------------------
414 #define SKINS2_LAST N_("Skin to use")
415 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
416 #define SKINS2_CONFIG N_("Config of last used skin")
417 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
418 "This option is updated automatically, do not touch it." )
419 #define SKINS2_SYSTRAY N_("Systray icon")
420 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
421 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
422 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
423 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
424 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
425 " if you want. This is mainly useful when moving windows does not behave" \
427 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
428 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
431 set_category( CAT_INTERFACE );
432 set_subcategory( SUBCAT_INTERFACE_MAIN );
433 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
436 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
441 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
442 SKINS2_SYSTRAY_LONG, false );
443 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
444 SKINS2_TASKBAR_LONG, false );
445 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
446 SKINS2_TRANSPARENCY_LONG, false );
449 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
450 SKINS2_PLAYLIST_LONG, false );
451 set_shortname( N_("Skins"));
452 set_description( N_("Skinnable Interface") );
453 set_capability( "interface", 30 );
454 set_callbacks( Open, Close );
455 add_shortcut( "skins" );
458 set_description( N_("Skins loader demux") );
459 set_capability( "demux", 5 );
460 set_callbacks( DemuxOpen, NULL );