forked from aglasgall/barnowl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buddy.c
75 lines (62 loc) · 1.18 KB
/
buddy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "owl.h"
void owl_buddy_create(owl_buddy *b, int proto, const char *name)
{
b->proto=proto;
b->name=g_strdup(name);
b->idlesince=0;
}
const char *owl_buddy_get_name(const owl_buddy *b)
{
if (b->name) return(b->name);
return("");
}
int owl_buddy_is_idle(const owl_buddy *b)
{
if (b->isidle) return(1);
return(0);
}
void owl_buddy_set_idle(owl_buddy *b)
{
b->isidle=1;
}
void owl_buddy_set_unidle(owl_buddy *b)
{
b->isidle=0;
}
int owl_buddy_get_proto(const owl_buddy *b)
{
return(b->proto);
}
int owl_buddy_is_proto_aim(const owl_buddy *b)
{
if (b->proto==OWL_PROTOCOL_AIM) return(1);
return(0);
}
/* Set the buddy to have been idle since 'diff' minutes ago
*/
void owl_buddy_set_idle_since(owl_buddy *b, int diff)
{
time_t now;
now=time(NULL);
b->idlesince=now-(diff*60);
}
/* return the number of minutes the buddy has been idle
*/
int owl_buddy_get_idle_time(const owl_buddy *b)
{
time_t now;
if (b->isidle) {
now=time(NULL);
return((now - b->idlesince)/60);
}
return(0);
}
void owl_buddy_cleanup(owl_buddy *b)
{
if (b->name) g_free(b->name);
}
void owl_buddy_delete(owl_buddy *b)
{
owl_buddy_cleanup(b);
g_slice_free(owl_buddy, b);
}