-static GtkItemFactoryEntry menu_items[] = {
- {"/Show",
- NULL, cb_appindicator_show, 0, "<Item>"},
- {"/Preferences",
- NULL, cb_appindicator_preferences, 0, "<Item>"},
- {"/sep1",
- NULL, NULL, 0, "<Separator>"},
- {"/Quit",
- "", cb_appindicator_quit, 0, "<StockItem>", GTK_STOCK_QUIT},
-};
-
-static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
-GtkWidget *ui_appindicator_get_menu(struct ui_psensor *ui)
+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)
+{
+ gchar *str;
+ char *v;
+
+ v = psensor_current_value_to_str(s, use_celcius);
+
+ str = g_strdup_printf("%s: %s", s->name, v);
+
+ gtk_menu_item_set_label(item, str);
+
+ free(v);
+ g_free(str);
+}
+
+static void update_menu_items(int use_celcius)
+{
+ struct psensor **s;
+ GtkMenuItem **m;
+
+ if (!sensors)
+ return ;
+
+ for (s = sensors, m = menu_items; *s; s++, m++)
+ update_menu_item(*m, *s, use_celcius);
+}
+
+static void
+build_sensor_menu_items(const struct ui_psensor *ui,
+ GtkMenu *menu)
+{
+ int i, j, n, celcius;
+ const char *name;
+ struct psensor **sorted_sensors;
+
+ free(menu_items);
+
+ celcius = ui->config->temperature_unit == CELCIUS;
+
+ sorted_sensors = ui_get_sensors_ordered_by_position(ui);
+ n = psensor_list_size(sorted_sensors);
+ menu_items = malloc(n * sizeof(GtkWidget *));
+ sensors = malloc((n + 1) * sizeof(struct psensor *));
+ for (i = 0, j = 0; i < n; i++) {
+ if (config_is_appindicator_enabled(sorted_sensors[i]->id)) {
+ sensors[j] = sorted_sensors[i];
+ name = sensors[j]->name;
+
+ menu_items[j] = GTK_MENU_ITEM
+ (gtk_menu_item_new_with_label(name));
+
+ gtk_menu_shell_insert(GTK_MENU_SHELL(menu),
+ GTK_WIDGET(menu_items[j]),
+ j+2);
+
+ update_menu_item(menu_items[j], sensors[j], celcius);
+
+ j++;
+ }
+ }
+
+ sensors[j] = NULL;
+
+ free(sorted_sensors);
+}
+
+static GtkWidget *get_menu(struct ui_psensor *ui)