X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fui_appindicator.c;h=a396f655828ec21a5540f4a8cef812c94f381eb0;hb=c4c838efcc14cd46807052fa0303f4ba6df48e5f;hp=49ca58fbb9991f38bfa2b207aaae23fbfa53454c;hpb=7b650a5af89f66cd833d6157c4487e992a586bcf;p=psensor.git diff --git a/src/ui_appindicator.c b/src/ui_appindicator.c index 49ca58f..a396f65 100644 --- a/src/ui_appindicator.c +++ b/src/ui_appindicator.c @@ -34,53 +34,40 @@ static const char *ICON = "psensor_normal"; static const char *ATTENTION_ICON = "psensor_hot"; +static const char *GLADE_FILE += PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "psensor-appindicator.glade"; + static struct psensor **sensors; static GtkMenuItem **menu_items; -static int appindicator_supported = 1; +static bool appindicator_supported = true; static AppIndicator *indicator; static struct ui_psensor *ui_psensor; -void cb_menu_show(GtkMenuItem *mi, gpointer data) +void ui_appindicator_menu_show_cb(GtkMenuItem *mi, gpointer data) { ui_window_show((struct ui_psensor *)data); } void ui_appindicator_cb_preferences(GtkMenuItem *mi, gpointer data) { -#ifdef HAVE_APPINDICATOR_029 - gdk_threads_enter(); -#endif - ui_pref_dialog_run((struct ui_psensor *)data); - -#ifdef HAVE_APPINDICATOR_029 - gdk_threads_leave(); -#endif } void ui_appindicator_cb_sensor_preferences(GtkMenuItem *mi, gpointer data) { struct ui_psensor *ui = data; -#ifdef HAVE_APPINDICATOR_029 - gdk_threads_enter(); -#endif - if (ui->sensors && *ui->sensors) ui_sensorpref_dialog_run(*ui->sensors, ui); - -#ifdef HAVE_APPINDICATOR_029 - gdk_threads_leave(); -#endif } static void -update_menu_item(GtkMenuItem *item, struct psensor *s, int use_celcius) +update_menu_item(GtkMenuItem *item, struct psensor *s, int use_celsius) { gchar *str; char *v; - v = psensor_current_value_to_str(s, use_celcius); + v = psensor_current_value_to_str(s, use_celsius); str = g_strdup_printf("%s: %s", s->name, v); @@ -90,29 +77,28 @@ update_menu_item(GtkMenuItem *item, struct psensor *s, int use_celcius) g_free(str); } -static void update_menu_items(int use_celcius) +static void update_menu_items(int use_celsius) { struct psensor **s; GtkMenuItem **m; if (!sensors) - return ; + return; for (s = sensors, m = menu_items; *s; s++, m++) - update_menu_item(*m, *s, use_celcius); + update_menu_item(*m, *s, use_celsius); } static void -build_sensor_menu_items(const struct ui_psensor *ui, - GtkMenu *menu) +build_sensor_menu_items(const struct ui_psensor *ui, GtkMenu *menu) { - int i, j, n, celcius; + int i, j, n, celsius; const char *name; struct psensor **sorted_sensors; free(menu_items); - celcius = ui->config->temperature_unit == CELCIUS; + celsius = ui->config->temperature_unit == CELSIUS; sorted_sensors = ui_get_sensors_ordered_by_position(ui); n = psensor_list_size(sorted_sensors); @@ -130,7 +116,7 @@ build_sensor_menu_items(const struct ui_psensor *ui, GTK_WIDGET(menu_items[j]), j+2); - update_menu_item(menu_items[j], sensors[j], celcius); + update_menu_item(menu_items[j], sensors[j], celsius); j++; } @@ -148,16 +134,20 @@ static GtkWidget *get_menu(struct ui_psensor *ui) guint ok; GtkBuilder *builder; + log_fct_enter(); + builder = gtk_builder_new(); error = NULL; ok = gtk_builder_add_from_file - (builder, - PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "psensor.glade", - &error); + (builder, + GLADE_FILE, + &error); if (!ok) { - log_printf(LOG_ERR, error->message); + log_err(_("Failed to load glade file %s: %s"), + GLADE_FILE, + error->message); g_error_free(error); return NULL; } @@ -169,9 +159,63 @@ static GtkWidget *get_menu(struct ui_psensor *ui) g_object_ref(G_OBJECT(menu)); g_object_unref(G_OBJECT(builder)); + log_fct_exit(); + return GTK_WIDGET(menu); } +static void update_label(struct ui_psensor *ui) +{ + char *label, *str, *tmp, *guide; + struct psensor **p; + + p = ui_get_sensors_ordered_by_position(ui); + label = NULL; + guide = NULL; + while (*p) { + if (config_is_appindicator_label_enabled((*p)->id)) { + str = psensor_current_value_to_str + (*p, ui->config->temperature_unit == CELSIUS); + + if (label == NULL) { + label = str; + } else { + tmp = malloc(strlen(label) + + 1 + + strlen(str) + + 1); + sprintf(tmp, "%s %s", label, str); + free(label); + free(str); + label = tmp; + } + + if (is_temp_type((*p)->type)) + str = "999UUU"; + else if ((*p)->type & SENSOR_TYPE_RPM) + str = "999UUU"; + else /* percent */ + str = "999%"; + + if (guide == NULL) { + guide = strdup(str); + } else { + tmp = malloc(strlen(guide) + + 1 + + strlen(str) + + 1); + sprintf(tmp, "%sW%s", guide, str); + free(guide); + guide = tmp; + } + + } + p++; + } + + app_indicator_set_label(indicator, label, guide); +} + void ui_appindicator_update(struct ui_psensor *ui, unsigned int attention) { AppIndicatorStatus status; @@ -179,6 +223,8 @@ void ui_appindicator_update(struct ui_psensor *ui, unsigned int attention) if (!indicator) return; + update_label(ui); + status = app_indicator_get_status(indicator); if (!attention && status == APP_INDICATOR_STATUS_ATTENTION) @@ -189,7 +235,7 @@ void ui_appindicator_update(struct ui_psensor *ui, unsigned int attention) app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ATTENTION); - update_menu_items(ui->config->temperature_unit == CELCIUS); + update_menu_items(ui->config->temperature_unit == CELSIUS); } static GtkStatusIcon *unity_fallback(AppIndicator *indicator) @@ -198,7 +244,7 @@ static GtkStatusIcon *unity_fallback(AppIndicator *indicator) log_debug("ui_appindicator.unity_fallback()"); - appindicator_supported = 0; + appindicator_supported = false; ico = ui_status_get_icon(ui_psensor); @@ -214,7 +260,7 @@ unity_unfallback(AppIndicator *indicator, GtkStatusIcon *status_icon) ui_status_set_visible(0); - appindicator_supported = 1; + appindicator_supported = true; } void ui_appindicator_update_menu(struct ui_psensor *ui) @@ -245,12 +291,12 @@ void ui_appindicator_init(struct ui_psensor *ui) ui_appindicator_update_menu(ui); } -int is_appindicator_supported() +bool is_appindicator_supported(void) { return appindicator_supported; } -void ui_appindicator_cleanup() +void ui_appindicator_cleanup(void) { free(sensors); }