summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/dialogs.cpp
blob: 81a17351fb932a30d6ddcd4cf7697ab487c2c07c (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
#include "common.h"

INT_PTR CALLBACK WhatsAppAccountProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
   WhatsAppProto *proto;
   
	switch ( message )
	{

	case WM_INITDIALOG:
		TranslateDialogDefault(hwnd);

		proto = reinterpret_cast<WhatsAppProto*>(lparam);
		SetWindowLongPtr(hwnd,GWLP_USERDATA,lparam);

		DBVARIANT dbv;

		if ( !db_get_s(0,proto->ModuleName(),WHATSAPP_KEY_CC,&dbv,DBVT_ASCIIZ))
		{
			SetDlgItemTextA(hwnd,IDC_CC,dbv.pszVal);
			db_free(&dbv);
		}
      
		if ( !db_get_s(0,proto->ModuleName(),WHATSAPP_KEY_LOGIN,&dbv,DBVT_ASCIIZ))
		{
			SetDlgItemTextA(hwnd,IDC_LOGIN,dbv.pszVal);
			db_free(&dbv);
		}

		if ( !db_get_s(0,proto->ModuleName(),WHATSAPP_KEY_NICK,&dbv,DBVT_ASCIIZ))
		{
			SetDlgItemTextA(hwnd,IDC_NICK,dbv.pszVal);
			db_free(&dbv);
		}

		if ( !db_get_s(0,proto->ModuleName(),WHATSAPP_KEY_PASS,&dbv,DBVT_ASCIIZ))
		{
			CallService(MS_DB_CRYPT_DECODESTRING,strlen(dbv.pszVal)+1,
				reinterpret_cast<LPARAM>(dbv.pszVal));
			SetDlgItemTextA(hwnd,IDC_PW,dbv.pszVal);
			db_free(&dbv);
		}
      

		if (!proto->isOffline()) {
         SendMessage(GetDlgItem(hwnd,IDC_CC),EM_SETREADONLY,1,0);
			SendMessage(GetDlgItem(hwnd,IDC_LOGIN),EM_SETREADONLY,1,0);
			SendMessage(GetDlgItem(hwnd,IDC_NICK),EM_SETREADONLY,1,0);
         SendMessage(GetDlgItem(hwnd,IDC_PW),EM_SETREADONLY,1,0);
      }

		return TRUE;

	case WM_COMMAND:
      if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE)
      {
         if (MessageBox(NULL, _T("An SMS with registration-code will be sent to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneousley!\nContinue?"),
            PRODUCT_NAME, MB_YESNO) == IDYES)
         {
            proto = reinterpret_cast<WhatsAppProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
            proto->RequestCode();
         }
      }

		if ( HIWORD( wparam ) == EN_CHANGE && reinterpret_cast<HWND>(lparam) == GetFocus())
		{
			switch(LOWORD(wparam))
			{
         case IDC_CC:
			case IDC_LOGIN:
         case IDC_NICK:
			case IDC_PW:
				SendMessage(GetParent(hwnd),PSM_CHANGED,0,0);
			}
		}
		break;

	case WM_NOTIFY:
		if ( reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY )
		{
			proto = reinterpret_cast<WhatsAppProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
			char str[128];

			GetDlgItemTextA(hwnd, IDC_CC, str, sizeof(str));
			db_set_s(0,proto->ModuleName(),WHATSAPP_KEY_CC,str);

			GetDlgItemTextA(hwnd, IDC_LOGIN, str, sizeof(str));
			db_set_s(0,proto->ModuleName(),WHATSAPP_KEY_LOGIN,str);

			GetDlgItemTextA(hwnd, IDC_NICK, str, sizeof(str));
			db_set_s(0,proto->ModuleName(),WHATSAPP_KEY_NICK,str);

			GetDlgItemTextA(hwnd,IDC_PW,str,sizeof(str));
			CallService(MS_DB_CRYPT_ENCODESTRING,sizeof(str),reinterpret_cast<LPARAM>(str));
			db_set_s(0,proto->ModuleName(),WHATSAPP_KEY_PASS,str);

			return TRUE;
		}
		break;

	}

	return FALSE;

}

INT_PTR CALLBACK WhatsAppInputBoxProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
	input_box* ib;

	switch(message)
	{

	case WM_INITDIALOG:
	{
		TranslateDialogDefault(hwnd);

		ib = reinterpret_cast<input_box*>(lparam);
		SetWindowLongPtr(hwnd,GWLP_USERDATA,lparam);
		SendDlgItemMessage(hwnd,IDC_VALUE,EM_LIMITTEXT,ib->limit,0);
      SetDlgItemText(hwnd, IDC_VALUE, ib->defaultValue.c_str());
      SetDlgItemText(hwnd, IDC_TEXT, ib->text.c_str());

      /*
      DBVARIANT dbv = { DBVT_TCHAR };
		if (!DBGetContactSettingTString(NULL,ib->proto->m_szModuleName,WHATSAPP_KEY_PUSH_NAME,&dbv))
		{
			SetWindowText( hwnd, dbv.ptszVal );
			db_free( &dbv );
		}
      */
      SetWindowText(hwnd, ib->title.c_str());
	}

	EnableWindow(GetDlgItem( hwnd, IDC_OK ), FALSE);
	return TRUE;

	case WM_COMMAND:
		if ( LOWORD( wparam ) == IDC_VALUE && HIWORD( wparam ) == EN_CHANGE )
		{
         ib = reinterpret_cast<input_box*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
			size_t len = SendDlgItemMessage(hwnd,IDC_VALUE,WM_GETTEXTLENGTH,0,0);
			TCHAR str[4];
			_sntprintf( str, 4, TEXT( "%d" ), ib->limit - len );
			//SetDlgItemText(hwnd,IDC_CHARACTERS,str);

			EnableWindow(GetDlgItem( hwnd, IDC_OK ), len > 0);
			return TRUE;
		}
		else if ( LOWORD( wparam ) == IDC_OK )
		{
         ib = reinterpret_cast<input_box*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
			TCHAR* value = new TCHAR[ib->limit+1];

			GetDlgItemText(hwnd,IDC_VALUE,value, ib->limit + 1);
			ShowWindow(hwnd,SW_HIDE);

         input_box_ret* ret = new input_box_ret;
         ret->userData = ib->userData;
         ret->value = mir_utf8encodeT(value);
         delete value;
			ForkThread(ib->thread, ib->proto, ret);
			EndDialog(hwnd, wparam);
         delete ib;
			return TRUE;
		}
		else if ( LOWORD( wparam ) == IDC_CANCEL )
		{
			EndDialog(hwnd, wparam);
         ib = reinterpret_cast<input_box*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
         delete ib;
			return TRUE;
		}
		break;

	}

	return FALSE;
}