source: buddylist.c @ 5b85d19

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 5b85d19 was 5b85d19, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Idle time reported in minutes, not seconds
  • Property mode set to 100644
File size: 3.7 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}
10
11/* Deal with an "oncoming" message.  This means recognizing the user
12 * has logged in, and sending a message if they were not already
13 * logged in.
14 */
15void owl_buddylist_oncoming(owl_buddylist *b, char *screenname)
16{
17  int i, j, found;
18  owl_message *m;
19  int *zero;
20
21  found=0;
22  j=owl_list_get_size(&(b->buddies));
23  for (i=0; i<j; i++) {
24    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
25      found=1;
26      break;
27    }
28  }
29
30  if (!found) {
31    /* add the buddy */
32    owl_list_append_element(&(b->buddies), owl_strdup(screenname));
33    zero=owl_malloc(sizeof(int));
34    *zero=0;
35    owl_list_append_element(&(b->idletimes), zero);
36
37    /* do a request for idle time */
38    owl_buddylist_request_idletimes(owl_global_get_buddylist(&g));
39       
40    /* are we ingoring login messages for a while? */
41    if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
42
43    m=owl_malloc(sizeof(owl_message));
44    owl_message_create_aim(m,
45                           screenname,
46                           owl_global_get_aim_screenname(&g),
47                           "",
48                           OWL_MESSAGE_DIRECTION_IN,
49                           1);
50    owl_global_messagequeue_addmsg(&g, m);
51
52  }
53}
54
55/* Deal with an "offgoing" message.  This means recognizing the user
56 * has logged out, and sending a message if they were logged in.
57 */
58void owl_buddylist_offgoing(owl_buddylist *b, char *screenname)
59{
60  int i, j, found;
61  owl_message *m;
62
63  found=0;
64  j=owl_list_get_size(&(b->buddies));
65  for (i=0; i<j; i++) {
66    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
67      found=1;
68      owl_free(owl_list_get_element(&(b->buddies), i));
69      owl_free(owl_list_get_element(&(b->idletimes), i));
70      owl_list_remove_element(&(b->buddies), i);
71      owl_list_remove_element(&(b->idletimes), i);
72      break;
73    }
74  }
75
76  if (found) {
77    m=owl_malloc(sizeof(owl_message));
78    owl_message_create_aim(m,
79                           screenname,
80                           owl_global_get_aim_screenname(&g),
81                           "",
82                           OWL_MESSAGE_DIRECTION_IN,
83                           -1);
84
85    owl_global_messagequeue_addmsg(&g, m);
86  }
87}
88
89/* send requests to the AIM server to retrieve info
90 * on all buddies.  The AIM callback then fills in the
91 * values when the responses are received
92 */
93void owl_buddylist_request_idletimes(owl_buddylist *b)
94{
95  int i, j;
96
97  j=owl_buddylist_get_size(b);
98  for (i=0; i<j; i++) {
99    owl_aim_get_idle(owl_buddylist_get_buddy(b, i));
100  }
101}
102
103/* return the number of logged in buddies */
104int owl_buddylist_get_size(owl_buddylist *b)
105{
106  return(owl_list_get_size(&(b->buddies)));
107}
108
109/* get buddy number 'n' */
110char *owl_buddylist_get_buddy(owl_buddylist *b, int n)
111{
112  return(owl_list_get_element(&(b->buddies), n));
113}
114
115/* get the idle time for buddy number 'n' */
116int owl_buddylist_get_idletime(owl_buddylist *b, int n)
117{
118  int *foo;
119
120  foo=owl_list_get_element(&(b->idletimes), n);
121  return(*foo);
122}
123
124/* set the idle time for user 'screenname'.  If the given
125 * screenname is not on the buddy list do nothing
126 */
127void owl_buddylist_set_idletime(owl_buddylist *b, char *screenname, int minutes)
128{
129  int i, j, *idle;
130
131  j=owl_buddylist_get_size(b);
132  for (i=0; i<j; i++) {
133    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
134      owl_free(owl_list_get_element(&(b->idletimes), i));
135      idle=owl_malloc(sizeof(int));
136      *idle=minutes;
137      owl_list_replace_element(&(b->idletimes), i, idle);
138      return;
139    }
140  }
141}
142
143/* remove all buddies from the list */
144void owl_buddylist_clear(owl_buddylist *b) {
145  owl_list_free_all(&(b->buddies), owl_free);
146  owl_list_free_all(&(b->idletimes), owl_free);
147  owl_list_create(&(b->buddies));
148  owl_list_create(&(b->idletimes));
149}
Note: See TracBrowser for help on using the repository browser.