summaryrefslogtreecommitdiff
path: root/plugins/WhenWasIt/src/birthdays.cpp
blob: 43e60ffdc9cf06bdce6fe43cae18d3825b8da1f6 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
WhenWasIt (birthday reminder) plugin for Miranda IM

Copyright © 2006 Cristian Libotean

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "stdafx.h"

CBirthdays birthdays;

CBirthdays::CBirthdays(int initialSize)
{
	count = 0;
	size = 0;
	birthdays = nullptr;
	advancedIcon = CLIST_ICON;

	Realloc(initialSize);
}

CBirthdays::~CBirthdays()
{
	Destroy();
}

void CBirthdays::Destroy()
{
	if (birthdays) {
		Clear();
		free(birthdays);
		birthdays = nullptr;
	}
}

void CBirthdays::Clear()
{
	for (int i = 0; i < Count(); i++)
		ClearItem(i);

	count = 0;
}

void CBirthdays::ClearItem(int index)
{
	free(birthdays[index]);
	birthdays[index] = nullptr;
}

int CBirthdays::Count() const
{
	return count;
}

int CBirthdays::Size() const
{
	return size;
}

void CBirthdays::EnsureCapacity()
{
	if (count >= size)
		Realloc(size / 2);
}

void CBirthdays::Realloc(int increaseCapacity)
{
	size += increaseCapacity;
	birthdays = (PBirthdayContact *)realloc(birthdays, size * sizeof(PBirthdayContact));
}

int CBirthdays::Add(MCONTACT hContact, HANDLE hClistIcon)
{
	if (!Contains(hContact)) {
		EnsureCapacity();
		TBirthdayContact *item = (TBirthdayContact *)malloc(sizeof(TBirthdayContact));
		item->hContact = hContact;
		item->hClistIcon = hClistIcon;
		birthdays[count++] = item;
		return 0;
	}
	return -1;
}

int CBirthdays::Remove(int index)
{
	if ((index >= 0) && (index < count)) {
		for (int i = index + 1; i < count; i++)
			birthdays[i - 1] = birthdays[i];

		ClearItem(count--);
		return 0;
	}
	return -1;
}

int CBirthdays::Remove(MCONTACT hContact)
{
	return Remove(Index(hContact));
}

int CBirthdays::Contains(MCONTACT hContact) const
{
	for (int i = 0; i < count; i++)
		if (birthdays[i]->hContact == hContact)
			return TRUE;

	return FALSE;
}

int CBirthdays::Index(MCONTACT hContact) const
{
	for (int i = 0; i < count; i++)
		if (birthdays[i]->hContact == hContact)
			return i;

	return -1;
}

void CBirthdays::SetAdvancedIconIndex(int advIcon)
{
	advancedIcon = advIcon;
}

int CBirthdays::GetAdvancedIconIndex() const
{
	return advancedIcon;
}

HANDLE CBirthdays::GetClistIcon(MCONTACT hContact) const
{
	int index = Index(hContact);
	if ((index >= 0) && (index < count))
		return birthdays[index]->hClistIcon;

	return INVALID_HANDLE_VALUE;
}