/*! \brief Enable log playback controls \param state whether to enable or disable the playback controls */ G_MODULE_EXPORT void enable_playback_controls(gboolean state) { static GtkWidget * playback_controls_window = NULL; gchar *fname = NULL; gchar * filename = NULL; GladeXML *xml = NULL; GtkWidget *widget = NULL; GtkAdjustment *adj = NULL; if (state) /* show the controls */ { if (!GTK_IS_WIDGET(playback_controls_window)) { fname = g_build_filename(GUI_DATA_DIR,"logviewer.glade",NULL); filename = get_file(g_strdup(fname),NULL); if (filename) { xml = glade_xml_new(filename, "logviewer_controls_window",NULL); g_free(filename); g_free(fname); glade_xml_signal_autoconnect(xml); playback_controls_window = glade_xml_get_widget(xml,"logviewer_controls_window"); OBJ_SET(glade_xml_get_widget(xml,"goto_start_button"),"handler",GINT_TO_POINTER(LV_GOTO_START)); OBJ_SET(glade_xml_get_widget(xml,"goto_end_button"),"handler",GINT_TO_POINTER(LV_GOTO_END)); OBJ_SET(glade_xml_get_widget(xml,"rewind_button"),"handler",GINT_TO_POINTER(LV_REWIND)); OBJ_SET(glade_xml_get_widget(xml,"fast_forward_button"),"handler",GINT_TO_POINTER(LV_FAST_FORWARD)); OBJ_SET(glade_xml_get_widget(xml,"play_button"),"handler",GINT_TO_POINTER(LV_PLAY)); OBJ_SET(glade_xml_get_widget(xml,"stop_button"),"handler",GINT_TO_POINTER(LV_STOP)); register_widget("logviewer_controls_hbox",glade_xml_get_widget(xml,"controls_hbox")); widget = lookup_widget("logviewer_scroll_hscale"); if (GTK_IS_WIDGET(widget)) { adj = gtk_range_get_adjustment(GTK_RANGE(widget)); gtk_range_set_adjustment(GTK_RANGE(glade_xml_get_widget(xml,"scroll_speed")),adj); } widget = lookup_widget("logviewer_log_position_hscale"); if (GTK_IS_WIDGET(widget)) { adj = gtk_range_get_adjustment(GTK_RANGE(widget)); gtk_range_set_adjustment(GTK_RANGE(glade_xml_get_widget(xml,"log_position_hscale")),adj); } } register_widget("playback_controls_window",playback_controls_window); } else gtk_widget_show_all(playback_controls_window); } else { if (GTK_IS_WIDGET(playback_controls_window)) gtk_widget_hide(playback_controls_window); } return; }
int gui_init(int argc, char **argv) { if (gui == NULL) { gui = (struct _GuiCore*)malloc(sizeof(struct _GuiCore)); if (gui == NULL) return -1; } memset(gui, 0, sizeof(struct _GuiCore) ); gui->running = 1; gui->need_update = 1; register_widget("Window" , &window_ops ); register_widget("ListBox" , &listbox_ops ); register_widget("ListBoxItem", &listboxitem_ops ); register_widget("Button" , &button_ops ); register_widget("Image" , &image_ops ); register_widget("label" , &label_ops ); register_widget("NoteBook" , ¬ebook_ops ); register_widget("MessageBox" , &msgbox_ops ); // register_widget("MessageBox" , &messagebox_ops ); gui->signal_hash = hash_new(1, signal_Free ); gui->font_hash = hash_new(1, FontDesc_Free ); gui->image_hash = hash_new(9, ImageDesc_Free ); gui->theme_hash = hash_new(1, Theme_Free ); gui->win_stack = stack_new(NULL); gui->root_widget = widget_new("root", "Window", NULL); gui->argc = argc; gui->argv = argv; if (gui_load("./gui.xml") != 0 ) return -1; if (sdl_init(gui->width, gui->height, gui->bpp) != 0) return -1; return 0; }
/*! \brief load_rt_text_pf() is called to load up the runtime text configurations from the file specified in the firmware's interrogation profile, and populate a new window with the runtiem vars text value box. */ G_MODULE_EXPORT void load_rt_text_pf(void) { GtkWidget *treeview = NULL; GtkWidget *window = NULL; GtkWidget *parent = NULL; gint x = 0; gint y = 0; GtkListStore *store = NULL; gchar *filename = NULL; GladeXML *main_xml = NULL; GladeXML *xml = NULL; gboolean xml_result = FALSE; CmdLineArgs *args = DATA_GET(global_data,"args"); xmlDoc *doc = NULL; xmlNode *root_element = NULL; Firmware_Details *firmware = NULL; firmware = DATA_GET(global_data,"firmware"); if (!(DATA_GET(global_data,"interrogated"))) return; if (!firmware->rtt_map_file) { dbg_func(CRITICAL,g_strdup_printf(__FILE__": firmware->rtt_map_file is UNDEFINED,\n\texiting runtime text window creation routine!!!!\n")); return; } main_xml = (GladeXML *)DATA_GET(global_data,"main_xml"); if ((!main_xml) || (DATA_GET(global_data,"leaving"))) return; if (!DATA_GET(global_data,"rtvars_loaded")) { dbg_func(CRITICAL,g_strdup(__FILE__": load_rt_text_pf()\n\tCRITICAL ERROR, Realtime Variable definitions NOT LOADED!!!\n\n")); return; } gdk_threads_enter(); set_title(g_strdup(_("Loading RT Text..."))); filename = get_file(g_build_path(PSEP,RTTEXT_DATA_DIR,firmware->rtt_map_file,NULL),g_strdup("xml")); if (!filename) { dbg_func(RTMLOADER|CRITICAL,g_strdup_printf(__FILE__": load_rt_text_pf()\n\t File \"%s.xml\" not found!!, exiting function\n",firmware->rtt_map_file)); set_title(g_strdup(_("ERROR RunTimeText Map XML file DOES NOT EXIST!!!"))); gdk_threads_leave(); return; } /* Create window */ xml = glade_xml_new(main_xml->filename,"rtt_window",NULL); window = glade_xml_get_widget(xml,"rtt_window"); register_widget("rtt_window",window); x = (GINT)DATA_GET(global_data,"rtt_x_origin"); y = (GINT)DATA_GET(global_data,"rtt_y_origin"); gtk_window_move(GTK_WINDOW(window),x,y); gtk_window_set_default_size(GTK_WINDOW(window),-1,-1); g_object_set(window, "resizable", TRUE, NULL); parent = glade_xml_get_widget(xml,"rtt_vbox"); glade_xml_signal_autoconnect(xml); LIBXML_TEST_VERSION doc = xmlReadFile(filename, NULL, 0); g_free(filename); if (doc == NULL) { printf(_("error: could not parse file %s\n"),filename); gdk_threads_leave(); return; } /*Get the root element node */ store = gtk_list_store_new(RTT_NUM_COLS,G_TYPE_POINTER,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_FLOAT); DATA_SET(global_data,"rtt_model",store); treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); gtk_box_pack_start(GTK_BOX(parent),treeview,TRUE,TRUE,0); setup_rtt_treeview(treeview); root_element = xmlDocGetRootElement(doc); xml_result = load_rtt_xml_elements(root_element,store,parent); xmlFreeDoc(doc); xmlCleanupParser(); if (xml_result == FALSE) gtk_widget_destroy(window); else if ((!args->hide_rttext) && (xml_result)) gtk_widget_show_all(window); set_title(g_strdup(_("RT Text Loaded..."))); gdk_threads_leave(); return; }
/*! \brief load_status_pf() is called to create the ECU status window, load the settings from the StatusMapFile. */ G_MODULE_EXPORT void load_status_pf(void) { gchar *filename = NULL; gint x = 0; gint y = 0; gint w = 0; gint h = 0; GtkWidget * window; GtkWidget * parent; GladeXML *xml = NULL; gboolean xml_result = FALSE; xmlDoc *doc = NULL; xmlNode *root_element = NULL; GladeXML *main_xml; Firmware_Details *firmware = NULL; CmdLineArgs *args = NULL; args = DATA_GET(global_data,"args"); firmware = DATA_GET(global_data,"firmware"); g_return_if_fail(firmware); g_return_if_fail(args); if (!(DATA_GET(global_data,"interrogated"))) return; if (!firmware->status_map_file) { //dbg_func(CRITICAL,g_strdup_printf(__FILE__": firmware->status_map_file is UNDEFINED,\n\texiting status window creation routine!!!!\n")); return; } gdk_threads_enter(); set_title(g_strdup(_("Loading RT Status..."))); filename = get_file(g_build_path(PSEP,RTSTATUS_DATA_DIR,firmware->status_map_file,NULL),g_strdup("xml")); if (!filename) { dbg_func(CRITICAL,g_strdup_printf(__FILE__": load_runtime_status()\n\t File \"%s.xml\" not found!!, exiting function\n",firmware->status_map_file)); set_title(g_strdup(_("ERROR RT Statusfile DOES NOT EXIST!!!"))); gdk_threads_leave(); return; } main_xml = (GladeXML *)DATA_GET(global_data,"main_xml"); xml = glade_xml_new(main_xml->filename,"status_window",NULL); window = glade_xml_get_widget(xml,"status_window"); register_widget("status_window",window); gtk_window_set_focus_on_map((GtkWindow *)window,FALSE); gtk_window_set_title(GTK_WINDOW(window),_("ECU Status")); x = (GINT)DATA_GET(global_data,"status_x_origin"); y = (GINT)DATA_GET(global_data,"status_y_origin"); gtk_window_move(GTK_WINDOW(window),x,y); w = (GINT)DATA_GET(global_data,"status_width"); h = (GINT)DATA_GET(global_data,"status_height"); gtk_window_set_default_size(GTK_WINDOW(window),w,h); /* if (g_strcasecmp(firmware->actual_signature,DATA_GET(global_data,"last_signature")) == 0) gtk_window_set_default_size(GTK_WINDOW(window),w,h); else gtk_window_set_default_size(GTK_WINDOW(window),-1,-1); */ // gtk_window_resize(GTK_WINDOW(window),w,h); // g_object_set(window, "resizable", FALSE, NULL); parent = glade_xml_get_widget(xml,"status_vbox"); glade_xml_signal_autoconnect(xml); LIBXML_TEST_VERSION doc = xmlReadFile(filename, NULL, 0); g_free(filename); if (doc == NULL) { printf(_("error: could not parse file %s\n"),filename); gdk_threads_leave(); return; } root_element = xmlDocGetRootElement(doc); xml_result = load_status_xml_elements(root_element,parent); xmlFreeDoc(doc); xmlCleanupParser(); if (xml_result == FALSE) gtk_widget_destroy(window); else if ((!args->hide_status) && (xml_result)) gtk_widget_show_all(window); set_title(g_strdup(_("RT Status Loaded..."))); gdk_threads_leave(); return; }
/*! \brief bind_data() is a recursive function that is called for every container widget in a glade frame and it's purpose is to search the datamap file passed for the widget names in the glade file and if it's fond in the datamap to load all the attribues listed and bind them to the object using GTK+'s object model. \param widget is the widget passed to load attributes on \param user_data is the pointer to a BingGroup structure. */ G_MODULE_EXPORT void bind_data(GtkWidget *widget, gpointer user_data) { BindGroup *bindgroup = (BindGroup *)user_data; ConfigFile *cfgfile = bindgroup->cfgfile; GHashTable *groups = bindgroup->groups; gchar * tmpbuf = NULL; gchar * section = NULL; gchar ** keys = NULL; gint num_keys = 0; gint offset = 0; gint page = 0; gint index = 0; gchar * initializer = NULL; GdkColor color; gchar *size = NULL; gint count = 0; gint tmpi = 0; gboolean hidden = FALSE; gchar *ptr = NULL; gchar **vector = NULL; gchar **vec2 = NULL; void (*func)(void) = NULL; GList *list = NULL; GList *list2 = NULL; const gchar *name = NULL; gboolean indexed = FALSE; Firmware_Details *firmware = NULL; GList ***ecu_widgets = NULL; GList *tab_widgets = NULL; void (*load_dep_obj)(GObject *, ConfigFile *,const gchar *,const gchar *) = NULL; ENTER(); MTXDBG(TABLOADER,_("Entered")); ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets"); firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); g_return_if_fail(ecu_widgets); g_return_if_fail(firmware); if (!GTK_IS_WIDGET(widget)) { EXIT(); return; } if (GTK_IS_WIDGET(widget)) if (GTK_IS_CONTAINER(widget)) gtk_container_foreach(GTK_CONTAINER(widget),bind_data,user_data); name = gtk_widget_get_name(widget); if (!name) { EXIT(); return; } if (NULL != (ptr = g_strrstr_len(name,strlen(name),"_of_"))) { indexed = TRUE; ptr = g_strrstr_len(name,ptr-name,"_"); tmpbuf = g_strdelimit(g_strdup(ptr),"_",' '); section = g_strndup(name,ptr-name); /*printf("(indexed) section is %s\n",section);*/ gint result = sscanf(tmpbuf,"%d of %d",&index,&count); /*printf("sscanf result %i\n",result);* * printf("Found indexed value for \"%s\", index %i, count %i\n",tmpbuf,index,count); */ g_free(tmpbuf); } else section = g_strdup(name); if(cfg_read_string(cfgfile, section, "keys", &tmpbuf)) { keys = parse_keys(tmpbuf,&num_keys,","); MTXDBG(TABLOADER,_("Number of keys for %s is %i\n"),section,num_keys); g_free(tmpbuf); } else { g_free(section); EXIT(); return; } page = -1; /* Store ptr to self in qdata, needed for bind_to_lists from groups*/ OBJ_SET(widget,"self",widget); /* Bind the data in the "defaults" group per tab to EVERY var in that * tab */ page = bind_group_data(cfgfile, G_OBJECT(widget), groups, "defaults"); if(cfg_read_string(cfgfile, section, "group", &tmpbuf)) { page = bind_group_data(cfgfile,G_OBJECT(widget),groups,tmpbuf); g_free(tmpbuf); } if ((!cfg_read_int(cfgfile, section, "page", &page)) && (page == -1)) { MTXDBG(TABLOADER|CRITICAL,_("Object %s doesn't have a page assigned!!!!\n"),section); } /* Bind widgets to lists if they have the bind_to_list flag set... */ tmpbuf = NULL; if (cfg_read_string(cfgfile, section, "bind_to_list", &tmpbuf)) { bind_to_lists(widget, tmpbuf); g_free(tmpbuf); } if (cfg_read_boolean(cfgfile,section,"ellipsize",&tmpi)) { if ((GTK_IS_LABEL(widget)) && (tmpi)) { OBJ_SET(widget,"ellipsize_preferred",GINT_TO_POINTER(TRUE)); if (DATA_GET(global_data,"ellipsize_tabs")) gtk_label_set_ellipsize(GTK_LABEL(widget),PANGO_ELLIPSIZE_END); } } /* Color selections */ if (cfg_read_string(cfgfile, section, "active_fg", &tmpbuf)) { gdk_color_parse(tmpbuf, &color); gtk_widget_modify_fg(widget, GTK_STATE_NORMAL, &color); g_free(tmpbuf); } if (cfg_read_string(cfgfile, section, "inactive_fg", &tmpbuf)) { gdk_color_parse(tmpbuf, &color); gtk_widget_modify_fg(widget, GTK_STATE_INSENSITIVE, &color); g_free(tmpbuf); } /* If this widget has a "depend_on" tag we need to load the dependancy * information and store it for use when needed... */ if (cfg_read_string(cfgfile,section,"depend_on",&tmpbuf)) { if (get_symbol("load_dependencies_obj",(void **)&load_dep_obj)) load_dep_obj(G_OBJECT(widget),cfgfile,section,"depend_on"); g_free(tmpbuf); } /* If this widget (a textview) has "create_tags" we call a special * handler just for that.. */ if (cfg_read_string(cfgfile,section,"create_tags",&tmpbuf)) { load_tags(G_OBJECT(widget),cfgfile,section); g_free(tmpbuf); } /* If this widget has "tooltip" set the tip on the widget */ if (cfg_read_string(cfgfile,section,"tooltip",&tmpbuf)) { gtk_widget_set_tooltip_text(widget,tmpbuf); g_free(tmpbuf); } /* If this widget (a label) has "set_label" we set the label on it */ if (cfg_read_string(cfgfile,section,"set_label",&tmpbuf)) { /* printf("setting label on %s to \"%s\"\n",glade_get_widget_name(widget),tmpbuf);*/ gtk_label_set_text(GTK_LABEL(widget),tmpbuf); g_free(tmpbuf); } /* If this widget is temp dependant, set the current units on it */ if (cfg_read_string(cfgfile,section,"temp_dep",&tmpbuf)) { OBJ_SET(widget,"widget_temp",DATA_GET(global_data,"mtx_temp_units")); g_free(tmpbuf); } /* If this widget has "register_as", register it with the supplied name */ if (cfg_read_string(cfgfile,section,"register_as",&tmpbuf)) { register_widget(tmpbuf,widget); g_free(tmpbuf); } /* If this widget has visible_functions defined */ if (cfg_read_string(cfgfile,section,"visible_functions",&tmpbuf)) { vector = g_strsplit(tmpbuf,",",-1); g_free(tmpbuf); for (guint i=0;i<g_strv_length(vector);i++) { vec2 = g_strsplit(vector[i],":",2); if (g_strv_length(vec2) != 2) { printf("ERROR in %s, visible_functions param is missing the framerate parameter (func:fps)\n",cfgfile->filename); g_strfreev(vec2); continue; } gint fps = (GINT)g_strtod(vec2[1],NULL); get_symbol(vec2[0],(void **)&func); if (func) { list = g_list_prepend(list,(gpointer)func); list2 = g_list_prepend(list2,GINT_TO_POINTER(fps)); } g_strfreev(vec2); } g_strfreev(vector); OBJ_SET_FULL(widget,"func_list",list,g_list_free); OBJ_SET_FULL(widget,"func_fps_list",list2,g_list_free); } /* If this widget has "initializer" there's a global variable * with it's name on it */ if (cfg_read_string(cfgfile,section,"initializer",&initializer)) { gint widget_type = 0; if (!cfg_read_string(cfgfile,section,"widget_type",&tmpbuf)) MTXDBG(TABLOADER|CRITICAL,_("Object %s has initializer, but no widget_type!!!!\n"),section); else widget_type = translate_string(tmpbuf); g_free(tmpbuf); switch (widget_type) { case MTX_RANGE: gtk_range_set_value(GTK_RANGE(widget),(GINT)DATA_GET(global_data,initializer)); break; case MTX_SPINBUTTON: gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),(GINT)DATA_GET(global_data,initializer)); break; case MTX_ENTRY: gtk_entry_set_text(GTK_ENTRY(widget),(gchar *)DATA_GET(global_data,initializer)); default: break; } g_free(initializer); } /* Hidden widgets have special handlers and should NOT be updated normally */ cfg_read_boolean(cfgfile,section, "hidden", &hidden); offset = -1; cfg_read_int(cfgfile,section, "offset", &offset); if (offset >= 0 && indexed) { /*printf("indexed widget %s\n",name); */ if (cfg_read_string(cfgfile, section, "size", &size)) { offset += index * get_multiplier ((DataSize)translate_string (size)); g_free(size); } else { if(OBJ_GET(widget, "size")) { offset += index * get_multiplier ((DataSize)(GINT)OBJ_GET(widget, "size")); } else { MTXDBG(TABLOADER|CRITICAL,_("Indexed Object %s has index and offset, but no size!!!!\n"),section); g_free(section); EXIT(); return; } } /*printf("widget %s, offset %i\n",name,offset);*/ OBJ_SET(widget,"offset",GINT_TO_POINTER(offset)); } if (offset >= 0) { /* The way we do it now is to STORE widgets in LISTS for each * offset, thus we can have multiple on screen controls bound * to single data offset in the ECU */ if (page < 0) { MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap widget %s, page %i, at offset %i...\n\n"),section,page,offset); g_free(section); EXIT(); return; } if (page < firmware->total_pages) { if (offset >= firmware->page_params[page]->length) MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap widget %s, at offset %i...\n\n"),section,offset); else if (!hidden) { tab_widgets = OBJ_GET(bindgroup->topframe,"tab_widgets"); tab_widgets = g_list_prepend(tab_widgets, widget); OBJ_SET(bindgroup->topframe,"tab_widgets",tab_widgets); ecu_widgets[page][offset] = g_list_prepend( ecu_widgets[page][offset], (gpointer)widget); } } else MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap for widget %s, at page %i offset %i...\n\n"),section,page,offset); } /* If there is a "group" key in a section it means that it gets the * rest of it's setting from the groupname listed. This reduces * redundant keys all throughout the file... */ bind_keys(G_OBJECT(widget), cfgfile, section, keys, num_keys); g_strfreev(keys); /* If this widget has the "choices" key (combobox) */ if (cfg_read_string(cfgfile,section,"choices",&tmpbuf)) { combo_setup(G_OBJECT(widget),cfgfile,section); g_free(tmpbuf); } if (cfg_read_string(cfgfile,section,"post_functions_with_arg",&tmpbuf)) { run_post_functions_with_arg(tmpbuf,widget); g_free(tmpbuf); } if (cfg_read_string(cfgfile,section,"post_functions",&tmpbuf)) { run_post_functions(tmpbuf); g_free(tmpbuf); } if (cfg_read_boolean(cfgfile,section,"show_widget",&tmpi)) { if (tmpi) gtk_widget_show(widget); else gtk_widget_hide(widget); } if (cfg_read_string(cfgfile,section,"set_tab_labels",&tmpbuf)) { if (GTK_IS_NOTEBOOK(widget)) { vector=g_strsplit(tmpbuf,",",-1); if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(widget)) == g_strv_length(vector)) { for (int i=0;i<g_strv_length(vector);i++) { gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(widget), gtk_notebook_get_nth_page(GTK_NOTEBOOK(widget),i), vector[i]); } } g_strfreev(vector); } g_free(tmpbuf); } g_free(section); MTXDBG(TABLOADER,_("Leaving")); EXIT(); return; }