diff options
Diffstat (limited to 'src/plugins/stats/functions.c')
-rw-r--r-- | src/plugins/stats/functions.c | 188 |
1 files changed, 8 insertions, 180 deletions
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 * | |||
491 | updateDaemonStatus (void *cls) | 491 | updateDaemonStatus (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 | ||