summaryrefslogtreecommitdiff
path: root/plugins/Non-IM Contact/src/main.cpp
blob: 1d8b9cf6236604e20034f5bb8f12aaa1c0775fe0 (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
//=====================================================
//	Includes
//=====================================================

#include "commonheaders.h"

#include "Version.h"

CLIST_INTERFACE *pcli;
HINSTANCE hInst;
int hLangpack;

PLUGININFOEX pluginInfoEx = {
	sizeof(pluginInfoEx),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__AUTHOREMAIL,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	//2e0d2ae3-e123-4607-8539-d4448d675ddb
	{ 0x2e0d2ae3, 0xe123, 0x4607, {0x85, 0x39, 0xd4, 0x44, 0x8d, 0x67, 0x5d, 0xdb} }
};

INT_PTR doubleClick(WPARAM wParam,LPARAM lParam)
{
	char program[MAX_PATH], params[MAX_PATH];
	int shellEXEerror = 0;
	char* proto = GetContactProto((MCONTACT)wParam);
	if (proto && !strcmp(proto, MODNAME)) {
		if (GetKeyState(VK_CONTROL)&0x8000) // ctrl is pressed
			editContact((WPARAM)(HANDLE)wParam, (LPARAM)NULL);		// for later when i add a second double click setting
		else if (db_get_static((MCONTACT)wParam, MODNAME, "Program", program) && strcmp(program, ""))
		{
			if (!db_get_static((MCONTACT)wParam, MODNAME, "ProgramParams", params) )
				strcpy(params, "");
			if (strstr(program, "http://") || strstr(program, "https://"))
				CallService(MS_UTILS_OPENURL,1,(LPARAM)program);
			else shellEXEerror = (int)ShellExecuteA(NULL, NULL, program, params, NULL, SW_SHOW);  //ignore the warning, its M$'s backwards compatabilty screwup :)
			if (shellEXEerror == ERROR_FILE_NOT_FOUND || shellEXEerror == ERROR_PATH_NOT_FOUND)
				CallService(MS_UTILS_OPENURL,1,(LPARAM)program);
		}
		else editContact((WPARAM)(HANDLE)wParam, (LPARAM)NULL);
		return 1;
	}
	return 0;
}

//=====================================================
//	Definitions
//=====================================================
int LCStatus = ID_STATUS_OFFLINE;
//=====================================================

//=====================================================
// Name : MainInit
// Parameters: wparam , lparam
// Returns : int
// Description : Called at very beginning of plugin
//=====================================================
int NimcOptInit(WPARAM wParam,LPARAM lParam)
{
	OPTIONSDIALOGPAGE odp = { sizeof(odp) };
	odp.hInstance = hInst;
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
	odp.pszGroup = LPGEN("Plugins");
	odp.pszTitle = LPGEN("Non-IM Contacts");
	odp.pfnDlgProc = DlgProcNimcOpts;
	Options_AddPage(wParam, &odp);
	return 0;
}

int MainInit(WPARAM wparam,LPARAM lparam)
{
	return 0;
}

//=====================================================
// Name : __declspec(dllexport) PLUGININFO* MirandaPluginInfo
// Parameters: (DWORD mirandaVersion)
// Returns :
// Description : Sets plugin info
//=====================================================

extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
	return &pluginInfoEx;
}

//=====================================================
// Name : WINAPI DllMain
// Parameters: HINSTANCE hinst,DWORD fdwReason,LPVOID lpvReserved
// Returns : BOOL
// Description :
//=====================================================

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

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

//=====================================================
// Name : Load
// Parameters: PLUGINLINK *link
// Returns : int
// Description : Called when plugin is loaded into Miranda
//=====================================================

IconItem icoList[] =
{
	{ LPGEN("Main Icon"), MODNAME, IDI_MAIN },
};

extern "C" __declspec(dllexport) int Load()
{
	mir_getLP(&pluginInfoEx);
	mir_getCLI();

	Icon_Register(hInst, LPGEN("Non-IM Contact"), icoList, SIZEOF(icoList));

	HookEvent(ME_CLIST_DOUBLECLICKED, (MIRANDAHOOK)doubleClick);
	HookEvent(ME_OPT_INITIALISE,NimcOptInit);
	HookEvent(ME_CLIST_STATUSMODECHANGE, SetLCStatus);

	PROTOCOLDESCRIPTOR pd = { PROTOCOLDESCRIPTOR_V3_SIZE, MODNAME, PROTOTYPE_VIRTUAL };
	CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd);

	//load services (the first 5 are the basic ones needed to make a new protocol)
	CreateServiceFunction(MODNAME PS_GETCAPS, GetLCCaps);
	CreateServiceFunction(MODNAME PS_GETNAME, GetLCName);
	CreateServiceFunction(MODNAME PS_LOADICON, LoadLCIcon);
	CreateServiceFunction(MODNAME PS_GETSTATUS, GetLCStatus);

	CreateServiceFunction("AddLCcontact", addContact);
	CreateServiceFunction("EditLCcontact", editContact);
	CreateServiceFunction("LoadFilesDlg", LoadFilesDlg);
	CreateServiceFunction("ExportLCcontacts", exportContacts);
	CreateServiceFunction("ImportLCcontacts", ImportContacts);
	CreateServiceFunction("TestStringReplaceLine", testStringReplacer);
	CreateServiceFunction("NIM_Contact/DoubleClick", doubleClick);

	CLISTMENUITEM mi = { sizeof(mi) };
	mi.position = 600090000;
	mi.pszPopupName = LPGEN("&Non-IM Contact");
	mi.popupPosition = 600090000;
	mi.pszName = LPGEN("&Add Non-IM Contact");
	mi.pszService = "AddLCcontact";
	mi.icolibItem = icoList[0].hIcolib;
	Menu_AddMainMenuItem(&mi);

	mi.position = 600090001;
	mi.pszName = LPGEN("&View/Edit Files");
	mi.pszService = "LoadFilesDlg";
	Menu_AddMainMenuItem(&mi);

	if (db_get_b(NULL, MODNAME, "Beta",0)) {
		mi.position = 600090002;
		mi.pszName = LPGEN("&Export all Non-IM Contacts");
		mi.pszService = "ExportLCcontacts";
		Menu_AddMainMenuItem(&mi);

		mi.position = 600090003;
		mi.pszName = LPGEN("&Import Non-IM Contacts");
		mi.pszService = "ImportLCcontacts";
		Menu_AddMainMenuItem(&mi);
	}

	mi.position = 600090000;
	mi.pszPopupName = LPGEN("&Non-IM Contact");
	mi.pszName = LPGEN("&String Maker");
	mi.pszService = "TestStringReplaceLine";
	Menu_AddMainMenuItem(&mi);

	mi.position = -2000080000;
	mi.pszContactOwner = MODNAME;
	mi.pszName = LPGEN("E&dit Contact Settings");
	mi.pszService = "EditLCcontact";
	Menu_AddContactMenuItem(&mi);

	HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);

	return 0;
}

//=====================================================
// Name : Unload
// Parameters: void
// Returns :
// Description : Unloads plugin
//=====================================================

extern "C" __declspec(dllexport) int Unload(void)
{
	return 0;
}