aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-03-30 16:45:31 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-04-09 11:56:17 -0400
commit810abc5b84f2855cc328cb709e75046a646be463 (patch)
tree4fdd360cfb3bc31b24696d93d0803e1343bde99b
parent395ef10599bb35b100ecf3a87bad9a22d010b178 (diff)
kernelshark: Created trace_get_file_dialog() to ask for filename
Added shortcut trace_get_file_dialog() to simplify the asking for a file name. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--kernel-shark.c34
-rw-r--r--trace-dialog.c19
-rw-r--r--trace-graph-main.c28
-rw-r--r--trace-gui.h2
-rw-r--r--trace-view-main.c28
5 files changed, 56 insertions, 55 deletions
diff --git a/kernel-shark.c b/kernel-shark.c
index 58aa860..d913ae0 100644
--- a/kernel-shark.c
+++ b/kernel-shark.c
@@ -141,28 +141,21 @@ load_clicked (gpointer data)
141{ 141{
142 struct shark_info *info = data; 142 struct shark_info *info = data;
143 struct tracecmd_input *handle; 143 struct tracecmd_input *handle;
144 GtkWidget *dialog;
145 gchar *filename; 144 gchar *filename;
146 145
147 dialog = gtk_file_chooser_dialog_new("Load File", 146 filename = trace_get_file_dialog("Load File");
148 NULL, 147 if (!filename)
149 GTK_FILE_CHOOSER_ACTION_OPEN, 148 return;
150 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 149
151 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 150 handle = tracecmd_open(filename);
152 NULL); 151 if (handle) {
153 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { 152 tracecmd_close(info->handle);
154 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 153 info->handle = handle;
155 handle = tracecmd_open(filename); 154 trace_graph_load_handle(info->ginfo, handle);
156 if (handle) { 155 trace_view_reload(info->treeview, handle, info->spin);
157 tracecmd_close(info->handle); 156 update_title(info->window, filename);
158 info->handle = handle;
159 trace_graph_load_handle(info->ginfo, handle);
160 trace_view_reload(info->treeview, handle, info->spin);
161 update_title(info->window, filename);
162 }
163 g_free(filename);
164 } 157 }
165 gtk_widget_destroy(dialog); 158 g_free(filename);
166} 159}
167 160
168/* Callback for the clicked signal of the Exit button */ 161/* Callback for the clicked signal of the Exit button */
@@ -763,12 +756,11 @@ void kernel_shark(int argc, char **argv)
763 756
764 /* --- File - Load Option --- */ 757 /* --- File - Load Option --- */
765 758
766 sub_item = gtk_menu_item_new_with_label("Load info"); 759 sub_item = gtk_menu_item_new_with_label("Load data");
767 760
768 /* Add them to the menu */ 761 /* Add them to the menu */
769 gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item); 762 gtk_menu_shell_append(GTK_MENU_SHELL (menu), sub_item);
770 763
771 /* We can attach the Quit menu item to our exit function */
772 g_signal_connect_swapped (G_OBJECT (sub_item), "activate", 764 g_signal_connect_swapped (G_OBJECT (sub_item), "activate",
773 G_CALLBACK (load_clicked), 765 G_CALLBACK (load_clicked),
774 (gpointer) info); 766 (gpointer) info);
diff --git a/trace-dialog.c b/trace-dialog.c
index 65d184d..e27245d 100644
--- a/trace-dialog.c
+++ b/trace-dialog.c
@@ -77,3 +77,22 @@ void trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
77 gtk_dialog_run(GTK_DIALOG(dialog)); 77 gtk_dialog_run(GTK_DIALOG(dialog));
78 gtk_widget_destroy(dialog); 78 gtk_widget_destroy(dialog);
79} 79}
80
81gchar *trace_get_file_dialog(const gchar *title)
82{
83 GtkWidget *dialog;
84 gchar *filename = NULL;
85
86 dialog = gtk_file_chooser_dialog_new(title,
87 NULL,
88 GTK_FILE_CHOOSER_ACTION_OPEN,
89 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
90 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
91 NULL);
92 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
93 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
94
95 gtk_widget_destroy(dialog);
96
97 return filename;
98}
diff --git a/trace-graph-main.c b/trace-graph-main.c
index b373dd2..303f342 100644
--- a/trace-graph-main.c
+++ b/trace-graph-main.c
@@ -29,6 +29,7 @@
29#include "trace-cmd.h" 29#include "trace-cmd.h"
30#include "trace-graph.h" 30#include "trace-graph.h"
31#include "trace-filter.h" 31#include "trace-filter.h"
32#include "trace-gui.h"
32 33
33#define version "0.1.1" 34#define version "0.1.1"
34 35
@@ -52,26 +53,19 @@ load_clicked (gpointer data)
52{ 53{
53 struct graph_info *ginfo = data; 54 struct graph_info *ginfo = data;
54 struct tracecmd_input *handle; 55 struct tracecmd_input *handle;
55 GtkWidget *dialog;
56 gchar *filename; 56 gchar *filename;
57 57
58 dialog = gtk_file_chooser_dialog_new("Load File", 58 filename = trace_get_file_dialog("Load File");
59 NULL, 59 if (!filename)
60 GTK_FILE_CHOOSER_ACTION_OPEN, 60 return;
61 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 61
62 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 62 handle = tracecmd_open(filename);
63 NULL); 63 if (handle) {
64 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { 64 trace_graph_load_handle(ginfo, handle);
65 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 65 /* Free handle when freeing graph */
66 handle = tracecmd_open(filename); 66 tracecmd_close(handle);
67 if (handle) {
68 trace_graph_load_handle(ginfo, handle);
69 /* Free handle when freeing graph */
70 tracecmd_close(handle);
71 }
72 g_free(filename);
73 } 67 }
74 gtk_widget_destroy(dialog); 68 g_free(filename);
75} 69}
76 70
77/* Callback for the clicked signal of the Exit button */ 71/* Callback for the clicked signal of the Exit button */
diff --git a/trace-gui.h b/trace-gui.h
index 97b8e41..55778bf 100644
--- a/trace-gui.h
+++ b/trace-gui.h
@@ -34,5 +34,7 @@ void trace_show_help(GtkWidget *window, const gchar *link, GError **error);
34void trace_dialog(GtkWindow *parent, enum trace_dialog_type type, 34void trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
35 gchar *message, ...); 35 gchar *message, ...);
36 36
37gchar *trace_get_file_dialog(const gchar *title);
38
37 39
38#endif /* _TRACE_GUI */ 40#endif /* _TRACE_GUI */
diff --git a/trace-view-main.c b/trace-view-main.c
index 52678ce..7f1461b 100644
--- a/trace-view-main.c
+++ b/trace-view-main.c
@@ -28,6 +28,7 @@
28 28
29#include "trace-cmd.h" 29#include "trace-cmd.h"
30#include "trace-view.h" 30#include "trace-view.h"
31#include "trace-gui.h"
31 32
32#define version "0.1.1" 33#define version "0.1.1"
33 34
@@ -55,26 +56,19 @@ load_clicked (gpointer data)
55{ 56{
56 struct trace_tree_info *info = data; 57 struct trace_tree_info *info = data;
57 struct tracecmd_input *handle; 58 struct tracecmd_input *handle;
58 GtkWidget *dialog;
59 gchar *filename; 59 gchar *filename;
60 60
61 dialog = gtk_file_chooser_dialog_new("Load File", 61 filename = trace_get_file_dialog("Load File");
62 NULL, 62 if (!filename)
63 GTK_FILE_CHOOSER_ACTION_OPEN, 63 return;
64 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 64
65 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 65 handle = tracecmd_open(filename);
66 NULL); 66 if (handle) {
67 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { 67 trace_view_reload(info->trace_tree, handle, info->spin);
68 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 68 /* Free handle when freeing the trace tree */
69 handle = tracecmd_open(filename); 69 tracecmd_close(handle);
70 if (handle) {
71 trace_view_reload(info->trace_tree, handle, info->spin);
72 /* Free handle when freeing the trace tree */
73 tracecmd_close(handle);
74 }
75 g_free(filename);
76 } 70 }
77 gtk_widget_destroy(dialog); 71 g_free(filename);
78} 72}
79 73
80/* Callback for the clicked signal of the Exit button */ 74/* Callback for the clicked signal of the Exit button */