1 /*
2 roxterm - VTE/GTK terminal emulator with tabs
3 Copyright (C) 2004-2015 Tony Houghton <h@realh.co.uk>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include "dlg.h"
21
run_msg_dialog(GtkWindow * parent,const char * title,GtkMessageType mtype,const char * msg)22 static void run_msg_dialog(GtkWindow *parent, const char *title,
23 GtkMessageType mtype, const char *msg)
24 {
25 GtkWidget *dialog;
26 char *full_title = g_strdup_printf(_("%s from ROXTerm"), title);
27
28 dialog = gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT,
29 mtype, GTK_BUTTONS_OK, "%s", msg);
30 gtk_window_set_title(GTK_WINDOW(dialog), full_title);
31 g_free(full_title);
32 gtk_dialog_run(GTK_DIALOG (dialog));
33 gtk_widget_destroy(dialog);
34 }
35
36 #define ROXTERM_DEFINE_REPORT_FN(fn, title, log_level, diag_type) \
37 void fn(GtkWindow *parent, const char *s, ...) \
38 { \
39 va_list ap; \
40 char *msg; \
41 va_start(ap, s); \
42 msg = g_strdup_vprintf(s, ap); \
43 g_log(G_LOG_DOMAIN, log_level, "%s", msg); \
44 run_msg_dialog(parent, title, diag_type, msg); \
45 va_end(ap); \
46 g_free(msg); \
47 }
48
49 ROXTERM_DEFINE_REPORT_FN(dlg_message, _("Message"), G_LOG_LEVEL_MESSAGE,
50 GTK_MESSAGE_INFO)
51
52 ROXTERM_DEFINE_REPORT_FN(dlg_warning, _("Warning"), G_LOG_LEVEL_WARNING,
53 GTK_MESSAGE_WARNING)
54
55 ROXTERM_DEFINE_REPORT_FN(dlg_critical, _("Error"), G_LOG_LEVEL_CRITICAL,
56 GTK_MESSAGE_ERROR)
57
dlg_ok_cancel(GtkWindow * parent,const char * title,const char * format,...)58 GtkWidget *dlg_ok_cancel(GtkWindow *parent, const char *title,
59 const char *format, ...)
60 {
61 va_list ap;
62 char *msg;
63 GtkWidget *w;
64
65 va_start(ap, format);
66 msg = g_strdup_vprintf(format, ap);
67 va_end(ap);
68 w = gtk_message_dialog_new(parent,
69 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
70 GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
71 "%s", msg);
72 g_free(msg);
73 gtk_window_set_title(GTK_WINDOW(w), title);
74 return w;
75 }
76
77 /* vi:set sw=4 ts=4 et cindent cino= */
78