1 |
werner |
36 |
/* wptCommonDlg.cpp |
2 |
|
|
* Copyright (C) 2004, 2005 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
#ifdef HAVE_CONFIG_H |
21 |
|
|
#include <config.h> |
22 |
|
|
#endif |
23 |
|
|
|
24 |
|
|
#include <windows.h> |
25 |
|
|
|
26 |
werner |
47 |
#include "resource.h" |
27 |
werner |
36 |
|
28 |
|
|
#include "wptTypes.h" |
29 |
|
|
#include "wptW32API.h" |
30 |
|
|
#include "wptVersion.h" |
31 |
|
|
#include "wptGPG.h" |
32 |
|
|
#include "wptCommonCtl.h" |
33 |
|
|
#include "wptContext.h" |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
/* check if the given buf contains a valid URL. */ |
37 |
|
|
static int |
38 |
|
|
check_URL (const char *buf) |
39 |
|
|
{ |
40 |
|
|
/* XXX: be more strict */ |
41 |
|
|
if (!strchr (buf, ':')) |
42 |
|
|
return -1; |
43 |
|
|
if (!strstr (buf, "//")) |
44 |
|
|
return -1; |
45 |
|
|
return 0; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
static BOOL CALLBACK |
50 |
|
|
http_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
51 |
|
|
{ |
52 |
|
|
static struct URL_ctx_s * ctx; |
53 |
|
|
int n; |
54 |
|
|
|
55 |
|
|
switch (msg) { |
56 |
|
|
case WM_INITDIALOG: |
57 |
|
|
ctx = (struct URL_ctx_s*)lparam; |
58 |
|
|
if (!ctx) |
59 |
|
|
BUG (0); |
60 |
|
|
if (ctx->desc != NULL) |
61 |
|
|
SetWindowText (dlg, ctx->desc); |
62 |
|
|
if (ctx->title != NULL) |
63 |
|
|
SetDlgItemText (dlg, IDC_HTTP_TITLE, ctx->title); |
64 |
twoaday |
123 |
else |
65 |
|
|
SetDlgItemText (dlg, IDC_HTTP_TITLE, _("Enter URL to retrieve the public key")); |
66 |
|
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
67 |
|
|
SetWindowText (dlg, _("HTTP Key Import")); |
68 |
werner |
36 |
SetForegroundWindow (dlg); |
69 |
|
|
break; |
70 |
|
|
|
71 |
|
|
case WM_COMMAND: |
72 |
|
|
switch (LOWORD (wparam)) { |
73 |
|
|
case IDOK: |
74 |
|
|
n = GetDlgItemText (dlg, IDC_HTTP_URL, ctx->url, DIM (ctx->url)-1); |
75 |
|
|
if (ctx->check && (!n || check_URL (ctx->url))) { |
76 |
|
|
msg_box (dlg, _("Please enter a valid URL."), "HTTP", MB_ERR); |
77 |
|
|
return FALSE; |
78 |
|
|
} |
79 |
|
|
ctx->cancel = 0; |
80 |
|
|
EndDialog (dlg, TRUE); |
81 |
|
|
break; |
82 |
|
|
|
83 |
|
|
case IDCANCEL: |
84 |
|
|
ctx->cancel = 1; |
85 |
|
|
EndDialog (dlg, FALSE); |
86 |
|
|
break; |
87 |
|
|
} |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
return FALSE; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
/* Common dialog to request a URL from the user. |
95 |
|
|
Return value is the URL context. */ |
96 |
|
|
void* |
97 |
|
|
get_http_file_dlg (HWND root) |
98 |
|
|
{ |
99 |
|
|
struct URL_ctx_s *ctx; |
100 |
|
|
|
101 |
|
|
ctx = new URL_ctx_s; |
102 |
|
|
if (!ctx) |
103 |
|
|
BUG (0); |
104 |
|
|
memset (ctx, 0, sizeof *ctx); |
105 |
|
|
ctx->check = 1; |
106 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root, |
107 |
|
|
http_dlg_proc, (LPARAM)ctx); |
108 |
|
|
return ctx; |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
/* Wrapper to request a preferred keyserver from the user. |
112 |
|
|
Return value is the URL context. */ |
113 |
|
|
void* |
114 |
|
|
get_keyserver_URL_dlg (HWND root) |
115 |
|
|
{ |
116 |
|
|
struct URL_ctx_s *ctx; |
117 |
|
|
|
118 |
|
|
ctx = new URL_ctx_s; |
119 |
|
|
if (!ctx) |
120 |
|
|
BUG (0); |
121 |
|
|
memset (ctx, 0, sizeof *ctx); |
122 |
|
|
ctx->check = 1; |
123 |
|
|
ctx->desc = _("Key Edit"); |
124 |
|
|
ctx->title = _("Enter preferred keyserver URL"); |
125 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root, |
126 |
|
|
http_dlg_proc, (LPARAM)ctx); |
127 |
|
|
return ctx; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
|
131 |
|
|
/* Generic text input dialog. */ |
132 |
|
|
char* |
133 |
|
|
get_input_dialog (HWND root, const char *title, const char *desc) |
134 |
|
|
{ |
135 |
|
|
struct URL_ctx_s ctx; |
136 |
|
|
|
137 |
|
|
memset (&ctx, 0, sizeof (ctx)); |
138 |
|
|
ctx.title = title; |
139 |
|
|
ctx.desc = desc; |
140 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root, |
141 |
|
|
http_dlg_proc, (LPARAM)&ctx); |
142 |
|
|
if (ctx.cancel || strlen (ctx.url) == 0) |
143 |
|
|
return NULL; |
144 |
|
|
return m_strdup (ctx.url); |
145 |
|
|
} |