1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, 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"
41 //---------------------------------------------------------------------------
42 // Exported interface functions.
43 //---------------------------------------------------------------------------
45 extern "C" __declspec( dllexport )
46 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
50 //---------------------------------------------------------------------------
52 //---------------------------------------------------------------------------
53 static int Open ( vlc_object_t * );
54 static void Close ( vlc_object_t * );
55 static void Run ( intf_thread_t * );
57 static int DemuxOpen( vlc_object_t * );
58 static int Demux( demux_t * );
59 static int DemuxControl( demux_t *, int, va_list );
62 //---------------------------------------------------------------------------
63 // Open: initialize interface
64 //---------------------------------------------------------------------------
65 static int Open( vlc_object_t *p_this )
67 intf_thread_t *p_intf = (intf_thread_t *)p_this;
69 // Allocate instance and initialize some members
70 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
71 if( p_intf->p_sys == NULL )
73 msg_Err( p_intf, "out of memory" );
79 // Suscribe to messages bank
80 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
82 p_intf->p_sys->p_input = NULL;
83 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
84 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
85 if( p_intf->p_sys->p_playlist == NULL )
87 msg_Err( p_intf, "No playlist object found" );
91 // Initialize "singleton" objects
92 p_intf->p_sys->p_logger = NULL;
93 p_intf->p_sys->p_queue = NULL;
94 p_intf->p_sys->p_dialogs = NULL;
95 p_intf->p_sys->p_interpreter = NULL;
96 p_intf->p_sys->p_osFactory = NULL;
97 p_intf->p_sys->p_osLoop = NULL;
98 p_intf->p_sys->p_varManager = NULL;
99 p_intf->p_sys->p_vlcProc = NULL;
100 p_intf->p_sys->p_repository = NULL;
103 p_intf->p_sys->p_theme = NULL;
105 // Create a variable to be notified of skins to be loaded
106 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
108 // Initialize singletons
109 if( OSFactory::instance( p_intf ) == NULL )
111 msg_Err( p_intf, "Cannot initialize OSFactory" );
114 if( AsyncQueue::instance( p_intf ) == NULL )
116 msg_Err( p_intf, "Cannot initialize AsyncQueue" );
119 if( Interpreter::instance( p_intf ) == NULL )
121 msg_Err( p_intf, "Cannot instanciate Interpreter" );
124 if( VarManager::instance( p_intf ) == NULL )
126 msg_Err( p_intf, "Cannot instanciate VarManager" );
129 if( VlcProc::instance( p_intf ) == NULL )
131 msg_Err( p_intf, "Cannot initialize VLCProc" );
134 Dialogs::instance( p_intf );
135 ThemeRepository::instance( p_intf );
137 // We support play on start
138 p_intf->b_play = VLC_TRUE;
140 return( VLC_SUCCESS );
143 //---------------------------------------------------------------------------
144 // Close: destroy interface
145 //---------------------------------------------------------------------------
146 static void Close( vlc_object_t *p_this )
148 intf_thread_t *p_intf = (intf_thread_t *)p_this;
150 // Destroy "singleton" objects
151 OSFactory::instance( p_intf )->destroyOSLoop();
152 ThemeRepository::destroy( p_intf );
153 Dialogs::destroy( p_intf );
154 Interpreter::destroy( p_intf );
155 AsyncQueue::destroy( p_intf );
156 VarManager::destroy( p_intf );
157 VlcProc::destroy( p_intf );
158 OSFactory::destroy( p_intf );
160 if( p_intf->p_sys->p_playlist )
162 vlc_object_release( p_intf->p_sys->p_playlist );
165 // Unsubscribe from messages bank
166 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
169 free( p_intf->p_sys );
173 //---------------------------------------------------------------------------
175 //---------------------------------------------------------------------------
176 static void Run( intf_thread_t *p_intf )
179 ThemeLoader *pLoader = new ThemeLoader( p_intf );
180 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
182 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
184 // Get the resource path and try to load the default skin
185 OSFactory *pOSFactory = OSFactory::instance( p_intf );
186 const list<string> &resPath = pOSFactory->getResourcePath();
187 const string &sep = pOSFactory->getDirSeparator();
189 list<string>::const_iterator it;
190 for( it = resPath.begin(); it != resPath.end(); it++ )
192 string path = (*it) + sep + "default.vlt";
193 if( pLoader->load( path ) )
195 // Theme loaded successfully
199 if( it == resPath.end() )
201 // Last chance: the user can select a new theme file
202 if( Dialogs::instance( p_intf ) )
204 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
205 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
206 pQueue->push( CmdGenericPtr( pCmd ) );
210 // No dialogs provider, just quit...
211 CmdQuit *pCmd = new CmdQuit( p_intf );
212 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
213 pQueue->push( CmdGenericPtr( pCmd ) );
215 "Cannot show the \"open skin\" dialog: exiting...");
226 // Get the instance of OSLoop
227 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
229 // Check if we need to start playing
232 playlist_t *p_playlist =
233 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
237 p_playlist->status.i_view = -1;
238 playlist_Control( p_playlist, PLAYLIST_AUTOPLAY );
239 vlc_object_release( p_playlist );
243 // Enter the main event loop
246 // Delete the theme and save the configuration of the windows
247 if( p_intf->p_sys->p_theme )
249 p_intf->p_sys->p_theme->saveConfig();
250 delete p_intf->p_sys->p_theme;
251 p_intf->p_sys->p_theme = NULL;
256 //---------------------------------------------------------------------------
257 // DemuxOpen: initialize demux
258 //---------------------------------------------------------------------------
259 static int DemuxOpen( vlc_object_t *p_this )
261 demux_t *p_demux = (demux_t*)p_this;
262 intf_thread_t *p_intf;
266 p_demux->pf_demux = Demux;
267 p_demux->pf_control = DemuxControl;
269 // Test that we have a valid .vlt file, based on the extension
270 // TODO: an actual check of the contents would be better...
271 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
272 strcasecmp( ext, ".vlt" ) )
277 p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
281 // Do nothing is skins2 is not the main interface
282 if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING )
284 playlist_t *p_playlist =
285 (playlist_t *) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
287 if( p_playlist != NULL )
289 // Make sure the item is deleted afterwards
290 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion =
292 vlc_object_release( p_playlist );
296 val.psz_string = p_demux->psz_path;
297 var_Set( p_intf, "skin-to-load", val );
302 "skin could not be loaded (not using skins2 intf)" );
305 vlc_object_release( p_intf );
312 //---------------------------------------------------------------------------
314 //---------------------------------------------------------------------------
315 static int Demux( demux_t *p_demux )
321 //---------------------------------------------------------------------------
323 //---------------------------------------------------------------------------
324 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
326 return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
330 //---------------------------------------------------------------------------
332 //---------------------------------------------------------------------------
333 #define SKINS2_LAST N_("Last skin used")
334 #define SKINS2_LAST_LONG N_("Select the path to the last skin used.")
335 #define SKINS2_CONFIG N_("Config of last used skin")
336 #define SKINS2_CONFIG_LONG N_("Config of last used skin.")
337 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
338 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
339 " if you want. This is mainly useful when moving windows does not behave" \
343 set_category( CAT_INTERFACE );
344 set_subcategory( SUBCAT_INTERFACE_GENERAL );
345 add_string( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
347 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
350 add_bool( "skins2-transparency", VLC_FALSE, NULL, SKINS2_TRANSPARENCY,
351 SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
354 set_description( _("Skinnable Interface") );
355 set_capability( "interface", 30 );
356 set_callbacks( Open, Close );
357 add_shortcut( "skins" );
358 set_program( "svlc" );
361 set_description( _("Skins loader demux") );
362 set_capability( "demux2", 5 );
363 set_callbacks( DemuxOpen, NULL );