/[winpt]/trunk/Src/wptCommonDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptCommonDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 181 - (hide annotations)
Tue Mar 14 11:01:22 2006 UTC (18 years, 11 months ago) by twoaday
File size: 5962 byte(s)
2006-03-12  Timo Schulz  <ts@g10code.de>
 
        * wptGPG.cpp (gnupg_load_config): Search for 'ask-cert-expire'.
        * wptKeyPropsDlg.cpp (display_key_info): Automatically update
        sym algorithm preferences if needed.
        * wptKeysignDlg.cpp (date_is_today): New.
        (keysign_dlg_proc): Only allow to set cert expire date if
        the option was found.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Allow to set
        'ask-cert-expire'.
         


1 werner 36 /* wptCommonDlg.cpp
2 twoaday 181 * Copyright (C) 2004, 2005, 2006 Timo Schulz
3 werner 36 *
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 twoaday 181 #include <ctype.h>
26 werner 36
27 werner 47 #include "resource.h"
28 werner 36
29     #include "wptTypes.h"
30     #include "wptW32API.h"
31     #include "wptVersion.h"
32     #include "wptGPG.h"
33     #include "wptCommonCtl.h"
34     #include "wptContext.h"
35    
36    
37     /* check if the given buf contains a valid URL. */
38     static int
39     check_URL (const char *buf)
40     {
41 twoaday 181 size_t i;
42     const char *allowed = "-./#_:";
43    
44     if (strncmp (buf, "http://", 7))
45     return -1;
46 werner 36 if (!strchr (buf, ':'))
47     return -1;
48     if (!strstr (buf, "//"))
49     return -1;
50 twoaday 181 if (strstr (buf, " "))
51     return -1;
52     buf += 7;
53     for (i=0; i < strlen (buf); i++) {
54     if (isalpha (buf[i]) || isdigit (buf[i]))
55     continue;
56     if (!strchr (allowed, buf[i]))
57     return -1;
58     }
59    
60 werner 36 return 0;
61     }
62    
63    
64     static BOOL CALLBACK
65     http_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
66     {
67     static struct URL_ctx_s * ctx;
68     int n;
69    
70     switch (msg) {
71     case WM_INITDIALOG:
72     ctx = (struct URL_ctx_s*)lparam;
73     if (!ctx)
74     BUG (0);
75     if (ctx->desc != NULL)
76     SetWindowText (dlg, ctx->desc);
77     if (ctx->title != NULL)
78     SetDlgItemText (dlg, IDC_HTTP_TITLE, ctx->title);
79 twoaday 123 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
80 werner 36 SetForegroundWindow (dlg);
81     break;
82    
83     case WM_COMMAND:
84     switch (LOWORD (wparam)) {
85     case IDOK:
86     n = GetDlgItemText (dlg, IDC_HTTP_URL, ctx->url, DIM (ctx->url)-1);
87     if (ctx->check && (!n || check_URL (ctx->url))) {
88     msg_box (dlg, _("Please enter a valid URL."), "HTTP", MB_ERR);
89     return FALSE;
90     }
91     ctx->cancel = 0;
92     EndDialog (dlg, TRUE);
93     break;
94    
95     case IDCANCEL:
96     ctx->cancel = 1;
97     EndDialog (dlg, FALSE);
98     break;
99     }
100     }
101    
102     return FALSE;
103     }
104    
105    
106     /* Common dialog to request a URL from the user.
107     Return value is the URL context. */
108     void*
109     get_http_file_dlg (HWND root)
110     {
111     struct URL_ctx_s *ctx;
112    
113     ctx = new URL_ctx_s;
114     if (!ctx)
115     BUG (0);
116     memset (ctx, 0, sizeof *ctx);
117 twoaday 181 ctx->check = 1;
118     ctx->desc = _("HTTP Key Import");
119     ctx->title = _("Enter URL to retrieve the public key");
120 werner 36 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
121     http_dlg_proc, (LPARAM)ctx);
122     return ctx;
123     }
124    
125     /* Wrapper to request a preferred keyserver from the user.
126     Return value is the URL context. */
127     void*
128     get_keyserver_URL_dlg (HWND root)
129     {
130     struct URL_ctx_s *ctx;
131    
132     ctx = new URL_ctx_s;
133     if (!ctx)
134     BUG (0);
135     memset (ctx, 0, sizeof *ctx);
136     ctx->check = 1;
137     ctx->desc = _("Key Edit");
138     ctx->title = _("Enter preferred keyserver URL");
139     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
140     http_dlg_proc, (LPARAM)ctx);
141     return ctx;
142     }
143    
144    
145     /* Generic text input dialog. */
146     char*
147     get_input_dialog (HWND root, const char *title, const char *desc)
148     {
149     struct URL_ctx_s ctx;
150    
151     memset (&ctx, 0, sizeof (ctx));
152     ctx.title = title;
153     ctx.desc = desc;
154     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
155     http_dlg_proc, (LPARAM)&ctx);
156     if (ctx.cancel || strlen (ctx.url) == 0)
157     return NULL;
158     return m_strdup (ctx.url);
159     }
160 twoaday 150
161     #if 0
162     struct infodlg_s {
163     const char *title;
164     const char *button_1;
165     const char *button_2;
166     const char *text;
167     HICON ico;
168     int retval;
169     };
170    
171     /* Dialog box procedure for the info dialog. */
172     static BOOL CALLBACK
173     infodlg_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
174     {
175     static struct infodlg_s *ctx;
176    
177     switch (msg) {
178     case WM_INITDIALOG:
179     ctx = (struct infodlg_s *)lparam;
180     if (!ctx)
181     EndDialog (dlg, FALSE);
182     if (ctx->title)
183     SetWindowText (dlg, ctx->title);
184     if (ctx->text)
185     SetDlgItemText (dlg, IDC_INFODLG_TEXT, ctx->text);
186     if (ctx->button_1)
187     SetDlgItemText (dlg, IDOK, ctx->button_1);
188     if (ctx->button_2)
189     SetDlgItemText (dlg, IDCANCEL, ctx->button_2);
190     if (ctx->ico != NULL) {
191     SendMessage (GetDlgItem (dlg, IDC_INFODLG_ICO), STM_SETICON,
192     (WPARAM)(HICON)ctx->ico, 0);
193     }
194     SetForegroundWindow (dlg);
195     return TRUE;
196    
197     case WM_COMMAND:
198     switch (LOWORD (wparam)) {
199     case IDOK:
200     ctx->retval = IDOK;
201     EndDialog (dlg, TRUE);
202     break;
203    
204     case IDCANCEL:
205     ctx->retval = IDCANCEL;
206     EndDialog (dlg, FALSE);
207     break;
208     }
209     break;
210     }
211     return FALSE;
212     }
213    
214    
215     int
216     InfoBox (HWND hwnd, LPCTSTR text, LPCTSTR title, UINT type)
217     {
218     struct infodlg_s inf;
219    
220     memset (&inf, 0, sizeof (inf));
221     inf.text = text;
222     inf.title = title;
223     if (type & MB_YESNO) {
224     inf.button_1 = _("Yes");
225     inf.button_2 = _("No");
226     }
227     else {
228     inf.button_1 = _("OK");
229     inf.button_2 = _("Cancel");
230     }
231     if (type & MB_ICONERROR)
232     inf.ico = LoadIcon (NULL, IDI_ERROR);
233     else if (type & MB_ICONWARNING)
234     inf.ico = LoadIcon (NULL, IDI_EXCLAMATION);
235     else if (type & MB_ICONINFORMATION)
236     inf.ico = LoadIcon (NULL, IDI_INFORMATION);
237     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_INFODLG, hwnd,
238     infodlg_dlg_proc, (LPARAM)&inf);
239     return inf.retval;
240     }
241    
242    
243     int
244     InfoBoxEx (HWND hwnd, LPCTSTR text, LPCTSTR title, UINT type, ...)
245     {
246     va_list arg_ptr;
247     char buf[2048];
248     int id;
249    
250     va_start (arg_ptr, type);
251     _vsnprintf (buf, sizeof (buf)-1, text, arg_ptr);
252     id = InfoBox (hwnd, buf, title, type);
253     va_end (arg_ptr);
254     return id;
255     }
256     #endif
257    

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26