color panel: Convert to GtkListBox

https://bugzilla.gnome.org/show_bug.cgi?id=702164
This commit is contained in:
Alexander Larsson 2013-06-13 12:19:54 +02:00 committed by Thomas Wood
parent a07825a58e
commit 3a811defed
5 changed files with 71 additions and 89 deletions

View file

@ -40,7 +40,7 @@ struct _CcColorDevicePrivate
guint device_changed_id; guint device_changed_id;
}; };
G_DEFINE_TYPE (CcColorDevice, cc_color_device, GTK_TYPE_BOX) G_DEFINE_TYPE (CcColorDevice, cc_color_device, GTK_TYPE_LIST_BOX_ROW)
enum enum
{ {
@ -326,7 +326,7 @@ cc_color_device_init (CcColorDevice *color_device)
gtk_box_pack_start (GTK_BOX (box), priv->widget_nocalib, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box), priv->widget_nocalib, FALSE, FALSE, 0);
/* refresh */ /* refresh */
gtk_box_pack_start (GTK_BOX (color_device), box, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (color_device), box);
gtk_widget_set_visible (box, TRUE); gtk_widget_set_visible (box, TRUE);
} }

View file

@ -40,7 +40,7 @@ typedef struct _CcColorDevicePrivate CcColorDevicePrivate;
struct _CcColorDevice struct _CcColorDevice
{ {
GtkBox parent; GtkListBoxRow parent;
/*< private >*/ /*< private >*/
CcColorDevicePrivate *priv; CcColorDevicePrivate *priv;
@ -48,7 +48,7 @@ struct _CcColorDevice
struct _CcColorDeviceClass struct _CcColorDeviceClass
{ {
GtkBoxClass parent_class; GtkListBoxRowClass parent_class;
void (*expanded_changed) (CcColorDevice *color_device, void (*expanded_changed) (CcColorDevice *color_device,
gboolean expanded); gboolean expanded);
}; };

View file

@ -21,7 +21,6 @@
#include <config.h> #include <config.h>
#include <egg-list-box/egg-list-box.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <colord.h> #include <colord.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -55,7 +54,7 @@ struct _CcColorPanelPrivate
GtkBuilder *builder; GtkBuilder *builder;
GtkWidget *main_window; GtkWidget *main_window;
CcColorCalibrate *calibrate; CcColorCalibrate *calibrate;
EggListBox *list_box; GtkListBox *list_box;
gchar *list_box_filter; gchar *list_box_filter;
guint list_box_selected_id; guint list_box_selected_id;
GtkSizeGroup *list_box_size; GtkSizeGroup *list_box_size;
@ -1049,12 +1048,13 @@ gcm_prefs_profile_remove_cb (GtkWidget *widget, CcColorPanel *prefs)
CdProfile *profile; CdProfile *profile;
gboolean ret = FALSE; gboolean ret = FALSE;
GError *error = NULL; GError *error = NULL;
GtkListBoxRow *row;
/* get the selected profile */ /* get the selected profile */
widget = egg_list_box_get_selected_child (priv->list_box); row = gtk_list_box_get_selected_row (priv->list_box);
if (widget == NULL) if (row == NULL)
return; return;
profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (widget)); profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (row));
if (profile == NULL) if (profile == NULL)
{ {
g_warning ("failed to get the active profile"); g_warning ("failed to get the active profile");
@ -1099,12 +1099,13 @@ gcm_prefs_device_profile_enable_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
CcColorPanelPrivate *priv = prefs->priv; CcColorPanelPrivate *priv = prefs->priv;
CdProfile *profile; CdProfile *profile;
GtkListBoxRow *row;
/* get the selected profile */ /* get the selected profile */
widget = egg_list_box_get_selected_child (priv->list_box); row = gtk_list_box_get_selected_row (priv->list_box);
if (widget == NULL) if (row == NULL)
return; return;
profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (widget)); profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (row));
if (profile == NULL) if (profile == NULL)
{ {
g_warning ("failed to get the active profile"); g_warning ("failed to get the active profile");
@ -1160,13 +1161,13 @@ gcm_prefs_profile_assign_link_activate_cb (GtkLabel *label,
{ {
CcColorPanelPrivate *priv = prefs->priv; CcColorPanelPrivate *priv = prefs->priv;
CdProfile *profile; CdProfile *profile;
GtkWidget *widget; GtkListBoxRow *row;
/* get the selected profile */ /* get the selected profile */
widget = egg_list_box_get_selected_child (priv->list_box); row = gtk_list_box_get_selected_row (priv->list_box);
if (widget == NULL) if (row == NULL)
return; return;
profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (widget)); profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (row));
if (profile == NULL) if (profile == NULL)
{ {
g_warning ("failed to get the active profile"); g_warning ("failed to get the active profile");
@ -1181,12 +1182,13 @@ static void
gcm_prefs_profile_view_cb (GtkWidget *widget, CcColorPanel *prefs) gcm_prefs_profile_view_cb (GtkWidget *widget, CcColorPanel *prefs)
{ {
CdProfile *profile; CdProfile *profile;
GtkListBoxRow *row;
/* get the selected profile */ /* get the selected profile */
widget = egg_list_box_get_selected_child (prefs->priv->list_box); row = gtk_list_box_get_selected_row (prefs->priv->list_box);
if (widget == NULL) if (row == NULL)
return; return;
profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (widget)); profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (row));
if (profile == NULL) if (profile == NULL)
{ {
g_warning ("failed to get the active profile"); g_warning ("failed to get the active profile");
@ -1724,8 +1726,11 @@ gcm_prefs_device_changed_cb (CdDevice *device, CcColorPanel *prefs)
profile_tmp = cc_color_profile_get_profile (CC_COLOR_PROFILE (l->data)); profile_tmp = cc_color_profile_get_profile (CC_COLOR_PROFILE (l->data));
ret = gcm_prefs_find_profile_by_object_path (profiles, ret = gcm_prefs_find_profile_by_object_path (profiles,
cd_profile_get_object_path (profile_tmp)); cd_profile_get_object_path (profile_tmp));
if (!ret) if (!ret) {
gtk_widget_destroy (GTK_WIDGET (l->data)); gtk_widget_destroy (GTK_WIDGET (l->data));
/* Don't look at the destroyed widget below */
l->data = NULL;
}
} }
/* add anything in Device.Profiles that's not in the list view */ /* add anything in Device.Profiles that's not in the list view */
@ -1741,7 +1746,7 @@ gcm_prefs_device_changed_cb (CdDevice *device, CcColorPanel *prefs)
g_list_free (list); g_list_free (list);
/* resort */ /* resort */
egg_list_box_resort (priv->list_box); gtk_list_box_invalidate_sort (priv->list_box);
} }
static void static void
@ -1779,7 +1784,7 @@ gcm_prefs_device_expanded_changed_cb (CcColorDevice *widget,
{ {
priv->list_box_filter = NULL; priv->list_box_filter = NULL;
} }
egg_list_box_refilter (priv->list_box); gtk_list_box_invalidate_filter (priv->list_box);
} }
static void static void
@ -1813,7 +1818,7 @@ gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
/* watch for changes */ /* watch for changes */
g_signal_connect (device, "changed", g_signal_connect (device, "changed",
G_CALLBACK (gcm_prefs_device_changed_cb), prefs); G_CALLBACK (gcm_prefs_device_changed_cb), prefs);
egg_list_box_resort (priv->list_box); gtk_list_box_invalidate_sort (priv->list_box);
out: out:
return; return;
} }
@ -1928,62 +1933,37 @@ out:
} }
static void static void
gcm_prefs_list_box_handle_selection_flags (EggListBox *list_box, gcm_prefs_list_box_row_selected_cb (GtkListBox *list_box,
GtkWidget *child) GtkListBoxRow *row,
{
GList *l;
GList *list;
list = gtk_container_get_children (GTK_CONTAINER (list_box));
for (l = list; l != NULL; l = l->next)
{
if (child != l->data)
{
gtk_widget_unset_state_flags (GTK_WIDGET (l->data),
GTK_STATE_FLAG_SELECTED);
continue;
}
gtk_widget_set_state_flags (child, GTK_STATE_FLAG_SELECTED, FALSE);
}
g_list_free (list);
}
static void
gcm_prefs_list_box_child_selected_cb (EggListBox *list_box,
GtkWidget *child,
CcColorPanel *panel) CcColorPanel *panel)
{ {
CdProfile *profile = NULL; CdProfile *profile = NULL;
GtkWidget *widget; GtkWidget *widget;
CcColorPanelPrivate *priv = panel->priv; CcColorPanelPrivate *priv = panel->priv;
gboolean is_device = CC_IS_COLOR_DEVICE (child); gboolean is_device = CC_IS_COLOR_DEVICE (row);
/* nothing selected */ /* nothing selected */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"toolbar_devices")); "toolbar_devices"));
gtk_widget_set_visible (widget, child != NULL); gtk_widget_set_visible (widget, row != NULL);
if (child == NULL) if (row == NULL)
return; return;
/* until Alex works out what to do with forwarding the state onto
* children in an EggListBox, we have to do this ourselves */
gcm_prefs_list_box_handle_selection_flags (list_box, child);
/* save current device */ /* save current device */
if (priv->current_device != NULL) if (priv->current_device != NULL)
g_object_unref (priv->current_device); g_object_unref (priv->current_device);
g_object_get (child, "device", &priv->current_device, NULL); g_object_get (row, "device", &priv->current_device, NULL);
/* device actions */ /* device actions */
g_debug ("%s selected", is_device ? "device" : "profile"); g_debug ("%s selected", is_device ? "device" : "profile");
if (CC_IS_COLOR_DEVICE (child)) if (CC_IS_COLOR_DEVICE (row))
{ {
gcm_prefs_device_clicked (panel, priv->current_device); gcm_prefs_device_clicked (panel, priv->current_device);
cc_color_device_set_expanded (CC_COLOR_DEVICE (child), TRUE); cc_color_device_set_expanded (CC_COLOR_DEVICE (row), TRUE);
} }
else if (CC_IS_COLOR_PROFILE (child)) else if (CC_IS_COLOR_PROFILE (row))
{ {
profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (child)); profile = cc_color_profile_get_profile (CC_COLOR_PROFILE (row));
gcm_prefs_profile_clicked (panel, profile, priv->current_device); gcm_prefs_profile_clicked (panel, profile, priv->current_device);
} }
else else
@ -1991,13 +1971,13 @@ gcm_prefs_list_box_child_selected_cb (EggListBox *list_box,
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"toolbutton_device_default")); "toolbutton_device_default"));
gtk_widget_set_visible (widget, !is_device && cc_color_profile_get_is_default (CC_COLOR_PROFILE (child))); gtk_widget_set_visible (widget, !is_device && cc_color_profile_get_is_default (CC_COLOR_PROFILE (row)));
if (profile) if (profile)
gtk_widget_set_sensitive (widget, !cd_profile_get_is_system_wide (profile)); gtk_widget_set_sensitive (widget, !cd_profile_get_is_system_wide (profile));
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"toolbutton_device_enable")); "toolbutton_device_enable"));
gtk_widget_set_visible (widget, !is_device && !cc_color_profile_get_is_default (CC_COLOR_PROFILE (child))); gtk_widget_set_visible (widget, !is_device && !cc_color_profile_get_is_default (CC_COLOR_PROFILE (row)));
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"toolbutton_device_calibrate")); "toolbutton_device_calibrate"));
@ -2165,8 +2145,8 @@ cc_color_panel_class_init (CcColorPanelClass *klass)
} }
static gint static gint
cc_color_panel_sort_func (gconstpointer a, cc_color_panel_sort_func (GtkListBoxRow *a,
gconstpointer b, GtkListBoxRow *b,
gpointer user_data) gpointer user_data)
{ {
const gchar *sort_a = NULL; const gchar *sort_a = NULL;
@ -2187,36 +2167,38 @@ cc_color_panel_sort_func (gconstpointer a,
} }
static gboolean static gboolean
cc_color_panel_filter_func (GtkWidget *child, void *user_data) cc_color_panel_filter_func (GtkListBoxRow *row, void *user_data)
{ {
CcColorPanel *prefs = CC_COLOR_PANEL (user_data); CcColorPanel *prefs = CC_COLOR_PANEL (user_data);
CdDevice *device; CdDevice *device;
gboolean ret; gboolean ret;
/* always show all devices */ /* always show all devices */
if (CC_IS_COLOR_DEVICE (child)) if (CC_IS_COLOR_DEVICE (row))
return TRUE; return TRUE;
g_object_get (child, "device", &device, NULL); g_object_get (row, "device", &device, NULL);
ret = g_strcmp0 (cd_device_get_id (device), prefs->priv->list_box_filter) == 0; ret = g_strcmp0 (cd_device_get_id (device), prefs->priv->list_box_filter) == 0;
g_object_unref (device); g_object_unref (device);
return ret; return ret;
} }
static void static void
cc_color_panel_separator_func (GtkWidget **separator, cc_color_panel_header_func (GtkListBoxRow *row,
GtkWidget *child, GtkListBoxRow *before,
GtkWidget *before,
gpointer user_data) gpointer user_data)
{ {
GtkWidget *current;
if (before == NULL) if (before == NULL)
return; return;
if (*separator == NULL) current = gtk_list_box_row_get_header (row);
if (current == NULL)
{ {
*separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); current = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
g_object_ref_sink (*separator); gtk_widget_show (current);
gtk_widget_show (*separator); gtk_list_box_row_set_header (row, current);
} }
} }
@ -2493,29 +2475,28 @@ cc_color_panel_init (CcColorPanel *prefs)
G_CALLBACK (gcm_prefs_device_removed_cb), prefs, 0); G_CALLBACK (gcm_prefs_device_removed_cb), prefs, 0);
/* use a listbox for the main UI */ /* use a listbox for the main UI */
priv->list_box = egg_list_box_new (); priv->list_box = GTK_LIST_BOX (gtk_list_box_new ());
egg_list_box_set_filter_func (priv->list_box, gtk_list_box_set_filter_func (priv->list_box,
cc_color_panel_filter_func, cc_color_panel_filter_func,
prefs, prefs,
NULL); NULL);
egg_list_box_set_sort_func (priv->list_box, gtk_list_box_set_sort_func (priv->list_box,
cc_color_panel_sort_func, cc_color_panel_sort_func,
prefs, prefs,
NULL); NULL);
egg_list_box_set_separator_funcs (priv->list_box, gtk_list_box_set_header_func (priv->list_box,
cc_color_panel_separator_func, cc_color_panel_header_func,
prefs, NULL); prefs, NULL);
egg_list_box_set_selection_mode (priv->list_box, gtk_list_box_set_selection_mode (priv->list_box,
GTK_SELECTION_SINGLE); GTK_SELECTION_SINGLE);
priv->list_box_selected_id = priv->list_box_selected_id =
g_signal_connect (priv->list_box, "child-selected", g_signal_connect (priv->list_box, "row-selected",
G_CALLBACK (gcm_prefs_list_box_child_selected_cb), G_CALLBACK (gcm_prefs_list_box_row_selected_cb),
prefs); prefs);
priv->list_box_size = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL); priv->list_box_size = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_devices")); widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_devices"));
egg_list_box_add_to_scrolled (priv->list_box, gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (priv->list_box));
GTK_SCROLLED_WINDOW (widget));
gtk_widget_show (GTK_WIDGET (priv->list_box)); gtk_widget_show (GTK_WIDGET (priv->list_box));
/* connect to colord */ /* connect to colord */

View file

@ -29,6 +29,7 @@
struct _CcColorProfilePrivate struct _CcColorProfilePrivate
{ {
GtkWidget *box;
CdDevice *device; CdDevice *device;
CdProfile *profile; CdProfile *profile;
gboolean is_default; gboolean is_default;
@ -46,7 +47,7 @@ struct _CcColorProfilePrivate
#define IMAGE_WIDGET_PADDING 12 #define IMAGE_WIDGET_PADDING 12
G_DEFINE_TYPE (CcColorProfile, cc_color_profile, GTK_TYPE_BOX) G_DEFINE_TYPE (CcColorProfile, cc_color_profile, GTK_TYPE_LIST_BOX_ROW)
enum enum
{ {
@ -479,7 +480,7 @@ cc_color_profile_init (CcColorProfile *color_profile)
gtk_box_pack_start (GTK_BOX (box), priv->widget_info, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box), priv->widget_info, FALSE, FALSE, 0);
/* refresh */ /* refresh */
gtk_box_pack_start (GTK_BOX (color_profile), box, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (color_profile), box);
gtk_widget_set_visible (box, TRUE); gtk_widget_set_visible (box, TRUE);
} }

View file

@ -40,7 +40,7 @@ typedef struct _CcColorProfilePrivate CcColorProfilePrivate;
struct _CcColorProfile struct _CcColorProfile
{ {
GtkBox parent; GtkListBoxRow parent;
/*< private >*/ /*< private >*/
CcColorProfilePrivate *priv; CcColorProfilePrivate *priv;
@ -48,7 +48,7 @@ struct _CcColorProfile
struct _CcColorProfileClass struct _CcColorProfileClass
{ {
GtkBoxClass parent_class; GtkListBoxRowClass parent_class;
}; };
GType cc_color_profile_get_type (void); GType cc_color_profile_get_type (void);