]> git.sesse.net Git - vlc/commitdiff
Skins2: Factor out repeated code and use var_SetVariant where applicable.
authorJP Dinger <jpd@videolan.org>
Fri, 20 Nov 2009 14:59:23 +0000 (15:59 +0100)
committerJP Dinger <jpd@videolan.org>
Sat, 5 Dec 2009 21:25:41 +0000 (22:25 +0100)
modules/gui/skins2/vars/time.cpp
modules/gui/skins2/vars/time.hpp

index b62b488e0959fb20f13d1bd1f240e3f929018369..5290c8abf4b825de093d1149d3f6374a2aaec509 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-
-#include "time.hpp"
 #include <vlc_input.h>
+#include "time.hpp"
+
+
+inline bool StreamTime::havePosition() const {
+    input_thread_t *p_input = getIntf()->p_sys->p_input;
+    return p_input && ( var_GetFloat( p_input, "position" ) != 0.0 );
+}
+
 
 void StreamTime::set( float percentage, bool updateVLC )
 {
@@ -48,66 +54,33 @@ const string StreamTime::getAsStringPercent() const
 
 const string StreamTime::getAsStringCurrTime( bool bShortFormat ) const
 {
-    if( getIntf()->p_sys->p_input == NULL )
-    {
+    if( !havePosition() )
         return "-:--:--";
-    }
-
-    vlc_value_t pos; pos.f_float = 0.0;
-    var_Get( getIntf()->p_sys->p_input, "position", &pos );
-    if( pos.f_float == 0.0 )
-    {
-        return "-:--:--";
-    }
-
-    vlc_value_t time; time.i_time = 0L;
-    var_Get( getIntf()->p_sys->p_input, "time", &time );
 
-    return formatTime( time.i_time / 1000000, bShortFormat );
+    mtime_t time = var_GetTime( getIntf()->p_sys->p_input, "time" );
+    return formatTime( time / 1000000, bShortFormat );
 }
 
 
 const string StreamTime::getAsStringTimeLeft( bool bShortFormat ) const
 {
-    if( getIntf()->p_sys->p_input == NULL )
-    {
+    if( !havePosition() )
         return "-:--:--";
-    }
 
-    vlc_value_t pos;
-    var_Get( getIntf()->p_sys->p_input, "position", &pos );
-    if( pos.f_float == 0.0 )
-    {
-        return "-:--:--";
-    }
-
-    vlc_value_t time, duration;
-    var_Get( getIntf()->p_sys->p_input, "time", &time );
-    var_Get( getIntf()->p_sys->p_input, "length", &duration );
+    mtime_t time = var_GetTime( getIntf()->p_sys->p_input, "time" ),
+        duration = var_GetTime( getIntf()->p_sys->p_input, "length" );
 
-    return formatTime( (duration.i_time - time.i_time) / 1000000,
-                       bShortFormat );
+    return formatTime( (duration - time) / 1000000, bShortFormat );
 }
 
 
 const string StreamTime::getAsStringDuration( bool bShortFormat ) const
 {
-    if( getIntf()->p_sys->p_input == NULL )
-    {
+    if( !havePosition() )
         return "-:--:--";
-    }
-
-    vlc_value_t pos; pos.f_float = 0.0;
-    var_Get( getIntf()->p_sys->p_input, "position", &pos );
-    if( pos.f_float == 0.0 )
-    {
-        return "-:--:--";
-    }
-
-    vlc_value_t time;
-    var_Get( getIntf()->p_sys->p_input, "length", &time );
 
-    return formatTime( time.i_time / 1000000, bShortFormat );
+    mtime_t time = var_GetTime( getIntf()->p_sys->p_input, "length" );
+    return formatTime( time / 1000000, bShortFormat );
 }
 
 
index ea4cb70992827dae5884641864302a8404511978..f82a30dfea36bc5a8ffaef816c7d1df8dd7a7b51 100644 (file)
@@ -51,6 +51,8 @@ public:
 private:
     /// Convert a number of seconds into "h:mm:ss" format
     const string formatTime( int seconds, bool bShortFormat ) const;
+    /// Return true when there is a non-null input and its position is not 0.0.
+    bool havePosition() const;
 };
 
 #endif