source: buddylist.c @ 12582d3

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 12582d3 was 2404c3a, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Added the "source" command
  • Property mode set to 100644
File size: 4.5 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5void owl_buddylist_init(owl_buddylist *b)
6{
7  owl_list_create(&(b->buddies));
8  owl_list_create(&(b->idletimes));
9  /* owl_list_create(&(g->buddymsg_queue)); */
10}
11
12/* Deal with an "oncoming" message.  This means recognizing the user
13 * has logged in, and displaying a message if they were not already
14 * logged in.
15 */
16void owl_buddylist_oncoming(owl_buddylist *b, char *screenname)
17{
18  int *zero;
19  owl_message *m;
20
21  if (!owl_buddylist_is_buddy_loggedin(b, screenname)) {
22
23    /* add the buddy */
24    owl_list_append_element(&(b->buddies), owl_strdup(screenname));
25    zero=owl_malloc(sizeof(int));
26    *zero=0;
27    owl_list_append_element(&(b->idletimes), zero);
28
29    /* do a request for idle time */
30    owl_buddylist_request_idletime(b, screenname);
31       
32    /* are we ingoring login messages for a while? */
33    if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
34
35    /* if not, create the login message */
36    m=owl_malloc(sizeof(owl_message));
37    owl_message_create_aim(m,
38                           screenname,
39                           owl_global_get_aim_screenname(&g),
40                           "",
41                           OWL_MESSAGE_DIRECTION_IN,
42                           1);
43    owl_global_messagequeue_addmsg(&g, m);
44  }
45}
46
47/* Deal with an "offgoing" message.  This means recognizing the user
48 * has logged out, and sending a message if they were logged in.
49 */
50void owl_buddylist_offgoing(owl_buddylist *b, char *screenname)
51{
52  int index;
53  owl_message *m;
54
55  index=owl_buddylist_get_buddy_index(b, screenname);
56  if (index==-1) return;
57
58  owl_free(owl_list_get_element(&(b->buddies), index));
59  owl_free(owl_list_get_element(&(b->idletimes), index));
60  owl_list_remove_element(&(b->buddies), index);
61  owl_list_remove_element(&(b->idletimes), index);
62
63  m=owl_malloc(sizeof(owl_message));
64  owl_message_create_aim(m,
65                         screenname,
66                         owl_global_get_aim_screenname(&g),
67                         "",
68                         OWL_MESSAGE_DIRECTION_IN,
69                         -1);
70  owl_global_messagequeue_addmsg(&g, m);
71}
72
73/* send requests to the AIM server to retrieve info
74 * on all buddies.  The AIM callback then fills in the
75 * values when the responses are received
76 */
77void owl_buddylist_request_idletimes(owl_buddylist *b)
78{
79  int i, j;
80
81  j=owl_buddylist_get_size(b);
82  for (i=0; i<j; i++) {
83    owl_aim_get_idle(owl_buddylist_get_buddy(b, i));
84  }
85}
86
87/* send request to the AIM server to retrieve info on one buddy.  The
88 * AIM callback then fills in the values when the responses are
89 * received.  The buddy must be logged in or no request will be
90 * performed.
91 */
92void owl_buddylist_request_idletime(owl_buddylist *b, char *screenname)
93{
94  if (!owl_buddylist_is_buddy_loggedin(b, screenname)) return;
95 
96  owl_aim_get_idle(screenname);
97}
98
99/* return the number of logged in buddies */
100int owl_buddylist_get_size(owl_buddylist *b)
101{
102  return(owl_list_get_size(&(b->buddies)));
103}
104
105/* get buddy number 'n' */
106char *owl_buddylist_get_buddy(owl_buddylist *b, int n)
107{
108  if (n > owl_buddylist_get_size(b)-1) return("");
109  return(owl_list_get_element(&(b->buddies), n));
110}
111
112/* Return the index of the buddy 'screename' or -1
113 * if the buddy is not logged in.
114 */
115int owl_buddylist_get_buddy_index(owl_buddylist *b, char *screenname)
116{
117  int i, j;
118 
119  j=owl_list_get_size(&(b->buddies));
120  for (i=0; i<j; i++) {
121    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
122      return(i);
123    }
124  }
125  return(-1);
126}
127
128/* return 1 if the buddy 'screenname' is logged in,
129 * otherwise return 0
130 */
131int owl_buddylist_is_buddy_loggedin(owl_buddylist *b, char *screenname)
132{
133  if (owl_buddylist_get_buddy_index(b, screenname)!=-1) return(1);
134  return(0);
135}
136
137/* get the idle time for buddy number 'n' */
138int owl_buddylist_get_idletime(owl_buddylist *b, int n)
139{
140  int *foo;
141
142  foo=owl_list_get_element(&(b->idletimes), n);
143  return(*foo);
144}
145
146/* Set the idle time for user 'screenname'.  If the given screenname
147 * is not on the buddy list do nothing.  If there is a queued request
148 * for this screename, remove it from the queue.
149 */
150void owl_buddylist_set_idletime(owl_buddylist *b, char *screenname, int minutes)
151{
152  int index, *idle;
153
154  index=owl_buddylist_get_buddy_index(b, screenname);
155  if (index==-1) return;
156
157  owl_free(owl_list_get_element(&(b->idletimes), index));
158  idle=owl_malloc(sizeof(int));
159  *idle=minutes;
160  owl_list_replace_element(&(b->idletimes), index, idle);
161}
162
163/* remove all buddies from the list */
164void owl_buddylist_clear(owl_buddylist *b) {
165  owl_list_free_all(&(b->buddies), owl_free);
166  owl_list_free_all(&(b->idletimes), owl_free);
167  owl_list_create(&(b->buddies));
168  owl_list_create(&(b->idletimes));
169}
Note: See TracBrowser for help on using the repository browser.