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

Annotation of /trunk/Src/wptKeyeditSetPrefDlg.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: 4516 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 2 /* wptKeyEditOwnertrustDlg.cpp - Key onwertrust dialog
2     * Copyright (C) 2003 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    
21     #include <windows.h>
22     #include <stdio.h>
23     #include "../resource.h"
24     #include "wptTypes.h"
25     #include "wptW32API.h"
26     #include "wptVersion.h"
27     #include "wptNLS.h"
28     #include "wptErrors.h"
29    
30     static const char * algos[] = {
31     "TWOFISH",
32     "AES256",
33     "AES192",
34     "AES",
35     "BLOWFISH",
36     "CAST5",
37     "3DES",
38     "MD5",
39     "SHA1",
40     "ZIP",
41     "ZLIB",
42     NULL
43     };
44    
45     #define MDC_FEATURE 0x01
46     #define KSNO_FLAG 0x02
47    
48    
49     struct prefs_cb_s {
50     char * p;
51     int flags;
52     };
53    
54     static void
55     load_listbox (HWND dlg)
56     {
57     HWND lb = GetDlgItem (dlg, IDC_SETPREF_PREFLIST);
58     const char * s;
59     int i;
60    
61     for (i=0; (s=algos[i]); i++)
62     listbox_add_string (lb, s);
63     }
64    
65    
66     static int
67     copy_listbox_entry (HWND dlg)
68     {
69     int idx=0, ctlid=0, rctlid=0;
70     char buf[256];
71    
72     if (listbox_get_cursel (GetDlgItem (dlg, IDC_SETPREF_PREFLIST)) != LB_ERR) {
73     ctlid = IDC_SETPREF_PREFLIST;
74     rctlid = IDC_SETPREF_LIST;
75     }
76     else {
77     ctlid = IDC_SETPREF_LIST;
78     rctlid = IDC_SETPREF_PREFLIST;
79     }
80     idx = listbox_get_cursel (GetDlgItem (dlg, ctlid));
81     if (idx == LB_ERR)
82     return -1;
83     SendDlgItemMessage (dlg, ctlid, LB_GETTEXT, (WPARAM)idx, (LPARAM)buf);
84     SendDlgItemMessage (dlg, ctlid, LB_DELETESTRING, (WPARAM)idx, 0);
85     SendDlgItemMessage (dlg, rctlid, LB_ADDSTRING, 0, (LPARAM)(const char *)buf);
86     return 0;
87     }
88    
89    
90     static int
91     return_pref_flags (HWND dlg)
92     {
93     int flags=0;
94    
95     if (IsDlgButtonChecked (dlg, IDC_SETPREF_MDC))
96     flags |= MDC_FEATURE;
97     if (IsDlgButtonChecked (dlg, IDC_SETPREF_KSNO))
98     flags |= KSNO_FLAG;
99     return flags;
100     }
101    
102    
103     static char *
104     mk_prefs_from_list (HWND dlg, int flags)
105     {
106     int i, nlist, n=0;
107     char * p, buf[32];
108    
109     nlist = SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETCOUNT, 0, 0);
110     if (!nlist) {
111     msg_box (dlg, _("There are no preferences in the list."),
112     _("Key Preferences"), MB_ERR);
113     return NULL;
114     }
115     for (i=0; i < nlist; i++)
116     n += SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETTEXTLEN, i, 0);
117     if (flags & MDC_FEATURE)
118     n += 4;
119     if (flags & KSNO_FLAG)
120     n += 10;
121     p = new char[n+2*nlist+1];
122     if (!p)
123     BUG (NULL);
124     memset (p, 0, n+2*nlist+1);
125     for (i=0; i < nlist; i++) {
126     SendDlgItemMessage (dlg, IDC_SETPREF_LIST, LB_GETTEXT, i, (LPARAM)(char *)buf);
127     strcat (p, buf);
128     strcat (p, " ");
129     }
130     if (flags & MDC_FEATURE)
131     strcat (p, "MDC");
132     if (flags & KSNO_FLAG) {
133     strcat (p, " ");
134     strcat (p, "NO-MODIFY");
135     }
136     return p;
137     }
138    
139    
140     BOOL CALLBACK
141     keyedit_setpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
142     {
143     static struct prefs_cb_s * cb;
144    
145     switch (msg) {
146     case WM_INITDIALOG:
147     cb = (struct prefs_cb_s *)lparam;
148     if (!cb)
149     BUG (NULL);
150     load_listbox (dlg);
151     CheckDlgButton (dlg, IDC_SETPREF_MDC, BST_CHECKED);
152 twoaday 23 center_window (dlg, NULL);
153 twoaday 2 SetForegroundWindow (dlg);
154     break;
155    
156     case WM_COMMAND:
157     switch (LOWORD (wparam)) {
158     case IDOK:
159     cb->flags = return_pref_flags (dlg);
160     cb->p = mk_prefs_from_list (dlg, cb->flags);
161     if (!cb->p)
162     return FALSE;
163     EndDialog (dlg, TRUE);
164     break;
165    
166     case IDCANCEL:
167     EndDialog (dlg, FALSE);
168     break;
169    
170     case IDC_SETPREF_UPDATE:
171     copy_listbox_entry (dlg);
172     break;
173     }
174     break;
175     }
176    
177     return FALSE;
178     }
179    
180    
181     void
182     get_userid_preflist (char ** r_prefs, int * r_flags)
183     {
184     struct prefs_cb_s cb;
185    
186     memset (&cb, 0, sizeof cb);
187     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SETPREF,
188     GetDesktopWindow (), keyedit_setpref_dlg_proc, (LPARAM)&cb);
189     *r_prefs = cb.p;
190     *r_flags = cb.flags;
191     }
192    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26