From 5ecc62d6d02f797bbbe6b3bc6ef9af42490f610a Mon Sep 17 00:00:00 2001 From: Michael Cronenworth Date: Wed, 27 Jan 2010 00:02:06 -0600 Subject: [PATCH] Prep for the next release. * Add new portrait mode display. * Add timer precision preference in app menu. Defaults to minute precision. --- debian/changelog | 7 ++ src/stopish.c | 244 +++++++++++++++++++++++++++++++++++++++++++++++++----- src/stopish.h | 9 +- src/timer.c | 56 ++++++------- 4 files changed, 265 insertions(+), 51 deletions(-) diff --git a/debian/changelog b/debian/changelog index 9bbd7aa..ada5252 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +stopish (0.9.2-1) unstable; urgency=low + + * Fix timer display in portrait mode. + * Add timer precision preference. + + -- Michael Cronenworth Wed, 27 Jan 2010 12:00:00 -0600 + stopish (0.9.1-5) unstable; urgency=low * Fix typo with package icon so it displays on Maemo.org. diff --git a/src/stopish.c b/src/stopish.c index bf561d6..270fb8e 100644 --- a/src/stopish.c +++ b/src/stopish.c @@ -40,20 +40,34 @@ struct _AppData { DBusConnection *system_bus; }; +typedef struct timerData { + GtkWidget *vBox; + GtkWidget *label; + GtkWidget *labelHour; + GtkWidget *labelMinute; + GtkWidget *labelSecond; +}; + static AppData appdata; -static GtkWidget *timerLabel = NULL; +static struct timerData timerdata; static GtkWidget *timerHistoryLabel1 = NULL; static GtkWidget *timerHistoryLabel2 = NULL; static GtkWidget *timerHistoryLabel3 = NULL; static GtkWidget *timerHistoryLabel4 = NULL; static GSList *historyList = NULL; static int stopishMode = STOPISH_MODE_START; +static int stopishOrientation = STOPISH_LANDSCAPE; static int timerHandle = -1; + //Prototypes gint dbus_callback( const gchar *interface, const gchar *method, GArray *arguments, gpointer data, osso_rpc_t *retval ); static GtkWindow *stopish_new( void ); +static void main_menu( GtkWindow *window ); +static void label_timer_landscape( void ); +static void label_timer_portrait( void ); +static gint timeout_cb( gpointer data ); static void start_cb( GtkButton* button, gpointer data ); static void reset_cb( GtkButton* button, gpointer data ); static void close_cb( GtkButton* button, gpointer data ); @@ -61,6 +75,8 @@ static gboolean focus_in_cb( GtkWidget *widget, GdkEventFocus *event, gpointer data ); static gboolean focus_out_cb( GtkWidget *widget, GdkEventFocus *event, gpointer data ); +static void preference_timer_hour( GtkRadioButton* radio, GtkLabel *label ); +static void preference_timer_minute( GtkRadioButton* radio, GtkLabel *label ); static void accelerometer_enable( void ); static void accelerometer_disable( void ); static DBusHandlerResult mce_filter_func( DBusConnection * connection, @@ -151,26 +167,21 @@ static GtkWindow *stopish_new( void ) g_signal_connect( G_OBJECT( window ), "focus-out-event", G_CALLBACK( focus_out_cb ), NULL ); + // setup main menu + main_menu( window ); + vBoxMain = gtk_vbox_new( FALSE, 10 ); // separator label = gtk_label_new( NULL ); gtk_container_add( GTK_CONTAINER( vBoxMain ), label ); - // stop watch area vBox0 = gtk_vbox_new( FALSE, 5 ); - // main timer - timerLabel = gtk_label_new( NULL ); - gtk_label_set_markup( GTK_LABEL( timerLabel ), - "" - "00:00:00.0" ); - gtk_widget_set_size_request( timerLabel, 700, -1 ); - gtk_label_set_line_wrap( GTK_LABEL( timerLabel ), TRUE ); - gtk_label_set_line_wrap_mode( GTK_LABEL( timerLabel ), PANGO_WRAP_CHAR ); - gtk_misc_set_alignment( GTK_MISC( timerLabel ), 1.0f, 0.5f ); - gtk_container_add( GTK_CONTAINER( vBox0 ), timerLabel ); + // stop watch area + timerdata.vBox = gtk_vbox_new( FALSE, 0 ); + gtk_container_add( GTK_CONTAINER( vBox0 ), timerdata.vBox ); + label_timer_landscape( ); // history area timerHistoryLabel1 = gtk_label_new( NULL ); @@ -225,6 +236,169 @@ static GtkWindow *stopish_new( void ) } +static void main_menu( GtkWindow *window ) +{ + GtkWidget *menu, *radio; + + menu = hildon_app_menu_new( ); + + // Hour preference + radio = gtk_radio_button_new_with_label( NULL, "Hour" ); + gtk_toggle_button_set_mode( GTK_TOGGLE_BUTTON( radio ), FALSE ); + g_signal_connect_after( radio, "clicked", + G_CALLBACK( preference_timer_hour ), NULL ); + hildon_app_menu_add_filter( menu, GTK_BUTTON( radio ) ); + + // Minute preference + radio = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON( radio ), "Minute" ); + gtk_toggle_button_set_mode( GTK_TOGGLE_BUTTON ( radio ), FALSE ); + g_signal_connect_after( radio, "clicked", + G_CALLBACK( preference_timer_minute ), NULL ); + hildon_app_menu_add_filter( menu, GTK_BUTTON( radio ) ); + + // default to minute + gtk_toggle_button_set_active( radio, TRUE ); + + gtk_widget_show_all( menu ); + + hildon_window_set_app_menu( HILDON_WINDOW( window ), menu ); +} + + +static void label_timer_landscape( void ) +{ + gtk_widget_set_size_request( timerdata.vBox, 800, -1 ); + + gtk_widget_destroy( timerdata.label ); + timerdata.label = gtk_label_new( NULL ); + if ( stopish_timer_get_precision( ) == TIMER_PRECISION_MINUTE ) + gtk_label_set_markup( GTK_LABEL( timerdata.label ), + "" + "00:00.0" ); + else + gtk_label_set_markup( GTK_LABEL( timerdata.label ), + "" + "00:00:00.0" ); + gtk_misc_set_alignment( GTK_MISC( timerdata.label ), 0.5f, 0.5f ); + gtk_container_add( GTK_CONTAINER( timerdata.vBox ), timerdata.label ); + gtk_widget_show( timerdata.label ); +} + + +static void label_timer_portrait( void ) +{ + GtkWidget *vBox, *hBox, *label; + + gtk_widget_set_size_request( timerdata.vBox, 480, -1 ); + + gtk_widget_destroy( timerdata.label ); + vBox = gtk_vbox_new( FALSE, 10 ); + + if ( stopish_timer_get_precision( ) == TIMER_PRECISION_HOUR ) { + hBox = gtk_hbox_new( FALSE, 10 ); + label = gtk_label_new( "Hours" ); + gtk_widget_set_size_request( label, 100, -1 ); + gtk_misc_set_alignment( GTK_MISC( label ), 1.0f, 0.5f ); + gtk_container_add( GTK_CONTAINER( hBox ), label ); + timerdata.labelHour = gtk_label_new( NULL ); + gtk_widget_set_size_request( timerdata.labelHour, 350, -1 ); + gtk_misc_set_alignment( GTK_MISC( timerdata.labelHour ), 0.0f, 0.5f ); + gtk_label_set_markup( GTK_LABEL( timerdata.labelHour ), + "" + "00" ); + gtk_container_add( GTK_CONTAINER( hBox ), timerdata.labelHour ); + gtk_container_add( GTK_CONTAINER( vBox ), hBox ); + } + + hBox = gtk_hbox_new( FALSE, 10 ); + label = gtk_label_new( "Minutes" ); + gtk_widget_set_size_request( label, 100, -1 ); + gtk_misc_set_alignment( GTK_MISC( label ), 1.0f, 0.5f ); + gtk_container_add( GTK_CONTAINER( hBox ), label ); + timerdata.labelMinute = gtk_label_new( NULL ); + gtk_widget_set_size_request( timerdata.labelMinute, 350, -1 ); + gtk_misc_set_alignment( GTK_MISC( timerdata.labelMinute ), 0.0f, 0.5f ); + gtk_label_set_markup( GTK_LABEL( timerdata.labelMinute ), + "" + "00" ); + gtk_container_add( GTK_CONTAINER( hBox ), timerdata.labelMinute ); + gtk_container_add( GTK_CONTAINER( vBox ), hBox ); + + hBox = gtk_hbox_new( FALSE, 10 ); + label = gtk_label_new( "Seconds" ); + gtk_widget_set_size_request( label, 100, -1 ); + gtk_misc_set_alignment( GTK_MISC( label ), 1.0f, 0.5f ); + gtk_container_add( GTK_CONTAINER( hBox ), label ); + timerdata.labelSecond = gtk_label_new( NULL ); + gtk_widget_set_size_request( timerdata.labelSecond, 350, -1 ); + gtk_misc_set_alignment( GTK_MISC( timerdata.labelSecond ), 0.0f, 0.5f ); + gtk_label_set_markup( GTK_LABEL( timerdata.labelSecond ), + "" + "00.0" ); + gtk_container_add( GTK_CONTAINER( hBox ), timerdata.labelSecond ); + gtk_container_add( GTK_CONTAINER( vBox ), hBox ); + + timerdata.label = vBox; + gtk_container_add( GTK_CONTAINER( timerdata.vBox ), vBox ); + gtk_widget_show_all( vBox ); +} + + +// +// Timer callback +// +static gint timeout_cb( gpointer data ) +{ + char formatBuffer[128], tempBuffer[8]; + char *tempString; + + // print to screen + tempString = stopish_get_time_string( ); + if ( stopishOrientation == STOPISH_LANDSCAPE ) { + sprintf( formatBuffer, "" + "%s", tempString ); + gtk_label_set_markup( GTK_LABEL( timerdata.label ), formatBuffer ); + } + else { + if ( stopish_timer_get_precision( ) == TIMER_PRECISION_HOUR ) { + sprintf( tempBuffer, "%.2s", tempString ); + sprintf( formatBuffer, "" + "%s", tempBuffer ); + gtk_label_set_markup( GTK_LABEL( timerdata.labelHour ), + formatBuffer ); + } + if ( stopish_timer_get_precision( ) == TIMER_PRECISION_HOUR ) + sprintf( tempBuffer, "%.2s", tempString + 3 ); + else + sprintf( tempBuffer, "%.2s", tempString ); + sprintf( formatBuffer, "" + "%s", tempBuffer ); + gtk_label_set_markup( GTK_LABEL( timerdata.labelMinute ), + formatBuffer ); + if ( stopish_timer_get_precision( ) == TIMER_PRECISION_HOUR ) + sprintf( tempBuffer, "%.4s", tempString + 6 ); + else + sprintf( tempBuffer, "%.4s", tempString + 3 ); + sprintf( formatBuffer, "" + "%s", tempBuffer ); + gtk_label_set_markup( GTK_LABEL( timerdata.labelSecond ), + formatBuffer ); + } + free( tempString ); + + return TRUE; +} + + static void start_cb( GtkButton* button, gpointer data ) { if ( stopishMode == STOPISH_MODE_START ) { @@ -232,14 +406,14 @@ static void start_cb( GtkButton* button, gpointer data ) gtk_button_set_label( button, "Pause" ); stopishMode = STOPISH_MODE_PAUSE; stopish_set_time_start( stopish_current_time( ) ); - timerHandle = g_timeout_add( 100, stopish_timeout_cb, timerLabel ); + timerHandle = g_timeout_add( 100, timeout_cb, NULL ); } else if ( stopishMode == STOPISH_MODE_RESUME ) { // resume timer gtk_button_set_label( button, "Pause" ); stopishMode = STOPISH_MODE_PAUSE; stopish_timer_resume( ); - timerHandle = g_timeout_add( 100, stopish_timeout_cb, timerLabel ); + timerHandle = g_timeout_add( 100, timeout_cb, NULL ); } else { // pause timer, remove timeout @@ -266,10 +440,16 @@ static void reset_cb( GtkButton* button, gpointer data ) // set label text and remove timer handle gtk_button_set_label( GTK_BUTTON( data ), "Start" ); stopishMode = STOPISH_MODE_START; - gtk_label_set_markup( GTK_LABEL( timerLabel ), - "" - "00:00:00.0" ); + if ( stopish_timer_get_precision( ) == TIMER_PRECISION_MINUTE ) + gtk_label_set_markup( GTK_LABEL( timerdata.label ), + "" + "00:00.0" ); + else + gtk_label_set_markup( GTK_LABEL( timerdata.label ), + "" + "00:00:00.0" ); g_source_remove( timerHandle ); // add current time to history @@ -347,6 +527,26 @@ static gboolean focus_out_cb( GtkWidget *widget, GdkEventFocus *event, } +static void preference_timer_hour( GtkRadioButton* radio, GtkLabel *label ) +{ + stopish_timer_set_precision( TIMER_PRECISION_HOUR ); + if ( stopishOrientation == STOPISH_LANDSCAPE ) + label_timer_landscape( ); + else + label_timer_portrait( ); +} + + +static void preference_timer_minute( GtkRadioButton* radio, GtkLabel *label ) +{ + stopish_timer_set_precision( TIMER_PRECISION_MINUTE ); + if ( stopishOrientation == STOPISH_LANDSCAPE ) + label_timer_landscape( ); + else + label_timer_portrait( ); +} + + static void accelerometer_enable( void ) { if ( osso_rpc_run_system( appdata.osso_context, MCE_SERVICE, @@ -386,12 +586,14 @@ static DBusHandlerResult mce_filter_func( DBusConnection * connection, if ( !strcmp( rotation, MCE_ORIENTATION_PORTRAIT ) ) { hildon_gtk_window_set_portrait_flags( GTK_WINDOW( appdata.main_window ), HILDON_PORTRAIT_MODE_REQUEST ); - gtk_widget_set_size_request( timerLabel, 400, -1 ); + label_timer_portrait( ); + stopishOrientation = STOPISH_PORTRAIT; } else { hildon_gtk_window_set_portrait_flags( GTK_WINDOW( appdata.main_window ), ~HILDON_PORTRAIT_MODE_REQUEST ); - gtk_widget_set_size_request( timerLabel, 700, -1 ); + label_timer_landscape( ); + stopishOrientation = STOPISH_LANDSCAPE; } } else diff --git a/src/stopish.h b/src/stopish.h index 986e3ae..1a43464 100644 --- a/src/stopish.h +++ b/src/stopish.h @@ -25,18 +25,25 @@ #define STOPISH_MODE_PAUSE 1 #define STOPISH_MODE_RESUME 2 +#define STOPISH_PORTRAIT 0 +#define STOPISH_LANDSCAPE 1 + +#define TIMER_PRECISION_HOUR 0 +#define TIMER_PRECISION_MINUTE 1 + // stopish.c gint dbus_callback( const gchar *interface, const gchar *method, GArray *arguments, gpointer data, osso_rpc_t *retval ); int stopish_get_mode( void ); // timer.c -gint stopish_timeout_cb( gpointer data ); char *stopish_get_time_string( void ); long int stopish_get_time_timer( void ); void stopish_set_time_start( long int time ); void stopish_timer_resume( void ); void stopish_timer_save( void ); long int stopish_current_time( void ); +void stopish_timer_set_precision( int setting ); +int stopish_timer_get_precision( void ); #endif diff --git a/src/timer.c b/src/timer.c index 41f9f3a..42f65d5 100644 --- a/src/timer.c +++ b/src/timer.c @@ -28,31 +28,8 @@ 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, "" - "%s", 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; +} -- 1.7.9.5