[vlc-devel] commit: Skins2: Factor out repeated code and use var_SetVariant where applicable. ( JP Dinger )

git version control git at videolan.org
Sat Dec 5 22:35:08 CET 2009


vlc | branch: master | JP Dinger <jpd at videolan.org> | Fri Nov 20 15:59:23 2009 +0100| [abaee12ac65e5a92d78ab91004cd0c99de4f60e3] | committer: JP Dinger 

Skins2: Factor out repeated code and use var_SetVariant where applicable.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=abaee12ac65e5a92d78ab91004cd0c99de4f60e3
---

 modules/gui/skins2/vars/time.cpp |   69 +++++++++++--------------------------
 modules/gui/skins2/vars/time.hpp |    2 +
 2 files changed, 23 insertions(+), 48 deletions(-)

diff --git a/modules/gui/skins2/vars/time.cpp b/modules/gui/skins2/vars/time.cpp
index b62b488..5290c8a 100644
--- a/modules/gui/skins2/vars/time.cpp
+++ b/modules/gui/skins2/vars/time.cpp
@@ -17,14 +17,20 @@
  * 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 );
 }
 
 
diff --git a/modules/gui/skins2/vars/time.hpp b/modules/gui/skins2/vars/time.hpp
index ea4cb70..f82a30d 100644
--- a/modules/gui/skins2/vars/time.hpp
+++ b/modules/gui/skins2/vars/time.hpp
@@ -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




More information about the vlc-devel mailing list