disabled left click on the color cell (did not find how to disable the row moving...
[psensor.git] / src / ui_sensorlist.c
index b4ac650..4f45c07 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 jeanfi@gmail.com
+ * Copyright (C) 2010-2013 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -36,6 +36,7 @@ enum {
        COL_COLOR_STR,
        COL_ENABLED,
        COL_EMPTY,
+       COL_SENSOR,
        COLS_COUNT
 };
 
@@ -68,24 +69,26 @@ void ui_sensorlist_update(struct ui_psensor *ui)
 
        use_celcius = ui->config->temperature_unit == CELCIUS;
 
-       while (valid && *sensor) {
-               s = *sensor;
+       while (valid) {
+               gtk_tree_model_get(model, &iter, 
+                                  COL_SENSOR, &s, 
+                                  -1);
 
-               str = psensor_value_to_string(s->type,
-                                             s->measures[s->values_max_length -
-                                                         1].value.d_num,
-                                             use_celcius);
+               str = psensor_value_to_str(s->type,
+                                          s->measures[s->values_max_length -
+                                                      1].value,
+                                          use_celcius);
 
                gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_TEMP, str,
                                   -1);
                free(str);
 
-               str = psensor_value_to_string(s->type, s->min, use_celcius);
+               str = psensor_value_to_str(s->type, s->min, use_celcius);
                gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                                   COL_TEMP_MIN, str, -1);
                free(str);
 
-               str = psensor_value_to_string(s->type, s->max, use_celcius);
+               str = psensor_value_to_str(s->type, s->max, use_celcius);
                gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                                   COL_TEMP_MAX, str, -1);
                free(str);
@@ -219,9 +222,13 @@ static GtkWidget *create_sensor_popup(struct ui_psensor *ui,
 
 static int on_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
 {
+       GtkWidget *menu;
        struct ui_psensor *ui = (struct ui_psensor *)data;
        GtkTreeView *view = ui->ui_sensorlist->treeview;
 
+       if (event->button != 3)
+               return FALSE;
+
        struct psensor *sensor = get_sensor_at_pos(view,
                                                   event->x,
                                                   event->y,
@@ -239,8 +246,7 @@ static int on_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
                                                        sensor->color);
                        }
                } else if (coli >= 0 && coli != COL_ENABLED) {
-                       GtkWidget *menu = create_sensor_popup(ui,
-                                                             sensor);
+                       menu = create_sensor_popup(ui, sensor);
 
                        gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
                                       event->button, event->time);
@@ -248,7 +254,7 @@ static int on_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
                }
 
        }
-       return FALSE;
+       return TRUE;
 }
 
 static void
@@ -290,21 +296,9 @@ static void create_widget(struct ui_psensor *ui)
        struct psensor **s_cur = ui->sensors;
        struct ui_sensorlist *ui_sl = ui->ui_sensorlist;
 
-       store = gtk_list_store_new(COLS_COUNT,
-                                  G_TYPE_STRING,
-                                  G_TYPE_STRING,
-                                  G_TYPE_STRING,
-                                  G_TYPE_STRING,
-                                  G_TYPE_STRING,
-                                  G_TYPE_STRING,
-                                  G_TYPE_BOOLEAN, G_TYPE_STRING);
-
-       ui_sl->treeview = GTK_TREE_VIEW
-               (gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
+       store = ui->sensors_store;
 
-       gtk_tree_selection_set_mode
-               (gtk_tree_view_get_selection(ui_sl->treeview),
-                GTK_SELECTION_NONE);
+       ui_sl->treeview = ui->sensors_tree;
 
        renderer = gtk_cell_renderer_text_new();
        gtk_tree_view_insert_column_with_attributes(ui_sl->treeview,
@@ -346,7 +340,7 @@ static void create_widget(struct ui_psensor *ui)
        renderer = gtk_cell_renderer_toggle_new();
        gtk_tree_view_insert_column_with_attributes(ui_sl->treeview,
                                                    -1,
-                                                   _("Enabled"),
+                                                   _("Graph"),
                                                    renderer,
                                                    "active", COL_ENABLED,
                                                    NULL);
@@ -379,22 +373,18 @@ static void create_widget(struct ui_psensor *ui)
                                   COL_TEMP_MIN, _("N/A"),
                                   COL_TEMP_MAX, _("N/A"),
                                   COL_COLOR_STR, scolor,
-                                  COL_ENABLED, s->enabled, -1);
+                                  COL_ENABLED, s->enabled,
+                                  COL_SENSOR, s, -1);
 
                free(scolor);
 
                s_cur++;
        }
-
-       ui_sl->widget = gtk_scrolled_window_new(NULL, NULL);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui_sl->widget),
-                                      GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-       gtk_container_add(GTK_CONTAINER(ui_sl->widget),
-                         GTK_WIDGET(ui_sl->treeview));
 }
 
 void ui_sensorlist_create(struct ui_psensor *ui)
 {
+       log_debug("ui_sensorlist_create()");
        ui->ui_sensorlist = malloc(sizeof(struct ui_sensorlist));
        ui->ui_sensorlist->sensors = ui->sensors;