[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3833 - gnunet-gtk/src/common
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3833 - gnunet-gtk/src/common |
Date: |
Thu, 30 Nov 2006 08:27:38 -0800 (PST) |
Author: grothoff
Date: 2006-11-30 08:27:35 -0800 (Thu, 30 Nov 2006)
New Revision: 3833
Added:
gnunet-gtk/src/common/iterators.c
gnunet-gtk/src/common/logging.c
Modified:
gnunet-gtk/src/common/Makefile.am
gnunet-gtk/src/common/helper.c
Log:
refact
Modified: gnunet-gtk/src/common/Makefile.am
===================================================================
--- gnunet-gtk/src/common/Makefile.am 2006-11-30 15:45:37 UTC (rev 3832)
+++ gnunet-gtk/src/common/Makefile.am 2006-11-30 16:27:35 UTC (rev 3833)
@@ -9,7 +9,9 @@
libgnunetgtk_common.la
libgnunetgtk_common_la_SOURCES = \
- helper.c
+ helper.c \
+ iterators.c \
+ logging.c
libgnunetgtk_common_la_LDFLAGS = \
-export-dynamic $(LIBLTDL) $(LIBS) \
Modified: gnunet-gtk/src/common/helper.c
===================================================================
--- gnunet-gtk/src/common/helper.c 2006-11-30 15:45:37 UTC (rev 3832)
+++ gnunet-gtk/src/common/helper.c 2006-11-30 16:27:35 UTC (rev 3833)
@@ -89,11 +89,6 @@
static struct GC_Configuration * cfg;
-#ifdef WINDOWS
-static void CALLBACK sigalrmHandler(DWORD sig) {
-}
-#endif
-
static gboolean saveCallWrapper(gpointer data) {
SaveCall * call = data;
int i;
@@ -155,94 +150,6 @@
}
/**
- * Closure for doInfoMessage.
- */
-typedef struct {
- int doPopup;
- char * note;
-} InfoMessage;
-
-/**
- * Callback for infoMessage()
- */
-static void * doInfoMessage(void * args) {
- const InfoMessage * info = args;
- GtkTextIter iter;
- GtkTextBuffer * buffer;
-
- if (info->doPopup==YES)
- gtk_widget_show(infoWindow);
- buffer
- = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoWindowTextView));
- gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
- gtk_text_buffer_insert(buffer,
- &iter,
- info->note,
- -1);
- return NULL;
-}
-
-/**
- * Appends a message to the info window
- *
- * @param doPopup do we open the window, YES or NO
- */
-void infoMessage(int doPopup,
- const char * format,
- ...) {
- va_list args;
- InfoMessage info;
-
- va_start(args, format);
- info.note = g_strdup_vprintf(format, args);
- va_end(args);
- info.doPopup = doPopup;
- gtkSaveCall(&doInfoMessage,
- &info);
- g_free(info.note);
-}
-
-static void * saveAddLogEntry(void * args) {
- static GtkWidget * s = NULL;
- static int once = 1;
- static guint id;
-
- if (once) {
- once = 0;
- s = glade_xml_get_widget(mainXML,
- "statusbar");
- id = gtk_statusbar_get_context_id(GTK_STATUSBAR(s),
- "LOG");
- } else
- gtk_statusbar_pop(GTK_STATUSBAR(s),
- id);
- gtk_statusbar_push(GTK_STATUSBAR(s),
- id,
- (const char*) args);
- return NULL;
-}
-
-/**
- * Appends a log entry to the info window
- *
- * @param txt the log entry
- *
- */
-void addLogEntry(const char * txt,
- ...) {
- va_list args;
- gchar * note;
-
- va_start(args, txt);
- note = g_strdup_vprintf(txt, args);
- va_end(args);
- infoMessage(NO, note);
- gtkSaveCall(&saveAddLogEntry,
- (void*) note);
- g_free(note);
-}
-
-/**
* Simple accessor method.
*/
const char * getGladeFileName() {
@@ -653,89 +560,48 @@
* Start gnunet-setup, asking for a password if needed
*/
gboolean startGNUnetSetup (gboolean run_wizard) {
+ GtkWidget * mainWindow;
+ GtkWidget * messageDialog;
int code;
char *error_message;
#ifdef WITH_LIBGKSU2
GError *gerror = NULL;
if(run_wizard) {
- code = gksu_run("gnunet-setup -d wizard-gtk", &gerror); }
- else {
- code = gksu_run("gnunet-setup -d", &gerror); }
- if(code && !gerror) {
- error_message = STRDUP(_("GKSu encountered an unknown error running the
configuration tool (gnunet-setup).")); }
- else if(code && gerror) {
- error_message = g_strdup_printf(_("GKSu returned:\n%s"), gerror->message);
- g_error_free(gerror); }
- else {
- error_message = NULL; }
+ code = gksu_run("gnunet-setup -d wizard-gtk",
+ &gerror);
+ } else {
+ code = gksu_run("gnunet-setup -d",
+ &gerror);
+ }
+ if (code && !gerror) {
+ error_message = STRDUP(_("GKSu encountered an unknown error running the
configuration tool (gnunet-setup)."));
+ } else if (code && gerror) {
+ error_message = g_strdup_printf(_("GKSu returned:\n%s"),
+ gerror->message);
+ g_error_free(gerror);
+ } else {
+ error_message = NULL;
+ }
#elif defined(WINDOWS)
/* FIXME: run gnunet-setup, assuming we can get the needed rights */
- error_message = STRDUP("Not implemented yet !");
- return TRUE;
+ error_message = STRDUP(_("Not implemented yet!"));
+ code = TRUE;
#else
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."));
- return TRUE;
+ code = TRUE;
#endif
- GtkWidget *mainWindow, *messageDialog;
- mainWindow = glade_xml_get_widget(getMainXML(), "mainWindow");
- messageDialog = gtk_message_dialog_new (GTK_WINDOW(mainWindow),
- GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE,
- _("Failed to run the configuration
tool (gnunet-setup): %s"),
- error_message);
+ mainWindow = glade_xml_get_widget(getMainXML(),
+ "mainWindow");
+ messageDialog = gtk_message_dialog_new(GTK_WINDOW(mainWindow),
+ GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_CLOSE,
+ _("Failed to run the configuration
tool (gnunet-setup): %s"),
+ error_message);
gtk_dialog_run(GTK_DIALOG(messageDialog));
- gtk_widget_destroy (messageDialog);
+ gtk_widget_destroy(messageDialog);
FREE(error_message);
return code;
}
-/**
- * Identical to "gtk_tree_selection_selected_foreach",
- * except that modifications of the underlying model
- * during the iteration are tolerated.
- */
-void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection,
- GtkTreeSelectionForeachFunc func,
- gpointer data) {
- unsigned int i;
- unsigned int size;
- GList * selected;
- GtkTreeRowReference ** refs;
- GtkTreeModel * model;
- GtkTreePath * path;
- GtkTreeIter iter;
-
- selected = gtk_tree_selection_get_selected_rows(selection,
- &model);
-
- i = g_list_length(selected);
- size = 0;
- refs = NULL;
- GROW(refs,
- size,
- i);
- for (i=0;i<size;i++)
- refs[i] = gtk_tree_row_reference_new(model,
- g_list_nth_data(selected, i));
- g_list_foreach(selected,
- (GFunc) >k_tree_path_free,
- NULL);
- g_list_free(selected);
- for (i=0;i<size;i++) {
- path = gtk_tree_row_reference_get_path(refs[i]);
- gtk_tree_row_reference_free(refs[i]);
- if (TRUE == gtk_tree_model_get_iter(model,
- &iter,
- path))
- func(model,
- path,
- &iter,
- data);
- gtk_tree_path_free(path);
- }
- GROW(refs,
- size,
- 0);
-}
-
/* end of helper.c */
Added: gnunet-gtk/src/common/iterators.c
===================================================================
--- gnunet-gtk/src/common/iterators.c 2006-11-30 15:45:37 UTC (rev 3832)
+++ gnunet-gtk/src/common/iterators.c 2006-11-30 16:27:35 UTC (rev 3833)
@@ -0,0 +1,74 @@
+/*
+ This file is part of GNUnet
+ (C) 2006 Christian Grothoff (and other contributing authors)
+
+ GNUnet 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, or (at your
+ option) any later version.
+
+ GNUnet 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 GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file src/common/iterators.c
+ * @brief This file contains GTK helper functions related to iterations
+ * @author Igor Wronsky
+ * @author Christian Grothoff
+ */
+
+/**
+ * Identical to "gtk_tree_selection_selected_foreach",
+ * except that modifications of the underlying model
+ * during the iteration are tolerated.
+ */
+void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection,
+ GtkTreeSelectionForeachFunc func,
+ gpointer data) {
+ unsigned int i;
+ unsigned int size;
+ GList * selected;
+ GtkTreeRowReference ** refs;
+ GtkTreeModel * model;
+ GtkTreePath * path;
+ GtkTreeIter iter;
+
+ selected = gtk_tree_selection_get_selected_rows(selection,
+ &model);
+
+ i = g_list_length(selected);
+ size = 0;
+ refs = NULL;
+ GROW(refs,
+ size,
+ i);
+ for (i=0;i<size;i++)
+ refs[i] = gtk_tree_row_reference_new(model,
+ g_list_nth_data(selected, i));
+ g_list_foreach(selected,
+ (GFunc) >k_tree_path_free,
+ NULL);
+ g_list_free(selected);
+ for (i=0;i<size;i++) {
+ path = gtk_tree_row_reference_get_path(refs[i]);
+ gtk_tree_row_reference_free(refs[i]);
+ if (TRUE == gtk_tree_model_get_iter(model,
+ &iter,
+ path))
+ func(model,
+ path,
+ &iter,
+ data);
+ gtk_tree_path_free(path);
+ }
+ GROW(refs,
+ size,
+ 0);
+}
Added: gnunet-gtk/src/common/logging.c
===================================================================
--- gnunet-gtk/src/common/logging.c 2006-11-30 15:45:37 UTC (rev 3832)
+++ gnunet-gtk/src/common/logging.c 2006-11-30 16:27:35 UTC (rev 3833)
@@ -0,0 +1,120 @@
+/*
+ This file is part of GNUnet
+ (C) 2006 Christian Grothoff (and other contributing authors)
+
+ GNUnet 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, or (at your
+ option) any later version.
+
+ GNUnet 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 GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file src/common/logging.c
+ * @brief This file contains GUI functions related to logging
+ * @author Igor Wronsky
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunetgtk_common.h"
+#include <GNUnet/gnunet_util_crypto.h>
+#include <glib.h>
+#include <gmodule.h>
+
+/**
+ * Closure for doInfoMessage.
+ */
+typedef struct {
+ int doPopup;
+ char * note;
+} InfoMessage;
+
+/**
+ * Callback for infoMessage()
+ */
+static void * doInfoMessage(void * args) {
+ const InfoMessage * info = args;
+ GtkTextIter iter;
+ GtkTextBuffer * buffer;
+
+ if (info->doPopup==YES)
+ gtk_widget_show(infoWindow);
+ buffer
+ = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoWindowTextView));
+ gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
+ gtk_text_buffer_insert(buffer,
+ &iter,
+ info->note,
+ -1);
+ return NULL;
+}
+
+/**
+ * Appends a message to the info window
+ *
+ * @param doPopup do we open the window, YES or NO
+ */
+void infoMessage(int doPopup,
+ const char * format,
+ ...) {
+ va_list args;
+ InfoMessage info;
+
+ va_start(args, format);
+ info.note = g_strdup_vprintf(format, args);
+ va_end(args);
+ info.doPopup = doPopup;
+ gtkSaveCall(&doInfoMessage,
+ &info);
+ g_free(info.note);
+}
+
+static void * saveAddLogEntry(void * args) {
+ static GtkWidget * s = NULL;
+ static int once = 1;
+ static guint id;
+
+ if (once) {
+ once = 0;
+ s = glade_xml_get_widget(mainXML,
+ "statusbar");
+ id = gtk_statusbar_get_context_id(GTK_STATUSBAR(s),
+ "LOG");
+ } else
+ gtk_statusbar_pop(GTK_STATUSBAR(s),
+ id);
+ gtk_statusbar_push(GTK_STATUSBAR(s),
+ id,
+ (const char*) args);
+ return NULL;
+}
+
+/**
+ * Appends a log entry to the info window
+ *
+ * @param txt the log entry
+ *
+ */
+void addLogEntry(const char * txt,
+ ...) {
+ va_list args;
+ gchar * note;
+
+ va_start(args, txt);
+ note = g_strdup_vprintf(txt, args);
+ va_end(args);
+ infoMessage(NO, note);
+ gtkSaveCall(&saveAddLogEntry,
+ (void*) note);
+ g_free(note);
+}
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3833 - gnunet-gtk/src/common,
grothoff <=