summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/utils.cpp
blob: fc73af9a17f85831c83589f8f50ff4e454d08aae (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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "stdafx.h"

DWORD toggleBit(DWORD dw, DWORD bit)
{
	if (dw & bit)
		return dw & ~bit;
	return dw | bit;
}

bool CheckFilter(wchar_t* buf, wchar_t* filter)
{
	//	MessageBox(0, buf, filter, MB_OK);
	int l1 = mir_wstrlen(buf);
	int l2 = mir_wstrlen(filter);
	for (int i = 0; i < l1 - l2 + 1; i++)
		if (CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, buf + i, l2, filter, l2) == CSTR_EQUAL)
			return true;
	return false;
}

void CopyText(HWND hwnd, wchar_t* text)
{
	OpenClipboard(hwnd);
	EmptyClipboard();
	HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * (mir_wstrlen(text) + 1));
	wchar_t* s = (wchar_t*)GlobalLock(hMem);
	mir_wstrcpy(s, text);
	GlobalUnlock(hMem);
#ifdef UNICODE
	SetClipboardData(CF_UNICODETEXT, hMem);
#else
	SetClipboardData(CF_TEXT, hMem);
#endif
	CloseClipboard();
	//	GlobalFree(hMem);
}

/*void ExportHistory(HANDLE hContact, char *fnTemplate, char *fn, HWND hwndHistory)
{
/*
	char *szHeader    = "---header---";
	char *szMsgIn     = "---msgin---";
	char *szMsgOut    = "---msgout---";
	char *szFile      = "---file---";
	char *szURL       = "---url---";
	char *szStatus    = "---status---";
	char *szOther     = "---other---";
	char *szFooter    = "---footer---";
	char *szEnd       = "---end---";

	char *tHeader = 0;
	char *tMsgIn = 0;
	char *tMsgOut = 0;
	char *tFile = 0;
	char *tURL = 0;
	char *tStatus = 0;
	char *tOther = 0;
	char *tFooter = 0;
	char *tEnd = 0;

	char **tActive = 0;
	int size;

	char line[1024];

	FILE *f;

	f = fopen(fnTemplate, "rt");
	while (!feof(f))
	{
		fgets(line, 1024, f);
		int linesize = lstrlen(line)-1;
		if (*line) line[linesize] = 0;

		if (!lstrcmp(line, szHeader))
		{
			tActive = &tHeader;
			size = 0;
		} else
		if (!lstrcmp(line, szMsgIn))
		{
			tActive = &tMsgIn;
			size = 0;
		} else
		if (!lstrcmp(line, szMsgOut))
		{
			tActive = &tMsgOut;
			size = 0;
		} else
		if (!lstrcmp(line, szFile))
		{
			tActive = &tFile;
			size = 0;
		} else
		if (!lstrcmp(line, szURL))
		{
			tActive = &tURL;
			size = 0;
		} else
		if (!lstrcmp(line, szStatus))
		{
			tActive = &tStatus;
			size = 0;
		} else
		if (!lstrcmp(line, szOther))
		{
			tActive = &tOther;
			size = 0;
		} else
		if (!lstrcmp(line, szFooter))
		{
			tActive = &tFooter;
			size = 0;
		} else
		if (!lstrcmp(line, szEnd))
		{
			break;
		} else
		if (tActive)
		{
			line[linesize+0]  = '\n';
			line[linesize+1]  = '\0';
			*tActive = appendString(*tActive, line);
		}
	}
	fclose(f);

	f = fopen(fn, "wt");
	if (!f)
	{
		MessageBox(hwndHistory, Translate("Can't open optput file."), Translate("Newstory Export"), MB_ICONSTOP|MB_OK);
		free(tHeader);
		free(tMsgIn);
		free(tMsgOut);
		free(tFile);
		free(tURL);
		free(tStatus);
		free(tOther);
		free(tFooter);
		free(tEnd);
		return;
	}

	char *s;

	VFArgs args;
	args.hContact = hContact;
	args.event = 0;

	s = TplFormatStringEx(TPL_TITLE, tHeader, &args);
	fputs(s,f);
	free(s);

	int eventCount = SendMessage(hwndHistory, UM_GETEVENTCOUNT, 0, 0);
	for (int i = 0; i < eventCount; i++)
	{
		if (!SendMessage(hwndHistory, UM_SELECTED, i, 0))
			continue;

		args.event = (DBEVENTINFO *)SendMessage(hwndHistory, UM_GETEVENT, i, TRUE);
		switch (args.event->eventType)
		{
			case EVENTTYPE_MESSAGE:
				if (args.event->flags & DBEF_SENT)
				{
					s = TplFormatStringEx(TPL_MESSAGE, tMsgOut?tMsgOut:tOther, &args);
				} else
				{
					s = TplFormatStringEx(TPL_MESSAGE, tMsgIn?tMsgOut:tOther, &args);
				}
				break;

			case EVENTTYPE_FILE:
				s = TplFormatStringEx(TPL_FILE, tFile?tFile:tOther, &args);
				break;

			case EVENTTYPE_STATUSCHANGE:
				s = TplFormatStringEx(TPL_SIGN, tStatus?tStatus:tOther, &args);
				break;

			default:
				s = TplFormatStringEx(TPL_OTHER, tOther, &args);
				break;
		}

		fputs(s,f);
		free(s);
	}

	s = TplFormatStringEx(TPL_TITLE, tHeader, &args);
	fputs(s,f);
	free(s);

	fclose(f);

	free(tHeader);
	free(tMsgIn);
	free(tMsgOut);
	free(tFile);
	free(tURL);
	free(tStatus);
	free(tOther);
	free(tFooter);
	free(tEnd);

}*/

char* appendString(char* s1, char* s2)
{
	if (s1) {
		int l1 = mir_strlen(s1);
		int l2 = mir_strlen(s2);
		char* buf = (char*)mir_alloc(l1 + l2 + 1);
		mir_snprintf(buf, l1 + l2 + 1, "%s%s", s1, s2);
		mir_free(s1);
		return buf;
	}
	else {
		char* buf = (char*)mir_alloc(mir_strlen(s2) + 1);
		mir_strcpy(buf, s2);
		return buf;
	}
}

wchar_t* appendString(wchar_t* s1, wchar_t* s2)
{
	if (s1) {
		int l1 = mir_wstrlen(s1);
		int l2 = mir_wstrlen(s2);
		wchar_t* buf = (wchar_t*)mir_alloc(sizeof(wchar_t) * (l1 + l2 + 1));
		mir_snwprintf(buf, l1 + l2 + 1, L"%s%s", s1, s2);
		mir_free(s1);
		return buf;
	}
	else {
		wchar_t* buf = (wchar_t*)mir_alloc(sizeof(wchar_t) * (mir_wstrlen(s2) + 1));
		mir_wstrcpy(buf, s2);
		return buf;
	}
}