-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathnemo-emblemed-icon.c
More file actions
171 lines (134 loc) · 4.35 KB
/
Copy pathnemo-emblemed-icon.c
File metadata and controls
171 lines (134 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* nemo-emblemed-icon.c - Icon with custom emblem compositing
*
* Copyright (C) 2026 Linux Mint
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*/
#include <config.h>
#include "nemo-emblemed-icon.h"
struct _NemoEmblemedIcon {
GObject parent_instance;
GIcon *icon;
GList *emblems;
};
static void nemo_emblemed_icon_icon_iface_init (GIconIface *iface);
G_DEFINE_TYPE_WITH_CODE (NemoEmblemedIcon, nemo_emblemed_icon, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_ICON, nemo_emblemed_icon_icon_iface_init))
static void
nemo_emblemed_icon_finalize (GObject *object)
{
NemoEmblemedIcon *self = NEMO_EMBLEMED_ICON (object);
g_clear_object (&self->icon);
g_list_free_full (self->emblems, g_object_unref);
G_OBJECT_CLASS (nemo_emblemed_icon_parent_class)->finalize (object);
}
static guint
nemo_emblemed_icon_hash (GIcon *icon)
{
NemoEmblemedIcon *self = NEMO_EMBLEMED_ICON (icon);
guint hash;
GList *l;
hash = g_icon_hash (self->icon);
for (l = self->emblems; l != NULL; l = l->next) {
hash ^= g_icon_hash (G_ICON (l->data));
}
return hash;
}
static gboolean
nemo_emblemed_icon_equal (GIcon *icon1, GIcon *icon2)
{
NemoEmblemedIcon *a = NEMO_EMBLEMED_ICON (icon1);
NemoEmblemedIcon *b = NEMO_EMBLEMED_ICON (icon2);
GList *la, *lb;
if (!g_icon_equal (a->icon, b->icon)) {
return FALSE;
}
if (g_list_length (a->emblems) != g_list_length (b->emblems)) {
return FALSE;
}
for (la = a->emblems, lb = b->emblems; la != NULL; la = la->next, lb = lb->next) {
if (!g_icon_equal (G_ICON (la->data), G_ICON (lb->data))) {
return FALSE;
}
}
return TRUE;
}
static GVariant *
nemo_emblemed_icon_serialize (GIcon *icon)
{
NemoEmblemedIcon *self = NEMO_EMBLEMED_ICON (icon);
GVariantBuilder builder;
GVariant *inner;
GList *l;
inner = g_icon_serialize (self->icon);
if (inner == NULL) {
return NULL;
}
g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
for (l = self->emblems; l != NULL; l = l->next) {
GVariant *emblem_v = g_icon_serialize (G_ICON (l->data));
if (emblem_v != NULL) {
g_variant_builder_add (&builder, "v", emblem_v);
}
}
return g_variant_new ("(vav)", inner, &builder);
}
static void
nemo_emblemed_icon_icon_iface_init (GIconIface *iface)
{
iface->hash = nemo_emblemed_icon_hash;
iface->equal = nemo_emblemed_icon_equal;
iface->serialize = nemo_emblemed_icon_serialize;
}
static void
nemo_emblemed_icon_class_init (NemoEmblemedIconClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = nemo_emblemed_icon_finalize;
}
static void
nemo_emblemed_icon_init (NemoEmblemedIcon *self)
{
}
GIcon *
nemo_emblemed_icon_new (GIcon *icon,
NemoEmblem *emblem)
{
NemoEmblemedIcon *self;
g_return_val_if_fail (G_IS_ICON (icon), NULL);
self = g_object_new (NEMO_TYPE_EMBLEMED_ICON, NULL);
self->icon = g_object_ref (icon);
if (emblem != NULL) {
self->emblems = g_list_append (self->emblems, g_object_ref (emblem));
}
return G_ICON (self);
}
void
nemo_emblemed_icon_add_emblem (NemoEmblemedIcon *emblemed_icon,
NemoEmblem *emblem)
{
g_return_if_fail (NEMO_IS_EMBLEMED_ICON (emblemed_icon));
g_return_if_fail (NEMO_IS_EMBLEM (emblem));
emblemed_icon->emblems = g_list_append (emblemed_icon->emblems,
g_object_ref (emblem));
}
GIcon *
nemo_emblemed_icon_get_icon (NemoEmblemedIcon *emblemed_icon)
{
g_return_val_if_fail (NEMO_IS_EMBLEMED_ICON (emblemed_icon), NULL);
return emblemed_icon->icon;
}
GList *
nemo_emblemed_icon_get_emblems (NemoEmblemedIcon *emblemed_icon)
{
g_return_val_if_fail (NEMO_IS_EMBLEMED_ICON (emblemed_icon), NULL);
return emblemed_icon->emblems;
}