[gnome-control-center] region: Turn CcInputOptions into a templatized composite widget
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] region: Turn CcInputOptions into a templatized composite widget
- Date: Fri, 20 Nov 2015 17:33:49 +0000 (UTC)
commit 7d9f7f30bc538e14d64a07b71c2ba3225c89d130
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Nov 13 12:21:11 2015 +0100
region: Turn CcInputOptions into a templatized composite widget
This is a pre-requisite for using a header bar.
GtkDialog:use-header-bar is a construct-only property, and has no
effect when set from the XML. Therefore, the only option is to turn
the widget into a template and set use-header-bar from C.
There should be no behavioral changes due to this patch.
Bump required GLib version for the G_DECLARE_FINAL_TYPE macro.
https://bugzilla.gnome.org/show_bug.cgi?id=757516
configure.ac | 2 +-
panels/region/cc-input-options.c | 122 +++++++++++++++++++-------------------
panels/region/cc-input-options.h | 5 +-
panels/region/input-options.ui | 24 ++++----
4 files changed, 78 insertions(+), 75 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index edaa20c..f93034c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,7 +85,7 @@ dnl ==============================================
dnl Check that we meet the dependencies
dnl ==============================================
-GLIB_REQUIRED_VERSION=2.39.91
+GLIB_REQUIRED_VERSION=2.44.0
GTK_REQUIRED_VERSION=3.15.0
PA_REQUIRED_VERSION=2.0
CANBERRA_REQUIRED_VERSION=0.13
diff --git a/panels/region/cc-input-options.c b/panels/region/cc-input-options.c
index 1ef761f..a72ef63 100644
--- a/panels/region/cc-input-options.c
+++ b/panels/region/cc-input-options.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013, 2015 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -26,25 +26,20 @@
#include "cc-input-options.h"
-typedef struct {
+struct _CcInputOptions {
+ GtkDialog parent_instance;
GtkWidget *same_source;
GtkWidget *per_window_source;
GtkWidget *previous_source;
+ GtkWidget *previous_source_label;
GtkWidget *next_source;
+ GtkWidget *next_source_label;
GtkWidget *alt_next_source;
+ GtkWidget *alt_next_source_label;
GSettings *settings;
-} CcInputOptionsPrivate;
+};
-#define GET_PRIVATE(options) ((CcInputOptionsPrivate *) g_object_get_data (G_OBJECT (options), "private"))
-
-static void
-cc_input_options_private_free (gpointer data)
-{
- CcInputOptionsPrivate *priv = data;
-
- g_clear_object (&priv->settings);
- g_free (priv);
-}
+G_DEFINE_TYPE (CcInputOptions, cc_input_options, GTK_TYPE_DIALOG);
static void
update_shortcut_label (GtkWidget *widget,
@@ -73,9 +68,8 @@ update_shortcut_label (GtkWidget *widget,
}
static void
-update_shortcuts (GtkWidget *options)
+update_shortcuts (CcInputOptions *self)
{
- CcInputOptionsPrivate *priv = GET_PRIVATE (options);
gchar **previous;
gchar **next;
gchar *previous_shortcut;
@@ -88,8 +82,8 @@ update_shortcuts (GtkWidget *options)
previous_shortcut = g_strdup (previous[0]);
- update_shortcut_label (priv->previous_source, previous_shortcut);
- update_shortcut_label (priv->next_source, next[0]);
+ update_shortcut_label (self->previous_source, previous_shortcut);
+ update_shortcut_label (self->next_source, next[0]);
g_free (previous_shortcut);
@@ -100,9 +94,8 @@ update_shortcuts (GtkWidget *options)
}
static void
-update_modifiers_shortcut (GtkWidget *dialog)
+update_modifiers_shortcut (CcInputOptions *self)
{
- CcInputOptionsPrivate *priv = GET_PRIVATE (dialog);
gchar **options, **p;
GSettings *settings;
GnomeXkbInfo *xkb_info;
@@ -118,9 +111,9 @@ update_modifiers_shortcut (GtkWidget *dialog)
if (p && *p) {
text = gnome_xkb_info_description_for_option (xkb_info, "grp", *p);
- gtk_label_set_text (GTK_LABEL (priv->alt_next_source), text);
+ gtk_label_set_text (GTK_LABEL (self->alt_next_source), text);
} else {
- gtk_widget_hide (priv->alt_next_source);
+ gtk_widget_hide (self->alt_next_source);
}
g_strfreev (options);
@@ -128,57 +121,64 @@ update_modifiers_shortcut (GtkWidget *dialog)
g_object_unref (xkb_info);
}
-#define WID(name) ((GtkWidget *) gtk_builder_get_object (builder, name))
-
-GtkWidget *
-cc_input_options_new (GtkWidget *parent)
+static void
+cc_input_options_finalize (GObject *object)
{
- GtkBuilder *builder;
- GtkWidget *options;
- CcInputOptionsPrivate *priv;
- GError *error = NULL;
-
- builder = gtk_builder_new ();
- if (gtk_builder_add_from_resource (builder, "/org/gnome/control-center/region/input-options.ui",
&error) == 0) {
- g_object_unref (builder);
- g_warning ("failed to load input options: %s", error->message);
- g_error_free (error);
- return NULL;
- }
+ CcInputOptions *self = CC_INPUT_OPTIONS (object);
- options = WID ("dialog");
- priv = g_new0 (CcInputOptionsPrivate, 1);
- g_object_set_data_full (G_OBJECT (options), "private", priv, cc_input_options_private_free);
- g_object_set_data_full (G_OBJECT (options), "builder", builder, g_object_unref);
+ g_object_unref (self->settings);
+ G_OBJECT_CLASS (cc_input_options_parent_class)->finalize (object);
+}
- priv->same_source = WID ("same-source");
- priv->per_window_source = WID ("per-window-source");
- priv->previous_source = WID ("previous-source");
- priv->next_source = WID ("next-source");
- priv->alt_next_source = WID ("alt-next-source");
+static void
+cc_input_options_init (CcInputOptions *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
- g_object_bind_property (priv->previous_source, "visible",
- WID ("previous-source-label"), "visible",
+ g_object_bind_property (self->previous_source, "visible",
+ self->previous_source_label, "visible",
G_BINDING_DEFAULT);
- g_object_bind_property (priv->next_source, "visible",
- WID ("next-source-label"), "visible",
+ g_object_bind_property (self->next_source, "visible",
+ self->next_source_label, "visible",
G_BINDING_DEFAULT);
- g_object_bind_property (priv->alt_next_source, "visible",
- WID ("alt-next-source-label"), "visible",
+ g_object_bind_property (self->alt_next_source, "visible",
+ self->alt_next_source_label, "visible",
G_BINDING_DEFAULT);
- priv->settings = g_settings_new ("org.gnome.desktop.input-sources");
- g_settings_bind (priv->settings, "per-window",
- priv->per_window_source, "active",
+ self->settings = g_settings_new ("org.gnome.desktop.input-sources");
+ g_settings_bind (self->settings, "per-window",
+ self->per_window_source, "active",
G_SETTINGS_BIND_DEFAULT);
- g_settings_bind (priv->settings, "per-window",
- priv->same_source, "active",
+ g_settings_bind (self->settings, "per-window",
+ self->same_source, "active",
G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);
- update_shortcuts (options);
- update_modifiers_shortcut (options);
+ update_shortcuts (self);
+ update_modifiers_shortcut (self);
+}
- gtk_window_set_transient_for (GTK_WINDOW (options), GTK_WINDOW (parent));
+static void
+cc_input_options_class_init (CcInputOptionsClass *klass)
+{
+ GObjectClass *object_klass = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_klass = GTK_WIDGET_CLASS (klass);
+
+ object_klass->finalize = cc_input_options_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_klass,
+ "/org/gnome/control-center/region/input-options.ui");
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, same_source);
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, per_window_source);
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, previous_source);
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, previous_source_label);
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, next_source);
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, next_source_label);
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, alt_next_source);
+ gtk_widget_class_bind_template_child (widget_klass, CcInputOptions, alt_next_source_label);
+}
- return options;
+GtkWidget *
+cc_input_options_new (GtkWidget *parent)
+{
+ return g_object_new (CC_TYPE_INPUT_OPTIONS, "transient-for", parent, NULL);
}
diff --git a/panels/region/cc-input-options.h b/panels/region/cc-input-options.h
index ac1c6e1..cd472d7 100644
--- a/panels/region/cc-input-options.h
+++ b/panels/region/cc-input-options.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Red Hat, Inc
+ * Copyright (C) 2013, 2015 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -26,6 +26,9 @@
G_BEGIN_DECLS
+#define CC_TYPE_INPUT_OPTIONS (cc_input_options_get_type ())
+G_DECLARE_FINAL_TYPE (CcInputOptions, cc_input_options, CC, INPUT_OPTIONS, GtkDialog)
+
GtkWidget *cc_input_options_new (GtkWidget *parent);
G_END_DECLS
diff --git a/panels/region/input-options.ui b/panels/region/input-options.ui
index 723314e..ad5a144 100644
--- a/panels/region/input-options.ui
+++ b/panels/region/input-options.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.0 -->
- <object class="GtkDialog" id="dialog">
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="CcInputOptions" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Input Source Options</property>
@@ -49,7 +49,7 @@
<property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<child>
- <object class="GtkRadioButton" id="same-source">
+ <object class="GtkRadioButton" id="same_source">
<property name="label" translatable="yes">Use the _same source for all windows</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -67,7 +67,7 @@
</packing>
</child>
<child>
- <object class="GtkRadioButton" id="per-window-source">
+ <object class="GtkRadioButton" id="per_window_source">
<property name="label" translatable="yes">Allow _different sources for each window</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -76,7 +76,7 @@
<property name="xalign">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
- <property name="group">same-source</property>
+ <property name="group">same_source</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -104,7 +104,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="previous-source-label">
+ <object class="GtkLabel" id="previous_source_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
@@ -121,7 +121,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="previous-source">
+ <object class="GtkLabel" id="previous_source">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
@@ -135,7 +135,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="next-source-label">
+ <object class="GtkLabel" id="next_source_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
@@ -152,7 +152,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="next-source">
+ <object class="GtkLabel" id="next_source">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
@@ -183,7 +183,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="alt-next-source-label">
+ <object class="GtkLabel" id="alt_next_source_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
@@ -200,7 +200,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="alt-next-source">
+ <object class="GtkLabel" id="alt_next_source">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
@@ -225,5 +225,5 @@
<action-widgets>
<action-widget response="-5">ok-button</action-widget>
</action-widgets>
- </object>
+ </template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]