Commit 3d8429aa authored by Cyril Deguet's avatar Cyril Deguet

* theme_repository.*: the popup menu for skin selection works !

  (it looks for .vlt files in all the directories of the resource path)
  * dialogs.cpp: fixed a stupid copy/paste mistake
parent 78b01836
...@@ -43,7 +43,7 @@ static void showChangeSkinCB( intf_dialog_args_t *pArg ) ...@@ -43,7 +43,7 @@ static void showChangeSkinCB( intf_dialog_args_t *pArg )
// Push the command in the asynchronous command queue // Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pIntf ); AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
pQueue->remove( "resize" ); pQueue->remove( "change skin" );
pQueue->push( CmdGenericPtr( pCmd ) ); pQueue->push( CmdGenericPtr( pCmd ) );
} }
} }
......
...@@ -22,6 +22,21 @@ ...@@ -22,6 +22,21 @@
*****************************************************************************/ *****************************************************************************/
#include "theme_repository.hpp" #include "theme_repository.hpp"
#include "os_factory.hpp"
#include "../commands/async_queue.hpp"
#include "../commands/cmd_dialogs.hpp"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#elif defined( WIN32 )
# include <direct.h>
#endif
#if (!defined( WIN32 ) || defined(__MINGW32__))
/* Mingw has its own version of dirent */
# include <dirent.h>
#endif
const char *ThemeRepository::kOpenDialog = "@openSkin@";
ThemeRepository *ThemeRepository::instance( intf_thread_t *pIntf ) ThemeRepository *ThemeRepository::instance( intf_thread_t *pIntf )
...@@ -49,125 +64,103 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf ) ...@@ -49,125 +64,103 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
{ {
vlc_value_t val, text; vlc_value_t val, text;
/* // Create a timer to poll the status of the vlc // Create a variable to add items in wxwindows popup menu
OSFactory *pOsFactory = OSFactory::instance( pIntf );
m_pTimer = pOsFactory->createOSTimer( Callback( this, &doManage ) );
m_pTimer->start( 100, false );
// Create and register VLC variables
VarManager *pVarManager = VarManager::instance( getIntf() );
#define REGISTER_VAR( var, type, name ) \
var = VariablePtr( new type( getIntf() ) ); \
pVarManager->registerVar( var, name );
REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
"playlist.slider" );
REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
REGISTER_VAR( m_cVarTime, StreamTime, "time" )
REGISTER_VAR( m_cVarVolume, Volume, "volume" )
REGISTER_VAR( m_cVarStream, Stream, "stream" )
REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
#undef REGISTER_VAR
// XXX WARNING XXX
// The object variable callbacks are called from other VLC threads,
// so they must put commands in the queue and NOT do anything else
// (X11 calls are not reentrant)
// Called when the playlist changes
var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
onIntfChange, this );
// Called when the current played item changes
var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
onPlaylistChange, this );
// Called when a playlist item changed
var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
onItemChange, this );
// Called when our skins2 demux wants us to load a new skin
var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
// Callbacks for vout requests
getIntf()->pf_request_window = &getWindow;
getIntf()->pf_release_window = &releaseWindow;
getIntf()->pf_control_window = &controlWindow;
getIntf()->p_sys->p_input = NULL;*/
var_Create( pIntf, "intf-skins", VLC_VAR_STRING | var_Create( pIntf, "intf-skins", VLC_VAR_STRING |
VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND ); VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND );
text.psz_string = _("Select skin"); text.psz_string = _("Select skin");
var_Change( pIntf, "intf-skins", VLC_VAR_SETTEXT, &text, NULL ); var_Change( pIntf, "intf-skins", VLC_VAR_SETTEXT, &text, NULL );
val.psz_string = "test"; // Scan vlt files in the resource path
text.psz_string = "test"; OSFactory *pOsFactory = OSFactory::instance( pIntf );
var_Change( pIntf, "intf-skins", VLC_VAR_ADDCHOICE, list<string> resPath = pOsFactory->getResourcePath();
&val, &text ); list<string>::const_iterator it;
for( it = resPath.begin(); it != resPath.end(); it++ )
/* Only fill the list with available modules */
/* p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
for( ppsz_parser = ppsz_interfaces; *ppsz_parser; ppsz_parser += 2 )
{ {
for( i = 0; i < p_list->i_count; i++ ) parseDirectory( *it );
{
module_t *p_module = (module_t *)p_list->p_values[i].p_object;
if( !strcmp( p_module->psz_object_name, ppsz_parser[0] ) )
{
val.psz_string = ppsz_parser[0];
text.psz_string = ppsz_parser[1];
var_Change( p_intf, "intf-switch", VLC_VAR_ADDCHOICE,
&val, &text );
break;
}
}
} }
vlc_list_release( p_list );
*/
var_AddCallback( pIntf, "intf-skins", changeSkin, this );
// Add an entry for the "open skin" dialog
val.psz_string = (char*)kOpenDialog;
text.psz_string = "Open skin...";
var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
&text );
// Set the callback
var_AddCallback( pIntf, "intf-skins", changeSkin, this );
} }
ThemeRepository::~ThemeRepository() ThemeRepository::~ThemeRepository()
{ {
/* m_pTimer->stop(); var_Destroy( getIntf(), "intf-skins" );
delete( m_pTimer ); }
if( getIntf()->p_sys->p_input )
void ThemeRepository::parseDirectory( const string &rDir )
{
DIR *pDir;
struct dirent *pDirContent;
vlc_value_t val, text;
// Path separator
const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
// Open the dir
pDir = opendir( rDir.c_str() );
if( pDir == NULL )
{ {
vlc_object_release( getIntf()->p_sys->p_input ); // An error occurred
msg_Dbg( getIntf(), "Cannot open directory %s", rDir.c_str() );
return;
} }
// Callbacks for vout requests // Get the first directory entry
getIntf()->pf_request_window = NULL; pDirContent = readdir( pDir );
getIntf()->pf_release_window = NULL;
getIntf()->pf_control_window = NULL; // While we still have entries in the directory
while( pDirContent != NULL )
var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change", {
onIntfChange, this ); string name = pDirContent->d_name;
var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current", if( name.size() > 4 && name.substr( name.size() - 4, 4 ) == ".vlt" )
onPlaylistChange, this ); {
var_DelCallback( getIntf()->p_sys->p_playlist, "item-change", string path = rDir + sep + name;
onItemChange, this );*/ msg_Dbg( getIntf(), "found skin %s", path.c_str() );
// Add the theme in the popup menu
val.psz_string = (char*)path.c_str();
text.psz_string = (char*)name.substr(0, name.size() - 4).c_str();
var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
&text );
}
pDirContent = readdir( pDir );
}
} }
int ThemeRepository::changeSkin( vlc_object_t *pThis, char const *pCmd,
int ThemeRepository::changeSkin( vlc_object_t *pIntf, char const *pCmd,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
void *pData ) void *pData )
{ {
/* intf_thread_t *p_intf = (intf_thread_t *)p_this; ThemeRepository *pThis = (ThemeRepository*)(pData);
// Special menu entry for the open skin dialog
if( !strcmp( newval.psz_string, kOpenDialog ) )
{
CmdDlgChangeSkin cmd( pThis->getIntf() );
cmd.execute();
}
else
{
// Try to load the new skin
CmdChangeSkin *pCmd = new CmdChangeSkin( pThis->getIntf(),
newval.psz_string );
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
pQueue->remove( "change skin" );
pQueue->push( CmdGenericPtr( pCmd ) );
}
p_intf->psz_switch_intf =
malloc( strlen(newval.psz_string) + sizeof(",none") );
sprintf( p_intf->psz_switch_intf, "%s,none", newval.psz_string );
p_intf->b_die = VLC_TRUE;
*/
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -44,6 +44,12 @@ class ThemeRepository: public SkinObject ...@@ -44,6 +44,12 @@ class ThemeRepository: public SkinObject
virtual ~ThemeRepository(); virtual ~ThemeRepository();
private: private:
/// Identifier for the special menu entry
static const char *kOpenDialog;
/// Look for themes in a directory
void parseDirectory( const string &rDir );
/// Callback for menu item selection /// Callback for menu item selection
static int changeSkin( vlc_object_t *pThis, char const *pCmd, static int changeSkin( vlc_object_t *pThis, char const *pCmd,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment