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

Annotation of /trunk/Src/wptCommonDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 3462 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 2 /* wptCommonDlg.cpp
2 twoaday 23 * Copyright (C) 2004, 2005 Timo Schulz
3 twoaday 2 *
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    
21     #include <windows.h>
22    
23     #include "../resource.h"
24    
25     #include "wptTypes.h"
26     #include "wptW32API.h"
27     #include "wptVersion.h"
28     #include "wptGPG.h"
29     #include "wptCommonCtl.h"
30     #include "wptContext.h"
31    
32    
33 twoaday 23 /* check if the given buf contains a valid URL. */
34 twoaday 20 static int
35     check_URL (const char *buf)
36     {
37     /* XXX: be more strict */
38     if (!strchr (buf, ':'))
39     return -1;
40     if (!strstr (buf, "//"))
41     return -1;
42     return 0;
43     }
44    
45    
46 twoaday 2 static BOOL CALLBACK
47 twoaday 20 http_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
48 twoaday 2 {
49 twoaday 20 static struct URL_ctx_s * ctx;
50 twoaday 22 int n;
51 twoaday 2
52     switch (msg) {
53     case WM_INITDIALOG:
54 twoaday 20 ctx = (struct URL_ctx_s*)lparam;
55 twoaday 2 if (!ctx)
56     BUG (0);
57 twoaday 20 if (ctx->desc != NULL)
58     SetWindowText (dlg, ctx->desc);
59     if (ctx->title != NULL)
60     SetDlgItemText (dlg, IDC_HTTP_TITLE, ctx->title);
61 twoaday 2 SetForegroundWindow (dlg);
62     break;
63    
64     case WM_COMMAND:
65     switch (LOWORD (wparam)) {
66     case IDOK:
67 twoaday 22 n = GetDlgItemText (dlg, IDC_HTTP_URL, ctx->url, DIM (ctx->url)-1);
68     if (ctx->check && (!n || check_URL (ctx->url))) {
69 twoaday 20 msg_box (dlg, _("Please enter a valid URL."), _("HTTP"), MB_ERR);
70 twoaday 2 return FALSE;
71     }
72     ctx->cancel = 0;
73     EndDialog (dlg, TRUE);
74     break;
75    
76     case IDCANCEL:
77     ctx->cancel = 1;
78     EndDialog (dlg, FALSE);
79     break;
80     }
81     }
82    
83     return FALSE;
84     }
85    
86    
87 twoaday 23 /* Common dialog to request a URL from the user.
88     Return value is the URL context. */
89 twoaday 20 void*
90 twoaday 2 get_http_file_dlg (HWND root)
91     {
92 twoaday 20 struct URL_ctx_s *ctx;
93 twoaday 2
94 twoaday 20 ctx = new URL_ctx_s;
95 twoaday 2 if (!ctx)
96     BUG (0);
97     memset (ctx, 0, sizeof *ctx);
98 twoaday 22 ctx->check = 1;
99 twoaday 2 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
100 twoaday 20 http_dlg_proc, (LPARAM)ctx);
101 twoaday 2 return ctx;
102     }
103 twoaday 20
104 twoaday 23 /* Wrapper to request a preferred keyserver from the user.
105     Return value is the URL context. */
106 twoaday 20 void*
107     get_keyserver_URL_dlg (HWND root)
108     {
109     struct URL_ctx_s *ctx;
110    
111     ctx = new URL_ctx_s;
112     if (!ctx)
113     BUG (0);
114     memset (ctx, 0, sizeof *ctx);
115 twoaday 22 ctx->check = 1;
116 twoaday 20 ctx->desc = "Key Edit";
117     ctx->title = "Enter preferred keyserver URL";
118     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
119     http_dlg_proc, (LPARAM)ctx);
120     return ctx;
121     }
122 twoaday 22
123    
124 twoaday 23 /* Generic text input dialog. */
125 twoaday 22 char*
126     get_input_dialog (HWND root, const char *title, const char *desc)
127     {
128     struct URL_ctx_s ctx;
129    
130     memset (&ctx, 0, sizeof (ctx));
131     ctx.title = title;
132     ctx.desc = desc;
133     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
134     http_dlg_proc, (LPARAM)&ctx);
135     if (ctx.cancel || strlen (ctx.url) == 0)
136     return NULL;
137     return m_strdup (ctx.url);
138     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26