static gboolean percent_change (gpointer user_data) { percentage = (percentage + 1) % 100; if (can_haz_label) { gchar * percentstr = g_strdup_printf("%d%%", percentage + 1); app_indicator_set_label (APP_INDICATOR(user_data), percentstr, "100%"); g_free(percentstr); } else { app_indicator_set_label (APP_INDICATOR(user_data), NULL, NULL); } return TRUE; }
static void is_indicator_set_label(IsIndicator *self, const gchar *label) { #if HAVE_APPINDICATOR app_indicator_set_label(APP_INDICATOR(self), label, label); #else gtk_status_icon_set_tooltip_text(GTK_STATUS_ICON(self), label); #endif }
static GtkMenu * is_indicator_get_menu(IsIndicator *self) { GtkMenu *menu; #if HAVE_APPINDICATOR menu = app_indicator_get_menu(APP_INDICATOR(self)); #else menu = GTK_MENU(g_object_get_data(G_OBJECT(self), "indicator-menu")); #endif return menu; }
static void is_indicator_set_menu(IsIndicator *self, GtkMenu *menu) { #if HAVE_APPINDICATOR app_indicator_set_menu(APP_INDICATOR(self), menu); #else g_object_set_data_full(G_OBJECT(self), "indicator-menu", menu, (GDestroyNotify)gtk_widget_destroy); g_signal_connect(self, "popup-menu", G_CALLBACK(popup_menu), self); #endif }
static void impl_activate(PeasActivatable *activatable) { XmrIndicatorPlugin *plugin; XmrWindow *window = NULL; XmrPlayer *player; plugin = XMR_INDICATOR_PLUGIN(activatable); g_object_get(plugin, "object", &window, NULL); if (window) { plugin->window = window; if (!plugin->indicator) { #if HAVE_APP_INDICATOR gchar *icon_path; plugin->indicator = xmr_app_indicator_new(plugin->popup_menu); icon_path = g_build_filename(xmr_app_dir(), "icons", NULL); if (g_file_test(icon_path, G_FILE_TEST_EXISTS)) app_indicator_set_icon_theme_path(APP_INDICATOR(plugin->indicator), icon_path); g_free(icon_path); #else plugin->indicator = xmr_tray_icon_new(GTK_WIDGET(window), plugin->popup_menu); #endif } g_signal_connect(window, "delete-event", G_CALLBACK(on_xmr_window_delete), plugin); g_signal_connect(window, "track-changed", G_CALLBACK(track_changed), plugin); g_object_get(window, "player", &player, NULL); if (player) { g_signal_connect(player, "state-changed", G_CALLBACK(player_state_changed), plugin); g_object_unref(player); } } plugin->hide_on_exit = g_settings_get_boolean(plugin->settings, "hide-on-exit"); g_signal_connect(plugin->settings, "changed", G_CALLBACK(on_settings_changed), plugin); if (xmr_window_playing(plugin->window)){ gtk_widget_hide(plugin->menu_item_play); } else { gtk_widget_hide(plugin->menu_item_pause); } }
static void local_icon_toggle_cb (GtkWidget *widget, gpointer data) { AppIndicator * ci = APP_INDICATOR(data); if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) { app_indicator_set_icon_full(ci, LOCAL_ICON, "Local Icon"); } else { app_indicator_set_icon_full(ci, "indicator-messages", "System Icon"); } return; }
static void activate_clicked_cb (GtkWidget *widget, gpointer data) { AppIndicator * ci = APP_INDICATOR(data); if (active) { app_indicator_set_status (ci, APP_INDICATOR_STATUS_ATTENTION); gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "I'm okay now"); active = FALSE; } else { app_indicator_set_status (ci, APP_INDICATOR_STATUS_ACTIVE); gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "Get Attention"); active = TRUE; } }
static void is_indicator_constructed(GObject *object) { IsIndicator *self = IS_INDICATOR(object); GtkActionGroup *action_group; GtkUIManager *ui_manager; GError *error = NULL; GtkWidget *menu; action_group = gtk_action_group_new("AppActions"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, entries, n_entries, self); ui_manager = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); if (!gtk_ui_manager_add_ui_from_string(ui_manager, ui_info, -1, &error)) { g_error("Failed to build menus: %s\n", error->message); } menu = gtk_ui_manager_get_widget(ui_manager, "/ui/Indicator"); /* manually add separator since specifying it in the ui description means it gets optimised out (since there is no menu item above it) but if we manually add it and show the whole menu then all is good... */ gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); gtk_widget_show_all(menu); is_indicator_set_label(self, _("No Sensors")); is_indicator_set_menu(self, GTK_MENU(menu)); #if HAVE_APPINDICATOR app_indicator_set_status(APP_INDICATOR(self), APP_INDICATOR_STATUS_ACTIVE); #endif fake_add_enable_sensors(IS_INDICATOR(object)); }
static void update_sensor_menu_item_label(IsIndicator *self, IsSensor *sensor, GtkMenuItem *menu_item) { gchar *text; text = g_strdup_printf("%s %2.*f%s", is_sensor_get_label(sensor), is_sensor_get_digits(sensor), is_sensor_get_value(sensor), is_sensor_get_units(sensor)); gtk_menu_item_set_label(menu_item, text); g_free(text); text = NULL; #if HAVE_APPINDICATOR if (sensor == self->priv->primary) { IsIndicatorPrivate *priv = self->priv; gboolean connected; g_object_get(self, "connected", &connected, NULL); /* using fallback so just set icon */ if (!connected) { app_indicator_set_icon_full(APP_INDICATOR(self), PACKAGE, is_sensor_get_label(sensor)); return; } if (priv->display_flags & IS_INDICATOR_DISPLAY_VALUE) { text = g_strdup_printf("%2.*f%s", is_sensor_get_digits(sensor), is_sensor_get_value(sensor), is_sensor_get_units(sensor)); } if (priv->display_flags & IS_INDICATOR_DISPLAY_LABEL) { /* join label to existing text - if text is NULL this will just show label */ text = g_strjoin(" ", is_sensor_get_label(sensor), text, NULL); } if (priv->display_flags & IS_INDICATOR_DISPLAY_ICON) { app_indicator_set_icon_full(APP_INDICATOR(self), is_sensor_get_icon_path(sensor), is_sensor_get_label(sensor)); } else { /* set to a 1x1 transparent icon for no icon */ app_indicator_set_icon_full(APP_INDICATOR(self), "indicator-sensors-no-icon", is_sensor_get_label(sensor)); } app_indicator_set_label(APP_INDICATOR(self), text, text); g_free(text); app_indicator_set_status(APP_INDICATOR(self), is_sensor_get_alarmed(sensor) ? APP_INDICATOR_STATUS_ATTENTION : APP_INDICATOR_STATUS_ACTIVE); } #else gtk_status_icon_set_from_icon_name(GTK_STATUS_ICON(self), PACKAGE); #endif }