[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r7366 - in gnunet-gtk/src: common include plugins/daemon pl
From: |
gnunet |
Subject: |
[GNUnet-SVN] r7366 - in gnunet-gtk/src: common include plugins/daemon plugins/stats |
Date: |
Sun, 29 Jun 2008 08:41:40 -0600 (MDT) |
Author: moon
Date: 2008-06-29 08:41:39 -0600 (Sun, 29 Jun 2008)
New Revision: 7366
Modified:
gnunet-gtk/src/common/helper.c
gnunet-gtk/src/include/gnunetgtk_common.h
gnunet-gtk/src/plugins/daemon/daemon.c
gnunet-gtk/src/plugins/stats/functions.c
Log:
centralize the display of gnunetd status in one function
use this function to update the status from the daemon plugin (immediate update)
Modified: gnunet-gtk/src/common/helper.c
===================================================================
--- gnunet-gtk/src/common/helper.c 2008-06-29 06:16:46 UTC (rev 7365)
+++ gnunet-gtk/src/common/helper.c 2008-06-29 14:41:39 UTC (rev 7366)
@@ -495,6 +495,192 @@
return retval;
}
+/*
+ * Update the status bar indicator and the status icon
+ * about daemon and connexions status.
+ */
+void
+GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS status,
+ unsigned long long peers)
+{
+ static gboolean once = TRUE;
+ static int last_status = GNUNET_GTK_STATUS_UNKNOWN;
+ unsigned long long last_peers = 0;
+ char *label;
+ static GtkWidget *statusConnexionsLabel;
+ static GtkWidget *statusConnexionsPic;
+#if GTK_CHECK_VERSION (2,10,0)
+ static GtkStatusIcon *trayIcon;
+#endif
+
+ if (once)
+ {
+ statusConnexionsLabel =
+ glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
+ "statusConnexionsLabel");
+ statusConnexionsPic =
+ glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
+ "statusConnexionsPic");
+#if GTK_CHECK_VERSION (2,10,0)
+ GtkIconSet *iconSet;
+ GtkIconSource *iconSource;
+ char *iconPath;
+ char *finalPath;
+ char *instDir;
+ char *dataDir;
+
+ trayIcon = GNUNET_GTK_get_trayIcon ();
+
+ instDir = GNUNET_get_installation_path (GNUNET_IPK_DATADIR);
+ dataDir = g_strconcat (instDir, "/../gnunet-gtk/", NULL);
+#if MINGW
+ finalPath = GNUNET_malloc (_MAX_PATH + 1);
+ plibc_conv_to_win_path (dataDir, finalPath);
+#else
+ finalPath = GNUNET_strdup (dataDir);
+#endif
+ GNUNET_free (instDir);
+ g_free (dataDir);
+ iconSource = gtk_icon_source_new ();
+
+ iconSet = gtk_icon_set_new ();
+ iconPath =
+ g_strconcat (finalPath, "gnunet-gtk-status-unknown.svg", NULL);
+ gtk_icon_source_set_filename (iconSource, iconPath);
+ g_free (iconPath);
+ gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
+ gtk_icon_set_add_source (iconSet, iconSource);
+ iconPath =
+ g_strconcat (finalPath, "gnunet-gtk-status-unknown.png", NULL);
+ gtk_icon_source_set_filename (iconSource, iconPath);
+ g_free (iconPath);
+ gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
+ gtk_icon_set_add_source (iconSet, iconSource);
+
+ gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
+ "gnunet-gtk-status-unknown", iconSet);
+ gtk_icon_set_unref (iconSet);
+
+ iconSet = gtk_icon_set_new ();
+ iconPath =
+ g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.svg", NULL);
+ gtk_icon_source_set_filename (iconSource, iconPath);
+ g_free (iconPath);
+ gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
+ gtk_icon_set_add_source (iconSet, iconSource);
+ iconPath =
+ g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.png", NULL);
+ gtk_icon_source_set_filename (iconSource, iconPath);
+ g_free (iconPath);
+ gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
+ gtk_icon_set_add_source (iconSet, iconSource);
+
+ gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
+ "gnunet-gtk-status-nodaemon", iconSet);
+ gtk_icon_set_unref (iconSet);
+
+ iconSet = gtk_icon_set_new ();
+ iconPath =
+ g_strconcat (finalPath, "gnunet-gtk-status-disconnected.svg", NULL);
+ gtk_icon_source_set_filename (iconSource, iconPath);
+ g_free (iconPath);
+ gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
+ gtk_icon_set_add_source (iconSet, iconSource);
+ iconPath =
+ g_strconcat (finalPath, "gnunet-gtk-status-disconnected.png", NULL);
+ gtk_icon_source_set_filename (iconSource, iconPath);
+ g_free (iconPath);
+ gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
+ gtk_icon_set_add_source (iconSet, iconSource);
+
+ gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
+ "gnunet-gtk-status-disconnected", iconSet);
+ gtk_icon_set_unref (iconSet);
+
+
+ gtk_icon_source_free (iconSource);
+ GNUNET_free (finalPath);
+#endif
+
+ once = FALSE;
+ }
+ if (status == last_status && peers == last_peers)
+ return;
+ switch (status)
+ {
+ case GNUNET_GTK_STATUS_CONNECTED :
+ GNUNET_GE_BREAK (NULL, peers > 0);
+ if (peers == 1)
+ {
+ gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
+ _("Connected to 1 peer"));
+#if GTK_CHECK_VERSION (2,10,0)
+ gtk_status_icon_set_tooltip (trayIcon,
+ _("GNUnet - Connected to 1 peer"));
+#endif
+ }
+ else
+ {
+ label = g_strdup_printf (_("Connected to %Lu peers"), peers);
+ gtk_label_set_text (GTK_LABEL (statusConnexionsLabel), label);
+ g_free (label);
+#if GTK_CHECK_VERSION (2,10,0)
+ label =
+ g_strdup_printf (_("GNUnet - Connected to %Lu peers"), peers);
+ gtk_status_icon_set_tooltip (trayIcon, label);
+ g_free (label);
+#endif
+ }
+#if GTK_CHECK_VERSION (2,10,0)
+ gtk_status_icon_set_from_stock (trayIcon,
+ "gnunet-gtk-status-connected");
+#endif
+ gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
+ GTK_STOCK_NETWORK, 1);
+ break;
+
+ case GNUNET_GTK_STATUS_DISCONNECTED :
+ gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
+ _("<b>Disconnected</b>"));
+ gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
+ GTK_STOCK_DISCONNECT, 1);
+#if GTK_CHECK_VERSION (2,10,0)
+ gtk_status_icon_set_tooltip (trayIcon, _("GNUnet - Disconnected"));
+ gtk_status_icon_set_from_stock (trayIcon,
+ "gnunet-gtk-status-disconnected");
+#endif
+ break;
+
+ case GNUNET_GTK_STATUS_NODAEMON :
+ gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
+ _("<b>Daemon not running</b>"));
+ gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
+ GTK_STOCK_NO, 1);
+#if GTK_CHECK_VERSION (2,10,0)
+ gtk_status_icon_set_tooltip (trayIcon,
+ _("GNUnet - Daemon not running"));
+ gtk_status_icon_set_from_stock (trayIcon,
"gnunet-gtk-status-nodaemon");
+#endif
+ break;
+
+ default : /* GNUNET_GTK_STATUS_UNKNOWN */
+ GNUNET_GTK_add_log_entry (_
+ ("WARNING: Failed to obtain connection
statistics from gnunetd.\n"));
+ gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
+ _("Unknown status"));
+ gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
+ GTK_STOCK_DIALOG_ERROR, 1);
+#if GTK_CHECK_VERSION (2,10,0)
+ gtk_status_icon_set_tooltip (trayIcon, _("Unknown status"));
+ gtk_status_icon_set_from_stock (trayIcon,
+ "gnunet-gtk-status-unknown");
+#endif
+ break;
+ }
+ last_status = status;
+ last_peers = peers;
+}
+
/**
* Simple glue to libnotify, and others?
*
Modified: gnunet-gtk/src/include/gnunetgtk_common.h
===================================================================
--- gnunet-gtk/src/include/gnunetgtk_common.h 2008-06-29 06:16:46 UTC (rev
7365)
+++ gnunet-gtk/src/include/gnunetgtk_common.h 2008-06-29 14:41:39 UTC (rev
7366)
@@ -98,6 +98,25 @@
#define GNUNET_GTK_NOTIFY_LEVEL_NORMAL 1
#define GNUNET_GTK_NOTIFY_LEVEL_CRITICAL 2
+typedef enum
+{
+ GNUNET_GTK_STATUS_NODAEMON,
+ GNUNET_GTK_STATUS_DISCONNECTED,
+ GNUNET_GTK_STATUS_CONNECTED,
+ GNUNET_GTK_STATUS_UNKNOWN
+} GNUNET_GTK_STATUS;
+
+/*
+ * Update the status bar indicator and the status icon
+ * about daemon and connexions status.
+ *
+ * @param status current status of gnunetd
+ * @param peers number of connected peers (with GNUNET_GTK_STATUS_CONNECTED)
+ */
+void
+GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS status,
+ unsigned long long peers);
+
/**
* Sends a message to libnotify
*/
Modified: gnunet-gtk/src/plugins/daemon/daemon.c
===================================================================
--- gnunet-gtk/src/plugins/daemon/daemon.c 2008-06-29 06:16:46 UTC (rev
7365)
+++ gnunet-gtk/src/plugins/daemon/daemon.c 2008-06-29 14:41:39 UTC (rev
7366)
@@ -253,6 +253,10 @@
{
updateAppModel (NULL);
last = ret;
+ if (ret)
+ GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_DISCONNECTED, 0);
+ else
+ GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_NODAEMON, 0);
}
GNUNET_GTK_save_call (&doUpdateMenus, &ret);
}
Modified: gnunet-gtk/src/plugins/stats/functions.c
===================================================================
--- gnunet-gtk/src/plugins/stats/functions.c 2008-06-29 06:16:46 UTC (rev
7365)
+++ gnunet-gtk/src/plugins/stats/functions.c 2008-06-29 14:41:39 UTC (rev
7366)
@@ -491,194 +491,22 @@
updateDaemonStatus (void *cls)
{
struct UpdateClosure *uc = cls;
- static gboolean once = TRUE;
- static long long last_status = -5;
unsigned long long connected_peers;
- char *label;
- static GtkWidget *statusConnexionsLabel;
- static GtkWidget *statusConnexionsPic;
-#if GTK_CHECK_VERSION (2,10,0)
- static GtkStatusIcon *trayIcon;
-#endif
-
- if (once)
- {
- statusConnexionsLabel =
- glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
- "statusConnexionsLabel");
- statusConnexionsPic =
- glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
- "statusConnexionsPic");
-#if GTK_CHECK_VERSION (2,10,0)
- GtkIconSet *iconSet;
- GtkIconSource *iconSource;
- char *iconPath;
- char *finalPath;
- char *instDir;
- char *dataDir;
-
- trayIcon = GNUNET_GTK_get_trayIcon ();
-
- instDir = GNUNET_get_installation_path (GNUNET_IPK_DATADIR);
- dataDir = g_strconcat (instDir, "/../gnunet-gtk/", NULL);
-#if MINGW
- finalPath = GNUNET_malloc (_MAX_PATH + 1);
- plibc_conv_to_win_path (dataDir, finalPath);
-#else
- finalPath = GNUNET_strdup (dataDir);
-#endif
- GNUNET_free (instDir);
- g_free (dataDir);
- iconSource = gtk_icon_source_new ();
-
- iconSet = gtk_icon_set_new ();
- iconPath =
- g_strconcat (finalPath, "gnunet-gtk-status-unknown.svg", NULL);
- gtk_icon_source_set_filename (iconSource, iconPath);
- g_free (iconPath);
- gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
- gtk_icon_set_add_source (iconSet, iconSource);
- iconPath =
- g_strconcat (finalPath, "gnunet-gtk-status-unknown.png", NULL);
- gtk_icon_source_set_filename (iconSource, iconPath);
- g_free (iconPath);
- gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
- gtk_icon_set_add_source (iconSet, iconSource);
-
- gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
- "gnunet-gtk-status-unknown", iconSet);
- gtk_icon_set_unref (iconSet);
-
- iconSet = gtk_icon_set_new ();
- iconPath =
- g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.svg", NULL);
- gtk_icon_source_set_filename (iconSource, iconPath);
- g_free (iconPath);
- gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
- gtk_icon_set_add_source (iconSet, iconSource);
- iconPath =
- g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.png", NULL);
- gtk_icon_source_set_filename (iconSource, iconPath);
- g_free (iconPath);
- gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
- gtk_icon_set_add_source (iconSet, iconSource);
-
- gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
- "gnunet-gtk-status-nodaemon", iconSet);
- gtk_icon_set_unref (iconSet);
-
- iconSet = gtk_icon_set_new ();
- iconPath =
- g_strconcat (finalPath, "gnunet-gtk-status-disconnected.svg", NULL);
- gtk_icon_source_set_filename (iconSource, iconPath);
- g_free (iconPath);
- gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
- gtk_icon_set_add_source (iconSet, iconSource);
- iconPath =
- g_strconcat (finalPath, "gnunet-gtk-status-disconnected.png", NULL);
- gtk_icon_source_set_filename (iconSource, iconPath);
- g_free (iconPath);
- gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
- gtk_icon_set_add_source (iconSet, iconSource);
-
- gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
- "gnunet-gtk-status-disconnected", iconSet);
- gtk_icon_set_unref (iconSet);
-
-
- gtk_icon_source_free (iconSource);
- GNUNET_free (finalPath);
-#endif
-
- once = FALSE;
- }
+
if (uc->is_running)
{
if (GNUNET_OK !=
getStatValue (&connected_peers, NULL, NULL,
"# of connected peers", GNUNET_NO))
- {
- if (last_status != -1)
- {
- GNUNET_GTK_add_log_entry (_
- ("WARNING: Failed to obtain connection
statistics from gnunetd.\n"));
- gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
- _("Unknown status"));
- gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
- GTK_STOCK_DIALOG_ERROR, 1);
-#if GTK_CHECK_VERSION (2,10,0)
- gtk_status_icon_set_tooltip (trayIcon, _("Unknown status"));
- gtk_status_icon_set_from_stock (trayIcon,
- "gnunet-gtk-status-unknown");
-#endif
- last_status = -1;
- }
- }
+ GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_UNKNOWN, 0);
else if (connected_peers > 0)
- {
- if (last_status != (long long) connected_peers)
- {
- if (connected_peers == 1)
- {
- gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
- _("Connected to 1 peer"));
-#if GTK_CHECK_VERSION (2,10,0)
- gtk_status_icon_set_tooltip (trayIcon,
- _
- ("GNUnet - Connected to 1
peer"));
-#endif
- }
- else
- {
- label = g_strdup_printf (_("Connected to %Lu peers"),
- connected_peers);
- gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
- label);
- g_free (label);
-#if GTK_CHECK_VERSION (2,10,0)
- label =
- g_strdup_printf (_("GNUnet - Connected to %Lu peers"),
- connected_peers);
- gtk_status_icon_set_tooltip (trayIcon, label);
- g_free (label);
-#endif
- }
-#if GTK_CHECK_VERSION (2,10,0)
- gtk_status_icon_set_from_stock (trayIcon,
- "gnunet-gtk-status-connected");
-#endif
- gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
- GTK_STOCK_NETWORK, 1);
- last_status = (long long) connected_peers;
- }
- }
- else if (last_status != 0)
- {
- gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
- _("<b>Disconnected</b>"));
- gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
- GTK_STOCK_DISCONNECT, 1);
-#if GTK_CHECK_VERSION (2,10,0)
- gtk_status_icon_set_tooltip (trayIcon, _("GNUnet - Disconnected"));
- gtk_status_icon_set_from_stock (trayIcon,
- "gnunet-gtk-status-disconnected");
-#endif
- last_status = 0;
- }
+ GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_CONNECTED,
+ connected_peers);
+ else
+ GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_DISCONNECTED, 0);
}
- else if (last_status != -2)
- {
- gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
- _("<b>Daemon not running</b>"));
- gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
- GTK_STOCK_NO, 1);
-#if GTK_CHECK_VERSION (2,10,0)
- gtk_status_icon_set_tooltip (trayIcon,
- _("GNUnet - Daemon not running"));
- gtk_status_icon_set_from_stock (trayIcon, "gnunet-gtk-status-nodaemon");
-#endif
- last_status = -2;
- }
+ else
+ GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_NODAEMON, 0);
return NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r7366 - in gnunet-gtk/src: common include plugins/daemon plugins/stats,
gnunet <=