update for powerpc
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / callbacks.c
index 96cfe049191f2a7b3eced8482825a04eb3731687..4f2a9639e40fcd0fa4b201c835917764d27c1ff5 100644 (file)
@@ -46,7 +46,6 @@
 #include <lttvwindow/toolbar.h>
 #include <lttvwindow/lttvwindow.h>
 #include <lttvwindow/lttvwindowtraces.h>
-#include <lttvwindow/gtkdirsel.h>
 
 
 static LttTime lttvwindow_default_time_width = { 1, 0 };
@@ -64,10 +63,13 @@ static char remember_trace_dir[PATH_MAX] = "";
 
 
 MainWindow * get_window_data_struct(GtkWidget * widget);
-char * get_load_module(char ** load_module_name, int nb_module);
-char * get_unload_module(char ** loaded_module_name, int nb_module);
-char * get_remove_trace(char ** all_trace_name, int nb_trace);
-char * get_selection(char ** all_name, int nb, char *title, char * column_title);
+char * get_load_module(MainWindow *mw,
+    char ** load_module_name, int nb_module);
+char * get_unload_module(MainWindow *mw,
+    char ** loaded_module_name, int nb_module);
+char * get_remove_trace(MainWindow *mw, char ** all_trace_name, int nb_trace);
+char * get_selection(MainWindow *mw,
+    char ** all_name, int nb, char *title, char * column_title);
 Tab* create_tab(MainWindow * mw, Tab *copy_tab,
                  GtkNotebook * notebook, char * label);
 
@@ -804,6 +806,9 @@ void open_traceset(GtkWidget * widget, gpointer user_data)
 
   gtk_file_selection_hide_fileop_buttons(file_selector);
   
+  gtk_window_set_transient_for(GTK_WINDOW(file_selector),
+      GTK_WINDOW(mw_data->mwindow));
+
   id = gtk_dialog_run(GTK_DIALOG(file_selector));
   switch(id){
     case GTK_RESPONSE_ACCEPT:
@@ -1085,6 +1090,8 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
 
         } else {
           LttTime pos_time;
+                                       LttvTracefileContext *tfc =
+                                               lttv_traceset_context_get_current_tfc(tsc);
           /* Else, the first request in list_in is a position request */
           /* If first req in list_in pos != current pos */
           g_assert(events_request->start_position != NULL);
@@ -1093,10 +1100,16 @@ gboolean lttvwindow_process_pending_requests(Tab *tab)
                       events_request->start_position).tv_sec,
                  lttv_traceset_context_position_get_time(
                       events_request->start_position).tv_nsec);
-
-          g_debug("SEEK POS context time : %lu, %lu", 
-               lttv_traceset_context_get_current_tfc(tsc)->timestamp.tv_sec,
-               lttv_traceset_context_get_current_tfc(tsc)->timestamp.tv_nsec);
+                                       
+                                       if(tfc) {
+                                               g_debug("SEEK POS context time : %lu, %lu", 
+                                                        tfc->timestamp.tv_sec,
+                                                        tfc->timestamp.tv_nsec);
+                                       } else {
+                                               g_debug("SEEK POS context time : %lu, %lu", 
+                                                        ltt_time_infinite.tv_sec,
+                                                        ltt_time_infinite.tv_nsec);
+                                       }
           g_assert(events_request->start_position != NULL);
           if(lttv_traceset_context_ctx_pos_compare(tsc,
                      events_request->start_position) != 0) {
@@ -1702,6 +1715,8 @@ void add_trace(GtkWidget * widget, gpointer user_data)
   GtkFileSelection * file_selector = (GtkFileSelection *)gtk_file_selection_new("Select a trace");
   gtk_widget_hide( (file_selector)->file_list->parent) ;
   gtk_file_selection_hide_fileop_buttons(file_selector);
+  gtk_window_set_transient_for(GTK_WINDOW(file_selector),
+      GTK_WINDOW(mw_data->mwindow));
   
   if(remember_trace_dir[0] != '\0')
     gtk_file_selection_set_filename(file_selector, remember_trace_dir);
@@ -1723,6 +1738,18 @@ void add_trace(GtkWidget * widget, gpointer user_data)
         trace = ltt_trace_open(abs_path);
         if(trace == NULL) {
           g_warning("cannot open trace %s", abs_path);
+
+          GtkWidget *dialogue = 
+            gtk_message_dialog_new(
+              GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+              GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+              GTK_MESSAGE_ERROR,
+              GTK_BUTTONS_OK,
+              "Cannot open trace : maybe you should enter in the trace "
+              "directory to select it ?");
+          gtk_dialog_run(GTK_DIALOG(dialogue));
+          gtk_widget_destroy(dialogue);
+
         } else {
           trace_v = lttv_trace_new(trace);
           lttvwindowtraces_add_trace(trace_v);
@@ -1793,7 +1820,7 @@ void remove_trace(GtkWidget *widget, gpointer user_data)
     name[i] = g_quark_to_string(ltt_trace_name(trace));
   }
 
-  remove_trace_name = get_remove_trace(name, nb_trace);
+  remove_trace_name = get_remove_trace(mw_data, name, nb_trace);
 
 
   if(remove_trace_name){
@@ -2480,7 +2507,8 @@ on_load_library_activate                (GtkMenuItem     *menuitem,
       g_ptr_array_add(name, path);
     }
 
-    load_module_path = get_selection((char **)(name->pdata), name->len,
+    load_module_path = get_selection(mw_data,
+                             (char **)(name->pdata), name->len,
                              "Select a library path", "Library paths");
     if(load_module_path != NULL)
       strncpy(load_module_path_alter, load_module_path, PATH_MAX-1); // -1 for /
@@ -2513,6 +2541,9 @@ on_load_library_activate                (GtkMenuItem     *menuitem,
     gtk_file_selection_set_filename(file_selector, load_module_path_alter);
     gtk_file_selection_hide_fileop_buttons(file_selector);
     
+    gtk_window_set_transient_for(GTK_WINDOW(file_selector),
+        GTK_WINDOW(mw_data->mwindow));
+
     str[0] = '\0';
     id = gtk_dialog_run(GTK_DIALOG(file_selector));
     switch(id){
@@ -2587,7 +2618,7 @@ on_unload_library_activate              (GtkMenuItem     *menuitem,
     gchar *path = lib_info[i].name;
     g_ptr_array_add(name, path);
   }
-  lib_name = get_selection((char **)(name->pdata), name->len,
+  lib_name = get_selection(mw_data, (char **)(name->pdata), name->len,
                            "Select a library", "Libraries");
   if(lib_name != NULL) {
     for(i=0;i<nb;i++){
@@ -2634,7 +2665,7 @@ on_load_module_activate                (GtkMenuItem     *menuitem,
       gchar *path = lib_info[i].name;
       g_ptr_array_add(name, path);
     }
-    lib_name = get_selection((char **)(name->pdata), name->len,
+    lib_name = get_selection(mw_data,(char **)(name->pdata), name->len,
                              "Select a library", "Libraries");
     if(lib_name != NULL) {
       for(i=0;i<nb;i++){
@@ -2669,7 +2700,7 @@ on_load_module_activate                (GtkMenuItem     *menuitem,
       gchar *path = module_info[i].name;
       g_ptr_array_add(name, path);
     }
-    module_name = get_selection((char **)(name->pdata), name->len,
+    module_name = get_selection(mw_data, (char **)(name->pdata), name->len,
                              "Select a module", "Modules");
     if(module_name != NULL) {
       for(i=0;i<nb;i++){
@@ -2781,7 +2812,7 @@ on_unload_module_activate              (GtkMenuItem     *menuitem,
       gchar *path = lib_info[i].name;
       g_ptr_array_add(name, path);
     }
-    lib_name = get_selection((char **)(name->pdata), name->len,
+    lib_name = get_selection(mw_data, (char **)(name->pdata), name->len,
                              "Select a library", "Libraries");
     if(lib_name != NULL) {
       for(i=0;i<nb;i++){
@@ -2815,7 +2846,7 @@ on_unload_module_activate              (GtkMenuItem     *menuitem,
       gchar *path = module_info[i].name;
       if(module_info[i].use_count > 0) g_ptr_array_add(name, path);
     }
-    module_name = get_selection((char **)(name->pdata), name->len,
+    module_name = get_selection(mw_data, (char **)(name->pdata), name->len,
                              "Select a module", "Modules");
     if(module_name != NULL) {
       for(i=0;i<nb;i++){
@@ -2847,13 +2878,17 @@ void
 on_add_library_search_path_activate     (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
+  MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
   //GtkDirSelection * file_selector = (GtkDirSelection *)gtk_dir_selection_new("Select library path");
   GtkFileSelection * file_selector = (GtkFileSelection *)gtk_file_selection_new("Select a trace");
   gtk_widget_hide( (file_selector)->file_list->parent) ;
+
+  gtk_window_set_transient_for(GTK_WINDOW(file_selector),
+      GTK_WINDOW(mw_data->mwindow));
+
   const char * dir;
   gint id;
 
-  MainWindow * mw_data = get_window_data_struct((GtkWidget*)menuitem);
   if(remember_plugins_dir[0] != '\0')
     gtk_file_selection_set_filename(file_selector, remember_plugins_dir);
 
@@ -2896,7 +2931,7 @@ on_remove_library_search_path_activate     (GtkMenuItem     *menuitem,
       gchar *path = lttv_library_path_get(i);
       g_ptr_array_add(name, path);
     }
-    lib_path = get_selection((char **)(name->pdata), name->len,
+    lib_path = get_selection(mw_data, (char **)(name->pdata), name->len,
                              "Select a library path", "Library paths");
 
     g_ptr_array_free(name, TRUE);
@@ -3606,6 +3641,8 @@ void current_position_change_manager(Tab *tab,
 
   g_assert(lttv_process_traceset_seek_position(tsc, pos) == 0);
   LttTime new_time = lttv_traceset_context_position_get_time(pos);
+  /* Put the context in a state coherent position */
+  lttv_state_traceset_seek_time_closest((LttvTracesetState*)tsc, ltt_time_zero);
   
   current_time_change_manager(tab, new_time);
   
@@ -3728,9 +3765,10 @@ void scroll_value_changed_cb(GtkWidget *scrollbar,
 /* Select a trace which will be removed from traceset
  */
 
-char * get_remove_trace(char ** all_trace_name, int nb_trace)
+char * get_remove_trace(MainWindow *mw_data, 
+    char ** all_trace_name, int nb_trace)
 {
-  return get_selection(all_trace_name, nb_trace, 
+  return get_selection(mw_data, all_trace_name, nb_trace, 
                       "Select a trace", "Trace pathname");
 }
 
@@ -3738,9 +3776,10 @@ char * get_remove_trace(char ** all_trace_name, int nb_trace)
 /* Select a module which will be loaded
  */
 
-char * get_load_module(char ** load_module_name, int nb_module)
+char * get_load_module(MainWindow *mw_data, 
+    char ** load_module_name, int nb_module)
 {
-  return get_selection(load_module_name, nb_module, 
+  return get_selection(mw_data, load_module_name, nb_module, 
                       "Select a module to load", "Module name");
 }
 
@@ -3750,9 +3789,10 @@ char * get_load_module(char ** load_module_name, int nb_module)
 /* Select a module which will be unloaded
  */
 
-char * get_unload_module(char ** loaded_module_name, int nb_module)
+char * get_unload_module(MainWindow *mw_data,
+    char ** loaded_module_name, int nb_module)
 {
-  return get_selection(loaded_module_name, nb_module, 
+  return get_selection(mw_data, loaded_module_name, nb_module, 
                       "Select a module to unload", "Module name");
 }
 
@@ -3761,8 +3801,9 @@ char * get_unload_module(char ** loaded_module_name, int nb_module)
  * select one of them
  */
 
-char * get_selection(char ** loaded_module_name, int nb_module,
-                    char *title, char * column_title)
+char * get_selection(MainWindow *mw_data,
+    char ** loaded_module_name, int nb_module,
+         char *title, char * column_title)
 {
   GtkWidget         * dialogue;
   GtkWidget         * scroll_win;
@@ -3782,6 +3823,8 @@ char * get_selection(char ** loaded_module_name, int nb_module,
                                         GTK_STOCK_CANCEL,GTK_RESPONSE_REJECT,
                                         NULL); 
   gtk_window_set_default_size((GtkWindow*)dialogue, 500, 200);
+  gtk_window_set_transient_for(GTK_WINDOW(dialogue), 
+      GTK_WINDOW(mw_data->mwindow));
 
   scroll_win = gtk_scrolled_window_new (NULL, NULL);
   gtk_widget_show ( scroll_win);
@@ -3941,7 +3984,7 @@ void add_all_menu_toolbar_constructors(MainWindow * mw, gpointer user_data)
 /* Create a main window
  */
 
-void construct_main_window(MainWindow * parent)
+MainWindow *construct_main_window(MainWindow * parent)
 {
   g_debug("construct_main_window()");
   GtkWidget  * new_window; /* New generated main window */
@@ -3981,7 +4024,9 @@ void construct_main_window(MainWindow * parent)
   notebook = (GtkNotebook *)lookup_widget(new_m_window->mwindow, "MNotebook");
   if(notebook == NULL){
     g_info("Notebook does not exist\n");
-    return;
+    /* FIXME : destroy partially created widgets */
+    g_free(new_m_window);
+    return NULL;
   }
   //gtk_notebook_popup_enable (GTK_NOTEBOOK(notebook));
   //for now there is no name field in LttvTraceset structure
@@ -4000,61 +4045,54 @@ void construct_main_window(MainWindow * parent)
     new_tab = create_tab(new_m_window, parent_tab, notebook, "Traceset");
   } else {
     new_tab = create_tab(new_m_window, NULL, notebook, "Traceset");
-    /* First window, use command line trace */
-    if(g_init_trace != NULL){
-      lttvwindow_add_trace(new_tab,
-                           g_init_trace);
+  }
 
+  /* Insert default viewers */
+  {
+    LttvAttributeType type;
+    LttvAttributeName name;
+    LttvAttributeValue value;
+    LttvAttribute *attribute;
+    
+    LttvIAttribute *attributes_global = 
+       LTTV_IATTRIBUTE(lttv_global_attributes());
+
+    g_assert(attribute = 
+      LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
+                                LTTV_IATTRIBUTE(attributes_global),
+                                LTTV_VIEWER_CONSTRUCTORS)));
+
+    name = g_quark_from_string("guievents");
+    type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
+                                       name, &value);
+    if(type == LTTV_POINTER) {
+      lttvwindow_viewer_constructor viewer_constructor = 
+                (lttvwindow_viewer_constructor)*value.v_pointer;
+      insert_viewer(new_window, viewer_constructor);
     }
-    LttvTraceset *traceset = new_tab->traceset_info->traceset;
-    SetTraceset(new_tab, traceset);
 
-    /* Insert default viewers */
-    {
-      LttvAttributeType type;
-      LttvAttributeName name;
-      LttvAttributeValue value;
-      LttvAttribute *attribute;
-      
-      LttvIAttribute *attributes_global = 
-         LTTV_IATTRIBUTE(lttv_global_attributes());
-
-      g_assert(attribute = 
-        LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(
-                                  LTTV_IATTRIBUTE(attributes_global),
-                                  LTTV_VIEWER_CONSTRUCTORS)));
-
-      name = g_quark_from_string("guievents");
-      type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
-                                         name, &value);
-      if(type == LTTV_POINTER) {
-        lttvwindow_viewer_constructor viewer_constructor = 
-                  (lttvwindow_viewer_constructor)*value.v_pointer;
-        insert_viewer(new_window, viewer_constructor);
-      }
-
-      name = g_quark_from_string("guicontrolflow");
-      type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
-                                         name, &value);
-      if(type == LTTV_POINTER) {
-        lttvwindow_viewer_constructor viewer_constructor = 
-                  (lttvwindow_viewer_constructor)*value.v_pointer;
-        insert_viewer(new_window, viewer_constructor);
-      }
-
-      name = g_quark_from_string("guistatistics");
-      type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
-                                         name, &value);
-      if(type == LTTV_POINTER) {
-        lttvwindow_viewer_constructor viewer_constructor = 
-                  (lttvwindow_viewer_constructor)*value.v_pointer;
-        insert_viewer(new_window, viewer_constructor);
-      }
+    name = g_quark_from_string("guicontrolflow");
+    type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
+                                       name, &value);
+    if(type == LTTV_POINTER) {
+      lttvwindow_viewer_constructor viewer_constructor = 
+                (lttvwindow_viewer_constructor)*value.v_pointer;
+      insert_viewer(new_window, viewer_constructor);
+    }
 
+    name = g_quark_from_string("guistatistics");
+    type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
+                                       name, &value);
+    if(type == LTTV_POINTER) {
+      lttvwindow_viewer_constructor viewer_constructor = 
+                (lttvwindow_viewer_constructor)*value.v_pointer;
+      insert_viewer(new_window, viewer_constructor);
     }
   }
 
   g_info("There are now : %d windows\n",g_slist_length(g_main_window_list));
+
+  return new_m_window;
 }
 
 
@@ -4477,3 +4515,60 @@ gboolean execute_events_requests(Tab *tab)
   return ( lttvwindow_process_pending_requests(tab) );
 }
 
+
+void create_main_window_with_trace(const gchar *path)
+{
+  if(path == NULL) return;
+
+  /* Create window */
+  MainWindow *mw = construct_main_window(NULL);
+  GtkWidget *widget = mw->mwindow;
+
+  GtkWidget * notebook = lookup_widget(widget, "MNotebook");
+  GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
+                      gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
+  Tab *tab;
+  
+  if(!page) {
+    tab = create_new_tab(widget, NULL);
+  } else {
+    tab = (Tab *)g_object_get_data(G_OBJECT(page), "Tab_Info");
+  }
+
+  /* Add trace */
+  gchar abs_path[PATH_MAX];
+  LttvTrace *trace_v;
+  LttTrace *trace;
+
+  get_absolute_pathname(path, abs_path);
+  trace_v = lttvwindowtraces_get_trace_by_name(abs_path);
+  if(trace_v == NULL) {
+    trace = ltt_trace_open(abs_path);
+    if(trace == NULL) {
+      g_warning("cannot open trace %s", abs_path);
+
+      GtkWidget *dialogue = 
+        gtk_message_dialog_new(
+          GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+          GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+          GTK_MESSAGE_ERROR,
+          GTK_BUTTONS_OK,
+          "Cannot open trace : maybe you should enter in the directory"
+          "to select it ?");
+      gtk_dialog_run(GTK_DIALOG(dialogue));
+      gtk_widget_destroy(dialogue);
+    } else {
+      trace_v = lttv_trace_new(trace);
+      lttvwindowtraces_add_trace(trace_v);
+      lttvwindow_add_trace(tab, trace_v);
+    }
+  } else {
+    lttvwindow_add_trace(tab, trace_v);
+  }
+
+  LttvTraceset *traceset;
+
+  traceset = tab->traceset_info->traceset;
+  SetTraceset(tab, traceset);
+}
+
This page took 0.028415 seconds and 4 git commands to generate.