summaryrefslogtreecommitdiff
path: root/plugins/SkypeStatusChange/src/stdafx.h
blob: 307fa73413175a39d8690e2000a68d3ce5f686cf (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
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <assert.h>
#include <commctrl.h>

#include <newpluginapi.h>
#include <m_database.h>
#include <m_protocols.h>
#include <m_protosvc.h>
#include <m_awaymsg.h>
#include <m_options.h>
#include <m_langpack.h>
#include <m_utils.h>
#include <win2k.h>

#define MODULENAME "Change Skype Status"

class COptions
{
	enum
	{
		cssOnline		= 0x00000001,
		cssOffline		= 0x00000002,
		cssInvisible	= 0x00000004,
		cssShortAway	= 0x00000008,
		cssLongAway		= 0x00000010,
		cssLightDND		= 0x00000020,
		cssHeavyDND		= 0x00000040,
		cssFreeChart	= 0x00000080,
		cssOutToLunch	= 0x00000100,
		cssOnThePhone	= 0x00000200,
		cssIdle			= 0x00000400,
		cssAll			= 0x80000000
	};

	static unsigned long Status2Flag(int status)
	{
		switch(status)
		{
			case ID_STATUS_ONLINE: return cssOnline;
			case ID_STATUS_OFFLINE: return cssOffline;
			case ID_STATUS_INVISIBLE: return cssInvisible;
			case ID_STATUS_OUTTOLUNCH: return cssOutToLunch;
			case ID_STATUS_ONTHEPHONE: return cssOnThePhone;
			case ID_STATUS_AWAY: return cssShortAway;
			case ID_STATUS_NA: return cssLongAway;
			case ID_STATUS_OCCUPIED: return cssLightDND;
			case ID_STATUS_DND: return cssHeavyDND;
			case ID_STATUS_FREECHAT: return cssFreeChart;
			case ID_STATUS_IDLE: return cssIdle;
		}
		return 0;
	}

	struct PrevStatus
	{
		PrevStatus(const char *_proto, int _status) :
			szProto(mir_strdup(_proto)),
			iStatus(_status)
		{}

		ptrA szProto;
		int iStatus;
	};

	OBJLIST<PrevStatus> m_aProtocol2Status;
	static int CompareStatuses(const PrevStatus *p1, const PrevStatus *p2)
	{	return mir_strcmp(p1->szProto, p2->szProto);
	}

public:
	COptions() :
		m_aProtocol2Status(3, CompareStatuses)
		{}

	bool IsProtocolExcluded(const char* pszProtocol)const
	{
		DWORD dwSettings = db_get_dw(NULL,pszProtocol,"ChangeSkypeStatus_Exclusions",0);
		return ((dwSettings&cssAll) ? true : false);
	}

	bool IsProtocolStatusExcluded(const char* pszProtocol,int nStatus)const
	{
		DWORD dwSettings = db_get_dw(NULL,pszProtocol,"ChangeSkypeStatus_Exclusions",0);
		return ((dwSettings&Status2Flag(nStatus)) ? true : false);
	}

	void ExcludeProtocol(const char* pszProtocol,bool bExclude)
	{
		DWORD dwSettings = db_get_dw(NULL,pszProtocol,"ChangeSkypeStatus_Exclusions",0);
		if (bExclude)
			dwSettings |=cssAll;
		else
			dwSettings &= ~cssAll;

		db_set_dw(NULL,pszProtocol,"ChangeSkypeStatus_Exclusions",dwSettings);
	}

	void ExcludeProtocolStatus(const char* pszProtocol,int nStatus,bool bExclude)
	{
		DWORD dwSettings = db_get_dw(NULL,pszProtocol,"ChangeSkypeStatus_Exclusions",0);
		if (bExclude)
			dwSettings |=Status2Flag(nStatus);
		else
			dwSettings &= ~Status2Flag(nStatus);

		db_set_dw(NULL,pszProtocol,"ChangeSkypeStatus_Exclusions",dwSettings);
	}

	bool GetSyncStatusMsgFlag()const
	{
		return db_get_b(NULL,MODULENAME,"SyncStatusMsg",false) > 0;
	}

	bool GetSyncStatusStateFlag()const
	{
		return db_get_b(NULL,MODULENAME,"SyncStatusState",false) > 0;
	}

	void SetSyncStatusMsgFlag(bool b)
	{
		db_set_b(NULL,MODULENAME,"SyncStatusMsg",b);
	}

	void SetSyncStatusStateFlag(bool b)
	{
		db_set_b(NULL,MODULENAME,"SyncStatusState",b);
	}

	bool GetPreviousStatus(const char* pszProtocol,int& nStatus)const
	{
		int i = m_aProtocol2Status.getIndex((PrevStatus*)&pszProtocol);
		if (i != -1) {
			nStatus = m_aProtocol2Status[i].iStatus;
			return true;
		}

		return false;
	}

	void SetPreviousStatus(const char* pszProtocol,int nStatus)
	{
		int i = m_aProtocol2Status.getIndex((PrevStatus*)&pszProtocol);
		if (i != -1)
			m_aProtocol2Status[i].iStatus = nStatus;
		else
			m_aProtocol2Status.insert( new PrevStatus(pszProtocol, nStatus));
	}
};

extern COptions g_Options;

/////////////////////////////////////////////////////////////////////////////////////////

struct CMirandaStatus2SkypeStatus
{
	int m_nMirandaStatus;
	LPCSTR m_pszSkypeStatus;
	LPCTSTR m_ptszStatusName;
};

extern const CMirandaStatus2SkypeStatus g_aStatusCode[10];

/////////////////////////////////////////////////////////////////////////////////////////

extern HINSTANCE g_hModule;