2 Copyright (C) 2010-2011 jeanfi@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
36 #include "ui_sensorlist.h"
54 #ifdef HAVE_REMOTE_SUPPORT
58 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
59 #include "ui_appindicator.h"
63 #include "ui_notify.h"
72 static const char *program_name;
76 printf("psensor %s\n", VERSION);
77 printf(_("Copyright (C) %s jeanfi@gmail.com\n\
78 License GPLv2: GNU GPL version 2 or later \
79 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n\
80 This is free software: you are free to change and redistribute it.\n\
81 There is NO WARRANTY, to the extent permitted by law.\n"),
87 printf(_("Usage: %s [OPTION]...\n"), program_name);
89 puts(_("psensor is a GTK application for monitoring hardware sensors, "
90 "including temperatures and fan speeds."));
95 -h, --help display this help and exit\n\
96 -v, --version display version information and exit"));
102 the URL of the psensor-server, example: http://hostname:3131"));
106 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
108 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
112 Updates the size of the sensor values if different than the
116 update_psensor_values_size(struct psensor **sensors, struct config *cfg)
118 struct psensor **cur;
122 struct psensor *s = *cur;
124 if (s->values_max_length != cfg->sensor_values_max_length)
125 psensor_values_resize(s,
126 cfg->sensor_values_max_length);
132 void update_psensor_measures(struct ui_psensor *ui)
134 struct psensor **sensors = ui->sensors;
135 struct config *cfg = ui->config;
138 g_mutex_lock(ui->sensors_mutex);
143 update_psensor_values_size(sensors, ui->config);
145 psensor_list_update_measures(sensors);
146 #ifdef HAVE_REMOTE_SUPPORT
147 remote_psensor_list_update(sensors);
150 nvidia_psensor_list_update(sensors);
152 #ifdef HAVE_LIBATIADL
153 amd_psensor_list_update(sensors);
155 g_mutex_unlock(ui->sensors_mutex);
157 sleep(cfg->sensor_update_interval);
161 gboolean ui_refresh_thread(gpointer data)
165 struct ui_psensor *ui = (struct ui_psensor *)data;
170 g_mutex_lock(ui->sensors_mutex);
172 graph_update(ui->sensors, ui->w_graph, ui->config);
174 ui_sensorlist_update(ui);
176 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
177 ui_appindicator_update(ui);
181 ui_unity_launcher_entry_update(ui->sensors,
182 !cfg->unity_launcher_count_disabled);
185 if (ui->graph_update_interval != cfg->graph_update_interval) {
186 ui->graph_update_interval = cfg->graph_update_interval;
190 g_mutex_unlock(ui->sensors_mutex);
193 g_timeout_add(1000 * ui->graph_update_interval,
194 ui_refresh_thread, ui);
199 void cb_alarm_raised(struct psensor *sensor, void *data)
201 #ifdef HAVE_LIBNOTIFY
203 ui_notify(sensor, (struct ui_psensor *)data);
207 void associate_colors(struct psensor **sensors)
209 /* number of uniq colors */
210 #define COLORS_COUNT 8
212 unsigned int colors[COLORS_COUNT][3] = {
213 {0x0000, 0x0000, 0x0000}, /* black */
214 {0xffff, 0x0000, 0x0000}, /* red */
215 {0x0000, 0.0000, 0xffff}, /* blue */
216 {0x0000, 0xffff, 0x0000}, /* green */
218 {0x7fff, 0x7fff, 0x7fff}, /* grey */
219 {0x7fff, 0x0000, 0x0000}, /* dark red */
220 {0x0000, 0x0000, 0x7fff}, /* dark blue */
221 {0x0000, 0x7fff, 0x0000} /* dark green */
224 struct psensor **sensor_cur = sensors;
226 while (*sensor_cur) {
227 struct color default_color;
228 color_set(&default_color,
229 colors[i % COLORS_COUNT][0],
230 colors[i % COLORS_COUNT][1],
231 colors[i % COLORS_COUNT][2]);
234 = config_get_sensor_color((*sensor_cur)->id,
243 associate_cb_alarm_raised(struct psensor **sensors, struct ui_psensor *ui)
245 struct psensor **sensor_cur = sensors;
246 while (*sensor_cur) {
247 struct psensor *s = *sensor_cur;
249 s->cb_alarm_raised = cb_alarm_raised;
250 s->cb_alarm_raised_data = ui;
252 if (is_temp_type(s->type)) {
254 = config_get_sensor_alarm_limit(s->id, 60);
256 = config_get_sensor_alarm_enabled(s->id);
259 s->alarm_enabled = 0;
266 void associate_preferences(struct psensor **sensors)
268 struct psensor **sensor_cur = sensors;
269 while (*sensor_cur) {
271 struct psensor *s = *sensor_cur;
273 s->enabled = config_is_sensor_enabled(s->id);
275 n = config_get_sensor_name(s->id);
285 static struct option long_options[] = {
286 {"version", no_argument, 0, 'v'},
287 {"help", no_argument, 0, 'h'},
288 {"url", required_argument, 0, 'u'},
292 int main(int argc, char **argv)
294 struct ui_psensor ui;
301 program_name = argv[0];
303 setlocale(LC_ALL, "");
306 bindtextdomain(PACKAGE, LOCALEDIR);
310 while ((optc = getopt_long(argc, argv, "vhu:", long_options,
315 url = strdup(optarg);
329 if (!cmdok || optind != argc) {
330 fprintf(stderr, _("Try `%s --help' for more information.\n"),
337 /* gdk_threads_enter(); */
339 gtk_init(&argc, &argv);
341 #ifdef HAVE_LIBNOTIFY
342 ui.notification_last_time = NULL;
345 ui.sensors_mutex = g_mutex_new();
349 ui.config = config_load();
354 #ifdef HAVE_REMOTE_SUPPORT
356 ui.sensors = get_remote_sensors(url, 600);
359 _("ERROR: Not compiled with remote sensor support.\n"));
363 ui.sensors = get_all_sensors(600);
365 ui.sensors = nvidia_psensor_list_add(ui.sensors, 600);
367 #ifdef HAVE_LIBATIADL
368 ui.sensors = amd_psensor_list_add(ui.sensors, 600);
371 ui.sensors = cpu_psensor_list_add(ui.sensors, 600);
375 associate_preferences(ui.sensors);
376 associate_colors(ui.sensors);
377 associate_cb_alarm_raised(ui.sensors, &ui);
380 ui_window_create(&ui);
381 ui.sensor_box = NULL;
384 ui.w_graph = ui_graph_create(&ui);
387 ui_sensorlist_create(&ui);
389 ui_window_update(&ui);
391 thread = g_thread_create((GThreadFunc) update_psensor_measures,
397 ui.graph_update_interval = ui.config->graph_update_interval;
399 g_timeout_add(1000 * ui.graph_update_interval, ui_refresh_thread, &ui);
401 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
402 ui_appindicator_init(&ui);
410 psensor_list_free(ui.sensors);
415 #ifdef HAVE_LIBATIADL