[gnome-control-center] color: Do not show the user display types the selected sensor does not support
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] color: Do not show the user display types the selected sensor does not support
- Date: Wed, 6 Feb 2013 15:23:09 +0000 (UTC)
commit edc9286a0afdcbd33c071d66d2b4153e80bf44b9
Author: Richard Hughes <richard hughsie com>
Date: Wed Feb 6 13:24:07 2013 +0000
color: Do not show the user display types the selected sensor does not support
Additionally, hide the display types page if the sensor only supports one
display technology.
panels/color/cc-color-calibrate.c | 4 +-
panels/color/cc-color-panel.c | 87 +++++++++++++++++++++++++++++++++++-
panels/color/color.ui | 55 ++++++++++++++---------
3 files changed, 119 insertions(+), 27 deletions(-)
---
diff --git a/panels/color/cc-color-calibrate.c b/panels/color/cc-color-calibrate.c
index 5569571..70644d2 100644
--- a/panels/color/cc-color-calibrate.c
+++ b/panels/color/cc-color-calibrate.c
@@ -79,7 +79,6 @@ cc_color_calibrate_set_kind (CcColorCalibrate *calibrate,
CdSensorCap kind)
{
g_return_if_fail (CC_IS_COLOR_CALIB (calibrate));
- g_return_if_fail (kind != CD_SENSOR_CAP_UNKNOWN);
calibrate->priv->device_kind = kind;
}
@@ -854,7 +853,8 @@ cc_color_calibrate_setup (CcColorCalibrate *calibrate,
gboolean ret = TRUE;
g_return_val_if_fail (CC_IS_COLOR_CALIB (calibrate), FALSE);
-
+ g_return_val_if_fail (calibrate->priv->device_kind != CD_SENSOR_CAP_UNKNOWN, FALSE);
+
/* use logind to disable system state idle */
priv->proxy_inhibit = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c
index ec62ed0..9f4595f 100644
--- a/panels/color/cc-color-panel.c
+++ b/panels/color/cc-color-panel.c
@@ -72,6 +72,7 @@ enum {
enum {
COLUMN_CALIB_KIND_DESCRIPTION,
COLUMN_CALIB_KIND_CAP_VALUE,
+ COLUMN_CALIB_KIND_VISIBLE,
COLUMN_CALIB_KIND_LAST
};
enum {
@@ -427,11 +428,84 @@ gcm_prefs_calib_quality_treeview_clicked_cb (GtkTreeSelection *selection,
cc_color_calibrate_set_quality (priv->calibrate, quality);
}
+static gboolean
+gcm_prefs_calib_set_sensor_cap_supported_cb (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ CdSensorCap cap;
+ CdSensor *sensor = CD_SENSOR (data);
+ gboolean supported;
+
+ gtk_tree_model_get (model, iter,
+ COLUMN_CALIB_KIND_CAP_VALUE, &cap,
+ -1);
+ supported = cd_sensor_has_cap (sensor, cap);
+ g_debug ("%s(%s) is %s",
+ cd_sensor_get_model (sensor),
+ cd_sensor_cap_to_string (cap),
+ supported ? "supported" : "not-supported");
+ gtk_list_store_set (GTK_LIST_STORE (model), iter,
+ COLUMN_CALIB_KIND_VISIBLE, supported,
+ -1);
+ return FALSE;
+}
+
+static guint8
+_cd_bitfield_popcount (guint64 bitfield)
+{
+ guint8 i;
+ guint8 tmp = 0;
+ for (i = 0; i < 64; i++)
+ tmp += cd_bitfield_contain (bitfield, i);
+ return tmp;
+}
+
+static void
+gcm_prefs_calib_set_sensor (CcColorPanel *prefs,
+ CdSensor *sensor)
+{
+ CcColorPanelPrivate *priv = prefs->priv;
+ GtkTreeModel *model;
+ GtkWidget *page;
+ guint64 caps;
+ guint8 i;
+
+ /* use this sensor for calibration */
+ cc_color_calibrate_set_sensor (priv->calibrate, sensor);
+
+ /* hide display types the sensor does not support */
+ model = GTK_TREE_MODEL (gtk_builder_get_object (priv->builder,
+ "liststore_calib_kind"));
+ gtk_tree_model_foreach (model,
+ gcm_prefs_calib_set_sensor_cap_supported_cb,
+ sensor);
+
+ /* if the sensor only supports one kind then do not show the panel at all */
+ page = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
+ "box_calib_kind"));
+ caps = cd_sensor_get_caps (sensor);
+ if (_cd_bitfield_popcount (caps) == 1)
+ {
+ gtk_widget_set_visible (page, FALSE);
+ for (i = 0; i < CD_SENSOR_CAP_LAST; i++)
+ {
+ if (cd_bitfield_contain (caps, i))
+ cc_color_calibrate_set_kind (priv->calibrate, i);
+ }
+ }
+ else
+ {
+ cc_color_calibrate_set_kind (priv->calibrate, CD_SENSOR_CAP_UNKNOWN);
+ gtk_widget_set_visible (page, TRUE);
+ }
+}
+
static void
gcm_prefs_calib_sensor_treeview_clicked_cb (GtkTreeSelection *selection,
CcColorPanel *prefs)
{
- CcColorPanelPrivate *priv = prefs->priv;
gboolean ret;
GtkTreeIter iter;
GtkTreeModel *model;
@@ -453,7 +527,7 @@ gcm_prefs_calib_sensor_treeview_clicked_cb (GtkTreeSelection *selection,
gtk_tree_model_get (model, &iter,
COLUMN_CALIB_SENSOR_OBJECT, &sensor,
-1);
- cc_color_calibrate_set_sensor (priv->calibrate, sensor);
+ gcm_prefs_calib_set_sensor (prefs, sensor);
g_object_unref (sensor);
}
@@ -494,7 +568,7 @@ gcm_prefs_calibrate_display (CcColorPanel *prefs)
else
{
sensor_tmp = g_ptr_array_index (priv->sensors, 0);
- cc_color_calibrate_set_sensor (priv->calibrate, sensor_tmp);
+ gcm_prefs_calib_set_sensor (prefs, sensor_tmp);
gtk_widget_set_visible (page, FALSE);
}
@@ -2062,6 +2136,7 @@ cc_color_panel_init (CcColorPanel *prefs)
GtkCellRenderer *renderer;
GtkStyleContext *context;
GtkTreeModel *model;
+ GtkTreeModel *model_filter;
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
GtkWidget *widget;
@@ -2269,6 +2344,12 @@ cc_color_panel_init (CcColorPanel *prefs)
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer,
"markup", COLUMN_CALIB_KIND_DESCRIPTION);
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+ model_filter = gtk_tree_model_filter_new (model, NULL);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (widget), model_filter);
+ gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (model_filter),
+ COLUMN_CALIB_KIND_VISIBLE);
+
gtk_tree_view_column_set_expand (column, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (widget),
GTK_TREE_VIEW_COLUMN (column));
diff --git a/panels/color/color.ui b/panels/color/color.ui
index 3edf69b..2be0822 100644
--- a/panels/color/color.ui
+++ b/panels/color/color.ui
@@ -124,18 +124,18 @@
</packing>
</child>
<child>
- <object class="GtkBox" id="box_calib_kind">
+ <object class="GtkBox" id="box_calib_sensor">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">9</property>
<child>
- <object class="GtkLabel" id="label_calib_kind_message">
+ <object class="GtkLabel" id="label_calib_sensor_message">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">6</property>
- <property name="label" translatable="yes">Select the type of display that is connected.</property>
+ <property name="label" translatable="yes">Select the sensor device you want to use for calibration.</property>
<property name="wrap">True</property>
</object>
<packing>
@@ -145,21 +145,21 @@
</packing>
</child>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow_calib_kind">
+ <object class="GtkScrolledWindow" id="scrolledwindow_calib_sensor">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
- <object class="GtkTreeView" id="treeview_calib_kind">
+ <object class="GtkTreeView" id="treeview_calib_sensor">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">liststore_calib_kind</property>
+ <property name="model">liststore_calib_sensor</property>
<property name="headers_visible">False</property>
- <property name="search_column">0</property>
+ <property name="search_column">1</property>
<child internal-child="selection">
- <object class="GtkTreeSelection" id="treeview-selection5"/>
+ <object class="GtkTreeSelection" id="treeview-selection4"/>
</child>
</object>
</child>
@@ -172,22 +172,22 @@
</child>
</object>
<packing>
- <property name="title" translatable="yes">Display Type</property>
+ <property name="title" translatable="yes">Calibration Device</property>
</packing>
</child>
<child>
- <object class="GtkBox" id="box_calib_sensor">
+ <object class="GtkBox" id="box_calib_kind">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">9</property>
<child>
- <object class="GtkLabel" id="label_calib_sensor_message">
+ <object class="GtkLabel" id="label_calib_kind_message">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">6</property>
- <property name="label" translatable="yes">Select the sensor device you want to use for calibration.</property>
+ <property name="label" translatable="yes">Select the type of display that is connected.</property>
<property name="wrap">True</property>
</object>
<packing>
@@ -197,21 +197,21 @@
</packing>
</child>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow_calib_sensor">
+ <object class="GtkScrolledWindow" id="scrolledwindow_calib_kind">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
- <object class="GtkTreeView" id="treeview_calib_sensor">
+ <object class="GtkTreeView" id="treeview_calib_kind">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">liststore_calib_sensor</property>
+ <property name="model">liststore_calib_kind</property>
<property name="headers_visible">False</property>
- <property name="search_column">1</property>
+ <property name="search_column">0</property>
<child internal-child="selection">
- <object class="GtkTreeSelection" id="treeview-selection4"/>
+ <object class="GtkTreeSelection" id="treeview-selection5"/>
</child>
</object>
</child>
@@ -224,7 +224,7 @@
</child>
</object>
<packing>
- <property name="title" translatable="yes">Calibration Device</property>
+ <property name="title" translatable="yes">Display Type</property>
</packing>
</child>
<child>
@@ -1133,23 +1133,34 @@
<column type="gchararray"/>
<!-- column-name kind -->
<column type="guint"/>
+ <!-- column-name visible -->
+ <column type="gboolean"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">LCD</col>
- <col id="1" translatable="no">1</col>
+ <col id="1">1</col>
+ <col id="2">False</col>
</row>
<row>
<col id="0" translatable="yes">LED</col>
- <col id="1" translatable="no">8</col>
+ <col id="1">8</col>
+ <col id="2">False</col>
</row>
<row>
<col id="0" translatable="yes">CRT</col>
- <col id="1" translatable="no">2</col>
+ <col id="1">2</col>
+ <col id="2">False</col>
</row>
<row>
<col id="0" translatable="yes">Projector</col>
- <col id="1" translatable="no">5</col>
+ <col id="1">5</col>
+ <col id="2">False</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Plasma</col>
+ <col id="1">9</col>
+ <col id="2">False</col>
</row>
</data>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]