X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fstopish.c;h=af7a7daeb59be1de002a69e372257f126898e9e9;hb=f293aee603c7b4abfb88e3bf8ba44cad54cc2e91;hp=b8923abc43d5d5008369709f29195aedae91452c;hpb=24378226940341b1a14ef3039042f8d643f570ec;p=stopish diff --git a/src/stopish.c b/src/stopish.c index b8923ab..af7a7da 100644 --- a/src/stopish.c +++ b/src/stopish.c @@ -35,6 +35,7 @@ typedef struct _AppData AppData; struct _AppData { GtkWindow *main_window; + GtkWindow *countdown_window; osso_context_t *osso_context; DBusConnection *system_bus; }; @@ -43,17 +44,15 @@ struct _AppData { static AppData appdata; static int stopishMode = STOPISH_MODE_START; static int stopishOrientation = STOPISH_LANDSCAPE; +static int stopishType = STOPISH_TYPE_STOPWATCH; //Prototypes gint dbus_callback( const gchar *interface, const gchar *method, GArray *arguments, gpointer data, osso_rpc_t *retval ); static void main_menu( GtkWindow *window ); +static void change_type_cb( GtkButton* button, gpointer data ); static void close_cb( GtkButton* button, gpointer data ); -static gboolean focus_in_cb( GtkWidget *widget, GdkEventFocus *event, - gpointer data ); -static gboolean focus_out_cb( GtkWidget *widget, GdkEventFocus *event, - gpointer data ); static void accelerometer_enable( void ); static void accelerometer_disable( void ); static DBusHandlerResult mce_filter_func( DBusConnection * connection, @@ -84,9 +83,9 @@ int main( int argc, char *argv[] ) g_signal_connect( G_OBJECT( appdata.main_window ), "destroy", G_CALLBACK( close_cb ), appdata.main_window ); g_signal_connect( G_OBJECT( appdata.main_window ), "focus-in-event", - G_CALLBACK( focus_in_cb ), NULL ); + G_CALLBACK( stopish_focus_in_cb ), NULL ); g_signal_connect( G_OBJECT( appdata.main_window ), "focus-out-event", - G_CALLBACK( focus_out_cb ), NULL ); + G_CALLBACK( stopish_focus_out_cb ), NULL ); // setup main menu main_menu( appdata.main_window ); @@ -131,6 +130,36 @@ gint dbus_callback( const gchar *interface, const gchar *method, } +void stopish_about_cb( GtkButton* button, gpointer data ) +{ + GdkPixbuf *logo; + GError *error; + GtkWidget *dialog; + char *authors[2]; + + authors[0] = strdup( "Michael Cronenworth" ); + authors[1] = NULL; + + dialog = gtk_about_dialog_new( ); + + gtk_about_dialog_set_program_name( GTK_ABOUT_DIALOG( dialog ), + "Stopish" ); + gtk_about_dialog_set_version( GTK_ABOUT_DIALOG( dialog ), + STOPISH_VERSION_STR ); + gtk_about_dialog_set_authors( GTK_ABOUT_DIALOG( dialog ), + ( const char ** ) authors ); + logo = gdk_pixbuf_new_from_file( "/usr/share/icons/hicolor/40x40/hildon/stopish.png", + &error ); + gtk_about_dialog_set_logo( GTK_ABOUT_DIALOG( dialog ), + logo ); + + gtk_dialog_run( GTK_DIALOG( dialog ) ); + + gtk_widget_destroy( dialog ); + free( authors[0] ); +} + + int stopish_get_mode( void ) { return stopishMode; @@ -143,17 +172,60 @@ void stopish_set_mode( int newMode ) } +int stopish_get_type( void ) +{ + return stopishType; +} + + +void stopish_set_type( int newType ) +{ + stopishType = newType; +} + + int stopish_get_orientation( void ) { return stopishOrientation; } +gboolean stopish_focus_in_cb( GtkWidget *widget, GdkEventFocus *event, + gpointer data ) +{ + // enable accelerometer hardware for portrait mode support + accelerometer_enable( ); + + return FALSE; +} + + +gboolean stopish_focus_out_cb( GtkWidget *widget, GdkEventFocus *event, + gpointer data ) +{ + // disable accelerometer for battery savings + accelerometer_disable( ); + + return FALSE; +} + + static void main_menu( GtkWindow *window ) { - GtkWidget *menu, *radio; + HildonAppMenu *menu; + GtkWidget *button, *radio; + + menu = ( HildonAppMenu * ) hildon_app_menu_new( ); - menu = hildon_app_menu_new( ); + button = gtk_button_new_with_label( "Countdown" ); + g_signal_connect_after( G_OBJECT( button ), "clicked", + G_CALLBACK( change_type_cb ), NULL ); + hildon_app_menu_append( menu, GTK_BUTTON( button ) ); + + button = gtk_button_new_with_label( "About" ); + g_signal_connect_after( G_OBJECT( button ), "clicked", + G_CALLBACK( stopish_about_cb ), NULL ); + hildon_app_menu_append( menu, GTK_BUTTON( button ) ); // Hour preference radio = gtk_radio_button_new_with_label( NULL, "Hour" ); @@ -170,42 +242,30 @@ static void main_menu( GtkWindow *window ) hildon_app_menu_add_filter( menu, GTK_BUTTON( radio ) ); // default to minute - gtk_toggle_button_set_active( radio, TRUE ); + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( radio ), TRUE ); - gtk_widget_show_all( menu ); + gtk_widget_show_all( GTK_WIDGET( menu ) ); hildon_window_set_app_menu( HILDON_WINDOW( window ), menu ); } -static void close_cb( GtkButton* button, gpointer data ) -{ - // disable accelerometer for battery savings - accelerometer_disable( ); - - // destroy main window and exit gtk main loop - gtk_widget_destroy( GTK_WIDGET( data ) ); - gtk_main_quit( ); -} - - -static gboolean focus_in_cb( GtkWidget *widget, GdkEventFocus *event, - gpointer data ) +static void change_type_cb( GtkButton* button, gpointer data ) { - // enable accelerometer hardware for portrait mode support - accelerometer_enable( ); - - return FALSE; + stopish_stopwatch_reset( ); + stopishType = STOPISH_TYPE_COUNTDOWN; + stopish_countdown_new( ); } -static gboolean focus_out_cb( GtkWidget *widget, GdkEventFocus *event, - gpointer data ) +static void close_cb( GtkButton* button, gpointer data ) { // disable accelerometer for battery savings accelerometer_disable( ); - return FALSE; + // destroy main window and exit gtk main loop + gtk_widget_destroy( GTK_WIDGET( data ) ); + gtk_main_quit( ); } @@ -248,13 +308,19 @@ 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 ); - stopish_stopwatch_label_timer_portrait( ); + if ( stopishType == STOPISH_TYPE_STOPWATCH ) + stopish_stopwatch_label_timer_portrait( ); + else + stopish_countdown_label_timer_portrait( ); stopishOrientation = STOPISH_PORTRAIT; } else { hildon_gtk_window_set_portrait_flags( GTK_WINDOW( appdata.main_window ), ~HILDON_PORTRAIT_MODE_REQUEST ); - stopish_stopwatch_label_timer_landscape( ); + if ( stopishType == STOPISH_TYPE_STOPWATCH ) + stopish_stopwatch_label_timer_landscape( ); + else + stopish_countdown_label_timer_landscape( ); stopishOrientation = STOPISH_LANDSCAPE; } }