[gnome-control-center] notifications: Use GtkTemplate
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] notifications: Use GtkTemplate
- Date: Mon, 15 Oct 2018 20:49:14 +0000 (UTC)
commit 9fa1e73da898ac30f72a2c8a8b227a15a7670e48
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Oct 10 15:41:37 2018 +1300
notifications: Use GtkTemplate
Switch from GtkBuilder to using GtkTemplate.
Rename widget IDs to be more readable.
Drop widget IDs that are not used.
Move code into the .ui file that can be.
Connect signals in swapped form.
panels/notifications/cc-notifications-panel.c | 139 ++++++-------
panels/notifications/cc-notifications-panel.ui | 242 +++++++++++++++++++++++
panels/notifications/meson.build | 2 +-
panels/notifications/notifications.gresource.xml | 2 +-
panels/notifications/notifications.ui | 228 ---------------------
po/POTFILES.in | 2 +-
6 files changed, 303 insertions(+), 312 deletions(-)
---
diff --git a/panels/notifications/cc-notifications-panel.c b/panels/notifications/cc-notifications-panel.c
index e46f0f8a2..83a2fdbee 100644
--- a/panels/notifications/cc-notifications-panel.c
+++ b/panels/notifications/cc-notifications-panel.c
@@ -35,21 +35,28 @@
#define APP_PREFIX "/org/gnome/desktop/notifications/application/"
struct _CcNotificationsPanel {
- CcPanel parent_instance;
+ CcPanel parent_instance;
- GSettings *master_settings;
- GtkBuilder *builder;
+ GtkListBox *app_listbox;
+ GtkSwitch *lock_screen_switch;
+ GtkScrolledWindow *main_scrolled_window;
+ GtkBox *main_box;
+ GtkListBox *options_listbox;
+ GtkSwitch *popups_switch;
+ GtkSizeGroup *sizegroup1;
- GCancellable *apps_load_cancellable;
+ GSettings *master_settings;
- GHashTable *known_applications;
+ GCancellable *apps_load_cancellable;
- GtkAdjustment *focus_adjustment;
+ GHashTable *known_applications;
- GList *sections;
- GList *sections_reverse;
+ GtkAdjustment *focus_adjustment;
- GDBusProxy *perm_store;
+ GList *sections;
+ GList *sections_reverse;
+
+ GDBusProxy *perm_store;
};
struct _CcNotificationsPanelClass {
@@ -67,7 +74,7 @@ typedef struct {
} Application;
static void build_app_store (CcNotificationsPanel *panel);
-static void select_app (GtkListBox *box, GtkListBoxRow *row, CcNotificationsPanel *panel);
+static void select_app (CcNotificationsPanel *panel, GtkListBoxRow *row);
static int sort_apps (gconstpointer one, gconstpointer two, gpointer user_data);
CC_PANEL_REGISTER (CcNotificationsPanel, cc_notifications_panel);
@@ -77,7 +84,6 @@ cc_notifications_panel_dispose (GObject *object)
{
CcNotificationsPanel *panel = CC_NOTIFICATIONS_PANEL (object);
- g_clear_object (&panel->builder);
g_clear_object (&panel->master_settings);
g_clear_pointer (&panel->known_applications, g_hash_table_unref);
g_clear_pointer (&panel->sections, g_list_free);
@@ -100,9 +106,9 @@ cc_notifications_panel_finalize (GObject *object)
}
static gboolean
-keynav_failed (GtkWidget *widget,
+keynav_failed (CcNotificationsPanel *panel,
GtkDirectionType direction,
- CcNotificationsPanel *panel)
+ GtkWidget *widget)
{
gdouble value, lower, upper, page;
GList *item, *sections;
@@ -164,79 +170,41 @@ on_perm_store_ready (GObject *source_object,
static void
cc_notifications_panel_init (CcNotificationsPanel *panel)
{
- GtkWidget *w;
- GtkWidget *label;
- g_autoptr(GError) error = NULL;
-
g_resources_register (cc_notifications_get_resource ());
+
+ gtk_widget_init_template (GTK_WIDGET (panel));
+
panel->known_applications = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, g_free);
- panel->builder = gtk_builder_new ();
- if (gtk_builder_add_from_resource (panel->builder,
- "/org/gnome/control-center/notifications/notifications.ui",
- &error) == 0)
- {
- g_error ("Error loading UI file: %s", error->message);
- return;
- }
-
panel->master_settings = g_settings_new (MASTER_SCHEMA);
g_settings_bind (panel->master_settings, "show-banners",
- gtk_builder_get_object (panel->builder, "ccnotify-switch-banners"),
+ panel->popups_switch,
"active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (panel->master_settings, "show-in-lock-screen",
- gtk_builder_get_object (panel->builder, "ccnotify-switch-lock-screen"),
+ panel->lock_screen_switch,
"active", G_SETTINGS_BIND_DEFAULT);
- w = GTK_WIDGET (gtk_builder_get_object (panel->builder,
- "ccnotify-main-scrolled-window"));
- panel->focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (w));
+ panel->focus_adjustment = gtk_scrolled_window_get_vadjustment (panel->main_scrolled_window);
- w = GTK_WIDGET (gtk_builder_get_object (panel->builder,
- "ccnotify-main-box"));
- gtk_container_set_focus_vadjustment (GTK_CONTAINER (w), panel->focus_adjustment);
+ gtk_container_set_focus_vadjustment (GTK_CONTAINER (panel->main_box), panel->focus_adjustment);
- w = GTK_WIDGET (gtk_builder_get_object (panel->builder,
- "ccnotify-switch-listbox"));
- panel->sections = g_list_append (panel->sections, w);
- panel->sections_reverse = g_list_prepend (panel->sections_reverse, w);
- g_signal_connect_object (w, "keynav-failed", G_CALLBACK (keynav_failed), panel, 0);
- gtk_list_box_set_header_func (GTK_LIST_BOX (w),
+ panel->sections = g_list_append (panel->sections, panel->options_listbox);
+ panel->sections_reverse = g_list_prepend (panel->sections_reverse, panel->options_listbox);
+ gtk_list_box_set_header_func (panel->options_listbox,
cc_list_box_update_header_func,
NULL, NULL);
- label = GTK_WIDGET (gtk_builder_get_object (panel->builder,
- "label1"));
- w = GTK_WIDGET (gtk_builder_get_object (panel->builder,
- "ccnotify-app-listbox"));
- atk_object_add_relationship (ATK_OBJECT (gtk_widget_get_accessible (label)),
- ATK_RELATION_LABEL_FOR,
- ATK_OBJECT (gtk_widget_get_accessible (w)));
- atk_object_add_relationship (ATK_OBJECT (gtk_widget_get_accessible (w)),
- ATK_RELATION_LABELLED_BY,
- ATK_OBJECT (gtk_widget_get_accessible (label)));
-
- panel->sections = g_list_append (panel->sections, w);
- panel->sections_reverse = g_list_prepend (panel->sections_reverse, w);
- g_signal_connect_object (w, "keynav-failed", G_CALLBACK (keynav_failed), panel, 0);
- gtk_list_box_set_sort_func (GTK_LIST_BOX (w), (GtkListBoxSortFunc)sort_apps, NULL, NULL);
- gtk_list_box_set_header_func (GTK_LIST_BOX (w),
+ panel->sections = g_list_append (panel->sections, panel->app_listbox);
+ panel->sections_reverse = g_list_prepend (panel->sections_reverse, panel->app_listbox);
+ gtk_list_box_set_sort_func (panel->app_listbox, (GtkListBoxSortFunc)sort_apps, NULL, NULL);
+ gtk_list_box_set_header_func (panel->app_listbox,
cc_list_box_update_header_func,
NULL, NULL);
- g_signal_connect_object (GTK_LIST_BOX (w), "row-activated",
- G_CALLBACK (select_app), panel, 0);
-
build_app_store (panel);
- w = GTK_WIDGET (gtk_builder_get_object (panel->builder,
- "ccnotify-main-scrolled-window"));
- gtk_container_add (GTK_CONTAINER (panel), w);
-
- gtk_widget_show (w);
-
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
@@ -257,8 +225,9 @@ cc_notifications_panel_get_help_uri (CcPanel *panel)
static void
cc_notifications_panel_class_init (CcNotificationsPanelClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
panel_class->get_help_uri = cc_notifications_panel_get_help_uri;
@@ -267,6 +236,19 @@ cc_notifications_panel_class_init (CcNotificationsPanelClass *klass)
* gets finalized */
object_class->dispose = cc_notifications_panel_dispose;
object_class->finalize = cc_notifications_panel_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/notifications/cc-notifications-panel.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, app_listbox);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, lock_screen_switch);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, main_scrolled_window);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, main_box);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, options_listbox);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, popups_switch);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, sizegroup1);
+
+ gtk_widget_class_bind_template_callback (widget_class, keynav_failed);
+ gtk_widget_class_bind_template_callback (widget_class, select_app);
}
static inline GQuark
@@ -306,7 +288,7 @@ static void
add_application (CcNotificationsPanel *panel,
Application *app)
{
- GtkWidget *box, *w, *row, *list_box;
+ GtkWidget *box, *w, *row;
g_autoptr(GIcon) icon = NULL;
const gchar *app_name;
int size;
@@ -330,17 +312,14 @@ add_application (CcNotificationsPanel *panel,
g_object_set_qdata_full (G_OBJECT (row), application_quark (),
app, (GDestroyNotify) application_free);
- list_box = GTK_WIDGET (gtk_builder_get_object (panel->builder,
- "ccnotify-app-listbox"));
-
- gtk_container_add (GTK_CONTAINER (list_box), row);
+ gtk_container_add (GTK_CONTAINER (panel->app_listbox), row);
gtk_container_add (GTK_CONTAINER (row), box);
w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
gtk_widget_show (w);
gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &size, NULL);
gtk_image_set_pixel_size (GTK_IMAGE (w), size);
- gtk_size_group_add_widget (GTK_SIZE_GROUP (gtk_builder_get_object (panel->builder, "sizegroup1")), w);
+ gtk_size_group_add_widget (panel->sizegroup1, w);
gtk_container_add (GTK_CONTAINER (box), w);
w = gtk_label_new (app_name);
@@ -527,9 +506,8 @@ load_apps_async (CcNotificationsPanel *panel)
}
static void
-children_changed (GSettings *settings,
- const char *key,
- CcNotificationsPanel *panel)
+children_changed (CcNotificationsPanel *panel,
+ const char *key)
{
int i;
g_auto (GStrv) new_app_ids = NULL;
@@ -545,19 +523,18 @@ static void
build_app_store (CcNotificationsPanel *panel)
{
/* Build application entries for known applications */
- children_changed (panel->master_settings, NULL, panel);
+ children_changed (panel, NULL);
g_signal_connect_object (panel->master_settings,
"changed::application-children",
- G_CALLBACK (children_changed), panel, 0);
+ G_CALLBACK (children_changed), panel, G_CONNECT_SWAPPED);
/* Scan applications that statically declare to show notifications */
load_apps_async (panel);
}
static void
-select_app (GtkListBox *list_box,
- GtkListBoxRow *row,
- CcNotificationsPanel *panel)
+select_app (CcNotificationsPanel *panel,
+ GtkListBoxRow *row)
{
Application *app;
g_autofree gchar *app_id = NULL;
diff --git a/panels/notifications/cc-notifications-panel.ui b/panels/notifications/cc-notifications-panel.ui
new file mode 100644
index 000000000..7527001d8
--- /dev/null
+++ b/panels/notifications/cc-notifications-panel.ui
@@ -0,0 +1,242 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <template class="CcNotificationsPanel" parent="CcPanel">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkScrolledWindow" id="main_scrolled_window">
+ <property name="height_request">400</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">never</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkViewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+
+ <!-- Stub boxes to make the content cover 1/3 of the screen -->
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
+ </child>
+
+ <!-- Content -->
+ <child>
+ <object class="GtkBox" id="main_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin">32</property>
+ <property name="orientation">vertical</property>
+ <property name="hexpand">True</property>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_bottom">32</property>
+ <property name="hexpand">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkListBox" id="options_listbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="selection_mode">none</property>
+ <property name="activate_on_single_click">False</property>
+ <signal name="keynav-failed" handler="keynav_failed"
object="CcNotificationsPanel" swapped="yes" />
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="activatable">False</property>
+ <property name="selectable">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="height_request">32</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="margin_start">12</property>
+ <property name="margin_top">8</property>
+ <property name="margin_bottom">8</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Notification
_Popups</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">popups_switch</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="popups_switch">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="margin_end">12</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="activatable">False</property>
+ <property name="selectable">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="height_request">32</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="margin_start">12</property>
+ <property name="margin_top">8</property>
+ <property name="margin_bottom">8</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Lock Screen
Notifications</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">lock_screen_switch</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="lock_screen_switch">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="margin_end">12</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label_item">
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="app_list_heading_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="margin_bottom">12</property>
+ <property name="label" translatable="yes" comments="List of
applications.">Applications</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ <accessibility>
+ <relation type="label-for" target="app_listbox"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkListBox" id="app_listbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="selection_mode">none</property>
+ <signal name="keynav-failed" handler="keynav_failed"
object="CcNotificationsPanel" swapped="yes" />
+ <signal name="row-activated" handler="select_app" object="CcNotificationsPanel"
swapped="yes" />
+ <accessibility>
+ <relation type="labelled-by" target="app_list_heading_label"/>
+ </accessibility>
+ </object>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+ <object class="GtkSizeGroup" id="sizegroup1">
+ <property name="mode">both</property>
+ </object>
+</interface>
diff --git a/panels/notifications/meson.build b/panels/notifications/meson.build
index 03930955a..bbec5dfea 100644
--- a/panels/notifications/meson.build
+++ b/panels/notifications/meson.build
@@ -24,7 +24,7 @@ sources = files(
resource_data = files(
'cc-app-notifications-dialog.ui',
- 'notifications.ui'
+ 'cc-notifications-panel.ui'
)
sources += gnome.compile_resources(
diff --git a/panels/notifications/notifications.gresource.xml
b/panels/notifications/notifications.gresource.xml
index 0098c9c0b..8f1d5dbb8 100644
--- a/panels/notifications/notifications.gresource.xml
+++ b/panels/notifications/notifications.gresource.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/control-center/notifications">
- <file preprocess="xml-stripblanks">notifications.ui</file>
<file preprocess="xml-stripblanks">cc-app-notifications-dialog.ui</file>
+ <file preprocess="xml-stripblanks">cc-notifications-panel.ui</file>
</gresource>
</gresources>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index bfea59b4c..1a0d2fc26 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -123,8 +123,8 @@ panels/network/wireless-security/ws-wpa-psk.c
panels/network/wireless-security/ws-wpa-psk.ui
panels/notifications/cc-app-notifications-dialog.ui
panels/notifications/cc-notifications-panel.c
+panels/notifications/cc-notifications-panel.ui
panels/notifications/gnome-notifications-panel.desktop.in.in
-panels/notifications/notifications.ui
panels/online-accounts/cc-online-accounts-panel.c
panels/online-accounts/gnome-online-accounts-panel.desktop.in.in
panels/online-accounts/online-accounts.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]