summaryrefslogtreecommitdiff
path: root/MySpace/options.cpp
blob: cf592d85c9d505672f00bec1bcbd981ad4a5565d (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
#include "common.h"
#include "options.h"
#include "resource.h"

Options options = {0};

void LoadOptions() {
	DBVARIANT dbv;
	if(!DBGetContactSettingTString(0, MODULE, "email", &dbv)) {
		_tcsncpy(options.email, dbv.ptszVal, 256);
		DBFreeVariant(&dbv);
	}
	if(!DBGetContactSettingTString(0, MODULE, "pw", &dbv)) {
		_tcsncpy(options.pw, dbv.ptszVal, 256);
		DBFreeVariant(&dbv);
	}

	options.sound = (DBGetContactSettingByte(0, MODULE, "sound", 0) != 0);
	options.privacy_mode = (PrivacyMode)DBGetContactSettingByte(0, MODULE, "privacy_mode", PM_ANYONE);
	options.show_only_to_list = (DBGetContactSettingByte(0, MODULE, "show_only_to_list", 0) != 0);
	options.offline_message_mode = (OfflineMessageMode)DBGetContactSettingByte(0, MODULE, "offline_message_mode", OMM_CLIST);;
	options.show_avatar = (DBGetContactSettingByte(0, MODULE, "show_avatar", 0) != 0);
	if(!DBGetContactSettingStringUtf(0, MODULE, "Nick", &dbv)) {
		strncpy(options.im_name, dbv.pszVal, 256);
		DBFreeVariant(&dbv);
	}
}

void SaveOptions() {
	DBWriteContactSettingTString(0, MODULE, "email", options.email);
	DBWriteContactSettingTString(0, MODULE, "pw", options.pw);

	DBWriteContactSettingByte(0, MODULE, "sound", options.sound ? 1 : 0);
	DBWriteContactSettingByte(0, MODULE, "privacy_mode", (BYTE)options.privacy_mode);
	DBWriteContactSettingByte(0, MODULE, "show_only_to_list", options.show_only_to_list ? 1 : 0);
	DBWriteContactSettingByte(0, MODULE, "offline_message_mode", (BYTE)options.offline_message_mode);
	DBWriteContactSettingByte(0, MODULE, "show_avatar", options.show_avatar ? 1 : 0);
	DBWriteContactSettingStringUtf(0, MODULE, "Nick", options.im_name);
}

BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
	//static HANDLE hItemAll;

	switch ( msg ) {
	case WM_INITDIALOG:
		TranslateDialogDefault( hwndDlg );
		SetDlgItemText(hwndDlg, IDC_ED_EMAIL, options.email);
		SetDlgItemText(hwndDlg, IDC_ED_PW, options.pw);
		return FALSE;		
	case WM_COMMAND:
		if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) {
			switch( LOWORD( wParam )) {
			case IDC_ED_EMAIL:
			case IDC_ED_PW:
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			}	
			break;
		}
		break;
	case WM_NOTIFY:
		switch(((LPNMHDR)lParam)->idFrom) {
			case 0:
				switch (((LPNMHDR)lParam)->code)
				{
					case PSN_APPLY:
						GetDlgItemText(hwndDlg, IDC_ED_EMAIL, options.email, 256);
						GetDlgItemText(hwndDlg, IDC_ED_PW, options.pw, 256);

						SaveOptions();
				}
				break;
		}
		break;
	}

	return 0;
}

int OptInit(WPARAM wParam, LPARAM lParam) {
	OPTIONSDIALOGPAGE odp = { 0 };
	odp.cbSize						= sizeof(odp);
	odp.flags						= ODPF_BOLDGROUPS;
	odp.flags |= ODPF_TCHAR;
	odp.position					= -790000000;
	odp.hInstance					= hInst;

	odp.pszTemplate					= MAKEINTRESOURCEA(IDD_OPT1);
	odp.ptszTitle					= TranslateT(MODULE);
	odp.ptszGroup					= TranslateT("Network");
	odp.ptszTab						= TranslateT("Account");
	odp.nIDBottomSimpleControl		= 0;
	odp.pfnDlgProc					= DlgProcOpts;
	CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp );

	return 0;
}

HANDLE hEventOptInit;
void InitOptions() {
	hEventOptInit = HookEvent(ME_OPT_INITIALISE, OptInit);
	LoadOptions();
}

void DeinitOptions() {
	UnhookEvent(hEventOptInit);
}