2 #include "../../util/debug.h"
8 struct perf_gtk_context
*pgctx
;
10 struct perf_gtk_context
*perf_gtk__activate_context(GtkWidget
*window
)
12 struct perf_gtk_context
*ctx
;
14 ctx
= malloc(sizeof(*pgctx
));
16 ctx
->main_window
= window
;
21 int perf_gtk__deactivate_context(struct perf_gtk_context
**ctx
)
23 if (!perf_gtk__is_active_context(*ctx
))
30 static int perf_gtk__error(const char *format
, va_list args
)
35 if (!perf_gtk__is_active_context(pgctx
) ||
36 vasprintf(&msg
, format
, args
) < 0) {
37 fprintf(stderr
, "Error:\n");
38 vfprintf(stderr
, format
, args
);
39 fprintf(stderr
, "\n");
43 dialog
= gtk_message_dialog_new_with_markup(GTK_WINDOW(pgctx
->main_window
),
44 GTK_DIALOG_DESTROY_WITH_PARENT
,
47 "<b>Error</b>\n\n%s", msg
);
48 gtk_dialog_run(GTK_DIALOG(dialog
));
50 gtk_widget_destroy(dialog
);
55 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
56 static int perf_gtk__warning_info_bar(const char *format
, va_list args
)
60 if (!perf_gtk__is_active_context(pgctx
) ||
61 vasprintf(&msg
, format
, args
) < 0) {
62 fprintf(stderr
, "Warning:\n");
63 vfprintf(stderr
, format
, args
);
64 fprintf(stderr
, "\n");
68 gtk_label_set_text(GTK_LABEL(pgctx
->message_label
), msg
);
69 gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx
->info_bar
),
71 gtk_widget_show(pgctx
->info_bar
);
77 static int perf_gtk__warning_statusbar(const char *format
, va_list args
)
81 if (!perf_gtk__is_active_context(pgctx
) ||
82 vasprintf(&msg
, format
, args
) < 0) {
83 fprintf(stderr
, "Warning:\n");
84 vfprintf(stderr
, format
, args
);
85 fprintf(stderr
, "\n");
89 gtk_statusbar_pop(GTK_STATUSBAR(pgctx
->statbar
),
90 pgctx
->statbar_ctx_id
);
92 /* Only first line can be displayed */
93 p
= strchr(msg
, '\n');
97 gtk_statusbar_push(GTK_STATUSBAR(pgctx
->statbar
),
98 pgctx
->statbar_ctx_id
, msg
);
105 struct perf_error_ops perf_gtk_eops
= {
106 .error
= perf_gtk__error
,
107 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
108 .warning
= perf_gtk__warning_info_bar
,
110 .warning
= perf_gtk__warning_statusbar
,