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"
50 #ifdef HAVE_REMOTE_SUPPORT
54 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
55 #include "ui_appindicator.h"
59 #include "ui_notify.h"
64 static const char *program_name;
68 printf("psensor %s\n", VERSION);
69 printf(_("Copyright (C) %s jeanfi@gmail.com\n\
70 License GPLv2: GNU GPL version 2 or later \
71 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n\
72 This is free software: you are free to change and redistribute it.\n\
73 There is NO WARRANTY, to the extent permitted by law.\n"),
79 printf(_("Usage: %s [OPTION]...\n"), program_name);
81 puts(_("psensor is a GTK application for monitoring hardware sensors, "
82 "including temperatures and fan speeds."));
87 -h, --help display this help and exit\n\
88 -v, --version display version information and exit"));
94 the URL of the psensor-server, example: http://hostname:3131"));
98 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
100 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
104 Updates the size of the sensor values if different than the
108 update_psensor_values_size(struct psensor **sensors, struct config *cfg)
110 struct psensor **cur;
114 struct psensor *s = *cur;
116 if (s->values_max_length != cfg->sensor_values_max_length)
117 psensor_values_resize(s,
118 cfg->sensor_values_max_length);
124 void update_psensor_measures(struct ui_psensor *ui)
126 struct psensor **sensors = ui->sensors;
127 struct config *cfg = ui->config;
130 g_mutex_lock(ui->sensors_mutex);
135 update_psensor_values_size(sensors, ui->config);
137 psensor_list_update_measures(sensors);
138 #ifdef HAVE_REMOTE_SUPPORT
139 remote_psensor_list_update(sensors);
142 nvidia_psensor_list_update(sensors);
145 g_mutex_unlock(ui->sensors_mutex);
147 sleep(cfg->sensor_update_interval);
151 gboolean ui_refresh_thread(gpointer data)
155 struct ui_psensor *ui = (struct ui_psensor *)data;
160 g_mutex_lock(ui->sensors_mutex);
162 graph_update(ui->sensors, ui->w_graph, ui->config);
164 ui_sensorlist_update(ui);
166 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
167 ui_appindicator_update(ui);
171 ui_unity_launcher_entry_update(ui->sensors,
172 !cfg->unity_launcher_count_disabled);
175 if (ui->graph_update_interval != cfg->graph_update_interval) {
176 ui->graph_update_interval = cfg->graph_update_interval;
180 g_mutex_unlock(ui->sensors_mutex);
183 g_timeout_add(1000 * ui->graph_update_interval,
184 ui_refresh_thread, ui);
189 void cb_alarm_raised(struct psensor *sensor, void *data)
191 #ifdef HAVE_LIBNOTIFY
193 ui_notify(sensor, (struct ui_psensor *)data);
197 void associate_colors(struct psensor **sensors)
199 /* number of uniq colors */
200 #define COLORS_COUNT 8
202 unsigned int colors[COLORS_COUNT][3] = {
203 {0x0000, 0x0000, 0x0000}, /* black */
204 {0xffff, 0x0000, 0x0000}, /* red */
205 {0x0000, 0.0000, 0xffff}, /* blue */
206 {0x0000, 0xffff, 0x0000}, /* green */
208 {0x7fff, 0x7fff, 0x7fff}, /* grey */
209 {0x7fff, 0x0000, 0x0000}, /* dark red */
210 {0x0000, 0x0000, 0x7fff}, /* dark blue */
211 {0x0000, 0x7fff, 0x0000} /* dark green */
214 struct psensor **sensor_cur = sensors;
216 while (*sensor_cur) {
217 struct color default_color;
218 color_set(&default_color,
219 colors[i % COLORS_COUNT][0],
220 colors[i % COLORS_COUNT][1],
221 colors[i % COLORS_COUNT][2]);
224 = config_get_sensor_color((*sensor_cur)->id,
233 associate_cb_alarm_raised(struct psensor **sensors, struct ui_psensor *ui)
235 struct psensor **sensor_cur = sensors;
236 while (*sensor_cur) {
237 struct psensor *s = *sensor_cur;
239 s->cb_alarm_raised = cb_alarm_raised;
240 s->cb_alarm_raised_data = ui;
242 if (is_temp_type(s->type)) {
244 = config_get_sensor_alarm_limit(s->id, 60);
246 = config_get_sensor_alarm_enabled(s->id);
249 s->alarm_enabled = 0;
256 void associate_preferences(struct psensor **sensors)
258 struct psensor **sensor_cur = sensors;
259 while (*sensor_cur) {
261 struct psensor *s = *sensor_cur;
263 s->enabled = config_is_sensor_enabled(s->id);
265 n = config_get_sensor_name(s->id);
275 static struct option long_options[] = {
276 {"version", no_argument, 0, 'v'},
277 {"help", no_argument, 0, 'h'},
278 {"url", required_argument, 0, 'u'},
282 int main(int argc, char **argv)
284 struct ui_psensor ui;
291 program_name = argv[0];
293 setlocale(LC_ALL, "");
296 bindtextdomain(PACKAGE, LOCALEDIR);
300 while ((optc = getopt_long(argc, argv, "vhu:", long_options,
305 url = strdup(optarg);
319 if (!cmdok || optind != argc) {
320 fprintf(stderr, _("Try `%s --help' for more information.\n"),
327 /* gdk_threads_enter(); */
329 gtk_init(&argc, &argv);
331 #ifdef HAVE_LIBNOTIFY
332 ui.notification_last_time = NULL;
335 ui.sensors_mutex = g_mutex_new();
339 ui.config = config_load();
344 #ifdef HAVE_REMOTE_SUPPORT
346 ui.sensors = get_remote_sensors(url, 600);
349 _("ERROR: Not compiled with remote sensor support.\n"));
353 ui.sensors = get_all_sensors(600);
355 ui.sensors = nvidia_psensor_list_add(ui.sensors, 600);
359 associate_preferences(ui.sensors);
360 associate_colors(ui.sensors);
361 associate_cb_alarm_raised(ui.sensors, &ui);
364 ui_window_create(&ui);
365 ui.sensor_box = NULL;
368 ui.w_graph = ui_graph_create(&ui);
371 ui_sensorlist_create(&ui);
373 ui_window_update(&ui);
375 thread = g_thread_create((GThreadFunc) update_psensor_measures,
381 ui.graph_update_interval = ui.config->graph_update_interval;
383 g_timeout_add(1000 * ui.graph_update_interval, ui_refresh_thread, &ui);
385 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
386 ui_appindicator_init(&ui);
394 psensor_list_free(ui.sensors);