annotate mcabber/buddies.c @ 0:b3b2332715fb

Tailorization of /trunk Import of the upstream sources from Repository: file:///tmp/svn-mcabber Module: /trunk Revision: 15
author tailor@frmp8452
date Thu, 30 Jun 2005 21:39:31 +0000
parents
children 455ab6bc14ac
rev   line source
0
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
1 #include <stdio.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
2 #include <stdlib.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
3 #include <string.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
4 #include <ncurses.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
5 #include <panel.h>
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
6 #include "screen.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
7 #include "buddies.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
8
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
9 #include "lang.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
10 #include "utils.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
11 #include "server.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
12 #include "list.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
13 #include "harddefines.h"
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
14
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
15 /* global vars for BUDDIES.C */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
16 int buddySelected = 1; /* Hold the selected Buddy */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
17 int buddyOffset = 0; /* Hold the roster offset */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
18
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
19 static LIST_HEAD(buddy_list);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
20 static LIST_HEAD(sorted_buddies);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
21 #define buddy_entry(n) list_entry(n, buddy_entry_t, list)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
22
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
23
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
24 void bud_SetBuddyStatus(char *jidfrom, int status)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
25 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
26 struct list_head *pos, *n;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
27 buddy_entry_t *tmp;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
28 int changed = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
29 char *buffer = (char *) malloc(4096);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
30
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
31 list_for_each_safe(pos, n, &buddy_list) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
32 tmp = buddy_entry(pos);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
33 if (!strcmp(tmp->jid, jidfrom)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
34 if (tmp->flags != status) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
35 tmp->flags = status;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
36 changed = 1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
37 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
38 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
39 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
40 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
41 if (changed) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
42 bud_DrawRoster(scr_GetRosterWindow());
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
43 switch (status) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
44 case FLAG_BUDDY_DISCONNECTED:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
45 sprintf(buffer, "--> %s %s!", jidfrom, i18n("disconected"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
46 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
47
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
48 case FLAG_BUDDY_CONNECTED:
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
49 sprintf(buffer, "--> %s %s!", jidfrom, i18n("connected"));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
50 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
51 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
52 scr_WriteInWindow(i18n("status window"), buffer, TRUE);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
53 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
54 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
55 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
56
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
57 int compara(buddy_entry_t * t1, buddy_entry_t * t2)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
58 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
59 const char *s1 =
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
60 (const char *) (STR_EMPTY(t1->name) ? t1->jid : t1->name);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
61 const char *s2 =
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
62 (const char *) (STR_EMPTY(t2->name) ? t2->jid : t2->name);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
63 return strcasecmp(s1, s2);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
64 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
65
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
66 void bud_SortRoster(void)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
67 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
68 buddy_entry_t *indice, *tmp;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
69 struct list_head *pos, *n;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
70
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
71 while (!list_empty(&buddy_list)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
72 indice = NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
73 tmp = NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
74 list_for_each_safe(pos, n, &buddy_list) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
75 if (!indice) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
76 indice = buddy_entry(pos);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
77 tmp = buddy_entry(pos);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
78 } else {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
79 tmp = buddy_entry(pos);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
80 if (compara(indice, tmp) > 0) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
81 indice = tmp;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
82 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
83 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
84 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
85 list_move_tail(&indice->list, &sorted_buddies);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
86 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
87 list_splice(&sorted_buddies, &buddy_list);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
88 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
89
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
90 void bud_ParseBuddies(char *roster)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
91 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
92 buddy_entry_t *tmp = NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
93 char *aux;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
94 char *p, *str;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
95
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
96 ut_WriteLog("[roster]: %s\n\n", roster);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
97
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
98 while ((aux = ut_strrstr(roster, "<item")) != NULL) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
99 char *jid = getattr(aux, "jid='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
100 char *name = getattr(aux, "name='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
101 char *group = gettag(aux, "group='");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
102
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
103 *aux = '\0';
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
104
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
105 tmp = (buddy_entry_t *) calloc(1, sizeof(buddy_entry_t));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
106
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
107 tmp->flags = FLAG_BUDDY_DISCONNECTED;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
108
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
109 if (strncmp(jid, "UNK", 3)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
110 char *res = strstr(jid, "/");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
111 if (res)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
112 *res = '\0';
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
113
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
114 tmp->jid = (char *) malloc(strlen(jid) + 1);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
115 strcpy(tmp->jid, jid);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
116 free(jid);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
117 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
118
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
119 if (strncmp(name, "UNK", 3)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
120 tmp->name = (char *) calloc(1, strlen(name) + 1);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
121 strcpy(tmp->name, name);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
122 free(name);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
123 } else {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
124 tmp->name = (char *) calloc(1, strlen(tmp->jid) + 1);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
125 str = strdup(tmp->jid);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
126 p = strstr(str, "@");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
127 if (p) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
128 *p = '\0';
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
129 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
130 strncpy(tmp->name, str, 18);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
131 free(str);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
132 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
133
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
134 if (strncmp(group, "UNK", 3)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
135 tmp->group = (char *) malloc(strlen(group) + 1);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
136 strcpy(tmp->group, group);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
137 free(group);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
138 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
139
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
140 if (!strncmp(tmp->jid, "msn.", 4)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
141 sprintf(tmp->name, "%c MSN %c", 254, 254);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
142 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
143
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
144 if (!STR_EMPTY(tmp->jid)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
145 list_add_tail(&tmp->list, &buddy_list);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
146 } else {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
147 if (tmp->jid)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
148 free(tmp->jid);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
149 if (tmp->name)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
150 free(tmp->name);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
151 if (tmp->group)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
152 free(tmp->group);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
153 free(tmp);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
154 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
155 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
156 free(roster);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
157
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
158 bud_SortRoster();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
159 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
160
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
161 /* Desc: Initialize buddy list
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
162 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
163 * In : none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
164 * Out: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
165 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
166 * Note: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
167 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
168 void bud_InitBuddies(int sock)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
169 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
170 char *roster;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
171 roster = srv_getroster(sock);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
172 bud_ParseBuddies(roster);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
173 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
174
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
175 /* Desc: Destroy (and free) buddy list
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
176 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
177 * In : none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
178 * Out: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
179 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
180 * Note: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
181 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
182 void bud_TerminateBuddies(void)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
183 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
184 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
185
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
186 /* Desc: Count elements in buddy list
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
187 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
188 * In : none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
189 * Out: number of buddies
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
190 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
191 * Note: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
192 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
193 int bud_BuddyCount(void)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
194 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
195 int i = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
196 struct list_head *pos, *n;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
197
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
198 list_for_each_safe(pos, n, &buddy_list) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
199 i++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
200 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
201 return i;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
202 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
203
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
204 /* Desc: Draw the roster in roster window
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
205 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
206 * In : roster window
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
207 * Out: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
208 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
209 * Note: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
210 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
211 void bud_DrawRoster(WINDOW * win)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
212 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
213 buddy_entry_t *tmp = NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
214 struct list_head *pos, *nn;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
215 int i = 1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
216 int n;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
217 int maxx, maxy;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
218 int fakeOffset = buddyOffset;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
219
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
220 keypad(win, TRUE);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
221 getmaxyx(win, maxy, maxx);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
222
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
223
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
224 /* cleanup of roster window */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
225 wattrset(win, COLOR_PAIR(COLOR_GENERAL));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
226 for (i = 1; i < maxy - 1; i++) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
227 mvwprintw(win, i, 1, "");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
228 for (n = 2; n < maxx; n++)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
229 waddch(win, ' ');
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
230 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
231
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
232 i = 1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
233 list_for_each_safe(pos, nn, &buddy_list) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
234
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
235 if (fakeOffset > 0) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
236 fakeOffset--;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
237 continue;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
238 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
239
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
240 tmp = buddy_entry(pos);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
241
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
242 if ((tmp->flags && FLAG_BUDDY_CONNECTED) == 1) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
243 if (i == (buddySelected - buddyOffset))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
244 wattrset(win, COLOR_PAIR(COLOR_BD_CONSEL));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
245 else
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
246 wattrset(win, COLOR_PAIR(COLOR_BD_CON));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
247 } else {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
248 if (i == (buddySelected - buddyOffset))
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
249 wattrset(win, COLOR_PAIR(COLOR_BD_DESSEL));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
250 else
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
251 wattrset(win, COLOR_PAIR(COLOR_BD_DES));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
252 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
253 mvwprintw(win, i, 1, "");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
254 for (n = 2; n < maxx; n++)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
255 waddch(win, ' ');
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
256 mvwprintw(win, i, (maxx - strlen(tmp->name)) / 2, "%s", tmp->name);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
257 i++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
258 if (i >= maxy - 1)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
259 break;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
260 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
261 update_panels();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
262 doupdate();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
263 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
264
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
265 /* Desc: Change selected buddy (one position down)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
266 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
267 * In : none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
268 * Out: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
269 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
270 * Note: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
271 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
272 void bud_RosterDown(void)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
273 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
274 int x, y;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
275 getmaxyx(scr_GetRosterWindow(), y, x);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
276 y -= 2;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
277
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
278 if (buddySelected < bud_BuddyCount()) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
279 buddySelected++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
280 if (buddySelected > y)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
281 buddyOffset++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
282 bud_DrawRoster(scr_GetRosterWindow());
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
283 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
284 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
285
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
286 /* Desc: Change selected buddy (one position up)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
287 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
288 * In : none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
289 * Out: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
290 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
291 * Note: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
292 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
293 void bud_RosterUp(void)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
294 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
295 if (buddySelected > 1) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
296 buddySelected--;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
297 if (buddySelected - buddyOffset < 1)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
298 buddyOffset--;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
299 bud_DrawRoster(scr_GetRosterWindow());
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
300 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
301 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
302
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
303 /* Desc: Retrieve info for selected buddy
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
304 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
305 * In : none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
306 * Out: (buddy_entry_t *) of selected buddy
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
307 *
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
308 * Note: none
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
309 */
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
310 buddy_entry_t *bud_SelectedInfo(void)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
311 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
312 struct list_head *pos, *n;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
313 buddy_entry_t *tmp = NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
314
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
315 int i = 0;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
316
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
317 list_for_each_safe(pos, n, &buddy_list) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
318 tmp = buddy_entry(pos);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
319 if (i == buddySelected - 1) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
320 return tmp;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
321 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
322 i++;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
323 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
324 return NULL;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
325 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
326
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
327 void bud_AddBuddy(int sock)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
328 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
329 char *buffer = (char *) calloc(1, 1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
330 char *buffer2 = (char *) calloc(1, 1024);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
331 char *p, *str;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
332 buddy_entry_t *tmp;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
333
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
334 ut_CenterMessage(i18n("write jid here"), 60, buffer2);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
335 scr_CreatePopup(i18n("Add jid"), buffer2, 60, 1, buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
336
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
337 if (!STR_EMPTY(buffer)) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
338 tmp = (buddy_entry_t *) calloc(1, sizeof(buddy_entry_t));
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
339 tmp->jid = (char *) malloc(strlen(buffer) + 1);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
340 strcpy(tmp->jid, buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
341 tmp->name = (char *) malloc(strlen(buffer) + 1);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
342
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
343 str = strdup(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
344 p = strstr(str, "@");
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
345 if (p) {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
346 *p = '\0';
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
347 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
348 strcpy(tmp->name, str);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
349 free(str);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
350
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
351 list_add_tail(&tmp->list, &buddy_list);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
352 buddySelected = 1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
353 bud_DrawRoster(scr_GetRosterWindow());
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
354 srv_AddBuddy(sock, tmp->jid);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
355 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
356 free(buffer);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
357 }
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
358
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
359 void bud_DeleteBuddy(int sock)
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
360 {
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
361 buddy_entry_t *tmp = bud_SelectedInfo();
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
362 srv_DelBuddy(sock, tmp->jid);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
363 list_del(&tmp->list);
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
364 buddySelected = 1;
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
365 bud_DrawRoster(scr_GetRosterWindow());
b3b2332715fb Tailorization of /trunk
tailor@frmp8452
parents:
diff changeset
366 }