aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-06-14 20:51:50 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-06-14 20:51:50 -0400
commitad15344e398191ae63bde380b865c57c286e2732 (patch)
treef79c661d8db7d2ff283f4f51713c7a409f8b6585
parenta06b4a35cf29205d4c17da6c8f6fbc63b503b68f (diff)
kernelshark: Have file dialog ask if we want to overwrite
If someone selects a file that already exists and the command will be used to overwrite the file. Ask the user if they want to overwrite it instead of just doing so. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--kernel-shark.c6
-rw-r--r--trace-capture.c2
-rw-r--r--trace-dialog.c50
-rw-r--r--trace-graph-main.c6
-rw-r--r--trace-gui.h8
-rw-r--r--trace-view-main.c6
6 files changed, 58 insertions, 20 deletions
diff --git a/kernel-shark.c b/kernel-shark.c
index 7c0f816..e97d612 100644
--- a/kernel-shark.c
+++ b/kernel-shark.c
@@ -290,7 +290,7 @@ load_clicked (gpointer data)
290 struct tracecmd_input *handle; 290 struct tracecmd_input *handle;
291 gchar *filename; 291 gchar *filename;
292 292
293 filename = trace_get_file_dialog("Load File"); 293 filename = trace_get_file_dialog("Load File", NULL, FALSE);
294 if (!filename) 294 if (!filename)
295 return; 295 return;
296 296
@@ -321,7 +321,7 @@ load_filters_clicked (gpointer data)
321 gchar *filename; 321 gchar *filename;
322 int ret; 322 int ret;
323 323
324 filename = trace_get_file_dialog("Load Filters"); 324 filename = trace_get_file_dialog("Load Filters", NULL, FALSE);
325 if (!filename) 325 if (!filename)
326 return; 326 return;
327 327
@@ -407,7 +407,7 @@ save_filters_clicked (gpointer data)
407 struct filter_task *hide_tasks; 407 struct filter_task *hide_tasks;
408 gchar *filename; 408 gchar *filename;
409 409
410 filename = trace_get_file_dialog("Save Filters"); 410 filename = trace_get_file_dialog("Save Filters", "Save", TRUE);
411 if (!filename) 411 if (!filename)
412 return; 412 return;
413 413
diff --git a/trace-capture.c b/trace-capture.c
index fda61fc..3fa5a1e 100644
--- a/trace-capture.c
+++ b/trace-capture.c
@@ -554,7 +554,7 @@ file_clicked (GtkWidget *widget, gpointer data)
554 struct trace_capture *cap = data; 554 struct trace_capture *cap = data;
555 gchar *filename; 555 gchar *filename;
556 556
557 filename = trace_get_file_dialog("Trace File"); 557 filename = trace_get_file_dialog("Trace File", "Save", TRUE);
558 if (!filename) 558 if (!filename)
559 return; 559 return;
560 560
diff --git a/trace-dialog.c b/trace-dialog.c
index 4fab040..4bddd08 100644
--- a/trace-dialog.c
+++ b/trace-dialog.c
@@ -250,13 +250,15 @@ void trace_show_help(GtkWidget *window, const gchar *link, GError **error)
250#endif 250#endif
251} 251}
252 252
253void trace_dialog(GtkWindow *parent, enum trace_dialog_type type, 253GtkResponseType trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
254 gchar *message, ...) 254 gchar *message, ...)
255{ 255{
256 GtkWidget *dialog; 256 GtkWidget *dialog;
257 GtkMessageType mtype; 257 GtkMessageType mtype;
258 GtkButtonsType btype = GTK_BUTTONS_CLOSE;
258 gchar *str; 259 gchar *str;
259 va_list ap; 260 va_list ap;
261 int result;
260 262
261 switch (type) { 263 switch (type) {
262 case TRACE_GUI_INFO: 264 case TRACE_GUI_INFO:
@@ -268,6 +270,10 @@ void trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
268 case TRACE_GUI_ERROR: 270 case TRACE_GUI_ERROR:
269 mtype = GTK_MESSAGE_ERROR; 271 mtype = GTK_MESSAGE_ERROR;
270 break; 272 break;
273 case TRACE_GUI_ASK:
274 mtype = GTK_MESSAGE_WARNING;
275 btype = GTK_BUTTONS_YES_NO;
276 break;
271 } 277 }
272 278
273 va_start(ap, message); 279 va_start(ap, message);
@@ -277,26 +283,56 @@ void trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
277 dialog = gtk_message_dialog_new(parent, 283 dialog = gtk_message_dialog_new(parent,
278 GTK_DIALOG_DESTROY_WITH_PARENT, 284 GTK_DIALOG_DESTROY_WITH_PARENT,
279 mtype, 285 mtype,
280 GTK_BUTTONS_CLOSE, 286 btype,
281 "%s", str); 287 "%s", str);
282 g_free(str); 288 g_free(str);
283 gtk_dialog_run(GTK_DIALOG(dialog)); 289 result = gtk_dialog_run(GTK_DIALOG(dialog));
284 gtk_widget_destroy(dialog); 290 gtk_widget_destroy(dialog);
291
292 return result;
285} 293}
286 294
287gchar *trace_get_file_dialog(const gchar *title) 295/**
296 * trace_get_file_dialog - pop up a file dialog to get a file
297 * @title: the title of the dialog
298 * @open: the text for the "open" button (NULL for default)
299 * @warn: if the file exists, warn and let them choose again.
300 *
301 * Returns: the filename if it should be used. NULL otherwise.
302 * The filename needs to be freed with g_free().
303 */
304gchar *trace_get_file_dialog(const gchar *title, const char *open,
305 gboolean warn)
288{ 306{
289 GtkWidget *dialog; 307 GtkWidget *dialog;
308 GtkResponseType ret;
290 gchar *filename = NULL; 309 gchar *filename = NULL;
291 310
311 if (!open)
312 open = GTK_STOCK_OPEN;
313
292 dialog = gtk_file_chooser_dialog_new(title, 314 dialog = gtk_file_chooser_dialog_new(title,
293 NULL, 315 NULL,
294 GTK_FILE_CHOOSER_ACTION_OPEN, 316 GTK_FILE_CHOOSER_ACTION_OPEN,
295 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 317 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
296 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 318 open, GTK_RESPONSE_ACCEPT,
297 NULL); 319 NULL);
298 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) 320
321 again:
322 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
299 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 323 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
324 if (warn) {
325 ret = trace_dialog(GTK_WINDOW(dialog), TRACE_GUI_ASK,
326 "The file '%s' already exists.\n"
327 "Are you sure you want to replace it",
328 filename);
329 if (ret == GTK_RESPONSE_NO) {
330 g_free(filename);
331 filename = NULL;
332 goto again;
333 }
334 }
335 }
300 336
301 gtk_widget_destroy(dialog); 337 gtk_widget_destroy(dialog);
302 338
diff --git a/trace-graph-main.c b/trace-graph-main.c
index b4f05fb..cc8bf6c 100644
--- a/trace-graph-main.c
+++ b/trace-graph-main.c
@@ -57,7 +57,7 @@ load_clicked (gpointer data)
57 struct tracecmd_input *handle; 57 struct tracecmd_input *handle;
58 gchar *filename; 58 gchar *filename;
59 59
60 filename = trace_get_file_dialog("Load File"); 60 filename = trace_get_file_dialog("Load File", NULL, FALSE);
61 if (!filename) 61 if (!filename)
62 return; 62 return;
63 63
@@ -162,7 +162,7 @@ load_filters_clicked (gpointer data)
162 struct tracecmd_xml_handle *handle; 162 struct tracecmd_xml_handle *handle;
163 gchar *filename; 163 gchar *filename;
164 164
165 filename = trace_get_file_dialog("Load Filters"); 165 filename = trace_get_file_dialog("Load Filters", NULL, FALSE);
166 if (!filename) 166 if (!filename)
167 return; 167 return;
168 168
@@ -189,7 +189,7 @@ save_filters_clicked (gpointer data)
189 struct tracecmd_xml_handle *handle; 189 struct tracecmd_xml_handle *handle;
190 gchar *filename; 190 gchar *filename;
191 191
192 filename = trace_get_file_dialog("Save Filters"); 192 filename = trace_get_file_dialog("Save Filters", "Save", TRUE);
193 if (!filename) 193 if (!filename)
194 return; 194 return;
195 195
diff --git a/trace-gui.h b/trace-gui.h
index a2177b0..ca9f6ca 100644
--- a/trace-gui.h
+++ b/trace-gui.h
@@ -27,6 +27,7 @@ enum trace_dialog_type {
27 TRACE_GUI_INFO, 27 TRACE_GUI_INFO,
28 TRACE_GUI_WARNING, 28 TRACE_GUI_WARNING,
29 TRACE_GUI_ERROR, 29 TRACE_GUI_ERROR,
30 TRACE_GUI_ASK,
30}; 31};
31 32
32GtkWidget *trace_status_bar_new(void); 33GtkWidget *trace_status_bar_new(void);
@@ -36,10 +37,11 @@ void trace_dialog_register_alt_warning(void (*alt)(const char *fmt, va_list ap))
36 37
37void trace_show_help(GtkWidget *window, const gchar *link, GError **error); 38void trace_show_help(GtkWidget *window, const gchar *link, GError **error);
38 39
39void trace_dialog(GtkWindow *parent, enum trace_dialog_type type, 40GtkResponseType trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
40 gchar *message, ...); 41 gchar *message, ...);
41 42
42gchar *trace_get_file_dialog(const gchar *title); 43gchar *trace_get_file_dialog(const gchar *title, const char *open,
44 gboolean warn);
43 45
44GtkWidget * 46GtkWidget *
45trace_create_combo_box(GtkWidget *hbox, const gchar *text, 47trace_create_combo_box(GtkWidget *hbox, const gchar *text,
diff --git a/trace-view-main.c b/trace-view-main.c
index 59d6838..636ebd1 100644
--- a/trace-view-main.c
+++ b/trace-view-main.c
@@ -68,7 +68,7 @@ load_clicked (gpointer data)
68 struct tracecmd_input *handle; 68 struct tracecmd_input *handle;
69 gchar *filename; 69 gchar *filename;
70 70
71 filename = trace_get_file_dialog("Load File"); 71 filename = trace_get_file_dialog("Load File", NULL, FALSE);
72 if (!filename) 72 if (!filename)
73 return; 73 return;
74 74
@@ -91,7 +91,7 @@ load_filters_clicked (gpointer data)
91 struct tracecmd_xml_handle *handle; 91 struct tracecmd_xml_handle *handle;
92 gchar *filename; 92 gchar *filename;
93 93
94 filename = trace_get_file_dialog("Load Filters"); 94 filename = trace_get_file_dialog("Load Filters", NULL, FALSE);
95 if (!filename) 95 if (!filename)
96 return; 96 return;
97 97
@@ -121,7 +121,7 @@ save_filters_clicked (gpointer data)
121 struct tracecmd_xml_handle *handle; 121 struct tracecmd_xml_handle *handle;
122 gchar *filename; 122 gchar *filename;
123 123
124 filename = trace_get_file_dialog("Save Filters"); 124 filename = trace_get_file_dialog("Save Filters", "Save", TRUE);
125 if (!filename) 125 if (!filename)
126 return; 126 return;
127 127