2
Copyright (C) 2010-2011 wpitchoune@gmail.com
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2
* Copyright (C) 2010-2011 jeanfi@gmail.com
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
20
#include <stdlib.h>
22
21
#include <string.h>
58
GtkWidget *ui_appindicator_get_menu(struct ui_psensor *ui)
60
GtkWidget *menu, *item;
62
menu = gtk_menu_new();
64
item = gtk_menu_item_new_with_label(_("Show"));
65
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
66
g_signal_connect(item,
67
"activate", G_CALLBACK(cb_appindicator_show), ui);
69
item = gtk_menu_item_new_with_label(_("Preferences"));
70
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
71
g_signal_connect(item,
72
"activate", G_CALLBACK(cb_appindicator_preferences),
75
item = gtk_separator_menu_item_new();
76
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
78
item = gtk_menu_item_new_with_label(_("Quit"));
79
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
80
g_signal_connect(item,
81
"activate", G_CALLBACK(cb_appindicator_quit), ui);
83
gtk_widget_show_all(menu);
88
void ui_appindicator_update(struct ui_psensor *ui)
90
struct psensor **sensor_cur = ui->sensors;
65
static void cb_sensor_preferences(GtkMenuItem *mi, gpointer data)
67
struct ui_psensor *ui = data;
69
#ifdef HAVE_APPINDICATOR_029
73
if (ui->sensors && *ui->sensors)
74
ui_sensorpref_dialog_run(*ui->sensors, ui);
76
#ifdef HAVE_APPINDICATOR_029
81
static void cb_about(GtkMenuItem *mi, gpointer data)
83
ui_show_about_dialog();
86
static const char *menu_desc =
88
" <popup name='MainMenu'>"
89
" <menuitem name='Show' action='ShowAction' />"
92
" <menuitem name='Preferences' action='PreferencesAction' />"
93
" <menuitem name='SensorPreferences' action='SensorPreferencesAction' />"
95
" <menuitem name='About' action='AboutAction' />"
97
" <menuitem name='Quit' action='QuitAction' />"
101
static GtkActionEntry entries[] = {
102
{ "PsensorMenuAction", NULL, "_Psensor" },
104
{ "ShowAction", NULL,
107
G_CALLBACK(cb_menu_show) },
109
{ "PreferencesAction", GTK_STOCK_PREFERENCES,
110
"_Preferences", NULL,
112
G_CALLBACK(cb_menu_preferences) },
114
{ "SensorPreferencesAction", GTK_STOCK_PREFERENCES,
115
"S_ensor Preferences",
118
G_CALLBACK(cb_sensor_preferences) },
120
{ "AboutAction", NULL,
124
G_CALLBACK(cb_about) },
127
GTK_STOCK_QUIT, "_Quit", NULL, "Quit", G_CALLBACK(cb_menu_quit) }
129
static guint n_entries = G_N_ELEMENTS(entries);
131
static void update_sensor_menu_item(GtkMenuItem *item, struct psensor *s)
135
str = g_strdup_printf("%s: %2.f %s",
137
psensor_get_current_value(s),
138
psensor_type_to_unit_str(s->type));
140
gtk_menu_item_set_label(item, str);
145
static void update_sensor_menu_items(struct psensor **sensors)
149
n = psensor_list_size(sensors);
150
for (i = 0; i < n; i++)
151
update_sensor_menu_item(sensor_menu_items[i], sensors[i]);
154
static GtkWidget *get_menu(struct ui_psensor *ui)
156
GtkActionGroup *action_group;
157
GtkUIManager *menu_manager;
161
int n = psensor_list_size(ui->sensors);
162
struct psensor **sensors = ui->sensors;
165
action_group = gtk_action_group_new("PsensorActions");
166
gtk_action_group_set_translation_domain(action_group, PACKAGE);
167
menu_manager = gtk_ui_manager_new();
169
gtk_action_group_add_actions(action_group, entries, n_entries, ui);
170
gtk_ui_manager_insert_action_group(menu_manager, action_group, 0);
173
gtk_ui_manager_add_ui_from_string(menu_manager, menu_desc, -1, &error);
176
g_error(_("building menus failed: %s"), error->message);
178
menu = GTK_MENU(gtk_ui_manager_get_widget(menu_manager, "/MainMenu"));
180
sensor_menu_items = malloc(sizeof(GtkWidget *)*n);
181
for (i = 0; i < n; i++) {
182
struct psensor *s = sensors[i];
185
= GTK_MENU_ITEM(gtk_menu_item_new_with_label(s->name));
187
gtk_menu_shell_insert(GTK_MENU_SHELL(menu),
188
GTK_WIDGET(sensor_menu_items[i]),
191
update_sensor_menu_item(sensor_menu_items[i],
196
return GTK_WIDGET(menu);
199
void ui_appindicator_update(struct ui_psensor *ui, unsigned int attention)
91
201
AppIndicatorStatus status;
98
struct psensor *s = *sensor_cur;
100
if (s->alarm_enabled && s->alarm_raised) {
108
status = app_indicator_get_status(ui->indicator);
206
status = app_indicator_get_status(indicator);
110
208
if (!attention && status == APP_INDICATOR_STATUS_ATTENTION)
111
209
app_indicator_set_status
112
(ui->indicator, APP_INDICATOR_STATUS_ACTIVE);
210
(indicator, APP_INDICATOR_STATUS_ACTIVE);
114
212
if (attention && status == APP_INDICATOR_STATUS_ACTIVE)
115
213
app_indicator_set_status
116
(ui->indicator, APP_INDICATOR_STATUS_ATTENTION);
214
(indicator, APP_INDICATOR_STATUS_ATTENTION);
216
update_sensor_menu_items(ui->sensors);
219
static GtkStatusIcon *unity_fallback(AppIndicator *indicator)
221
log_debug("ui_appindicator#unity_fallback");
223
appindicator_supported = 0;
225
return ui_status_get_icon(ui_psensor);
229
unity_unfallback(AppIndicator *indicator, GtkStatusIcon *status_icon)
231
log_debug("ui_appindicator#unity_unfallback");
233
appindicator_supported = 1;
119
236
void ui_appindicator_init(struct ui_psensor *ui)
121
GtkWidget *indicatormenu;
124
= app_indicator_new("psensor",
126
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
128
indicatormenu = ui_appindicator_get_menu(ui);
130
app_indicator_set_status(ui->indicator, APP_INDICATOR_STATUS_ACTIVE);
131
app_indicator_set_attention_icon(ui->indicator, "psensor_hot");
133
app_indicator_set_menu(ui->indicator, GTK_MENU(indicatormenu));
241
main_window = ui->main_window;
243
indicator = app_indicator_new
246
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
248
APP_INDICATOR_GET_CLASS(indicator)->fallback = unity_fallback;
249
APP_INDICATOR_GET_CLASS(indicator)->unfallback = unity_unfallback;
251
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
252
app_indicator_set_attention_icon(indicator, ATTENTION_ICON);
255
app_indicator_set_menu(indicator, GTK_MENU(menu));
257
gtk_widget_show_all(menu);
260
int is_appindicator_supported()
262
return appindicator_supported;
265
void ui_appindicator_cleanup()
267
/* TODO: cleanup menu items. */