Commit d8158122 authored by Olivier Teulière's avatar Olivier Teulière

* skins2/parser/builder.cpp: check Font::init()'s return value

 * skins/utils/var_text.cpp: added $D (duration) and $L (time left) variables
parent af178856
...@@ -133,8 +133,14 @@ void Builder::addFont( const BuilderData::Font &rData ) ...@@ -133,8 +133,14 @@ void Builder::addFont( const BuilderData::Font &rData )
{ {
GenericFont *pFont = new FT2Font( getIntf(), rData.m_fontName, GenericFont *pFont = new FT2Font( getIntf(), rData.m_fontName,
rData.m_size ); rData.m_size );
pFont->init(); if( pFont->init() )
m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont ); {
m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
}
else
{
delete pFont;
}
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* var_text.cpp * var_text.cpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: var_text.cpp,v 1.2 2004/01/11 17:12:17 asmax Exp $ * $Id$
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr> * Olivier Teulire <ipkiss@via.ecp.fr>
...@@ -55,7 +55,8 @@ const UString VarText::get() const ...@@ -55,7 +55,8 @@ const UString VarText::get() const
VlcProc *pVlcProc = VlcProc::instance( getIntf() ); VlcProc *pVlcProc = VlcProc::instance( getIntf() );
// Fill a temporary UString object, and replace the escape characters // Fill a temporary UString object, and replace the escape characters
// ($H for help, $T for time, $V for volume) // ($H for help, $T for current time, $L for time left, $D for duration,
// $V for volume)
UString temp( m_text ); UString temp( m_text );
while( (pos = temp.find( "$H" )) != UString::npos ) while( (pos = temp.find( "$H" )) != UString::npos )
...@@ -67,7 +68,17 @@ const UString VarText::get() const ...@@ -67,7 +68,17 @@ const UString VarText::get() const
while( (pos = temp.find( "$T" )) != UString::npos ) while( (pos = temp.find( "$T" )) != UString::npos )
{ {
temp.replace( pos, 2, temp.replace( pos, 2,
pVlcProc->getTimeVar().getAsStringTime().c_str() ); pVlcProc->getTimeVar().getAsStringCurrTime().c_str() );
}
while( (pos = temp.find( "$L" )) != UString::npos )
{
temp.replace( pos, 2,
pVlcProc->getTimeVar().getAsStringTimeLeft().c_str() );
}
while( (pos = temp.find( "$D" )) != UString::npos )
{
temp.replace( pos, 2,
pVlcProc->getTimeVar().getAsStringDuration().c_str() );
} }
while( (pos = temp.find( "$V" )) != UString::npos ) while( (pos = temp.find( "$V" )) != UString::npos )
{ {
...@@ -105,6 +116,14 @@ void VarText::set( const UString &rText ) ...@@ -105,6 +116,14 @@ void VarText::set( const UString &rText )
{ {
pVlcProc->getTimeVar().addObserver( this ); pVlcProc->getTimeVar().addObserver( this );
} }
if( m_text.find( "$L" ) != UString::npos )
{
pVlcProc->getTimeVar().addObserver( this );
}
if( m_text.find( "$D" ) != UString::npos )
{
pVlcProc->getTimeVar().addObserver( this );
}
if( m_text.find( "$V" ) != UString::npos ) if( m_text.find( "$V" ) != UString::npos )
{ {
pVlcProc->getVolumeVar().addObserver( this ); pVlcProc->getVolumeVar().addObserver( this );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* time.cpp * time.cpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: time.cpp,v 1.2 2004/01/11 17:12:17 asmax Exp $ * $Id$
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr> * Olivier Teulire <ipkiss@via.ecp.fr>
...@@ -48,7 +48,7 @@ void Time::set( float percentage, bool updateVLC ) ...@@ -48,7 +48,7 @@ void Time::set( float percentage, bool updateVLC )
} }
string Time::getAsStringPercent() const const string Time::getAsStringPercent() const
{ {
int value = (int)(100. * get()); int value = (int)(100. * get());
// 0 <= value <= 100, so we need 4 chars // 0 <= value <= 100, so we need 4 chars
...@@ -61,7 +61,7 @@ string Time::getAsStringPercent() const ...@@ -61,7 +61,7 @@ string Time::getAsStringPercent() const
} }
string Time::getAsStringTime() const const string Time::getAsStringCurrTime() const
{ {
if( getIntf()->p_sys->p_input == NULL || if( getIntf()->p_sys->p_input == NULL ||
!getIntf()->p_sys->p_input->stream.b_seekable ) !getIntf()->p_sys->p_input->stream.b_seekable )
...@@ -70,14 +70,50 @@ string Time::getAsStringTime() const ...@@ -70,14 +70,50 @@ string Time::getAsStringTime() const
} }
vlc_value_t time; vlc_value_t time;
char *psz_time = new char[MSTRTIME_MAX_SIZE];
var_Get( getIntf()->p_sys->p_input, "time", &time ); var_Get( getIntf()->p_sys->p_input, "time", &time );
int i_seconds = time.i_time / 1000000; return formatTime( time.i_time / 1000000 );
}
const string Time::getAsStringTimeLeft() const
{
if( getIntf()->p_sys->p_input == NULL ||
!getIntf()->p_sys->p_input->stream.b_seekable )
{
return "-:--:--";
}
vlc_value_t time, duration;
var_Get( getIntf()->p_sys->p_input, "time", &time );
var_Get( getIntf()->p_sys->p_input, "length", &duration );
return formatTime( (duration.i_time - time.i_time) / 1000000 );
}
const string Time::getAsStringDuration() const
{
if( getIntf()->p_sys->p_input == NULL ||
!getIntf()->p_sys->p_input->stream.b_seekable )
{
return "-:--:--";
}
vlc_value_t time;
var_Get( getIntf()->p_sys->p_input, "length", &time );
return formatTime( time.i_time / 1000000 );
}
const string Time::formatTime( int seconds ) const
{
char *psz_time = new char[MSTRTIME_MAX_SIZE];
snprintf( psz_time, MSTRTIME_MAX_SIZE, "%d:%02d:%02d", snprintf( psz_time, MSTRTIME_MAX_SIZE, "%d:%02d:%02d",
(int) (i_seconds / (60 * 60)), (int) (seconds / (60 * 60)),
(int) (i_seconds / 60 % 60), (int) (seconds / 60 % 60),
(int) (i_seconds % 60) ); (int) (seconds % 60) );
string ret = psz_time; string ret = psz_time;
delete[] psz_time; delete[] psz_time;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* time.hpp * time.hpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: time.hpp,v 1.2 2004/01/11 17:12:17 asmax Exp $ * $Id$
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr> * Olivier Teulière <ipkiss@via.ecp.fr>
...@@ -40,9 +40,17 @@ class Time: public VarPercent ...@@ -40,9 +40,17 @@ class Time: public VarPercent
virtual void set( float percentage ) { set( percentage, true ); } virtual void set( float percentage ) { set( percentage, true ); }
/// Return a string containing a value from 0 to 100 /// Return a string containing a value from 0 to 100
virtual string getAsStringPercent() const; virtual const string getAsStringPercent() const;
/// Return a string formatted as a time display (h:mm:ss) /// Return the current time formatted as a time display (h:mm:ss)
virtual string getAsStringTime() const; virtual const string getAsStringCurrTime() const;
/// Return the time left formatted as a time display (h:mm:ss)
virtual const string getAsStringTimeLeft() const;
/// Return the duration formatted as a time display (h:mm:ss)
virtual const string getAsStringDuration() const;
private:
/// Convert a number of seconds into "h:mm:ss" format
const string formatTime( int seconds ) const;
}; };
#endif #endif
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