aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2006-11-30 16:27:35 +0000
committerChristian Grothoff <christian@grothoff.org>2006-11-30 16:27:35 +0000
commit7257f405932eef9a658d2b5e9b5811c7ce62e31c (patch)
treea8d2f021b8373b905053aff68bee25550d04194c
parent74f4e52f167f1815fe79f4229ccdfdeefd10e257 (diff)
downloadgnunet-gtk-7257f405932eef9a658d2b5e9b5811c7ce62e31c.tar.gz
gnunet-gtk-7257f405932eef9a658d2b5e9b5811c7ce62e31c.zip
refact
-rw-r--r--src/common/Makefile.am4
-rw-r--r--src/common/helper.c192
-rw-r--r--src/common/iterators.c74
-rw-r--r--src/common/logging.c120
4 files changed, 226 insertions, 164 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index a06b6a87..d34269b2 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -9,7 +9,9 @@ lib_LTLIBRARIES = \
9 libgnunetgtk_common.la 9 libgnunetgtk_common.la
10 10
11libgnunetgtk_common_la_SOURCES = \ 11libgnunetgtk_common_la_SOURCES = \
12 helper.c 12 helper.c \
13 iterators.c \
14 logging.c
13 15
14libgnunetgtk_common_la_LDFLAGS = \ 16libgnunetgtk_common_la_LDFLAGS = \
15 -export-dynamic $(LIBLTDL) $(LIBS) \ 17 -export-dynamic $(LIBLTDL) $(LIBS) \
diff --git a/src/common/helper.c b/src/common/helper.c
index 90c817b5..558d8f3f 100644
--- a/src/common/helper.c
+++ b/src/common/helper.c
@@ -89,11 +89,6 @@ static struct GE_Context * ectx;
89 89
90static struct GC_Configuration * cfg; 90static struct GC_Configuration * cfg;
91 91
92#ifdef WINDOWS
93static void CALLBACK sigalrmHandler(DWORD sig) {
94}
95#endif
96
97static gboolean saveCallWrapper(gpointer data) { 92static gboolean saveCallWrapper(gpointer data) {
98 SaveCall * call = data; 93 SaveCall * call = data;
99 int i; 94 int i;
@@ -155,94 +150,6 @@ void * gtkSaveCall(PThreadMain func,
155} 150}
156 151
157/** 152/**
158 * Closure for doInfoMessage.
159 */
160typedef struct {
161 int doPopup;
162 char * note;
163} InfoMessage;
164
165/**
166 * Callback for infoMessage()
167 */
168static void * doInfoMessage(void * args) {
169 const InfoMessage * info = args;
170 GtkTextIter iter;
171 GtkTextBuffer * buffer;
172
173 if (info->doPopup==YES)
174 gtk_widget_show(infoWindow);
175 buffer
176 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoWindowTextView));
177 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
178 gtk_text_buffer_insert(buffer,
179 &iter,
180 info->note,
181 -1);
182 return NULL;
183}
184
185/**
186 * Appends a message to the info window
187 *
188 * @param doPopup do we open the window, YES or NO
189 */
190void infoMessage(int doPopup,
191 const char * format,
192 ...) {
193 va_list args;
194 InfoMessage info;
195
196 va_start(args, format);
197 info.note = g_strdup_vprintf(format, args);
198 va_end(args);
199 info.doPopup = doPopup;
200 gtkSaveCall(&doInfoMessage,
201 &info);
202 g_free(info.note);
203}
204
205static void * saveAddLogEntry(void * args) {
206 static GtkWidget * s = NULL;
207 static int once = 1;
208 static guint id;
209
210 if (once) {
211 once = 0;
212 s = glade_xml_get_widget(mainXML,
213 "statusbar");
214 id = gtk_statusbar_get_context_id(GTK_STATUSBAR(s),
215 "LOG");
216 } else
217 gtk_statusbar_pop(GTK_STATUSBAR(s),
218 id);
219 gtk_statusbar_push(GTK_STATUSBAR(s),
220 id,
221 (const char*) args);
222 return NULL;
223}
224
225/**
226 * Appends a log entry to the info window
227 *
228 * @param txt the log entry
229 *
230 */
231void addLogEntry(const char * txt,
232 ...) {
233 va_list args;
234 gchar * note;
235
236 va_start(args, txt);
237 note = g_strdup_vprintf(txt, args);
238 va_end(args);
239 infoMessage(NO, note);
240 gtkSaveCall(&saveAddLogEntry,
241 (void*) note);
242 g_free(note);
243}
244
245/**
246 * Simple accessor method. 153 * Simple accessor method.
247 */ 154 */
248const char * getGladeFileName() { 155const char * getGladeFileName() {
@@ -653,89 +560,48 @@ GdkWindowState getMainWindowState() {
653 * Start gnunet-setup, asking for a password if needed 560 * Start gnunet-setup, asking for a password if needed
654 */ 561 */
655gboolean startGNUnetSetup (gboolean run_wizard) { 562gboolean startGNUnetSetup (gboolean run_wizard) {
563 GtkWidget * mainWindow;
564 GtkWidget * messageDialog;
656 int code; 565 int code;
657 char *error_message; 566 char *error_message;
658#ifdef WITH_LIBGKSU2 567#ifdef WITH_LIBGKSU2
659 GError *gerror = NULL; 568 GError *gerror = NULL;
660 if(run_wizard) { 569 if(run_wizard) {
661 code = gksu_run("gnunet-setup -d wizard-gtk", &gerror); } 570 code = gksu_run("gnunet-setup -d wizard-gtk",
662 else { 571 &gerror);
663 code = gksu_run("gnunet-setup -d", &gerror); } 572 } else {
664 if(code && !gerror) { 573 code = gksu_run("gnunet-setup -d",
665 error_message = STRDUP(_("GKSu encountered an unknown error running the configuration tool (gnunet-setup).")); } 574 &gerror);
666 else if(code && gerror) { 575 }
667 error_message = g_strdup_printf(_("GKSu returned:\n%s"), gerror->message); 576 if (code && !gerror) {
668 g_error_free(gerror); } 577 error_message = STRDUP(_("GKSu encountered an unknown error running the configuration tool (gnunet-setup)."));
669 else { 578 } else if (code && gerror) {
670 error_message = NULL; } 579 error_message = g_strdup_printf(_("GKSu returned:\n%s"),
580 gerror->message);
581 g_error_free(gerror);
582 } else {
583 error_message = NULL;
584 }
671#elif defined(WINDOWS) 585#elif defined(WINDOWS)
672/* FIXME: run gnunet-setup, assuming we can get the needed rights */ 586/* FIXME: run gnunet-setup, assuming we can get the needed rights */
673 error_message = STRDUP("Not implemented yet !"); 587 error_message = STRDUP(_("Not implemented yet!"));
674 return TRUE; 588 code = TRUE;
675#else 589#else
676 error_message = STRDUP(_("GKSu support is not enabled, impossible to get the needed rights. You should build gnunet-gtk with the --enable-libgksu2 option, or get the right binary package. Note you can still start the configuration tool (gnunet-setup) manually.")); 590 error_message = STRDUP(_("GKSu support is not enabled, impossible to get the needed rights. You should build gnunet-gtk with the --enable-libgksu2 option, or get the right binary package. Note you can still start the configuration tool (gnunet-setup) manually."));
677 return TRUE; 591 code = TRUE;
678#endif 592#endif
679 GtkWidget *mainWindow, *messageDialog; 593 mainWindow = glade_xml_get_widget(getMainXML(),
680 mainWindow = glade_xml_get_widget(getMainXML(), "mainWindow"); 594 "mainWindow");
681 messageDialog = gtk_message_dialog_new (GTK_WINDOW(mainWindow), 595 messageDialog = gtk_message_dialog_new(GTK_WINDOW(mainWindow),
682 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, 596 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
683 GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, 597 GTK_MESSAGE_WARNING,
684 _("Failed to run the configuration tool (gnunet-setup): %s"), 598 GTK_BUTTONS_CLOSE,
685 error_message); 599 _("Failed to run the configuration tool (gnunet-setup): %s"),
600 error_message);
686 gtk_dialog_run(GTK_DIALOG(messageDialog)); 601 gtk_dialog_run(GTK_DIALOG(messageDialog));
687 gtk_widget_destroy (messageDialog); 602 gtk_widget_destroy(messageDialog);
688 FREE(error_message); 603 FREE(error_message);
689 return code; 604 return code;
690} 605}
691 606
692/**
693 * Identical to "gtk_tree_selection_selected_foreach",
694 * except that modifications of the underlying model
695 * during the iteration are tolerated.
696 */
697void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection,
698 GtkTreeSelectionForeachFunc func,
699 gpointer data) {
700 unsigned int i;
701 unsigned int size;
702 GList * selected;
703 GtkTreeRowReference ** refs;
704 GtkTreeModel * model;
705 GtkTreePath * path;
706 GtkTreeIter iter;
707
708 selected = gtk_tree_selection_get_selected_rows(selection,
709 &model);
710
711 i = g_list_length(selected);
712 size = 0;
713 refs = NULL;
714 GROW(refs,
715 size,
716 i);
717 for (i=0;i<size;i++)
718 refs[i] = gtk_tree_row_reference_new(model,
719 g_list_nth_data(selected, i));
720 g_list_foreach(selected,
721 (GFunc) &gtk_tree_path_free,
722 NULL);
723 g_list_free(selected);
724 for (i=0;i<size;i++) {
725 path = gtk_tree_row_reference_get_path(refs[i]);
726 gtk_tree_row_reference_free(refs[i]);
727 if (TRUE == gtk_tree_model_get_iter(model,
728 &iter,
729 path))
730 func(model,
731 path,
732 &iter,
733 data);
734 gtk_tree_path_free(path);
735 }
736 GROW(refs,
737 size,
738 0);
739}
740
741/* end of helper.c */ 607/* end of helper.c */
diff --git a/src/common/iterators.c b/src/common/iterators.c
new file mode 100644
index 00000000..36fe7dba
--- /dev/null
+++ b/src/common/iterators.c
@@ -0,0 +1,74 @@
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/iterators.c
22 * @brief This file contains GTK helper functions related to iterations
23 * @author Igor Wronsky
24 * @author Christian Grothoff
25 */
26
27/**
28 * Identical to "gtk_tree_selection_selected_foreach",
29 * except that modifications of the underlying model
30 * during the iteration are tolerated.
31 */
32void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection,
33 GtkTreeSelectionForeachFunc func,
34 gpointer data) {
35 unsigned int i;
36 unsigned int size;
37 GList * selected;
38 GtkTreeRowReference ** refs;
39 GtkTreeModel * model;
40 GtkTreePath * path;
41 GtkTreeIter iter;
42
43 selected = gtk_tree_selection_get_selected_rows(selection,
44 &model);
45
46 i = g_list_length(selected);
47 size = 0;
48 refs = NULL;
49 GROW(refs,
50 size,
51 i);
52 for (i=0;i<size;i++)
53 refs[i] = gtk_tree_row_reference_new(model,
54 g_list_nth_data(selected, i));
55 g_list_foreach(selected,
56 (GFunc) &gtk_tree_path_free,
57 NULL);
58 g_list_free(selected);
59 for (i=0;i<size;i++) {
60 path = gtk_tree_row_reference_get_path(refs[i]);
61 gtk_tree_row_reference_free(refs[i]);
62 if (TRUE == gtk_tree_model_get_iter(model,
63 &iter,
64 path))
65 func(model,
66 path,
67 &iter,
68 data);
69 gtk_tree_path_free(path);
70 }
71 GROW(refs,
72 size,
73 0);
74}
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