aboutsummaryrefslogtreecommitdiff
path: root/src/common/logging.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/logging.c')
-rw-r--r--src/common/logging.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/common/logging.c b/src/common/logging.c
new file mode 100644
index 00000000..d49298fd
--- /dev/null
+++ b/src/common/logging.c
@@ -0,0 +1,120 @@
1/*
2 This file is part of GNUnet
3 (C) 2006 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file src/common/logging.c
22 * @brief This file contains GUI functions related to logging
23 * @author Igor Wronsky
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunetgtk_common.h"
29#include <GNUnet/gnunet_util_crypto.h>
30#include <glib.h>
31#include <gmodule.h>
32
33/**
34 * Closure for doInfoMessage.
35 */
36typedef struct {
37 int doPopup;
38 char * note;
39} InfoMessage;
40
41/**
42 * Callback for infoMessage()
43 */
44static void * doInfoMessage(void * args) {
45 const InfoMessage * info = args;
46 GtkTextIter iter;
47 GtkTextBuffer * buffer;
48
49 if (info->doPopup==YES)
50 gtk_widget_show(infoWindow);
51 buffer
52 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoWindowTextView));
53 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
54 gtk_text_buffer_insert(buffer,
55 &iter,
56 info->note,
57 -1);
58 return NULL;
59}
60
61/**
62 * Appends a message to the info window
63 *
64 * @param doPopup do we open the window, YES or NO
65 */
66void infoMessage(int doPopup,
67 const char * format,
68 ...) {
69 va_list args;
70 InfoMessage info;
71
72 va_start(args, format);
73 info.note = g_strdup_vprintf(format, args);
74 va_end(args);
75 info.doPopup = doPopup;
76 gtkSaveCall(&doInfoMessage,
77 &info);
78 g_free(info.note);
79}
80
81static void * saveAddLogEntry(void * args) {
82 static GtkWidget * s = NULL;
83 static int once = 1;
84 static guint id;
85
86 if (once) {
87 once = 0;
88 s = glade_xml_get_widget(mainXML,
89 "statusbar");
90 id = gtk_statusbar_get_context_id(GTK_STATUSBAR(s),
91 "LOG");
92 } else
93 gtk_statusbar_pop(GTK_STATUSBAR(s),
94 id);
95 gtk_statusbar_push(GTK_STATUSBAR(s),
96 id,
97 (const char*) args);
98 return NULL;
99}
100
101/**
102 * Appends a log entry to the info window
103 *
104 * @param txt the log entry
105 *
106 */
107void addLogEntry(const char * txt,
108 ...) {
109 va_list args;
110 gchar * note;
111
112 va_start(args, txt);
113 note = g_strdup_vprintf(txt, args);
114 va_end(args);
115 infoMessage(NO, note);
116 gtkSaveCall(&saveAddLogEntry,
117 (void*) note);
118 g_free(note);
119}
120