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

Annotation of /trunk/Src/wptCommonDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 150 - (hide annotations)
Wed Jan 18 11:52:45 2006 UTC (19 years, 1 month ago) by twoaday
File size: 5711 byte(s)
2006-01-18  Timo Schulz  <ts@g10code.com>
 
        * wptListview.cpp (listview_del_sel_items): Fixed index
        calculation. This fixed a lot of problems with the KM listview
        update.
        (listview_del_all): Renamed to...
        (listview_del_all_items): ..this. Changed all callers.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Just refresh
        list when file import contained new/updated keys.
        * wptKeyManager.cpp (km_file_import): Indicate if the
        import contained any new/update keys.
        * wptClipImportDlg.cpp (print_import_status): Just mark
        keys which actually changed.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26