[gnome-control-center] online-accounts: Add CcOnlineAccountProviderRow



commit 32a807b964768f2c2b9a2cae777023b0670867f7
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Nov 3 15:25:58 2020 +1300

    online-accounts: Add CcOnlineAccountProviderRow

 .../cc-online-account-provider-row.c               | 135 +++++++++++++++++++++
 .../cc-online-account-provider-row.h               |  32 +++++
 .../cc-online-account-provider-row.ui              |  12 ++
 panels/online-accounts/cc-online-accounts-panel.c  |  62 ++--------
 panels/online-accounts/meson.build                 |   6 +-
 .../online-accounts/online-accounts.gresource.xml  |   1 +
 po/POTFILES.in                                     |   1 +
 7 files changed, 195 insertions(+), 54 deletions(-)
---
diff --git a/panels/online-accounts/cc-online-account-provider-row.c 
b/panels/online-accounts/cc-online-account-provider-row.c
new file mode 100644
index 000000000..d581d1523
--- /dev/null
+++ b/panels/online-accounts/cc-online-account-provider-row.c
@@ -0,0 +1,135 @@
+/* -*- 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-provider-row.h"
+#include "cc-online-accounts-resources.h"
+
+struct _CcOnlineAccountProviderRow
+{
+  AdwActionRow parent;
+
+  GtkImage *icon_image;
+
+  GVariant *provider;
+};
+
+G_DEFINE_TYPE (CcOnlineAccountProviderRow, cc_online_account_provider_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_provider_row_dispose (GObject *object)
+{
+  CcOnlineAccountProviderRow *self = CC_ONLINE_ACCOUNT_PROVIDER_ROW (object);
+
+  g_clear_pointer (&self->provider, g_variant_unref);
+
+  G_OBJECT_CLASS (cc_online_account_provider_row_parent_class)->dispose (object);
+}
+
+static void
+cc_online_account_provider_row_class_init (CcOnlineAccountProviderRowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = cc_online_account_provider_row_dispose;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/online-accounts/cc-online-account-provider-row.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, CcOnlineAccountProviderRow, icon_image);
+}
+
+static void
+cc_online_account_provider_row_init (CcOnlineAccountProviderRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+CcOnlineAccountProviderRow *
+cc_online_account_provider_row_new (GVariant *provider)
+{
+  CcOnlineAccountProviderRow *self;
+  g_autoptr(GIcon) icon = NULL;
+  g_autofree gchar *name = NULL;
+
+  self = g_object_new (cc_online_account_provider_row_get_type (), NULL);
+
+  if (provider == NULL)
+    {
+      icon = g_themed_icon_new_with_default_fallbacks ("goa-account");
+      name = g_strdup (C_("Online Account", "Other"));
+    }
+  else
+    {
+      g_autoptr(GVariant) icon_variant = NULL;
+
+      self->provider = g_variant_ref (provider);
+
+      g_variant_get (provider, "(ssviu)",
+                     NULL,
+                     &name,
+                     &icon_variant,
+                     NULL,
+                     NULL);
+
+      icon = g_icon_deserialize (icon_variant);
+    }
+
+  gtk_image_set_from_gicon (self->icon_image, icon);
+  if (is_gicon_symbolic (GTK_WIDGET (self), icon))
+    {
+      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");
+    }
+
+  adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self), name);
+
+  return self;
+}
+
+GVariant *
+cc_online_account_provider_row_get_provider (CcOnlineAccountProviderRow *self)
+{
+  g_return_val_if_fail (CC_IS_ONLINE_ACCOUNT_PROVIDER_ROW (self), NULL);
+  return self->provider;
+}
diff --git a/panels/online-accounts/cc-online-account-provider-row.h 
b/panels/online-accounts/cc-online-account-provider-row.h
new file mode 100644
index 000000000..6f75a5bb2
--- /dev/null
+++ b/panels/online-accounts/cc-online-account-provider-row.h
@@ -0,0 +1,32 @@
+/* -*- 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>
+
+G_BEGIN_DECLS
+
+G_DECLARE_FINAL_TYPE (CcOnlineAccountProviderRow, cc_online_account_provider_row, CC, 
ONLINE_ACCOUNT_PROVIDER_ROW, AdwActionRow)
+
+CcOnlineAccountProviderRow *cc_online_account_provider_row_new          (GVariant *provider);
+
+GVariant                   *cc_online_account_provider_row_get_provider (CcOnlineAccountProviderRow *row);
+
+G_END_DECLS
diff --git a/panels/online-accounts/cc-online-account-provider-row.ui 
b/panels/online-accounts/cc-online-account-provider-row.ui
new file mode 100644
index 000000000..6c51df769
--- /dev/null
+++ b/panels/online-accounts/cc-online-account-provider-row.ui
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="CcOnlineAccountProviderRow" 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>
+  </template>
+</interface>
diff --git a/panels/online-accounts/cc-online-accounts-panel.c 
b/panels/online-accounts/cc-online-accounts-panel.c
index 601ebd528..44498f220 100644
--- a/panels/online-accounts/cc-online-accounts-panel.c
+++ b/panels/online-accounts/cc-online-accounts-panel.c
@@ -28,6 +28,7 @@
 #include <goa/goa.h>
 
 #include "cc-online-accounts-panel.h"
+#include "cc-online-account-provider-row.h"
 #include "cc-online-accounts-resources.h"
 
 #ifdef GDK_WINDOWING_X11
@@ -391,57 +392,12 @@ static void
 add_provider_row (CcOnlineAccountsPanel *self,
                   GVariant              *provider)
 {
-  g_autofree char *name = NULL;
-  g_autoptr(GIcon) icon = NULL;
-  GtkWidget *image;
-  GtkWidget *row;
+  CcOnlineAccountProviderRow *row;
 
-  row = adw_action_row_new ();
-  gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), TRUE);
-
-  if (provider == NULL)
-    {
-      g_object_set_data (G_OBJECT (row), "goa-provider", NULL);
-      icon = g_themed_icon_new_with_default_fallbacks ("goa-account");
-      name = g_strdup (C_("Online Account", "Other"));
-    }
-  else
-    {
-      g_autoptr(GVariant) icon_variant = NULL;
-
-      g_object_set_data_full (G_OBJECT (row),
-                              "goa-provider",
-                              g_variant_ref (provider),
-                              (GDestroyNotify) g_variant_unref);
-
-      g_variant_get (provider, "(ssviu)",
-                     NULL,
-                     &name,
-                     &icon_variant,
-                     NULL,
-                     NULL);
-
-      icon = g_icon_deserialize (icon_variant);
-    }
-
-  image = gtk_image_new_from_gicon (icon);
-  gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
-  gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
-  if (is_gicon_symbolic (image, icon))
-    {
-      gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_NORMAL);
-      gtk_widget_add_css_class (image, "symbolic-circular");
-    }
-  else
-    {
-      gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
-      gtk_widget_add_css_class (image, "lowres-icon");
-    }
-  adw_action_row_add_prefix (ADW_ACTION_ROW (row), image);
-
-  adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), name);
+  row = cc_online_account_provider_row_new (provider);
 
-  gtk_list_box_append (self->providers_listbox, row);
+  gtk_widget_show (GTK_WIDGET (row));
+  gtk_list_box_append (self->providers_listbox, GTK_WIDGET (row));
 }
 
 static void
@@ -667,7 +623,7 @@ command_add (CcOnlineAccountsPanel *self,
         {
           g_autofree gchar *provider_type = NULL;
 
-          provider = g_object_get_data (G_OBJECT (child), "goa-provider");
+          provider = cc_online_account_provider_row_get_provider (CC_ONLINE_ACCOUNT_PROVIDER_ROW (child));
           g_variant_get (provider, "(ssviu)", &provider_type, NULL, NULL, NULL, NULL);
 
           if (g_strcmp0 (provider_type, provider_name) == 0)
@@ -724,8 +680,8 @@ sort_providers_func (GtkListBoxRow *a,
   gboolean a_branded, b_branded;
   gint a_features, b_features;
 
-  a_provider = g_object_get_data (G_OBJECT (a), "goa-provider");
-  b_provider = g_object_get_data (G_OBJECT (b), "goa-provider");
+  a_provider = cc_online_account_provider_row_get_provider (CC_ONLINE_ACCOUNT_PROVIDER_ROW (a));
+  b_provider = cc_online_account_provider_row_get_provider (CC_ONLINE_ACCOUNT_PROVIDER_ROW (b));
 
   g_variant_get (a_provider, "(ssviu)", NULL, NULL, NULL, &a_features, NULL);
   g_variant_get (b_provider, "(ssviu)", NULL, NULL, NULL, &b_features, NULL);
@@ -839,7 +795,7 @@ static void
 on_provider_row_activated_cb (CcOnlineAccountsPanel *self,
                               GtkListBoxRow         *activated_row)
 {
-  GVariant *provider = g_object_get_data (G_OBJECT (activated_row), "goa-provider");
+  GVariant *provider = cc_online_account_provider_row_get_provider (CC_ONLINE_ACCOUNT_PROVIDER_ROW 
(activated_row));
 
   create_account (self, provider);
 }
diff --git a/panels/online-accounts/meson.build b/panels/online-accounts/meson.build
index 9cdd71625..3265503ee 100644
--- a/panels/online-accounts/meson.build
+++ b/panels/online-accounts/meson.build
@@ -20,9 +20,13 @@ cflags += [
   '-DLIBEXECDIR="@0@"'.format(control_center_libexecdir),
 ]
 
-sources = files('cc-online-accounts-panel.c')
+sources = files(
+  'cc-online-account-provider-row.c',
+  'cc-online-accounts-panel.c',
+)
 
 resource_data = files(
+  'cc-online-account-provider-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 84c5bb2eb..c562c8c38 100644
--- a/panels/online-accounts/online-accounts.gresource.xml
+++ b/panels/online-accounts/online-accounts.gresource.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <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-accounts-panel.ui</file>
     <file>online-accounts.css</file>
   </gresource>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 619a6112c..80a0ae97d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -155,6 +155,7 @@ 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/online-accounts/cc-online-account-provider-row.c
 panels/online-accounts/cc-online-accounts-panel.c
 panels/online-accounts/cc-online-accounts-panel.ui
 panels/online-accounts/gnome-control-center-goa-helper.c


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]