Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

skin_main.cpp

00001 /*****************************************************************************
00002  * skin_main.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: skin_main.cpp 12034 2005-08-05 17:52:46Z massiot $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include <stdlib.h>
00026 #include <vlc/input.h>
00027 #include "dialogs.hpp"
00028 #include "os_factory.hpp"
00029 #include "os_loop.hpp"
00030 #include "var_manager.hpp"
00031 #include "vlcproc.hpp"
00032 #include "theme_loader.hpp"
00033 #include "theme.hpp"
00034 #include "theme_repository.hpp"
00035 #include "../parser/interpreter.hpp"
00036 #include "../commands/async_queue.hpp"
00037 #include "../commands/cmd_quit.hpp"
00038 #include "../commands/cmd_dialogs.hpp"
00039 
00040 
00041 //---------------------------------------------------------------------------
00042 // Exported interface functions.
00043 //---------------------------------------------------------------------------
00044 #ifdef WIN32_SKINS
00045 extern "C" __declspec( dllexport )
00046     int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
00047 #endif
00048 
00049 
00050 //---------------------------------------------------------------------------
00051 // Local prototypes.
00052 //---------------------------------------------------------------------------
00053 static int  Open  ( vlc_object_t * );
00054 static void Close ( vlc_object_t * );
00055 static void Run   ( intf_thread_t * );
00056 
00057 static int DemuxOpen( vlc_object_t * );
00058 static int Demux( demux_t * );
00059 static int DemuxControl( demux_t *, int, va_list );
00060 
00061 
00062 //---------------------------------------------------------------------------
00063 // Open: initialize interface
00064 //---------------------------------------------------------------------------
00065 static int Open( vlc_object_t *p_this )
00066 {
00067     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00068 
00069     // Allocate instance and initialize some members
00070     p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
00071     if( p_intf->p_sys == NULL )
00072     {
00073         msg_Err( p_intf, "out of memory" );
00074         return( VLC_ENOMEM );
00075     };
00076 
00077     p_intf->pf_run = Run;
00078 
00079     // Suscribe to messages bank
00080     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
00081 
00082     p_intf->p_sys->p_input = NULL;
00083     p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
00084         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00085     if( p_intf->p_sys->p_playlist == NULL )
00086     {
00087         msg_Err( p_intf, "No playlist object found" );
00088         msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00089         return VLC_EGENERIC;
00090     }
00091 
00092     // Initialize "singleton" objects
00093     p_intf->p_sys->p_logger = NULL;
00094     p_intf->p_sys->p_queue = NULL;
00095     p_intf->p_sys->p_dialogs = NULL;
00096     p_intf->p_sys->p_interpreter = NULL;
00097     p_intf->p_sys->p_osFactory = NULL;
00098     p_intf->p_sys->p_osLoop = NULL;
00099     p_intf->p_sys->p_varManager = NULL;
00100     p_intf->p_sys->p_vlcProc = NULL;
00101     p_intf->p_sys->p_repository = NULL;
00102 
00103     // No theme yet
00104     p_intf->p_sys->p_theme = NULL;
00105 
00106     // Create a variable to be notified of skins to be loaded
00107     var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
00108 
00109     // Initialize singletons
00110     if( OSFactory::instance( p_intf ) == NULL )
00111     {
00112         msg_Err( p_intf, "Cannot initialize OSFactory" );
00113         vlc_object_release( p_intf->p_sys->p_playlist );
00114         msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00115         return VLC_EGENERIC;
00116     }
00117     if( AsyncQueue::instance( p_intf ) == NULL )
00118     {
00119         msg_Err( p_intf, "Cannot initialize AsyncQueue" );
00120         vlc_object_release( p_intf->p_sys->p_playlist );
00121         msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00122         return VLC_EGENERIC;
00123     }
00124     if( Interpreter::instance( p_intf ) == NULL )
00125     {
00126         msg_Err( p_intf, "Cannot instanciate Interpreter" );
00127         vlc_object_release( p_intf->p_sys->p_playlist );
00128         msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00129         return VLC_EGENERIC;
00130     }
00131     if( VarManager::instance( p_intf ) == NULL )
00132     {
00133         msg_Err( p_intf, "Cannot instanciate VarManager" );
00134         vlc_object_release( p_intf->p_sys->p_playlist );
00135         msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00136         return VLC_EGENERIC;
00137     }
00138     if( VlcProc::instance( p_intf ) == NULL )
00139     {
00140         msg_Err( p_intf, "Cannot initialize VLCProc" );
00141         vlc_object_release( p_intf->p_sys->p_playlist );
00142         msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00143         return VLC_EGENERIC;
00144     }
00145     Dialogs::instance( p_intf );
00146     ThemeRepository::instance( p_intf );
00147 
00148     // We support play on start
00149     p_intf->b_play = VLC_TRUE;
00150 
00151     return( VLC_SUCCESS );
00152 }
00153 
00154 //---------------------------------------------------------------------------
00155 // Close: destroy interface
00156 //---------------------------------------------------------------------------
00157 static void Close( vlc_object_t *p_this )
00158 {
00159     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00160 
00161     // Destroy "singleton" objects
00162     OSFactory::instance( p_intf )->destroyOSLoop();
00163     ThemeRepository::destroy( p_intf );
00164     Dialogs::destroy( p_intf );
00165     Interpreter::destroy( p_intf );
00166     AsyncQueue::destroy( p_intf );
00167     VarManager::destroy( p_intf );
00168     VlcProc::destroy( p_intf );
00169     OSFactory::destroy( p_intf );
00170 
00171     if( p_intf->p_sys->p_playlist )
00172     {
00173         vlc_object_release( p_intf->p_sys->p_playlist );
00174     }
00175 
00176     // Unsubscribe from messages bank
00177     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
00178 
00179     // Destroy structure
00180     free( p_intf->p_sys );
00181 }
00182 
00183 
00184 //---------------------------------------------------------------------------
00185 // Run: main loop
00186 //---------------------------------------------------------------------------
00187 static void Run( intf_thread_t *p_intf )
00188 {
00189     // Load a theme
00190     ThemeLoader *pLoader = new ThemeLoader( p_intf );
00191     char *skin_last = config_GetPsz( p_intf, "skins2-last" );
00192 
00193     if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
00194     {
00195         // Get the resource path and try to load the default skin
00196         OSFactory *pOSFactory = OSFactory::instance( p_intf );
00197         const list<string> &resPath = pOSFactory->getResourcePath();
00198         const string &sep = pOSFactory->getDirSeparator();
00199 
00200         list<string>::const_iterator it;
00201         for( it = resPath.begin(); it != resPath.end(); it++ )
00202         {
00203             string path = (*it) + sep + "default.vlt";
00204             if( pLoader->load( path ) )
00205             {
00206                 // Theme loaded successfully
00207                 break;
00208             }
00209         }
00210         if( it == resPath.end() )
00211         {
00212             // Last chance: the user can select a new theme file
00213             if( Dialogs::instance( p_intf ) )
00214             {
00215                 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
00216                 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
00217                 pQueue->push( CmdGenericPtr( pCmd ) );
00218             }
00219             else
00220             {
00221                 // No dialogs provider, just quit...
00222                 CmdQuit *pCmd = new CmdQuit( p_intf );
00223                 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
00224                 pQueue->push( CmdGenericPtr( pCmd ) );
00225                 msg_Err( p_intf,
00226                          "Cannot show the \"open skin\" dialog: exiting...");
00227             }
00228         }
00229     }
00230     delete pLoader;
00231 
00232     if( skin_last )
00233     {
00234         free( skin_last );
00235     }
00236 
00237     // Get the instance of OSLoop
00238     OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
00239 
00240     // Check if we need to start playing
00241     if( p_intf->b_play )
00242     {
00243         playlist_t *p_playlist =
00244             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00245                                            FIND_ANYWHERE );
00246         if( p_playlist )
00247         {
00248             p_playlist->status.i_view = -1;
00249             playlist_Control( p_playlist, PLAYLIST_AUTOPLAY );
00250             vlc_object_release( p_playlist );
00251         }
00252     }
00253 
00254     // Enter the main event loop
00255     loop->run();
00256 
00257     // Delete the theme and save the configuration of the windows
00258     if( p_intf->p_sys->p_theme )
00259     {
00260         p_intf->p_sys->p_theme->saveConfig();
00261         delete p_intf->p_sys->p_theme;
00262         p_intf->p_sys->p_theme = NULL;
00263     }
00264 }
00265 
00266 
00267 //---------------------------------------------------------------------------
00268 // DemuxOpen: initialize demux
00269 //---------------------------------------------------------------------------
00270 static int DemuxOpen( vlc_object_t *p_this )
00271 {
00272     demux_t *p_demux = (demux_t*)p_this;
00273     intf_thread_t *p_intf;
00274     char *ext;
00275 
00276     // Needed callbacks
00277     p_demux->pf_demux   = Demux;
00278     p_demux->pf_control = DemuxControl;
00279 
00280     // Test that we have a valid .vlt file, based on the extension
00281     // TODO: an actual check of the contents would be better...
00282     if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
00283         strcasecmp( ext, ".vlt" ) )
00284     {
00285         return VLC_EGENERIC;
00286     }
00287 
00288     p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
00289                                                FIND_ANYWHERE );
00290     if( p_intf != NULL )
00291     {
00292         // Do nothing is skins2 is not the main interface
00293         if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING )
00294         {
00295             playlist_t *p_playlist =
00296                 (playlist_t *) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
00297                                                 FIND_ANYWHERE );
00298             if( p_playlist != NULL )
00299             {
00300                 // Make sure the item is deleted afterwards
00301                 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion =
00302                     VLC_TRUE;
00303                 vlc_object_release( p_playlist );
00304             }
00305 
00306             vlc_value_t val;
00307             val.psz_string = p_demux->psz_path;
00308             var_Set( p_intf, "skin-to-load", val );
00309         }
00310         else
00311         {
00312             msg_Warn( p_this,
00313                       "skin could not be loaded (not using skins2 intf)" );
00314         }
00315 
00316         vlc_object_release( p_intf );
00317     }
00318 
00319     return VLC_SUCCESS;
00320 }
00321 
00322 
00323 //---------------------------------------------------------------------------
00324 // Demux: return EOF
00325 //---------------------------------------------------------------------------
00326 static int Demux( demux_t *p_demux )
00327 {
00328     return 0;
00329 }
00330 
00331 
00332 //---------------------------------------------------------------------------
00333 // DemuxControl
00334 //---------------------------------------------------------------------------
00335 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
00336 {
00337     return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
00338 }
00339 
00340 
00341 //---------------------------------------------------------------------------
00342 // Module descriptor
00343 //---------------------------------------------------------------------------
00344 #define SKINS2_LAST      N_("Last skin used")
00345 #define SKINS2_LAST_LONG N_("Select the path to the last skin used.")
00346 #define SKINS2_CONFIG      N_("Config of last used skin")
00347 #define SKINS2_CONFIG_LONG N_("Config of last used skin.")
00348 #define SKINS2_TRANSPARENCY      N_("Enable transparency effects")
00349 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
00350     " if you want. This is mainly useful when moving windows does not behave" \
00351     " correctly.")
00352 
00353 vlc_module_begin();
00354     set_category( CAT_INTERFACE );
00355     set_subcategory( SUBCAT_INTERFACE_GENERAL );
00356     add_string( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
00357                 VLC_TRUE );
00358         change_autosave();
00359     add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
00360                 VLC_TRUE );
00361         change_autosave();
00362 #ifdef WIN32
00363     add_bool( "skins2-transparency", VLC_FALSE, NULL, SKINS2_TRANSPARENCY,
00364               SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
00365 #endif
00366     set_shortname( _("Skins"));
00367     set_description( _("Skinnable Interface") );
00368     set_capability( "interface", 30 );
00369     set_callbacks( Open, Close );
00370     add_shortcut( "skins" );
00371     set_program( "svlc" );
00372 
00373     add_submodule();
00374         set_description( _("Skins loader demux") );
00375         set_capability( "demux2", 5 );
00376         set_callbacks( DemuxOpen, NULL );
00377 
00378 vlc_module_end();

Generated on Tue Dec 20 10:14:42 2005 for vlc-0.8.4a by  doxygen 1.4.2