[go: up one dir, main page]

Menu

[4ff852]: / src / dlg.c  Maximize  Restore  History

Download this file

78 lines (64 with data), 2.5 kB

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