ARM: dts: kirkwood: gpio-leds fixes for linkstation ls-wvl/vl
[linux/fpc-iii.git] / tools / perf / ui / gtk / util.c
blob52e7fc48af9f488088785b8e216e05f6b22546fc
1 #include "../util.h"
2 #include "../../util/debug.h"
3 #include "gtk.h"
5 #include <string.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));
15 if (ctx)
16 ctx->main_window = window;
18 return ctx;
21 int perf_gtk__deactivate_context(struct perf_gtk_context **ctx)
23 if (!perf_gtk__is_active_context(*ctx))
24 return -1;
26 zfree(ctx);
27 return 0;
30 static int perf_gtk__error(const char *format, va_list args)
32 char *msg;
33 GtkWidget *dialog;
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");
40 return -1;
43 dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(pgctx->main_window),
44 GTK_DIALOG_DESTROY_WITH_PARENT,
45 GTK_MESSAGE_ERROR,
46 GTK_BUTTONS_CLOSE,
47 "<b>Error</b>\n\n%s", msg);
48 gtk_dialog_run(GTK_DIALOG(dialog));
50 gtk_widget_destroy(dialog);
51 free(msg);
52 return 0;
55 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
56 static int perf_gtk__warning_info_bar(const char *format, va_list args)
58 char *msg;
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");
65 return -1;
68 gtk_label_set_text(GTK_LABEL(pgctx->message_label), msg);
69 gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx->info_bar),
70 GTK_MESSAGE_WARNING);
71 gtk_widget_show(pgctx->info_bar);
73 free(msg);
74 return 0;
76 #else
77 static int perf_gtk__warning_statusbar(const char *format, va_list args)
79 char *msg, *p;
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");
86 return -1;
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');
94 if (p)
95 *p = '\0';
97 gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar),
98 pgctx->statbar_ctx_id, msg);
100 free(msg);
101 return 0;
103 #endif
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,
109 #else
110 .warning = perf_gtk__warning_statusbar,
111 #endif