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"
68 static const char *program_name;
72 printf("psensor %s\n", VERSION);
73 printf(_("Copyright (C) %s jeanfi@gmail.com\n\
74 License GPLv2: GNU GPL version 2 or later \
75 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n\
76 This is free software: you are free to change and redistribute it.\n\
77 There is NO WARRANTY, to the extent permitted by law.\n"),
83 printf(_("Usage: %s [OPTION]...\n"), program_name);
85 puts(_("psensor is a GTK application for monitoring hardware sensors, "
86 "including temperatures and fan speeds."));
91 -h, --help display this help and exit\n\
92 -v, --version display version information and exit"));
98 the URL of the psensor-server, example: http://hostname:3131"));
102 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
104 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
108 Updates the size of the sensor values if different than the
112 update_psensor_values_size(struct psensor **sensors, struct config *cfg)
114 struct psensor **cur;
118 struct psensor *s = *cur;
120 if (s->values_max_length != cfg->sensor_values_max_length)
121 psensor_values_resize(s,
122 cfg->sensor_values_max_length);
128 void update_psensor_measures(struct ui_psensor *ui)
130 struct psensor **sensors = ui->sensors;
131 struct config *cfg = ui->config;
134 g_mutex_lock(ui->sensors_mutex);
139 update_psensor_values_size(sensors, ui->config);
141 psensor_list_update_measures(sensors);
142 #ifdef HAVE_REMOTE_SUPPORT
143 remote_psensor_list_update(sensors);
146 nvidia_psensor_list_update(sensors);
148 #ifdef HAVE_LIBATIADL
149 amd_psensor_list_update(sensors);
151 g_mutex_unlock(ui->sensors_mutex);
153 sleep(cfg->sensor_update_interval);
157 gboolean ui_refresh_thread(gpointer data)
161 struct ui_psensor *ui = (struct ui_psensor *)data;
166 g_mutex_lock(ui->sensors_mutex);
168 graph_update(ui->sensors, ui->w_graph, ui->config);
170 ui_sensorlist_update(ui);
172 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
173 ui_appindicator_update(ui);
177 ui_unity_launcher_entry_update(ui->sensors,
178 !cfg->unity_launcher_count_disabled);
181 if (ui->graph_update_interval != cfg->graph_update_interval) {
182 ui->graph_update_interval = cfg->graph_update_interval;
186 g_mutex_unlock(ui->sensors_mutex);
189 g_timeout_add(1000 * ui->graph_update_interval,
190 ui_refresh_thread, ui);
195 void cb_alarm_raised(struct psensor *sensor, void *data)
197 #ifdef HAVE_LIBNOTIFY
199 ui_notify(sensor, (struct ui_psensor *)data);
203 void associate_colors(struct psensor **sensors)
205 /* number of uniq colors */
206 #define COLORS_COUNT 8
208 unsigned int colors[COLORS_COUNT][3] = {
209 {0x0000, 0x0000, 0x0000}, /* black */
210 {0xffff, 0x0000, 0x0000}, /* red */
211 {0x0000, 0.0000, 0xffff}, /* blue */
212 {0x0000, 0xffff, 0x0000}, /* green */
214 {0x7fff, 0x7fff, 0x7fff}, /* grey */
215 {0x7fff, 0x0000, 0x0000}, /* dark red */
216 {0x0000, 0x0000, 0x7fff}, /* dark blue */
217 {0x0000, 0x7fff, 0x0000} /* dark green */
220 struct psensor **sensor_cur = sensors;
222 while (*sensor_cur) {
223 struct color default_color;
224 color_set(&default_color,
225 colors[i % COLORS_COUNT][0],
226 colors[i % COLORS_COUNT][1],
227 colors[i % COLORS_COUNT][2]);
230 = config_get_sensor_color((*sensor_cur)->id,
239 associate_cb_alarm_raised(struct psensor **sensors, struct ui_psensor *ui)
241 struct psensor **sensor_cur = sensors;
242 while (*sensor_cur) {
243 struct psensor *s = *sensor_cur;
245 s->cb_alarm_raised = cb_alarm_raised;
246 s->cb_alarm_raised_data = ui;
248 if (is_temp_type(s->type)) {
250 = config_get_sensor_alarm_limit(s->id, 60);
252 = config_get_sensor_alarm_enabled(s->id);
255 s->alarm_enabled = 0;
262 void associate_preferences(struct psensor **sensors)
264 struct psensor **sensor_cur = sensors;
265 while (*sensor_cur) {
267 struct psensor *s = *sensor_cur;
269 s->enabled = config_is_sensor_enabled(s->id);
271 n = config_get_sensor_name(s->id);
281 static struct option long_options[] = {
282 {"version", no_argument, 0, 'v'},
283 {"help", no_argument, 0, 'h'},
284 {"url", required_argument, 0, 'u'},
288 int main(int argc, char **argv)
290 struct ui_psensor ui;
297 program_name = argv[0];
299 setlocale(LC_ALL, "");
302 bindtextdomain(PACKAGE, LOCALEDIR);
306 while ((optc = getopt_long(argc, argv, "vhu:", long_options,
311 url = strdup(optarg);
325 if (!cmdok || optind != argc) {
326 fprintf(stderr, _("Try `%s --help' for more information.\n"),
333 /* gdk_threads_enter(); */
335 gtk_init(&argc, &argv);
337 #ifdef HAVE_LIBNOTIFY
338 ui.notification_last_time = NULL;
341 ui.sensors_mutex = g_mutex_new();
345 ui.config = config_load();
350 #ifdef HAVE_REMOTE_SUPPORT
352 ui.sensors = get_remote_sensors(url, 600);
355 _("ERROR: Not compiled with remote sensor support.\n"));
359 ui.sensors = get_all_sensors(600);
361 ui.sensors = nvidia_psensor_list_add(ui.sensors, 600);
363 #ifdef HAVE_LIBATIADL
364 ui.sensors = amd_psensor_list_add(ui.sensors, 600);
368 associate_preferences(ui.sensors);
369 associate_colors(ui.sensors);
370 associate_cb_alarm_raised(ui.sensors, &ui);
373 ui_window_create(&ui);
374 ui.sensor_box = NULL;
377 ui.w_graph = ui_graph_create(&ui);
380 ui_sensorlist_create(&ui);
382 ui_window_update(&ui);
384 thread = g_thread_create((GThreadFunc) update_psensor_measures,
390 ui.graph_update_interval = ui.config->graph_update_interval;
392 g_timeout_add(1000 * ui.graph_update_interval, ui_refresh_thread, &ui);
394 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
395 ui_appindicator_init(&ui);
403 psensor_list_free(ui.sensors);
408 #ifdef HAVE_LIBATIADL