summaryrefslogtreecommitdiff
path: root/protocols/ICQCorp/src/user.cpp
blob: ba2fd4c2fbf76655467ed65a409f94d2e0615735 (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
/*
    ICQ Corporate protocol plugin for Miranda IM.
    Copyright (C) 2003-2005 Eugene Tarasenko <zlyden13@inbox.ru>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "corp.h"

std::vector <ICQUser *> icqUsers;

///////////////////////////////////////////////////////////////////////////////

ICQUser::ICQUser() :
    socket(WM_NETEVENT_USER)
{
}

///////////////////////////////////////////////////////////////////////////////

void ICQUser::setStatus(unsigned short newStatus)
{
    if (statusVal == newStatus) return;

    statusVal = newStatus;
    db_set_w(hContact, protoName, "Status", newStatus);
}

///////////////////////////////////////////////////////////////////////////////

void ICQUser::setInfo(char *name, unsigned int data)
{
    if (data && data != 0xFFFFFFFF) db_set_dw(hContact, protoName, name, data);
    else db_unset(hContact, protoName, name);
}

///////////////////////////////////////////////////////////////////////////////

void ICQUser::setInfo(char *name, unsigned short data)
{
    if (data && data != 0xFFFF) db_set_w(hContact, protoName, name, data);
    else db_unset(hContact, protoName, name);
}

///////////////////////////////////////////////////////////////////////////////

void ICQUser::setInfo(char *name, unsigned char data)
{
    if (data && data != 0xFF) db_set_b(hContact, protoName, name, data);
    else db_unset(hContact, protoName, name);
}

///////////////////////////////////////////////////////////////////////////////

void ICQUser::setInfo(char *name, char *data)
{
    if (data[0]) db_set_s(hContact, protoName, name, data);
    else db_unset(hContact, protoName, name);
}

///////////////////////////////////////////////////////////////////////////////

static char *iptoa(unsigned int ip)
{
    struct in_addr addr;

    addr.S_un.S_addr = htonl(ip);
    return inet_ntoa(addr);
}

///////////////////////////////////////////////////////////////////////////////

static void setTextValue(HWND hWnd, int id, char *value)
{
    bool unspecified = value == NULL;

    EnableWindow(GetDlgItem(hWnd, id), !unspecified);
    SetDlgItemText(hWnd, id, unspecified ? Translate("<not specified>") : value);
}

///////////////////////////////////////////////////////////////////////////////

static BOOL CALLBACK icqUserInfoDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    LPNMHDR hdr;

    switch (msg)
    {
    case WM_INITDIALOG:
        TranslateDialogDefault(hWnd);
        return TRUE;

    case WM_NOTIFY:
        hdr = (LPNMHDR)lParam;
        if (hdr->idFrom == 0 && hdr->code == PSN_INFOCHANGED)
        {
            char buffer[64];
            unsigned long ip, port;
			MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;

            _itoa(db_get_dw(hContact, protoName, "UIN", 0), buffer, 10);
            setTextValue(hWnd, IDC_INFO_UIN, buffer);

            ip = db_get_dw(hContact, protoName, "IP", 0);
            setTextValue(hWnd, IDC_INFO_IP, ip ? iptoa(ip) : NULL);

            ip = db_get_dw(hContact, protoName, "RealIP", 0);
            setTextValue(hWnd, IDC_INFO_REALIP, ip ? iptoa(ip) : NULL);

            port = db_get_w(hContact, protoName, "Port", 0);
            _itoa(port, buffer, 10);
            setTextValue(hWnd, IDC_INFO_PORT, port ? buffer : NULL);

            setTextValue(hWnd, IDC_INFO_VERSION, NULL);
            setTextValue(hWnd, IDC_INFO_MIRVER, NULL);
            setTextValue(hWnd, IDC_INFO_PING, NULL);
        }
        break;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDCANCEL) SendMessage(GetParent(hWnd), msg, wParam, lParam);
        break;
    }
    return FALSE;
}

///////////////////////////////////////////////////////////////////////////////

int icqUserInfoInitialise(WPARAM wParam, LPARAM lParam)
{
	char *proto = GetContactProto(lParam);
	if ((proto == NULL || mir_strcmp(proto, protoName)) && lParam)
		return 0;

	OPTIONSDIALOGPAGE odp = { 0 };
	odp.position = -1900000000;
	odp.pszTitle = Translate(protoName);
	odp.pfnDlgProc = (DLGPROC)icqUserInfoDlgProc;
	odp.pszTemplate = MAKEINTRESOURCE(IDD_INFO_ICQCORP);
	odp.hInstance = hInstance;
	Options_AddPage(wParam, &odp);
	return 0;
}

///////////////////////////////////////////////////////////////////////////////