| |
1 /* |
| |
2 * Pidgin - Internet Messenger |
| |
3 * Copyright (C) Pidgin Developers <devel@pidgin.im> |
| |
4 * |
| |
5 * Pidgin is the legal property of its developers, whose names are too numerous |
| |
6 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
7 * source distribution. |
| |
8 * |
| |
9 * This program is free software; you can redistribute it and/or modify |
| |
10 * it under the terms of the GNU General Public License as published by |
| |
11 * the Free Software Foundation; either version 2 of the License, or |
| |
12 * (at your option) any later version. |
| |
13 * |
| |
14 * This program is distributed in the hope that it will be useful, |
| |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
17 * GNU General Public License for more details. |
| |
18 * |
| |
19 * You should have received a copy of the GNU General Public License |
| |
20 * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| |
21 */ |
| |
22 #include <glib/gi18n-lib.h> |
| |
23 |
| |
24 #include <gtk/gtk.h> |
| |
25 |
| |
26 #include "pidginbadges.h" |
| |
27 |
| |
28 struct _PidginBadges { |
| |
29 AdwBin parent; |
| |
30 |
| |
31 PurpleBadges *badges; |
| |
32 |
| |
33 GtkSliceListModel *model; |
| |
34 }; |
| |
35 |
| |
36 enum { |
| |
37 PROP_0, |
| |
38 PROP_BADGES, |
| |
39 N_PROPERTIES, |
| |
40 }; |
| |
41 static GParamSpec *properties[N_PROPERTIES] = {NULL, }; |
| |
42 |
| |
43 /****************************************************************************** |
| |
44 * GObject implementation |
| |
45 *****************************************************************************/ |
| |
46 G_DEFINE_FINAL_TYPE(PidginBadges, pidgin_badges, ADW_TYPE_BIN) |
| |
47 |
| |
48 static void |
| |
49 pidgin_badges_get_property(GObject *object, guint prop_id, GValue *value, |
| |
50 GParamSpec *pspec) |
| |
51 { |
| |
52 PidginBadges *badges = PIDGIN_BADGES(object); |
| |
53 |
| |
54 switch (prop_id) { |
| |
55 case PROP_BADGES: |
| |
56 g_value_set_object(value, pidgin_badges_get_badges(badges)); |
| |
57 break; |
| |
58 default: |
| |
59 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
| |
60 break; |
| |
61 } |
| |
62 } |
| |
63 |
| |
64 static void |
| |
65 pidgin_badges_set_property(GObject *object, guint prop_id, const GValue *value, |
| |
66 GParamSpec *pspec) |
| |
67 { |
| |
68 PidginBadges *badges = PIDGIN_BADGES(object); |
| |
69 |
| |
70 switch (prop_id) { |
| |
71 case PROP_BADGES: |
| |
72 pidgin_badges_set_badges(badges, g_value_get_object(value)); |
| |
73 break; |
| |
74 default: |
| |
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
| |
76 break; |
| |
77 } |
| |
78 } |
| |
79 |
| |
80 static void |
| |
81 pidgin_badges_finalize(GObject *obj) { |
| |
82 PidginBadges *badges = PIDGIN_BADGES(obj); |
| |
83 |
| |
84 g_clear_object(&badges->badges); |
| |
85 |
| |
86 G_OBJECT_CLASS(pidgin_badges_parent_class)->finalize(obj); |
| |
87 } |
| |
88 |
| |
89 static void |
| |
90 pidgin_badges_class_init(PidginBadgesClass *klass) { |
| |
91 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
| |
92 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
| |
93 |
| |
94 /* Properties */ |
| |
95 obj_class->get_property = pidgin_badges_get_property; |
| |
96 obj_class->set_property = pidgin_badges_set_property; |
| |
97 obj_class->finalize = pidgin_badges_finalize; |
| |
98 |
| |
99 /** |
| |
100 * PidginBadges:badges: |
| |
101 * |
| |
102 * The badges that are being displayed. |
| |
103 * |
| |
104 * Since: 3.0 |
| |
105 */ |
| |
106 properties[PROP_BADGES] = g_param_spec_object( |
| |
107 "badges", NULL, NULL, |
| |
108 PURPLE_TYPE_BADGES, |
| |
109 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| |
110 |
| |
111 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); |
| |
112 |
| |
113 /* Widget template */ |
| |
114 gtk_widget_class_set_template_from_resource(widget_class, |
| |
115 "/im/pidgin/Pidgin3/badges.ui"); |
| |
116 |
| |
117 gtk_widget_class_bind_template_child(widget_class, PidginBadges, |
| |
118 model); |
| |
119 } |
| |
120 |
| |
121 static void |
| |
122 pidgin_badges_init(PidginBadges *badges) { |
| |
123 gtk_widget_init_template(GTK_WIDGET(badges)); |
| |
124 } |
| |
125 |
| |
126 /****************************************************************************** |
| |
127 * Public API |
| |
128 *****************************************************************************/ |
| |
129 GtkWidget * |
| |
130 pidgin_badges_new(PurpleBadges *badges) { |
| |
131 return g_object_new(PIDGIN_TYPE_BADGES, |
| |
132 "badges", badges, |
| |
133 NULL); |
| |
134 } |
| |
135 |
| |
136 PurpleBadges * |
| |
137 pidgin_badges_get_badges(PidginBadges *badges) { |
| |
138 g_return_val_if_fail(PIDGIN_IS_BADGES(badges), NULL); |
| |
139 |
| |
140 return badges->badges; |
| |
141 } |
| |
142 |
| |
143 void |
| |
144 pidgin_badges_set_badges(PidginBadges *pidgin_badges, |
| |
145 PurpleBadges *purple_badges) |
| |
146 { |
| |
147 g_return_if_fail(PIDGIN_IS_BADGES(pidgin_badges)); |
| |
148 |
| |
149 if(g_set_object(&pidgin_badges->badges, purple_badges)) { |
| |
150 gtk_slice_list_model_set_model(pidgin_badges->model, |
| |
151 G_LIST_MODEL(purple_badges)); |
| |
152 |
| |
153 g_object_notify_by_pspec(G_OBJECT(pidgin_badges), |
| |
154 properties[PROP_BADGES]); |
| |
155 } |
| |
156 } |