gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r1280 - in gnunet-gtk/src: common core include plugins/fs


From: grothoff
Subject: [GNUnet-SVN] r1280 - in gnunet-gtk/src: common core include plugins/fs
Date: Tue, 5 Jul 2005 15:36:40 -0700 (PDT)

Author: grothoff
Date: 2005-07-05 15:36:34 -0700 (Tue, 05 Jul 2005)
New Revision: 1280

Modified:
   gnunet-gtk/src/common/helper.c
   gnunet-gtk/src/core/main.c
   gnunet-gtk/src/include/gnunetgtk_common.h
   gnunet-gtk/src/plugins/fs/search.c
   gnunet-gtk/src/plugins/fs/upload.c
Log:
proper signal connect code, more use of glade

Modified: gnunet-gtk/src/common/helper.c
===================================================================
--- gnunet-gtk/src/common/helper.c      2005-07-05 22:26:19 UTC (rev 1279)
+++ gnunet-gtk/src/common/helper.c      2005-07-05 22:36:34 UTC (rev 1280)
@@ -29,25 +29,33 @@
 
 #define HELPER_DEBUG NO
 
+typedef struct {
+  Semaphore * sem;
+  void * args;
+  SimpleCallback func;
+} SaveCall;
+
+typedef struct Plugin {
+  struct Plugin * next;
+  char * name;
+  void * library;
+} Plugin;
+
 static GladeXML * mainXML;
 
 static char * gladeFile;
 
+static GladeXML * statusXML;
+
 static GtkWidget * infoWindow;
 
-static GtkWidget * infoText;
+static GtkWidget * infoWindowTextView;
 
 /**
  * the main thread 
  */
 static PTHREAD_T mainThread;
 
-typedef struct {
-  Semaphore * sem;
-  void * args;
-  SimpleCallback func;
-} SaveCall;
-
 static SaveCall ** psc;
 
 static unsigned int pscCount;
@@ -56,6 +64,9 @@
 
 static int saveCallsUp;
 
+static Plugin * plugin;
+
+
 static gboolean saveCallWrapper(gpointer data) {
   SaveCall * call = data;
 
@@ -138,19 +149,12 @@
 /**
  * Callback for handling "delete_event": close the window 
  */
-static gint 
-deleteEvent(GtkWidget * widget,
-           GdkEvent * event,
-           gpointer data) {
+gint on_statusWindow_delete_event(GtkWidget * widget,
+                            GdkEvent * event,
+                            gpointer data) {
   return FALSE;
 }
 
-static void hideWindow(GtkWidget * widget,
-                      gpointer data) {
-  if (widget != NULL)
-    gtk_widget_hide(widget);
-}
-
 /**
  * Closure for doInfoMessage.
  */
@@ -161,84 +165,16 @@
 
 /**
  * Callback for infoMessage()
- *
- * FIXME: use GLADE (or direct GTK functionality) here!
  */
 static void doInfoMessage(void * args) {
   const InfoMessage * info = args;
   GtkTextIter iter;
   GtkTextBuffer * buffer;
 
-  if (! infoWindow) {
-    GtkWidget * box1;
-    GtkWidget * button;
-    GtkWidget * scrolled_window;
-
-    infoWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-    gtk_signal_connect(GTK_OBJECT(infoWindow),
-                       "delete_event",
-                       GTK_SIGNAL_FUNC(deleteEvent),
-                       NULL);
-
-    gtk_window_set_title(GTK_WINDOW(infoWindow),
-                         _("Messages"));
-    gtk_widget_set_usize(GTK_WIDGET(infoWindow),
-                         780,
-                         300);
-
-    box1 = gtk_vbox_new(FALSE, 0);
-    gtk_container_add(GTK_CONTAINER (infoWindow),
-                      box1);
-    gtk_widget_show(box1);
-    
-    /* create a scrollable window */
-    scrolled_window = gtk_scrolled_window_new(NULL, NULL);
-    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
-                                  GTK_POLICY_AUTOMATIC,
-                                  GTK_POLICY_ALWAYS);
-    gtk_box_pack_start(GTK_BOX(box1),
-                      scrolled_window,
-                      TRUE,
-                      TRUE,
-                      0);
-    gtk_widget_show(scrolled_window);
-
-    /* create a text widget */
-    infoText = gtk_text_view_new();
-    
-    gtk_text_view_set_editable(GTK_TEXT_VIEW (infoText),
-                              FALSE);
-    gtk_container_add(GTK_CONTAINER(scrolled_window),
-                     infoText);
-    gtk_widget_show(infoText);
-    gtk_widget_realize(infoText);
-  
-    /* finish with a close button */
-    button = gtk_button_new_with_label(_("Close"));
-    gtk_box_pack_start(GTK_BOX (box1),
-                       button,
-                       FALSE,
-                       FALSE,
-                       0);
-    gtk_signal_connect_object(GTK_OBJECT(button),
-                              "clicked",
-                              GTK_SIGNAL_FUNC(hideWindow),
-                              GTK_OBJECT(infoWindow));
-    gtk_signal_connect_object(GTK_OBJECT(infoWindow), 
-                             "delete_event",
-                              GTK_SIGNAL_FUNC(hideWindow),
-                              GTK_OBJECT(infoWindow));
-    gtk_signal_connect_object(GTK_OBJECT(infoWindow), 
-                             "destroy",
-                              GTK_SIGNAL_FUNC(hideWindow),
-                              GTK_OBJECT(infoWindow));
-    gtk_widget_show(button);
-  }
   if (info->doPopup==YES)
     gtk_widget_show(infoWindow);
-
-  /* append the text */
-  buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoText));
+  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,
@@ -311,7 +247,120 @@
   return mainXML;
 }
 
+static void connector(const gchar *handler_name,
+                     GObject *object,
+                     const gchar *signal_name,
+                     const gchar *signal_data,
+                     GObject *connect_object,
+                     gboolean after,
+                     gpointer user_data) {
+  Plugin * plug = user_data;
+  void * method;
+
+  while (plug != NULL) {
+    method = trybindDynamicMethod(plug->library,
+                                 "",
+                                 handler_name);
+    if (method != NULL)
+      break;
+    plug = plug->next;
+  }
+  if (method == NULL) {
+    LOG(LOG_DEBUG,
+       _("Failed to find handler for '%s'\n"),
+       handler_name);
+    return;
+  }
+  glade_xml_signal_connect(getMainXML(),
+                          handler_name,
+                          (GCallback) method);
+}
+
+void connectGladeWithPlugins(GladeXML * xml) {
+  glade_xml_signal_autoconnect_full(xml,
+                                   &connector, plugin);
+}
+
+typedef void (*PlainCall)();
+
+static Plugin * loadPlugin(const char * name,
+                          Plugin * next) {
+  Plugin * p;
+  void * lib;
+  PlainCall init;
+
+  lib = loadDynamicLibrary("libgnunetgtkmodule_",
+                          name);
+  if (lib == NULL) {
+    LOG(LOG_WARNING,
+       _("Failed to load plugin '%s'\n"),
+       name);
+    return next;
+  }
+  p = MALLOC(sizeof(Plugin));
+  p->name = STRDUP(name);
+  p->next = next;
+  p->library = lib;
+  init = trybindDynamicMethod(lib,
+                             "init_",
+                             name);
+  if (init != NULL)
+    init();
+
+  return p;
+}
+
+static Plugin * loadPlugins(const char * names,
+                           Plugin * plug) {
+  char * dup;
+  char * next;
+  const char * pos;
+
+  if (names == NULL)
+    return plug;
+
+  dup = STRDUP(names);
+  next = dup;
+  do {
+    while (*next == ' ')
+      next++;
+    pos = next;
+    while ( (*next != '\0') &&
+           (*next != ' ') )
+      next++;
+    if (*next == '\0') {
+      next = NULL; /* terminate! */
+    } else {
+      *next = '\0'; /* add 0-termination for pos */
+      next++;
+    }
+    if (strlen(pos) > 0) {
+      LOG(LOG_DEBUG,
+         "Loading plugin '%s'\n",
+         pos);
+      plug = loadPlugin(pos, plug);
+    }
+  } while (next != NULL);
+  FREE(dup);
+  return plug;
+}
+
+static void unloadPlugin(Plugin * plug) {
+  PlainCall done;
+
+  done = trybindDynamicMethod(plug->library,
+                             "done_",
+                             plug->name);
+  if (done != NULL)
+    done();
+  unloadDynamicLibrary(plug->library);
+  FREE(plug->name);
+  FREE(plug);
+}
+
 void initGNUnetGTKCommon() {
+  char * load;
+
   MUTEX_CREATE_RECURSIVE(&sclock);
   PTHREAD_GET_SELF(&mainThread);
   saveCallsUp = YES;
@@ -319,7 +368,8 @@
   /* load the interface */
 #ifdef MINGW
   gladeFile = MALLOC(_MAX_PATH + 1);
-  plibc_conv_to_win_path(PACKAGE_DATA_DIR"/gnunet-gtk.glade", gladeFile);
+  plibc_conv_to_win_path(PACKAGE_DATA_DIR"/gnunet-gtk.glade",
+                        gladeFile);
 #else
   gladeFile = STRDUP(PACKAGE_DATA_DIR"/gnunet-gtk.glade");
 #endif
@@ -327,11 +377,43 @@
   mainXML = glade_xml_new(gladeFile,
                          "mainWindow",
                          NULL);
+  statusXML
+    = glade_xml_new(getGladeFileName(),
+                   "statusWindow", 
+                   NULL);
+  infoWindow
+    = glade_xml_get_widget(statusXML,
+                          "statusWindow");
+  infoWindowTextView
+    = glade_xml_get_widget(statusXML,
+                          "messageWindowTextView");
+  /* load the plugins */
+  load = getConfigurationString("GNUNET-GTK",
+                               "PLUGINS");
+  if (load == NULL)
+    load = STRDUP("about daemon fs");
+  plugin = loadPlugins(load, NULL);
+  FREE(load);
+
+  connectGladeWithPlugins(mainXML);
+  connectGladeWithPlugins(statusXML);
 }
 
 void doneGNUnetGTKCommon() {
   int i;
 
+  /* unload the plugins */
+  while (plugin != NULL) {
+    Plugin * next;
+
+    next = plugin->next;
+    unloadPlugin(plugin);
+    plugin = next;
+  }
+ 
+  gtk_widget_destroy(infoWindow);
+  infoWindow = NULL;
+  UNREF(statusXML);
   UNREF(mainXML);
   mainXML = NULL;
   FREE(gladeFile);
@@ -354,7 +436,6 @@
     MUTEX_UNLOCK(&sclock);
   }
   MUTEX_DESTROY(&sclock);
-
 }
 
 /* end of helper.c */

Modified: gnunet-gtk/src/core/main.c
===================================================================
--- gnunet-gtk/src/core/main.c  2005-07-05 22:26:19 UTC (rev 1279)
+++ gnunet-gtk/src/core/main.c  2005-07-05 22:36:34 UTC (rev 1280)
@@ -88,122 +88,8 @@
   return OK;
 }
 
-typedef struct Plugin {
-  struct Plugin * next;
-  char * name;
-  void * library;
-} Plugin;
-
-static void connector(const gchar *handler_name,
-                     GObject *object,
-                     const gchar *signal_name,
-                     const gchar *signal_data,
-                     GObject *connect_object,
-                     gboolean after,
-                     gpointer user_data) {
-  Plugin * plug = user_data;
-  void * method;
-
-  while (plug != NULL) {
-    method = trybindDynamicMethod(plug->library,
-                                 "",
-                                 handler_name);
-    if (method != NULL)
-      break;
-    plug = plug->next;
-  }
-  if (method == NULL) {
-    LOG(LOG_DEBUG,
-       _("Failed to find handler for '%s'\n"),
-       handler_name);
-    return;
-  }
-  glade_xml_signal_connect(getMainXML(),
-                          handler_name,
-                          (GCallback) method);
-}
-
-typedef void (*PlainCall)();
-
-static Plugin * loadPlugin(const char * name,
-                          Plugin * next) {
-  Plugin * p;
-  void * lib;
-  PlainCall init;
-
-  lib = loadDynamicLibrary("libgnunetgtkmodule_",
-                          name);
-  if (lib == NULL) {
-    LOG(LOG_WARNING,
-       _("Failed to load plugin '%s'\n"),
-       name);
-    return next;
-  }
-  p = MALLOC(sizeof(Plugin));
-  p->name = STRDUP(name);
-  p->next = next;
-  p->library = lib;
-  init = trybindDynamicMethod(lib,
-                             "init_",
-                             name);
-  if (init != NULL)
-    init();
-
-  return p;
-}
-
-static Plugin * loadPlugins(const char * names,
-                           Plugin * plug) {
-  char * dup;
-  char * next;
-  const char * pos;
-
-  if (names == NULL)
-    return plug;
-
-  dup = STRDUP(names);
-  next = dup;
-  do {
-    while (*next == ' ')
-      next++;
-    pos = next;
-    while ( (*next != '\0') &&
-           (*next != ' ') )
-      next++;
-    if (*next == '\0') {
-      next = NULL; /* terminate! */
-    } else {
-      *next = '\0'; /* add 0-termination for pos */
-      next++;
-    }
-    if (strlen(pos) > 0) {
-      LOG(LOG_DEBUG,
-         "Loading plugin '%s'\n",
-         pos);
-      plug = loadPlugin(pos, plug);
-    }
-  } while (next != NULL);
-  FREE(dup);
-  return plug;
-}
-
-static void unloadPlugin(Plugin * plug) {
-  PlainCall done;
-
-  done = trybindDynamicMethod(plug->library,
-                             "done_",
-                             plug->name);
-  if (done != NULL)
-    done();
-  unloadDynamicLibrary(plug->library);
-  FREE(plug->name);
-  FREE(plug);
-}
-
 int main(int argc, 
         char *argv[]) {
-  Plugin * plugin;
-  char * load;
   GtkWidget * root;
   
   g_thread_init(NULL);
@@ -217,22 +103,9 @@
   root
     = glade_xml_get_widget(getMainXML(),
                           "mainWindow");
-
-  /* load the plugins */
-  load = getConfigurationString("GNUNET-GTK",
-                               "PLUGINS");
-  if (load == NULL)
-    load = STRDUP("about daemon fs");
-  plugin = loadPlugins(load, NULL);
-  FREE(load);
-                       
   gtk_window_maximize(GTK_WINDOW(root));
   gtk_widget_show(root);
-  /* connect the signals in the interface */
   setCustomLogProc(&addLogEntry);
-  glade_xml_signal_autoconnect_full(getMainXML(),
-                                   &connector, plugin);
-
   /* start the event loop */
   gdk_threads_enter();    
   gtk_main();
@@ -240,15 +113,6 @@
   setCustomLogProc(NULL);
   stopCron();
 
-  /* unload the plugins */
-  while (plugin != NULL) {
-    Plugin * next;
-
-    next = plugin->next;
-    unloadPlugin(plugin);
-    plugin = next;
-  }
- 
   doneGNUnetGTKCommon();
   doneUtil();
   

Modified: gnunet-gtk/src/include/gnunetgtk_common.h
===================================================================
--- gnunet-gtk/src/include/gnunetgtk_common.h   2005-07-05 22:26:19 UTC (rev 
1279)
+++ gnunet-gtk/src/include/gnunetgtk_common.h   2005-07-05 22:36:34 UTC (rev 
1280)
@@ -78,5 +78,12 @@
  * still continue.
  */
 int gtkRunSomeSaveCalls();
+
+/**
+ * Bind handlers defined by the various
+ * plugins to the signals defined by the
+ * Glade XML.
+ */
+void connectGladeWithPlugins(GladeXML * xml);
  
 #endif

Modified: gnunet-gtk/src/plugins/fs/search.c
===================================================================
--- gnunet-gtk/src/plugins/fs/search.c  2005-07-05 22:26:19 UTC (rev 1279)
+++ gnunet-gtk/src/plugins/fs/search.c  2005-07-05 22:36:34 UTC (rev 1280)
@@ -374,7 +374,7 @@
     = glade_xml_new(getGladeFileName(),
                    "searchResultsFrame", 
                    NULL);
-  glade_xml_signal_autoconnect(searchXML);
+  connectGladeWithPlugins(searchXML);
   window = glade_xml_get_widget(searchXML,
                               "searchResultsFrame");
   resultList = glade_xml_get_widget(searchXML,

Modified: gnunet-gtk/src/plugins/fs/upload.c
===================================================================
--- gnunet-gtk/src/plugins/fs/upload.c  2005-07-05 22:26:19 UTC (rev 1279)
+++ gnunet-gtk/src/plugins/fs/upload.c  2005-07-05 22:36:34 UTC (rev 1280)
@@ -415,7 +415,7 @@
     = glade_xml_new(getGladeFileName(),
                    "metaDataDialog",
                    NULL);
-  glade_xml_signal_autoconnect(metaXML);
+  connectGladeWithPlugins(metaXML);
   dialog = glade_xml_get_widget(metaXML,
                                "metaDataDialog");
   metamodel
@@ -684,7 +684,7 @@
     = glade_xml_new(getGladeFileName(),
                    "uploadfilechooserdialog",
                    NULL);
-  glade_xml_signal_autoconnect(uploadXML);
+  connectGladeWithPlugins(uploadXML);
   dialog = glade_xml_get_widget(uploadXML,
                                "uploadfilechooserdialog");
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]