Prep for the next release.
[stopish] / src / timer.c
index 41f9f3a..42f65d5 100644 (file)
 static long int timerStartTime = 0;
 static long int timerSave = 0;
 
-
-//
-// Timer callback
-//
-gint stopish_timeout_cb( gpointer data )
-{
-    GtkLabel *timerLabel;
-    char formatBuffer[128];
-    char *tempString;
-
-    if ( !data )
-        return -1;
-
-    timerLabel = ( GtkLabel * ) data;
-
-    // print to screen
-    tempString = stopish_get_time_string(  );
-    sprintf( formatBuffer, "<span font_family=\"monospace\" "
-                          "size=\"70000\" weight=\"ultrabold\">"
-                          "%s</span>", tempString );
-    free( tempString );
-    gtk_label_set_markup( GTK_LABEL( timerLabel ), formatBuffer );
-
-    return TRUE;
-}
+//Preferences
+static int timerPrecision = TIMER_PRECISION_MINUTE;
 
 
 char *stopish_get_time_string( void )
@@ -72,15 +49,24 @@ char *stopish_get_time_string( void )
     h = m / 60;
     m = m % 60;
 
-    // rollover once we hit one day
-    if ( h > 24 ) {
+    if ( timerPrecision == TIMER_PRECISION_MINUTE && m > 60 ) {
+        // rollover once we hit one hour
+        stopish_set_time_start( stopish_current_time(  ) );
+        h = m = s = ss = 0;
+    }
+    else if ( timerPrecision == TIMER_PRECISION_HOUR && h > 24 ) {
+        // rollover once we hit one day
         stopish_set_time_start( stopish_current_time(  ) );
         h = m = s = ss = 0;
     }
 
     timeBuffer = malloc( 64 );
-    sprintf( timeBuffer, "%.02d:%.02d:%.02d.%.1d",
-             h, m, s, ss );
+    if ( timerPrecision == TIMER_PRECISION_MINUTE )
+        sprintf( timeBuffer, "%.02d:%.02d.%.1d",
+                 m, s, ss );
+    else
+        sprintf( timeBuffer, "%.02d:%.02d:%.02d.%.1d",
+                 h, m, s, ss );
 
     return timeBuffer;
 }
@@ -119,3 +105,15 @@ long int stopish_current_time( void )
 
     return ( s * 10 + us );
 }
+
+
+void stopish_timer_set_precision( int setting )
+{
+    timerPrecision = setting;
+}
+
+
+int stopish_timer_get_precision( void )
+{
+    return timerPrecision;
+}