GCC Code Coverage Report


Directory: ./
File: panels/online-accounts/cc-online-account-provider-row.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 54 0.0%
Functions: 0 10 0.0%
Branches: 0 25 0.0%

Line Branch Exec Source
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /*
3 * Copyright 2020 Canonical Ltd.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <config.h>
20 #include <glib/gi18n.h>
21
22 #define GOA_API_IS_SUBJECT_TO_CHANGE
23 #define GOA_BACKEND_API_IS_SUBJECT_TO_CHANGE
24 #include <goabackend/goabackend.h>
25
26 #include "cc-online-account-provider-row.h"
27 #include "cc-online-accounts-resources.h"
28
29 struct _CcOnlineAccountProviderRow
30 {
31 AdwActionRow parent;
32
33 GtkImage *icon_image;
34
35 GoaProvider *provider;
36 };
37
38 G_DEFINE_TYPE (CcOnlineAccountProviderRow, cc_online_account_provider_row, ADW_TYPE_ACTION_ROW)
39
40 typedef struct
41 {
42 const char *provider;
43 const char *title;
44 const char *description;
45 } ProviderInfo;
46
47 static ProviderInfo
48 _goa_provider_get_provider_info (GoaProvider *provider)
49 {
50 const char *provider_type = NULL;
51
52 g_assert (GOA_IS_PROVIDER (provider));
53
54 /* These override the strings that GOA returns, since they lack detail
55 */
56 static ProviderInfo goa_metadata[] = {
57 { "owncloud", N_("Nextcloud"), N_("Calendar, contacts, files") },
58 { "google", N_("Google"), N_("Email, calendar, contacts, files") },
59 { "windows_live", N_("Microsoft"), N_("Email") },
60 { "ms_graph", N_("Microsoft 365"), N_("Files") },
61 { "exchange", N_("Microsoft Exchange"), N_("Email, calendar, contacts") },
62 { "fedora", N_("Fedora"), N_("Enterprise authentication") },
63 { "imap_smtp", N_("Email Server"), N_("IMAP/SMTP") },
64 { "webdav", N_("Calendar, Contacts and Files"), N_("WebDAV") },
65 { "kerberos", N_("Enterprise Authentication"), N_("Kerberos") },
66 };
67
68 provider_type = goa_provider_get_provider_type (provider);
69 for (size_t i = 0; i < G_N_ELEMENTS (goa_metadata); i++)
70 {
71 if (g_str_equal (goa_metadata[i].provider, provider_type))
72 return goa_metadata[i];
73 }
74
75 return (ProviderInfo){ provider_type, C_("Online Account", "Other"), NULL };
76 }
77
78 static gboolean
79 is_gicon_symbolic (GtkWidget *widget,
80 GIcon *icon)
81 {
82 g_autoptr(GtkIconPaintable) icon_paintable = NULL;
83 GtkIconTheme *icon_theme;
84
85 icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
86 icon_paintable = gtk_icon_theme_lookup_by_gicon (icon_theme,
87 icon,
88 32,
89 gtk_widget_get_scale_factor (widget),
90 gtk_widget_get_direction (widget),
91 0);
92
93 return icon_paintable && gtk_icon_paintable_is_symbolic (icon_paintable);
94 }
95
96 static void
97 cc_online_account_provider_row_dispose (GObject *object)
98 {
99 CcOnlineAccountProviderRow *self = CC_ONLINE_ACCOUNT_PROVIDER_ROW (object);
100
101 g_clear_object (&self->provider);
102
103 G_OBJECT_CLASS (cc_online_account_provider_row_parent_class)->dispose (object);
104 }
105
106 static void
107 cc_online_account_provider_row_class_init (CcOnlineAccountProviderRowClass *klass)
108 {
109 GObjectClass *object_class = G_OBJECT_CLASS (klass);
110 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
111
112 object_class->dispose = cc_online_account_provider_row_dispose;
113
114 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/online-accounts/cc-online-account-provider-row.ui");
115
116 gtk_widget_class_bind_template_child (widget_class, CcOnlineAccountProviderRow, icon_image);
117 }
118
119 static void
120 cc_online_account_provider_row_init (CcOnlineAccountProviderRow *self)
121 {
122 gtk_widget_init_template (GTK_WIDGET (self));
123 }
124
125 CcOnlineAccountProviderRow *
126 cc_online_account_provider_row_new (GoaProvider *provider)
127 {
128 CcOnlineAccountProviderRow *self;
129 g_autoptr(GIcon) icon = NULL;
130 const char *title = NULL;
131 const char *description = NULL;
132
133 self = g_object_new (CC_TYPE_ONLINE_ACCOUNT_PROVIDER_ROW, NULL);
134
135 if (provider == NULL)
136 {
137 icon = g_themed_icon_new_with_default_fallbacks ("goa-account");
138 title = C_("Online Account", "Other");
139 }
140 else
141 {
142 ProviderInfo info;
143
144 self->provider = g_object_ref (provider);
145 info = _goa_provider_get_provider_info (provider);
146 icon = goa_provider_get_provider_icon (provider, NULL);
147 title = info.title;
148 description = info.description;
149 }
150
151 gtk_image_set_from_gicon (self->icon_image, icon);
152 if (is_gicon_symbolic (GTK_WIDGET (self), icon))
153 {
154 gtk_image_set_icon_size (self->icon_image, GTK_ICON_SIZE_NORMAL);
155 gtk_widget_add_css_class (GTK_WIDGET (self->icon_image), "symbolic-circular");
156 }
157 else
158 {
159 gtk_image_set_icon_size (self->icon_image, GTK_ICON_SIZE_LARGE);
160 gtk_widget_add_css_class (GTK_WIDGET (self->icon_image), "lowres-icon");
161 }
162
163 adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self), title);
164 adw_action_row_set_subtitle (ADW_ACTION_ROW (self), description);
165
166 return self;
167 }
168
169 GoaProvider *
170 cc_online_account_provider_row_get_provider (CcOnlineAccountProviderRow *self)
171 {
172 g_return_val_if_fail (CC_IS_ONLINE_ACCOUNT_PROVIDER_ROW (self), NULL);
173 return self->provider;
174 }
175