[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26411 - in gnunet-gtk: contrib src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26411 - in gnunet-gtk: contrib src/fs |
Date: |
Wed, 13 Mar 2013 22:44:45 +0100 |
Author: LRN
Date: 2013-03-13 22:44:45 +0100 (Wed, 13 Mar 2013)
New Revision: 26411
Added:
gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-connection.c
Modified:
gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade
gnunet-gtk/src/fs/Makefile.am
gnunet-gtk/src/fs/gnunet-fs-gtk.c
gnunet-gtk/src/fs/gnunet-fs-gtk.h
gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h
Log:
Connection indicator (with a tooltip\!)
Modified: gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade 2013-03-13 21:44:40 UTC
(rev 26410)
+++ gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade 2013-03-13 21:44:45 UTC
(rev 26411)
@@ -214,10 +214,34 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkStatusbar" id="GNUNET_GTK_status_bar">
+ <object class="GtkHBox" id="main_window_bottom_hbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">2</property>
+ <child>
+ <object class="GtkImage"
id="GNUNET_FS_GTK_main_window_connection_indicator">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-no</property>
+ <signal name="button-press-event"
handler="GNUNET_FS_GTK_main_window_connection_indicator_button_press_event_cb"
swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkStatusbar" id="GNUNET_GTK_status_bar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">2</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
Modified: gnunet-gtk/src/fs/Makefile.am
===================================================================
--- gnunet-gtk/src/fs/Makefile.am 2013-03-13 21:44:40 UTC (rev 26410)
+++ gnunet-gtk/src/fs/Makefile.am 2013-03-13 21:44:45 UTC (rev 26411)
@@ -20,6 +20,7 @@
gnunet-fs-gtk_create-pseudonym.c \
gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \
gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \
+ gnunet-fs-gtk_main-window-connection.c \
gnunet-fs-gtk_main-window-meta-data-context-menu.c \
gnunet-fs-gtk_main-window-namespace-dropdown.c \
gnunet-fs-gtk_main-window-search.c \
@@ -40,6 +41,7 @@
@GLADE_LIBS@ @GNUNET_LIBS@ @unique_LIBS@ \
-lextractor \
-lgnunetutil \
+ -lgnunetarm \
-lgnunetfs \
$(INTLLIBS)
gnunet_fs_gtk_LDFLAGS = \
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk.c 2013-03-13 21:44:40 UTC (rev 26410)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk.c 2013-03-13 21:44:45 UTC (rev 26411)
@@ -32,6 +32,8 @@
#include <unique/unique.h>
#endif
+#include <gnunet/gnunet_arm_service.h>
+
/**
* How many block requests can we have outstanding in parallel at a time by
default?
*/
@@ -42,6 +44,7 @@
*/
#define DEFAULT_MAX_PARALLEL_DOWNLOADS 128
+#define SERVICE_LIST_TIMEOUT GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 1)
/**
* Should gnunet-fs-gtk start in tray mode?
@@ -59,6 +62,16 @@
static struct GNUNET_FS_Handle *fs;
/**
+ * Handle for ARM monitoring.
+ */
+static struct GNUNET_ARM_MonitorHandle *armon;
+
+/**
+ * Handle for ARM controlling.
+ */
+static struct GNUNET_ARM_Handle *arm;
+
+/**
* Context for main window.
*/
static struct GNUNET_GTK_MainWindowContext main_context;
@@ -210,6 +223,16 @@
GNUNET_FS_stop (fs);
fs = NULL;
}
+ if (NULL != armon)
+ {
+ GNUNET_ARM_monitor_disconnect (armon);
+ armon = NULL;
+ }
+ if (NULL != arm)
+ {
+ GNUNET_ARM_disconnect (arm);
+ arm = NULL;
+ }
GNUNET_FS_GTK_close_uri_tab_ ();
if (NULL != ml)
GNUNET_GTK_main_loop_quit (ml);
@@ -372,7 +395,114 @@
}
#endif
+static char *
+format_service_list (unsigned int count, const char *const*list)
+{
+ size_t len = 0;
+ int i;
+ const char *header = _("GNUnet node appears to be on.");
+ const char *listheader = _("Currently running services:\n");
+ char *result;
+ char *p;
+ int r;
+ len = strlen (header) + 1;
+ if (list)
+ {
+ len += strlen (listheader);
+ for (i = 0; i < count; i++)
+ len += strlen (list[i]) + 1;
+ }
+ len += 1;
+ result = p = GNUNET_malloc (len * sizeof (char));
+ r = GNUNET_snprintf (p, (size_t) (result + len - p), "%s\n", header);
+ if (r < 0)
+ {
+ GNUNET_free (result);
+ return NULL;
+ }
+ p += r;
+ if (list)
+ {
+ r = GNUNET_snprintf (p, (size_t) (result + len - p), "%s", listheader);
+ if (r < 0)
+ {
+ GNUNET_free (result);
+ return NULL;
+ }
+ p += r;
+ for (i = 0; i < count; i++)
+ {
+ size_t l = strlen (list[i]);
+ memcpy (p, list[i], l);
+ p += l;
+ if (i + 1 < count)
+ {
+ p[0] = '\n';
+ p += 1;
+ }
+ }
+ }
+ p[0] = '\0';
+ return result;
+}
+
+static void
+service_list_callback (void *cls, struct GNUNET_ARM_Handle *arm,
+ enum GNUNET_ARM_RequestStatus rs, unsigned int count,
+ const char *const*list)
+{
+ char *service_list;
+ if ((GNUNET_ARM_REQUEST_SENT_OK != rs) || (NULL == list))
+ return;
+ service_list = format_service_list (count, list);
+ GNUNET_FS_GTK_update_connection_indicator (cls, TRUE, service_list);
+ GNUNET_free_non_null (service_list);
+}
+
+
+static void
+arm_connection_state_change (void *cls, struct GNUNET_ARM_Handle *arm,
+ unsigned char connected, unsigned char error)
+{
+ char *service_list;
+ if (GNUNET_YES == error)
+ {
+ /* This is really extreme, but actually only happens if your
+ * configuration is b0rked.
+ */
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (connected)
+ {
+ service_list = format_service_list (0, NULL);
+ GNUNET_FS_GTK_update_connection_indicator (cls, TRUE, service_list);
+ GNUNET_free_non_null (service_list);
+ GNUNET_ARM_request_service_list (arm, SERVICE_LIST_TIMEOUT,
+ service_list_callback, cls);
+ }
+ else
+ GNUNET_FS_GTK_update_connection_indicator (cls, FALSE,
+ _("Can't connect to the Automatic Restart Manager service."));
+}
+
+
+static void
+service_status_change (void *cls, struct GNUNET_ARM_MonitorHandle *armon,
+ const char *service, enum GNUNET_ARM_ServiceStatus status)
+{
+ /* Very crude, we can probably do better.
+ * Maybe keep a list of running services, and modify it in response
+ * to service status changes, then update the indicator,
+ * without requesting a list from ARM every goddamned time?
+ */
+ GNUNET_ARM_request_service_list (arm, SERVICE_LIST_TIMEOUT,
+ service_list_callback, cls);
+}
+
+
/**
* Actual main function run right after GNUnet's scheduler
* is initialized. Initializes up GTK and Glade.
@@ -423,6 +553,8 @@
main_context.notebook = GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
("GNUNET_GTK_main_window_notebook"));
+ main_context.connection_indicator = GTK_IMAGE
(GNUNET_FS_GTK_get_main_window_object
("GNUNET_FS_GTK_main_window_connection_indicator"));
+
GNUNET_GTK_set_icon_search_path ();
GNUNET_GTK_setup_nls ();
@@ -491,6 +623,10 @@
GNUNET_GTK_main_loop_quit (cls);
return;
}
+ arm = GNUNET_ARM_alloc (main_context.cfg);
+ GNUNET_ARM_connect (arm, arm_connection_state_change, &main_context);
+ armon = GNUNET_ARM_monitor_alloc (main_context.cfg);
+ GNUNET_ARM_monitor (armon, service_status_change, &main_context);
GNUNET_GTK_main_window_refresh_ns_list (&main_context);
#if HAVE_LIBUNIQUE
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk.h 2013-03-13 21:44:40 UTC (rev 26410)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk.h 2013-03-13 21:44:45 UTC (rev 26411)
@@ -70,6 +70,8 @@
GtkVBox *download_panel;
GtkNotebook *notebook;
+
+ GtkImage *connection_indicator;
};
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h 2013-03-13 21:44:40 UTC
(rev 26410)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.h 2013-03-13 21:44:45 UTC
(rev 26411)
@@ -27,8 +27,8 @@
#define GNUNET_FS_GTK_EVENT_HANDLER_H
#include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk.h"
-
/**
* State we keep for each (search) result entry in the
* tree view of a search tab.
@@ -278,5 +278,18 @@
GNUNET_FS_GTK_close_uri_tab_ ();
+/**
+ * Update the connection indicator widget.
+ *
+ * @param main_ctx context
+ * @param connected TRUE if connected to arm, FALSE otherwise
+ * @param tooltip new tooltip text
+ */
+void
+GNUNET_FS_GTK_update_connection_indicator (
+ struct GNUNET_GTK_MainWindowContext *main_ctx,
+ gboolean connected, const gchar *tooltip);
+
+
#endif
/* end of gnunet-fs-gtk-event_handler.h */
Added: gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-connection.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-connection.c
(rev 0)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-connection.c 2013-03-13
21:44:45 UTC (rev 26411)
@@ -0,0 +1,72 @@
+/*
+ This file is part of GNUnet
+ (C) 2011, 2012 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/fs/gnunet-fs-gtk_main-window-connection.c
+ * @author LRN
+ * @brief event handlers for the connection indicator in the main window
+ */
+#include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk.h"
+
+/**
+ * Update the connection indicator widget.
+ *
+ * @param main_ctx context
+ * @param connected TRUE if connected to arm, FALSE otherwise
+ * @param tooltip new tooltip text
+ */
+void
+GNUNET_FS_GTK_update_connection_indicator (
+ struct GNUNET_GTK_MainWindowContext *main_ctx,
+ gboolean connected, const gchar *tooltip)
+{
+ gtk_image_set_from_stock (main_ctx->connection_indicator,
+ connected ? "gtk-yes" : "gtk-no", GTK_ICON_SIZE_BUTTON);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (main_ctx->connection_indicator),
+ tooltip);
+}
+
+/**
+ * Runs gnunet-armview-gtk (no, armview does not exist. Yet?).
+ * @param main_ctx main window context
+ */
+static void
+run_armview (struct GNUNET_GTK_MainWindowContext *main_ctx)
+{
+ /* TODO: implement armview? */
+}
+
+/**
+ * User clicked on the connection indicator in the main window.
+ *
+ * @param widget the image widget
+ * @param event event describing the button that was clicked
+ * @param user_data the main window context
+ */
+gboolean
+GNUNET_FS_GTK_main_window_connection_indicator_button_press_event_cb (
+ GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+ run_armview (user_data);
+ return FALSE;
+}
+
+/* end of gnunet-fs-gtk_main-window-search.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26411 - in gnunet-gtk: contrib src/fs,
gnunet <=