diff options
Diffstat (limited to 'src/plugins/stats/functions.c')
-rw-r--r-- | src/plugins/stats/functions.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c index 0dd1b9ec..f566f45e 100644 --- a/src/plugins/stats/functions.c +++ b/src/plugins/stats/functions.c | |||
@@ -466,6 +466,148 @@ statsProcessor (const char *optName, unsigned long long value, void *data) | |||
466 | return GNUNET_OK; | 466 | return GNUNET_OK; |
467 | } | 467 | } |
468 | 468 | ||
469 | /* | ||
470 | * Update the status bar indicator about daemon and connexions status | ||
471 | */ | ||
472 | static void * | ||
473 | updateDaemonStatus (void *delta) | ||
474 | { | ||
475 | static gboolean once = TRUE; | ||
476 | static int last_status = -5; | ||
477 | long long connected_peers; | ||
478 | char *label; | ||
479 | static GtkWidget *statusConnexionsLabel; | ||
480 | static GtkWidget *statusConnexionsPic; | ||
481 | #if GTK_CHECK_VERSION (2,10,0) | ||
482 | static GdkPixbuf *iconNoDaemon; | ||
483 | static GdkPixbuf *iconDisconnected; | ||
484 | static GdkPixbuf *iconConnected; | ||
485 | #endif | ||
486 | |||
487 | if (once) | ||
488 | { | ||
489 | statusConnexionsLabel = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
490 | "statusConnexionsLabel"); | ||
491 | statusConnexionsPic = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
492 | "statusConnexionsPic"); | ||
493 | #if GTK_CHECK_VERSION (2,10,0) | ||
494 | char *iconFile; | ||
495 | char *finalPath; | ||
496 | char *instDir; | ||
497 | char *dataDir; | ||
498 | |||
499 | instDir = GNUNET_get_installation_path (GNUNET_IPK_DATADIR); | ||
500 | dataDir = g_strconcat (instDir, "/../gnunet-gtk/", NULL); | ||
501 | #if MINGW | ||
502 | finalPath = GNUNET_malloc (_MAX_PATH + 1); | ||
503 | plibc_conv_to_win_path (dataDir, finalPath); | ||
504 | #else | ||
505 | finalPath = GNUNET_strdup (dataDir); | ||
506 | #endif | ||
507 | GNUNET_free (instDir); | ||
508 | g_free (dataDir); | ||
509 | iconFile = g_strconcat (finalPath, "tray-nodaemon.png", NULL); | ||
510 | iconNoDaemon = gdk_pixbuf_new_from_file (iconFile, NULL); | ||
511 | g_free (iconFile); | ||
512 | iconFile = g_strconcat (finalPath, "tray-disconnected.png", NULL); | ||
513 | iconDisconnected = gdk_pixbuf_new_from_file (iconFile, NULL); | ||
514 | g_free (iconFile); | ||
515 | iconFile = g_strconcat (finalPath, "tray-connected.png", NULL); | ||
516 | iconConnected = gdk_pixbuf_new_from_file (iconFile, NULL); | ||
517 | g_free (iconFile); | ||
518 | GNUNET_free (finalPath); | ||
519 | #endif | ||
520 | |||
521 | once = FALSE; | ||
522 | } | ||
523 | if (GNUNET_OK == GNUNET_test_daemon_running (ectx, cfg)) | ||
524 | { | ||
525 | if (GNUNET_OK != getStatValue (&connected_peers, (GNUNET_CronTime *) delta, | ||
526 | NULL, "# of connected peers", GNUNET_NO)) | ||
527 | { | ||
528 | if (last_status != -1) | ||
529 | { | ||
530 | GNUNET_GTK_add_log_entry (_("WARNING: Failed to obtain connection statistics from gnunetd.\n")); | ||
531 | gtk_label_set_text (GTK_LABEL(statusConnexionsLabel), | ||
532 | _("Unknown status")); | ||
533 | gtk_image_set_from_stock (GTK_IMAGE(statusConnexionsPic), | ||
534 | GTK_STOCK_DIALOG_ERROR, 1); | ||
535 | #if GTK_CHECK_VERSION (2,10,0) | ||
536 | gtk_status_icon_set_tooltip (GNUNET_GTK_get_trayIcon (), | ||
537 | _("Unknown status")); | ||
538 | gtk_status_icon_set_from_pixbuf (GNUNET_GTK_get_trayIcon(), | ||
539 | iconNoDaemon); | ||
540 | #endif | ||
541 | last_status = -1; | ||
542 | } | ||
543 | } | ||
544 | else if (connected_peers > 0) | ||
545 | { | ||
546 | if (last_status != connected_peers) | ||
547 | { | ||
548 | if (connected_peers == 1) | ||
549 | { | ||
550 | gtk_label_set_text (GTK_LABEL(statusConnexionsLabel), | ||
551 | _("Connected to 1 peer")); | ||
552 | #if GTK_CHECK_VERSION (2,10,0) | ||
553 | gtk_status_icon_set_tooltip (GNUNET_GTK_get_trayIcon (), | ||
554 | _("GNUnet - Connected to 1 peer")); | ||
555 | #endif | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | label = g_strdup_printf (_("Connected to %Lu peers"), | ||
560 | connected_peers); | ||
561 | gtk_label_set_text (GTK_LABEL(statusConnexionsLabel), label); | ||
562 | g_free (label); | ||
563 | #if GTK_CHECK_VERSION (2,10,0) | ||
564 | label = g_strdup_printf (_("GNUnet - Connected to %Lu peers"), | ||
565 | connected_peers); | ||
566 | gtk_status_icon_set_tooltip (GNUNET_GTK_get_trayIcon (), label); | ||
567 | g_free (label); | ||
568 | #endif | ||
569 | } | ||
570 | #if GTK_CHECK_VERSION (2,10,0) | ||
571 | gtk_status_icon_set_from_pixbuf (GNUNET_GTK_get_trayIcon(), | ||
572 | iconConnected); | ||
573 | #endif | ||
574 | gtk_image_set_from_stock (GTK_IMAGE(statusConnexionsPic), | ||
575 | GTK_STOCK_NETWORK, 1); | ||
576 | last_status = connected_peers; | ||
577 | } | ||
578 | } | ||
579 | else if (last_status != 0) | ||
580 | { | ||
581 | gtk_label_set_markup (GTK_LABEL(statusConnexionsLabel), | ||
582 | _("<b>Disconnected</b>")); | ||
583 | gtk_image_set_from_stock (GTK_IMAGE(statusConnexionsPic), | ||
584 | GTK_STOCK_DISCONNECT, 1); | ||
585 | #if GTK_CHECK_VERSION (2,10,0) | ||
586 | gtk_status_icon_set_tooltip (GNUNET_GTK_get_trayIcon (), | ||
587 | _("GNUnet - Disconnected")); | ||
588 | gtk_status_icon_set_from_pixbuf (GNUNET_GTK_get_trayIcon(), | ||
589 | iconDisconnected); | ||
590 | #endif | ||
591 | last_status = 0; | ||
592 | } | ||
593 | } | ||
594 | else if (last_status != -2) | ||
595 | { | ||
596 | gtk_label_set_markup (GTK_LABEL(statusConnexionsLabel), | ||
597 | _("<b>Daemon not running</b>")); | ||
598 | gtk_image_set_from_stock (GTK_IMAGE(statusConnexionsPic), | ||
599 | GTK_STOCK_NO, 1); | ||
600 | #if GTK_CHECK_VERSION (2,10,0) | ||
601 | gtk_status_icon_set_tooltip (GNUNET_GTK_get_trayIcon (), | ||
602 | _("GNUnet - Daemon not running")); | ||
603 | gtk_status_icon_set_from_pixbuf (GNUNET_GTK_get_trayIcon(), | ||
604 | iconNoDaemon); | ||
605 | #endif | ||
606 | last_status = -2; | ||
607 | } | ||
608 | return NULL; | ||
609 | } | ||
610 | |||
469 | /** | 611 | /** |
470 | * Cron-job that updates all stat values. | 612 | * Cron-job that updates all stat values. |
471 | */ | 613 | */ |
@@ -482,6 +624,7 @@ updateStatValues (void *unused) | |||
482 | if (GNUNET_OK == | 624 | if (GNUNET_OK == |
483 | GNUNET_STATS_get_statistics (ectx, sock, &statsProcessor, &delta)) | 625 | GNUNET_STATS_get_statistics (ectx, sock, &statsProcessor, &delta)) |
484 | lastUpdate = now; | 626 | lastUpdate = now; |
627 | GNUNET_GTK_save_call (&updateDaemonStatus, (void *) &delta); | ||
485 | GNUNET_mutex_unlock (lock); | 628 | GNUNET_mutex_unlock (lock); |
486 | } | 629 | } |
487 | 630 | ||