libpurple/protocols/demo/purpledemocontacts.c

Tue, 05 Sep 2023 00:05:12 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 05 Sep 2023 00:05:12 -0500
changeset 42312
7d6f0b8b6e77
parent 42304
51a419226147
permissions
-rw-r--r--

Use PurpleAvatar for PurplePerson and PurpleContactInfo

I'm not sure why we didn't do this earlier, but it's done now.

Testing Done:
Connected a demo account and verified all of its icons showed up in the contact list.

Reviewed at https://reviews.imfreedom.org/r/2605/

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 {
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42304
diff changeset
32 PurpleAvatar *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
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
36 path = g_strdup_printf("/im/pidgin/purple/demo/buddy_icons/%s.png", name);
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42304
diff changeset
37 avatar = purple_avatar_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
38
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
39 if(error != NULL) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
40 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
41 error->message);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
42
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
43 g_free(path);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
44 g_clear_error(&error);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
45
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 return;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
49 g_free(path);
42178
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
50
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42304
diff changeset
51 if(PURPLE_IS_AVATAR(avatar)) {
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42304
diff changeset
52 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
53
42312
7d6f0b8b6e77 Use PurpleAvatar for PurplePerson and PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42304
diff changeset
54 g_clear_object(&avatar);
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
55 }
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 static void
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
59 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
60 PurpleContactInfo *info)
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
61 {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
62 PurplePerson *person = NULL;
42205
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
63 gboolean new_person = FALSE;
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
64 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
65
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
66 /* 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
67 * person object.
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
68 */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
69 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
70 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
71 }
42178
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
72
42205
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
73 /* 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
74 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
75 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
76 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
77
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
78 /* 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
79 * 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
80 */
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
81 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
82 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
83 person = NULL;
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
84 }
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 /* 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
88 * with the id.
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
89 */
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
90 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
91 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
92 new_person = TRUE;
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
93 }
42178
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
94
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
95 /* Alias */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
96 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
97 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
98 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
99 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
100 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
103 /* 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
104 if(new_person) {
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
105 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
106 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
107
42205
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
108 g_clear_object(&person);
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
109 }
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
110 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
112 static void
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
113 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
114 PurpleContactInfo *info)
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
115 {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
116 PurplePresence *presence = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
117 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
118
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
119 presence = purple_contact_info_get_presence(info);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
120
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
121 /* Emoji */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
122 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
123 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
124 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
125 purple_presence_set_emoji(presence, value);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
126 }
42178
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
127 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
129 /* Idle Time */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
130 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
131 GDateTime *now = NULL;
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
132 GDateTime *idle_since = NULL;
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
133 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
134
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
135 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
136
42178
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
137 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
138 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
139
42178
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
140 purple_presence_set_idle(presence, TRUE, 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
141
42178
e795355c3165 Use the new status api in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42104
diff changeset
142 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
143 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
144 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
146 /* Message */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
147 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
148 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
149 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
150 purple_presence_set_message(presence, value);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
151 }
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
152 }
41274
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
153
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
154 /* Mobile */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
155 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
156 gboolean bvalue = FALSE;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
157 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
158 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
159 }
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
160
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
161 /* Primitive */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
162 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
163 PurplePresencePrimitive primitive = PURPLE_PRESENCE_PRIMITIVE_OFFLINE;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
164
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
165 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
166 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
167 GEnumClass *enum_class = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
168 GEnumValue *enum_value = NULL;
41274
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
169
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
170 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
171 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
172
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
173 if(enum_value != NULL) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
174 primitive = enum_value->value;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
175 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
177 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
178 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
180 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
181 }
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 static void
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
185 purple_demo_contacts_load_contact(PurpleContactManager *manager,
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
186 PurpleAccount *account,
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
187 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
188 {
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
189 PurpleContact *contact = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
190 PurpleContactInfo *info = NULL;
42205
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
191 gboolean new_contact = FALSE;
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
192 const char *id = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
193 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
194
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
195 /* 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
196 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
197 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
198 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
42205
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
200 /* 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
201 * 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
202 */
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
203 if(!purple_strempty(id)) {
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
204 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
205 }
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 /* 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
208 * id.
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
209 */
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
210 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
211 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
212 new_contact = TRUE;
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
213 }
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
214
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
215 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
216
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
217 /* Alias */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
218 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
219 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
220 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
221 purple_contact_info_set_alias(info, value);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
222 }
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
223 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
225 /* Color */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
226 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
227 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
228 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
229 purple_contact_info_set_color(info, value);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
230 }
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
231 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
233 /* Display Name */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
234 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
235 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
236 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
237 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
238 }
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
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
241 /* Username */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
242 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
243 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
244 if(!purple_strempty(value)) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
245 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
246
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
247 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
248 }
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
249 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250
42304
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42214
diff changeset
251 /* Load the profile if it exists. */
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42214
diff changeset
252 if(json_object_has_member(contact_object, "profile")) {
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42214
diff changeset
253 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
254 if(!purple_strempty(value)) {
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42214
diff changeset
255 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
256 g_strdup(value), g_free);
51a419226147 A basic context menu for PurpleContactInfo
Gary Kramlich <grim@reaperworld.com>
parents: 42214
diff changeset
257 }
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
42214
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
260 /* Load the tags. */
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
261 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
262 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
263 JsonArray *array = NULL;
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
264 GList *elements = NULL;
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
265
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
266 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
267 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
268 while(elements != NULL) {
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
269 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
270 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
271
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
272 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
273
a836808f9c60 Load the tags for contacts in the demo protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42205
diff changeset
274 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
275 }
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
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
278 /* Load the person. */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
279 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
280 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
281
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
282 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
283 "person");
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
284
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
285 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
286 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
288 /* Load the presence. */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
289 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
290 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
291
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
292 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
293 "presence");
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
295 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
296 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297
42205
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
298 /* 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
299 if(new_contact) {
d3fb75a80601 Don't duplicate contacts in the demo protocol when reconnecting
Gary Kramlich <grim@reaperworld.com>
parents: 42203
diff changeset
300 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
301 }
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 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
304 }
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 * Local Exports
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 *****************************************************************************/
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 void
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 purple_demo_contacts_load(PurpleAccount *account) {
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
311 PurpleContactManager *manager = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
312 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
313 GInputStream *istream = NULL;
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
314 GList *contacts = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
315 JsonArray *contacts_array = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
316 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
317 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
318
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 /* 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
320 istream = g_resource_open_stream(purple_demo_get_resource(),
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 "/im/pidgin/purple/demo/contacts.json",
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322 G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 /* 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
325 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
326
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 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
328 g_critical("%s", error->message);
42182
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42178
diff changeset
329 g_clear_error(&error);
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42178
diff changeset
330 return;
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 }
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 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
334
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
335 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
336
42203
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
337 /* Load the contacts! */
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
338 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
339 contacts = json_array_get_elements(contacts_array);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
340 while(contacts != NULL) {
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
341 JsonNode *contact_node = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
342 JsonObject *contact_object = NULL;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
343
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
344 contact_node = contacts->data;
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
345 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
346
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
347 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
348
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
349 contacts = g_list_delete_link(contacts, contacts);
9cb78e799a79 Port the demo protocol plugin to contacts
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
350 }
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 /* 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
353 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
354
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 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
356 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
357 }

mercurial