comparison libpurple/protocols/qq/group_find.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /**
2 * @file group_find.c
3 *
4 * gaim
5 *
6 * Gaim is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * source distribution.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25 #include "conversation.h"
26 #include "debug.h"
27 #include "util.h"
28
29 #include "group_find.h"
30 #include "group_network.h"
31 #include "qq.h"
32 #include "utils.h"
33
34 /* find the internal_group_id by the reply packet sequence
35 * return TRUE if we have a record of it, return FALSE if not */
36 gboolean qq_group_find_internal_group_id_by_seq(GaimConnection *gc, guint16 seq, guint32 *internal_group_id)
37 {
38 GList *list;
39 qq_data *qd;
40 group_packet *p;
41
42 if (internal_group_id == NULL)
43 return FALSE;
44 qd = (qq_data *) gc->proto_data;
45
46 list = qd->group_packets;
47 while (list != NULL) {
48 p = (group_packet *) (list->data);
49 if (p->send_seq == seq) { /* found and remove */
50 *internal_group_id = p->internal_group_id;
51 qd->group_packets = g_list_remove(qd->group_packets, p);
52 g_free(p);
53 return TRUE;
54 }
55 list = list->next;
56 }
57
58 return FALSE;
59 }
60
61 /* find a qq_buddy by uid, called by im.c */
62 qq_buddy *qq_group_find_member_by_uid(qq_group *group, guint32 uid)
63 {
64 GList *list;
65 qq_buddy *member;
66 g_return_val_if_fail(group != NULL && uid > 0, NULL);
67
68 list = group->members;
69 while (list != NULL) {
70 member = (qq_buddy *) list->data;
71 if (member->uid == uid)
72 return member;
73 else
74 list = list->next;
75 }
76
77 return NULL;
78 }
79
80 /* remove a qq_buddy by uid, called by qq_group_opt.c */
81 void qq_group_remove_member_by_uid(qq_group *group, guint32 uid)
82 {
83 GList *list;
84 qq_buddy *member;
85 g_return_if_fail(group != NULL && uid > 0);
86
87 list = group->members;
88 while (list != NULL) {
89 member = (qq_buddy *) list->data;
90 if (member->uid == uid) {
91 group->members = g_list_remove(group->members, member);
92 return;
93 } else {
94 list = list->next;
95 }
96 }
97 }
98
99 qq_buddy *qq_group_find_or_add_member(GaimConnection *gc, qq_group *group, guint32 member_uid)
100 {
101 qq_buddy *member, *q_bud;
102 GaimBuddy *buddy;
103 g_return_val_if_fail(group != NULL && member_uid > 0, NULL);
104
105 member = qq_group_find_member_by_uid(group, member_uid);
106 if (member == NULL) { /* first appear during my session */
107 member = g_new0(qq_buddy, 1);
108 member->uid = member_uid;
109 buddy = gaim_find_buddy(gaim_connection_get_account(gc), uid_to_gaim_name(member_uid));
110 if (buddy != NULL) {
111 q_bud = (qq_buddy *) buddy->proto_data;
112 if (q_bud != NULL && q_bud->nickname != NULL)
113 member->nickname = g_strdup(q_bud->nickname);
114 else if (buddy->alias != NULL)
115 member->nickname = g_strdup(buddy->alias);
116 }
117 group->members = g_list_append(group->members, member);
118 }
119
120 return member;
121 }
122
123 /* find a qq_group by chatroom channel */
124 qq_group *qq_group_find_by_channel(GaimConnection *gc, gint channel)
125 {
126 GaimConversation *conv;
127 qq_data *qd;
128 qq_group *group;
129 GList *list;
130
131 qd = (qq_data *) gc->proto_data;
132
133 conv = gaim_find_chat(gc, channel);
134 g_return_val_if_fail(conv != NULL, NULL);
135
136 list = qd->groups;
137 group = NULL;
138 while (list != NULL) {
139 group = (qq_group *) list->data;
140 if (!g_ascii_strcasecmp(gaim_conversation_get_name(conv), group->group_name_utf8))
141 break;
142 list = list->next;
143 }
144
145 return group;
146 }
147
148 /* find a qq_group by its id, flag is QQ_INTERNAL_ID or QQ_EXTERNAL_ID */
149 qq_group *qq_group_find_by_id(GaimConnection *gc, guint32 id, gboolean flag)
150 {
151 GList *list;
152 qq_group *group;
153 qq_data *qd;
154
155 qd = (qq_data *) gc->proto_data;
156
157 if (qd->groups == NULL || id <= 0)
158 return NULL;
159
160 list = qd->groups;
161 while (list != NULL) {
162 group = (qq_group *) list->data;
163 if (flag == QQ_INTERNAL_ID ?
164 (group->internal_group_id == id) : (group->external_group_id == id))
165 return group;
166 list = list->next;
167 }
168
169 return NULL;
170 }