aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/helper.c186
-rw-r--r--src/include/gnunetgtk_common.h19
-rw-r--r--src/plugins/daemon/daemon.c4
-rw-r--r--src/plugins/stats/functions.c188
4 files changed, 217 insertions, 180 deletions
diff --git a/src/common/helper.c b/src/common/helper.c
index 864051a9..d8722bc5 100644
--- a/src/common/helper.c
+++ b/src/common/helper.c
@@ -495,6 +495,192 @@ GNUNET_GTK_run_with_save_calls (GNUNET_ThreadMainFunction cb, void *arg)
495 return retval; 495 return retval;
496} 496}
497 497
498/*
499 * Update the status bar indicator and the status icon
500 * about daemon and connexions status.
501 */
502void
503GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS status,
504 unsigned long long peers)
505{
506 static gboolean once = TRUE;
507 static int last_status = GNUNET_GTK_STATUS_UNKNOWN;
508 unsigned long long last_peers = 0;
509 char *label;
510 static GtkWidget *statusConnexionsLabel;
511 static GtkWidget *statusConnexionsPic;
512#if GTK_CHECK_VERSION (2,10,0)
513 static GtkStatusIcon *trayIcon;
514#endif
515
516 if (once)
517 {
518 statusConnexionsLabel =
519 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
520 "statusConnexionsLabel");
521 statusConnexionsPic =
522 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
523 "statusConnexionsPic");
524#if GTK_CHECK_VERSION (2,10,0)
525 GtkIconSet *iconSet;
526 GtkIconSource *iconSource;
527 char *iconPath;
528 char *finalPath;
529 char *instDir;
530 char *dataDir;
531
532 trayIcon = GNUNET_GTK_get_trayIcon ();
533
534 instDir = GNUNET_get_installation_path (GNUNET_IPK_DATADIR);
535 dataDir = g_strconcat (instDir, "/../gnunet-gtk/", NULL);
536#if MINGW
537 finalPath = GNUNET_malloc (_MAX_PATH + 1);
538 plibc_conv_to_win_path (dataDir, finalPath);
539#else
540 finalPath = GNUNET_strdup (dataDir);
541#endif
542 GNUNET_free (instDir);
543 g_free (dataDir);
544 iconSource = gtk_icon_source_new ();
545
546 iconSet = gtk_icon_set_new ();
547 iconPath =
548 g_strconcat (finalPath, "gnunet-gtk-status-unknown.svg", NULL);
549 gtk_icon_source_set_filename (iconSource, iconPath);
550 g_free (iconPath);
551 gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
552 gtk_icon_set_add_source (iconSet, iconSource);
553 iconPath =
554 g_strconcat (finalPath, "gnunet-gtk-status-unknown.png", NULL);
555 gtk_icon_source_set_filename (iconSource, iconPath);
556 g_free (iconPath);
557 gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
558 gtk_icon_set_add_source (iconSet, iconSource);
559
560 gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
561 "gnunet-gtk-status-unknown", iconSet);
562 gtk_icon_set_unref (iconSet);
563
564 iconSet = gtk_icon_set_new ();
565 iconPath =
566 g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.svg", NULL);
567 gtk_icon_source_set_filename (iconSource, iconPath);
568 g_free (iconPath);
569 gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
570 gtk_icon_set_add_source (iconSet, iconSource);
571 iconPath =
572 g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.png", NULL);
573 gtk_icon_source_set_filename (iconSource, iconPath);
574 g_free (iconPath);
575 gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
576 gtk_icon_set_add_source (iconSet, iconSource);
577
578 gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
579 "gnunet-gtk-status-nodaemon", iconSet);
580 gtk_icon_set_unref (iconSet);
581
582 iconSet = gtk_icon_set_new ();
583 iconPath =
584 g_strconcat (finalPath, "gnunet-gtk-status-disconnected.svg", NULL);
585 gtk_icon_source_set_filename (iconSource, iconPath);
586 g_free (iconPath);
587 gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
588 gtk_icon_set_add_source (iconSet, iconSource);
589 iconPath =
590 g_strconcat (finalPath, "gnunet-gtk-status-disconnected.png", NULL);
591 gtk_icon_source_set_filename (iconSource, iconPath);
592 g_free (iconPath);
593 gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
594 gtk_icon_set_add_source (iconSet, iconSource);
595
596 gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
597 "gnunet-gtk-status-disconnected", iconSet);
598 gtk_icon_set_unref (iconSet);
599
600
601 gtk_icon_source_free (iconSource);
602 GNUNET_free (finalPath);
603#endif
604
605 once = FALSE;
606 }
607 if (status == last_status && peers == last_peers)
608 return;
609 switch (status)
610 {
611 case GNUNET_GTK_STATUS_CONNECTED :
612 GNUNET_GE_BREAK (NULL, peers > 0);
613 if (peers == 1)
614 {
615 gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
616 _("Connected to 1 peer"));
617#if GTK_CHECK_VERSION (2,10,0)
618 gtk_status_icon_set_tooltip (trayIcon,
619 _("GNUnet - Connected to 1 peer"));
620#endif
621 }
622 else
623 {
624 label = g_strdup_printf (_("Connected to %Lu peers"), peers);
625 gtk_label_set_text (GTK_LABEL (statusConnexionsLabel), label);
626 g_free (label);
627#if GTK_CHECK_VERSION (2,10,0)
628 label =
629 g_strdup_printf (_("GNUnet - Connected to %Lu peers"), peers);
630 gtk_status_icon_set_tooltip (trayIcon, label);
631 g_free (label);
632#endif
633 }
634#if GTK_CHECK_VERSION (2,10,0)
635 gtk_status_icon_set_from_stock (trayIcon,
636 "gnunet-gtk-status-connected");
637#endif
638 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
639 GTK_STOCK_NETWORK, 1);
640 break;
641
642 case GNUNET_GTK_STATUS_DISCONNECTED :
643 gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
644 _("<b>Disconnected</b>"));
645 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
646 GTK_STOCK_DISCONNECT, 1);
647#if GTK_CHECK_VERSION (2,10,0)
648 gtk_status_icon_set_tooltip (trayIcon, _("GNUnet - Disconnected"));
649 gtk_status_icon_set_from_stock (trayIcon,
650 "gnunet-gtk-status-disconnected");
651#endif
652 break;
653
654 case GNUNET_GTK_STATUS_NODAEMON :
655 gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
656 _("<b>Daemon not running</b>"));
657 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
658 GTK_STOCK_NO, 1);
659#if GTK_CHECK_VERSION (2,10,0)
660 gtk_status_icon_set_tooltip (trayIcon,
661 _("GNUnet - Daemon not running"));
662 gtk_status_icon_set_from_stock (trayIcon, "gnunet-gtk-status-nodaemon");
663#endif
664 break;
665
666 default : /* GNUNET_GTK_STATUS_UNKNOWN */
667 GNUNET_GTK_add_log_entry (_
668 ("WARNING: Failed to obtain connection statistics from gnunetd.\n"));
669 gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
670 _("Unknown status"));
671 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
672 GTK_STOCK_DIALOG_ERROR, 1);
673#if GTK_CHECK_VERSION (2,10,0)
674 gtk_status_icon_set_tooltip (trayIcon, _("Unknown status"));
675 gtk_status_icon_set_from_stock (trayIcon,
676 "gnunet-gtk-status-unknown");
677#endif
678 break;
679 }
680 last_status = status;
681 last_peers = peers;
682}
683
498/** 684/**
499 * Simple glue to libnotify, and others? 685 * Simple glue to libnotify, and others?
500 * 686 *
diff --git a/src/include/gnunetgtk_common.h b/src/include/gnunetgtk_common.h
index 678a5a71..4125550e 100644
--- a/src/include/gnunetgtk_common.h
+++ b/src/include/gnunetgtk_common.h
@@ -98,6 +98,25 @@ GNUNET_GTK_shutdown_logger();
98#define GNUNET_GTK_NOTIFY_LEVEL_NORMAL 1 98#define GNUNET_GTK_NOTIFY_LEVEL_NORMAL 1
99#define GNUNET_GTK_NOTIFY_LEVEL_CRITICAL 2 99#define GNUNET_GTK_NOTIFY_LEVEL_CRITICAL 2
100 100
101typedef enum
102{
103 GNUNET_GTK_STATUS_NODAEMON,
104 GNUNET_GTK_STATUS_DISCONNECTED,
105 GNUNET_GTK_STATUS_CONNECTED,
106 GNUNET_GTK_STATUS_UNKNOWN
107} GNUNET_GTK_STATUS;
108
109/*
110 * Update the status bar indicator and the status icon
111 * about daemon and connexions status.
112 *
113 * @param status current status of gnunetd
114 * @param peers number of connected peers (with GNUNET_GTK_STATUS_CONNECTED)
115 */
116void
117GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS status,
118 unsigned long long peers);
119
101/** 120/**
102 * Sends a message to libnotify 121 * Sends a message to libnotify
103 */ 122 */
diff --git a/src/plugins/daemon/daemon.c b/src/plugins/daemon/daemon.c
index 703e5c4b..6d1e1e8c 100644
--- a/src/plugins/daemon/daemon.c
+++ b/src/plugins/daemon/daemon.c
@@ -253,6 +253,10 @@ cronCheckDaemon (void *dummy)
253 { 253 {
254 updateAppModel (NULL); 254 updateAppModel (NULL);
255 last = ret; 255 last = ret;
256 if (ret)
257 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_DISCONNECTED, 0);
258 else
259 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_NODAEMON, 0);
256 } 260 }
257 GNUNET_GTK_save_call (&doUpdateMenus, &ret); 261 GNUNET_GTK_save_call (&doUpdateMenus, &ret);
258} 262}
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c
index eb897abf..9a4dabb1 100644
--- a/src/plugins/stats/functions.c
+++ b/src/plugins/stats/functions.c
@@ -491,194 +491,22 @@ static void *
491updateDaemonStatus (void *cls) 491updateDaemonStatus (void *cls)
492{ 492{
493 struct UpdateClosure *uc = cls; 493 struct UpdateClosure *uc = cls;
494 static gboolean once = TRUE;
495 static long long last_status = -5;
496 unsigned long long connected_peers; 494 unsigned long long connected_peers;
497 char *label; 495
498 static GtkWidget *statusConnexionsLabel;
499 static GtkWidget *statusConnexionsPic;
500#if GTK_CHECK_VERSION (2,10,0)
501 static GtkStatusIcon *trayIcon;
502#endif
503
504 if (once)
505 {
506 statusConnexionsLabel =
507 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
508 "statusConnexionsLabel");
509 statusConnexionsPic =
510 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
511 "statusConnexionsPic");
512#if GTK_CHECK_VERSION (2,10,0)
513 GtkIconSet *iconSet;
514 GtkIconSource *iconSource;
515 char *iconPath;
516 char *finalPath;
517 char *instDir;
518 char *dataDir;
519
520 trayIcon = GNUNET_GTK_get_trayIcon ();
521
522 instDir = GNUNET_get_installation_path (GNUNET_IPK_DATADIR);
523 dataDir = g_strconcat (instDir, "/../gnunet-gtk/", NULL);
524#if MINGW
525 finalPath = GNUNET_malloc (_MAX_PATH + 1);
526 plibc_conv_to_win_path (dataDir, finalPath);
527#else
528 finalPath = GNUNET_strdup (dataDir);
529#endif
530 GNUNET_free (instDir);
531 g_free (dataDir);
532 iconSource = gtk_icon_source_new ();
533
534 iconSet = gtk_icon_set_new ();
535 iconPath =
536 g_strconcat (finalPath, "gnunet-gtk-status-unknown.svg", NULL);
537 gtk_icon_source_set_filename (iconSource, iconPath);
538 g_free (iconPath);
539 gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
540 gtk_icon_set_add_source (iconSet, iconSource);
541 iconPath =
542 g_strconcat (finalPath, "gnunet-gtk-status-unknown.png", NULL);
543 gtk_icon_source_set_filename (iconSource, iconPath);
544 g_free (iconPath);
545 gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
546 gtk_icon_set_add_source (iconSet, iconSource);
547
548 gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
549 "gnunet-gtk-status-unknown", iconSet);
550 gtk_icon_set_unref (iconSet);
551
552 iconSet = gtk_icon_set_new ();
553 iconPath =
554 g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.svg", NULL);
555 gtk_icon_source_set_filename (iconSource, iconPath);
556 g_free (iconPath);
557 gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
558 gtk_icon_set_add_source (iconSet, iconSource);
559 iconPath =
560 g_strconcat (finalPath, "gnunet-gtk-status-nodaemon.png", NULL);
561 gtk_icon_source_set_filename (iconSource, iconPath);
562 g_free (iconPath);
563 gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
564 gtk_icon_set_add_source (iconSet, iconSource);
565
566 gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
567 "gnunet-gtk-status-nodaemon", iconSet);
568 gtk_icon_set_unref (iconSet);
569
570 iconSet = gtk_icon_set_new ();
571 iconPath =
572 g_strconcat (finalPath, "gnunet-gtk-status-disconnected.svg", NULL);
573 gtk_icon_source_set_filename (iconSource, iconPath);
574 g_free (iconPath);
575 gtk_icon_source_set_size_wildcarded (iconSource, TRUE);
576 gtk_icon_set_add_source (iconSet, iconSource);
577 iconPath =
578 g_strconcat (finalPath, "gnunet-gtk-status-disconnected.png", NULL);
579 gtk_icon_source_set_filename (iconSource, iconPath);
580 g_free (iconPath);
581 gtk_icon_source_set_size_wildcarded (iconSource, FALSE);
582 gtk_icon_set_add_source (iconSet, iconSource);
583
584 gtk_icon_factory_add (GNUNET_GTK_get_iconFactory (),
585 "gnunet-gtk-status-disconnected", iconSet);
586 gtk_icon_set_unref (iconSet);
587
588
589 gtk_icon_source_free (iconSource);
590 GNUNET_free (finalPath);
591#endif
592
593 once = FALSE;
594 }
595 if (uc->is_running) 496 if (uc->is_running)
596 { 497 {
597 if (GNUNET_OK != 498 if (GNUNET_OK !=
598 getStatValue (&connected_peers, NULL, NULL, 499 getStatValue (&connected_peers, NULL, NULL,
599 "# of connected peers", GNUNET_NO)) 500 "# of connected peers", GNUNET_NO))
600 { 501 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_UNKNOWN, 0);
601 if (last_status != -1)
602 {
603 GNUNET_GTK_add_log_entry (_
604 ("WARNING: Failed to obtain connection statistics from gnunetd.\n"));
605 gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
606 _("Unknown status"));
607 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
608 GTK_STOCK_DIALOG_ERROR, 1);
609#if GTK_CHECK_VERSION (2,10,0)
610 gtk_status_icon_set_tooltip (trayIcon, _("Unknown status"));
611 gtk_status_icon_set_from_stock (trayIcon,
612 "gnunet-gtk-status-unknown");
613#endif
614 last_status = -1;
615 }
616 }
617 else if (connected_peers > 0) 502 else if (connected_peers > 0)
618 { 503 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_CONNECTED,
619 if (last_status != (long long) connected_peers) 504 connected_peers);
620 { 505 else
621 if (connected_peers == 1) 506 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_DISCONNECTED, 0);
622 {
623 gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
624 _("Connected to 1 peer"));
625#if GTK_CHECK_VERSION (2,10,0)
626 gtk_status_icon_set_tooltip (trayIcon,
627 _
628 ("GNUnet - Connected to 1 peer"));
629#endif
630 }
631 else
632 {
633 label = g_strdup_printf (_("Connected to %Lu peers"),
634 connected_peers);
635 gtk_label_set_text (GTK_LABEL (statusConnexionsLabel),
636 label);
637 g_free (label);
638#if GTK_CHECK_VERSION (2,10,0)
639 label =
640 g_strdup_printf (_("GNUnet - Connected to %Lu peers"),
641 connected_peers);
642 gtk_status_icon_set_tooltip (trayIcon, label);
643 g_free (label);
644#endif
645 }
646#if GTK_CHECK_VERSION (2,10,0)
647 gtk_status_icon_set_from_stock (trayIcon,
648 "gnunet-gtk-status-connected");
649#endif
650 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
651 GTK_STOCK_NETWORK, 1);
652 last_status = (long long) connected_peers;
653 }
654 }
655 else if (last_status != 0)
656 {
657 gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
658 _("<b>Disconnected</b>"));
659 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
660 GTK_STOCK_DISCONNECT, 1);
661#if GTK_CHECK_VERSION (2,10,0)
662 gtk_status_icon_set_tooltip (trayIcon, _("GNUnet - Disconnected"));
663 gtk_status_icon_set_from_stock (trayIcon,
664 "gnunet-gtk-status-disconnected");
665#endif
666 last_status = 0;
667 }
668 }
669 else if (last_status != -2)
670 {
671 gtk_label_set_markup (GTK_LABEL (statusConnexionsLabel),
672 _("<b>Daemon not running</b>"));
673 gtk_image_set_from_stock (GTK_IMAGE (statusConnexionsPic),
674 GTK_STOCK_NO, 1);
675#if GTK_CHECK_VERSION (2,10,0)
676 gtk_status_icon_set_tooltip (trayIcon,
677 _("GNUnet - Daemon not running"));
678 gtk_status_icon_set_from_stock (trayIcon, "gnunet-gtk-status-nodaemon");
679#endif
680 last_status = -2;
681 } 507 }
508 else
509 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_NODAEMON, 0);
682 return NULL; 510 return NULL;
683} 511}
684 512