Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2012 Richard Hughes <richard@hughsie.com> |
4 |
|
|
* |
5 |
|
|
* Licensed under the GNU General Public License Version 2 |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "config.h" |
23 |
|
|
|
24 |
|
|
#include <glib/gi18n.h> |
25 |
|
|
#include <gtk/gtk.h> |
26 |
|
|
|
27 |
|
|
#include "cc-color-common.h" |
28 |
|
|
#include "cc-color-device.h" |
29 |
|
|
|
30 |
|
|
struct _CcColorDevice |
31 |
|
|
{ |
32 |
|
|
GtkListBoxRow parent_instance; |
33 |
|
|
|
34 |
|
|
CdDevice *device; |
35 |
|
|
gboolean expanded; |
36 |
|
|
gchar *sortable; |
37 |
|
|
GtkWidget *widget_description; |
38 |
|
|
GtkWidget *widget_button; |
39 |
|
|
GtkWidget *widget_switch; |
40 |
|
|
GtkWidget *widget_arrow; |
41 |
|
|
GtkWidget *widget_nocalib; |
42 |
|
|
}; |
43 |
|
|
|
44 |
|
✗ |
G_DEFINE_TYPE (CcColorDevice, cc_color_device, GTK_TYPE_LIST_BOX_ROW) |
45 |
|
|
|
46 |
|
|
enum |
47 |
|
|
{ |
48 |
|
|
SIGNAL_EXPANDED_CHANGED, |
49 |
|
|
SIGNAL_LAST |
50 |
|
|
}; |
51 |
|
|
|
52 |
|
|
enum |
53 |
|
|
{ |
54 |
|
|
PROP_0, |
55 |
|
|
PROP_DEVICE, |
56 |
|
|
PROP_LAST |
57 |
|
|
}; |
58 |
|
|
|
59 |
|
|
static guint signals [SIGNAL_LAST] = { 0 }; |
60 |
|
|
|
61 |
|
|
static void |
62 |
|
✗ |
cc_color_device_refresh (CcColorDevice *color_device) |
63 |
|
|
{ |
64 |
|
✗ |
g_autofree gchar *title = NULL; |
65 |
|
✗ |
g_autoptr(GPtrArray) profiles = NULL; |
66 |
|
✗ |
g_autofree gchar *name1 = NULL; |
67 |
|
✗ |
g_autofree gchar *name2 = NULL; |
68 |
|
|
|
69 |
|
|
/* add switch and expander if there are profiles, otherwise use a label */ |
70 |
|
✗ |
profiles = cd_device_get_profiles (color_device->device); |
71 |
|
✗ |
if (profiles == NULL) |
72 |
|
✗ |
return; |
73 |
|
|
|
74 |
|
✗ |
title = cc_color_device_get_title (color_device->device); |
75 |
|
✗ |
gtk_label_set_label (GTK_LABEL (color_device->widget_description), title); |
76 |
|
✗ |
gtk_widget_set_visible (color_device->widget_description, TRUE); |
77 |
|
|
|
78 |
|
✗ |
gtk_widget_set_visible (color_device->widget_switch, profiles->len > 0); |
79 |
|
✗ |
gtk_widget_set_visible (color_device->widget_button, profiles->len > 0); |
80 |
|
✗ |
gtk_image_set_from_icon_name (GTK_IMAGE (color_device->widget_arrow), |
81 |
|
✗ |
color_device->expanded ? "pan-down-symbolic" : "pan-end-symbolic"); |
82 |
|
✗ |
gtk_widget_set_visible (color_device->widget_nocalib, profiles->len == 0); |
83 |
|
✗ |
gtk_widget_set_sensitive (color_device->widget_button, cd_device_get_enabled (color_device->device)); |
84 |
|
✗ |
gtk_switch_set_active (GTK_SWITCH (color_device->widget_switch), |
85 |
|
|
cd_device_get_enabled (color_device->device)); |
86 |
|
|
|
87 |
|
✗ |
name1 = g_strdup_printf (_("Enable color management for %s"), title); |
88 |
|
✗ |
gtk_accessible_update_property (GTK_ACCESSIBLE (color_device->widget_switch), |
89 |
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, name1, |
90 |
|
|
-1); |
91 |
|
|
|
92 |
|
✗ |
name2 = g_strdup_printf (_("Show color profiles for %s"), title); |
93 |
|
✗ |
gtk_accessible_update_property (GTK_ACCESSIBLE (color_device->widget_button), |
94 |
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, name2, |
95 |
|
|
-1); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
CdDevice * |
99 |
|
✗ |
cc_color_device_get_device (CcColorDevice *color_device) |
100 |
|
|
{ |
101 |
|
✗ |
g_return_val_if_fail (CC_IS_COLOR_DEVICE (color_device), NULL); |
102 |
|
✗ |
return color_device->device; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
const gchar * |
106 |
|
✗ |
cc_color_device_get_sortable (CcColorDevice *color_device) |
107 |
|
|
{ |
108 |
|
✗ |
g_return_val_if_fail (CC_IS_COLOR_DEVICE (color_device), NULL); |
109 |
|
✗ |
return color_device->sortable; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
static void |
113 |
|
✗ |
cc_color_device_get_property (GObject *object, guint param_id, |
114 |
|
|
GValue *value, GParamSpec *pspec) |
115 |
|
|
{ |
116 |
|
✗ |
CcColorDevice *color_device = CC_COLOR_DEVICE (object); |
117 |
|
✗ |
switch (param_id) |
118 |
|
|
{ |
119 |
|
✗ |
case PROP_DEVICE: |
120 |
|
✗ |
g_value_set_object (value, color_device->device); |
121 |
|
✗ |
break; |
122 |
|
✗ |
default: |
123 |
|
✗ |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
124 |
|
✗ |
break; |
125 |
|
|
} |
126 |
|
✗ |
} |
127 |
|
|
|
128 |
|
|
static void |
129 |
|
✗ |
cc_color_device_set_property (GObject *object, guint param_id, |
130 |
|
|
const GValue *value, GParamSpec *pspec) |
131 |
|
|
{ |
132 |
|
✗ |
CcColorDevice *color_device = CC_COLOR_DEVICE (object); |
133 |
|
|
|
134 |
|
✗ |
switch (param_id) |
135 |
|
|
{ |
136 |
|
✗ |
case PROP_DEVICE: |
137 |
|
✗ |
color_device->device = g_value_dup_object (value); |
138 |
|
✗ |
break; |
139 |
|
✗ |
default: |
140 |
|
✗ |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
141 |
|
✗ |
break; |
142 |
|
|
} |
143 |
|
✗ |
} |
144 |
|
|
|
145 |
|
|
static void |
146 |
|
✗ |
cc_color_device_finalize (GObject *object) |
147 |
|
|
{ |
148 |
|
✗ |
CcColorDevice *color_device = CC_COLOR_DEVICE (object); |
149 |
|
|
|
150 |
|
✗ |
g_free (color_device->sortable); |
151 |
|
✗ |
g_object_unref (color_device->device); |
152 |
|
|
|
153 |
|
✗ |
G_OBJECT_CLASS (cc_color_device_parent_class)->finalize (object); |
154 |
|
✗ |
} |
155 |
|
|
|
156 |
|
|
void |
157 |
|
✗ |
cc_color_device_set_expanded (CcColorDevice *color_device, |
158 |
|
|
gboolean expanded) |
159 |
|
|
{ |
160 |
|
|
/* same as before */ |
161 |
|
✗ |
if (color_device->expanded == expanded) |
162 |
|
✗ |
return; |
163 |
|
|
|
164 |
|
|
/* refresh */ |
165 |
|
✗ |
color_device->expanded = expanded; |
166 |
|
✗ |
g_signal_emit (color_device, |
167 |
|
|
signals[SIGNAL_EXPANDED_CHANGED], 0, |
168 |
|
|
color_device->expanded); |
169 |
|
✗ |
cc_color_device_refresh (color_device); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
static void |
173 |
|
✗ |
cc_color_device_notify_enable_device_cb (CcColorDevice *color_device) |
174 |
|
|
{ |
175 |
|
|
gboolean enable; |
176 |
|
|
gboolean ret; |
177 |
|
✗ |
g_autoptr(GError) error = NULL; |
178 |
|
|
|
179 |
|
✗ |
enable = gtk_switch_get_active (GTK_SWITCH (color_device->widget_switch)); |
180 |
|
✗ |
g_debug ("Set %s to %i", cd_device_get_id (color_device->device), enable); |
181 |
|
✗ |
ret = cd_device_set_enabled_sync (color_device->device, |
182 |
|
|
enable, NULL, &error); |
183 |
|
✗ |
if (!ret) |
184 |
|
✗ |
g_warning ("failed to %s to the device: %s", |
185 |
|
|
enable ? "enable" : "disable", error->message); |
186 |
|
|
|
187 |
|
|
/* if expanded, close */ |
188 |
|
✗ |
cc_color_device_set_expanded (color_device, FALSE); |
189 |
|
✗ |
} |
190 |
|
|
|
191 |
|
|
static void |
192 |
|
✗ |
cc_color_device_changed_cb (CcColorDevice *color_device) |
193 |
|
|
{ |
194 |
|
✗ |
cc_color_device_refresh (color_device); |
195 |
|
✗ |
} |
196 |
|
|
|
197 |
|
|
static void |
198 |
|
✗ |
cc_color_device_constructed (GObject *object) |
199 |
|
|
{ |
200 |
|
✗ |
CcColorDevice *color_device = CC_COLOR_DEVICE (object); |
201 |
|
✗ |
g_autofree gchar *sortable_tmp = NULL; |
202 |
|
|
|
203 |
|
|
/* watch the device for changes */ |
204 |
|
✗ |
g_signal_connect_object (color_device->device, "changed", |
205 |
|
|
G_CALLBACK (cc_color_device_changed_cb), color_device, G_CONNECT_SWAPPED); |
206 |
|
|
|
207 |
|
|
/* calculate sortable -- FIXME: we have to hack this as EggListBox |
208 |
|
|
* does not let us specify a GtkSortType: |
209 |
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=691341 */ |
210 |
|
✗ |
sortable_tmp = cc_color_device_get_sortable_base (color_device->device); |
211 |
|
✗ |
color_device->sortable = g_strdup_printf ("%sXX", sortable_tmp); |
212 |
|
|
|
213 |
|
✗ |
cc_color_device_refresh (color_device); |
214 |
|
|
|
215 |
|
|
/* watch to see if the user flicked the switch */ |
216 |
|
✗ |
g_signal_connect_object (color_device->widget_switch, "notify::active", |
217 |
|
|
G_CALLBACK (cc_color_device_notify_enable_device_cb), |
218 |
|
|
color_device, G_CONNECT_SWAPPED); |
219 |
|
✗ |
} |
220 |
|
|
|
221 |
|
|
static void |
222 |
|
✗ |
cc_color_device_class_init (CcColorDeviceClass *klass) |
223 |
|
|
{ |
224 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
225 |
|
✗ |
object_class->get_property = cc_color_device_get_property; |
226 |
|
✗ |
object_class->set_property = cc_color_device_set_property; |
227 |
|
✗ |
object_class->constructed = cc_color_device_constructed; |
228 |
|
✗ |
object_class->finalize = cc_color_device_finalize; |
229 |
|
|
|
230 |
|
✗ |
g_object_class_install_property (object_class, PROP_DEVICE, |
231 |
|
|
g_param_spec_object ("device", NULL, |
232 |
|
|
NULL, |
233 |
|
|
CD_TYPE_DEVICE, |
234 |
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); |
235 |
|
|
|
236 |
|
✗ |
signals [SIGNAL_EXPANDED_CHANGED] = |
237 |
|
✗ |
g_signal_new ("expanded-changed", |
238 |
|
|
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
239 |
|
|
0, |
240 |
|
|
NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, |
241 |
|
|
G_TYPE_NONE, 1, G_TYPE_BOOLEAN); |
242 |
|
✗ |
} |
243 |
|
|
|
244 |
|
|
static void |
245 |
|
✗ |
cc_color_device_clicked_expander_cb (CcColorDevice *color_device) |
246 |
|
|
{ |
247 |
|
✗ |
color_device->expanded = !color_device->expanded; |
248 |
|
✗ |
cc_color_device_refresh (color_device); |
249 |
|
✗ |
g_signal_emit (color_device, signals[SIGNAL_EXPANDED_CHANGED], 0, |
250 |
|
|
color_device->expanded); |
251 |
|
✗ |
} |
252 |
|
|
|
253 |
|
|
static void |
254 |
|
✗ |
cc_color_device_init (CcColorDevice *color_device) |
255 |
|
|
{ |
256 |
|
|
GtkWidget *box; |
257 |
|
|
|
258 |
|
|
/* description */ |
259 |
|
✗ |
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 9); |
260 |
|
✗ |
color_device->widget_description = gtk_label_new (""); |
261 |
|
✗ |
gtk_widget_set_margin_start (color_device->widget_description, 20); |
262 |
|
✗ |
gtk_widget_set_margin_top (color_device->widget_description, 12); |
263 |
|
✗ |
gtk_widget_set_margin_bottom (color_device->widget_description, 12); |
264 |
|
✗ |
gtk_widget_set_halign (color_device->widget_description, GTK_ALIGN_START); |
265 |
|
✗ |
gtk_widget_set_hexpand (color_device->widget_description, TRUE); |
266 |
|
✗ |
gtk_label_set_ellipsize (GTK_LABEL (color_device->widget_description), PANGO_ELLIPSIZE_END); |
267 |
|
✗ |
gtk_label_set_xalign (GTK_LABEL (color_device->widget_description), 0); |
268 |
|
✗ |
gtk_box_append (GTK_BOX (box), color_device->widget_description); |
269 |
|
|
|
270 |
|
|
/* switch */ |
271 |
|
✗ |
color_device->widget_switch = gtk_switch_new (); |
272 |
|
✗ |
gtk_widget_set_valign (color_device->widget_switch, GTK_ALIGN_CENTER); |
273 |
|
✗ |
gtk_box_append (GTK_BOX (box), color_device->widget_switch); |
274 |
|
|
|
275 |
|
|
/* arrow button */ |
276 |
|
✗ |
color_device->widget_arrow = gtk_image_new_from_icon_name ("pan-end-symbolic"); |
277 |
|
✗ |
color_device->widget_button = gtk_button_new (); |
278 |
|
✗ |
g_signal_connect_object (color_device->widget_button, "clicked", |
279 |
|
|
G_CALLBACK (cc_color_device_clicked_expander_cb), |
280 |
|
|
color_device, G_CONNECT_SWAPPED); |
281 |
|
✗ |
gtk_widget_set_valign (color_device->widget_button, GTK_ALIGN_CENTER); |
282 |
|
✗ |
gtk_widget_add_css_class (color_device->widget_button, "flat"); |
283 |
|
✗ |
gtk_button_set_child (GTK_BUTTON (color_device->widget_button), color_device->widget_arrow); |
284 |
|
✗ |
gtk_widget_set_margin_top (color_device->widget_button, 9); |
285 |
|
✗ |
gtk_widget_set_margin_bottom (color_device->widget_button, 9); |
286 |
|
✗ |
gtk_widget_set_margin_end (color_device->widget_button, 12); |
287 |
|
✗ |
gtk_box_append (GTK_BOX (box), color_device->widget_button); |
288 |
|
|
|
289 |
|
|
/* not calibrated */ |
290 |
|
✗ |
color_device->widget_nocalib = gtk_label_new (_("Not calibrated")); |
291 |
|
✗ |
gtk_widget_add_css_class (color_device->widget_nocalib, "dim-label"); |
292 |
|
✗ |
gtk_widget_set_margin_end (color_device->widget_nocalib, 18); |
293 |
|
✗ |
gtk_box_append (GTK_BOX (box), color_device->widget_nocalib); |
294 |
|
|
|
295 |
|
|
/* refresh */ |
296 |
|
✗ |
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (color_device), box); |
297 |
|
✗ |
} |
298 |
|
|
|
299 |
|
|
GtkWidget * |
300 |
|
✗ |
cc_color_device_new (CdDevice *device) |
301 |
|
|
{ |
302 |
|
✗ |
return g_object_new (CC_TYPE_COLOR_DEVICE, |
303 |
|
|
"device", device, |
304 |
|
|
NULL); |
305 |
|
|
} |
306 |
|
|
|
307 |
|
|
|