[gnome-control-center] online-accounts: Add CcOnlineAccountRow
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] online-accounts: Add CcOnlineAccountRow
- Date: Wed, 11 May 2022 02:59:03 +0000 (UTC)
commit b7302348cfdf058374a6020224545c080077db3d
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Nov 3 16:01:34 2020 +1300
online-accounts: Add CcOnlineAccountRow
panels/online-accounts/cc-online-account-row.c | 140 +++++++++++++++++++++
panels/online-accounts/cc-online-account-row.h | 35 ++++++
panels/online-accounts/cc-online-account-row.ui | 17 +++
panels/online-accounts/cc-online-accounts-panel.c | 87 ++-----------
panels/online-accounts/meson.build | 2 +
.../online-accounts/online-accounts.gresource.xml | 1 +
6 files changed, 204 insertions(+), 78 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-account-row.c b/panels/online-accounts/cc-online-account-row.c
new file mode 100644
index 000000000..1406a3d04
--- /dev/null
+++ b/panels/online-accounts/cc-online-account-row.c
@@ -0,0 +1,140 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright 2020 Canonical Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <glib/gi18n.h>
+
+#include "cc-online-account-row.h"
+#include "cc-online-accounts-resources.h"
+
+struct _CcOnlineAccountRow
+{
+ AdwActionRow parent;
+
+ GtkImage *icon_image;
+ GtkImage *warning_image;
+
+ GoaObject *object;
+};
+
+G_DEFINE_TYPE (CcOnlineAccountRow, cc_online_account_row, ADW_TYPE_ACTION_ROW)
+
+static gboolean
+is_gicon_symbolic (GtkWidget *widget,
+ GIcon *icon)
+{
+ g_autoptr(GtkIconPaintable) icon_paintable = NULL;
+ GtkIconTheme *icon_theme;
+
+ icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
+ icon_paintable = gtk_icon_theme_lookup_by_gicon (icon_theme,
+ icon,
+ 32,
+ gtk_widget_get_scale_factor (widget),
+ gtk_widget_get_direction (widget),
+ 0);
+
+ return icon_paintable && gtk_icon_paintable_is_symbolic (icon_paintable);
+}
+
+static void
+cc_online_account_row_dispose (GObject *object)
+{
+ CcOnlineAccountRow *self = CC_ONLINE_ACCOUNT_ROW (object);
+
+ g_clear_object (&self->object);
+
+ G_OBJECT_CLASS (cc_online_account_row_parent_class)->dispose (object);
+}
+
+static void
+cc_online_account_row_class_init (CcOnlineAccountRowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->dispose = cc_online_account_row_dispose;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/online-accounts/cc-online-account-row.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, CcOnlineAccountRow, icon_image);
+ gtk_widget_class_bind_template_child (widget_class, CcOnlineAccountRow, warning_image);
+}
+
+static void
+cc_online_account_row_init (CcOnlineAccountRow *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+CcOnlineAccountRow *
+cc_online_account_row_new (GoaObject *object)
+{
+ CcOnlineAccountRow *self;
+ GoaAccount *account;
+ g_autoptr(GIcon) gicon = NULL;
+ g_autoptr(GError) error = NULL;
+
+ self = g_object_new (cc_online_account_row_get_type (), NULL);
+
+ self->object = g_object_ref (object);
+
+ account = goa_object_peek_account (object);
+
+ adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self),
+ goa_account_get_provider_name (account));
+ adw_action_row_set_subtitle (ADW_ACTION_ROW (self),
+ goa_account_get_presentation_identity (account));
+
+ gicon = g_icon_new_for_string (goa_account_get_provider_icon (account), &error);
+ if (error != NULL)
+ {
+ g_warning ("Error creating GIcon for account: %s (%s, %d)",
+ error->message,
+ g_quark_to_string (error->domain),
+ error->code);
+ }
+ else
+ {
+ gtk_image_set_from_gicon (self->icon_image, gicon);
+
+ if (is_gicon_symbolic (GTK_WIDGET (self), gicon))
+ {
+ gtk_image_set_icon_size (self->icon_image, GTK_ICON_SIZE_NORMAL);
+ gtk_widget_add_css_class (GTK_WIDGET (self->icon_image), "symbolic-circular");
+ }
+ else
+ {
+ gtk_image_set_icon_size (self->icon_image, GTK_ICON_SIZE_LARGE);
+ gtk_widget_add_css_class (GTK_WIDGET (self->icon_image), "lowres-icon");
+ }
+ }
+
+ g_object_bind_property (account, "attention-needed",
+ self->warning_image, "visible",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+
+ return self;
+}
+
+GoaObject *
+cc_online_account_row_get_object (CcOnlineAccountRow *self)
+{
+ g_return_val_if_fail (CC_IS_ONLINE_ACCOUNT_ROW (self), NULL);
+ return self->object;
+}
diff --git a/panels/online-accounts/cc-online-account-row.h b/panels/online-accounts/cc-online-account-row.h
new file mode 100644
index 000000000..aa0df4b98
--- /dev/null
+++ b/panels/online-accounts/cc-online-account-row.h
@@ -0,0 +1,35 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright 2020 Canonical Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+#include <adwaita.h>
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+#include <goa/goa.h>
+
+G_BEGIN_DECLS
+
+G_DECLARE_FINAL_TYPE (CcOnlineAccountRow, cc_online_account_row, CC, ONLINE_ACCOUNT_ROW, AdwActionRow)
+
+CcOnlineAccountRow *cc_online_account_row_new (GoaObject *object);
+
+GoaObject *cc_online_account_row_get_object (CcOnlineAccountRow *row);
+
+G_END_DECLS
diff --git a/panels/online-accounts/cc-online-account-row.ui b/panels/online-accounts/cc-online-account-row.ui
new file mode 100644
index 000000000..15dee5351
--- /dev/null
+++ b/panels/online-accounts/cc-online-account-row.ui
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="CcOnlineAccountRow" parent="AdwActionRow">
+ <property name="activatable">True</property>
+ <child type="prefix">
+ <object class="GtkImage" id="icon_image">
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ </object>
+ </child>
+ <child type="suffix">
+ <object class="GtkImage" id="warning_image">
+ <property name="icon-name">dialog-warning-symbolic</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/panels/online-accounts/cc-online-accounts-panel.c
b/panels/online-accounts/cc-online-accounts-panel.c
index 44498f220..6fc9d036d 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -29,6 +29,7 @@
#include "cc-online-accounts-panel.h"
#include "cc-online-account-provider-row.h"
+#include "cc-online-account-row.h"
#include "cc-online-accounts-resources.h"
#ifdef GDK_WINDOWING_X11
@@ -125,7 +126,7 @@ modify_row_for_account (CcOnlineAccountsPanel *self,
{
GoaObject *row_object;
- row_object = g_object_get_data (G_OBJECT (l->data), "goa-object");
+ row_object = cc_online_account_row_get_object (CC_ONLINE_ACCOUNT_ROW (l->data));
if (row_object == object)
{
GtkWidget *row = GTK_WIDGET (l->data);
@@ -370,24 +371,6 @@ create_account (CcOnlineAccountsPanel *self,
self);
}
-static gboolean
-is_gicon_symbolic (GtkWidget *widget,
- GIcon *icon)
-{
- g_autoptr(GtkIconPaintable) icon_paintable = NULL;
- GtkIconTheme *icon_theme;
-
- icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
- icon_paintable = gtk_icon_theme_lookup_by_gicon (icon_theme,
- icon,
- 32,
- gtk_widget_get_scale_factor (widget),
- gtk_widget_get_direction (widget),
- 0);
-
- return icon_paintable && gtk_icon_paintable_is_symbolic (icon_paintable);
-}
-
static void
add_provider_row (CcOnlineAccountsPanel *self,
GVariant *provider)
@@ -432,64 +415,12 @@ static void
add_account (CcOnlineAccountsPanel *self,
GoaObject *object)
{
- g_autoptr(GError) error = NULL;
- g_autoptr(GIcon) gicon = NULL;
- GoaAccount *account;
- GtkWidget *row, *icon;
-
- account = goa_object_peek_account (object);
-
- row = adw_action_row_new ();
- g_object_set_data (G_OBJECT (row), "goa-object", object);
- gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), TRUE);
-
- adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row),
- goa_account_get_provider_name (account));
- adw_action_row_set_subtitle (ADW_ACTION_ROW (row),
- goa_account_get_presentation_identity (account));
-
- /* The provider icon */
- icon = gtk_image_new ();
- gtk_widget_set_halign (icon, GTK_ALIGN_CENTER);
- gtk_widget_set_valign (icon, GTK_ALIGN_CENTER);
+ CcOnlineAccountRow *row;
- gicon = g_icon_new_for_string (goa_account_get_provider_icon (account), &error);
- if (error != NULL)
- {
- g_warning ("Error creating GIcon for account: %s (%s, %d)",
- error->message,
- g_quark_to_string (error->domain),
- error->code);
- }
- else
- {
- gtk_image_set_from_gicon (GTK_IMAGE (icon), gicon);
-
- if (is_gicon_symbolic (icon, gicon))
- {
- gtk_image_set_icon_size (GTK_IMAGE (icon), GTK_ICON_SIZE_NORMAL);
- gtk_widget_add_css_class (icon, "symbolic-circular");
- }
- else
- {
- gtk_image_set_icon_size (GTK_IMAGE (icon), GTK_ICON_SIZE_LARGE);
- gtk_widget_add_css_class (icon, "lowres-icon");
- }
-
- }
- adw_action_row_add_prefix (ADW_ACTION_ROW (row), icon);
-
- /* "Needs attention" icon */
- icon = gtk_image_new_from_icon_name ("dialog-warning-symbolic");
- g_object_bind_property (account,
- "attention-needed",
- icon,
- "visible",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- adw_action_row_add_suffix (ADW_ACTION_ROW (row), icon);
+ row = cc_online_account_row_new (object);
/* Add to the listbox */
- gtk_list_box_append (self->accounts_listbox, row);
+ gtk_list_box_append (self->accounts_listbox, GTK_WIDGET (row));
gtk_widget_show (GTK_WIDGET (self->accounts_frame));
}
@@ -575,7 +506,7 @@ select_account_by_id (CcOnlineAccountsPanel *self,
GoaAccount *account;
GoaObject *row_object;
- row_object = g_object_get_data (G_OBJECT (child), "goa-object");
+ row_object = cc_online_account_row_get_object (CC_ONLINE_ACCOUNT_ROW (child));
account = goa_object_peek_account (row_object);
if (g_strcmp0 (goa_account_get_id (account), account_id) == 0)
@@ -662,10 +593,10 @@ sort_accounts_func (GtkListBoxRow *a,
GoaAccount *a_account, *b_account;
GoaObject *a_object, *b_object;
- a_object = g_object_get_data (G_OBJECT (a), "goa-object");
+ a_object = cc_online_account_row_get_object (CC_ONLINE_ACCOUNT_ROW (a));
a_account = goa_object_peek_account (a_object);
- b_object = g_object_get_data (G_OBJECT (b), "goa-object");
+ b_object = cc_online_account_row_get_object (CC_ONLINE_ACCOUNT_ROW (b));
b_account = goa_object_peek_account (b_object);
return g_strcmp0 (goa_account_get_id (a_account), goa_account_get_id (b_account));
@@ -734,7 +665,7 @@ static void
on_accounts_listbox_row_activated (CcOnlineAccountsPanel *self,
GtkListBoxRow *activated_row)
{
- GoaObject *object = g_object_get_data (G_OBJECT (activated_row), "goa-object");
+ GoaObject *object = cc_online_account_row_get_object (CC_ONLINE_ACCOUNT_ROW (activated_row));
show_account (self, object);
}
diff --git a/panels/online-accounts/meson.build b/panels/online-accounts/meson.build
index 3265503ee..9d1b918e8 100644
--- a/panels/online-accounts/meson.build
+++ b/panels/online-accounts/meson.build
@@ -22,11 +22,13 @@ cflags += [
sources = files(
'cc-online-account-provider-row.c',
+ 'cc-online-account-row.c',
'cc-online-accounts-panel.c',
)
resource_data = files(
'cc-online-account-provider-row.ui',
+ 'cc-online-account-row.ui',
'cc-online-accounts-panel.ui',
'online-accounts.css',
)
diff --git a/panels/online-accounts/online-accounts.gresource.xml
b/panels/online-accounts/online-accounts.gresource.xml
index c562c8c38..0e452b6c8 100644
--- a/panels/online-accounts/online-accounts.gresource.xml
+++ b/panels/online-accounts/online-accounts.gresource.xml
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/control-center/online-accounts">
<file preprocess="xml-stripblanks">cc-online-account-provider-row.ui</file>
+ <file preprocess="xml-stripblanks">cc-online-account-row.ui</file>
<file preprocess="xml-stripblanks">cc-online-accounts-panel.ui</file>
<file>online-accounts.css</file>
</gresource>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]