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
|
////////////////////////////////////////////////////////////////////////////////
// Gadu-Gadu Plugin for Miranda IM
//
// Copyright (c) 2003-2006 Adam Strzelecki <ono+miranda@java.pl>
//
// 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 "gg.h"
#define MAX_LOADSTRING 100
#define HIMETRIC_INCH 2540
#define MAP_LOGHIM_TO_PIX(x,ppli) ( ((ppli)*(x) + HIMETRIC_INCH/2) / HIMETRIC_INCH )
////////////////////////////////////////////////////////////////////////////////
// User Util Dlg Page : Data
typedef struct _GGTOKENDLGDATA
{
int width;
int height;
char id[256];
char val[256];
HBITMAP hBitmap;
} GGTOKENDLGDATA;
INT_PTR CALLBACK gg_tokendlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
GGTOKENDLGDATA *dat = (GGTOKENDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg)
{
case WM_INITDIALOG:
{
RECT rc;
TranslateDialogDefault(hwndDlg);
GetClientRect(GetDlgItem(hwndDlg, IDC_WHITERECT), &rc);
InvalidateRect(hwndDlg, &rc, TRUE);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
{
GetDlgItemTextA(hwndDlg, IDC_TOKEN, dat->val, _countof(dat->val));
EndDialog(hwndDlg, IDOK);
break;
}
case IDCANCEL:
EndDialog(hwndDlg, IDCANCEL);
break;
}
break;
case WM_PAINT:
{
PAINTSTRUCT paintStruct;
HDC hdc = BeginPaint(hwndDlg, &paintStruct);
RECT rc;
GetClientRect(GetDlgItem(hwndDlg, IDC_WHITERECT), &rc);
FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
if (dat && dat->hBitmap)
{
HDC hdcBmp = nullptr;
BITMAP bmp;
GetObject(dat->hBitmap, sizeof(bmp), &bmp);
int nWidth = bmp.bmWidth;
int nHeight = bmp.bmHeight;
if (hdcBmp = CreateCompatibleDC(hdc))
{
SelectObject(hdcBmp, dat->hBitmap);
SetStretchBltMode(hdc, HALFTONE);
BitBlt(hdc,
(rc.left + rc.right - nWidth) / 2,
(rc.top + rc.bottom - nHeight) / 2,
nWidth, nHeight,
hdcBmp, 0, 0, SRCCOPY);
DeleteDC(hdcBmp);
}
}
EndPaint(hwndDlg, &paintStruct);
return 0;
}
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
// Gets GG token
//
int GaduProto::gettoken(GGTOKEN *token)
{
// Zero tokens
mir_strcpy(token->id, "");
mir_strcpy(token->val, "");
struct gg_http *h = gg_token(0);
if (!h || gg_token_watch_fd(h) || h->state == GG_STATE_ERROR || h->state != GG_STATE_DONE) {
wchar_t error[128];
mir_snwprintf(error, TranslateT("Token retrieval failed because of error:\n\t%s"), http_error_string(h ? h->error : 0));
MessageBox(nullptr, error, m_tszUserName, MB_OK | MB_ICONSTOP);
gg_free_pubdir(h);
return FALSE;
}
struct gg_token *t = (struct gg_token *)h->data;
if (!t || !h->body) {
wchar_t error[128];
mir_snwprintf(error, TranslateT("Token retrieval failed because of error:\n\t%s"), http_error_string(h->error));
MessageBox(nullptr, error, m_tszUserName, MB_OK | MB_ICONSTOP);
gg_free_pubdir(h);
return FALSE;
}
// Return token id
GGTOKENDLGDATA dat = { 0 };
strncpy(dat.id, t->tokenid, sizeof(dat.id));
dat.width = t->width;
dat.height = t->height;
// Load bitmap
dat.hBitmap = Image_LoadFromMem(h->body, h->body_size, FIF_UNKNOWN);
if (dat.hBitmap == nullptr) {
MessageBox(nullptr, TranslateT("Could not load token image."), m_tszUserName, MB_OK | MB_ICONSTOP);
gg_free_pubdir(h);
return FALSE;
}
// Load token dialog
if (DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_TOKEN), nullptr, gg_tokendlgproc, (LPARAM)&dat) == IDCANCEL)
return FALSE;
// Fillup patterns
strncpy(token->id, dat.id, sizeof(token->id));
strncpy(token->val, dat.val, sizeof(token->val));
return TRUE;
}
|