/*
- * Copyright (C) 2010-2011 jeanfi@gmail.com
+ * Copyright (C) 2010-2014 jeanfi@gmail.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
-
-#include <gtk/gtk.h>
-
#include "log.h"
#include "ui_status.h"
-GtkStatusIcon *status;
+static const char *ICON = "psensor_normal";
+static const char *ATTENTION_ICON = "psensor_hot";
-unsigned status_attention;
+static GtkStatusIcon *status;
+static unsigned status_attention;
static void cb_activate(GtkStatusIcon *icon,
gpointer data)
{
- struct ui_psensor *ui;
-
- log_printf(LOG_DEBUG, "cb_activate()");
-
- ui = (struct ui_psensor *)data;
- gtk_window_present(GTK_WINDOW(ui->main_window));
+ log_debug("cb_activate()");
+ ui_window_show((struct ui_psensor *)data);
}
static void cb_popup_menu(GtkStatusIcon *icon,
guint activate_time,
gpointer data)
{
- log_printf(LOG_DEBUG, "cb_popup_menu()");
+ log_debug("cb_popup_menu()");
}
void ui_status_init(struct ui_psensor *ui)
{
- log_printf(LOG_DEBUG, "ui_status_create()");
+ if (status)
+ return ;
+
+ log_debug("ui_status_create()");
status = gtk_status_icon_new();
- gtk_status_icon_set_from_icon_name(status, "psensor");
- gtk_status_icon_set_visible(status, TRUE);
+ gtk_status_icon_set_from_icon_name(status, ICON);
+ ui_status_set_visible(0);
g_signal_connect(G_OBJECT(status),
"popup-menu",
int is_status_supported()
{
- return gtk_status_icon_is_embedded(status);
+ return status && gtk_status_icon_is_embedded(status);
}
void ui_status_cleanup()
{
- log_printf(LOG_DEBUG, "ui_status_cleanup()");
+ log_debug("ui_status_cleanup()");
- g_object_unref(G_OBJECT(status));
+ if (status) {
+ g_object_unref(G_OBJECT(status));
+ status = NULL;
+ }
}
void ui_status_update(struct ui_psensor *ui, unsigned int attention)
{
- log_printf(LOG_DEBUG, "ui_status_update()");
+ log_debug("ui_status_update()");
if (status_attention && !attention)
- gtk_status_icon_set_from_icon_name(status, "psensor");
+ gtk_status_icon_set_from_icon_name(status, ICON);
else if (!status_attention && attention)
- gtk_status_icon_set_from_icon_name(status, "psensor_hot");
+ gtk_status_icon_set_from_icon_name(status, ATTENTION_ICON);
status_attention = attention;
}
+
+GtkStatusIcon *ui_status_get_icon(struct ui_psensor *ui)
+{
+ if (!status)
+ ui_status_init(ui);
+
+ return status;
+}
+
+void ui_status_set_visible(unsigned int visible)
+{
+ log_debug("ui_status_set_visible(%d)", visible);
+
+ if (status) {
+ if (visible)
+ gtk_status_icon_set_visible(status, TRUE);
+ else
+ gtk_status_icon_set_visible(status, FALSE);
+ }
+}