summaryrefslogtreecommitdiff
path: root/window_timeout/windowtimeout.c
blob: d5bf05e18b048053ac805c111f9ec1490ab68d7e (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
#include "windowtimeout.h"

HINSTANCE hInst;
PLUGINLINK *pluginLink;
struct MM_INTERFACE mmi;

PLUGININFO pluginInfo={
	sizeof(PLUGININFO),
	PLUG,
	PLUGIN_MAKE_VERSION(0,0,0,3),
	"Hides message windows after a specified period of inactivity",
	"Scott Ellis",
	"mail@scottellis.com.au",
	"© 2005 Scott Ellis",
	"http://www.scottellis.com.au/",
	0,		//not transient
	0		//doesn't replace anything built-in
};

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
	hInst=hinstDLL;
	return TRUE;
}

__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
{
	return &pluginInfo;
}

HANDLE hook_idle, hook_dbevent, hook_dbcontact, hook_window, hook_typing;

int OnIdleChanged(WPARAM wParam, LPARAM lParam) {
	return 0;
}

int OnWindowEvent(WPARAM wParam, LPARAM lParam) {
	MessageWindowEventData *mwed = (MessageWindowEventData *)lParam;
	if(mwed->uType == MSG_WINDOW_EVT_OPENING || mwed->uType == MSG_WINDOW_EVT_OPEN) {
		add_entry(mwed->hContact);
		set_window_handle(mwed->hContact, mwed->hwndWindow);
	} else if(mwed->uType == MSG_WINDOW_EVT_CLOSING || mwed->uType == MSG_WINDOW_EVT_CLOSE)
		remove_entry(mwed->hContact);
	return 0;
}

int OnDbEvent(WPARAM wParam, LPARAM lParam) {
	HANDLE hContact = (HANDLE)wParam;
	if(options.monitor_recv_only == FALSE) {
		add_entry(hContact);
		reset_timer(hContact);
	} else {
		DBEVENTINFO *dbe = (HANDLE)lParam;
		if(dbe->flags & DBEF_SENT) {
			struct Entry *entry = get_entry(hContact);
			msg("sent event");
			if(entry && entry->timer_id == 0) {
				msg("closing window");
				SendMessage(entry->hwnd, WM_CLOSE, 0, 0);
			}
			return 0;
		}
		if(dbe->flags & DBEF_READ) {
			msg("read event");
			return 0;
		}

		add_entry(hContact);
		reset_timer(hContact);
	}
	return 0;
}


int OnTyping(WPARAM wParam, LPARAM lParam) {
	if(lParam) reset_timer((HANDLE)wParam);

	return 0;
}

int OnContactDeleted(WPARAM wParam, LPARAM lParam) {
	HANDLE hContact = (HANDLE)wParam;
	remove_entry(hContact);
	return 0;
}

int OnModulesLoaded(WPARAM wParam, LPARAM lParam) {
	hook_idle = HookEvent(ME_IDLE_CHANGED, OnIdleChanged);
	hook_dbevent = HookEvent(ME_DB_EVENT_FILTER_ADD, OnDbEvent);
	hook_window = HookEvent(ME_MSG_WINDOWEVENT, OnWindowEvent);
	hook_dbcontact = HookEvent(ME_DB_CONTACT_DELETED, OnContactDeleted);
	hook_typing = HookEvent(ME_PROTO_CONTACTISTYPING, OnTyping);
	return 0;
}

int __declspec(dllexport) Load(PLUGINLINK *link)
{
	PROTOCOLDESCRIPTOR pd;
	HANDLE hContact;

	pluginLink = link;

	CallService(MS_SYSTEM_GET_MMI, 0, (LPARAM)&mmi);

	HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
	HookEvent(ME_OPT_INITIALISE, OptInit);

	load_options();
	return 0;
}

int __declspec(dllexport) Unload(void)
{
	if(hook_idle) UnhookEvent(hook_idle);
	if(hook_dbevent) UnhookEvent(hook_dbevent);
	if(hook_window) UnhookEvent(hook_window);
	if(hook_dbcontact) UnhookEvent(hook_dbcontact);
	if(hook_typing) UnhookEvent(hook_typing);
	return 0;
}


void msg(char *msg) {
	//MessageBox(0, msg, "Message", MB_OK);
}