Commit 1db26b43 authored by Alexander Larsson's avatar Alexander Larsson Committed by Thomas Wood
Browse files
parent eac949bd
......@@ -29,8 +29,6 @@
#include <string.h>
#include <glib/gi18n.h>
#include "egg-list-box/egg-list-box.h"
#include "cc-common-language.h"
#include "cc-util.h"
......@@ -40,7 +38,7 @@
typedef struct {
GtkWidget *no_results;
GtkWidget *more_item;
GtkListBoxRow *more_item;
GtkWidget *filter_entry;
GtkWidget *list;
GtkWidget *scrolledwindow;
......@@ -165,7 +163,7 @@ set_locale_id (GtkDialog *chooser,
is_extra = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (row), "is-extra"));
if (!priv->showing_extra && is_extra) {
g_object_set_data (G_OBJECT (row), "is-extra", GINT_TO_POINTER (FALSE));
egg_list_box_refilter (EGG_LIST_BOX (priv->list));
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
}
} else {
......@@ -223,56 +221,60 @@ region_widget_new (const gchar *locale_id,
gchar *locale_name;
gchar *locale_current_name;
gchar *locale_untranslated_name;
GtkWidget *widget;
GtkWidget *row, *box;
GtkWidget *check;
locale_name = gnome_get_country_from_locale (locale_id, locale_id);
locale_current_name = gnome_get_country_from_locale (locale_id, NULL);
locale_untranslated_name = gnome_get_country_from_locale (locale_id, "C");
widget = padded_label_new (locale_name, is_extra);
row = gtk_list_box_row_new ();
box = padded_label_new (locale_name, is_extra);
gtk_container_add (GTK_CONTAINER (row), box);
/* We add a check on each side of the label to keep it centered. */
check = gtk_image_new ();
gtk_image_set_from_icon_name (GTK_IMAGE (check), "object-select-symbolic", GTK_ICON_SIZE_MENU);
gtk_widget_set_opacity (check, 0.0);
g_object_set (check, "icon-size", GTK_ICON_SIZE_MENU, NULL);
gtk_box_pack_start (GTK_BOX (widget), check, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (widget), check, 0);
gtk_box_pack_start (GTK_BOX (box), check, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (box), check, 0);
check = gtk_image_new ();
gtk_image_set_from_icon_name (GTK_IMAGE (check), "object-select-symbolic", GTK_ICON_SIZE_MENU);
gtk_widget_set_opacity (check, 0.0);
g_object_set (check, "icon-size", GTK_ICON_SIZE_MENU, NULL);
gtk_box_pack_start (GTK_BOX (widget), check, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), check, FALSE, FALSE, 0);
g_object_set_data (G_OBJECT (widget), "check", check);
g_object_set_data_full (G_OBJECT (widget), "locale-id", g_strdup (locale_id), g_free);
g_object_set_data_full (G_OBJECT (widget), "locale-name", locale_name, g_free);
g_object_set_data_full (G_OBJECT (widget), "locale-current-name", locale_current_name, g_free);
g_object_set_data_full (G_OBJECT (widget), "locale-untranslated-name", locale_untranslated_name, g_free);
g_object_set_data (G_OBJECT (widget), "is-extra", GUINT_TO_POINTER (is_extra));
g_object_set_data (G_OBJECT (row), "check", check);
g_object_set_data_full (G_OBJECT (row), "locale-id", g_strdup (locale_id), g_free);
g_object_set_data_full (G_OBJECT (row), "locale-name", locale_name, g_free);
g_object_set_data_full (G_OBJECT (row), "locale-current-name", locale_current_name, g_free);
g_object_set_data_full (G_OBJECT (row), "locale-untranslated-name", locale_untranslated_name, g_free);
g_object_set_data (G_OBJECT (row), "is-extra", GUINT_TO_POINTER (is_extra));
return widget;
return row;
}
static GtkWidget *
static GtkListBoxRow *
more_widget_new (void)
{
GtkWidget *widget;
GtkWidget *box, *row;
GtkWidget *arrow;
widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_widget_set_tooltip_text (widget, _("More…"));
row = gtk_list_box_row_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_add (GTK_CONTAINER (row), box);
gtk_widget_set_tooltip_text (box, _("More…"));
arrow = gtk_image_new_from_icon_name ("view-more-symbolic", GTK_ICON_SIZE_MENU);
gtk_style_context_add_class (gtk_widget_get_style_context (arrow), "dim-label");
gtk_widget_set_margin_top (widget, 10);
gtk_widget_set_margin_bottom (widget, 10);
gtk_widget_set_margin_top (box, 10);
gtk_widget_set_margin_bottom (box, 10);
gtk_misc_set_alignment (GTK_MISC (arrow), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (widget), arrow, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), arrow, TRUE, TRUE, 0);
return widget;
return GTK_LIST_BOX_ROW (row);
}
static GtkWidget *
......@@ -310,8 +312,7 @@ add_regions (GtkDialog *chooser,
gtk_container_add (GTK_CONTAINER (priv->list), widget);
}
gtk_container_add (GTK_CONTAINER (priv->list), priv->more_item);
gtk_container_add (GTK_CONTAINER (priv->list), priv->no_results);
gtk_container_add (GTK_CONTAINER (priv->list), GTK_WIDGET (priv->more_item));
gtk_widget_show_all (priv->list);
......@@ -345,7 +346,7 @@ match_all (gchar **words,
}
static gboolean
region_visible (GtkWidget *child,
region_visible (GtkListBoxRow *row,
gpointer user_data)
{
GtkDialog *chooser = user_data;
......@@ -356,14 +357,10 @@ region_visible (GtkWidget *child,
gboolean is_extra;
gboolean visible;
if (child == priv->more_item)
if (row == priv->more_item)
return !priv->showing_extra;
/* We hide this in the after-refilter handler below. */
if (child == priv->no_results)
return TRUE;
is_extra = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (child), "is-extra"));
is_extra = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (row), "is-extra"));
if (!priv->showing_extra && is_extra)
return FALSE;
......@@ -374,19 +371,19 @@ region_visible (GtkWidget *child,
visible = FALSE;
locale_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (child), "locale-name"));
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "locale-name"));
visible = match_all (priv->filter_words, locale_name);
if (visible)
goto out;
locale_current_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (child), "locale-current-name"));
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "locale-current-name"));
visible = match_all (priv->filter_words, locale_current_name);
if (visible)
goto out;
locale_untranslated_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (child), "locale-untranslated-name"));
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (row), "locale-untranslated-name"));
visible = match_all (priv->filter_words, locale_untranslated_name);
out:
......@@ -407,12 +404,14 @@ filter_changed (GtkDialog *chooser)
filter_contents =
cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry)));
if (!filter_contents) {
egg_list_box_refilter (EGG_LIST_BOX (priv->list));
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), NULL);
return;
}
priv->filter_words = g_strsplit_set (g_strstrip (filter_contents), " ", 0);
g_free (filter_contents);
egg_list_box_refilter (EGG_LIST_BOX (priv->list));
gtk_list_box_set_placeholder (GTK_LIST_BOX (priv->list), GTK_WIDGET (priv->no_results));
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
}
static void
......@@ -436,13 +435,13 @@ show_more (GtkDialog *chooser)
priv->showing_extra = TRUE;
egg_list_box_refilter (EGG_LIST_BOX (priv->list));
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
}
static void
child_activated (EggListBox *box,
GtkWidget *child,
GtkDialog *chooser)
row_activated (GtkListBox *box,
GtkListBoxRow *row,
GtkDialog *chooser)
{
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
gchar *new_locale_id;
......@@ -450,65 +449,34 @@ child_activated (EggListBox *box,
if (priv->adding)
return;
if (child == NULL)
return;
if (child == priv->no_results)
if (row == NULL)
return;
if (child == priv->more_item) {
if (row == priv->more_item) {
show_more (chooser);
return;
}
new_locale_id = g_object_get_data (G_OBJECT (child), "locale-id");
new_locale_id = g_object_get_data (G_OBJECT (row), "locale-id");
set_locale_id (chooser, new_locale_id);
}
typedef struct {
gint count;
GtkWidget *ignore;
} CountChildrenData;
static void
count_visible_children (GtkWidget *widget,
gpointer user_data)
update_header_func (GtkListBoxRow *row,
GtkListBoxRow *before,
gpointer user_data)
{
CountChildrenData *data = user_data;
if (widget!= data->ignore &&
gtk_widget_get_child_visible (widget) &&
gtk_widget_get_visible (widget))
data->count++;
}
static void
end_refilter (EggListBox *list_box,
gpointer user_data)
{
GtkDialog *chooser = user_data;
CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
CountChildrenData data = { 0 };
data.ignore = priv->no_results;
gtk_container_foreach (GTK_CONTAINER (list_box),
count_visible_children, &data);
gtk_widget_set_visible (priv->no_results, (data.count == 0));
}
static void
update_separator_func (GtkWidget **separator,
GtkWidget *child,
GtkWidget *before,
gpointer user_data)
{
if (before == NULL)
return;
if (*separator == NULL) {
*separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
g_object_ref_sink (*separator);
gtk_widget_show (*separator);
}
GtkWidget *current;
if (before == NULL)
return;
current = gtk_list_box_row_get_header (row);
if (current == NULL)
{
current = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_show (current);
gtk_list_box_row_set_header (row, current);
}
}
static void
......@@ -516,6 +484,7 @@ cc_format_chooser_private_free (gpointer data)
{
CcFormatChooserPrivate *priv = data;
g_clear_object (&priv->no_results);
g_strfreev (priv->filter_words);
g_free (priv->region);
g_free (priv);
......@@ -548,7 +517,9 @@ cc_format_chooser_new (GtkWidget *parent)
priv->list = WID ("region-list");
priv->scrolledwindow = WID ("region-scrolledwindow");
priv->more_item = more_widget_new ();
priv->no_results = no_results_widget_new ();
/* We ref-sink here so we can reuse this widget multiple times */
priv->no_results = g_object_ref_sink (no_results_widget_new ());
gtk_widget_show_all (priv->no_results);
priv->full_date = WID ("full-date-format");
priv->medium_date = WID ("medium-date-format");
......@@ -558,30 +529,27 @@ cc_format_chooser_new (GtkWidget *parent)
priv->measurement = WID ("measurement-format");
priv->paper = WID ("paper-format");
egg_list_box_set_adjustment (EGG_LIST_BOX (priv->list),
gtk_list_box_set_adjustment (GTK_LIST_BOX (priv->list),
gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scrolledwindow)));
egg_list_box_set_sort_func (EGG_LIST_BOX (priv->list),
sort_regions, chooser, NULL);
egg_list_box_set_filter_func (EGG_LIST_BOX (priv->list),
gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->list),
(GtkListBoxSortFunc)sort_regions, chooser, NULL);
gtk_list_box_set_filter_func (GTK_LIST_BOX (priv->list),
region_visible, chooser, NULL);
egg_list_box_set_selection_mode (EGG_LIST_BOX (priv->list),
gtk_list_box_set_selection_mode (GTK_LIST_BOX (priv->list),
GTK_SELECTION_NONE);
egg_list_box_set_separator_funcs (EGG_LIST_BOX (priv->list),
update_separator_func, NULL, NULL);
gtk_list_box_set_header_func (GTK_LIST_BOX (priv->list),
update_header_func, NULL, NULL);
add_all_regions (GTK_DIALOG (chooser));
g_signal_connect_swapped (priv->filter_entry, "changed",
G_CALLBACK (filter_changed), chooser);
g_signal_connect (priv->list, "child-activated",
G_CALLBACK (child_activated), chooser);
g_signal_connect_after (priv->list, "refilter",
G_CALLBACK (end_refilter), chooser);
g_signal_connect (priv->list, "row-activated",
G_CALLBACK (row_activated), chooser);
egg_list_box_refilter (EGG_LIST_BOX (priv->list));
gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list));
gtk_window_set_transient_for (GTK_WINDOW (chooser), GTK_WINDOW (parent));
......
This diff is collapsed.
......@@ -47,7 +47,6 @@
#include <act/act.h>
#include "egg-list-box/egg-list-box.h"
#include <libgd/gd-notification.h>
#define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources"
......@@ -90,11 +89,11 @@ struct _CcRegionPanelPrivate {
GtkWidget *overlay;
GtkWidget *notification;
GtkWidget *language_section;
GtkWidget *language_row;
GtkWidget *language_label;
GtkWidget *formats_row;
GtkWidget *formats_label;
GtkWidget *language_section;
GtkListBoxRow *language_row;
GtkWidget *language_label;
GtkListBoxRow *formats_row;
GtkWidget *formats_label;
ActUserManager *user_manager;
ActUser *user;
......@@ -256,19 +255,22 @@ show_restart_notification (CcRegionPanel *self,
}
static void
update_separator_func (GtkWidget **separator,
GtkWidget *child,
GtkWidget *before,
gpointer user_data)
update_header_func (GtkListBoxRow *row,
GtkListBoxRow *before,
gpointer user_data)
{
if (before == NULL)
return;
GtkWidget *current;
if (*separator == NULL) {
*separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
g_object_ref_sink (*separator);
gtk_widget_show (*separator);
}
if (before == NULL)
return;
current = gtk_list_box_row_get_header (row);
if (current == NULL)
{
current = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_show (current);
gtk_list_box_row_set_header (row, current);
}
}
typedef struct {
......@@ -501,11 +503,12 @@ show_format_chooser (CcRegionPanel *self)
}
static void
activate_language_child (CcRegionPanel *self, GtkWidget *child)
activate_language_row (CcRegionPanel *self,
GtkListBoxRow *row)
{
CcRegionPanelPrivate *priv = self->priv;
if (child == priv->language_row) {
if (row == priv->language_row) {
if (!priv->login) {
show_language_chooser (self, priv->language);
} else if (g_permission_get_allowed (priv->permission)) {
......@@ -517,7 +520,7 @@ activate_language_child (CcRegionPanel *self, GtkWidget *child)
permission_acquired,
self);
}
} else if (child == priv->formats_row) {
} else if (row == priv->formats_row) {
show_format_chooser (self);
}
}
......@@ -604,19 +607,19 @@ setup_language_section (CcRegionPanel *self)
G_CALLBACK (update_region_from_setting), self);
priv->language_section = WID ("language_section");
priv->language_row = WID ("language_row");
priv->language_row = GTK_LIST_BOX_ROW (WID ("language_row"));
priv->language_label = WID ("language_label");
priv->formats_row = WID ("formats_row");
priv->formats_row = GTK_LIST_BOX_ROW (WID ("formats_row"));
priv->formats_label = WID ("formats_label");
widget = WID ("language_list");
egg_list_box_set_selection_mode (EGG_LIST_BOX (widget),
gtk_list_box_set_selection_mode (GTK_LIST_BOX (widget),
GTK_SELECTION_NONE);
egg_list_box_set_separator_funcs (EGG_LIST_BOX (widget),
update_separator_func,
NULL, NULL);
g_signal_connect_swapped (widget, "child-activated",
G_CALLBACK (activate_language_child), self);
gtk_list_box_set_header_func (GTK_LIST_BOX (widget),
update_header_func,
NULL, NULL);
g_signal_connect_swapped (widget, "row-activated",
G_CALLBACK (activate_language_row), self);
update_language_from_user (self);
update_region_from_setting (self);
......@@ -801,19 +804,22 @@ add_input_row (CcRegionPanel *self,
{
CcRegionPanelPrivate *priv = self->priv;
GtkWidget *row;
GtkWidget *box;
GtkWidget *label;
GtkWidget *image;
remove_no_input_row (GTK_CONTAINER (priv->input_list));
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
row = gtk_list_box_row_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (row), box);
label = gtk_label_new (name);
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
gtk_widget_set_margin_left (label, 20);
gtk_widget_set_margin_right (label, 20);
gtk_widget_set_margin_top (label, 6);
gtk_widget_set_margin_bottom (label, 6);
gtk_box_pack_start (GTK_BOX (row), label, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
if (strcmp (type, INPUT_SOURCE_TYPE_IBUS) == 0) {
image = gtk_image_new_from_icon_name ("system-run-symbolic", GTK_ICON_SIZE_BUTTON);
......@@ -822,7 +828,7 @@ add_input_row (CcRegionPanel *self,
gtk_widget_set_margin_top (image, 6);
gtk_widget_set_margin_bottom (image, 6);
gtk_style_context_add_class (gtk_widget_get_style_context (image), "dim-label");
gtk_box_pack_start (GTK_BOX (row), image, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), image, FALSE, TRUE, 0);
}
gtk_widget_show_all (row);
......@@ -934,7 +940,7 @@ select_by_id (GtkWidget *row,
row_id = (const gchar *)g_object_get_data (G_OBJECT (row), "id");
if (g_strcmp0 (row_id, id) == 0)
egg_list_box_select_child (EGG_LIST_BOX (gtk_widget_get_parent (row)), row);
gtk_list_box_select_row (GTK_LIST_BOX (gtk_widget_get_parent (row)), GTK_LIST_BOX_ROW (row));
}
static void
......@@ -951,10 +957,10 @@ input_sources_changed (GSettings *settings,
CcRegionPanel *self)
{
CcRegionPanelPrivate *priv = self->priv;
GtkWidget *selected;
GtkListBoxRow *selected;
gchar *id = NULL;
selected = egg_list_box_get_selected_child (EGG_LIST_BOX (priv->input_list));
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
if (selected)
id = g_strdup (g_object_get_data (G_OBJECT (selected), "id"));
clear_input_sources (self);
......@@ -970,7 +976,7 @@ static void
update_buttons (CcRegionPanel *self)
{
CcRegionPanelPrivate *priv = self->priv;
GtkWidget *selected;
GtkListBoxRow *selected;
GList *children;
gboolean multiple_sources;
......@@ -978,7 +984,7 @@ update_buttons (CcRegionPanel *self)
multiple_sources = g_list_next (children) != NULL;
g_list_free (children);
selected = egg_list_box_get_selected_child (EGG_LIST_BOX (priv->input_list));
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
if (selected == NULL) {
gtk_widget_set_visible (priv->show_config, FALSE);
gtk_widget_set_sensitive (priv->remove_input, FALSE);
......@@ -1221,16 +1227,16 @@ static void
do_remove_selected_input (CcRegionPanel *self)
{
CcRegionPanelPrivate *priv = self->priv;
GtkWidget *selected;
GtkListBoxRow *selected;
GtkWidget *sibling;
selected = egg_list_box_get_selected_child (EGG_LIST_BOX (priv->input_list));
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
if (selected == NULL)
return;
sibling = find_sibling (GTK_CONTAINER (priv->input_list), selected);
gtk_container_remove (GTK_CONTAINER (priv->input_list), selected);
egg_list_box_select_child (EGG_LIST_BOX (priv->input_list), sibling);
sibling = find_sibling (GTK_CONTAINER (priv->input_list), GTK_WIDGET (selected));
gtk_container_remove (GTK_CONTAINER (priv->input_list), GTK_WIDGET (selected));
gtk_list_box_select_row (GTK_LIST_BOX (priv->input_list), GTK_LIST_BOX_ROW (sibling));
priv->n_input_rows -= 1;
adjust_input_list_scrolling (self);
......@@ -1261,13 +1267,13 @@ static void
show_selected_settings (CcRegionPanel *self)
{
CcRegionPanelPrivate *priv = self->priv;
GtkWidget *selected;
GtkListBoxRow *selected;
GdkAppLaunchContext *ctx;
GDesktopAppInfo *app_info;
const gchar *id;
GError *error = NULL;
selected = egg_list_box_get_selected_child (EGG_LIST_BOX (priv->input_list));
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
if (selected == NULL)
return;
......@@ -1294,14 +1300,14 @@ static void
show_selected_layout (CcRegionPanel *self)
{
CcRegionPanelPrivate *priv = self->priv;
GtkWidget *selected;
GtkListBoxRow *selected;
const gchar *type;
const gchar *id;
const gchar *layout;
const gchar *variant;
gchar *commandline;
selected = egg_list_box_get_selected_child (EGG_LIST_BOX (priv->input_list));
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->input_list));
if (selected == NULL)
return;
......@@ -1413,12 +1419,12 @@ setup_input_section (CcRegionPanel *self)
g_signal_connect_swapped (priv->show_layout, "clicked",
G_CALLBACK (show_selected_layout), self);
egg_list_box_set_selection_mode (EGG_LIST_BOX (priv->input_list),
gtk_list_box_set_selection_mode (GTK_LIST_BOX (priv->input_list),
GTK_SELECTION_SINGLE);
egg_list_box_set_separator_funcs (EGG_LIST_BOX (priv->input_list),
update_separator_func,
NULL, NULL);
g_signal_connect_swapped (priv->input_list, "child-selected",
gtk_list_box_set_header_func (GTK_LIST_BOX (priv->input_list),
update_header_func,
NULL, NULL);
g_signal_connect_swapped (priv->input_list, "row-selected",
G_CALLBACK (update_buttons), self);
g_signal_connect (priv->input_settings, "changed::" KEY_INPUT_SOURCES,
......@@ -1647,7 +1653,7 @@ login_changed (CcRegionPanel *self)
gboolean can_acquire;
priv->login = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->login_button));
gtk_widget_set_visible (priv->formats_row, !priv->login);