open trace automagically upon stop
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / callbacks.c
index 060fcbc7dd64bd633a151699ba7cc152bf0292b6..8571eb25d03076414f69a34b8b380b89d0ab8278 100644 (file)
 #include <lttvwindow/toolbar.h>
 #include <lttvwindow/lttvwindow.h>
 #include <lttvwindow/lttvwindowtraces.h>
-#include <lttvwindow/gtkdirsel.h>
 
 
-#define DEFAULT_TIME_WIDTH_S   1
+static LttTime lttvwindow_default_time_width = { 1, 0 };
 #define CLIP_BUF 256 // size of clipboard buffer
 
 extern LttvTrace *g_init_trace ;
@@ -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);
 
@@ -408,8 +410,8 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
   LttvTracesetContext *tsc =
         LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
   TimeInterval time_span = tsc->time_span;
-  TimeWindow new_time_window;
-  LttTime new_current_time;
+  TimeWindow new_time_window = tab->time_window;
+  LttTime new_current_time = tab->current_time;
 
   /* Set the tab's time window and current time if
    * out of bounds */
@@ -421,24 +423,23 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
     new_current_time = time_span.start_time;
     
     LttTime tmp_time;
-
-    if(DEFAULT_TIME_WIDTH_S < time_span.end_time.tv_sec)
-      tmp_time.tv_sec = DEFAULT_TIME_WIDTH_S;
+    
+    if(ltt_time_compare(lttvwindow_default_time_width,
+          ltt_time_sub(time_span.end_time, time_span.start_time)) < 0
+        ||
+       ltt_time_compare(time_span.end_time, time_span.start_time) == 0)
+      tmp_time = lttvwindow_default_time_width;
     else
-      tmp_time.tv_sec = time_span.end_time.tv_sec;
-    tmp_time.tv_nsec = 0;
+      tmp_time = time_span.end_time;
+
     new_time_window.time_width = tmp_time ;
     new_time_window.time_width_double = ltt_time_to_double(tmp_time);
     new_time_window.end_time = ltt_time_add(new_time_window.start_time,
                                             new_time_window.time_width) ;
   }
-  time_change_manager(tab, new_time_window);
-  current_time_change_manager(tab, new_current_time);
 
-  //FIXME : we delete the filter tree, when it should be updated.
-  lttv_filter_destroy(tab->filter);
-  tab->filter = NULL;
-  
 #if 0
   /* Set scrollbar */
   GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
@@ -501,7 +502,9 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
   if(tmp == NULL) retval = 1;
   else lttv_hooks_call(tmp,traceset);
 
+  time_change_manager(tab, new_time_window);
+  current_time_change_manager(tab, new_current_time);
+
   return retval;
 }
 
@@ -514,7 +517,7 @@ int SetTraceset(Tab * tab, LttvTraceset *traceset)
  *  0 : filters updated
  *  1 : no filter hooks to update; not an error.
  */
-
+#if 0
 int SetFilter(Tab * tab, gpointer filter)
 {
   LttvHooks * tmp;
@@ -530,7 +533,7 @@ int SetFilter(Tab * tab, gpointer filter)
 
   return 0;
 }
-
+#endif //0
 
 
 /**
@@ -803,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:
@@ -1697,18 +1703,23 @@ void add_trace(GtkWidget * widget, gpointer user_data)
     tab = (Tab *)g_object_get_data(G_OBJECT(page), "Tab_Info");
   }
 
-  GtkDirSelection * file_selector = (GtkDirSelection *)gtk_dir_selection_new("Select a trace");
-  gtk_dir_selection_hide_fileop_buttons(file_selector);
+  //GtkDirSelection * file_selector = (GtkDirSelection *)gtk_dir_selection_new("Select a trace");
+  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_dir_selection_set_filename(file_selector, remember_trace_dir);
+    gtk_file_selection_set_filename(file_selector, remember_trace_dir);
   
   id = gtk_dialog_run(GTK_DIALOG(file_selector));
   switch(id){
     case GTK_RESPONSE_ACCEPT:
     case GTK_RESPONSE_OK:
-      dir = gtk_dir_selection_get_dir (file_selector);
+      dir = gtk_file_selection_get_filename (file_selector);
       strncpy(remember_trace_dir, dir, PATH_MAX);
+      strncat(remember_trace_dir, "/", PATH_MAX);
       if(!dir || strlen(dir) == 0){
        gtk_widget_destroy((GtkWidget*)file_selector);
        break;
@@ -1786,10 +1797,10 @@ void remove_trace(GtkWidget *widget, gpointer user_data)
   for(i = 0; i < nb_trace; i++){
     trace_v = lttv_traceset_get(tab->traceset_info->traceset, i);
     trace = lttv_trace(trace_v);
-    name[i] = ltt_trace_name(trace);
+    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){
@@ -2476,7 +2487,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 /
@@ -2509,6 +2521,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){
@@ -2583,7 +2598,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++){
@@ -2630,7 +2645,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++){
@@ -2665,7 +2680,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++){
@@ -2777,7 +2792,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++){
@@ -2811,7 +2826,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++){
@@ -2843,19 +2858,25 @@ void
 on_add_library_search_path_activate     (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  GtkDirSelection * file_selector = (GtkDirSelection *)gtk_dir_selection_new("Select library path");
+  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_dir_selection_set_filename(file_selector, remember_plugins_dir);
+    gtk_file_selection_set_filename(file_selector, remember_plugins_dir);
 
   id = gtk_dialog_run(GTK_DIALOG(file_selector));
   switch(id){
     case GTK_RESPONSE_ACCEPT:
     case GTK_RESPONSE_OK:
-      dir = gtk_dir_selection_get_dir (file_selector);
+      dir = gtk_file_selection_get_filename (file_selector);
       strncpy(remember_plugins_dir,dir,PATH_MAX);
       strncat(remember_plugins_dir,"/",PATH_MAX);
       lttv_library_path_add(dir);
@@ -2890,7 +2911,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);
@@ -2975,10 +2996,11 @@ on_about_activate                      (GtkMenuItem     *menuitem,
 Contributors :\n\
 \n\
 Michel Dagenais (New trace format, lttv main)\n\
-Mathieu Desnoyers (Directory structure, build with automake/conf,\n\
+Mathieu Desnoyers (Kernel Tracer, Directory structure, build with automake/conf,\n\
                    lttv gui, control flow view, gui cooperative trace reading\n\
                    scheduler with interruptible foreground and background\n\
-                   computation, detailed event list)\n\
+                   computation, detailed event list (rewrite), trace reading\n\
+                   library (rewrite))\n\
 Benoit Des Ligneris, Eric Clement (Cluster adaptation, work in progress)\n\
 Xang-Xiu Yang (new trace reading library and converter, lttv gui, \n\
                detailed event list and statistics view)\n\
@@ -3238,6 +3260,8 @@ void time_change_manager               (Tab *tab,
   LttTime start_time = new_time_window.start_time;
   LttTime end_time = new_time_window.end_time;
 
+  g_assert(ltt_time_compare(start_time, end_time) < 0);
+  
   /* Set scrollbar */
   GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(tab->scrollbar));
   LttTime upper = ltt_time_sub(time_span.end_time, time_span.start_time);
@@ -3597,6 +3621,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);
   
@@ -3719,9 +3745,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");
 }
 
@@ -3729,9 +3756,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");
 }
 
@@ -3741,9 +3769,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");
 }
 
@@ -3752,8 +3781,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;
@@ -3773,6 +3803,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);
@@ -3932,7 +3964,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 */
@@ -3972,7 +4004,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
@@ -4046,6 +4080,8 @@ void construct_main_window(MainWindow * parent)
   }
 
   g_info("There are now : %d windows\n",g_slist_length(g_main_window_list));
+
+  return new_m_window;
 }
 
 
@@ -4120,12 +4156,10 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
     /* We can clone the filter, as we copy the trace set also */
     /* The filter must always be in sync with the trace set */
     tab->filter = lttv_filter_clone(copy_tab->filter);
-
   } else {
     tab->traceset_info->traceset = lttv_traceset_new();
     tab->filter = NULL;
   }
-
 #ifdef DEBUG
   lttv_attribute_write_xml(
       lttv_traceset_attribute(tab->traceset_info->traceset),
@@ -4182,16 +4216,17 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
   tab->viewer_container = gtk_vbox_new(TRUE, 2);
   tab->scrollbar = gtk_hscrollbar_new(NULL);
   //tab->multivpaned = gtk_multi_vpaned_new();
-  tab->time_window.start_time = ltt_time_zero;
-  tab->time_window.end_time = ltt_time_zero;
-  tab->time_window.time_width = ltt_time_zero;
-  tab->current_time = ltt_time_zero;
-  
   gtk_box_pack_start(GTK_BOX(tab->vbox),
                      tab->viewer_container,
                      TRUE, /* expand */
                      TRUE, /* Give the extra space to the child */
                      0);    /* No padding */
+  
+//  if(copy_tab) {
+//    tab->time_window = copy_tab->time_window;
+//    tab->current_time = copy_tab->current_time;
+//  }
 
   /* Create the timebar */
   {
@@ -4435,6 +4470,25 @@ Tab* create_tab(MainWindow * mw, Tab *copy_tab,
   // always show : not if(g_list_length(list)>1)
   gtk_notebook_set_show_tabs(notebook, TRUE);
  
+  if(copy_tab) {
+    lttvwindow_report_time_window(tab, copy_tab->time_window);
+    lttvwindow_report_current_time(tab, copy_tab->current_time);
+  } else {
+    TimeWindow time_window;
+
+    time_window.start_time = ltt_time_zero;
+    time_window.end_time = ltt_time_add(time_window.start_time,
+        lttvwindow_default_time_width);
+    time_window.time_width = lttvwindow_default_time_width;
+    time_window.time_width_double = ltt_time_to_double(time_window.time_width);
+
+    lttvwindow_report_time_window(tab, time_window);
+    lttvwindow_report_current_time(tab, ltt_time_zero);
+  }
+  LttvTraceset *traceset = tab->traceset_info->traceset;
+  SetTraceset(tab, traceset);
+
   return tab;
 }
 
@@ -4450,3 +4504,49 @@ gboolean execute_events_requests(Tab *tab)
   return ( lttvwindow_process_pending_requests(tab) );
 }
 
+
+void create_main_window_with_trace(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);
+    } 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.02992 seconds and 4 git commands to generate.