libpurple/protocols/demo/purpledemocontacts.c

Wed, 25 May 2022 23:52:45 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Wed, 25 May 2022 23:52:45 -0500
changeset 41408
5323c0b51ddc
parent 41274
c6bd9ea15211
child 41487
86b6cbbee778
permissions
-rw-r--r--

Remove prpl-gtalk from XMPP console

It no longer exists, and complicates the code a bit.

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
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 purple_demo_protocol_load_status(PurpleAccount *account, PurpleGroup *group,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 PurpleContact *contact, PurpleBuddy *buddy,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 JsonObject *buddy_object)
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 JsonObject *status_object = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 const gchar *id = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 if(!json_object_has_member(buddy_object, "status")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 return;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 status_object = json_object_get_object_member(buddy_object, "status");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 if(json_object_has_member(status_object, "id")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 id = json_object_get_string_member(status_object, "id");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 if(id != NULL) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 if(json_object_has_member(status_object, "message")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 const gchar *message = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 message = json_object_get_string_member(status_object, "message");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 purple_protocol_got_user_status(account,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 purple_buddy_get_name(buddy),
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 id,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 "message", message,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 } else {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 purple_protocol_got_user_status(account,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 purple_buddy_get_name(buddy),
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 id,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 if(json_object_has_member(status_object, "idle")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 gint idle_seconds = 0;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 time_t now;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 idle_seconds = json_object_get_int_member(status_object, "idle");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 now = time(NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 purple_protocol_got_user_idle(account,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 purple_buddy_get_name(buddy), TRUE,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 now - idle_seconds);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 static void
41274
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
79 purple_demo_protocol_load_icon(PurpleAccount *account, const gchar *name)
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
80 {
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
81 gchar *path = NULL;
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
82 GBytes *icon = NULL;
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
83 gpointer icon_data = NULL;
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
84 gsize icon_len = 0;
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
85
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
86 path = g_strdup_printf("/im/pidgin/purple/demo/buddy_icons/%s.png", name);
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
87 icon = g_resource_lookup_data(purple_demo_get_resource(), path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
88 g_free(path);
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
89
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
90 if(icon == NULL) {
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
91 /* No stored icon. */
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
92 return;
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
93 }
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
94
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
95 icon_data = g_bytes_unref_to_data(icon, &icon_len);
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
96 purple_buddy_icons_set_for_user(account, name, icon_data, icon_len, NULL);
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
97 }
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
98
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
99 static void
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 purple_demo_protocol_load_buddies(PurpleAccount *account, PurpleGroup *group,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 PurpleContact *contact, GList *buddies)
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 while(buddies != NULL) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 JsonNode *buddy_node = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 JsonObject *buddy_object = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 const gchar *name = NULL, *alias = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 buddy_node = (JsonNode *)buddies->data;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 buddy_object = json_node_get_object(buddy_node);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 if(json_object_has_member(buddy_object, "name")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 name = json_object_get_string_member(buddy_object, "name");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 if(json_object_has_member(buddy_object, "alias")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 alias = json_object_get_string_member(buddy_object, "alias");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 if(name != NULL) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 PurpleBuddy *buddy = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 buddy = purple_blist_find_buddy(account, name);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 if(buddy == NULL) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 buddy = purple_buddy_new(account, name, alias);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 purple_blist_add_buddy(buddy, contact, group, NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127
41274
c6bd9ea15211 Add buddy icons in demo protocol
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41224
diff changeset
128 purple_demo_protocol_load_icon(account, name);
41224
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 purple_demo_protocol_load_status(account, group, contact, buddy,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 buddy_object);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 buddies = g_list_delete_link(buddies, buddies);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 static void
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 purple_demo_protocol_load_contacts(PurpleAccount *account, PurpleGroup *group,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 GList *contacts)
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 while(contacts != NULL) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 PurpleContact *contact = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 JsonNode *contact_node = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 JsonObject *contact_object = NULL;
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 contact_node = (JsonNode *)contacts->data;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 contact_object = json_node_get_object(contact_node);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 contact = purple_contact_new();
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 /* Set the contact's alias if one was specified. */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 if(json_object_has_member(contact_object, "alias")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 const gchar *alias = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 alias = json_object_get_string_member(contact_object, "alias");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 purple_contact_set_alias(contact, alias);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 /* Add the contact to the group. */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 purple_blist_add_contact(contact, group, NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 /* Finally add the buddies */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 if(json_object_has_member(contact_object, "buddies")) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 JsonArray *buddies_array = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 GList *buddies = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 buddies_array = json_object_get_array_member(contact_object,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 "buddies");
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 buddies = json_array_get_elements(buddies_array);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 purple_demo_protocol_load_buddies(account, group, contact,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 buddies);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 contacts = g_list_delete_link(contacts, contacts);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 }
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
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 static void
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 purple_demo_protocol_load_groups(PurpleAccount *account,
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 JsonObject *root_object)
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 PurpleGroup *last = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 GList *groups = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 /* Get the members of the root object, this is our list of group names. */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 groups = json_object_get_members(root_object);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 while(groups != NULL) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 PurpleGroup *group = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 JsonArray *group_array = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 GList *contacts = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 const gchar *group_name = (const gchar *)groups->data;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 /* Add each group according to the json file. */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 group = purple_group_new(group_name);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 purple_blist_add_group(group, PURPLE_BLIST_NODE(last));
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 /* Now get the contacts and add them. */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 group_array = json_object_get_array_member(root_object, group_name);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 contacts = json_array_get_elements(group_array);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 purple_demo_protocol_load_contacts(account, group, contacts);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 groups = g_list_delete_link(groups, groups);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 last = group;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 /******************************************************************************
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 * Local Exports
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214 *****************************************************************************/
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 void
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 purple_demo_contacts_load(PurpleAccount *account) {
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 GInputStream *istream = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 GError *error = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 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
220 JsonNode *root_node = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 JsonObject *root_object = NULL;
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 /* 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
224 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
225 "/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
226 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
227
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 /* 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
229 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
230
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 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
232 g_critical("%s", error->message);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 }
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 /* Load our data */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 root_node = json_parser_get_root(parser);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 root_object = json_node_get_object(root_node);
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 /* Load the groups! */
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 purple_demo_protocol_load_groups(account, root_object);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 /* 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
243 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
244
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 g_input_stream_close(istream, NULL, NULL);
32a7796a2a36 Create a demo protocol plugin that right now just adds contacts and statuses.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 }

mercurial