summaryrefslogtreecommitdiff
path: root/plugins/Non-IM Contact/src/services.cpp
blob: e6fcfb3da30ac1400ebe3e828d0a914c3798431f (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
#include "stdafx.h"

//=======================================================
// db_get_static
//=======================================================

int db_get_static(MCONTACT hContact, const char *szModule, const char *szSetting, char *value, size_t length)
{
	ptrA str(db_get_sa(hContact, szModule, szSetting));
	if (str == NULL)
		return 0;

	strncpy_s(value, length, str, _TRUNCATE);
	return 1;
}

//=======================================================
// GetCaps
//=======================================================

INT_PTR GetLCCaps(WPARAM wParam, LPARAM)
{
	if (wParam == PFLAGNUM_1)
		return 0;
	if (wParam == PFLAGNUM_2)
		return PF2_ONLINE | PF2_LONGAWAY | PF2_SHORTAWAY | PF2_LIGHTDND | PF2_HEAVYDND | PF2_FREECHAT | PF2_INVISIBLE | PF2_OUTTOLUNCH | PF2_ONTHEPHONE; // add the possible statuses here.
	if (wParam == PFLAGNUM_3)
		return 0;
	return 0;
}

//=======================================================
// GetName
//=======================================================
INT_PTR GetLCName(WPARAM wParam, LPARAM lParam)
{
	mir_strncpy((char*)lParam, MODNAME, wParam);
	return 0;
}

//=======================================================
// BPLoadIcon
//=======================================================
INT_PTR LoadLCIcon(WPARAM wParam, LPARAM)
{
	if (LOWORD(wParam) == PLI_PROTOCOL) {
		if (wParam & PLIF_ICOLIBHANDLE)
			return (INT_PTR)icoList[0].hIcolib;

		HICON hIcon = IcoLib_GetIconByHandle(icoList[0].hIcolib, (wParam & PLIF_SMALL) == 0);
		if (wParam & PLIF_ICOLIB)
			return (INT_PTR)hIcon;

		HICON hIcon2 = CopyIcon(hIcon);
		IcoLib_ReleaseIcon(hIcon);
		return (INT_PTR)hIcon2;
	}

	return NULL;
}

//=======================================================
// SetFStatus			
//=======================================================

int SetLCStatus(WPARAM wParam, LPARAM)
{
	int oldStatus = LCStatus;
	LCStatus = wParam;
	db_set_w(NULL, MODNAME, "Status", (WORD)wParam);
	db_set_w(NULL, MODNAME, "timerCount", 0);
	if (LCStatus == ID_STATUS_OFFLINE || (LCStatus == ID_STATUS_AWAY && !db_get_b(NULL, MODNAME, "AwayAsStatus", 0)) || !db_get_w(NULL, MODNAME, "Timer", 1))
		killTimer();
	else if (db_get_w(NULL, MODNAME, "Timer", 1))
		startTimer(TIMER);

	for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) {
		if (LCStatus != ID_STATUS_OFFLINE)
			replaceAllStrings(hContact);

		switch (LCStatus) {
		case ID_STATUS_OFFLINE:
			if (db_get_b(hContact, MODNAME, "AlwaysVisible", 0) && !db_get_b(hContact, MODNAME, "VisibleUnlessOffline", 1))
				db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
			else
				db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE);
			break;

		case ID_STATUS_ONLINE:
			db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
			break;

		case ID_STATUS_AWAY:
			if (db_get_b(NULL, MODNAME, "AwayAsStatus", 0) && (db_get_b(hContact, MODNAME, "AlwaysVisible", 0) || (db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE) == ID_STATUS_AWAY)))
				db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
			else if (!db_get_b(NULL, MODNAME, "AwayAsStatus", 0))
				db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
			else
				db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE);
			break;

		default:
			if (db_get_b(hContact, MODNAME, "AlwaysVisible", 0) || LCStatus == db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE))
				db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
			break;
		}
	}

	ProtoBroadcastAck(MODNAME, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, wParam);
	return 0;
}

//=======================================================
// GetStatus
//=======================================================

INT_PTR GetLCStatus(WPARAM, LPARAM)
{
	if ((LCStatus >= ID_STATUS_ONLINE) && (LCStatus <= ID_STATUS_OUTTOLUNCH))
		return LCStatus;
	else
		return ID_STATUS_OFFLINE;
}