Mon, 12 Dec 2022 23:38:47 -0600
Create PurpleAvatar to represent avatars
Testing Done:
Ran the unit tests and manually verified the docs.
Reviewed at https://reviews.imfreedom.org/r/2092/
|
41736
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Purple - Internet Messaging Library |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * Purple is the legal property of its developers, whose names are too numerous |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * source distribution. |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * This program is free software; you can redistribute it and/or modify |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * it under the terms of the GNU General Public License as published by |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * the Free Software Foundation; either version 2 of the License, or |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * (at your option) any later version. |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * This program is distributed in the hope that it will be useful, |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | * GNU General Public License for more details. |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | */ |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | #include "purpletags.h" |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | #include "util.h" |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | struct _PurpleTags { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | GObject parent; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | GList *tags; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | }; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | G_DEFINE_TYPE(PurpleTags, purple_tags, G_TYPE_OBJECT) |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 | /****************************************************************************** |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 | * GObject Implementation |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | *****************************************************************************/ |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | static void |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | purple_tags_dispose(GObject *obj) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | PurpleTags *tags = PURPLE_TAGS(obj); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | if(tags->tags != NULL) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 | g_list_free_full(tags->tags, g_free); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 | tags->tags = NULL; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | G_OBJECT_CLASS(purple_tags_parent_class)->dispose(obj); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | static void |
|
41960
c8a4853205e3
Bump C standard to C99 for libpurple files and fix warnings
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41945
diff
changeset
|
52 | purple_tags_init(G_GNUC_UNUSED PurpleTags *tags) { |
|
41736
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | static void |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | purple_tags_class_init(PurpleTagsClass *klass) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | obj_class->dispose = purple_tags_dispose; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | /****************************************************************************** |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | * Public API |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | *****************************************************************************/ |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | PurpleTags * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | purple_tags_new(void) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | return g_object_new(PURPLE_TYPE_TAGS, NULL); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | const gchar * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | purple_tags_lookup(PurpleTags *tags, const gchar *name, gboolean *found) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | size_t name_len = 0; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | g_return_val_if_fail(PURPLE_IS_TAGS(tags), FALSE); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 | g_return_val_if_fail(name != NULL, FALSE); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | /* Assume we're going to find the tag, if we don't we set found to false |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | * before we return. This sounds silly, but it saves some additional logic |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | * below. |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | */ |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | if(found) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | *found = TRUE; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 | name_len = strlen(name); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | for(GList *l = tags->tags; l != NULL; l = l->next) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | const gchar *tag = l->data; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | if(g_str_has_prefix(tag, name)) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | const gchar *value = tag + name_len; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | if(*value == '\0') { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | return NULL; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | } else if(*value == ':') { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | return value+1; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | /* We didn't find the tag, so set found to false if necessary. */ |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | if(found) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | *found = FALSE; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | return NULL; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 | const gchar * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
110 | purple_tags_get(PurpleTags *tags, const gchar *name) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 | g_return_val_if_fail(PURPLE_IS_TAGS(tags), NULL); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 | g_return_val_if_fail(name != NULL, NULL); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | return purple_tags_lookup(tags, name, NULL); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 | void |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 | purple_tags_add(PurpleTags *tags, const gchar *tag) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 | g_return_if_fail(PURPLE_IS_TAGS(tags)); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | g_return_if_fail(tag != NULL); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | |
|
41908
9d2735c0e848
Don't allow duplicate tags in PurpleTags
Gary Kramlich <grim@reaperworld.com>
parents:
41892
diff
changeset
|
122 | /* Remove any existing tags with this value. */ |
|
9d2735c0e848
Don't allow duplicate tags in PurpleTags
Gary Kramlich <grim@reaperworld.com>
parents:
41892
diff
changeset
|
123 | purple_tags_remove(tags, tag); |
|
9d2735c0e848
Don't allow duplicate tags in PurpleTags
Gary Kramlich <grim@reaperworld.com>
parents:
41892
diff
changeset
|
124 | |
|
9d2735c0e848
Don't allow duplicate tags in PurpleTags
Gary Kramlich <grim@reaperworld.com>
parents:
41892
diff
changeset
|
125 | /* Add the new tag. */ |
|
41736
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 | tags->tags = g_list_append(tags->tags, g_strdup(tag)); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
127 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 | |
|
41945
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
129 | void |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
130 | purple_tags_add_with_value(PurpleTags *tags, const char *name, |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
131 | const char *value) |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
132 | { |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
133 | char *tag = NULL; |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
134 | |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
135 | g_return_if_fail(PURPLE_IS_TAGS(tags)); |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
136 | g_return_if_fail(name != NULL); |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
137 | |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
138 | if(value != NULL) { |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
139 | tag = g_strdup_printf("%s:%s", name, value); |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
140 | } else { |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
141 | tag = g_strdup(name); |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
142 | } |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
143 | |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
144 | purple_tags_add(tags, tag); |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
145 | |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
146 | g_free(tag); |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
147 | } |
|
fd826d652e7d
Add purple_tags_add_with_value to help people not have to construct their own tags
Gary Kramlich <grim@reaperworld.com>
parents:
41908
diff
changeset
|
148 | |
|
41736
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 | gboolean |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
150 | purple_tags_remove(PurpleTags *tags, const gchar *tag) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
151 | g_return_val_if_fail(PURPLE_IS_TAGS(tags), FALSE); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
152 | g_return_val_if_fail(tag != NULL, FALSE); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
153 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
154 | for(GList *l = tags->tags; l != NULL; l = l->next) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
155 | gchar *etag = l->data; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
156 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
157 | if(purple_strequal(etag, tag)) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
158 | g_free(etag); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
159 | tags->tags = g_list_delete_link(tags->tags, l); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
160 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 | return TRUE; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
163 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
164 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
165 | return FALSE; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
166 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
167 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
168 | guint |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
169 | purple_tags_get_count(PurpleTags *tags) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
170 | g_return_val_if_fail(PURPLE_IS_TAGS(tags), 0); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
171 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
172 | return g_list_length(tags->tags); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
173 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
174 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
175 | GList * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
176 | purple_tags_get_all(PurpleTags *tags) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 | g_return_val_if_fail(PURPLE_IS_TAGS(tags), NULL); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 | return tags->tags; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
181 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 | gchar * |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 | purple_tags_to_string(PurpleTags *tags, const gchar *separator) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 | GString *value = NULL; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 | g_return_val_if_fail(PURPLE_IS_TAGS(tags), NULL); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
188 | value = g_string_new(""); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 | for(GList *l = tags->tags; l != NULL; l = l->next) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 | const gchar *tag = l->data; |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
193 | g_string_append(value, tag); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
194 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 | if(separator != NULL && l->next != NULL) { |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
196 | g_string_append(value, separator); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
197 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
198 | } |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
199 | |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
200 | return g_string_free(value, FALSE); |
|
d78c0951ea2c
Create the PurpleTags object for handling tags
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
201 | } |
|
41892
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
202 | |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
203 | void |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
204 | purple_tag_parse(const char *tag, char **name, char **value) { |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
205 | const char *colon = NULL; |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
206 | |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
207 | g_return_if_fail(tag != NULL); |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
208 | |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
209 | colon = g_strstr_len(tag, -1, ":"); |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
210 | if(colon == NULL) { |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
211 | if(name != NULL) { |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
212 | *name = g_strdup(tag); |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
213 | } |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
214 | if(value != NULL) { |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
215 | *value = NULL; |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
216 | } |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
217 | } else { |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
218 | if(name != NULL) { |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
219 | *name = g_strndup(tag, colon - tag); |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
220 | } |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
221 | if(value != NULL) { |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
222 | *value = g_strdup(colon + 1); |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
223 | } |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
224 | } |
|
39e595f7d056
Add purple_tag_parse for parsing tags
Gary Kramlich <grim@reaperworld.com>
parents:
41736
diff
changeset
|
225 | } |