summaryrefslogtreecommitdiff
path: root/plugins/MirandaG15/src/CAppletManager.h
blob: f3551b41fed07e10fc96c1fbc69f1c8f486766ac (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
#ifndef _COUTPUTMANAGER_H_
#define _COUTPUTMANAGER_H_

#include "CLCDOutputManager.h"

#include "CProtocolData.h"
#include "CIRCHistory.h"
#include "CIRCConnection.h"

#include "CNotificationScreen.h"
#include "CEventScreen.h"
#include "CContactlistScreen.h"
#include "CChatScreen.h"
#include "CCreditsScreen.h"
#include "CScreensaverScreen.h"

#include "CLCDConnectionLogitech.h"

struct SMessageJob
{
	HANDLE hEvent;
	HCONTACT hContact;
	DWORD dwFlags;
	char *pcBuffer;
	int iBufferSize;
	DWORD dwTimestamp;
};

class CAppletManager : public CLCDOutputManager
{
public:
	// returns the AppletManager's instance
	static CAppletManager *GetInstance();

	// Constructor
	CAppletManager();
	// Destructor
	~CAppletManager();

	// Initializes the AppletManager
	bool Initialize(tstring strAppletName);
	// Deinitializes the AppletManager
	bool Shutdown();
	// Updates the AppletManager
	bool Update();

	// the update timer's callback function
	static VOID CALLBACK UpdateTimer(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime);

	// called when the plugin's configuration has changed
	void OnConfigChanged();
	
	// called to process the specified event
	void HandleEvent(CEvent *pEvent);

	// screen activation functions
	void ActivatePreviousScreen();
	void ActivateScreensaverScreen();
	void ActivateCreditsScreen();
	void ActivateEventScreen();
	void ActivateCListScreen();
	bool ActivateChatScreen(HCONTACT hContact);

	// hook functions
	static int HookMessageWindowEvent(WPARAM wParam, LPARAM lParam);
	static int HookContactIsTyping(WPARAM wParam, LPARAM lParam);
	static int HookEventAdded(WPARAM wParam, LPARAM lParam); 
	static int HookStatusChanged(WPARAM wParam, LPARAM lParam);
	static int HookProtoAck(WPARAM wParam, LPARAM lParam);
	static int HookContactAdded(WPARAM wParam, LPARAM lParam);
	static int HookContactDeleted(WPARAM wParam, LPARAM lParam);
	static int HookSettingChanged(WPARAM wParam,LPARAM lParam);
	static int HookChatInbound(WPARAM wParam,LPARAM lParam);

	// check if a contacts message window is opened
	static bool IsMessageWindowOpen(HCONTACT hContact);
	// marks the given event as read
	static void MarkMessageAsRead(HCONTACT hContact,HANDLE hEvent);
	// translates the given database event
	static bool TranslateDBEvent(CEvent *pEvent,WPARAM wParam, LPARAM lParam);
	// sends a message to the specified contact
	static HANDLE SendMessageToContact(HCONTACT hContact,tstring strMessage);
	// sends typing notifications to the specified contact
	static void SendTypingNotification(HCONTACT hContact,bool bEnable);

	// returns the contacts message service name
	static char *GetMessageServiceName(HCONTACT hContact,bool bIsUnicode);
	static bool  IsUtfSendAvailable(HCONTACT hContact);
	// returns a formatted timestamp string
	static tstring GetFormattedTimestamp(tm *time);

	// returns wether or not a contact is a subcontact
	static bool IsSubContact(HCONTACT hContact);
	// returns the contacts group
	static tstring GetContactGroup(HCONTACT hContact);
	// returns the contacts displayname
	static tstring GetContactDisplayname(HCONTACT hContact,bool bShortened=false);

	// returns the history class for the specified IRC channel
	CIRCHistory *GetIRCHistory(HCONTACT hContact);
	CIRCHistory *GetIRCHistoryByName(tstring strProtocol,tstring strChannel);

	// returns the IRC connection class for the specified protocol
	CIRCConnection *GetIRCConnection(tstring strProtocol);
	// creates the IRC connection class for the specified protocol
	CIRCConnection *CreateIRCConnection(tstring strProtocol);

	// returns the bitmap for the specified status
	HBITMAP GetStatusBitmap(int iStatus);
	// returns the bitmap for the specified event
	HBITMAP GetEventBitmap(EventType eType, bool bLarge = false);

	// checks if the patched IRC protocol is in place
	bool IsIRCHookEnabled();

	static tstring TranslateString(TCHAR *szString,...);

private:
	list<CIRCHistory*> m_LIRCHistorys;
	// deletes the history class for the specified IRC channel
	void DeleteIRCHistory(HCONTACT hContact);
	// creates a history class for the specified IRC channel
	CIRCHistory *CreateIRCHistory(HCONTACT hContact,tstring strChannel);
	CIRCHistory *CreateIRCHistoryByName(tstring strProtocol,tstring strChannel);

	// activate a screen
	void ActivateScreen(CScreen *pScreen);

	// applies the volumewheel setting
	void SetVolumeWheelHook();

	// Called when the connection state has changed
	void OnConnectionChanged(int iConnectionState);
	// Called when the active screen has expired
	void OnScreenExpired(CLCDScreen *pScreen);
	
	// updates all pending message jobs
	void UpdateMessageJobs();
	// adds a message job to the list
	void AddMessageJob(SMessageJob *pJob);
	// finishes a message job
	void FinishMessageJob(SMessageJob *pJob);
	// cancels a message job
	void CancelMessageJob(SMessageJob *pJob);

	// removes a message job from the list

	// strip IRC formatting
	static tstring StripIRCFormatting(tstring strText);

	// Light status
	SG15LightStatus m_G15LightStatus;

	list<SMessageJob*> m_MessageJobs;

	// update timer handle
	UINT					m_uiTimer;

	// screens
	CNotificationScreen		m_NotificationScreen;
	CEventScreen			m_EventScreen;
	CContactlistScreen		m_ContactlistScreen;
	CChatScreen				m_ChatScreen;
	CCreditsScreen			m_CreditsScreen;
	CScreensaverScreen		m_ScreensaverScreen;

	// protocol data
	vector<CProtocolData*> m_vProtocolData;
	CProtocolData* GetProtocolData(tstring strProtocol);

	// hook handles
	HANDLE m_hMIHookMessageWindowEvent;
	HANDLE m_hMIHookContactIsTyping;
	HANDLE m_hMIHookEventAdded;	
	HANDLE m_hMIHookStatusChanged;	
	HANDLE m_hMIHookProtoAck;
	HANDLE m_hMIHookSettingChanged;
	HANDLE m_hMIHookContactDeleted;
	HANDLE m_hMIHookContactAdded;

	vector<CIRCConnection*> m_vIRCConnections;

	// last active screen
	CScreen *m_pLastScreen;
	
	bool m_bScreensaver;

	HBITMAP m_ahStatusBitmaps[8];
	HBITMAP m_ahEventBitmaps[4];
	HBITMAP m_ahLargeEventBitmaps[4];
};

#endif