Thu, 07 Aug 2025 21:34:33 -0500
Replace Purple.Avatar with Purple.Image
Purple.Avatar was unnecessary and this just moves everything to Purple.Image
which should work just fine.
Testing Done:
Loaded a demo account and verified that the avatars were shown in the contact list properly. Also called in the turtles.
Reviewed at https://reviews.imfreedom.org/r/4084/
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Purple - Internet Messaging Library |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * This library is free software; you can redistribute it and/or |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * modify it under the terms of the GNU Lesser General Public |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * License as published by the Free Software Foundation; either |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * version 2 of the License, or (at your option) any later version. |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * This library is distributed in the hope that it will be useful, |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * Lesser General Public License for more details. |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU Lesser General Public |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | */ |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | #include <json-glib/json-glib.h> |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | #include "purpledemocontacts.h" |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | #include "purpledemoresource.h" |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | /****************************************************************************** |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | * Helpers |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | *****************************************************************************/ |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | static void |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
29 | purple_demo_contacts_load_contact_icon(PurpleContactInfo *info, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
30 | const char *name) |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | { |
|
43301
0e43dc8462e8
Replace Purple.Avatar with Purple.Image
Gary Kramlich <grim@reaperworld.com>
parents:
43082
diff
changeset
|
32 | PurpleImage *avatar = NULL; |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
33 | GError *error = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
34 | char *path = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
35 | |
|
43082
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
36 | path = g_strdup_printf("/im/pidgin/libpurple/protocols/demo/buddy_icons/%s.png", |
|
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
37 | name); |
|
43301
0e43dc8462e8
Replace Purple.Avatar with Purple.Image
Gary Kramlich <grim@reaperworld.com>
parents:
43082
diff
changeset
|
38 | avatar = purple_image_new_from_resource(path, &error); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
40 | if(error != NULL) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
41 | g_message("Failed to load find an icon for %s: %s", path, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
42 | error->message); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
43 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
44 | g_free(path); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
45 | g_clear_error(&error); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
46 | |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | return; |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
50 | g_free(path); |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
51 | |
|
43301
0e43dc8462e8
Replace Purple.Avatar with Purple.Image
Gary Kramlich <grim@reaperworld.com>
parents:
43082
diff
changeset
|
52 | if(PURPLE_IS_IMAGE(avatar)) { |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42304
diff
changeset
|
53 | purple_contact_info_set_avatar(info, avatar); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | |
|
42312
7d6f0b8b6e77
Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42304
diff
changeset
|
55 | g_clear_object(&avatar); |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
56 | } |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
57 | } |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
58 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
59 | static void |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
60 | purple_demo_contacts_load_contact_person(JsonObject *person_object, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
61 | PurpleContactInfo *info) |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
62 | { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
63 | PurplePerson *person = NULL; |
|
42205
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
64 | gboolean new_person = FALSE; |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
65 | const char *value = NULL; |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
66 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
67 | /* If the person has an id, grab it so we can use it when constructing the |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
68 | * person object. |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
69 | */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
70 | if(json_object_has_member(person_object, "id")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
71 | value = json_object_get_string_member(person_object, "id"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
72 | } |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
73 | |
|
42205
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
74 | /* See if the contact has an existing person. */ |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
75 | person = purple_contact_info_get_person(info); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
76 | if(PURPLE_IS_PERSON(person)) { |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
77 | const char *existing_id = NULL; |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
78 | |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
79 | /* If the existing person's id doesn't match the new one, NULL out |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
80 | * person so it'll be recreated with the new id. |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
81 | */ |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
82 | existing_id = purple_person_get_id(person); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
83 | if(!purple_strequal(existing_id, value)) { |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
84 | person = NULL; |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
85 | } |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
86 | } |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
87 | |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
88 | /* If the person didn't exist or it had a different id, create a new person |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
89 | * with the id. |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
90 | */ |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
91 | if(!PURPLE_IS_PERSON(person)) { |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
92 | person = g_object_new(PURPLE_TYPE_PERSON, "id", value, NULL); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
93 | new_person = TRUE; |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
94 | } |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
95 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
96 | /* Alias */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
97 | if(json_object_has_member(person_object, "alias")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
98 | value = json_object_get_string_member(person_object, "alias"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
99 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
100 | purple_person_set_alias(person, value); |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
101 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
104 | /* Create the link between the person and the contact info. */ |
|
42205
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
105 | if(new_person) { |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
106 | purple_person_add_contact_info(person, info); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
107 | purple_contact_info_set_person(info, person); |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
108 | |
|
42205
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
109 | g_clear_object(&person); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
110 | } |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
111 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
113 | static void |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
114 | purple_demo_contacts_load_contact_presence(JsonObject *presence_object, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
115 | PurpleContactInfo *info) |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
116 | { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
117 | PurplePresence *presence = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
118 | const gchar *value = NULL; |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
119 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
120 | presence = purple_contact_info_get_presence(info); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
121 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
122 | /* Emoji */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
123 | if(json_object_has_member(presence_object, "emoji")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
124 | value = json_object_get_string_member(presence_object, "emoji"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
125 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
126 | purple_presence_set_emoji(presence, value); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
127 | } |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
128 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
130 | /* Idle Time */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
131 | if(json_object_has_member(presence_object, "idle")) { |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
132 | GDateTime *now = NULL; |
|
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
133 | GDateTime *idle_since = NULL; |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
134 | gint64 ivalue = 0; |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
136 | ivalue = json_object_get_int_member(presence_object, "idle"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
137 | |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
138 | now = g_date_time_new_now_local(); |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
139 | idle_since = g_date_time_add_minutes(now, -1 * ivalue); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
140 | |
|
42747
801025bad2e1
Make PurplePresence final and other clean ups
Gary Kramlich <grim@reaperworld.com>
parents:
42652
diff
changeset
|
141 | purple_presence_set_idle_time(presence, idle_since); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
142 | |
|
42178
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
143 | g_date_time_unref(idle_since); |
|
e795355c3165
Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42104
diff
changeset
|
144 | g_date_time_unref(now); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
145 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
146 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
147 | /* Message */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
148 | if(json_object_has_member(presence_object, "message")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
149 | value = json_object_get_string_member(presence_object, "message"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
150 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
151 | purple_presence_set_message(presence, value); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
152 | } |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
153 | } |
|
41274
c6bd9ea15211
Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41224
diff
changeset
|
154 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
155 | /* Mobile */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
156 | if(json_object_has_member(presence_object, "mobile")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
157 | gboolean bvalue = FALSE; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
158 | bvalue = json_object_get_boolean_member(presence_object, "mobile"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
159 | purple_presence_set_mobile(presence, bvalue); |
|
41274
c6bd9ea15211
Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41224
diff
changeset
|
160 | } |
|
c6bd9ea15211
Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41224
diff
changeset
|
161 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
162 | /* Primitive */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
163 | if(json_object_has_member(presence_object, "primitive")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
164 | PurplePresencePrimitive primitive = PURPLE_PRESENCE_PRIMITIVE_OFFLINE; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
165 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
166 | value = json_object_get_string_member(presence_object, "primitive"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
167 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
168 | GEnumClass *enum_class = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
169 | GEnumValue *enum_value = NULL; |
|
41274
c6bd9ea15211
Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
41224
diff
changeset
|
170 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
171 | enum_class = g_type_class_ref(PURPLE_TYPE_PRESENCE_PRIMITIVE); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
172 | enum_value = g_enum_get_value_by_nick(enum_class, value); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
173 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
174 | if(enum_value != NULL) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
175 | primitive = enum_value->value; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
176 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
178 | g_type_class_unref(enum_class); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
181 | purple_presence_set_primitive(presence, primitive); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 | static void |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
186 | purple_demo_contacts_load_contact(PurpleContactManager *manager, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
187 | PurpleAccount *account, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
188 | JsonObject *contact_object) |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 | { |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
190 | PurpleContact *contact = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
191 | PurpleContactInfo *info = NULL; |
|
42205
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
192 | gboolean new_contact = FALSE; |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
193 | const char *id = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
194 | const char *value = NULL; |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
196 | /* If we have an id, grab so we can create the contact with it. */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
197 | if(json_object_has_member(contact_object, "id")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
198 | id = json_object_get_string_member(contact_object, "id"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
199 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
200 | |
|
42205
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
201 | /* Look for an existing contact before creating a new one. This stops us |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
202 | * from getting multiples when we trigger connection errors. |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
203 | */ |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
204 | if(!purple_strempty(id)) { |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
205 | contact = purple_contact_manager_find_with_id(manager, account, id); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
206 | } |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
207 | |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
208 | /* If we didn't find an existing contact, create it now with the provided |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
209 | * id. |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
210 | */ |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
211 | if(!PURPLE_IS_CONTACT(contact)) { |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
212 | contact = purple_contact_new(account, id); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
213 | new_contact = TRUE; |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
214 | } |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
215 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
216 | info = PURPLE_CONTACT_INFO(contact); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
217 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
218 | /* Alias */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
219 | if(json_object_has_member(contact_object, "alias")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
220 | value = json_object_get_string_member(contact_object, "alias"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
221 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
222 | purple_contact_info_set_alias(info, value); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
223 | } |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
224 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
225 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
226 | /* Color */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
227 | if(json_object_has_member(contact_object, "color")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
228 | value = json_object_get_string_member(contact_object, "color"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
229 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
230 | purple_contact_info_set_color(info, value); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
231 | } |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
232 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
233 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
234 | /* Display Name */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
235 | if(json_object_has_member(contact_object, "display_name")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
236 | value = json_object_get_string_member(contact_object, "display_name"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
237 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
238 | purple_contact_info_set_display_name(info, value); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
239 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
240 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
241 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
242 | /* Username */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
243 | if(json_object_has_member(contact_object, "username")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
244 | value = json_object_get_string_member(contact_object, "username"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
245 | if(!purple_strempty(value)) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
246 | purple_contact_info_set_username(info, value); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
247 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
248 | purple_demo_contacts_load_contact_icon(info, value); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
249 | } |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
250 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
251 | |
|
42304
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
252 | /* Load the profile if it exists. */ |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
253 | if(json_object_has_member(contact_object, "profile")) { |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
254 | value = json_object_get_string_member(contact_object, "profile"); |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
255 | if(!purple_strempty(value)) { |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
256 | g_object_set_data_full(G_OBJECT(info), "demo-profile", |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
257 | g_strdup(value), g_free); |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
258 | } |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
259 | } |
|
51a419226147
A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents:
42214
diff
changeset
|
260 | |
|
42214
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
261 | /* Load the tags. */ |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
262 | if(json_object_has_member(contact_object, "tags")) { |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
263 | PurpleTags *tags = purple_contact_info_get_tags(info); |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
264 | JsonArray *array = NULL; |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
265 | GList *elements = NULL; |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
266 | |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
267 | array = json_object_get_array_member(contact_object, "tags"); |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
268 | elements = json_array_get_elements(array); |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
269 | while(elements != NULL) { |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
270 | JsonNode *tag_node = elements->data; |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
271 | const char *tag = json_node_get_string(tag_node); |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
272 | |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
273 | purple_tags_add(tags, tag); |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
274 | |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
275 | elements = g_list_delete_link(elements, elements); |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
276 | } |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
277 | } |
|
a836808f9c60
Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
42205
diff
changeset
|
278 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
279 | /* Load the person. */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
280 | if(json_object_has_member(contact_object, "person")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
281 | JsonObject *person_object = NULL; |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
282 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
283 | person_object = json_object_get_object_member(contact_object, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
284 | "person"); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
285 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
286 | purple_demo_contacts_load_contact_person(person_object, info); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
287 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
288 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
289 | /* Load the presence. */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
290 | if(json_object_has_member(contact_object, "presence")) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
291 | JsonObject *presence_object = NULL; |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
292 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
293 | presence_object = json_object_get_object_member(contact_object, |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
294 | "presence"); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
295 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
296 | purple_demo_contacts_load_contact_presence(presence_object, info); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
297 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
298 | |
|
42205
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
299 | /* Finally add the contact to the contact manager if it's new. */ |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
300 | if(new_contact) { |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
301 | purple_contact_manager_add(manager, contact); |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
302 | } |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
303 | |
|
d3fb75a80601
Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents:
42203
diff
changeset
|
304 | g_clear_object(&contact); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
305 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
306 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
307 | /****************************************************************************** |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
308 | * Local Exports |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
309 | *****************************************************************************/ |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
310 | void |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
311 | purple_demo_contacts_load(PurpleAccount *account) { |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
312 | PurpleContactManager *manager = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
313 | GError *error = NULL; |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
314 | GInputStream *istream = NULL; |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
315 | GList *contacts = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
316 | JsonArray *contacts_array = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
317 | JsonNode *root_node = NULL; |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
318 | JsonParser *parser = NULL; |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
319 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
320 | /* get a stream to the contacts.json resource */ |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
321 | istream = g_resource_open_stream(purple_demo_get_resource(), |
|
43082
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
322 | "/im/pidgin/libpurple/protocols/demo/contacts.json", |
|
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
323 | G_RESOURCE_LOOKUP_FLAGS_NONE, &error); |
|
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
324 | if(!G_IS_INPUT_STREAM(istream)) { |
|
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
325 | g_critical("%s", error->message); |
|
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
326 | g_clear_error(&error); |
|
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
327 | return; |
|
0248f784950d
Make protocol resource paths more consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42747
diff
changeset
|
328 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
329 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
330 | /* create our parser */ |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
331 | parser = json_parser_new(); |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
332 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
333 | if(!json_parser_load_from_stream(parser, istream, NULL, &error)) { |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
334 | g_critical("%s", error->message); |
|
42182
3fc2d2b7b7a8
Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42178
diff
changeset
|
335 | g_clear_error(&error); |
|
3fc2d2b7b7a8
Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42178
diff
changeset
|
336 | return; |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
337 | } |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
338 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
339 | root_node = json_parser_get_root(parser); |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
340 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
341 | manager = purple_contact_manager_get_default(); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
342 | |
|
42203
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
343 | /* Load the contacts! */ |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
344 | contacts_array = json_node_get_array(root_node); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
345 | contacts = json_array_get_elements(contacts_array); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
346 | while(contacts != NULL) { |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
347 | JsonNode *contact_node = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
348 | JsonObject *contact_object = NULL; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
349 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
350 | contact_node = contacts->data; |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
351 | contact_object = json_node_get_object(contact_node); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
352 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
353 | purple_demo_contacts_load_contact(manager, account, contact_object); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
354 | |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
355 | contacts = g_list_delete_link(contacts, contacts); |
|
9cb78e799a79
Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents:
42182
diff
changeset
|
356 | } |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
357 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
358 | /* Clean up everything else... */ |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
359 | g_clear_object(&parser); |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
360 | |
|
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
361 | g_input_stream_close(istream, NULL, NULL); |
|
42104
08966165974c
Fix leaks when loading accounts
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
42071
diff
changeset
|
362 | g_object_unref(istream); |
|
41224
32a7796a2a36
Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
363 | } |