[gnome-control-center/wip/gbsneto/new-goa-panel: 1/23] online-accounts: turn into a final template class
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/gbsneto/new-goa-panel: 1/23] online-accounts: turn into a final template class
- Date: Thu, 10 Nov 2016 19:31:59 +0000 (UTC)
commit da41a217ee9150b2b3383bcad0f0647957059c01
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Nov 9 12:30:13 2016 -0200
online-accounts: turn into a final template class
Since CcPanel has support for G_DEFINE_{FINAL|DERIVABLE}_TYPE now,
lets use it in the Online Accounts panel and simplify some code.
https://bugzilla.gnome.org/show_bug.cgi?id=774222
panels/online-accounts/cc-online-accounts-panel.c | 91 +++++++--------------
panels/online-accounts/cc-online-accounts-panel.h | 8 +--
panels/online-accounts/online-accounts.ui | 26 ++++---
3 files changed, 47 insertions(+), 78 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-accounts-panel.c
b/panels/online-accounts/cc-online-accounts-panel.c
index 825448c..502ef94 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -35,18 +35,18 @@
#include "cc-online-accounts-model.h"
#include "cc-online-accounts-resources.h"
-typedef struct _CcGoaPanelClass CcGoaPanelClass;
-
struct _CcGoaPanel
{
CcPanel parent_instance;
- GtkBuilder *builder;
-
GoaClient *client;
GoaPanelAccountsModel *accounts_model;
+ GtkWidget *accounts_notebook;
+ GtkWidget *accounts_tree_box;
+ GtkWidget *accounts_tree_label;
+ GtkWidget *add_account_button;
GtkWidget *toolbar;
GtkWidget *toolbar_add_button;
GtkWidget *toolbar_remove_button;
@@ -54,11 +54,6 @@ struct _CcGoaPanel
GtkWidget *accounts_vbox;
};
-struct _CcGoaPanelClass
-{
- CcPanelClass parent_class;
-};
-
static void on_model_row_deleted (GtkTreeModel *tree_model,
GtkTreePath *path,
gpointer user_data);
@@ -192,7 +187,6 @@ cc_goa_panel_finalize (GObject *object)
g_clear_object (&panel->accounts_model);
g_clear_object (&panel->client);
- g_clear_object (&panel->builder);
G_OBJECT_CLASS (cc_goa_panel_parent_class)->finalize (object);
}
@@ -200,32 +194,18 @@ cc_goa_panel_finalize (GObject *object)
static void
cc_goa_panel_init (CcGoaPanel *panel)
{
- GtkWidget *button;
- GtkWidget *w;
GError *error;
- GtkStyleContext *context;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
GtkTreeIter iter;
GNetworkMonitor *monitor;
g_resources_register (cc_online_accounts_get_resource ());
- monitor = g_network_monitor_get_default();
- panel->builder = gtk_builder_new ();
- error = NULL;
- if (gtk_builder_add_from_resource (panel->builder,
- "/org/gnome/control-center/online-accounts/online-accounts.ui",
- &error) == 0)
- {
- g_warning ("Error loading UI file: %s (%s, %d)",
- error->message, g_quark_to_string (error->domain), error->code);
- g_error_free (error);
- goto out;
- }
+ gtk_widget_init_template (GTK_WIDGET (panel));
+
+ monitor = g_network_monitor_get_default();
- panel->toolbar = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-toolbar"));
- panel->toolbar_add_button = GTK_WIDGET (gtk_builder_get_object (panel->builder,
"accounts-tree-toolbutton-add"));
g_object_bind_property (monitor, "network-available",
panel->toolbar_add_button, "sensitive",
G_BINDING_SYNC_CREATE);
@@ -233,34 +213,24 @@ cc_goa_panel_init (CcGoaPanel *panel)
"clicked",
G_CALLBACK (on_toolbar_add_button_clicked),
panel);
- panel->toolbar_remove_button = GTK_WIDGET (gtk_builder_get_object (panel->builder,
"accounts-tree-toolbutton-remove"));
g_signal_connect (panel->toolbar_remove_button,
"clicked",
G_CALLBACK (on_toolbar_remove_button_clicked),
panel);
- context = gtk_widget_get_style_context (GTK_WIDGET (gtk_builder_get_object (panel->builder,
"accounts-tree-scrolledwindow")));
- gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
- context = gtk_widget_get_style_context (panel->toolbar);
- gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
-
- panel->accounts_treeview = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-treeview"));
g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->accounts_treeview)),
"changed",
G_CALLBACK (on_tree_view_selection_changed),
panel);
- button = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-button-add"));
g_object_bind_property (monitor, "network-available",
- button, "sensitive",
+ panel->add_account_button, "sensitive",
G_BINDING_SYNC_CREATE);
- g_signal_connect (button,
+ g_signal_connect (panel->add_account_button,
"clicked",
G_CALLBACK (on_add_button_clicked),
panel);
- panel->accounts_vbox = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-vbox"));
-
/* TODO: probably want to avoid _sync() ... */
error = NULL;
panel->client = goa_client_new_sync (NULL /* GCancellable */, &error);
@@ -268,8 +238,7 @@ cc_goa_panel_init (CcGoaPanel *panel)
{
g_warning ("Error getting a GoaClient: %s (%s, %d)",
error->message, g_quark_to_string (error->domain), error->code);
- w = GTK_WIDGET (gtk_builder_get_object (panel->builder, "goa-top-widget"));
- gtk_widget_set_sensitive (w, FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET (panel), FALSE);
g_error_free (error);
goto out;
}
@@ -325,9 +294,7 @@ cc_goa_panel_init (CcGoaPanel *panel)
&iter);
out:
- w = GTK_WIDGET (gtk_builder_get_object (panel->builder, "goa-top-widget"));
- gtk_container_add (GTK_CONTAINER (panel), w);
- gtk_widget_show_all (w);
+ gtk_widget_show_all (GTK_WIDGET (panel));
}
static const char *
@@ -339,6 +306,7 @@ cc_goa_panel_get_help_uri (CcPanel *panel)
static void
cc_goa_panel_class_init (CcGoaPanelClass *klass)
{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
@@ -348,6 +316,18 @@ cc_goa_panel_class_init (CcGoaPanelClass *klass)
object_class->finalize = cc_goa_panel_finalize;
g_object_class_override_property (object_class, PROP_PARAMETERS, "parameters");
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/online-accounts/online-accounts.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_notebook);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_treeview);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_tree_box);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_tree_label);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, accounts_vbox);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, add_account_button);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, toolbar);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, toolbar_add_button);
+ gtk_widget_class_bind_template_child (widget_class, CcGoaPanel, toolbar_remove_button);
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -356,24 +336,16 @@ static void
show_page (CcGoaPanel *panel,
gint page_num)
{
- GtkNotebook *notebook;
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->builder, "accounts-notebook"));
- gtk_notebook_set_current_page (notebook, page_num);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->accounts_notebook), page_num);
}
static void
show_page_nothing_selected (CcGoaPanel *panel)
{
- GtkWidget *box;
- GtkWidget *label;
-
show_page (panel, 0);
- box = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-box"));
- gtk_widget_set_sensitive (box, FALSE);
-
- label = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-label"));
- gtk_widget_show (label);
+ gtk_widget_set_sensitive (panel->accounts_tree_box, FALSE);
+ gtk_widget_show (panel->accounts_tree_label);
}
static void
@@ -382,8 +354,6 @@ show_page_account (CcGoaPanel *panel,
{
GList *children;
GList *l;
- GtkWidget *box;
- GtkWidget *label;
GoaProvider *provider;
GoaAccount *account;
const gchar *provider_type;
@@ -391,11 +361,8 @@ show_page_account (CcGoaPanel *panel,
provider = NULL;
show_page (panel, 1);
- box = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-box"));
- gtk_widget_set_sensitive (box, TRUE);
-
- label = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-label"));
- gtk_widget_hide (label);
+ gtk_widget_set_sensitive (panel->accounts_tree_box, TRUE);
+ gtk_widget_hide (panel->accounts_tree_label);
/* Out with the old */
children = gtk_container_get_children (GTK_CONTAINER (panel->accounts_vbox));
diff --git a/panels/online-accounts/cc-online-accounts-panel.h
b/panels/online-accounts/cc-online-accounts-panel.h
index 65b7f2a..aa10e15 100644
--- a/panels/online-accounts/cc-online-accounts-panel.h
+++ b/panels/online-accounts/cc-online-accounts-panel.h
@@ -25,13 +25,9 @@
G_BEGIN_DECLS
-#define CC_GOA_TYPE_PANEL (cc_goa_panel_get_type ())
-#define CC_GOA_PANEL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CC_GOA_TYPE_PANEL, CcGoaPanel))
-#define CC_GOA_IS_PANEL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CC_GOA_TYPE_PANEL))
+#define CC_TYPE_ONLINE_ACCOUNTS_PANEL (cc_goa_panel_get_type())
-typedef struct _CcGoaPanel CcGoaPanel;
-
-GType cc_goa_panel_get_type (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (CcGoaPanel, cc_goa_panel, CC, GOA_PANEL, CcPanel)
G_END_DECLS
diff --git a/panels/online-accounts/online-accounts.ui b/panels/online-accounts/online-accounts.ui
index 3bba624..add2a99 100644
--- a/panels/online-accounts/online-accounts.ui
+++ b/panels/online-accounts/online-accounts.ui
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <object class="GtkBox" id="goa-top-widget">
+ <template class="CcGoaPanel" parent="CcPanel">
+ <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>
<property name="spacing">18</property>
@@ -12,7 +16,7 @@
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<child>
- <object class="GtkBox" id="accounts-tree-box">
+ <object class="GtkBox" id="accounts_tree_box">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">0</property>
@@ -27,7 +31,7 @@
<property name="shadow_type">in</property>
<property name="min_content_height">300</property>
<child>
- <object class="GtkTreeView" id="accounts-tree-treeview">
+ <object class="GtkTreeView" id="accounts_treeview">
<property name="width_request">278</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -44,7 +48,7 @@
</object>
</child>
<child type="overlay">
- <object class="GtkLabel" id="accounts-tree-label">
+ <object class="GtkLabel" id="accounts_tree_label">
<property name="can_focus">False</property>
<property name="no-show-all">True</property>
<property name="justify">center</property>
@@ -61,7 +65,7 @@
</packing>
</child>
<child>
- <object class="GtkToolbar" id="accounts-tree-toolbar">
+ <object class="GtkToolbar" id="toolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">icons</property>
@@ -70,7 +74,7 @@
<class name="inline-toolbar"/>
</style>
<child>
- <object class="GtkToolButton" id="accounts-tree-toolbutton-add">
+ <object class="GtkToolButton" id="toolbar_add_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
@@ -83,7 +87,7 @@
</packing>
</child>
<child>
- <object class="GtkToolButton" id="accounts-tree-toolbutton-remove">
+ <object class="GtkToolButton" id="toolbar_remove_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
@@ -105,7 +109,7 @@
</object>
</child>
<child>
- <object class="GtkNotebook" id="accounts-notebook">
+ <object class="GtkNotebook" id="accounts_notebook">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_tabs">False</property>
@@ -124,7 +128,7 @@
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
- <object class="GtkButton" id="accounts-button-add">
+ <object class="GtkButton" id="add_account_button">
<property name="label" translatable="yes">Add an online account</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
@@ -175,7 +179,7 @@
</packing>
</child>
<child>
- <object class="GtkBox" id="accounts-vbox">
+ <object class="GtkBox" id="accounts_vbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
@@ -216,4 +220,6 @@
</packing>
</child>
</object>
+ </child>
+ </template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]