3 // Copyright 2009 Michael Cronenworth <mike@cchtml.com>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 // MA 02110-1301, USA.
28 static long int timerStartTime = 0;
29 static long int timerSave = 0;
35 gint stopish_timeout_cb( gpointer data )
38 char formatBuffer[128];
44 timerLabel = ( GtkLabel * ) data;
47 tempString = stopish_get_time_string( );
48 sprintf( formatBuffer, "<span font_family=\"monospace\" "
49 "size=\"70000\" weight=\"ultrabold\">"
50 "%s</span>", tempString );
52 gtk_label_set_markup( GTK_LABEL( timerLabel ), formatBuffer );
58 char *stopish_get_time_string( void )
65 currentTime = stopish_current_time( );
67 // calculate time format
68 ss = ( currentTime - timerStartTime ) % 10;
69 s = ( currentTime - timerStartTime ) / 10;
75 // rollover once we hit one day
77 stopish_set_time_start( stopish_current_time( ) );
81 timeBuffer = malloc( 64 );
82 sprintf( timeBuffer, "%.02d:%.02d:%.02d.%.1d",
89 void stopish_set_time_start( long int time )
91 // reset timer to user-inputted time
92 timerStartTime = time;
97 void stopish_timer_resume( void )
99 timerStartTime = stopish_current_time( );
100 timerStartTime -= timerSave;
104 void stopish_timer_save( void )
107 timerSave = stopish_current_time( ) - timerStartTime;
111 long int stopish_current_time( void )
116 gettimeofday( &tv, NULL );
117 s = tv.tv_sec % 100000;
118 us = tv.tv_usec / 100000;
120 return ( s * 10 + us );