+
+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)
+{
+ 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->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->win_creation_data = parent->win_creation_data;
+ }else{
+ 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(NULL, new_m_window, 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)
+{
+ int i, nb, ref_count;
+ LttvTrace * trace;
+
+ 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;
+ }
+
+ if(tab_instance->traceset_info->traceset_context != NULL){
+ lttv_context_fini(LTTV_TRACESET_CONTEXT(tab_instance->traceset_info->
+ traceset_context));
+ g_object_unref(tab_instance->traceset_info->traceset_context);
+ }
+ if(tab_instance->traceset_info->traceset != NULL) {
+ nb = lttv_traceset_number(tab_instance->traceset_info->traceset);
+ for(i = 0 ; i < nb ; i++) {
+ trace = lttv_traceset_get(tab_instance->traceset_info->traceset, i);
+ ref_count = lttv_trace_get_ref_number(trace);
+ if(ref_count <= 1){
+ ltt_trace_close(lttv_trace(trace));
+ }
+ lttv_trace_destroy(trace);
+ }
+ }
+ lttv_traceset_destroy(tab_instance->traceset_info->traceset);
+ g_free(tab_instance->traceset_info);
+ g_free(tab_instance);
+}
+
+void * create_tab(MainWindow * parent, MainWindow* current_window,
+ GtkNotebook * notebook, char * label)
+{
+ GList * list;
+ Tab * tmp_tab;
+ MainWindow * mw_data = current_window;
+ LttTime tmp_time;
+
+ 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;
+ }
+
+ tmp_tab->traceset_info = g_new(TracesetInfo,1);
+ if(parent){
+ tmp_tab->traceset_info->traceset =
+ lttv_traceset_copy(parent->current_tab->traceset_info->traceset);
+ }else{
+ if(mw_data->current_tab){
+ tmp_tab->traceset_info->traceset =
+ lttv_traceset_copy(mw_data->current_tab->traceset_info->traceset);
+ }else{
+ tmp_tab->traceset_info->traceset = lttv_traceset_new();
+ /* Add the command line trace */
+ if(g_init_trace != NULL)
+ lttv_traceset_add(tmp_tab->traceset_info->traceset, g_init_trace);
+ }
+ }
+ //FIXME copy not implemented in lower level
+ tmp_tab->traceset_info->traceset_context =
+ g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
+ lttv_context_init(
+ LTTV_TRACESET_CONTEXT(tmp_tab->traceset_info->traceset_context),
+ tmp_tab->traceset_info->traceset);
+
+ 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->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(tmp_tab->traceset_info->traceset_context)->Time_Span->startTime;
+ if(DEFAULT_TIME_WIDTH_S <
+ LTTV_TRACESET_CONTEXT(tmp_tab->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(tmp_tab->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 =
+ LTTV_TRACESET_CONTEXT(tmp_tab->traceset_info->traceset_context)->Time_Span->startTime.tv_sec;
+ tmp_tab->current_time.tv_nsec =
+ LTTV_TRACESET_CONTEXT(tmp_tab->traceset_info->traceset_context)->Time_Span->startTime.tv_nsec;
+ }
+ tmp_tab->attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL));
+ // mw_data->current_tab = tmp_tab;
+ tmp_tab->multi_vpaned = (GtkMultiVPaned*)gtk_multi_vpaned_new();
+ tmp_tab->multi_vpaned->mw = mw_data;
+ gtk_widget_show((GtkWidget*)tmp_tab->multi_vpaned);
+ 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->multi_vpaned),
+ "Tab_Info",
+ tmp_tab,
+ (GDestroyNotify)tab_destructor);
+
+ gtk_notebook_append_page(notebook, (GtkWidget*)tmp_tab->multi_vpaned, 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;
+ }
+ }
+}