Mercurial > audlegacy-plugins
changeset 795:ca6dca840074 trunk
[svn] - statusicon: re-display statusicon popup with updated information when song (or title) changes, closes bug #846
author | giacomo |
---|---|
date | Wed, 07 Mar 2007 16:45:38 -0800 |
parents | 93dbfe1f0cd0 |
children | f3ce11fad729 |
files | ChangeLog src/statusicon/si.c src/statusicon/si_common.h src/statusicon/si_ui.c |
diffstat | 4 files changed, 155 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Mar 07 06:49:54 2007 -0800 +++ b/ChangeLog Wed Mar 07 16:45:38 2007 -0800 @@ -1,3 +1,11 @@ +2007-03-07 14:49:54 +0000 Yoshiki Yazawa <yaz@cc.rim.or.jp> + revision [1686] + - same sanity check on rarely executed part. + + trunk/src/madplug/decoder.c | 12 +++++++++++- + 1 file changed, 11 insertions(+), 1 deletion(-) + + 2007-03-07 14:16:04 +0000 Yoshiki Yazawa <yaz@cc.rim.or.jp> revision [1684] - add sanity check for open audio parameters.
--- a/src/statusicon/si.c Wed Mar 07 06:49:54 2007 -0800 +++ b/src/statusicon/si.c Wed Mar 07 16:45:38 2007 -0800 @@ -43,7 +43,7 @@ g_type_init(); g_log_set_handler( NULL , G_LOG_LEVEL_WARNING , g_log_default_handler , NULL ); plugin_active = TRUE; - si_ui_statusicon_show(); + si_ui_statusicon_enable( TRUE ); return; } @@ -54,7 +54,7 @@ if ( plugin_active == TRUE ) { plugin_active = FALSE; - si_ui_statusicon_hide(); + si_ui_statusicon_enable( FALSE ); } return; }
--- a/src/statusicon/si_common.h Wed Mar 07 06:49:54 2007 -0800 +++ b/src/statusicon/si_common.h Wed Mar 07 16:45:38 2007 -0800 @@ -30,6 +30,6 @@ #include "../../config.h" -#define SI_VERSION_PLUGIN "0.1" +#define SI_VERSION_PLUGIN "0.2" #endif /* !_I_ED_COMMON_H */
--- a/src/statusicon/si_ui.c Wed Mar 07 06:49:54 2007 -0800 +++ b/src/statusicon/si_ui.c Wed Mar 07 16:45:38 2007 -0800 @@ -34,7 +34,15 @@ #include <gtk/gtk.h> -static GtkWidget * si_evbox = NULL; + +/* this stuff required to make titlechange hook work properly */ +typedef struct +{ + gchar *title; + gchar *filename; + gpointer evbox; +} +si_hook_tchange_prevs_t; static GtkTrayIcon * @@ -100,7 +108,7 @@ GtkWidget *popup = g_object_get_data( G_OBJECT(evbox) , "popup" ); tuple = playlist_get_tuple( pl_active , pos ); - if (( tuple == NULL ) || (( tuple->track_name == NULL ) && ( tuple->length < 1 ))) + if ( ( tuple == NULL ) || ( tuple->length < 1 ) ) { gchar *title = playlist_get_songtitle( pl_active , pos ); audacious_fileinfopopup_show_from_title( popup , title ); @@ -154,6 +162,63 @@ } +static void +si_ui_statusicon_cb_hook_pbstart ( gpointer plentry_gp , gpointer evbox ) +{ + if ( ( GPOINTER_TO_INT(g_object_get_data( G_OBJECT(evbox) , "popup_active" )) == 1 ) && + ( plentry_gp != NULL ) ) + { + si_ui_statusicon_popup_hide( evbox ); + si_ui_statusicon_popup_timer_start( evbox ); + } +} + + +static void +si_ui_statusicon_cb_hook_tchange ( gpointer plentry_gp , gpointer prevs_gp ) +{ + si_hook_tchange_prevs_t *prevs = prevs_gp; + if ( ( GPOINTER_TO_INT(g_object_get_data( G_OBJECT(prevs->evbox) , "popup_active" )) == 1 ) && + ( plentry_gp != NULL ) ) + { + PlaylistEntry *pl_entry = plentry_gp; + if ( ( prevs->title != NULL ) && ( prevs->filename != NULL ) ) + { + if ( ( pl_entry->filename != NULL ) && + ( !strcmp(pl_entry->filename,prevs->filename) ) ) + { + if ( ( pl_entry->title != NULL ) && + ( strcmp(pl_entry->title,prevs->title) ) ) + { + si_ui_statusicon_popup_hide( prevs->evbox ); + si_ui_statusicon_popup_timer_start( prevs->evbox ); + g_free( prevs->title ); + prevs->title = g_strdup(pl_entry->title); + } + } + else + { + g_free(prevs->filename); + prevs->filename = g_strdup(pl_entry->filename); + /* if filename changes, reset title as well */ + if ( prevs->title != NULL ) + g_free(prevs->title); + prevs->title = g_strdup(pl_entry->title); + } + } + else + { + if ( prevs->title != NULL ) + g_free(prevs->title); + prevs->title = g_strdup(pl_entry->title); + if ( prevs->filename != NULL ) + g_free(prevs->filename); + prevs->filename = g_strdup(pl_entry->filename); + } + } +} + + static gboolean si_ui_statusicon_cb_popup ( GtkWidget * evbox , GdkEvent * event ) { @@ -258,72 +323,89 @@ void -si_ui_statusicon_show ( void ) +si_ui_statusicon_enable ( gboolean enable ) { - GtkWidget *si_image; - GtkWidget *si_popup; - GtkTrayIcon *si_applet; - GtkRequisition req; - GtkAllocation allocation; + static GtkWidget * si_evbox = NULL; + static si_hook_tchange_prevs_t * si_hook_tchange_prevs = NULL; + + if ( enable == TRUE ) + { + GtkWidget *si_image; + GtkWidget *si_popup; + GtkTrayIcon *si_applet; + GtkRequisition req; + GtkAllocation allocation; + + si_applet = si_ui_statusicon_create(); + if ( si_applet == NULL ) + { + g_warning( "StatusIcon plugin: unable to create a status icon.\n" ); + return; + } + + si_image = gtk_image_new(); + g_object_set_data( G_OBJECT(si_image) , "size" , GINT_TO_POINTER(0) ); + + g_signal_connect( si_image , "size-allocate" , + G_CALLBACK(si_ui_statusicon_cb_image_sizalloc) , si_applet ); + + si_evbox = gtk_event_box_new(); + si_popup = audacious_fileinfopopup_create(); + + g_object_set_data( G_OBJECT(si_evbox) , "applet" , si_applet ); - si_applet = si_ui_statusicon_create(); - if ( si_applet == NULL ) - { - g_warning( "StatusIcon plugin: unable to create a status icon.\n" ); + g_object_set_data( G_OBJECT(si_evbox) , "timer_id" , GINT_TO_POINTER(0) ); + g_object_set_data( G_OBJECT(si_evbox) , "timer_active" , GINT_TO_POINTER(0) ); + + g_object_set_data( G_OBJECT(si_evbox) , "popup_active" , GINT_TO_POINTER(0) ); + g_object_set_data( G_OBJECT(si_evbox) , "popup" , si_popup ); + + g_signal_connect( G_OBJECT(si_evbox) , "button-press-event" , + G_CALLBACK(si_ui_statusicon_cb_btpress) , NULL ); + g_signal_connect( G_OBJECT(si_evbox) , "scroll-event" , + G_CALLBACK(si_ui_statusicon_cb_btscroll) , NULL ); + g_signal_connect_after( G_OBJECT(si_evbox) , "event-after" , + G_CALLBACK(si_ui_statusicon_cb_popup) , NULL ); + + gtk_container_add( GTK_CONTAINER(si_evbox), si_image ); + gtk_container_add( GTK_CONTAINER(si_applet), si_evbox ); + + gtk_widget_show_all( GTK_WIDGET(si_applet) ); + + gtk_widget_size_request( GTK_WIDGET(si_applet) , &req ); + allocation.x = 0; + allocation.y = 0; + allocation.width = req.width; + allocation.height = req.height; + gtk_widget_size_allocate( GTK_WIDGET(si_applet) , &allocation ); + + hook_associate( "playback begin" , si_ui_statusicon_cb_hook_pbstart , si_evbox ); + si_hook_tchange_prevs = g_malloc0(sizeof(si_hook_tchange_prevs_t)); + si_hook_tchange_prevs->title = NULL; + si_hook_tchange_prevs->filename = NULL; + si_hook_tchange_prevs->evbox = si_evbox; + hook_associate( "playlist set info" , si_ui_statusicon_cb_hook_tchange , si_hook_tchange_prevs ); + return; } - - si_image = gtk_image_new(); - g_object_set_data( G_OBJECT(si_image) , "size" , GINT_TO_POINTER(0) ); - - g_signal_connect( si_image , "size-allocate" , - G_CALLBACK(si_ui_statusicon_cb_image_sizalloc) , si_applet ); - - si_evbox = gtk_event_box_new(); - si_popup = audacious_fileinfopopup_create(); - - g_object_set_data( G_OBJECT(si_evbox) , "applet" , si_applet ); - - g_object_set_data( G_OBJECT(si_evbox) , "timer_id" , GINT_TO_POINTER(0) ); - g_object_set_data( G_OBJECT(si_evbox) , "timer_active" , GINT_TO_POINTER(0) ); - - g_object_set_data( G_OBJECT(si_evbox) , "popup_active" , GINT_TO_POINTER(0) ); - g_object_set_data( G_OBJECT(si_evbox) , "popup" , si_popup ); - - g_signal_connect( G_OBJECT(si_evbox) , "button-press-event" , - G_CALLBACK(si_ui_statusicon_cb_btpress) , NULL ); - g_signal_connect( G_OBJECT(si_evbox) , "scroll-event" , - G_CALLBACK(si_ui_statusicon_cb_btscroll) , NULL ); - g_signal_connect_after( G_OBJECT(si_evbox) , "event-after" , - G_CALLBACK(si_ui_statusicon_cb_popup) , NULL ); - - gtk_container_add( GTK_CONTAINER(si_evbox), si_image ); - gtk_container_add( GTK_CONTAINER(si_applet), si_evbox ); - - gtk_widget_show_all( GTK_WIDGET(si_applet) ); - - gtk_widget_size_request( GTK_WIDGET(si_applet) , &req ); - allocation.x = 0; - allocation.y = 0; - allocation.width = req.width; - allocation.height = req.height; - gtk_widget_size_allocate( GTK_WIDGET(si_applet) , &allocation ); - - return; -} - - -void -si_ui_statusicon_hide ( void ) -{ - if ( si_evbox != NULL ) + else { - GtkTrayIcon *si_applet = g_object_get_data( G_OBJECT(si_evbox) , "applet" ); - si_ui_statusicon_popup_timer_stop( si_evbox ); /* just in case the timer is active */ - gtk_widget_destroy( GTK_WIDGET(si_evbox) ); - gtk_widget_destroy( GTK_WIDGET(si_applet) ); + if ( si_evbox != NULL ) + { + GtkTrayIcon *si_applet = g_object_get_data( G_OBJECT(si_evbox) , "applet" ); + si_ui_statusicon_popup_timer_stop( si_evbox ); /* just in case the timer is active */ + gtk_widget_destroy( GTK_WIDGET(si_evbox) ); + gtk_widget_destroy( GTK_WIDGET(si_applet) ); + hook_dissociate( "playback begin" , si_ui_statusicon_cb_hook_pbstart ); + hook_dissociate( "playlist set info" , si_ui_statusicon_cb_hook_tchange ); + if ( si_hook_tchange_prevs->title != NULL ) g_free( si_hook_tchange_prevs->title ); + if ( si_hook_tchange_prevs->filename != NULL ) g_free( si_hook_tchange_prevs->filename ); + g_free( si_hook_tchange_prevs ); + si_hook_tchange_prevs = NULL; + si_evbox = NULL; + } + return; } - return; }