skin_main.cpp
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:12k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*****************************************************************************
  2.  * skin_main.cpp
  3.  *****************************************************************************
  4.  * Copyright (C) 2003 VideoLAN
  5.  * $Id: skin_main.cpp 8524 2004-08-25 21:32:15Z ipkiss $
  6.  *
  7.  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  8.  *          Olivier Teuli鑢e <ipkiss@via.ecp.fr>
  9.  *
  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.
  14.  *
  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.
  19.  *
  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.  *****************************************************************************/
  24. #include <stdlib.h>
  25. #include <vlc/input.h>
  26. #include "dialogs.hpp"
  27. #include "os_factory.hpp"
  28. #include "os_loop.hpp"
  29. #include "var_manager.hpp"
  30. #include "vlcproc.hpp"
  31. #include "theme_loader.hpp"
  32. #include "theme.hpp"
  33. #include "theme_repository.hpp"
  34. #include "../parser/interpreter.hpp"
  35. #include "../commands/async_queue.hpp"
  36. #include "../commands/cmd_quit.hpp"
  37. #include "../commands/cmd_dialogs.hpp"
  38. //---------------------------------------------------------------------------
  39. // Exported interface functions.
  40. //---------------------------------------------------------------------------
  41. #ifdef WIN32_SKINS
  42. extern "C" __declspec( dllexport )
  43.     int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
  44. #endif
  45. //---------------------------------------------------------------------------
  46. // Local prototypes.
  47. //---------------------------------------------------------------------------
  48. static int  Open  ( vlc_object_t * );
  49. static void Close ( vlc_object_t * );
  50. static void Run   ( intf_thread_t * );
  51. static int DemuxOpen( vlc_object_t * );
  52. static int Demux( demux_t * );
  53. static int DemuxControl( demux_t *, int, va_list );
  54. //---------------------------------------------------------------------------
  55. // Open: initialize interface
  56. //---------------------------------------------------------------------------
  57. static int Open( vlc_object_t *p_this )
  58. {
  59.     intf_thread_t *p_intf = (intf_thread_t *)p_this;
  60.     // Allocate instance and initialize some members
  61.     p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
  62.     if( p_intf->p_sys == NULL )
  63.     {
  64.         msg_Err( p_intf, "out of memory" );
  65.         return( VLC_ENOMEM );
  66.     };
  67.     p_intf->pf_run = Run;
  68.     // Suscribe to messages bank
  69.     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
  70.     p_intf->p_sys->p_input = NULL;
  71.     p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
  72.         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
  73.     if( p_intf->p_sys->p_playlist == NULL )
  74.     {
  75.         msg_Err( p_intf, "No playlist object found" );
  76.         return VLC_EGENERIC;
  77.     }
  78.     // Initialize "singleton" objects
  79.     p_intf->p_sys->p_logger = NULL;
  80.     p_intf->p_sys->p_queue = NULL;
  81.     p_intf->p_sys->p_dialogs = NULL;
  82.     p_intf->p_sys->p_interpreter = NULL;
  83.     p_intf->p_sys->p_osFactory = NULL;
  84.     p_intf->p_sys->p_osLoop = NULL;
  85.     p_intf->p_sys->p_varManager = NULL;
  86.     p_intf->p_sys->p_vlcProc = NULL;
  87.     p_intf->p_sys->p_repository = NULL;
  88.     // No theme yet
  89.     p_intf->p_sys->p_theme = NULL;
  90.     // Create a variable to be notified of skins to be loaded
  91.     var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
  92.     // Initialize singletons
  93.     if( OSFactory::instance( p_intf ) == NULL )
  94.     {
  95.         msg_Err( p_intf, "Cannot initialize OSFactory" );
  96.         return VLC_EGENERIC;
  97.     }
  98.     if( AsyncQueue::instance( p_intf ) == NULL )
  99.     {
  100.         msg_Err( p_intf, "Cannot initialize AsyncQueue" );
  101.         return VLC_EGENERIC;
  102.     }
  103.     if( Interpreter::instance( p_intf ) == NULL )
  104.     {
  105.         msg_Err( p_intf, "Cannot instanciate Interpreter" );
  106.         return VLC_EGENERIC;
  107.     }
  108.     if( VarManager::instance( p_intf ) == NULL )
  109.     {
  110.         msg_Err( p_intf, "Cannot instanciate VarManager" );
  111.         return VLC_EGENERIC;
  112.     }
  113.     if( VlcProc::instance( p_intf ) == NULL )
  114.     {
  115.         msg_Err( p_intf, "Cannot initialize VLCProc" );
  116.         return VLC_EGENERIC;
  117.     }
  118.     Dialogs::instance( p_intf );
  119.     ThemeRepository::instance( p_intf );
  120.     // We support play on start
  121.     p_intf->b_play = VLC_TRUE;
  122.     return( VLC_SUCCESS );
  123. }
  124. //---------------------------------------------------------------------------
  125. // Close: destroy interface
  126. //---------------------------------------------------------------------------
  127. static void Close( vlc_object_t *p_this )
  128. {
  129.     intf_thread_t *p_intf = (intf_thread_t *)p_this;
  130.     // Destroy "singleton" objects
  131.     OSFactory::instance( p_intf )->destroyOSLoop();
  132.     ThemeRepository::destroy( p_intf );
  133.     Dialogs::destroy( p_intf );
  134.     Interpreter::destroy( p_intf );
  135.     AsyncQueue::destroy( p_intf );
  136.     VarManager::destroy( p_intf );
  137.     VlcProc::destroy( p_intf );
  138.     OSFactory::destroy( p_intf );
  139.     if( p_intf->p_sys->p_playlist )
  140.     {
  141.         vlc_object_release( p_intf->p_sys->p_playlist );
  142.     }
  143.    // Unsubscribe from messages bank
  144.     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
  145.     // Destroy structure
  146.     free( p_intf->p_sys );
  147. }
  148. //---------------------------------------------------------------------------
  149. // Run: main loop
  150. //---------------------------------------------------------------------------
  151. static void Run( intf_thread_t *p_intf )
  152. {
  153.     // Load a theme
  154.     ThemeLoader *pLoader = new ThemeLoader( p_intf );
  155.     char *skin_last = config_GetPsz( p_intf, "skins2-last" );
  156.     if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
  157.     {
  158.         // Get the resource path and try to load the default skin
  159.         OSFactory *pOSFactory = OSFactory::instance( p_intf );
  160.         const list<string> &resPath = pOSFactory->getResourcePath();
  161.         const string &sep = pOSFactory->getDirSeparator();
  162.         list<string>::const_iterator it;
  163.         for( it = resPath.begin(); it != resPath.end(); it++ )
  164.         {
  165.             string path = (*it) + sep + "default.vlt";
  166.             if( pLoader->load( path ) )
  167.             {
  168.                 // Theme loaded successfully
  169.                 break;
  170.             }
  171.         }
  172.         if( it == resPath.end() )
  173.         {
  174.             // Last chance: the user can select a new theme file
  175.             if( Dialogs::instance( p_intf ) )
  176.             {
  177.                 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
  178.                 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
  179.                 pQueue->push( CmdGenericPtr( pCmd ) );
  180.             }
  181.             else
  182.             {
  183.                 // No dialogs provider, just quit...
  184.                 CmdQuit *pCmd = new CmdQuit( p_intf );
  185.                 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
  186.                 pQueue->push( CmdGenericPtr( pCmd ) );
  187.                 msg_Err( p_intf,
  188.                          "Cannot show the "open skin" dialog: exiting...");
  189.             }
  190.         }
  191.     }
  192.     delete pLoader;
  193.     if( skin_last )
  194.     {
  195.         free( skin_last );
  196.     }
  197.     // Get the instance of OSLoop
  198.     OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
  199.     // Check if we need to start playing
  200.     if( p_intf->b_play )
  201.     {
  202.         playlist_t *p_playlist =
  203.             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
  204.                                            FIND_ANYWHERE );
  205.         if( p_playlist )
  206.         {
  207.             playlist_Play( p_playlist );
  208.             vlc_object_release( p_playlist );
  209.         }
  210.     }
  211.     // Enter the main event loop
  212.     loop->run();
  213.     // Delete the theme and save the configuration of the windows
  214.     if( p_intf->p_sys->p_theme )
  215.     {
  216.         p_intf->p_sys->p_theme->saveConfig();
  217.         delete p_intf->p_sys->p_theme;
  218.         p_intf->p_sys->p_theme = NULL;
  219.     }
  220. }
  221. //---------------------------------------------------------------------------
  222. // DemuxOpen: initialize demux
  223. //---------------------------------------------------------------------------
  224. static int DemuxOpen( vlc_object_t *p_this )
  225. {
  226.     demux_t *p_demux = (demux_t*)p_this;
  227.     intf_thread_t *p_intf;
  228.     char *ext;
  229.     // Needed callbacks
  230.     p_demux->pf_demux   = Demux;
  231.     p_demux->pf_control = DemuxControl;
  232.     // Test that we have a valid .vlt file, based on the extension
  233.     // TODO: an actual check of the contents would be better...
  234.     if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
  235.         strcasecmp( ext, ".vlt" ) )
  236.     {
  237.         return VLC_EGENERIC;
  238.     }
  239.     p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
  240.                                                FIND_ANYWHERE );
  241.     if( p_intf != NULL )
  242.     {
  243.         // Do nothing is skins2 is not the main interface
  244.         if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING )
  245.         {
  246.             playlist_t *p_playlist =
  247.                 (playlist_t *) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
  248.                                                 FIND_ANYWHERE );
  249.             if( p_playlist != NULL )
  250.             {
  251.                 // Make sure the item is deleted afterwards
  252.                 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion =
  253.                     VLC_TRUE;
  254.                 vlc_object_release( p_playlist );
  255.             }
  256.             vlc_value_t val;
  257.             val.psz_string = p_demux->psz_path;
  258.             var_Set( p_intf, "skin-to-load", val );
  259.         }
  260.         else
  261.         {
  262.             msg_Warn( p_this,
  263.                       "skin could not be loaded (not using skins2 intf)" );
  264.         }
  265.         vlc_object_release( p_intf );
  266.     }
  267.     return VLC_SUCCESS;
  268. }
  269. //---------------------------------------------------------------------------
  270. // Demux: return EOF
  271. //---------------------------------------------------------------------------
  272. static int Demux( demux_t *p_demux )
  273. {
  274.     return 0;
  275. }
  276. //---------------------------------------------------------------------------
  277. // DemuxControl
  278. //---------------------------------------------------------------------------
  279. static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
  280. {
  281.     return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
  282. }
  283. //---------------------------------------------------------------------------
  284. // Module descriptor
  285. //---------------------------------------------------------------------------
  286. #define SKINS2_LAST      N_("Last skin used")
  287. #define SKINS2_LAST_LONG N_("Select the path to the last skin used.")
  288. #define SKINS2_CONFIG      N_("Config of last used skin")
  289. #define SKINS2_CONFIG_LONG N_("Config of last used skin.")
  290. #define SKINS2_TRANSPARENCY      N_("Enable transparency effects")
  291. #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"
  292.     " if you want. This is mainly useful when moving windows does not behave" 
  293.     " correctly.")
  294. vlc_module_begin();
  295.     add_string( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
  296.                 VLC_TRUE );
  297.     add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
  298.                 VLC_TRUE );
  299. #ifdef WIN32
  300.     add_bool( "skins2-transparency", VLC_FALSE, NULL, SKINS2_TRANSPARENCY,
  301.               SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
  302. #endif
  303.     set_description( _("Skinnable Interface") );
  304.     set_capability( "interface", 30 );
  305.     set_callbacks( Open, Close );
  306.     add_shortcut( "skins" );
  307.     set_program( "svlc" );
  308.     add_submodule();
  309.         set_description( _("Skins loader demux") );
  310.         set_capability( "demux2", 5 );
  311.         set_callbacks( DemuxOpen, NULL );
  312. vlc_module_end();