diff options
author | Namhyung Kim <namhyung@gmail.com> | 2012-05-29 00:23:02 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-06-19 12:06:19 -0400 |
commit | e078ba14dff5c315ce19a978574883f417d2cfa0 (patch) | |
tree | 81fefb44d9ea360e3a943f58e088ba97039a2148 | |
parent | a6b702c117f839023814c1e03453c701d26de522 (diff) |
perf ui/gtk: Use struct perf_error_ops
Define and use perf_gtk_eops to provide a GTK2 message dialog for error
reporting and a info_bar for warning.
As GtkInfoBar requires recent GTK+ libraries, provides a fallback
implementation using statusbar widget too.
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1338265382-6872-8-git-send-email-namhyung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/ui/gtk/setup.c | 5 | ||||
-rw-r--r-- | tools/perf/ui/gtk/util.c | 86 |
2 files changed, 91 insertions, 0 deletions
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c index 829529957766..92879ce61e2f 100644 --- a/tools/perf/ui/gtk/setup.c +++ b/tools/perf/ui/gtk/setup.c | |||
@@ -1,12 +1,17 @@ | |||
1 | #include "gtk.h" | 1 | #include "gtk.h" |
2 | #include "../../util/cache.h" | 2 | #include "../../util/cache.h" |
3 | #include "../../util/debug.h" | ||
4 | |||
5 | extern struct perf_error_ops perf_gtk_eops; | ||
3 | 6 | ||
4 | int perf_gtk__init(void) | 7 | int perf_gtk__init(void) |
5 | { | 8 | { |
9 | perf_error__register(&perf_gtk_eops); | ||
6 | return gtk_init_check(NULL, NULL) ? 0 : -1; | 10 | return gtk_init_check(NULL, NULL) ? 0 : -1; |
7 | } | 11 | } |
8 | 12 | ||
9 | void perf_gtk__exit(bool wait_for_ok __used) | 13 | void perf_gtk__exit(bool wait_for_ok __used) |
10 | { | 14 | { |
15 | perf_error__unregister(&perf_gtk_eops); | ||
11 | gtk_main_quit(); | 16 | gtk_main_quit(); |
12 | } | 17 | } |
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c index 6fe13fdc513e..0ead373c0dfb 100644 --- a/tools/perf/ui/gtk/util.c +++ b/tools/perf/ui/gtk/util.c | |||
@@ -2,6 +2,8 @@ | |||
2 | #include "../../util/debug.h" | 2 | #include "../../util/debug.h" |
3 | #include "gtk.h" | 3 | #include "gtk.h" |
4 | 4 | ||
5 | #include <string.h> | ||
6 | |||
5 | 7 | ||
6 | struct perf_gtk_context *pgctx; | 8 | struct perf_gtk_context *pgctx; |
7 | 9 | ||
@@ -26,6 +28,90 @@ int perf_gtk__deactivate_context(struct perf_gtk_context **ctx) | |||
26 | return 0; | 28 | return 0; |
27 | } | 29 | } |
28 | 30 | ||
31 | static int perf_gtk__error(const char *format, va_list args) | ||
32 | { | ||
33 | char *msg; | ||
34 | GtkWidget *dialog; | ||
35 | |||
36 | if (!perf_gtk__is_active_context(pgctx) || | ||
37 | vasprintf(&msg, format, args) < 0) { | ||
38 | fprintf(stderr, "Error:\n"); | ||
39 | vfprintf(stderr, format, args); | ||
40 | fprintf(stderr, "\n"); | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(pgctx->main_window), | ||
45 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
46 | GTK_MESSAGE_ERROR, | ||
47 | GTK_BUTTONS_CLOSE, | ||
48 | "<b>Error</b>\n\n%s", msg); | ||
49 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
50 | |||
51 | gtk_widget_destroy(dialog); | ||
52 | free(msg); | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | #ifdef HAVE_GTK_INFO_BAR | ||
57 | static int perf_gtk__warning_info_bar(const char *format, va_list args) | ||
58 | { | ||
59 | char *msg; | ||
60 | |||
61 | if (!perf_gtk__is_active_context(pgctx) || | ||
62 | vasprintf(&msg, format, args) < 0) { | ||
63 | fprintf(stderr, "Warning:\n"); | ||
64 | vfprintf(stderr, format, args); | ||
65 | fprintf(stderr, "\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | gtk_label_set_text(GTK_LABEL(pgctx->message_label), msg); | ||
70 | gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx->info_bar), | ||
71 | GTK_MESSAGE_WARNING); | ||
72 | gtk_widget_show(pgctx->info_bar); | ||
73 | |||
74 | free(msg); | ||
75 | return 0; | ||
76 | } | ||
77 | #else | ||
78 | static int perf_gtk__warning_statusbar(const char *format, va_list args) | ||
79 | { | ||
80 | char *msg, *p; | ||
81 | |||
82 | if (!perf_gtk__is_active_context(pgctx) || | ||
83 | vasprintf(&msg, format, args) < 0) { | ||
84 | fprintf(stderr, "Warning:\n"); | ||
85 | vfprintf(stderr, format, args); | ||
86 | fprintf(stderr, "\n"); | ||
87 | return -1; | ||
88 | } | ||
89 | |||
90 | gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar), | ||
91 | pgctx->statbar_ctx_id); | ||
92 | |||
93 | /* Only first line can be displayed */ | ||
94 | p = strchr(msg, '\n'); | ||
95 | if (p) | ||
96 | *p = '\0'; | ||
97 | |||
98 | gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar), | ||
99 | pgctx->statbar_ctx_id, msg); | ||
100 | |||
101 | free(msg); | ||
102 | return 0; | ||
103 | } | ||
104 | #endif | ||
105 | |||
106 | struct perf_error_ops perf_gtk_eops = { | ||
107 | .error = perf_gtk__error, | ||
108 | #ifdef HAVE_GTK_INFO_BAR | ||
109 | .warning = perf_gtk__warning_info_bar, | ||
110 | #else | ||
111 | .warning = perf_gtk__warning_statusbar, | ||
112 | #endif | ||
113 | }; | ||
114 | |||
29 | /* | 115 | /* |
30 | * FIXME: Functions below should be implemented properly. | 116 | * FIXME: Functions below should be implemented properly. |
31 | * For now, just add stubs for NO_NEWT=1 build. | 117 | * For now, just add stubs for NO_NEWT=1 build. |