1 |
twoaday |
2 |
/* wptCardManager.cpp |
2 |
twoaday |
26 |
* Copyright (C) 2003, 2005 Timo Schulz |
3 |
|
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
twoaday |
2 |
* |
5 |
|
|
* This file is part of WinPT. |
6 |
|
|
* |
7 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* WinPT is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <stdio.h> |
23 |
|
|
#include <windows.h> |
24 |
|
|
|
25 |
|
|
#include "wptTypes.h" |
26 |
|
|
#include "wptW32API.h" |
27 |
|
|
#include "wptVersion.h" |
28 |
|
|
#include "wptNLS.h" |
29 |
|
|
#include "wptGPG.h" |
30 |
|
|
#include "wptCard.h" |
31 |
|
|
#include "../resource.h" |
32 |
|
|
|
33 |
|
|
|
34 |
twoaday |
26 |
/* Dialog box procedure for the card callback. */ |
35 |
twoaday |
2 |
static BOOL CALLBACK |
36 |
twoaday |
26 |
card_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
37 |
twoaday |
2 |
{ |
38 |
|
|
static card_cb_s * ctx; |
39 |
|
|
|
40 |
|
|
switch( msg ) { |
41 |
|
|
case WM_INITDIALOG: |
42 |
|
|
ctx = (struct card_cb_s *)lparam; |
43 |
|
|
if( !ctx ) |
44 |
|
|
BUG( NULL ); |
45 |
twoaday |
26 |
switch (ctx->code) { |
46 |
twoaday |
28 |
case CARD_CTL_INSERT: |
47 |
twoaday |
26 |
ShowWindow (GetDlgItem (dlg, IDC_CCTRL_VAL), FALSE); |
48 |
|
|
SetDlgItemText (dlg, IDC_CCTRL_MSG, |
49 |
|
|
_("Please insert the OpenPGP smart card\n" |
50 |
|
|
"Press OK to continue or Cancel")); |
51 |
twoaday |
2 |
break; |
52 |
|
|
} |
53 |
twoaday |
26 |
center_window (dlg, NULL); |
54 |
|
|
SetForegroundWindow (dlg); |
55 |
twoaday |
2 |
break; |
56 |
|
|
|
57 |
|
|
case WM_COMMAND: |
58 |
twoaday |
26 |
switch (LOWORD (wparam)) { |
59 |
twoaday |
2 |
case IDOK: |
60 |
twoaday |
26 |
strcpy (ctx->val, "\r\n"); |
61 |
twoaday |
2 |
EndDialog( dlg, TRUE ); |
62 |
|
|
break; |
63 |
|
|
|
64 |
|
|
case IDCANCEL: |
65 |
twoaday |
26 |
strcpy (ctx->val, "c"); |
66 |
twoaday |
2 |
ctx->cancel = 1; |
67 |
twoaday |
26 |
EndDialog (dlg, FALSE); |
68 |
twoaday |
2 |
break; |
69 |
|
|
} |
70 |
|
|
break; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
return FALSE; |
74 |
twoaday |
26 |
} |
75 |
twoaday |
2 |
|
76 |
|
|
|
77 |
twoaday |
23 |
const char* |
78 |
twoaday |
26 |
card_callback (int code, void *opaque) |
79 |
twoaday |
2 |
{ |
80 |
twoaday |
23 |
struct card_cb_s *ctx = (struct card_cb_s *)opaque; |
81 |
twoaday |
2 |
|
82 |
twoaday |
23 |
if (!ctx) |
83 |
twoaday |
2 |
return NULL; |
84 |
|
|
|
85 |
twoaday |
23 |
if (!ctx->init) { |
86 |
twoaday |
26 |
memset (ctx->val, 0, sizeof (ctx->val)); |
87 |
twoaday |
2 |
ctx->code = code; |
88 |
twoaday |
26 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_CTRL, glob_hwnd, |
89 |
|
|
card_cb_dlg_proc, (LPARAM)ctx); |
90 |
twoaday |
2 |
ctx->init = 0; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
return ctx->val; |
94 |
twoaday |
26 |
} |