+char * get_selection(char ** loaded_module_name, int nb_module,
+ char *title, char * column_title)
+{
+ GtkWidget * dialogue;
+ GtkWidget * scroll_win;
+ GtkWidget * tree;
+ GtkListStore * store;
+ GtkTreeViewColumn * column;
+ GtkCellRenderer * renderer;
+ GtkTreeSelection * select;
+ GtkTreeIter iter;
+ gint id, i;
+ char * unload_module_name = NULL;
+
+ dialogue = gtk_dialog_new_with_buttons(title,
+ NULL,
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_OK,GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL,GTK_RESPONSE_REJECT,
+ NULL);
+ gtk_window_set_default_size((GtkWindow*)dialogue, 500, 200);
+
+ scroll_win = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show ( scroll_win);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ store = gtk_list_store_new (N_COLUMNS,G_TYPE_STRING);
+ tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL (store));
+ gtk_widget_show ( tree);
+ g_object_unref (G_OBJECT (store));
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (column_title,
+ renderer,
+ "text", MODULE_COLUMN,
+ NULL);
+ gtk_tree_view_column_set_alignment (column, 0.5);
+ gtk_tree_view_column_set_fixed_width (column, 150);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
+
+ select = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
+ gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
+
+ gtk_container_add (GTK_CONTAINER (scroll_win), tree);
+
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialogue)->vbox), scroll_win,TRUE, TRUE,0);
+
+ for(i=0;i<nb_module;i++){
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, MODULE_COLUMN,loaded_module_name[i],-1);
+ }
+
+ id = gtk_dialog_run(GTK_DIALOG(dialogue));
+ switch(id){
+ case GTK_RESPONSE_ACCEPT:
+ case GTK_RESPONSE_OK:
+ if (gtk_tree_selection_get_selected (select, (GtkTreeModel**)&store, &iter)){
+ gtk_tree_model_get ((GtkTreeModel*)store, &iter, MODULE_COLUMN, &unload_module_name, -1);
+ }
+ case GTK_RESPONSE_REJECT:
+ case GTK_RESPONSE_CANCEL:
+ default:
+ gtk_widget_destroy(dialogue);
+ break;
+ }
+
+ return unload_module_name;
+}
+
+void main_window_destroy_hash_key(gpointer key)
+{
+ g_free(key);
+}
+
+void main_window_destroy_hash_data(gpointer data)
+{
+}
+
+
+void insert_menu_toolbar_item(MainWindow * mw, gpointer user_data)
+{
+ int i;
+ GdkPixbuf *pixbuf;
+ view_constructor constructor;
+ LttvMenus * menu;
+ LttvToolbars * toolbar;
+ lttv_menu_closure *menu_item;
+ lttv_toolbar_closure *toolbar_item;
+ LttvAttributeValue value;
+ LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+ GtkWidget * tool_menu_title_menu, *insert_view, *pixmap, *tmp;
+
+ g_assert(lttv_iattribute_find_by_path(attributes,
+ "viewers/menu", LTTV_POINTER, &value));
+ menu = (LttvMenus*)*(value.v_pointer);
+
+ if(menu){
+ for(i=0;i<menu->len;i++){
+ menu_item = &g_array_index(menu, lttv_menu_closure, i);
+ tmp = g_hash_table_lookup(mw->hash_menu_item, g_strdup(menu_item->menuText));
+ if(tmp)continue;
+ constructor = menu_item->con;
+ tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
+ insert_view = gtk_menu_item_new_with_mnemonic (menu_item->menuText);
+ gtk_widget_show (insert_view);
+ gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), insert_view);
+ g_signal_connect ((gpointer) insert_view, "activate",
+ G_CALLBACK (insert_viewer_wrap),
+ constructor);
+ g_hash_table_insert(mw->hash_menu_item, g_strdup(menu_item->menuText),
+ insert_view);
+ }
+ }
+
+ g_assert(lttv_iattribute_find_by_path(attributes,
+ "viewers/toolbar", LTTV_POINTER, &value));
+ toolbar = (LttvToolbars*)*(value.v_pointer);
+
+ if(toolbar){
+ for(i=0;i<toolbar->len;i++){
+ toolbar_item = &g_array_index(toolbar, lttv_toolbar_closure, i);
+ tmp = g_hash_table_lookup(mw->hash_toolbar_item, g_strdup(toolbar_item->tooltip));
+ if(tmp)continue;
+ constructor = toolbar_item->con;
+ tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar2");
+ pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)toolbar_item->pixmap);
+ pixmap = gtk_image_new_from_pixbuf(pixbuf);
+ insert_view = gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu),
+ GTK_TOOLBAR_CHILD_BUTTON,
+ NULL,
+ "",
+ toolbar_item->tooltip, NULL,
+ pixmap, NULL, NULL);
+ gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (tool_menu_title_menu)->children)->data))->label), TRUE);
+ gtk_widget_show (insert_view);
+ gtk_container_set_border_width (GTK_CONTAINER (insert_view), 1);
+ g_signal_connect ((gpointer) insert_view, "clicked",G_CALLBACK (insert_viewer_wrap),constructor);
+ g_hash_table_insert(mw->hash_toolbar_item, g_strdup(toolbar_item->tooltip),
+ insert_view);
+ }
+ }
+}
+
+void construct_main_window(MainWindow * parent, WindowCreationData * win_creation_data,
+ gboolean first_window)
+{
+ g_critical("construct_main_window()");
+ GtkWidget * new_window; /* New generated main window */
+ MainWindow * new_m_window;/* New main window structure */
+ GtkNotebook * notebook;
+ LttvIAttribute *attributes =
+ LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
+ LttvAttributeValue value;
+
+ new_m_window = g_new(MainWindow, 1);
+
+ // Add the object's information to the module's array
+ g_main_window_list = g_slist_append(g_main_window_list, new_m_window);
+
+
+ new_window = create_MWindow();
+ gtk_widget_show (new_window);
+
+ new_m_window->attributes = attributes;
+
+ new_m_window->traceset_info = g_new(TracesetInfo,1);
+ new_m_window->traceset_info->path = NULL ;
+
+
+ new_m_window->traceset_info->before_traceset = lttv_hooks_new();
+ new_m_window->traceset_info->after_traceset = lttv_hooks_new();
+ new_m_window->traceset_info->before_trace = lttv_hooks_new();
+ new_m_window->traceset_info->after_trace = lttv_hooks_new();
+ new_m_window->traceset_info->before_tracefile = lttv_hooks_new();
+ new_m_window->traceset_info->after_tracefile = lttv_hooks_new();
+ new_m_window->traceset_info->before_event = lttv_hooks_new();
+ new_m_window->traceset_info->after_event = lttv_hooks_new();
+
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->before_traceset;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->after_traceset;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->before_trace;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->after_trace;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->before_tracefile;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->after_tracefile;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->before_event;
+ g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
+ LTTV_POINTER, &value));
+ *(value.v_pointer) = new_m_window->traceset_info->after_event;
+
+
+ new_m_window->mwindow = new_window;
+ new_m_window->tab = NULL;
+ new_m_window->current_tab = NULL;
+ new_m_window->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
+ if(parent){
+ new_m_window->traceset_info->traceset =
+ lttv_traceset_copy(parent->traceset_info->traceset);
+
+//FIXME copy not implemented in lower level
+ new_m_window->traceset_info->traceset_context =
+ g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
+ lttv_context_init(
+ LTTV_TRACESET_CONTEXT(new_m_window->traceset_info->traceset_context),
+ new_m_window->traceset_info->traceset);
+ //new_m_window->traceset_context = parent->traceset_context;
+ new_m_window->win_creation_data = parent->win_creation_data;
+ }else{
+ new_m_window->traceset_info->traceset = lttv_traceset_new();
+
+ /* Add the command line trace */
+ if(g_init_trace != NULL && first_window)
+ lttv_traceset_add(new_m_window->traceset_info->traceset, g_init_trace);
+ /* NOTE : the context must be recreated if we change the traceset,
+ * ie : adding/removing traces */
+ new_m_window->traceset_info->traceset_context =
+ g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
+ lttv_context_init(
+ LTTV_TRACESET_CONTEXT(new_m_window->traceset_info->traceset_context),
+ new_m_window->traceset_info->traceset);
+
+ new_m_window->win_creation_data = win_creation_data;
+ }
+
+ new_m_window->hash_menu_item = g_hash_table_new_full (g_str_hash, g_str_equal,
+ main_window_destroy_hash_key,
+ main_window_destroy_hash_data);
+ new_m_window->hash_toolbar_item = g_hash_table_new_full (g_str_hash, g_str_equal,
+ main_window_destroy_hash_key,
+ main_window_destroy_hash_data);
+
+ insert_menu_toolbar_item(new_m_window, NULL);
+
+ g_object_set_data(G_OBJECT(new_window), "mainWindow", (gpointer)new_m_window);
+
+ //create a default tab
+ notebook = (GtkNotebook *)lookup_widget(new_m_window->mwindow, "MNotebook");
+ if(notebook == NULL){
+ g_printf("Notebook does not exist\n");
+ return;
+ }
+ //for now there is no name field in LttvTraceset structure
+ //Use "Traceset" as the label for the default tab
+ create_tab(new_m_window->mwindow, notebook,"Traceset");
+
+ g_object_set_data_full(
+ G_OBJECT(new_m_window->mwindow),
+ "Main_Window_Data",
+ new_m_window,
+ (GDestroyNotify)main_window_free);
+
+ g_win_count++;
+}
+
+void tab_destructor(Tab * tab_instance)
+{
+ if(tab_instance->attributes)
+ g_object_unref(tab_instance->attributes);
+
+ if(tab_instance->mw->tab == tab_instance){
+ tab_instance->mw->tab = tab_instance->next;
+ }else{
+ Tab * tmp1, *tmp = tab_instance->mw->tab;
+ while(tmp != tab_instance){
+ tmp1 = tmp;
+ tmp = tmp->next;
+ }
+ tmp1->next = tab_instance->next;
+ }
+ g_free(tab_instance);
+}
+
+void * create_tab(GtkWidget* parent, GtkNotebook * notebook, char * label)
+{
+ GList * list;
+ Tab * tmp_tab;
+ MainWindow * mw_data;
+ LttTime tmp_time;
+
+ mw_data = get_window_data_struct(parent);
+ tmp_tab = mw_data->tab;
+ while(tmp_tab && tmp_tab->next) tmp_tab = tmp_tab->next;
+ if(!tmp_tab){
+ mw_data->current_tab = NULL;
+ tmp_tab = g_new(Tab,1);
+ mw_data->tab = tmp_tab;
+ }else{
+ tmp_tab->next = g_new(Tab,1);
+ tmp_tab = tmp_tab->next;
+ }
+ if(mw_data->current_tab){
+ // Will have to read directly at the main window level, as we want
+ // to be able to modify a traceset on the fly.
+ // tmp_tab->traceStartTime = mw_data->current_tab->traceStartTime;
+ // tmp_tab->traceEndTime = mw_data->current_tab->traceEndTime;
+ tmp_tab->time_window = mw_data->current_tab->time_window;
+ tmp_tab->current_time = mw_data->current_tab->current_time;
+ }else{
+ // Will have to read directly at the main window level, as we want
+ // to be able to modify a traceset on the fly.
+ // get_traceset_time_span(mw_data,&tmp_tab->traceStartTime, &tmp_tab->traceEndTime);
+ tmp_tab->time_window.start_time =
+ LTTV_TRACESET_CONTEXT(mw_data->traceset_info->traceset_context)->Time_Span->startTime;
+ if(DEFAULT_TIME_WIDTH_S <
+ LTTV_TRACESET_CONTEXT(mw_data->traceset_info->traceset_context)->Time_Span->endTime.tv_sec)
+ tmp_time.tv_sec = DEFAULT_TIME_WIDTH_S;
+ else
+ tmp_time.tv_sec =
+ LTTV_TRACESET_CONTEXT(mw_data->traceset_info->traceset_context)->Time_Span->endTime.tv_sec;
+ tmp_time.tv_nsec = 0;
+ tmp_tab->time_window.time_width = tmp_time ;
+ tmp_tab->current_time.tv_sec = tmp_time.tv_sec / 2;
+ tmp_tab->current_time.tv_nsec = 0 ;
+ }
+ tmp_tab->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
+ // mw_data->current_tab = tmp_tab;
+ tmp_tab->custom = (GtkCustom*)gtk_custom_new();
+ tmp_tab->custom->mw = mw_data;
+ gtk_widget_show((GtkWidget*)tmp_tab->custom);
+ tmp_tab->next = NULL;
+ tmp_tab->mw = mw_data;
+
+ tmp_tab->label = gtk_label_new (label);
+ gtk_widget_show (tmp_tab->label);
+
+ g_object_set_data_full(
+ G_OBJECT(tmp_tab->custom),
+ "Tab_Info",
+ tmp_tab,
+ (GDestroyNotify)tab_destructor);
+
+ gtk_notebook_append_page(notebook, (GtkWidget*)tmp_tab->custom, tmp_tab->label);
+ list = gtk_container_get_children(GTK_CONTAINER(notebook));
+ gtk_notebook_set_current_page(notebook,g_list_length(list)-1);
+}
+
+void remove_menu_item(gpointer main_win, gpointer user_data)
+{
+ MainWindow * mw = (MainWindow *) main_win;
+ lttv_menu_closure *menu_item = (lttv_menu_closure *)user_data;
+ GtkWidget * tool_menu_title_menu, *insert_view;
+
+ tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu");
+ insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_menu_item,
+ menu_item->menuText);
+ if(insert_view){
+ g_hash_table_remove(mw->hash_menu_item, menu_item->menuText);
+ gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view);
+ }
+}
+
+void remove_toolbar_item(gpointer main_win, gpointer user_data)
+{
+ MainWindow * mw = (MainWindow *) main_win;
+ lttv_toolbar_closure *toolbar_item = (lttv_toolbar_closure *)user_data;
+ GtkWidget * tool_menu_title_menu, *insert_view;
+
+
+ tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar2");
+ insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_toolbar_item,
+ toolbar_item->tooltip);
+ if(insert_view){
+ g_hash_table_remove(mw->hash_toolbar_item, toolbar_item->tooltip);
+ gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view);
+ }
+}
+
+/**
+ * Remove menu and toolbar item when a module unloaded
+ */
+
+void main_window_remove_menu_item(lttv_constructor constructor)
+{
+ int i;
+ LttvMenus * menu;
+ lttv_menu_closure *menu_item;
+ LttvAttributeValue value;
+ LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+
+ g_assert(lttv_iattribute_find_by_path(attributes,
+ "viewers/menu", LTTV_POINTER, &value));
+ menu = (LttvMenus*)*(value.v_pointer);
+
+ if(menu){
+ for(i=0;i<menu->len;i++){
+ menu_item = &g_array_index(menu, lttv_menu_closure, i);
+ if(menu_item->con != constructor) continue;
+ if(g_main_window_list){
+ g_slist_foreach(g_main_window_list, remove_menu_item, menu_item);
+ }
+ break;
+ }
+ }
+
+}
+
+void main_window_remove_toolbar_item(lttv_constructor constructor)
+{
+ int i;
+ LttvToolbars * toolbar;
+ lttv_toolbar_closure *toolbar_item;
+ LttvAttributeValue value;
+ LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
+
+ g_assert(lttv_iattribute_find_by_path(attributes,
+ "viewers/toolbar", LTTV_POINTER, &value));
+ toolbar = (LttvToolbars*)*(value.v_pointer);
+
+ if(toolbar){
+ for(i=0;i<toolbar->len;i++){
+ toolbar_item = &g_array_index(toolbar, lttv_toolbar_closure, i);
+ if(toolbar_item->con != constructor) continue;
+ if(g_main_window_list){
+ g_slist_foreach(g_main_window_list, remove_toolbar_item, toolbar_item);
+ }
+ break;
+ }
+ }
+}