Qt: synchronization: subtitles duration parameter
[vlc/solaris.git] / modules / gui / skins2 / vars / time.cpp
blob3adec7620c7a7dee3f54f4aaec4b1be6db040f8f
1 /*****************************************************************************
2 * time.cpp
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
5 * $Id$
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 along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include <vlc_input.h>
26 #include "time.hpp"
29 inline bool StreamTime::havePosition() const {
30 input_thread_t *p_input = getIntf()->p_sys->p_input;
31 return p_input && ( var_GetFloat( p_input, "position" ) != 0.0 );
35 void StreamTime::set( float percentage, bool updateVLC )
37 VarPercent::set( percentage );
39 // Avoid looping forever...
40 if( updateVLC && getIntf()->p_sys->p_input )
41 var_SetFloat( getIntf()->p_sys->p_input, "position", percentage );
45 string StreamTime::getAsStringPercent() const
47 int value = (int)(100. * get());
48 // 0 <= value <= 100, so we need 4 chars
49 char str[4];
50 snprintf( str, 4, "%d", value );
51 return string(str);
55 string StreamTime::formatTime( int seconds, bool bShortFormat ) const
57 char psz_time[MSTRTIME_MAX_SIZE];
58 if( bShortFormat && (seconds < 60 * 60) )
60 snprintf( psz_time, MSTRTIME_MAX_SIZE, "%02d:%02d",
61 (int) (seconds / 60 % 60),
62 (int) (seconds % 60) );
64 else
66 snprintf( psz_time, MSTRTIME_MAX_SIZE, "%d:%02d:%02d",
67 (int) (seconds / (60 * 60)),
68 (int) (seconds / 60 % 60),
69 (int) (seconds % 60) );
71 return string(psz_time);
75 string StreamTime::getAsStringCurrTime( bool bShortFormat ) const
77 if( !havePosition() )
78 return "-:--:--";
80 mtime_t time = var_GetTime( getIntf()->p_sys->p_input, "time" );
81 return formatTime( time / 1000000, bShortFormat );
85 string StreamTime::getAsStringTimeLeft( bool bShortFormat ) const
87 if( !havePosition() )
88 return "-:--:--";
90 mtime_t time = var_GetTime( getIntf()->p_sys->p_input, "time" ),
91 duration = var_GetTime( getIntf()->p_sys->p_input, "length" );
93 return formatTime( (duration - time) / 1000000, bShortFormat );
97 string StreamTime::getAsStringDuration( bool bShortFormat ) const
99 if( !havePosition() )
100 return "-:--:--";
102 mtime_t time = var_GetTime( getIntf()->p_sys->p_input, "length" );
103 return formatTime( time / 1000000, bShortFormat );