# HG changeset patch # User giacomo # Date 1170377147 28800 # Node ID 1708b03e116c109bdc0e9e132b7fcbab368050e3 # Parent 99e8b9881cb9b64e9589f809530c987b6e44716a [svn] - aosd: replaced polling with hooks; added trigger options as well, working triggers are playback start and title changes diff -r 99e8b9881cb9 -r 1708b03e116c ChangeLog --- a/ChangeLog Thu Feb 01 11:12:38 2007 -0800 +++ b/ChangeLog Thu Feb 01 16:45:47 2007 -0800 @@ -1,3 +1,11 @@ +2007-02-01 19:12:38 +0000 Michael Farber <01mf02@gmail.com> + revision [1276] + - Uncommented some (obviously unneeded?) stuff -> fixed crash + + trunk/src/aac/src/libmp4.c | 3 +++ + 1 file changed, 3 insertions(+) + + 2007-02-01 13:10:14 +0000 Michael Farber <01mf02@gmail.com> revision [1274] - Adapted song_change plugin to new hook functions diff -r 99e8b9881cb9 -r 1708b03e116c src/aosd/Makefile --- a/src/aosd/Makefile Thu Feb 01 11:12:38 2007 -0800 +++ b/src/aosd/Makefile Thu Feb 01 16:45:47 2007 -0800 @@ -3,12 +3,12 @@ OBJECTIVE_LIBS = libaosd$(SHARED_SUFFIX) -noinst_HEADERS = aosd.h aosd_osd.h aosd_style.h aosd_style_private.h aosd_ui.h aosd_cfg.h aosd_common.h ghosd.h ghosd-text.h ghosd-internal.h +noinst_HEADERS = aosd.h aosd_osd.h aosd_style.h aosd_style_private.h aosd_trigger.h aosd_trigger_private.h aosd_ui.h aosd_cfg.h aosd_common.h ghosd.h ghosd-text.h ghosd-internal.h LIBDIR = $(plugindir)/$(GENERAL_PLUGIN_DIR) LIBADD = $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) $(CAIRO_LIBS) $(PANGOCAIRO_LIBS) -SOURCES = aosd.c aosd_osd.c aosd_style.c aosd_ui.c aosd_cfg.c ghosd.c ghosd-text.c ghosd-main.c +SOURCES = aosd.c aosd_osd.c aosd_style.c aosd_trigger.c aosd_ui.c aosd_cfg.c ghosd.c ghosd-text.c ghosd-main.c OBJECTS = ${SOURCES:.c=.o} diff -r 99e8b9881cb9 -r 1708b03e116c src/aosd/aosd.c --- a/src/aosd/aosd.c Thu Feb 01 11:12:38 2007 -0800 +++ b/src/aosd/aosd.c Thu Feb 01 16:45:47 2007 -0800 @@ -21,54 +21,11 @@ #include "aosd.h" #include "aosd_osd.h" #include "aosd_cfg.h" +#include "aosd_trigger.h" #include -#include -#include - - -static guint timeout_sid = 0; -static gchar *prev_title = NULL; -static gboolean was_playing = FALSE; -aosd_cfg_t * global_config = NULL; -gboolean -aosd_check_pl_change ( gpointer data ) -{ - if ( ip_data.playing ) - { - Playlist *active = playlist_get_active(); - gint pos = playlist_get_position(active); - gchar *title = playlist_get_songtitle(active, pos); - - if ( ( title != NULL ) && - ( (( prev_title != NULL ) && ( strcmp(title,prev_title) )) || - ( was_playing == FALSE ) ) ) - { - /* string formatting is done here a.t.m. - TODO - improve this area */ - gchar *utf8_title = str_to_utf8( title ); - gchar *utf8_title_markup = g_markup_printf_escaped( - "%s" , global_config->osd->text.fonts_name[0] , utf8_title ); - aosd_display( utf8_title_markup , global_config->osd , FALSE ); - g_free( utf8_title_markup ); - g_free( utf8_title ); - } - - if ( prev_title != NULL ) - g_free(prev_title); - prev_title = g_strdup(title); - - g_free( title ); - } - else - { - if ( prev_title != NULL ) - { g_free(prev_title); prev_title = NULL; } - } - - was_playing = ip_data.playing; - return TRUE; -} +aosd_cfg_t * global_config = NULL; /* ***************** */ @@ -88,7 +45,8 @@ global_config = aosd_cfg_new(); aosd_cfg_load( global_config ); - timeout_sid = g_timeout_add( 500 , (GSourceFunc)aosd_check_pl_change , NULL ); + aosd_trigger_start( &global_config->osd->trigger ); + return; } @@ -96,14 +54,7 @@ void aosd_cleanup ( void ) { - if ( timeout_sid > 0 ) - g_source_remove( timeout_sid ); - - if ( prev_title != NULL ) - { - g_free(prev_title); - prev_title = NULL; - } + aosd_trigger_stop( &global_config->osd->trigger ); aosd_shutdown(); diff -r 99e8b9881cb9 -r 1708b03e116c src/aosd/aosd_cfg.c --- a/src/aosd/aosd_cfg.c Thu Feb 01 11:12:38 2007 -0800 +++ b/src/aosd/aosd_cfg.c Thu Feb 01 16:45:47 2007 -0800 @@ -70,6 +70,7 @@ aosd_cfg_osd_t *cfg_osd = aosd_cfg_osd_new(); cfg->set = FALSE; cfg->osd = cfg_osd; + cfg->osd->trigger.active = g_array_new( FALSE , TRUE , sizeof(gint) ); return cfg; } @@ -81,6 +82,7 @@ { if ( cfg->osd != NULL ) aosd_cfg_osd_delete( cfg->osd ); + g_array_free( cfg->osd->trigger.active , TRUE ); g_free( cfg ); } return; @@ -160,6 +162,7 @@ aosd_cfg_debug ( aosd_cfg_t * cfg ) { gint i = 0; + GString *string = g_string_new( "" ); g_print("\n***** debug configuration *****\n\n"); g_print("POSITION\n"); g_print(" placement: %i\n", cfg->osd->position.placement); @@ -191,6 +194,13 @@ aosd_color_t color = g_array_index( cfg->osd->decoration.colors , aosd_color_t , i ); g_print(" color %i: %i,%i,%i (alpha %i)\n", i, color.red, color.green, color.blue, color.alpha); } + g_print("\TRIGGER\n"); + for ( i = 0 ; i < cfg->osd->trigger.active->len ; i++ ) + g_string_append_printf( string , "%i," , g_array_index( cfg->osd->trigger.active , gint , i ) ); + if ( string->len > 1 ) + g_string_truncate( string , string->len - 1 ); + g_print(" active: %s\n", string->str); + g_string_free( string , TRUE ); g_print("\nEXTRA\n"); g_print(" set: %i\n", cfg->set); g_print("\n*******************************\n\n"); @@ -205,6 +215,7 @@ ConfigDb *cfgfile = bmp_cfg_db_open(); gint i = 0; gint max_numcol; + gchar *trig_active_str; /* position */ if ( !bmp_cfg_db_get_int( cfgfile , "aosd" , @@ -309,6 +320,25 @@ g_array_insert_val( cfg->osd->decoration.colors , i , color ); } + /* trigger */ + if ( !bmp_cfg_db_get_string( cfgfile , "aosd" , "trigger_active" , &trig_active_str ) ) + { + gint trig_active_defval = 0; + g_array_append_val( cfg->osd->trigger.active , trig_active_defval ); + } + else if ( strcmp("x",trig_active_str) ) + { + gchar **trig_active_strv = g_strsplit( trig_active_str , "," , 0 ); + gint j = 0; + while ( trig_active_strv[j] != NULL ) + { + gint trig_active_val = strtol( trig_active_strv[j] , NULL , 10 ); + g_array_append_val( cfg->osd->trigger.active , trig_active_val ); + j++; + } + g_strfreev( trig_active_strv ); + } + bmp_cfg_db_close( cfgfile ); /* the config object has been filled with information */ @@ -324,6 +354,7 @@ ConfigDb *cfgfile = bmp_cfg_db_open(); gint i = 0; gint max_numcol; + GString *string = g_string_new( "" ); if ( cfg->set == FALSE ) return -1; @@ -404,6 +435,16 @@ g_free( color_str ); } + /* trigger */ + for ( i = 0 ; i < cfg->osd->trigger.active->len ; i++ ) + g_string_append_printf( string , "%i," , g_array_index( cfg->osd->trigger.active , gint , i ) ); + if ( string->len > 1 ) + g_string_truncate( string , string->len - 1 ); + else + g_string_assign( string , "x" ); + bmp_cfg_db_set_string( cfgfile , "aosd" , "trigger_active" , string->str ); + g_string_free( string , TRUE ); + bmp_cfg_db_close( cfgfile ); return 0; diff -r 99e8b9881cb9 -r 1708b03e116c src/aosd/aosd_cfg.h --- a/src/aosd/aosd_cfg.h Thu Feb 01 11:12:38 2007 -0800 +++ b/src/aosd/aosd_cfg.h Thu Feb 01 16:45:47 2007 -0800 @@ -94,6 +94,14 @@ aosd_cfg_osd_position_t; +/* config portion containing osd position information */ +typedef struct +{ + GArray *active; +} +aosd_cfg_osd_trigger_t; + + /* config portion containing all information */ typedef struct { @@ -101,6 +109,7 @@ aosd_cfg_osd_animation_t animation; aosd_cfg_osd_text_t text; aosd_cfg_osd_decoration_t decoration; + aosd_cfg_osd_trigger_t trigger; } aosd_cfg_osd_t; diff -r 99e8b9881cb9 -r 1708b03e116c src/aosd/aosd_ui.c --- a/src/aosd/aosd_ui.c Thu Feb 01 11:12:38 2007 -0800 +++ b/src/aosd/aosd_ui.c Thu Feb 01 16:45:47 2007 -0800 @@ -20,6 +20,7 @@ #include "aosd_ui.h" #include "aosd_style.h" +#include "aosd_trigger.h" #include "aosd_cfg.h" #include "aosd_osd.h" #include @@ -629,6 +630,47 @@ } +static void +aosd_cb_configure_trigger_lvchanged ( GtkTreeSelection *sel , gpointer nb ) +{ + GtkTreeModel *model; + GtkTreeIter iter; + + if ( gtk_tree_selection_get_selected( sel , &model , &iter ) == TRUE ) + { + gint page_num = 0; + gtk_tree_model_get( model , &iter , 2 , &page_num , -1 ); + gtk_notebook_set_current_page( GTK_NOTEBOOK(nb) , page_num ); + } + return; +} + + +static gboolean +aosd_cb_configure_trigger_findinarr ( GArray * array , gint value ) +{ + gint i = 0; + for ( i = 0 ; i < array->len ; i++ ) + { + if ( g_array_index( array , gint , i ) == value ) + return TRUE; + } + return FALSE; +} + + +static void +aosd_cb_configure_trigger_commit ( GtkWidget * cbt , aosd_cfg_t * cfg ) +{ + if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(cbt) ) == TRUE ) + { + gint value = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbt),"code")); + g_array_append_val( cfg->osd->trigger.active , value ); + } + return; +} + + static GtkWidget * aosd_ui_configure_trigger ( aosd_cfg_t * cfg , GList ** cb_list ) { @@ -639,27 +681,63 @@ GtkTreeViewColumn *tri_event_lv_col_desc; GtkTreeSelection *tri_event_lv_sel; GtkTreeIter iter; - GtkWidget *tri_event_label; + gint *trigger_code_array, trigger_code_array_size; + GtkWidget *tri_event_nb; + gint i = 0; + + tri_event_nb = gtk_notebook_new(); + gtk_notebook_set_tab_pos( GTK_NOTEBOOK(tri_event_nb) , GTK_POS_LEFT ); + gtk_notebook_set_show_tabs( GTK_NOTEBOOK(tri_event_nb) , FALSE ); + gtk_notebook_set_show_border( GTK_NOTEBOOK(tri_event_nb) , FALSE ); tri_hbox = gtk_hbox_new( FALSE , 4 ); gtk_container_set_border_width( GTK_CONTAINER(tri_hbox) , 6 ); - /* TODO this part will probably be changed in future! */ - - /* event model + /* trigger model --------------------------------------------- - G_TYPE_STRING -> decoration description + G_TYPE_STRING -> trigger description + G_TYPE_INT -> trigger code + G_TYPE_INT -> gtk notebook page number --------------------------------------------- */ - tri_event_store = gtk_list_store_new( 1 , G_TYPE_STRING ); - gtk_list_store_append( tri_event_store , &iter ); - gtk_list_store_set( tri_event_store , &iter , 0 , _("Song Change") , -1 ); + tri_event_store = gtk_list_store_new( 3 , G_TYPE_STRING , G_TYPE_INT , G_TYPE_INT ); + aosd_trigger_get_codes_array ( &trigger_code_array , &trigger_code_array_size ); + for ( i = 0 ; i < trigger_code_array_size ; i ++ ) + { + GtkWidget *frame, *vbox, *label, *checkbt; + gtk_list_store_append( tri_event_store , &iter ); + gtk_list_store_set( tri_event_store , &iter , + 0 , aosd_trigger_get_name( trigger_code_array[i] ) , + 1 , trigger_code_array[i] , 2 , i , -1 ); + vbox = gtk_vbox_new( FALSE , 0 ); + gtk_container_set_border_width( GTK_CONTAINER(vbox) , 6 ); + label = gtk_label_new( aosd_trigger_get_desc( trigger_code_array[i] ) ); + gtk_label_set_line_wrap( GTK_LABEL(label) , TRUE ); + gtk_misc_set_alignment( GTK_MISC(label) , 0.0 , 0.0 ); + checkbt = gtk_check_button_new_with_label( _("Enable trigger") ); + if ( aosd_cb_configure_trigger_findinarr( cfg->osd->trigger.active , trigger_code_array[i] ) ) + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(checkbt) , TRUE ); + else + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(checkbt) , FALSE ); + gtk_box_pack_start( GTK_BOX(vbox) , checkbt , FALSE , FALSE , 0 ); + gtk_box_pack_start( GTK_BOX(vbox) , gtk_hseparator_new() , FALSE , FALSE , 4 ); + gtk_box_pack_start( GTK_BOX(vbox) , label , FALSE , FALSE , 0 ); + frame = gtk_frame_new( NULL ); + gtk_container_add( GTK_CONTAINER(frame) , vbox ); + gtk_notebook_append_page( GTK_NOTEBOOK(tri_event_nb) , frame , NULL ); + g_object_set_data( G_OBJECT(checkbt) , "code" , GINT_TO_POINTER(trigger_code_array[i]) ); + aosd_callback_list_add( cb_list , checkbt , aosd_cb_configure_trigger_commit ); + } tri_event_lv_frame = gtk_frame_new( NULL ); tri_event_lv = gtk_tree_view_new_with_model( GTK_TREE_MODEL(tri_event_store) ); g_object_unref( tri_event_store ); tri_event_lv_sel = gtk_tree_view_get_selection( GTK_TREE_VIEW(tri_event_lv) ); gtk_tree_selection_set_mode( tri_event_lv_sel , GTK_SELECTION_BROWSE ); + g_signal_connect( G_OBJECT(tri_event_lv_sel) , "changed" , + G_CALLBACK(aosd_cb_configure_trigger_lvchanged) , tri_event_nb ); + if ( gtk_tree_model_get_iter_first( GTK_TREE_MODEL(tri_event_store) , &iter ) == TRUE ) + gtk_tree_selection_select_iter( tri_event_lv_sel , &iter ); tri_event_lv_rndr_text = gtk_cell_renderer_text_new(); tri_event_lv_col_desc = gtk_tree_view_column_new_with_attributes( @@ -674,11 +752,7 @@ gtk_box_pack_start( GTK_BOX(tri_hbox) , tri_event_lv_frame , FALSE , FALSE , 0 ); - tri_event_label = gtk_label_new( _("Song Change is currently the only event that triggers " - "the OSD. Other events will be added in next Audacious OSD versions.") ); - gtk_label_set_line_wrap( GTK_LABEL(tri_event_label) , TRUE ); - gtk_misc_set_alignment( GTK_MISC(tri_event_label) , 0.5 , 0.0 ); - gtk_box_pack_start( GTK_BOX(tri_hbox) , tri_event_label , FALSE , FALSE , 0 ); + gtk_box_pack_start( GTK_BOX(tri_hbox) , tri_event_nb , TRUE , TRUE , 0 ); return tri_hbox; } @@ -727,9 +801,11 @@ if ( global_config != NULL ) { /* plugin is active */ + aosd_trigger_stop( &global_config->osd->trigger ); /* stop triggers */ aosd_cfg_delete( global_config ); /* delete old global_config */ global_config = cfg; /* put the new one */ aosd_cfg_save( cfg ); /* save the new configuration on config file */ + aosd_trigger_start( &cfg->osd->trigger ); /* restart triggers */ } else {