aboutsummaryrefslogtreecommitdiffstats
path: root/trace-dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'trace-dialog.c')
-rw-r--r--trace-dialog.c97
1 files changed, 82 insertions, 15 deletions
diff --git a/trace-dialog.c b/trace-dialog.c
index a87118c..89415dd 100644
--- a/trace-dialog.c
+++ b/trace-dialog.c
@@ -305,18 +305,22 @@ GtkResponseType trace_dialog(GtkWindow *parent, enum trace_dialog_type type,
305 * trace_get_file_dialog - pop up a file dialog to get a file 305 * trace_get_file_dialog - pop up a file dialog to get a file
306 * @title: the title of the dialog 306 * @title: the title of the dialog
307 * @open: the text for the "open" button (NULL for default) 307 * @open: the text for the "open" button (NULL for default)
308 * @ftype: What extension the dialog should default filter on.
308 * @warn: if the file exists, warn and let them choose again. 309 * @warn: if the file exists, warn and let them choose again.
309 * 310 *
310 * Returns: the filename if it should be used. NULL otherwise. 311 * Returns: the filename if it should be used. NULL otherwise.
311 * The filename needs to be freed with g_free(). 312 * The filename needs to be freed with g_free().
312 */ 313 */
313gchar *trace_get_file_dialog(const gchar *title, const char *open, 314gchar *trace_get_file_dialog_filter(const gchar *title, const char *open,
314 gboolean warn) 315 enum trace_dialog_filter ftype, gboolean warn)
315{ 316{
316 struct stat st; 317 struct stat st;
317 GtkWidget *dialog; 318 GtkWidget *dialog;
318 GtkResponseType ret; 319 GtkResponseType ret;
320 GtkFileFilter *filter;
321 GtkFileFilter *setfilter;
319 gchar *filename = NULL; 322 gchar *filename = NULL;
323 gchar *ext = NULL;
320 324
321 if (!open) 325 if (!open)
322 open = GTK_STOCK_OPEN; 326 open = GTK_STOCK_OPEN;
@@ -328,20 +332,71 @@ gchar *trace_get_file_dialog(const gchar *title, const char *open,
328 open, GTK_RESPONSE_ACCEPT, 332 open, GTK_RESPONSE_ACCEPT,
329 NULL); 333 NULL);
330 334
335 setfilter = filter = gtk_file_filter_new();
336 gtk_file_filter_set_name(filter, "All Files");
337 gtk_file_filter_add_pattern(filter, "*");
338 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
339
340 filter = gtk_file_filter_new();
341 gtk_file_filter_set_name(filter, "trace-cmd .dat files");
342 gtk_file_filter_add_pattern(filter, "*.dat");
343 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
344
345 if (ftype == TRACE_DIALOG_FILTER_DATA) {
346 setfilter = filter;
347 ext = ".dat";
348 }
349
350 filter = gtk_file_filter_new();
351 gtk_file_filter_set_name(filter, "KernelShark filter files");
352 gtk_file_filter_add_pattern(filter, "*.ksf");
353 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
354
355 if (ftype == TRACE_DIALOG_FILTER_FILTER) {
356 setfilter = filter;
357 ext = ".ksf";
358 }
359
360 filter = gtk_file_filter_new();
361 gtk_file_filter_set_name(filter, "KernelShark setting files");
362 gtk_file_filter_add_pattern(filter, "*.kss");
363 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
364
365 if (ftype == TRACE_DIALOG_FILTER_SETTING) {
366 setfilter = filter;
367 ext = ".kss";
368 }
369
370 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), setfilter);
371
331 again: 372 again:
332 ret = gtk_dialog_run(GTK_DIALOG(dialog)); 373 ret = gtk_dialog_run(GTK_DIALOG(dialog));
333 374
334 if (ret == GTK_RESPONSE_ACCEPT) { 375 if (ret == GTK_RESPONSE_ACCEPT) {
335 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 376 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
336 if (filename && warn && (stat(filename, &st) >= 0)) { 377 if (filename && warn) {
337 ret = trace_dialog(GTK_WINDOW(dialog), TRACE_GUI_ASK, 378 if (ext) {
338 "The file '%s' already exists.\n" 379 int len = strlen(filename);
339 "Are you sure you want to replace it", 380 gchar *tmp;
340 filename); 381
341 if (ret == GTK_RESPONSE_NO) { 382 /* Add extension if not already there */
342 g_free(filename); 383 if (strcmp(filename + (len - 4), ext) != 0) {
343 filename = NULL; 384 tmp = filename;
344 goto again; 385 filename = g_strdup_printf("%s%s",
386 tmp, ext);
387 g_free(tmp);
388 }
389 }
390 if (stat(filename, &st) >= 0) {
391 ret = trace_dialog(GTK_WINDOW(dialog), TRACE_GUI_ASK,
392 "The file '%s' already exists.\n"
393 "Are you sure you want to replace it",
394 filename);
395 if (ret == GTK_RESPONSE_NO) {
396 g_free(filename);
397 filename = NULL;
398 goto again;
399 }
345 } 400 }
346 } 401 }
347 } 402 }
@@ -351,6 +406,12 @@ gchar *trace_get_file_dialog(const gchar *title, const char *open,
351 return filename; 406 return filename;
352} 407}
353 408
409gchar *trace_get_file_dialog(const gchar *title, const char *open,
410 gboolean warn)
411{
412 return trace_get_file_dialog_filter(title, open, TRACE_DIALOG_FILTER_NONE, warn);
413}
414
354/** 415/**
355 * trace_create_combo_box - helper function to create a label and combo box 416 * trace_create_combo_box - helper function to create a label and combo box
356 * @hbox: The hbox to add the label and combo box to 417 * @hbox: The hbox to add the label and combo box to
@@ -358,6 +419,9 @@ gchar *trace_get_file_dialog(const gchar *title, const char *open,
358 * @combo_model_create: The function used to create the combo model 419 * @combo_model_create: The function used to create the combo model
359 * @data: data to pass to the combo_model_create. 420 * @data: data to pass to the combo_model_create.
360 * 421 *
422 * If no @hbox is given, the @text is ignored, and only the combo box
423 * is created.
424 *
361 * Returns the combo box in the hbox. 425 * Returns the combo box in the hbox.
362 */ 426 */
363GtkWidget * 427GtkWidget *
@@ -370,9 +434,11 @@ trace_create_combo_box(GtkWidget *hbox, const gchar *text,
370 GtkWidget *label; 434 GtkWidget *label;
371 GtkWidget *combo; 435 GtkWidget *combo;
372 436
373 label = gtk_label_new(text); 437 if (hbox) {
374 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 438 label = gtk_label_new(text);
375 gtk_widget_show(label); 439 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
440 gtk_widget_show(label);
441 }
376 442
377 /* --- Set up the selection combo box --- */ 443 /* --- Set up the selection combo box --- */
378 444
@@ -381,7 +447,8 @@ trace_create_combo_box(GtkWidget *hbox, const gchar *text,
381 renderer = gtk_cell_renderer_text_new(); 447 renderer = gtk_cell_renderer_text_new();
382 448
383 combo = gtk_combo_box_new_with_model(model); 449 combo = gtk_combo_box_new_with_model(model);
384 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0); 450 if (hbox)
451 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
385 gtk_widget_show(combo); 452 gtk_widget_show(combo);
386 453
387 /* Free model with combobox */ 454 /* Free model with combobox */