~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/ui/gtk/util.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include "../util.h"
  3 #include "gtk.h"
  4 
  5 #include <stdlib.h>
  6 #include <string.h>
  7 #include <linux/zalloc.h>
  8 
  9 struct perf_gtk_context *pgctx;
 10 
 11 struct perf_gtk_context *perf_gtk__activate_context(GtkWidget *window)
 12 {
 13         struct perf_gtk_context *ctx;
 14 
 15         ctx = malloc(sizeof(*pgctx));
 16         if (ctx)
 17                 ctx->main_window = window;
 18 
 19         return ctx;
 20 }
 21 
 22 int perf_gtk__deactivate_context(struct perf_gtk_context **ctx)
 23 {
 24         if (!perf_gtk__is_active_context(*ctx))
 25                 return -1;
 26 
 27         zfree(ctx);
 28         return 0;
 29 }
 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_SUPPORT
 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_SUPPORT
109         .warning        = perf_gtk__warning_info_bar,
110 #else
111         .warning        = perf_gtk__warning_statusbar,
112 #endif
113 };
114 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php