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
20
19
#include <locale.h>
22
#define _(str) gettext(str)
24
21
#include <getopt.h>
26
23
#include <stdlib.h>
27
24
#include <string.h>
28
25
#include <unistd.h>
27
#include <sys/types.h>
30
29
#include <gtk/gtk.h>
32
#include <sensors/sensors.h>
33
#include <sensors/error.h>
35
31
#include "config.h"
42
38
#include "ui_color.h"
43
39
#include "lmsensor.h"
44
40
#include "ui_pref.h"
42
#include "ui_status.h"
47
49
#include "nvidia.h"
50
56
#ifdef HAVE_REMOTE_SUPPORT
51
57
#include "rsensor.h"
54
#if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
55
60
#include "ui_appindicator.h"
58
62
#ifdef HAVE_LIBNOTIFY
59
63
#include "ui_notify.h"
62
70
#include "compat.h"
64
72
static const char *program_name;
74
static void print_version()
68
76
printf("psensor %s\n", VERSION);
69
printf(_("Copyright (C) %s wpitchoune@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"),
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 "
82
"There is NO WARRANTY, to the extent permitted by law.\n"),
86
static void print_help()
79
88
printf(_("Usage: %s [OPTION]...\n"), program_name);
100
112
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
104
cb_preferences(gpointer data, guint callback_action, GtkWidget *item)
106
ui_pref_dialog_run((struct ui_psensor *)data);
109
static GtkItemFactoryEntry menu_items[] = {
111
NULL, cb_preferences, 0, "<Item>"},
114
NULL, NULL, 0, "<Separator>"},
117
"", ui_psensor_exit, 0, "<StockItem>", GTK_STOCK_QUIT},
120
static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
123
116
Updates the size of the sensor values if different than the
160
165
#ifdef HAVE_NVIDIA
161
166
nvidia_psensor_list_update(sensors);
168
#ifdef HAVE_LIBATIADL
169
amd_psensor_list_update(sensors);
172
log_measures(sensors);
174
g_mutex_unlock(ui->sensors_mutex);
166
176
sleep(cfg->sensor_update_interval);
180
static void indicators_update(struct ui_psensor *ui)
182
struct psensor **sensor_cur = ui->sensors;
183
unsigned int attention = 0;
185
while (*sensor_cur) {
186
struct psensor *s = *sensor_cur;
188
if (s->alarm_enabled && s->alarm_raised) {
196
#if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
197
if (is_appindicator_supported())
198
ui_appindicator_update(ui, attention);
201
if (is_status_supported())
202
ui_status_update(ui, attention);
170
205
gboolean ui_refresh_thread(gpointer data)
172
207
struct config *cfg;
298
GtkWidget *ui_get_popupmenu(gpointer data)
300
GtkItemFactory *item_factory;
303
item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
304
gtk_item_factory_create_items(item_factory,
305
nmenu_items, menu_items, data);
306
menu = gtk_item_factory_get_widget(item_factory, "<main>");
311
int on_graph_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
315
if (event->type != GDK_BUTTON_PRESS)
318
menu = ui_get_popupmenu(data);
320
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
321
event->button, event->time);
327
GtkWidget *create_graph_widget(struct ui_psensor * ui)
331
w_graph = gtk_drawing_area_new();
333
g_signal_connect(G_OBJECT(w_graph),
334
"expose-event", G_CALLBACK(on_expose_event), ui);
336
gtk_widget_add_events(w_graph, GDK_BUTTON_PRESS_MASK);
337
gtk_signal_connect(GTK_OBJECT(w_graph),
338
"button_press_event",
339
(GCallback) on_graph_clicked, ui);
344
void ui_main_box_create(struct ui_psensor *ui)
347
GtkWidget *w_sensorlist;
352
ui_sensorlist_create_widget(ui->ui_sensorlist);
354
gtk_container_remove(GTK_CONTAINER(ui->main_window),
357
ui->w_graph = create_graph_widget(ui);
358
ui->w_sensorlist = ui->ui_sensorlist->widget;
361
if (cfg->sensorlist_position == SENSORLIST_POSITION_RIGHT
362
|| cfg->sensorlist_position == SENSORLIST_POSITION_LEFT)
363
ui->main_box = gtk_hpaned_new();
365
ui->main_box = gtk_vpaned_new();
367
w_sensorlist = gtk_scrolled_window_new(NULL, NULL);
368
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w_sensorlist),
369
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
370
gtk_container_add(GTK_CONTAINER(w_sensorlist),
371
ui->ui_sensorlist->widget);
373
gtk_container_add(GTK_CONTAINER(ui->main_window), ui->main_box);
375
if (cfg->sensorlist_position == SENSORLIST_POSITION_RIGHT
376
|| cfg->sensorlist_position == SENSORLIST_POSITION_BOTTOM) {
377
gtk_paned_pack1(GTK_PANED(ui->main_box),
378
GTK_WIDGET(ui->w_graph), TRUE, TRUE);
379
gtk_paned_pack2(GTK_PANED(ui->main_box),
380
w_sensorlist, FALSE, TRUE);
382
gtk_paned_pack1(GTK_PANED(ui->main_box),
383
w_sensorlist, FALSE, TRUE);
384
gtk_paned_pack2(GTK_PANED(ui->main_box),
385
GTK_WIDGET(ui->w_graph), TRUE, TRUE);
388
gtk_widget_show_all(ui->main_box);
327
static void log_init()
329
char *home, *path, *dir;
331
home = getenv("HOME");
336
dir = malloc(strlen(home)+1+strlen(".psensor")+1);
337
sprintf(dir, "%s/%s", home, ".psensor");
340
path = malloc(strlen(dir)+1+strlen("log")+1);
341
sprintf(path, "%s/%s", dir, "log");
391
349
static struct option long_options[] = {
392
350
{"version", no_argument, 0, 'v'},
393
351
{"help", no_argument, 0, 'h'},
394
352
{"url", required_argument, 0, 'u'},
353
{"debug", required_argument, 0, 'd'},
357
static gboolean initial_window_show(gpointer data)
359
struct ui_psensor *ui;
361
log_debug("initial_window_show()");
363
ui = (struct ui_psensor *)data;
365
log_debug("is_status_supported: %d", is_status_supported());
366
log_debug("is_appindicator_supported: %d",
367
is_appindicator_supported());
368
log_debug("hide_on_startup: %d", ui->config->hide_on_startup);
370
if (!ui->config->hide_on_startup
371
|| (!is_appindicator_supported() && !is_status_supported()))
374
ui_window_update(ui);
398
379
int main(int argc, char **argv)
400
381
struct ui_psensor ui;
404
385
char *url = NULL;
407
387
program_name = argv[0];