[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r30409 - in gnunet-gtk: . contrib src src/main src/statisti
From: |
gnunet |
Subject: |
[GNUnet-SVN] r30409 - in gnunet-gtk: . contrib src src/main src/statistics |
Date: |
Fri, 25 Oct 2013 16:33:37 +0200 |
Author: grothoff
Date: 2013-10-25 16:33:37 +0200 (Fri, 25 Oct 2013)
New Revision: 30409
Added:
gnunet-gtk/contrib/gnunet_gtk.glade
gnunet-gtk/src/main/
gnunet-gtk/src/main/Makefile.am
gnunet-gtk/src/main/gnunet-gtk.c
Modified:
gnunet-gtk/configure.ac
gnunet-gtk/contrib/Makefile.am
gnunet-gtk/src/Makefile.am
gnunet-gtk/src/statistics/gnunet-statistics-gtk.c
Log:
-basics for pluggable GUIs
Modified: gnunet-gtk/configure.ac
===================================================================
--- gnunet-gtk/configure.ac 2013-10-25 13:00:24 UTC (rev 30408)
+++ gnunet-gtk/configure.ac 2013-10-25 14:33:37 UTC (rev 30409)
@@ -514,6 +514,7 @@
src/fs/gnunet-fs-gtk.conf
src/identity/Makefile
src/peerinfo/Makefile
+src/main/Makefile
src/namestore/Makefile
src/setup/Makefile
src/statistics/Makefile
Modified: gnunet-gtk/contrib/Makefile.am
===================================================================
--- gnunet-gtk/contrib/Makefile.am 2013-10-25 13:00:24 UTC (rev 30408)
+++ gnunet-gtk/contrib/Makefile.am 2013-10-25 14:33:37 UTC (rev 30409)
@@ -27,6 +27,7 @@
red.png \
green.png \
searching_sources.gif \
+ gnunet_gtk.glade \
gnunet_fs_gtk_about_window.glade \
gnunet_fs_gtk_download_as_dialog.glade \
gnunet_fs_gtk_main_window.glade \
Added: gnunet-gtk/contrib/gnunet_gtk.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_gtk.glade (rev 0)
+++ gnunet-gtk/contrib/gnunet_gtk.glade 2013-10-25 14:33:37 UTC (rev 30409)
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="2.24"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkWindow" id="gnunet_gtk_window">
+ <property name="can_focus">False</property>
+ <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK |
GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK |
GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK |
GDK_SCROLL_MASK</property>
+ <property name="title" translatable="yes">gnunet-gtk</property>
+ <signal name="delete-event" handler="gnunet_gtk_quit_cb" swapped="no"/>
+ <child>
+ <object class="GtkNotebook" id="notebook1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK |
GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK |
GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK |
GDK_SCROLL_MASK</property>
+ <child>
+ <object class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="events">GDK_EXPOSURE_MASK |
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK
| GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK |
GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK |
GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">page 1</property>
+ </object>
+ <packing>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFontButton" id="fontbutton1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">page 2</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-missing-image</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">page 3</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
Modified: gnunet-gtk/src/Makefile.am
===================================================================
--- gnunet-gtk/src/Makefile.am 2013-10-25 13:00:24 UTC (rev 30408)
+++ gnunet-gtk/src/Makefile.am 2013-10-25 14:33:37 UTC (rev 30409)
@@ -1 +1 @@
-SUBDIRS = . include lib $(GNUNET_FS_APP) $(GNUNET_SETUP_APP)
$(GNUNET_PEERINFO_APP) statistics identity namestore
+SUBDIRS = . include lib $(GNUNET_FS_APP) $(GNUNET_SETUP_APP)
$(GNUNET_PEERINFO_APP) statistics identity namestore main
Added: gnunet-gtk/src/main/Makefile.am
===================================================================
--- gnunet-gtk/src/main/Makefile.am (rev 0)
+++ gnunet-gtk/src/main/Makefile.am 2013-10-25 14:33:37 UTC (rev 30409)
@@ -0,0 +1,23 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/ \
+ -I$(top_srcdir)/src/include
+
+bin_PROGRAMS = gnunet-gtk
+
+gnunet_gtk_SOURCES = \
+ gnunet-gtk.c
+
+gnunet_gtk_LDADD = \
+ $(top_builddir)/src/lib/libgnunetgtk.la \
+ @GTK_LIBS@ @GNUNET_LIBS@ @GLADE_LIBS@ \
+ $(WINLIBS) \
+ -lgnunetutil \
+ $(INTLLIBS)
+gnunet_gtk_CFLAGS = \
+ @GTK_CFLAGS@ \
+ @GNUNET_CFLAGS@ \
+ @GLADE_CFLAGS@
+gnunet_gtk_LDFLAGS = \
+ -export-dynamic
Added: gnunet-gtk/src/main/gnunet-gtk.c
===================================================================
--- gnunet-gtk/src/main/gnunet-gtk.c (rev 0)
+++ gnunet-gtk/src/main/gnunet-gtk.c 2013-10-25 14:33:37 UTC (rev 30409)
@@ -0,0 +1,278 @@
+/*
+ This file is part of GNUnet
+ (C) 2012, 2013 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 3, 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/main/gnunet-gtk.c
+ * @author Christian Grothoff
+ * @brief Gtk user interface for GNUnet
+ */
+#include "gnunet_gtk.h"
+#include <gtk/gtkx.h>
+
+/**
+ * Main loop handle.
+ */
+static struct GNUNET_GTK_MainLoop *ml;
+
+/**
+ * Our configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Global return value (for success/failure of gnunet-gtk).
+ */
+static int gret;
+
+
+/**
+ * Get an object from the main window.
+ *
+ * @param name name of the object
+ * @return NULL on error, otherwise the object
+ */
+static GObject *
+get_object (const char *name)
+{
+ if (NULL == ml)
+ return NULL;
+ return GNUNET_GTK_main_loop_get_object (ml, name);
+}
+
+
+/**
+ * Actual main to tear down the system.
+ *
+ * @param cls the main loop handle
+ * @param tc scheduler context
+ */
+static void
+cleanup_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (NULL == ml)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_GTK_main_loop_quit (ml);
+}
+
+
+/**
+ * Callback invoked if the application is supposed to exit.
+ */
+void
+gnunet_gtk_quit_cb (GObject * object,
+ gpointer user_data)
+{
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Handle for a plugged in process.
+ */
+struct Plug
+{
+ /**
+ * The socket.
+ */
+ GtkWidget *s;
+
+ /**
+ * Name of the binary.
+ */
+ const char *binary;
+
+ /**
+ * Environment variable we set.
+ */
+ const char *env_var;
+
+ /**
+ * Handle to the child process.
+ */
+ struct GNUNET_OS_Process *proc;
+};
+
+
+/**
+ * Start the child process for the plug.
+ *
+ * @param p plug identification
+ */
+static void
+start_process (struct Plug *p)
+{
+ char window_id[128];
+ Window w;
+
+ w = gtk_socket_get_id (GTK_SOCKET (p->s));
+ GNUNET_snprintf (window_id,
+ sizeof (window_id),
+ "%llu",
+ (unsigned long long) w);
+ setenv (p->env_var, window_id, 1);
+ p->proc = GNUNET_OS_start_process (GNUNET_NO,
+ GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL,
+ p->binary,
+ p->binary,
+ NULL);
+}
+
+
+/**
+ * The window got detached, restart the child.
+ *
+ * @param sock socket the plug got detached from
+ * @param userdata our `struct Plug *`
+ * @return TRUE (keep socket open)
+ */
+static gboolean
+handle_remove (GtkSocket *sock,
+ gpointer userdata)
+{
+ struct Plug *p = userdata;
+
+ (void) GNUNET_OS_process_kill (p->proc, SIGTERM);
+ GNUNET_OS_process_destroy (p->proc);
+ p->proc = NULL;
+ start_process (p);
+ return TRUE;
+}
+
+
+/**
+ * The socket widget is being deleted, clean up child process.
+ *
+ * @param sock the widget
+ * @param userdata our `struct Plug *`
+ * @return FALSE (continue event processing)
+ */
+static gboolean
+handle_delete (GtkSocket *sock,
+ gpointer userdata)
+{
+ struct Plug *p = userdata;
+
+ (void) GNUNET_OS_process_kill (p->proc, SIGTERM);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_OS_process_wait (p->proc));
+ GNUNET_OS_process_destroy (p->proc);
+ p->proc = NULL;
+ GNUNET_free (p);
+ return FALSE;
+}
+
+
+/**
+ * Embed process in our GUI.
+ *
+ * @param container where to embed
+ * @param binary name of the binary to embed
+ * @param env_var name of the environment variable to set
+ */
+static void
+plug (const char *container,
+ const char *binary,
+ const char *env_var)
+{
+ GtkContainer *v;
+ struct Plug *p;
+
+ p = GNUNET_new (struct Plug);
+ p->s = gtk_socket_new ();
+ gtk_widget_set_events (p->s,
+ GDK_ALL_EVENTS_MASK);
+ v = GTK_CONTAINER (get_object (container));
+ gtk_container_add (v, p->s);
+ p->binary = binary;
+ p->env_var = env_var;
+ g_signal_connect (p->s,
+ "plug-removed",
+ G_CALLBACK (handle_remove),
+ p);
+ g_signal_connect (p->s,
+ "delete-event",
+ G_CALLBACK (handle_delete),
+ p);
+ start_process (p);
+ gtk_widget_show (p->s);
+}
+
+
+/**
+ * Actual main method that sets up the configuration window.
+ *
+ * @param cls the main loop handle
+ * @param tc scheduler context
+ */
+static void
+run (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GtkWidget *main_window;
+
+ ml = cls;
+ cfg = GNUNET_GTK_main_loop_get_configuration (ml);
+ if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
+ return;
+ main_window = GTK_WIDGET (get_object ("gnunet_gtk_window"));
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &cleanup_task, NULL);
+ plug ("hbox1",
+ "gnunet-statistics-gtk",
+ "GNUNET_STATISTICS_GTK_PLUG");
+ gtk_widget_show (main_window);
+ gtk_window_present (GTK_WINDOW (main_window));
+}
+
+
+/**
+ * Main function for gnunet-gtk.
+ *
+ * @param argc number of arguments
+ * @param argv arguments
+ * @return 0 on success
+ */
+int
+main (int argc, char *const *argv)
+{
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ int ret;
+
+ if (GNUNET_OK ==
+ GNUNET_GTK_main_loop_start ("gnunet-gtk",
+ "gnunet-gtk", argc, argv,
+ options, "gnunet_gtk.glade",
+ &run))
+ ret = gret;
+ else
+ ret = 1;
+ return ret;
+}
+
+
+
+/* end of gnunet-gtk.c */
Modified: gnunet-gtk/src/statistics/gnunet-statistics-gtk.c
===================================================================
--- gnunet-gtk/src/statistics/gnunet-statistics-gtk.c 2013-10-25 13:00:24 UTC
(rev 30408)
+++ gnunet-gtk/src/statistics/gnunet-statistics-gtk.c 2013-10-25 14:33:37 UTC
(rev 30409)
@@ -30,6 +30,8 @@
#include <cairo.h>
#include "gtk_statistics.h"
+#include <gtk/gtkx.h>
+
#define MAX_HISTORY 1280
@@ -239,6 +241,7 @@
run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GtkWidget *main_window;
+ char *plugid;
ml = cls;
@@ -261,6 +264,24 @@
/* setup main window */
main_window = GTK_WIDGET (get_object ("GNUNET_STATISTICS_GTK_main_window"));
+ if (NULL != (plugid = getenv ("GNUNET_STATISTICS_GTK_PLUG")))
+ {
+ GtkWidget *plug;
+ GtkWidget *child;
+ unsigned long long id;
+
+ if (1 == sscanf (plugid,
+ "%llu",
+ &id))
+ {
+ plug = gtk_plug_new ((Window) id);
+ child = gtk_bin_get_child (GTK_BIN (main_window));
+ gtk_widget_reparent (child,
+ plug);
+ gtk_widget_destroy (main_window);
+ main_window = plug;
+ }
+ }
gtk_window_maximize (GTK_WINDOW (main_window));
GNUNET_GTK_tray_icon_create (ml,
GTK_WINDOW (main_window),
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r30409 - in gnunet-gtk: . contrib src src/main src/statistics,
gnunet <=