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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
/*
YahooGroups plugin for Miranda IM
Copyright © 2007 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 "commonheaders.h"
#define CLIST_GROUPS "CListGroups"
HANDLE hsYGMove = NULL;
HANDLE hsYGReset = NULL;
int InitServices()
{
hsYGMove = CreateServiceFunction(MS_YAHOOGROUPS_MOVE, YahooGroupsMoveService);
hsYGReset = CreateServiceFunction(MS_YAHOOGROUPS_RESET, YahooGroupsResetService);
ReadAvailableGroups();
return 0;
}
int DestroyServices()
{
DestroyServiceFunction(hsYGMove);
DestroyServiceFunction(hsYGReset);
return 0;
}
void ReadAvailableGroups()
{
int ok = 1;
int index = 0;
char group[1024] = {0};
char tmp[128] = {0};
while (ok)
{
mir_snprintf(tmp, sizeof(tmp), "%d", index);
GetStringFromDatabase(NULL, CLIST_GROUPS, tmp, NULL, group, sizeof(group));
if (strlen(group) > 0)
{
availableGroups.Add(_strdup(group + 1));
index += 1;
}
else{
ok = 0;
}
}
}
int GetNextGroupIndex()
{
int index = 0;
int found = 0;
char buffer[1024] = {0};
char tmp[128] = {0};
while (!found)
{
mir_snprintf(tmp, sizeof(tmp), "%d", index++);
if (GetStringFromDatabase(NULL, CLIST_GROUPS, tmp, NULL, buffer, sizeof(buffer)))
{
found = 1;
}
}
return index - 1;
}
void AddNewGroup(char *newGroup)
{
int index = GetNextGroupIndex();
char tmp[128] = {0};
char group[1024] = {0};
*group = 1;
mir_snprintf(group + 1, sizeof(group) - 1, "%s", newGroup);
mir_snprintf(tmp, sizeof(tmp), "%d", index);
const int MAX_SIZE = 1024;
wchar_t wide[MAX_SIZE] = {0};
*wide = 1;
MultiByteToWideChar(currentCodePage, 0, group + 1, -1, wide + 1, MAX_SIZE - 1);
DBWriteContactSettingWString(NULL, CLIST_GROUPS, tmp, wide);
availableGroups.Add(_strdup(group + 1));
}
void AddContactToGroup(HANDLE hContact, char *group)
{
const int MAX_SIZE = 1024;
wchar_t wide[MAX_SIZE] = {0};
MultiByteToWideChar(currentCodePage, 0, group, -1, wide, MAX_SIZE);
DBWriteContactSettingWString(hContact, "CList", "Group", wide);
}
void CreateGroup(char *group)
{
char *p = group;
char *sub = group;
char buffer[1024] = {0};
while ((p = strchr(sub, '\\')))
{
*p = 0;
if (strlen(buffer) > 0)
{
strncat(buffer, "\\", sizeof(buffer));
strncat(buffer, sub, sizeof(buffer));
}
else{
mir_snprintf(buffer, sizeof(buffer), "%s", sub);
}
if (!availableGroups.Contains(buffer))
{
AddNewGroup(buffer);
}
*p++ = '\\';
sub = p;
}
if (sub)
{
if (strlen(buffer) > 0)
{
strncat(buffer, "\\", sizeof(buffer));
strncat(buffer, sub, sizeof(buffer));
}
else{
mir_snprintf(buffer, sizeof(buffer), "%s", sub);
}
if (!availableGroups.Contains(buffer))
{
AddNewGroup(buffer);
}
}
}
void ProcessContacts(void (*callback)(HANDLE, char *), char *protocol)
{
HANDLE hContact = db_find_first();
while (hContact)
{
callback(hContact, protocol);
hContact = db_find_next(hContact);
}
}
void YahooMoveCallback(HANDLE hContact, char *unused)
{
char protocol[128] = {0};
GetContactProtocol(hContact, protocol, sizeof(protocol));
if (strlen(protocol) > 0)
{
char ygroup[128] = {0};
if (!GetStringFromDatabase(hContact, protocol, "YGroup", NULL, ygroup, sizeof(ygroup)))
{
CreateGroup(ygroup);
AddContactToGroup(hContact, ygroup);
}
}
}
void ResetGroupCallback(HANDLE hContact, char *protocol)
{
char p[128] = {0};
GetContactProtocol(hContact, p, sizeof(protocol));
if ((!protocol) || (_stricmp(protocol, p) == 0))
{
db_unset(hContact, "CList", "Group");
}
}
INT_PTR YahooGroupsMoveService(WPARAM wParam, LPARAM lParam)
{
ProcessContacts(YahooMoveCallback, NULL);
return 0;
}
INT_PTR YahooGroupsResetService(WPARAM wParam, LPARAM lParam)
{
ProcessContacts(ResetGroupCallback, NULL);
return 0;
}
|