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 |
|
|
#include "cc-online-account-row.h" |
23 |
|
|
#include "cc-online-accounts-resources.h" |
24 |
|
|
|
25 |
|
|
struct _CcOnlineAccountRow |
26 |
|
|
{ |
27 |
|
|
AdwActionRow parent; |
28 |
|
|
|
29 |
|
|
GtkImage *icon_image; |
30 |
|
|
GtkBox *warning_box; |
31 |
|
|
|
32 |
|
|
GoaObject *object; |
33 |
|
|
}; |
34 |
|
|
|
35 |
|
✗ |
G_DEFINE_TYPE (CcOnlineAccountRow, cc_online_account_row, ADW_TYPE_ACTION_ROW) |
36 |
|
|
|
37 |
|
|
static gboolean |
38 |
|
✗ |
is_gicon_symbolic (GtkWidget *widget, |
39 |
|
|
GIcon *icon) |
40 |
|
|
{ |
41 |
|
✗ |
g_autoptr(GtkIconPaintable) icon_paintable = NULL; |
42 |
|
|
GtkIconTheme *icon_theme; |
43 |
|
|
|
44 |
|
✗ |
icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ()); |
45 |
|
✗ |
icon_paintable = gtk_icon_theme_lookup_by_gicon (icon_theme, |
46 |
|
|
icon, |
47 |
|
|
32, |
48 |
|
|
gtk_widget_get_scale_factor (widget), |
49 |
|
|
gtk_widget_get_direction (widget), |
50 |
|
|
0); |
51 |
|
|
|
52 |
|
✗ |
return icon_paintable && gtk_icon_paintable_is_symbolic (icon_paintable); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
static void |
56 |
|
✗ |
cc_online_account_row_dispose (GObject *object) |
57 |
|
|
{ |
58 |
|
✗ |
CcOnlineAccountRow *self = CC_ONLINE_ACCOUNT_ROW (object); |
59 |
|
|
|
60 |
|
✗ |
g_clear_object (&self->object); |
61 |
|
|
|
62 |
|
✗ |
G_OBJECT_CLASS (cc_online_account_row_parent_class)->dispose (object); |
63 |
|
✗ |
} |
64 |
|
|
|
65 |
|
|
static void |
66 |
|
✗ |
cc_online_account_row_class_init (CcOnlineAccountRowClass *klass) |
67 |
|
|
{ |
68 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
69 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
70 |
|
|
|
71 |
|
✗ |
object_class->dispose = cc_online_account_row_dispose; |
72 |
|
|
|
73 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/online-accounts/cc-online-account-row.ui"); |
74 |
|
|
|
75 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcOnlineAccountRow, icon_image); |
76 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcOnlineAccountRow, warning_box); |
77 |
|
✗ |
} |
78 |
|
|
|
79 |
|
|
static void |
80 |
|
✗ |
cc_online_account_row_init (CcOnlineAccountRow *self) |
81 |
|
|
{ |
82 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
83 |
|
✗ |
} |
84 |
|
|
|
85 |
|
|
CcOnlineAccountRow * |
86 |
|
✗ |
cc_online_account_row_new (GoaObject *object) |
87 |
|
|
{ |
88 |
|
|
CcOnlineAccountRow *self; |
89 |
|
|
GoaAccount *account; |
90 |
|
✗ |
g_autoptr(GIcon) gicon = NULL; |
91 |
|
✗ |
g_autoptr(GError) error = NULL; |
92 |
|
|
|
93 |
|
✗ |
self = g_object_new (CC_TYPE_ONLINE_ACCOUNT_ROW, NULL); |
94 |
|
|
|
95 |
|
✗ |
self->object = g_object_ref (object); |
96 |
|
|
|
97 |
|
✗ |
account = goa_object_peek_account (object); |
98 |
|
|
|
99 |
|
✗ |
adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self), |
100 |
|
✗ |
goa_account_get_provider_name (account)); |
101 |
|
✗ |
adw_action_row_set_subtitle (ADW_ACTION_ROW (self), |
102 |
|
✗ |
goa_account_get_presentation_identity (account)); |
103 |
|
|
|
104 |
|
✗ |
gicon = g_icon_new_for_string (goa_account_get_provider_icon (account), &error); |
105 |
|
✗ |
if (error != NULL) |
106 |
|
|
{ |
107 |
|
✗ |
g_warning ("Error creating GIcon for account: %s (%s, %d)", |
108 |
|
|
error->message, |
109 |
|
|
g_quark_to_string (error->domain), |
110 |
|
|
error->code); |
111 |
|
|
} |
112 |
|
|
else |
113 |
|
|
{ |
114 |
|
✗ |
gtk_image_set_from_gicon (self->icon_image, gicon); |
115 |
|
|
|
116 |
|
✗ |
if (is_gicon_symbolic (GTK_WIDGET (self), gicon)) |
117 |
|
|
{ |
118 |
|
✗ |
gtk_image_set_icon_size (self->icon_image, GTK_ICON_SIZE_NORMAL); |
119 |
|
✗ |
gtk_widget_add_css_class (GTK_WIDGET (self->icon_image), "symbolic-circular"); |
120 |
|
|
} |
121 |
|
|
else |
122 |
|
|
{ |
123 |
|
✗ |
gtk_image_set_icon_size (self->icon_image, GTK_ICON_SIZE_LARGE); |
124 |
|
✗ |
gtk_widget_add_css_class (GTK_WIDGET (self->icon_image), "lowres-icon"); |
125 |
|
|
} |
126 |
|
|
} |
127 |
|
|
|
128 |
|
✗ |
g_object_bind_property (account, "attention-needed", |
129 |
|
✗ |
self->warning_box, "visible", |
130 |
|
|
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); |
131 |
|
|
|
132 |
|
✗ |
return self; |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
GoaObject * |
136 |
|
✗ |
cc_online_account_row_get_object (CcOnlineAccountRow *self) |
137 |
|
|
{ |
138 |
|
✗ |
g_return_val_if_fail (CC_IS_ONLINE_ACCOUNT_ROW (self), NULL); |
139 |
|
✗ |
return self->object; |
140 |
|
|
} |
141 |
|
|
|