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