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

Diff of /trunk/Src/wptKeyManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by twoaday, Wed Oct 12 10:04:26 2005 UTC revision 217 by twoaday, Mon May 22 14:21:39 2006 UTC
# Line 1  Line 1 
1  /* wptKeyManagerDlg.cpp - WinPT Key Manager  /* wptKeyManagerDlg.cpp - WinPT Key Manager
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 Timo Schulz
3   *      Copyright (C) 2004 Andreas Jobs   *      Copyright (C) 2004 Andreas Jobs
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
7   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
8   * 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
9   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.   * (at your option) any later version.
11   *   *
12   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.   * GNU General Public License for more details.
16   *   *
17   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20   */   */
21    #ifdef HAVE_CONFIG_H
22  #include <windows.h>  #include <config.h>
23  #include <commctrl.h>  #endif
24    
25  #include "../resource.h"  #include <windows.h>
26  #include "wptTypes.h"  #include <commctrl.h>
27  #include "wptGPG.h"  
28  #include "wptCommonCtl.h"  #include "resource.h"
29  #include "wptContext.h" /* for passphrase_s */  #include "wptTypes.h"
30  #include "wptDlgs.h"  #include "wptGPG.h"
31  #include "wptW32API.h"  #include "wptCommonCtl.h"
32  #include "wptVersion.h"  #include "wptContext.h" /* for passphrase_s */
33  #include "wptKeylist.h"  #include "wptDlgs.h"
34  #include "wptNLS.h"  #include "wptW32API.h"
35  #include "wptErrors.h"  #include "wptVersion.h"
36  #include "wptHotkey.h"  #include "wptKeylist.h"
37  #include "wptKeyManager.h"  #include "wptNLS.h"
38  #include "wptKeyserver.h"  #include "wptErrors.h"
39  #include "wptKeyEdit.h"  #include "wptHotkey.h"
40  #include "wptRegistry.h"  #include "wptKeyManager.h"
41    #include "wptKeyserver.h"
42  #define KM_SEPARATOR_ID                10000  #include "wptKeyEdit.h"
43  #define WINDOWCLASS_SEPARATOR_CHILD "WINPT_SEP_CHILD"  #include "wptRegistry.h"
44  //#define KM_SEPARATOR_HEIGHT            5  #include "wptUTF8.h"
45    
46    /* Name and ID of the separator window. */
47  static subclass_s keylist_proc;  #define KM_SEPARATOR_ID                 10000
48  static int km_index = -1;  #define WINDOWCLASS_SEPARATOR_CHILD     "WINPT_SEP_CHILD"
49    
50  HIMAGELIST glob_imagelist;  /* Virtual key codes. */
51    #ifndef VK_F
52  struct km_info {  #define VK_F 70
53      /* Window positions */  #endif
54      int pos_x, pos_y;  #ifndef VK_A
55      int ypos_sep;  #define VK_A 65
56      int ypercent_sep;  #endif
57    #ifndef VK_C
58      HWND hwnd_sep;  #define VK_C 67
59      HWND toolbar;  #endif
60      HWND statbar;  #ifndef VK_P
61    #define VK_P 80
62      listview_ctrl_t lv;  #endif
63      int keylist_sortby;  
64  };  static subclass_s keylist_proc;
65    
66  struct mybuttons {  /* Handle to the global image list. */
67      long icon;  HIMAGELIST glob_imagelist;
68      long command;  
69      char *text;  struct km_info_s {
70  };      /* Window positions */
71        int pos_x, pos_y;
72  struct mybuttons myb[] = {      int ypos_sep;
73      {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},      int ypercent_sep;
74      {IMI_KEY_PROPS,  ID_KEYMISC_PROPS,  "Properties"},  
75      {IMI_KEY_SIGN,   ID_KEYMISC_SIGN,   "Sign"},      /* Different kind of windows. */
76      {IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"},      HWND dlg;
77      {IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"},      HWND hwnd_sep;
78  };      HWND toolbar;
79        HWND statbar;
80    
81  #ifndef VK_F      listview_ctrl_t lv;
82  #define VK_F 70      int             lv_idx;
83  #endif      int keylist_sortby;
84  #ifndef VK_A      int magic;
85  #define VK_A 65  
86  #endif      unsigned int enable_groups:1;
87  #ifndef VK_C  };
88  #define VK_C 67  
89  #endif  /* Toolbar button structure. */
90  #ifndef VK_P  struct mybuttons {
91  #define VK_P 80      long icon;
92  #endif      long command;
93        char *text;
94  static BOOL CALLBACK  };
95  keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
96  {  struct mybuttons myb[] = {
97      struct listview_ctrl_s lv;      {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},
98        {IMI_KEY_PROPS,  ID_KEYMISC_PROPS,  "Properties"},
99      switch (msg) {      {IMI_KEY_SIGN,   ID_KEYMISC_SIGN,   "Sign"},
100      case WM_LBUTTONDBLCLK:      {IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"},
101          send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);      {IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"},
102          break;  };
103            
104      case WM_KEYUP:  
105          int virt_key = (int)wparam;  static void km_gui_import (struct km_info_s *kmi, int cmd_id, void *param);
106          switch (virt_key) {  
107          case VK_SPACE:  
108              send_cmd_id( keylist_proc.dlg, ID_KEYMISC_PROPS );  /* Subclass the keylist listview control to allow extended commands. */
109              break;  static BOOL CALLBACK
110            keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
111          case VK_DELETE:  {
112              send_cmd_id( keylist_proc.dlg, ID_KEYMISC_DELETE );      struct listview_ctrl_s lv;
113              break;      struct km_info_s *kmi;
114            
115          case VK_INSERT:      switch (msg) {
116              send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);      case WM_DROPFILES:
117              break;          kmi = (km_info_s *)keylist_proc.opaque;
118            km_gui_import (kmi, WM_DROPFILES, (void*)wparam);
119          case VK_A:          break;
120              if (GetAsyncKeyState (VK_CONTROL)) {  
121                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);      case WM_LBUTTONDBLCLK:
122                  listview_select_all (&lv);          send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
123              }          break;
124              break;          
125                    case WM_KEYUP:
126          case VK_C:          int virt_key = (int)wparam;
127              if (GetAsyncKeyState (VK_CONTROL)) {          switch (virt_key) {
128                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);          case VK_SPACE:
129                  km_index = listview_get_curr_pos (&lv);              send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
130                  km_clip_export (keylist_proc.dlg, &lv);              break;
131              }          
132              break;          case VK_DELETE:
133                send_cmd_id (keylist_proc.dlg, ID_KEYMISC_DELETE);
134          case VK_P:              break;
135              if (GetAsyncKeyState (VK_CONTROL)) {          
136                  km_index = -1;          case VK_INSERT:
137                  km_clip_import (keylist_proc.dlg);              send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
138              }              break;
139              break;  
140            case VK_A:
141          case VK_F:              if (GetAsyncKeyState (VK_CONTROL)) {
142              if (GetAsyncKeyState (VK_CONTROL)) {                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
143                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);                  listview_select_all (&lv);
144                  km_find_key (dlg, &lv);              }
145              }              break;
146              break;              
147          }          case VK_C:
148          break;              if (GetAsyncKeyState (VK_CONTROL)) {
149      }                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
150                        km_clip_export (keylist_proc.dlg, &lv);
151      return CallWindowProc( keylist_proc.old, dlg, msg, wparam, lparam );              }
152  } /* keylist_subclass_proc */              break;
153    
154            case VK_P:
155  static HWND              if (GetAsyncKeyState (VK_CONTROL))
156  load_toolbar (HWND dlg, struct km_info * kmi)                  send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
157  {              break;
158      HWND tbwnd;  
159      TBSAVEPARAMS tbsp;          case VK_F:
160      TBBUTTON tb_buttons[] = {              if (GetAsyncKeyState (VK_CONTROL)) {
161          /*{imagelist_getindex(IMI_EXIT),       ID_KEYMISC_QUIT,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0L, 0},*/                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
162          {imagelist_getindex(IMI_KEY_DELETE), ID_KEYMISC_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},                  km_find_key (dlg, &lv);
163          {imagelist_getindex(IMI_KEY_PROPS),  ID_KEYMISC_PROPS,  TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},              }
164          {imagelist_getindex(IMI_KEY_SIGN),   ID_KEYMISC_SIGN,   TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},              break;
165          {0,                                  0,                 0,               TBSTYLE_SEP,    {0}, 0L, 0},          }
166          {imagelist_getindex(IMI_KEY_IMPORT), ID_KEYMISC_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},          break;
167          {imagelist_getindex(IMI_KEY_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},      }
168       };      
169            return CallWindowProc (keylist_proc.old, dlg, msg, wparam, lparam);
170      tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,  }
171                              WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,  
172                              0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);  
173      if (tbwnd) {  #define ico2idx(ico) imagelist_getindex((ico))
174          SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);  
175          SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);  static HWND
176                  SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);  load_toolbar (HWND dlg, struct km_info_s *kmi)
177          ShowWindow (tbwnd, SW_SHOW);  {
178        HWND tbwnd;
179          /* Restore toolbar */      TBSAVEPARAMS tbsp;
180          tbsp.hkr = HKEY_CURRENT_USER;      TBBUTTON tb_buttons[] = {
181          tbsp.pszSubKey = "Software\\WinPT";          {ico2idx (IMI_KEY_NEW),    ID_KEYMISC_KEYWIZARD, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L},
182          tbsp.pszValueName = "KM_toolbar";          {ico2idx (IMI_KEY_DELETE), ID_KEYMISC_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
183          if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0)          {ico2idx (IMI_KEY_PROPS),  ID_KEYMISC_PROPS,  TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
184              SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]), (LONG)&tb_buttons[0]);          {ico2idx (IMI_KEY_SIGN),   ID_KEYMISC_SIGN,   TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
185       }          {ico2idx (IMI_KEY_SEARCH), ID_KEYMISC_SENDRECV, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
186       return tbwnd;          {0,                                  0,                 0,               TBSTYLE_SEP,    {0}, 0L, 0},
187  } /* load_toolbar */          {ico2idx (IMI_KEY_FILE_IMPORT), ID_KEYMISC_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
188            {ico2idx (IMI_KEY_FILE_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
189            {ico2idx (IMI_KEY_IMPORT), ID_KEYCTX_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
190  static void          {ico2idx (IMI_KEY_EXPORT), ID_KEYCTX_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
191  do_center_window (HWND dlg, struct km_info * kmi)       };
192  {      
193      RECT rect;      tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,
194      char * p;                              WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,
195      int pos_x = 0, pos_y = 0;                              0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);
196                if (tbwnd) {
197      /* Find bottom of keylist */          SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
198      GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);          SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);
199      MapWindowPoints (NULL, dlg, (POINT*)&rect, 2);                  SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);
200            ShowWindow (tbwnd, SW_SHOW);
201      kmi->ypos_sep = rect.bottom;  
202            /* Restore toolbar */
203      p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X" );          tbsp.hkr = HKEY_CURRENT_USER;
204      if( p && !strcmp( p, " " ) ) {          tbsp.pszSubKey = "Software\\WinPT";
205          free_if_alloc( p );              tbsp.pszValueName = "KM_toolbar";
206          center_window( dlg, NULL );          if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0)
207          return;              SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]),
208      }                           (LONG)&tb_buttons[0]);
209      else if( p )       }
210          pos_x = atol( p );       return tbwnd;
211    }
212      p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y" );  
213      if( p && !strcmp( p, " " ) ) {  
214          free_if_alloc( p );  /* Restore the width of the columns from the registry.
215          center_window( dlg, NULL );     If no bitstring was found, the default size is used. */
216          return;  int
217      }  restore_column_info (struct km_info_s *kmi)
218      else if( p )  {
219          pos_y = atol( p );      WORD *buf;
220        HKEY root;
221      if( !pos_y && !pos_x ) {      DWORD type;
222          center_window( dlg, NULL );      DWORD size = kmi->lv->cols*sizeof (WORD), i;
223          return;      LONG ec;
224      }  
225            ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
226      if( pos_x > GetSystemMetrics( SM_CXSCREEN )                         KEY_ALL_ACCESS, &root);
227          || pos_y > GetSystemMetrics( SM_CYSCREEN ) ) {      if (ec != ERROR_SUCCESS)
228          pos_x = pos_y = 0;          return -1;
229      }  
230      GetClientRect( dlg, &rect );      buf = new WORD[size/2];
231      MoveWindow( dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE );      if (!buf)
232  }          BUG (NULL);
233        ec = RegQueryValueEx (root, "KMColumnSize", NULL, &type,
234                              (BYTE*)buf, &size);    
235  static void      if (ec != ERROR_SUCCESS) {
236  do_resize_window( HWND dlg, struct km_info *kmi)          RegCloseKey (root);
237  {          free_if_alloc (buf);
238      HWND h;          return -1;
239      RECT rclient, rect;      }
240      BOOL bRepaint = FALSE;  
241        /* check for garbled values. */
242      /* Get rect of client area and make life easier */      for (i=0; i < size/2; i++) {
243      GetClientRect( dlg, &rclient );          if (buf[i] == 0 || buf[i] > 512) {
244                free_if_alloc (buf);
245      /* Move toolbar to the top of the window */              return -1;
246      if (kmi->toolbar) {          }
247          GetWindowRect(kmi->toolbar, &rect);      }
248          ScreenToClient(dlg, (POINT*)&rect);      for (i=0; i < size/2; i++)
249          ScreenToClient(dlg, (POINT*)&(rect.right));          listview_set_column_width (kmi->lv, i, buf[i]);
250        free_if_alloc (buf);
251          rclient.top += rect.bottom - rect.top;  
252          MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left,      size = sizeof (kmi->keylist_sortby);
253                      rect.bottom - rect.top, bRepaint);      ec = RegQueryValueEx (root, "KMSortBy", NULL, &type,
254      }                            (BYTE*)&kmi->keylist_sortby, &size);
255        if (ec != ERROR_SUCCESS)
256      /* Move statusbar to the bottom of the window */          kmi->keylist_sortby = KEY_SORT_USERID;
257      if (kmi->statbar) {      RegCloseKey (root);
258          GetWindowRect( kmi->statbar, &rect );      return 0;
259          ScreenToClient(dlg, (POINT*)&rect);  }
260          ScreenToClient(dlg, (POINT*)&(rect.right));  
261    
262          rclient.bottom -= rect.bottom - rect.top;  /* Save the current column width to the registry. */
263          MoveWindow (kmi->statbar, 0, rclient.bottom, rclient.right - rclient.left,  int
264                      rect.bottom - rect.top, bRepaint);  save_column_info (struct km_info_s *kmi)
265      }  {    
266        HKEY root;
267      // Obtain separator information and move it to the desired posistion      WORD *buf;
268      if (kmi->ypercent_sep)      LONG ec;
269          kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100;      int i;
270      else  
271          kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top);      buf = new WORD[kmi->lv->cols];
272                if (!buf)
273      // Don't move away          BUG (NULL);
274      if (kmi->ypos_sep+5 > rclient.bottom)      for (i=0; i < kmi->lv->cols; i++) {
275          kmi->ypos_sep = rclient.bottom - 5;          LVCOLUMN lvc;
276      if (kmi->ypos_sep < rclient.top)  
277          kmi->ypos_sep = rclient.top;          memset (&lvc, 0, sizeof (lvc));
278      MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep, (rclient.right - rclient.left), 5, bRepaint);          lvc.mask = LVCF_WIDTH;
279                    ListView_GetColumn (kmi->lv->ctrl, i, &lvc);
280      // Place the keylist above the separator          buf[i] = lvc.cx;
281      h = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST );      }
282      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,  
283                  kmi->ypos_sep - rclient.top, bRepaint);      ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
284      rclient.top = kmi->ypos_sep + 5 + 8;                         KEY_ALL_ACCESS, &root);
285        if (ec != ERROR_SUCCESS) {
286      /* Place the group text and the group box below the separator */          free_if_alloc (buf);
287      h = GetDlgItem( dlg, IDC_KEYMISC_GTEXT );          return -1;
288      MoveWindow( h, rclient.left, rclient.top, 100, 14, bRepaint);      }
289      rclient.top += 18;  
290        ec = RegSetValueEx (root, "KMColumnSize", 0, REG_BINARY,
291      h = GetDlgItem( dlg, IDC_KEYMISC_GROUP );                          (const BYTE*)buf, 2*kmi->lv->cols);
292      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,      if (ec == ERROR_SUCCESS) {
293                  (rclient.bottom < rclient.top) ? 0 : rclient.bottom - rclient.top, bRepaint);          ec = RegSetValueEx (root, "KMSortBy", 0, REG_DWORD_BIG_ENDIAN,
294                                    (const BYTE*)&kmi->keylist_sortby,
295      /* Repaint the whole thing */                              sizeof (kmi->keylist_sortby));
296      InvalidateRect (dlg, NULL, TRUE);      }
297  } /* do_resize_window */      RegCloseKey (root);
298        free_if_alloc (buf);
299        return ec == ERROR_SUCCESS? 0 : -1;
300  static void  }
301  do_create_minpopup (HWND dlg)  
302  {  
303      HMENU hm;  /* Center window @dlg. */
304      MENUITEMINFO mi;  static void
305      char * s;  do_center_window (HWND dlg, struct km_info_s *kmi)
306      POINT p;  {
307            RECT rect;
308      if (gpg_read_only)      char *p;
309          return;      int pos_x = 0;
310      hm = CreatePopupMenu ();      int pos_y = 0;
311      if (!hm)          
312          BUG( NULL );      /* Find bottom of keylist */
313      memset (&mi, 0, sizeof mi);      GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);
314      mi.cbSize = sizeof mi;      MapWindowPoints (NULL, dlg, (POINT*)&rect, 2);
315      s = (char *)_("Paste Key from Clipboard");  
316      mi.fType = MF_STRING;      kmi->ypos_sep = rect.bottom;
317      mi.dwTypeData = s;  
318      mi.cch = strlen (s);      p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X");
319      mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;      if (p && !strcmp (p, " ")) {
320      mi.wID = ID_KEYCTX_PASTE;          free_if_alloc (p);      
321      InsertMenuItem (hm, 0, FALSE, &mi);          center_window (dlg, NULL);
322      GetCursorPos (&p);          return;
323      TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);      }
324      DestroyMenu (hm);      else if (p)
325  } /* do_create_minpopup */          pos_x = atol (p);
326    
327        p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y");
328  static void      if (p && !strcmp (p, " ")) {
329  do_check_cache (listview_ctrl_t lv, HWND dlg, HWND sb)          free_if_alloc (p);
330  {          center_window (dlg, NULL);
331      gpg_keycache_t cache;          return;
332        }
333      if( keycache_get_reload( ) ) {      else if (p)
334          keycache_reload( dlg );          pos_y = atol (p);
335          keycache_set_reload( 0 );  
336          cache = keycache_get_ctx( 1 );      if (!pos_y && !pos_x) {
337          if( !cache )          center_window (dlg, NULL);
338              BUG( dlg );          return;
339          keylist_reload( lv, cache, KEYLIST_LIST, KEY_SORT_USERID );      }
340          km_complete_status_bar (sb, lv);      
341      }      if (pos_x < 0 || pos_y < 0)
342  } /* do_check_cache */          pos_x = pos_y = 0;
343        if (pos_x > GetSystemMetrics (SM_CXSCREEN)
344            || pos_y > GetSystemMetrics (SM_CYSCREEN)) {
345  long CALLBACK          pos_x = pos_y = 0;
346  separator_wnd_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )      }
347  {      GetClientRect (dlg, &rect);
348      static POINT last_mouse_pos;      MoveWindow (dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE);
349    }
350      if (msg == WM_CREATE)  
351          SetWindowLong (hwnd, GWL_USERDATA, (long)(((CREATESTRUCT*)lparam)->lpCreateParams));  
352    /* Resize the key manager window with the information from @kmi. */
353      switch (msg) {  static void
354      case WM_PAINT:  do_resize_window (HWND dlg, struct km_info_s *kmi)
355          PAINTSTRUCT ps;  {
356          RECT rect;      HWND h;
357          HPEN hpen;      RECT rclient, rect;
358        BOOL bRepaint = FALSE;
359          GetClientRect (hwnd, &rect);  
360          BeginPaint (hwnd, &ps);      /* Get rect of client area and make life easier */
361        GetClientRect (dlg, &rclient);
362          // Background  
363          FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));      /* Move toolbar to the top of the window */
364        if (kmi->toolbar) {
365          // The lines from the light into the dark          GetWindowRect (kmi->toolbar, &rect);
366          MoveToEx(ps.hdc, 0,0, NULL);          ScreenToClient (dlg, (POINT*)&rect);
367          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT))) != NULL) {          ScreenToClient (dlg, (POINT*)&(rect.right));
368              SelectObject(ps.hdc, (LPVOID)hpen);  
369              LineTo(ps.hdc, rect.right, 0);          rclient.top += rect.bottom - rect.top;
370              DeleteObject(hpen);          MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left,
371          }                      rect.bottom - rect.top, bRepaint);
372          MoveToEx(ps.hdc, 0, 1, NULL);      }
373          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) {  
374               SelectObject(ps.hdc, (LPVOID)hpen);      /* Move statusbar to the bottom of the window */
375               LineTo(ps.hdc, rect.right, rect.bottom);      if (kmi->statbar) {
376               DeleteObject(hpen);          GetWindowRect (kmi->statbar, &rect);
377           }          ScreenToClient (dlg, (POINT*)&rect);
378            ScreenToClient (dlg, (POINT*)&(rect.right));
379          MoveToEx(ps.hdc, 0, rect.bottom-1, NULL);  
380          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) {          rclient.bottom -= rect.bottom - rect.top;
381              SelectObject(ps.hdc, (LPVOID)hpen);          MoveWindow (kmi->statbar, 0, rclient.bottom,
382              LineTo(ps.hdc, rect.right, rect.bottom-1);                      rclient.right - rclient.left,
383              DeleteObject(hpen);                      rect.bottom - rect.top, bRepaint);
384          }      }
385          MoveToEx(ps.hdc, 0, rect.bottom, NULL);  
386          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) {      /* Obtain separator information and move it to the desired posistion */
387              SelectObject(ps.hdc, (LPVOID)hpen);      if (kmi->ypercent_sep)
388              LineTo(ps.hdc, rect.right, rect.bottom);          kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100;
389              DeleteObject(hpen);      else
390          }          kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top);
391            
392          EndPaint (hwnd, &ps);      /* Don't move away */
393          return 0;      if (kmi->ypos_sep+5 > rclient.bottom)
394            kmi->ypos_sep = rclient.bottom - 5;
395      case WM_LBUTTONDOWN:      if (kmi->ypos_sep < rclient.top)
396          last_mouse_pos.x = LOWORD(lparam);          kmi->ypos_sep = rclient.top;
397          last_mouse_pos.y = HIWORD(lparam);      MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep,
398          ClientToScreen (hwnd, &last_mouse_pos);                  (rclient.right - rclient.left), 5, bRepaint);
399          SetCapture (hwnd);          
400          return 0;      /* Place the keylist above the separator */
401        h = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
402      case WM_LBUTTONUP:      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,
403          ReleaseCapture ();                  kmi->ypos_sep - rclient.top, bRepaint);
404          return 0;      rclient.top = kmi->ypos_sep + 5 + 8;
405    
406      case WM_MOUSEMOVE:      if (kmi->enable_groups != 0) {
407          if (wparam == MK_LBUTTON) {          /* Place the group text and the group box below the separator */
408              struct km_info *kmi;          h = GetDlgItem (dlg, IDC_KEYMISC_GTEXT);
409              POINT p;          MoveWindow (h, rclient.left, rclient.top, 100, 14, bRepaint);
410              RECT rect;          rclient.top += 18;
411    
412              if ((kmi = (struct km_info *)GetWindowLong (hwnd, GWL_USERDATA)) == NULL)          h = GetDlgItem (dlg, IDC_KEYMISC_GROUP);
413                  break;          MoveWindow (h, rclient.left, rclient.top,
414                        rclient.right - rclient.left,
415              // Calculate mouse movement                      (rclient.bottom < rclient.top) ?
416              p.x = LOWORD(lparam);                      0 : rclient.bottom - rclient.top, bRepaint);
417              p.y = HIWORD(lparam);      }
418              ClientToScreen (hwnd, &p);      
419        /* Repaint the whole thing */
420              GetWindowRect (hwnd, &rect);      InvalidateRect (dlg, NULL, TRUE);
421              rect.top += (short)(p.y - last_mouse_pos.y);  }
422              rect.bottom += (short)(p.y - last_mouse_pos.y);  
423    
424              last_mouse_pos.y = p.y;  /* Return true if the clipboard contains an OpenPGP key. */
425    static bool
426              // Apply mouse movement to window. Beware the MoveWindow is relaive  clip_contains_pgpkey (void)
427              // to parent NOT screen  {
428              MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&rect, 2);      char *ctxt;
429              kmi->ypos_sep = rect.top;      bool val = false;
430              kmi->ypercent_sep = 0; // This forces do_resize_window to use abs. position  
431              do_resize_window (GetParent(hwnd), kmi);      ctxt = get_clip_text (NULL);
432              return 0;      if (!ctxt || strlen (ctxt) < 512)
433          }          val = false;
434      }      else if (strstr (ctxt, "BEGIN PGP") && strstr (ctxt, "KEY BLOCK") &&
435                 strstr (ctxt, "END PGP"))
436      return DefWindowProc (hwnd, msg, wparam, lparam);          val = true;
437  }      free_if_alloc (ctxt);
438        return val;
439    }
440  static HWND  
441  regist_sep_wnd (HWND dlg, struct km_info * kmi)  
442  {  /* Show a mini popup menu to import keys. */
443      WNDCLASS wndclass;  static void
444      HWND h;  do_create_minpopup (HWND dlg)
445    {
446      wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;      HMENU hm;
447      wndclass.lpfnWndProc   = separator_wnd_proc;      POINT p;
448      wndclass.cbClsExtra    = 0;      
449      wndclass.cbWndExtra    = sizeof (long);      if (gpg_read_only || !clip_contains_pgpkey ())
450      wndclass.hInstance     = glob_hinst;          return;
451      wndclass.hIcon         = NULL;      hm = CreatePopupMenu ();
452      wndclass.hCursor       = LoadCursor (NULL, IDC_SIZENS);      if (!hm)
453      wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);          BUG (0);
454      wndclass.lpszMenuName  = 0;      insert_menu_item (hm, 0, ID_KEYCTX_PASTE, _("Paste Key from Clipboard"));
455      wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD;      GetCursorPos (&p);
456      RegisterClass (&wndclass);      TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);
457        DestroyMenu (hm);
458      h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,  }
459                          WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,  
460                          0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);      
461      ShowWindow (h, SW_SHOW);  /* Update the default key entry in the status bar for dialog @dlg. */
462      return h;  void
463  } /* regist_sep_wnd */  update_default_key_str (HWND dlg)
464    {
465        const char *fmt;
466        char *keyid;
467  #define enable_button(hwnd, cid) \      char defkeyinf[128];
468      SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG (key_selected, 0))  
469        keyid = get_gnupg_default_key ();
470        if (!keyid)
471  void          return;
472  update_ui_items (HWND hwnd, listview_ctrl_t lv)      if ((keyid[0] >= 'A' && keyid[0] <= 'Z') ||
473  {          (keyid[0] >= 'a' && keyid[0] <= 'z') ||
474      int key_selected = 0, key_has_sec = 0;          (keyid[0] == '0' && keyid[1] == 'x'))
475      int i, key_inv = 0;          fmt = _("Default Key: %s");
476      HWND hwnd_child;      else
477      HMENU hmenu;          fmt = _("Default Key: 0x%s");
478            _snprintf (defkeyinf, sizeof (defkeyinf) - 1, fmt, keyid);
479      /* Get some states */      SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf);
480      key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),      gpg_keycache_set_default_key (keycache_get_ctx (0), keyid);
481                                             LVM_GETSELECTEDCOUNT, 0, 0)      free_if_alloc (keyid);
482                                             ? TRUE : FALSE;  }
483      key_has_sec = FALSE;  
484      if (key_selected) {  
485          i = listview_get_curr_pos (lv);  /* Count all keys and show from @lv results in the status bar @sb. */
486          key_has_sec = km_check_for_seckey( lv, i, NULL ) ? TRUE : FALSE;          void
487          key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED;  update_status_bar (HWND sb, listview_ctrl_t lv)
488      }  {
489        char txt_sec[128], txt_pub[128];
490      /* Enable / disable toolbar buttons */      int nkeys = 0, nsec = 0;
491      hwnd_child = GetDlgItem(hwnd, IDR_WINPT_KMTB);      int i;
492      enable_button (hwnd_child, ID_KEYMISC_DELETE);  
493      enable_button (hwnd_child, ID_KEYMISC_PROPS);      nkeys = listview_count_items (lv, 0);
494      enable_button (hwnd_child, ID_KEYMISC_SIGN);      for (i = 0; i < nkeys; i++) {
495      enable_button (hwnd_child, ID_KEYMISC_EXPORT);          if (km_check_for_seckey (lv, i, NULL))
496                nsec++;
497      /* Enable / disable menu items */      }
498      hmenu = GetMenu (hwnd);      _snprintf (txt_sec, sizeof (txt_sec)-1, _("%d secret keys"), nsec);
499      set_menu_state (hmenu, ID_KEYMISC_EXPORT, key_selected ? MF_ENABLED : MF_GRAYED);      _snprintf (txt_pub, sizeof (txt_pub)-1, _("%d keys"), nkeys);
500      set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY, key_has_sec ? MF_ENABLED : MF_GRAYED);      SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec);
501      set_menu_state (hmenu, ID_KEYMISC_REVCERT, key_has_sec ? MF_ENABLED : MF_GRAYED);      SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub);
502      set_menu_state (hmenu, ID_KEYMISC_DELETE, key_selected ? MF_ENABLED : MF_GRAYED);  }
503      set_menu_state (hmenu, ID_KEYMISC_PROPS, key_selected ? MF_ENABLED : MF_GRAYED);  
504      set_menu_state (hmenu, ID_KEYMISC_SIGN, key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);  
505      set_menu_state (hmenu, ID_KEYMISC_EDITKEY, key_selected? MF_ENABLED : MF_GRAYED);  long CALLBACK
506      set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, key_selected? MF_ENABLED : MF_GRAYED);  separator_wnd_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
507  } /* update_ui_items */  {
508        static POINT last_mouse_pos;
509    
510  static void      if (msg == WM_CREATE)
511  popup_gpg_readonly (HWND dlg, HMENU hm)          SetWindowLong (hwnd, GWL_USERDATA,
512  {                         (long)(((CREATESTRUCT*)lparam)->lpCreateParams));
513      int resids[] = {  
514          ID_KEYCTX_PASTE,      switch (msg) {
515          ID_KEYCTX_EDIT,      case WM_PAINT:
516          ID_KEYCTX_SIGN,          PAINTSTRUCT ps;
517          ID_KEYCTX_REV,          RECT rect;
518          ID_KEYCTX_DEL,          HPEN hpen;
519          ID_KEYCTX_ENABLE,  
520          ID_KEYCTX_DISABLE,          GetClientRect (hwnd, &rect);
521          ID_KEYCTX_RECVFROM,          BeginPaint (hwnd, &ps);
522          ID_KEYCTX_ADDKEY,  
523          ID_KEYCTX_ADDPHOTO,          /* Background */
524          ID_KEYCTX_ADDUID,          FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));
525          ID_KEYCTX_ADDREV,  
526          0          /* The lines from the light into the dark */
527      };          MoveToEx(ps.hdc, 0,0, NULL);
528      int i;          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT))) != NULL) {
529                SelectObject (ps.hdc, (LPVOID)hpen);
530      if (gpg_read_only == 0)              LineTo (ps.hdc, rect.right, 0);
531          return;              DeleteObject (hpen);
532      for (i=0; resids[i] != 0; i++)          }
533          set_menu_state (hm, resids[i], MF_GRAYED);          MoveToEx(ps.hdc, 0, 1, NULL);
534  }          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) {
535                 SelectObject (ps.hdc, (LPVOID)hpen);
536                 LineTo (ps.hdc, rect.right, rect.bottom);
537  static void               DeleteObject (hpen);
538  menu_gpg_readonly (HWND dlg, HMENU hm, int id)           }
539  {  
540      int key_resids[] = {          MoveToEx(ps.hdc, 0, rect.bottom-1, NULL);
541          ID_KEYMISC_SIGN,          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) {
542          ID_KEYMISC_DELETE,              SelectObject (ps.hdc, (LPVOID)hpen);
543          ID_KEYMISC_REVCERT,              LineTo (ps.hdc, rect.right, rect.bottom-1);
544          ID_KEYMISC_IMPORT_HTTP,              DeleteObject (hpen);
545          ID_KEYMISC_IMPORT,          }
546          ID_KEYMISC_REFRESH_KEYS,          MoveToEx(ps.hdc, 0, rect.bottom, NULL);
547          ID_KEYMISC_REBUILD,          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) {
548          ID_KEYMISC_KEYWIZARD,              SelectObject (ps.hdc, (LPVOID)hpen);
549          ID_KEYMISC_CARDNEW,              LineTo (ps.hdc, rect.right, rect.bottom);
550          ID_KEYMISC_NEWKEY,              DeleteObject (hpen);
551          0,          }
552      };  
553      int edit_resids[] = {          EndPaint (hwnd, &ps);
554          ID_KEYMISC_PASTE,          return 0;
555          ID_KEYMISC_OT,  
556          ID_KEYMISC_EDITKEY,      case WM_LBUTTONDOWN:
557          0          last_mouse_pos.x = LOWORD (lparam);
558      };          last_mouse_pos.y = HIWORD (lparam);
559      int * resids;          ClientToScreen (hwnd, &last_mouse_pos);
560      int i;          SetCapture (hwnd);
561            return 0;
562        
563      if (gpg_read_only == 0)      case WM_LBUTTONUP:
564          return;          ReleaseCapture ();
565      switch (id) {          return 0;
566      case 0: return;  
567      case 3: resids = key_resids; break;      case WM_MOUSEMOVE:
568      case 1: resids = edit_resids;break;          if (wparam == MK_LBUTTON) {
569      }              struct km_info_s *kmi;
570                POINT p;
571      for (i=0; resids[i] != 0; i++)              RECT r;
572          set_menu_state (hm, resids[i], MF_GRAYED);  
573  }              kmi = (struct km_info_s *)GetWindowLong (hwnd, GWL_USERDATA);
574                if (kmi == NULL)
575                    break;
576  static char*  
577  gen_export_filename (const char *keyid, int is_secret)              /* Calculate mouse movement */
578  {              p.x = LOWORD(lparam);
579      gpgme_key_t key;              p.y = HIWORD(lparam);
580      const char *s;              ClientToScreen (hwnd, &p);
581      char *p;  
582                GetWindowRect (hwnd, &r);
583      if (get_pubkey (keyid, &key))              r.top += (short)(p.y - last_mouse_pos.y);
584          return m_strdup (keyid);              r.bottom += (short)(p.y - last_mouse_pos.y);
585      s = key->uids->name;  
586      if (!s)              last_mouse_pos.y = p.y;
587          return m_strdup (keyid);  
588      p = new char[strlen (s) + 8 + 16];              /* Apply mouse movement to window. Beware the MoveWindow is relaive
589      if (!p)                 to parent NOT screen */
590          BUG (0);              MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&r, 2);
591      sprintf (p, "%s%s.asc", s, is_secret? "_sec" : "");              kmi->ypos_sep = r.top;
592      for (size_t i=0; i < strlen (p); i++) {              kmi->ypercent_sep = 0; /* This forces do_resize_window to use abs. position */
593          if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|')              do_resize_window (GetParent(hwnd), kmi);
594              p[i] = '_';              return 0;
595      }          }
596      return p;      }
597  }  
598        return DefWindowProc (hwnd, msg, wparam, lparam);
599    }
600  static void  
601  update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair)  
602  {  /* Register the separator window with @dlg as the parent window. */
603      gpgme_key_t key;  static HWND
604    regist_sep_wnd (HWND dlg, struct km_info_s *kmi)
605      keycache_update (0, keyid);  {
606      if (keypair)      WNDCLASS wndclass;
607          keycache_update (1, keyid);      HWND h;
608    
609      /* because we replaced the key item, we need to update the      wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
610         address of the pointer in the ListView control. */      wndclass.lpfnWndProc   = separator_wnd_proc;
611      get_pubkey (keyid, &key);      wndclass.cbClsExtra    = 0;
612      keylist_upd_key (lv, pos, key);      wndclass.cbWndExtra    = sizeof (long);
613  }      wndclass.hInstance     = glob_hinst;
614        wndclass.hIcon         = NULL;
615        wndclass.hCursor       = LoadCursor (NULL, IDC_SIZENS);
616  /* Setup status bar for the main window @dlg. */      wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
617  static HWND      wndclass.lpszMenuName  = 0;
618  setup_status_bar (HWND dlg, listview_ctrl_t lv)      wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD;
619  {            RegisterClass (&wndclass);
620      HWND statbar;      
621      RECT r;      h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,
622      int partpos[3];                          WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
623      int i;                          0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);    
624        ShowWindow (h, SW_SHOW);
625      GetClientRect (dlg, &r);      return h;
626      for (i=1; i <= 3; i++)  }
627          partpos[i-1] = r.right/3*i;  
628      statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,  
629                                    "status bar", dlg, KM_SEPARATOR_ID);  #define enable_button(hwnd, cid, item_selected) \
630        SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG ((item_selected), 0))
631      ShowWindow (statbar, SW_SHOW);  
632      SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);  
633    /* Interactive modification of the dialog item which depend if an item
634      km_update_default_key_str (statbar);     is selected or not and what kind of item. @lv is the list view with
635      km_complete_status_bar (statbar, lv);     the items. */
636    void
637      return statbar;  update_ui_items (HWND hwnd, listview_ctrl_t lv)
638  }  {
639        HWND tb_hwnd;
640        HMENU hmenu;
641  BOOL CALLBACK      int mult_resids[] = {ID_KEYMISC_PROPS, ID_KEYMISC_SIGN, ID_KEYMISC_EDITKEY,
642  keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)                           ID_KEYMISC_CHECKSIGS, ID_KEYMISC_REVCERT, 0};
643  {      int key_selected = 0;
644      struct km_info *kmi;      int key_has_sec = 0;
645      static km_group_s *gc = NULL;      int key_inv = 0;
646      static HMENU menu = NULL;      int i, state=0;
647      static int refresh_keys = 0;      
648      INITCOMMONCONTROLSEX icex;      /* Get some states */
649      HWND kl;      key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),
650      HMENU hm;                                             LVM_GETSELECTEDCOUNT, 0, 0)
651      gpg_keycache_t c;                                             ? TRUE : FALSE;
652      gpgme_key_t key;      key_has_sec = FALSE;
653      /*km_group_cb_s gcb; XXX */      if (key_selected) {
654      struct genkey_s genkey;          i = listview_get_curr_pos (lv);
655      struct winpt_key_s k = {0};          key_has_sec = km_check_for_seckey (lv, i, NULL) ? TRUE : FALSE;
656      struct URL_ctx_s *url;          key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED ||
657      refresh_cache_s rcs = {0};                    km_get_key_status (lv, i) & KM_FLAG_EXPIRED;
658      char keyid[48], uid[128], type[32], *name;      }
659      const char *t, * host;  
660      u16 port = 0;      /* Enable / disable toolbar buttons */
661      int idx = 0, i=0, rc;      tb_hwnd = GetDlgItem (hwnd, IDR_WINPT_KMTB);
662      size_t size = 0;      enable_button (tb_hwnd, ID_KEYMISC_DELETE, key_selected);
663        enable_button (tb_hwnd, ID_KEYMISC_PROPS, key_selected);
664      if ((msg != WM_INITDIALOG)      enable_button (tb_hwnd, ID_KEYMISC_SIGN, key_selected && !key_inv);
665          && ((kmi = (struct km_info*)GetWindowLong (dlg, GWL_USERDATA)) == NULL))      enable_button (tb_hwnd, ID_KEYMISC_EXPORT, key_selected);
666          return FALSE;      enable_button (tb_hwnd, ID_KEYCTX_COPY, key_selected);
667        enable_button (tb_hwnd, ID_KEYCTX_PASTE, clip_contains_pgpkey ());
668      switch (msg) {  
669      case WM_INITDIALOG:      /* Enable / disable menu items */
670          kmi = new struct km_info;      state = key_selected? MF_ENABLED : MF_DISABLED|MF_GRAYED;
671          memset (kmi, 0, sizeof (struct km_info));      hmenu = GetMenu (hwnd);
672          icex.dwSize = sizeof (INITCOMMONCONTROLSEX);      set_menu_state (hmenu, ID_KEYMISC_EXPORT, state);
673          icex.dwICC  = ICC_BAR_CLASSES;      set_menu_state (hmenu, ID_KEYMISC_DELETE, state);
674          InitCommonControlsEx (&icex);      set_menu_state (hmenu, ID_KEYMISC_PROPS, state);
675          kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);      set_menu_state (hmenu, ID_KEYMISC_EDITKEY, state);
676          imagelist_load (dlg);      set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, state);
677        set_menu_state (hmenu, ID_KEYMISC_SIGN,
678  #ifndef LANG_DE                      key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);
679          SetWindowText( dlg, _("Key Manager") );      set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY,
680  #endif                              key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
681          menu = LoadMenu( glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC );      set_menu_state (hmenu, ID_KEYMISC_REVCERT,
682  #ifndef LANG_DE                      key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
683          set_menu_text( menu, ID_KEYMISC_QUIT, _("&Quit") );  
684          set_menu_text( menu, ID_KEYMISC_UID, _("User ID") );      /* Disable some menu items when multiple keys are selected. */
685          set_menu_text( menu, ID_KEYMISC_NEWKEY, _("&Expert") );      if (listview_count_items (lv, 1) > 1) {
686          set_menu_text( menu, ID_KEYMISC_KEYWIZARD, _("&Normal") );          for (i=0; mult_resids[i] != 0; i++)
687          set_menu_text( menu, ID_KEYMISC_EDIT, _("Edit") );              set_menu_state (hmenu, mult_resids[i], MF_GRAYED);
688          set_menu_text( menu, ID_KEYMISC_SIGN, _("&Sign") );      }
689          set_menu_text( menu, ID_KEYMISC_DELETE, _("&Delete") );  
690          set_menu_text( menu, ID_KEYMISC_REVCERT, _("&Revoke") );      /* Disable all secret-key functions when no secret key is available. */
691          set_menu_text( menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures") );      if (!secret_key_available ()) {
692          set_menu_text( menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path") );          enable_button (tb_hwnd, ID_KEYMISC_SIGN, FALSE);
693          set_menu_text( menu, ID_KEYMISC_PROPS, _("&Properties") );          set_menu_state (hmenu, ID_KEYMISC_SIGN, MF_GRAYED);
694          set_menu_text( menu, ID_KEYMISC_GPGOPT, _("Options") );      }
695          set_menu_text( menu, ID_KEYMISC_GPGPREFS, _("Preferences") );  }
696          set_menu_text( menu, ID_KEYMISC_SENDRECV, _("Keyserver") );  
697          set_menu_text( menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache") );  
698          set_menu_text( menu, ID_KEYMISC_REBUILD, _("R&everify Signatures") );  /* Disable some context menu items when multiple keys are selected. */
699          set_menu_text( menu, ID_KEYMISC_INFO, _("Info") );  static void
700          set_menu_text (menu, ID_KEYMISC_HELP, _("Help"));  popup_multiple (HWND dlg, HMENU hm)
701  #endif  {
702          SetMenu (dlg, menu);      int resids[] = {
703          if( keyring_check_last_access() )          ID_KEYCTX_EDIT,
704              keycache_set_reload( 1 );          ID_KEYCTX_SIGN,
705          if( keycache_get_reload( ) )          ID_KEYCTX_REV,
706              keycache_reload( dlg );          ID_KEYCTX_ENABLE,
707          c = keycache_get_ctx( KEYCACHE_PUB );          ID_KEYCTX_DISABLE,
708          if( !c )          ID_KEYCTX_ADDKEY,
709              BUG( NULL );          ID_KEYCTX_ADDPHOTO,
710          kmi->keylist_sortby = KEY_SORT_USERID;          ID_KEYCTX_ADDUID,
711          Header_SetImageList(ListView_GetHeader(GetDlgItem( dlg, IDC_KEYMISC_KEYLIST )),          ID_KEYCTX_ADDREV,
712                              glob_imagelist);          ID_KEYCTX_LISTSIGS,
713          kmi->lv = keylist_load( GetDlgItem( dlg, IDC_KEYMISC_KEYLIST ), c,          ID_KEYCTX_MAXTRUST,
714                                  NULL, KEYLIST_LIST, kmi->keylist_sortby );          ID_KEYCTX_PROPS,
715          /* init subclassing for the listview */          ID_KEYCTX_SENDMAIL,
716          kl = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST );          0};
717          keylist_proc.dlg = dlg;      int i;
718          keylist_proc.current = (WNDPROC)keylist_subclass_proc;      for (i=0; i < resids[i] != 0; i++)
719          keylist_proc.old = (WNDPROC)GetWindowLong( kl, GWL_WNDPROC );          set_menu_state (hm, resids[i], MF_GRAYED);
720          if( keylist_proc.old ) {  }
721              if( !SetWindowLong( kl, GWL_WNDPROC, (LONG)keylist_proc.current) ) {  
722                  msg_box( dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR );  
723                  BUG( NULL );  /* The items which are shown when GPG is in read-only mode. */
724              }  static void
725          }  popup_gpg_readonly (HWND dlg, HMENU hm)
726          #if 0  {
727          km_groups_new( &gc, GetDlgItem( dlg, IDC_KEYMISC_GROUP ) );      int resids[] = {
728          km_groups_load( gc );          ID_KEYCTX_PASTE,
729          #endif          ID_KEYCTX_EDIT,
730          SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst, (LPCTSTR)IDI_WINPT));          ID_KEYCTX_SIGN,
731          SetForegroundWindow (dlg);          ID_KEYCTX_REV,
732            ID_KEYCTX_DEL,
733          kmi->statbar = setup_status_bar (dlg, kmi->lv);          ID_KEYCTX_ENABLE,
734            ID_KEYCTX_DISABLE,
735          SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);          ID_KEYCTX_RECVFROM,
736          kmi->toolbar = load_toolbar (dlg, kmi);          ID_KEYCTX_ADDKEY,
737            ID_KEYCTX_ADDPHOTO,
738          do_center_window( dlg, kmi );          ID_KEYCTX_ADDUID,
739          do_resize_window( dlg, kmi );          ID_KEYCTX_ADDREV,
740          update_ui_items (dlg, kmi->lv);          0
741          return TRUE;      };
742                int i;
743      case WM_DESTROY:  
744          if (kmi->lv) {      if (gpg_read_only == 0)
745              keylist_delete (kmi->lv);          return;
746              kmi->lv = NULL;            for (i=0; resids[i] != 0; i++)
747                    set_menu_state (hm, resids[i], MF_GRAYED);
748           /*  }
749           if (gc) {  
750              km_groups_release (gc);  
751              gc = NULL;  /* Change the 'Edit' menu based on the current state. */
752          }*/  static void
753         imagelist_destroy ();  change_edit_menu (listview_ctrl_t lv, HMENU hm, int id)
754    {
755         char buf[32];      enum item { EDIT_MENU = 1 };
756         ltoa (kmi->pos_x, buf, 10);      int no_sel;
757         set_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", buf );  
758         ltoa (kmi->pos_y, buf, 10);      if (id != EDIT_MENU)
759         set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", buf);          return;
760         /* Remove runtime information. This should be the last action taken here. */  
761         delete kmi; kmi = NULL;      if (!clip_contains_pgpkey ())
762         SetWindowLong (dlg, GWL_USERDATA, NULL);              set_menu_state (hm, ID_KEYMISC_PASTE, MF_GRAYED);
763         keycache_set_reload (refresh_keys);      else
764         return FALSE;          set_menu_state (hm, ID_KEYMISC_PASTE, MF_ENABLED);
765        no_sel = listview_get_curr_pos (lv) == -1? 1 : 0;
766      case WM_MOVE:            set_menu_state (hm, ID_KEYMISC_DELETE2, no_sel? MF_GRAYED: MF_ENABLED);
767          /* kmi->pos_x = (int)(short)LOWORD(lparam);      set_menu_state (hm, ID_KEYMISC_COPY, no_sel? MF_GRAYED : MF_ENABLED);
768             kmi->pos_y = (int)(short)HIWORD(lparam); */  }
769          RECT r;  
770          GetWindowRect (dlg, &r);  
771          kmi->pos_x = r.left;  
772          kmi->pos_y = r.top;      /* Show limited key menu entries when GPG is in read-only mode. */
773          break;  static void
774            change_key_menu (HMENU hm, int id)
775    {
776      case WM_RBUTTONUP:      int key_resids[] = {
777          do_create_minpopup (dlg);          ID_KEYMISC_SIGN,
778          break;          ID_KEYMISC_DELETE,
779            ID_KEYMISC_REVCERT,
780      case WM_NOTIFY:                      ID_KEYMISC_IMPORT_HTTP,
781          NMHDR * notify;          ID_KEYMISC_IMPORT,
782          POINT p;          ID_KEYMISC_REFRESH_KEYS,
783          HMENU popup;          ID_KEYMISC_REBUILD,
784                    ID_KEYMISC_KEYWIZARD,
785          notify = (NMHDR *)lparam;          ID_KEYMISC_CARDNEW,
786          if (notify == NULL)          ID_KEYMISC_NEWKEY,
787              break;          0,
788          switch (notify->code)      };
789          {      int edit_resids[] = {
790          case TBN_QUERYDELETE:          ID_KEYMISC_PASTE,
791              SetWindowLong(dlg, DWL_MSGRESULT, TRUE);          ID_KEYMISC_OT,
792              return TRUE;          ID_KEYMISC_EDITKEY,
793                    0
794          case TBN_QUERYINSERT:      };
795              SetWindowLong(dlg, DWL_MSGRESULT, TRUE);      int *resids;
796              return TRUE;      int i;
797    
798          case TBN_GETBUTTONINFO:      
799              LPTBNOTIFY lpTbNotify;      if (gpg_read_only == 0)
800              lpTbNotify = (LPTBNOTIFY)lparam;          return;
801              if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) {      switch (id) {
802                  lpTbNotify->tbButton.iBitmap = imagelist_getindex(myb[lpTbNotify->iItem].icon);      case 0: return;
803                  lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command;      case 3: resids = key_resids; break;
804                  lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;      case 1: resids = edit_resids;break;
805                  lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;      default:resids = edit_resids; break;
806                  lpTbNotify->tbButton.iString = 0;      }
807                  strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText);  
808                  SetWindowLong(dlg, DWL_MSGRESULT, TRUE);      for (i=0; resids[i] != 0; i++)
809              }          set_menu_state (hm, resids[i], MF_GRAYED);
810              return TRUE;  }
811    
812          case TBN_RESET: /* Restore last saved toolbar status */  
813              TBSAVEPARAMS tbsp;  /* Reload a single key in the cache. */
814    static void
815              tbsp.hkr = HKEY_CURRENT_USER;  update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair)
816              tbsp.pszSubKey = "Software\\WinPT";  {
817              tbsp.pszValueName = "KM_toolbar";      struct winpt_key_s key;
818              SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp);  
819              break;      keycache_update (0, keyid);
820        if (keypair)
821          case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */          keycache_update (1, keyid);
822              tbsp.hkr = HKEY_CURRENT_USER;  
823              tbsp.pszSubKey = "Software\\WinPT";      /* because we replaced the key item, we need to update the
824              tbsp.pszValueName = "KM_toolbar";         address of the pointer in the ListView control. */
825              SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);      memset (&key, 0, sizeof (key));
826              break;      winpt_get_pubkey (keyid, &key);
827        keylist_upd_key (lv, pos, key.ext, key.ctx);
828          case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */      keyring_check_last_access ();
829              tbsp.hkr = HKEY_CURRENT_USER;  }
830              tbsp.pszSubKey = "Software\\WinPT";  
831              tbsp.pszValueName = "KM_toolbar";  
832              SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);  /* Setup status bar for the main window @dlg. */
833              break;  static HWND
834    setup_status_bar (HWND dlg, listview_ctrl_t lv)
835          case TTN_GETDISPINFO:  {      
836              LPTOOLTIPTEXT lpttt;      HWND statbar;
837              lpttt = (LPTOOLTIPTEXT)lparam;      RECT r;
838        int partpos[3];
839              lpttt->hinst = NULL;      int i;
840              switch (lpttt->hdr.idFrom) {  
841              case ID_KEYMISC_DELETE:      GetClientRect (dlg, &r);
842                  lpttt->lpszText = (char *)_("Delete key from keyring");      for (i=1; i <= 3; i++)
843                  break;          partpos[i-1] = r.right/3*i;
844        statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,
845              case ID_KEYMISC_PROPS:                                    "status bar", dlg, KM_SEPARATOR_ID);
846                  lpttt->lpszText = (char *)_("Show key properties");  
847                  break;      ShowWindow (statbar, SW_SHOW);
848        SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);
849              case ID_KEYMISC_SIGN:  
850                  lpttt->lpszText = (char *)_("Sign key");      update_default_key_str (statbar);
851                  break;      update_status_bar (statbar, lv);
852    
853              case ID_KEYMISC_IMPORT:      return statbar;
854                  lpttt->lpszText = (char *)_("Import key to keyring");  }
855                  break;  
856    
857              case ID_KEYMISC_EXPORT:  /* Remove or add columns which depends on the state of @checked. */
858                  lpttt->lpszText = (char *)_("Export key to a file");  void
859                  break;  modify_listview_columns (km_info_s *kmi, UINT m_uid, BOOL checked)
860              }  {
861              return TRUE;      UINT resids[] = {
862                        0,
863          case LVN_ITEMCHANGED:          ID_KEYMISC_VIEWKEYID,
864              if (((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */          ID_KEYMISC_VIEWTYPE,
865              {          0,
866                  update_ui_items (dlg, kmi->lv);          ID_KEYMISC_VIEWCIPHER,
867                  return TRUE;          0,
868              }          0,
869              break;          ID_KEYMISC_VIEWCREAT,
870            ID_KEYMISC_VIEWDESC,
871          case NM_RCLICK:          -1
872              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {      };
873                  if (listview_get_curr_pos (kmi->lv) == -1)      listview_column_s cols[] = {
874                      return TRUE; /* Popup only when a item was selected */      {0, 240, (char *)_("User ID")},
875                  do_check_cache (kmi->lv, dlg, kmi->statbar);      {1, 78, (char *)_("Key ID")},
876                  GetCursorPos (&p);      {2, 52, (char *)_("Type")},    
877                  hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));      {3, 66, (char *)_("Size")},
878                  popup = GetSubMenu (hm, 0);      {4, 60, (char *)_("Cipher")},
879              #ifndef LANG_DE      {5, 66, (char *)_("Validity")},
880                  set_menu_text( popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard") );      {6, 58, (char *)_("Trust")},
881                  set_menu_text( popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard") );      {7, 72, (char *)_("Creation")},
882                  set_menu_text( popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard") );                  {8, 160,(char *)_("Description")},
883                  set_menu_text( popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver") );      {0, 0, NULL}
884              #endif      };
885                  idx = listview_get_curr_pos (kmi->lv);      UINT pos;
886                  if (km_check_for_seckey (kmi->lv, idx, &i))  
887                      set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);      for (pos=0; resids[pos] != -1; pos++) {
888                  if (i == 0)          if (m_uid == resids[pos])
889                      set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);              break;
890                  if (!km_check_for_seckey (kmi->lv, idx, NULL)) {      }
891                      set_menu_state( popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED );      if (!checked)
892                      set_menu_state( popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED );          listview_del_column (kmi->lv, (int)pos);
893                      set_menu_state( popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED );      else {      
894                      set_menu_state( popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED );          listview_add_column (kmi->lv, &cols[pos]);
895                      set_menu_state( popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED );          keylist_upd_col (kmi->lv, pos);
896                      set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED);      }
897                  }  }
898                  else if( km_check_for_seckey (kmi->lv, idx, NULL)  
899                        && km_key_is_v3 (kmi->lv, idx)) {  
900                      /* PGP 2 keys, version 3 have no no support for photo-id's,  /* Helper to handle the help file. If @check is 1
901                         designated revokers and secondary keys. */     the existence of the file is checked.
902                      set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);     Otherwise the help file will be loaded. */
903                      set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);  static bool
904                      set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED);  start_help (HWND dlg, int check)
905                  }  {
906                  if( km_get_key_status( kmi->lv, idx ) & KM_FLAG_DISABLED )      DWORD n;
907                      set_menu_state( popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED );      char path[MAX_PATH+1+32];
908                  else  
909                      set_menu_state( popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED );      n = GetModuleFileName (NULL, path, sizeof (path)-1-32);
910                  if (km_get_key_status (kmi->lv, idx) & KM_FLAG_REVOKED)      if (!n)
911                      set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);          return false;
912                  if (mapi_init())      path[n] = 0;
913                      set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);      while (n-- && path[n] != '\\')
914                  /* Override 'Default Keyserver' with the actual name. */          ;
915                  host = kserver_get_hostname (0, -1, &port);      path[n+1] = 0;
916                  set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);      strcat (path, "winpt.chm");
917                  popup_gpg_readonly (dlg, popup);      if (!check)
918                  TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);          ShellExecute (dlg, "open", path, NULL, NULL, SW_SHOW);
919                  DestroyMenu (popup);      return file_exist_check (path) == 0? true : false;
920                  DestroyMenu (hm);  }
921                  return TRUE;  
922              }  /* Translate all menu strings. */
923              #if 0 /* XXX */  static void
924              if( notify->idFrom == IDC_KEYMISC_GROUP ) {  translate_menu_strings (HWND dlg)
925                  HWND tree = GetDlgItem( dlg, IDC_KEYMISC_GROUP );  {
926                  if( TreeView_GetSelection( tree ) ) {      HMENU menu;
927                      GetCursorPos( &p );  
928                      hm = LoadMenu( glob_hinst, MAKEINTRESOURCE(IDR_WINPT_GROUP_CTX) );      menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC);
929                      popup = GetSubMenu( hm, 0 );      set_menu_text_bypos (menu, 0, _("File"));
930                      if( km_index == -1 )      set_menu_text_bypos (menu, 1, _("Edit"));
931                          set_menu_state( popup, ID_GROUP_PASTE, MF_DISABLED|MF_GRAYED );      set_menu_text_bypos (menu, 2, _("View"));
932                      set_menu_text( popup, ID_GROUP_PASTE, _("Paste into this group") );      set_menu_text_bypos (menu, 3, _("Key"));
933                      set_menu_text( popup, ID_GROUP_DELETE, _("Delete") );      set_menu_text_bypos (menu, 4, _("Groups"));
934                      TrackPopupMenu( popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL );  
935                      DestroyMenu( popup );      set_menu_text (menu, ID_KEYMISC_EDITKEY, _("Edit"));
936                      DestroyMenu( hm );      set_menu_text (menu, ID_KEYMISC_MAIL, _("Send Mail..."));
937                      return TRUE;      set_menu_text (menu, ID_KEYMISC_OT, _("Ownertrust")); /* XXX */
938                  }      set_menu_text (menu, ID_KEYMISC_COPY, _("&Copy\tCtrl+C"));
939              }      set_menu_text (menu, ID_KEYMISC_PASTE, _("&Paste\tCtrl+V"));
940              #endif      set_menu_text (menu, ID_KEYMISC_FIND, _("Search...\tCtrl+F"));
941              break;      set_menu_text (menu, ID_KEYMISC_SELALL, _("Select All\tCtrl+A"));
942        set_menu_text (menu, ID_KEYMISC_QUIT, _("&Quit"));
943          case LVN_COLUMNCLICK:      set_menu_text (menu, ID_KEYMISC_UID, _("User ID"));
944              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {      set_menu_text (menu, ID_KEYMISC_NEWKEY, _("&Expert"));
945                  NMLISTVIEW * p = (LPNMLISTVIEW) lparam;      set_menu_text (menu, ID_KEYMISC_KEYWIZARD, _("&Normal"));
946                  int sortby = 0;      set_menu_text (menu, ID_KEYMISC_EDIT, _("Edit"));
947                  switch (p->iSubItem) {      set_menu_text (menu, ID_KEYMISC_SIGN, _("&Sign"));
948                  case 0:  sortby = KEY_SORT_USERID; break;      set_menu_text (menu, ID_KEYMISC_DELETE, _("&Delete"));
949                  case 1:  sortby = KEY_SORT_KEYID; break;      set_menu_text (menu, ID_KEYMISC_DELETE2, _("&Delete"));
950                  case 2:  sortby = KEY_SORT_IS_SECRET; break;      set_menu_text (menu, ID_KEYMISC_REVCERT, _("&Revoke Cert"));
951                  case 3:  sortby = KEY_SORT_LEN; break;      set_menu_text (menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures"));
952                  case 5:  sortby = KEY_SORT_VALIDITY; break;      set_menu_text (menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path"));
953                  case 6:  sortby = KEY_SORT_OTRUST; break;      set_menu_text (menu, ID_KEYMISC_EXPORT, _("&Export..."));
954                  case 7:  sortby = KEY_SORT_CREATED; break;      set_menu_text (menu, ID_KEYMISC_IMPORT, _("&Import..."));
955                  case 8:  sortby = KEY_SORT_ALGO; break;      set_menu_text (menu, ID_KEYMISC_PROPS, _("&Properties"));
956                  default: return TRUE; //sortby = KEY_SORT_USERID; break;      set_menu_text (menu, ID_KEYMISC_GPGOPT, _("Options"));
957                  }      set_menu_text (menu, ID_KEYMISC_GPGPREFS, _("Preferences"));
958        set_menu_text (menu, ID_KEYMISC_SENDRECV, _("Keyserver") );
959                  if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)      set_menu_text (menu, ID_KEYMISC_EXPORT_PRIVKEY, _("E&xport Secret Key"));
960                      kmi->keylist_sortby ^= KEYLIST_SORT_DESC;      set_menu_text (menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache"));
961                  else      set_menu_text (menu, ID_KEYMISC_REBUILD, _("R&everify Signatures"));
962                      kmi->keylist_sortby = sortby;      set_menu_text (menu, ID_KEYMISC_REFRESH_KEYS, _("Refresh &Keys (Keyserver)"));
963                  keylist_sort (kmi->lv, kmi->keylist_sortby);      set_menu_text (menu, ID_KEYMISC_INFO, _("Info") );
964                  return TRUE;      set_menu_text (menu, ID_KEYMISC_HELP, _("&Help"));
965              }  
966              break;      set_menu_text (menu, ID_KEYMISC_VIEWKEYID, _("Key ID"));
967          }      set_menu_text (menu, ID_KEYMISC_VIEWCIPHER, _("Cipher"));
968          break;      set_menu_text (menu, ID_KEYMISC_VIEWTYPE, _("Type"));
969          }      set_menu_text (menu, ID_KEYMISC_VIEWCREAT, _("Creation"));
970    
971      case WM_WINDOWPOSCHANGING:      if (!start_help (NULL, 1))
972          if (((WINDOWPOS*)lparam)->cx < 400)          set_menu_state (menu, ID_KEYMISC_HELP, MF_GRAYED);
973              ((WINDOWPOS*)lparam)->cx = 400;  
974          if (((WINDOWPOS*)lparam)->cy < 200)      SetMenu (dlg, menu);
975              ((WINDOWPOS*)lparam)->cy = 200;  }
976           return TRUE;  
977            
978      case WM_SIZE:  /* Translate popup menu strings. */
979          do_resize_window (dlg, kmi);  static void
980          return TRUE;  translate_popupmenu_strings (HMENU popup)
981            {
982      case WM_SYSCOMMAND:      set_menu_text (popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard"));
983          if( LOWORD (wparam) == SC_CLOSE )      set_menu_text (popup, ID_KEYCTX_KEYID_COPY, _("Copy Key ID to Clipboard"));
984              EndDialog( dlg, TRUE );      set_menu_text (popup, ID_KEYCTX_FPR_COPY, _("Copy Fingerprint to Clipboard"));
985          return FALSE;      set_menu_text (popup, ID_KEYCTX_KINFO_COPY, _("Copy Key Info to Clipboard"));
986                set_menu_text (popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard"));
987      case WM_MENUSELECT:      set_menu_text (popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard"));
988          menu_gpg_readonly (dlg, (HMENU)lparam, LOWORD (wparam));      set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver"));
989          break;      set_menu_text (popup, ID_KEYCTX_MAXTRUST, _("Set Implicit &Trust"));
990        set_menu_text (popup, ID_KEYCTX_LISTSIGS, _("&List Signatures"));
991      case WM_COMMAND:      set_menu_text (popup, ID_KEYCTX_PROPS, _("&Properties"));
992          if( gnupg_access_keyring( 1 ) ) {      set_menu_text (popup, ID_KEYCTX_EDIT, _("Key Edit"));
993              msg_box( dlg, _("Could not access public keyring"), _("Key Manager"), MB_ERR );      set_menu_text (popup, ID_KEYCTX_DEL, _("&Delete"));
994              return FALSE;      set_menu_text (popup, ID_KEYCTX_REV, _("&Revoke Cert"));
995          }      set_menu_text (popup, ID_KEYCTX_SIGN, _("&Sign"));
996          do_check_cache( kmi->lv, dlg, kmi->statbar );      set_menu_text (popup, ID_KEYCTX_ENABLE, _("&Enable"));
997          switch( LOWORD( wparam ) ) {      set_menu_text (popup, ID_KEYCTX_DISABLE, _("&Disable"));
998          case ID_KEYMISC_QUIT:      set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Re&fresh from Keyserver"));
999              EndDialog( dlg, TRUE );      set_menu_text (popup, ID_KEYCTX_SETPREFKS, _("Set preferred Keyserver URL"));
1000              return TRUE;      set_menu_text (popup, ID_KEYCTX_SENDMAIL, _("Send Key to Mail Recipient"));
1001                    set_menu_text (popup, ID_KEYCTX_SETDEFKEY, _("Set as Default Key"));
1002          case ID_KEYMISC_MAIL:  
1003              /* XXX      set_menu_text (popup, ID_KEYCTX_ADDKEY, _("Key..."));
1004              DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_MAIL, GetDesktopWindow (),      set_menu_text (popup, ID_KEYCTX_ADDUID, _("User ID..."));
1005                              winpt_mail_proc, NULL);*/      set_menu_text (popup, ID_KEYCTX_ADDPHOTO, _("Photo ID..."));
1006              break;      set_menu_text (popup, ID_KEYCTX_ADDREV, _("Revoker..."));
1007            
1008          case ID_KEYMISC_FIND:      /* change popup texts */
1009              km_find_key (dlg, kmi->lv);      set_menu_text_bypos (popup, 0, _("Key Attributes"));
1010              break;      set_menu_text_bypos (popup, 6, _("Add"));
1011        set_menu_text_bypos (popup, 19, _("Send to Keyserver"));
1012          case ID_KEYMISC_DELETE:  }
1013              km_delete_keys (kmi->lv, dlg);  
1014              return TRUE;  
1015                /* Return true if the cache contain marked keys. */
1016          case ID_KEYMISC_SIGN:          static bool
1017              if ( (idx = listview_get_curr_pos( kmi->lv )) == -1 ) {  updated_keys_avail (void)
1018                  msg_box( dlg, _("Please select a key."),  _("Key Manager"),  {
1019                           MB_ERR );      gpg_keycache_t kc = keycache_get_ctx (1);
1020                  return TRUE;;      struct keycache_s *k;
1021              }  
1022              if (km_check_key_status (kmi->lv, idx))      for (k = kc->item; k; k = k->next) {
1023                  return TRUE;          if (k->flags)
1024              key = (gpgme_key_t)listview_get_item2 (kmi->lv, idx);              return true;
1025              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);      }
1026              memset (&k, 0, sizeof (k));      return false;
1027              k.ctx = key;  }
1028              k.keyid = keyid;  
1029              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,  
1030                                keysign_dlg_proc, (LPARAM)&k,  /* Find the index of the key identified by @key. */
1031                                _("Key Signing"), IDS_WINPT_KEYSIGN);  static int
1032              if (k.update)  find_keypos (listview_ctrl_t lv, gpgme_key_t key)
1033                  update_key (kmi->lv, idx, k.keyid, 0);  {
1034              return TRUE;      char keyid[16+1];
1035                    int i;
1036          case ID_KEYMISC_REVCERT:  
1037              idx = listview_get_curr_pos( kmi->lv );      for (i=0; i < listview_count_items (lv, 0); i++) {
1038              if( idx == -1 ) {          listview_get_item_text (lv, i, KM_COL_KEYID, keyid, sizeof (keyid)-1);
1039                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );          if (!strcmp (key->subkeys->keyid+8, keyid+2))
1040                  return TRUE;              return i;
1041              }      }
1042              listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 );      return -1;
1043              listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 );  }
1044              if ( !km_check_for_seckey( kmi->lv, idx, NULL ) ) {  
1045                  msg_box( dlg, _("There is no secret key available!"), _("Key Manager"), MB_ERR );  
1046                  return TRUE;  /* Add all recently updated keys in the cache to the list
1047              }     and refresh all GUI elements. */
1048                static void
1049              {  refresh_keylist (struct km_info_s *kmi)
1050                  char t[128];  {
1051                  listview_get_item_text( kmi->lv, idx, 5, t, sizeof t -1 );      struct keycache_s *ctx;
1052                  if( strchr( t, 'R' ) ) {      gpg_keycache_t kc;
1053                      msg_box( dlg, _("Key already revoked!"), _("Key Manager"), MB_INFO );      int status=0, pos;
1054                      return TRUE;  
1055                  }      kc = keycache_get_ctx (1);
1056              }      while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) {
1057                        if (status == KC_FLAG_ADD)
1058              memset (&k, 0, sizeof (k));              keylist_add_key (kmi->lv, KEYLIST_LIST, ctx, ctx->key);
1059              k.key_pair = 1;          else {
1060              k.keyid = keyid;              pos = find_keypos (kmi->lv, ctx->key);
1061              k.is_protected = km_check_if_protected (kmi->lv, idx);              if (pos != -1)
1062              dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,                  keylist_upd_key (kmi->lv, pos, ctx, ctx->key);
1063                               key_revoke_dlg_proc, (LPARAM)&k,          }
1064                               _("Key Revocation"), IDS_WINPT_KEYREVOKE);      }
1065              return TRUE;      keylist_sort (kmi->lv, kmi->keylist_sortby);
1066                    update_status_bar (kmi->statbar, kmi->lv);
1067          case ID_KEYMISC_TRUSTPATH:      keyring_check_last_access ();
1068              idx = listview_get_curr_pos( kmi->lv );  }
1069              if( idx == -1 ) {  
1070                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  
1071                  return TRUE;  /* Reload the key cache. */
1072              }  static void
1073              listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 );  keycache_reload (HWND dlg)
1074              listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid -1 );  {      
1075              if( km_check_for_seckey( kmi->lv, idx, NULL ) ) {      refresh_cache_s rcs;
1076                  msg_box( dlg, _("It does not make any sense with a key pair!"), _("Key Manager"), MB_OK );  
1077                  return FALSE;      memset (&rcs, 0, sizeof rcs);
1078              }      rcs.kr_reload = rcs.kr_update = 1;
1079              memset (&k, 0, sizeof (k));      rcs.tr_update = 0;
1080              k.keyid = keyid;      DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,                                        
1081              k.uid = uid;                      keycache_dlg_proc, (LPARAM)&rcs);
1082              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,  }
1083                                keytrust_dlg_proc, (LPARAM)&k,  
1084                                _("List Trust Path"), IDS_WINPT_KEYTRUST );  
1085              return TRUE;  /* Check if the secret keyring contains at least one
1086                   key with ultimate trust.
1087          case ID_KEYMISC_CHECKSIGS:     Return value: 0 on success. */
1088              idx = listview_get_curr_pos (kmi->lv);  int
1089              if( idx == -1 ) {  check_ultimate_trusted_key (gpg_keycache_t _sec)
1090                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  {
1091                  return FALSE;      struct keycache_s *n;
1092              }      int nkeys = 0;
1093              listview_get_item_text (kmi->lv, idx, 0, uid, DIM (uid)-1);  
1094              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);      for (n = _sec->item; n; n = n->next) {
1095              memset (&k, 0, sizeof (k));          if (n->pubpart &&
1096              k.keyid = keyid;              n->pubpart->key->owner_trust == GPGME_VALIDITY_ULTIMATE)
1097              k.uid = uid;              return 0;
1098              k.ctx = (gpgme_key_t)listview_get_item2 (kmi->lv, idx);          nkeys++;
1099              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG, dlg,      }
1100                                keysig_dlg_proc, (LPARAM)&k,  
1101                                _("Key Signature List" ), IDS_WINPT_KEYSIG);      /* if we do not have any secret keys, it does not make sense
1102              return TRUE;         to return an error. */
1103                    if (nkeys == 0)
1104          case ID_KEYMISC_PROPS:          return 0;
1105              idx = listview_get_curr_pos( kmi->lv );      return -1;
1106              if( idx == -1 ) {  }
1107                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  
1108                  return FALSE;  
1109              }  static void
1110              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);  reload_keylist (struct km_info_s *kmi)
1111              listview_get_item_text (kmi->lv, idx, 2, type, DIM (type)-1);  {
1112              memset (&k, 0, sizeof (k));      gpg_keycache_t c;
1113              k.key_pair = 0;  
1114              k.keyid = keyid;      c = keycache_get_ctx (1);
1115              if( !strcmp( type, "pub/sec" ) || !strcmp( type, "pub/crd" ) )      keycache_reload (kmi->dlg);
1116                  k.key_pair = 1;      keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby);
1117              k.callback.ctl = kmi->lv;      update_status_bar (kmi->statbar, kmi->lv);
1118              k.callback.idx = idx;      keyring_check_last_access ();
1119              k.is_v3 = km_key_is_v3 (kmi->lv, idx);  }
1120              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,  
1121                                keyprops_dlg_proc, (LPARAM)&k,  
1122                                _("Key Properties"), IDS_WINPT_KEYPROPS );  /* Reload the entire key cache and update the listview. */
1123              if (k.callback.new_val != 0) {  static void
1124                  t = get_key_trust_str (k.callback.new_val);  reload_keycache (struct km_info_s *kmi)
1125                  listview_add_sub_item (kmi->lv, idx, 6, t);  {
1126              }      refresh_cache_s rcs = {0};
1127              return TRUE;      gpg_keycache_t c;
1128                
1129          case ID_KEYMISC_RECACHE:      rcs.kr_reload = rcs.kr_update = 1;
1130              /* If there is already a reload request, don't bother the user with a message. */      rcs.tr_update = 0;
1131              if( keycache_get_reload() == 1 )      DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, kmi->dlg,
1132                  idx = IDYES;                      keycache_dlg_proc, (LPARAM)&rcs);
1133              else {      c = keycache_get_ctx (1);
1134                  char t[256];      keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby);
1135                  _snprintf( t, sizeof t -1,      update_status_bar (kmi->statbar, kmi->lv);
1136                             _("This is only useful when the keyring has been "      SetForegroundWindow (kmi->dlg);
1137                               "modified (sign a key...).\n"  }
1138                               "Do you really want to reload the keycache?") );  
1139                  idx = msg_box( dlg, t, _("Key Manager"), MB_YESNO );  
1140              }  /* Handle all import request. */
1141              if( idx == IDYES ) {  static void
1142                  rcs.kr_reload = rcs.kr_update = 1;  km_gui_import (struct km_info_s *kmi, int cmd_id, void *param)
1143                  rcs.tr_update = 0;  {
1144                  DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,      int newkeys=0, newsks=0;
1145                                  keycache_dlg_proc, (LPARAM)&rcs );      int err = 0;
1146                  c = keycache_get_ctx( 1 );  
1147                  if( !c )      switch (cmd_id) {
1148                      BUG( dlg );      case ID_KEYMISC_PASTE:
1149                  keylist_reload( kmi->lv, c, KEYLIST_LIST, KEY_SORT_USERID );          err = km_clip_import (kmi->dlg, &newkeys, &newsks);
1150                  refresh_keys = 0;          break;
1151              }  
1152              return TRUE;      case ID_KEYMISC_IMPORT:
1153                        err = km_file_import (kmi->dlg, NULL, &newkeys, &newsks);
1154          case ID_KEYMISC_REBUILD:          break;
1155              name=NULL;  
1156              gpg_rebuild_cache (&name);      case WM_DROPFILES:
1157              if (name) {          err = km_dropped_file_import (kmi->dlg, (HDROP)param,
1158                  char *p = strchr (name, '\n');                                        &newkeys, &newsks);
1159                  show_msg (dlg, 2000, p? name + (p-name)+1 : name);          break;
1160                  free (name);  
1161              }      default:
1162              return TRUE;          err = 1;
1163                        break;
1164          case ID_KEYMISC_NEWKEY:      }
1165              memset (&genkey, 0, sizeof (genkey));  
1166              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,      if (!err && !newsks && (newkeys > 0 && newkeys < KM_PRELOAD_KEYS))
1167                                keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),          refresh_keylist (kmi);
1168                                IDS_WINPT_KEYGEN);      else if (!err) /* avoid to spawn too much processes. */
1169              if (genkey.newkey != NULL)          reload_keylist (kmi);
1170                  keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);  
1171              return TRUE;      SetForegroundWindow (kmi->dlg);
1172    }
1173          case ID_KEYMISC_CARDNEW:  
1174              if( !scard_support ) {  
1175                  msg_box( dlg, _("Smart Card support is not available."), _("Key Manager"), MB_INFO );  /* Dialog box procedure for the Key Manager. */
1176                  return TRUE;  BOOL CALLBACK
1177              }  keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1178              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,  {
1179                                card_keygen_dlg_proc, NULL, _("Card Key Generation"),      struct km_info_s *kmi = NULL;
1180                                IDS_WINPT_CARD_KEYGEN );      HWND kl;
1181              /* XXX: use new code */      HMENU hm;
1182              if( keycache_get_reload() )      struct keycache_s *kci;
1183                  send_cmd_id( dlg, ID_KEYMISC_RECACHE );      gpg_keycache_t c;
1184              return TRUE;      gpgme_key_t key;
1185        struct genkey_s genkey;
1186          case ID_KEYMISC_KEYWIZARD:      struct winpt_key_s k = {0};
1187              memset (&genkey, 0, sizeof (genkey));      struct URL_ctx_s *url;
1188              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg,      char type[32], *name;
1189                                keygen_wizard_dlg_proc, (LPARAM)&genkey, _("Key Generation Wizard"),      const char *t, *host;
1190                                IDS_WINPT_KEYWIZARD);      WORD port = 0;
1191              if (genkey.newkey != NULL)      int l_idx = 0, i=0, rc;
1192                  keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);  
1193              return TRUE;      if ((msg != WM_INITDIALOG)
1194                        && ((kmi = (struct km_info_s*)GetWindowLong (dlg, GWL_USERDATA)) == NULL))
1195          case ID_KEYMISC_SENDRECV:          return FALSE;
1196              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,      
1197                                keyserver_dlg_proc, NULL, _("Keyserver Access"),      /* handle dynamic popup items in the keyserver menu. */
1198                                IDS_WINPT_KEYSERVER );      if (msg == WM_COMMAND && LOWORD (wparam) >= WM_APP &&
1199              return TRUE;                               LOWORD (wparam) <= WM_APP+MAX_KEYSERVERS) {
1200                        l_idx = LOWORD (wparam)-WM_APP;
1201          case ID_KEYMISC_GPGPREFS:          if (l_idx < 0)
1202              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg,              return TRUE;
1203                                gpgprefs_dlg_proc, NULL, _("GnuPG Preferences"),          host = kserver_get_hostname (l_idx, 0, &port);
1204                                IDS_WINPT_GPGPREFS );          if (host != NULL)
1205              return TRUE;              km_send_to_keyserver (kmi->lv, dlg, host, port);
1206                        return TRUE;
1207          case ID_KEYMISC_GPGOPT:      }
1208              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,  
1209                                gpgopt_dlg_proc, NULL, _("GnuPG Options" ),      switch (msg) {
1210                                IDS_WINPT_GPGOPT );      case WM_INITDIALOG:
1211              return TRUE;          kmi = new struct km_info_s;
1212                        memset (kmi, 0, sizeof (struct km_info_s));
1213          case ID_KEYMISC_IMPORT:          kmi->lv_idx = -1;
1214              t = get_filename_dlg (dlg, FILE_OPEN, _("Choose Name of the Key File"), NULL, NULL);          kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);
1215              if (t)          imagelist_load (dlg);
1216                  km_file_import (dlg, t);          translate_menu_strings (dlg);
1217              return TRUE;          SetWindowText (dlg, _("Key Manager"));
1218    
1219          case ID_KEYMISC_IMPORT_HTTP:          c = keycache_get_ctx (KEYCACHE_PUB);
1220              url = (struct URL_ctx_s*)get_http_file_dlg (dlg);          if (!c)
1221              if (url->cancel == 0)              BUG (NULL);
1222                  km_http_import (dlg, url->url);          kl = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
1223              delete url; url=NULL;          kmi->keylist_sortby = KEY_SORT_USERID;
1224              break;          Header_SetImageList(ListView_GetHeader (kl), glob_imagelist);
1225                        kmi->lv = keylist_load (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST), c,
1226          case ID_KEYMISC_EXPORT:                                  NULL, KEYLIST_LIST, kmi->keylist_sortby);
1227              idx = listview_get_curr_pos (kmi->lv);          if (check_ultimate_trusted_key (keycache_get_ctx (0))) {
1228              if (idx == -1) {              msg_box (dlg, _("No ultimately trusted key found.\n"
1229                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );                              "Please set at least one secret key to ultimate trust."),
1230                  return TRUE;                              _("Key Manager"), MB_WARN);
1231              }          }
1232              if (listview_count_items (kmi->lv, 1) > 1)          /* init subclassing for the listview */
1233                  name = m_strdup ("Exported_GPG_Keys.asc");          keylist_proc.opaque = kmi;
1234              else {          keylist_proc.dlg = dlg;
1235                  listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);          keylist_proc.current = (WNDPROC)keylist_subclass_proc;
1236                  name = gen_export_filename (keyid, 0);          keylist_proc.old = (WNDPROC)GetWindowLong(kl, GWL_WNDPROC);
1237              }          if (keylist_proc.old) {
1238              t = get_filename_dlg (dlg, FILE_SAVE, _("Choose Name for Key File"), NULL, name);              if( !SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) {
1239              free_if_alloc (name);                  msg_box (dlg, _("Could not set keylist window procedure."),
1240              if (t == NULL)                           _("Key Manager"), MB_ERR);
1241                  return TRUE;                  BUG (NULL);
1242              km_file_export (dlg, kmi->lv, t);              }
1243              return TRUE;          }
1244                        kmi->statbar = setup_status_bar (dlg, kmi->lv);
1245          case ID_KEYMISC_EXPORT_PRIVKEY:          SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);
1246              idx = listview_get_curr_pos( kmi->lv );          kmi->toolbar = load_toolbar (dlg, kmi);
1247              if( idx == -1 ) {          kmi->dlg = dlg;
1248                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  
1249                  return TRUE;          do_center_window (dlg, kmi);
1250              }          do_resize_window (dlg, kmi);
1251              if( !km_check_for_seckey( kmi->lv, idx, NULL ) ) {          update_ui_items (dlg, kmi->lv);
1252                  msg_box( dlg, _("There is no corresponding secret key for this key."),          restore_column_info (kmi);
1253                          _("Key Manager"), MB_ERR );          keylist_sort (kmi->lv, kmi->keylist_sortby);
1254                  return TRUE;  
1255              }          SetDlgItemText (dlg, IDC_KEYMISC_GTEXT, _("Groups"));
1256              if( listview_count_items( kmi->lv, 1 ) > 1 ) {          SetDlgItemText (dlg, ID_GROUP_SHOW, _("&Show"));
1257                  msg_box( dlg, _("You can only export one secret key."), _("Key Manager"), MB_ERR );          SetDlgItemText (dlg, ID_GROUP_NEW, _("&New..."));
1258                  return TRUE;          SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst,
1259              }                        (LPCTSTR)IDI_WINPT));
1260              idx = msg_box( dlg,          SetForegroundWindow (dlg);
1261                            _("This operation will export your *SECRET* key!\n\n"          kmi->magic = SetTimer (dlg, 1, 1000, NULL);
1262                              "Never send this key to ANYONE, it should be available\n"          return TRUE;
1263                              "ONLY on your machine and you may use this function\n"  
1264                              "to copy the key to a safe place.\n\n"      case WM_TIMER:
1265                              "Do you really want to export the key?"),          KillTimer (dlg, kmi->magic);
1266                            _("WARNING"), MB_INFO|MB_YESNO );          SetForegroundWindow (dlg);
1267              if( idx == IDYES ) {          break;
1268                  idx = listview_get_curr_pos( kmi->lv );          
1269                  listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof (keyid)-8 );      case WM_DESTROY:
1270                  name = gen_export_filename (keyid, 1);          save_column_info (kmi);
1271                  t = get_filename_dlg (dlg, FILE_SAVE, _("Choose Name for Key File"), NULL, name);          if (kmi->lv) {
1272                  if (t != NULL)                        keylist_delete (kmi->lv);
1273                      km_privkey_export (dlg, kmi->lv, t);              kmi->lv = NULL;      
1274              }          }
1275              break;          imagelist_destroy ();
1276    
1277          case ID_KEYMISC_INFO:          ltoa (kmi->pos_x, type, 10);
1278              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd,          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type);
1279                                about_winpt_dlg_proc, NULL, _("About WinPT"),          ltoa (kmi->pos_y, type, 10);
1280                                IDS_WINPT_ABOUT );          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type);
1281              break;          /* XXX: store window size. */
1282            
1283          case ID_KEYMISC_HELP:          /* Remove runtime information. This should be the last action taken here. */
1284              ShellExecute (dlg, "open", "winpt.chm", NULL, NULL, SW_SHOW);          delete kmi;
1285              break;          kmi = NULL;
1286            SetWindowLong (dlg, GWL_USERDATA, 0);
1287          case ID_KEYMISC_OT:          return FALSE;
1288              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST, glob_hwnd,  
1289                                ownertrust_dlg_proc, NULL,      case WM_MOVE:
1290                                _("Ownertrust"), IDS_WINPT_OWNERTRUST );          RECT r;
1291              break;          GetWindowRect (dlg, &r);
1292            kmi->pos_x = r.left;
1293          case ID_KEYMISC_EDITKEY:          kmi->pos_y = r.top;    
1294              idx = listview_get_curr_pos (kmi->lv);          break;
1295              if (idx == -1)          
1296                  break;  
1297              listview_get_item_text (kmi->lv, idx, 1, keyid, sizeof (keyid)-1);      case WM_RBUTTONUP:
1298              /* XXX: pub/crd = secret key does not work */          do_create_minpopup (dlg);
1299              memset (&k, 0, sizeof (k));          break;
1300              k.is_protected = km_check_if_protected (kmi->lv, idx);  
1301              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);      case WM_NOTIFY:            
1302              k.keyid = keyid;          NMHDR *notify;
1303              k.is_v3 = km_key_is_v3 (kmi->lv, idx);          POINT p;
1304              k.flags = km_get_key_status (kmi->lv, idx);          HMENU popup;
1305              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,          
1306                                keyedit_main_dlg_proc, (LPARAM)&k,          notify = (NMHDR *)lparam;
1307                                _("Key Edit"), IDS_KEYCTX_EDIT);          if (!notify)
1308              if (k.update)              break;
1309                  update_key (kmi->lv,  idx, keyid, 1);          switch (notify->code) {
1310              break;          case TBN_QUERYDELETE:
1311                            SetWindowLong (dlg, DWL_MSGRESULT, TRUE);
1312          case ID_KEYMISC_COPY:              return TRUE;
1313              km_index = listview_get_curr_pos (kmi->lv);          
1314              km_clip_export (dlg, kmi->lv);          case TBN_QUERYINSERT:
1315              break;              SetWindowLong (dlg, DWL_MSGRESULT, TRUE);
1316                            return TRUE;
1317          case ID_KEYMISC_SELALL:  
1318              listview_select_all (kmi->lv);          case TBN_GETBUTTONINFO:
1319              break;              LPTBNOTIFY lpTbNotify;
1320                lpTbNotify = (LPTBNOTIFY)lparam;
1321          case ID_KEYMISC_PASTE:              if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) {
1322              km_index = -1;                  lpTbNotify->tbButton.iBitmap = imagelist_getindex (myb[lpTbNotify->iItem].icon);
1323              km_clip_import (dlg);                  lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command;
1324              break;                  lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;
1325                                lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;
1326          case ID_KEYCTX_SETPREFKS:                  lpTbNotify->tbButton.iString = 0;
1327              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM(keyid)-1);                  strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText);
1328              memset (&k, 0, sizeof (k));                  SetWindowLong(dlg, DWL_MSGRESULT, TRUE);
1329              k.keyid = keyid;              }
1330              keyedit_set_pref_keyserver (&k, dlg);              return TRUE;
1331              break;  
1332            case TBN_RESET: /* Restore last saved toolbar status */
1333          case ID_KEYMISC_REFRESH_KEYS:              TBSAVEPARAMS tbsp;
1334              if (listview_count_items (kmi->lv, 1) == 0) {  
1335                  msg_box (dlg, _("No key was selected, select all by default."), _("Key Manager"), MB_INFO);              tbsp.hkr = HKEY_CURRENT_USER;
1336                  listview_select_all (kmi->lv);              tbsp.pszSubKey = "Software\\WinPT";
1337              }              tbsp.pszValueName = "KM_toolbar";
1338              km_refresh_from_keyserver (kmi->lv, dlg);              SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp);
1339              break;              break;
1340                            
1341          /** Context menu **/          case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */
1342          case ID_KEYCTX_EDIT:              tbsp.hkr = HKEY_CURRENT_USER;
1343              send_cmd_id( dlg, ID_KEYMISC_EDITKEY );              tbsp.pszSubKey = "Software\\WinPT";
1344              break;              tbsp.pszValueName = "KM_toolbar";
1345                SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
1346          case ID_KEYCTX_PROPS:              break;
1347              send_cmd_id( dlg, ID_KEYMISC_PROPS );  
1348              break;          case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */
1349                tbsp.hkr = HKEY_CURRENT_USER;
1350          case ID_KEYCTX_UIDS:              tbsp.pszSubKey = "Software\\WinPT";
1351              send_cmd_id( dlg, ID_KEYMISC_UID );              tbsp.pszValueName = "KM_toolbar";
1352              break;              SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
1353                break;
1354          case ID_KEYCTX_SIGN:  
1355              send_cmd_id( dlg, ID_KEYMISC_SIGN );          case TTN_GETDISPINFO:
1356              break;              LPTOOLTIPTEXT lpttt;
1357                lpttt = (LPTOOLTIPTEXT)lparam;
1358          case ID_KEYCTX_DEL:  
1359              send_cmd_id (dlg, ID_KEYMISC_DELETE);              lpttt->hinst = NULL;
1360              break;              switch (lpttt->hdr.idFrom) {
1361                case ID_KEYMISC_KEYWIZARD:
1362          case ID_KEYCTX_REV:                  lpttt->lpszText = (char*)_("Generate new key pair");
1363              send_cmd_id( dlg, ID_KEYMISC_REVCERT );                  break;
1364              break;  
1365                case ID_KEYMISC_SENDRECV:
1366          case ID_KEYCTX_SENDMAIL:                  lpttt->lpszText = (char*)_("Search for a specific key");
1367              km_send_to_mail_recipient (kmi->lv, dlg);                  break;
1368              break;  
1369                case ID_KEYMISC_DELETE:
1370          case ID_KEYCTX_KS_DEFAULT:                  lpttt->lpszText = (char *)_("Delete key from keyring");
1371              host = kserver_get_hostname (0, -1, &port);                  break;
1372              km_send_to_keyserver (kmi->lv, dlg, host, port);  
1373              break;              case ID_KEYMISC_PROPS:
1374                    lpttt->lpszText = (char *)_("Show key properties");
1375          case ID_KEYCTX_ADDKEY:                  break;
1376              idx = listview_get_curr_pos (kmi->lv);  
1377              listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1);              case ID_KEYMISC_SIGN:
1378              memset (&k, 0, sizeof (k));                  lpttt->lpszText = (char *)_("Sign key");
1379              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);                  break;
1380              k.is_protected = km_check_if_protected (kmi->lv, idx);  
1381              k.keyid = keyid;              case ID_KEYCTX_COPY:
1382              keyedit_add_subkey (&k, dlg, NULL);                  lpttt->lpszText = (char *)_("Copy key to clipboard");
1383              if (k.update)                  break;
1384                  update_key (kmi->lv, idx, keyid, 1);  
1385              break;              case ID_KEYCTX_PASTE:
1386                    lpttt->lpszText = (char*)_("Paste key from clipboard");
1387          case ID_KEYCTX_ADDUID:                  break;
1388              idx = listview_get_curr_pos (kmi->lv);  
1389              listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1);              case ID_KEYMISC_IMPORT:
1390              memset (&k, 0, sizeof (k));                  lpttt->lpszText = (char *)_("Import key to keyring");
1391              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);                  break;
1392              k.is_protected = km_check_if_protected (kmi->lv, idx);  
1393              k.keyid = keyid;              case ID_KEYMISC_EXPORT:
1394              keyedit_add_userid (&k, dlg, NULL);                  lpttt->lpszText = (char *)_("Export key to a file");
1395              if (k.update)                  break;
1396                  update_key (kmi->lv, idx, keyid, 1);              }
1397              break;              return TRUE;
1398                
1399          case ID_KEYCTX_ADDREV:          case LVN_ITEMCHANGED:
1400              idx = listview_get_curr_pos (kmi->lv);              if (((LPNMLISTVIEW)lparam)->uNewState) { /* item selected? */
1401              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);                  kmi->lv_idx = listview_get_curr_pos (kmi->lv);
1402              memset (&k, 0, sizeof (k));                  update_ui_items (dlg, kmi->lv);
1403              k.keyid = keyid;                  return TRUE;
1404              k.is_protected = km_check_if_protected (kmi->lv, idx);              }
1405              k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL );              break;
1406              keyedit_add_revoker (&k, dlg);  
1407              if (k.update)          case NM_RCLICK:
1408                  update_key (kmi->lv, idx, keyid, 1);              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1409              break;                  l_idx =listview_get_curr_pos (kmi->lv);
1410                    if (l_idx == -1)
1411          case ID_KEYCTX_ADDPHOTO:                      return TRUE; /* Popup only when a item was selected */              
1412              idx = listview_get_curr_pos (kmi->lv);                  GetCursorPos (&p);
1413              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);                  hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));
1414              memset (&k, 0, sizeof (k));                  popup = GetSubMenu (hm, 0);
1415              k.keyid = keyid;                  translate_popupmenu_strings (popup);
1416              k.is_protected = km_check_if_protected (kmi->lv, idx);  
1417              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);                  if (km_check_for_seckey (kmi->lv, l_idx, &i))
1418              keyedit_add_photo (&k, dlg);                      set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);
1419              if (k.update)                  if (i == 0)
1420                  update_key (kmi->lv, idx, keyid, 1);                      set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);
1421              break;                  if (!km_check_for_seckey (kmi->lv, l_idx, NULL) ||
1422                        (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED)) {
1423          case ID_KEYCTX_KS_NL:                      set_menu_state (popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED);
1424          case ID_KEYCTX_KS_PL:                      set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
1425          case ID_KEYCTX_KS_AT:                      set_menu_state (popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED);
1426          case ID_KEYCTX_KS_DE:                      set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);
1427          case ID_KEYCTX_KS_DK:                      set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED );
1428          case ID_KEYCTX_KS_CZ:                      set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED);
1429          case ID_KEYCTX_KS_ES:                  }
1430          case ID_KEYCTX_KS_UK:                  else if (km_check_for_seckey (kmi->lv, l_idx, NULL) &&
1431              host = kserver_get_hostname (LOWORD (wparam) - 40107, 0, &port);                           km_key_is_v3 (kmi->lv, l_idx)) {
1432              km_send_to_keyserver (kmi->lv, dlg, host, port);                      /* PGP 2 keys, version 3 have no no support for photo-id's,
1433              break;                         designated revokers and secondary keys. */
1434                        set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
1435          case ID_KEYCTX_RECVFROM:                      set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);
1436              km_refresh_from_keyserver (kmi->lv, dlg);                      set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED);
1437              break;                  }
1438                    if (km_get_key_status( kmi->lv, l_idx ) & KM_FLAG_DISABLED)
1439          case ID_KEYCTX_UID_COPY:                      set_menu_state (popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED);
1440              /* XXX: add generic function to support multiple selection                  else
1441                      with a callback */                      set_menu_state (popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED);
1442              idx = listview_get_curr_pos( kmi->lv );                  if (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED ||
1443              listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid-1 );                      km_get_key_status (kmi->lv, l_idx) & KM_FLAG_EXPIRED)
1444              set_clip_text( NULL, uid, strlen( uid ) );                      set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);
1445              break;                  if (!clip_contains_pgpkey ())
1446                        set_menu_state (popup, ID_KEYCTX_PASTE, MF_DISABLED|MF_GRAYED);
1447          case ID_KEYCTX_KEYID_COPY:                  if (mapi_init ())
1448              idx = listview_get_curr_pos( kmi->lv );                      set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);
1449              listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 );                  if (!secret_key_available ())
1450              set_clip_text( NULL, uid, strlen( uid ) );                      set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);
1451              break;  
1452                    /* Override 'Default Keyserver' with the actual name. */
1453          case ID_KEYCTX_FPR_COPY:                  host = kserver_get_hostname (0, -1, &port);
1454              idx = listview_get_curr_pos( kmi->lv );                  if (!host)
1455              key = (gpgme_key_t) listview_get_item2 (kmi->lv, idx);                              host = DEF_HKP_KEYSERVER;
1456              if (key) {                  set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);
1457                  const char * s = get_key_fpr (key);                  {
1458                  set_clip_text (NULL, s? s : "", s? strlen (s): 0);                      HMENU ks = GetSubMenu (popup, 19);
1459              }                      for (i=0; server[i].name != NULL; i++)                      
1460              break;                          insert_menu_item (ks, i+2, WM_APP+i, server[i].name);
1461                    }
1462          case ID_KEYCTX_KINFO_COPY:                  popup_gpg_readonly (dlg, popup);
1463              idx = listview_get_curr_pos( kmi->lv );                  if (listview_count_items (kmi->lv, 1) > 1)
1464              listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 );                      popup_multiple (dlg, popup);
1465              km_set_clip_info( uid );                          TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
1466              break;                  DestroyMenu (popup);
1467                    DestroyMenu (hm);
1468          case ID_KEYCTX_COPY:                  return TRUE;
1469              km_index = listview_get_curr_pos (kmi->lv);              }
1470              km_clip_export (dlg, kmi->lv);              break;
1471              break;  
1472            case LVN_COLUMNCLICK:
1473          case ID_KEYCTX_PASTE:                if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1474              km_index = -1;                  NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
1475              km_clip_import (dlg);                  int sortby = 0;
1476              break;                  switch (nft->iSubItem) {
1477                    case 0:  sortby = KEY_SORT_USERID; break;
1478          case ID_KEYCTX_DISABLE:                  case 1:  sortby = KEY_SORT_KEYID; break;
1479              idx = listview_get_curr_pos (kmi->lv);                  case 2:  sortby = KEY_SORT_IS_SECRET; break;
1480              km_enable_disable_key (kmi->lv, dlg, idx, 0);                  case 3:  sortby = KEY_SORT_LEN; break;
1481              break;                  case 5:  sortby = KEY_SORT_VALIDITY; break;
1482                    case 6:  sortby = KEY_SORT_OTRUST; break;
1483          case ID_KEYCTX_ENABLE:                  case 7:  sortby = KEY_SORT_CREATED; break;
1484              idx = listview_get_curr_pos (kmi->lv);                  case 8:  sortby = KEY_SORT_ALGO; break;
1485              km_enable_disable_key (kmi->lv, dlg, idx, 1);                  default: return TRUE; //sortby = KEY_SORT_USERID; break;
1486              break;                  }
1487    
1488          case ID_KEYCTX_LISTSIGS:                  if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)
1489              send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS);                      kmi->keylist_sortby ^= KEYLIST_SORT_DESC;
1490              break;                  else
1491                        kmi->keylist_sortby = sortby;
1492          case ID_KEYCTX_MAXTRUST:                  keylist_sort (kmi->lv, kmi->keylist_sortby);
1493              idx = listview_get_curr_pos (kmi->lv);                  return TRUE;
1494              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);              }
1495              rc = km_set_implicit_trust (dlg, kmi->lv, idx);              break;
1496              if (!rc)          }
1497                  update_key (kmi->lv, idx, keyid, 0);          break;
1498              break;  
1499        case WM_WINDOWPOSCHANGING:
1500          case ID_KEYCTX_SETDEFKEY:          if (((WINDOWPOS*)lparam)->cx < 400)
1501              idx = listview_get_curr_pos (kmi->lv);              ((WINDOWPOS*)lparam)->cx = 400;
1502              if (!km_check_key_status (kmi->lv, idx)) {          if (((WINDOWPOS*)lparam)->cy < 200)
1503                  listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);              ((WINDOWPOS*)lparam)->cy = 200;
1504                  rc = set_gnupg_default_key (keyid);           return TRUE;
1505                  if (rc)          
1506                      msg_box( dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);      case WM_SIZE:
1507                  km_update_default_key_str (kmi->statbar);          do_resize_window (dlg, kmi);
1508              }          return TRUE;
1509              break;          
1510        case WM_SYSCOMMAND:
1511          #if 0 /* XXX */          if (LOWORD (wparam) == SC_CLOSE)
1512          case ID_GROUP_NEW:              EndDialog (dlg, TRUE);
1513              memset (&gcb, 0, sizeof (gcb));          return FALSE;
1514              gcb.gc = gc;          
1515              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GROUP, glob_hwnd,      case WM_MENUSELECT:
1516                               group_manager_dlg_proc, (LPARAM)&gcb, _("New Group"),          change_edit_menu (kmi->lv, (HMENU)lparam, LOWORD (wparam));
1517                               IDS_WINPT_GROUP);          change_key_menu ((HMENU)lparam, LOWORD (wparam));
1518              if( gcb.use_name )          break;
1519                  treeview_add_item( GetDlgItem(dlg, IDC_KEYMISC_GROUP), NULL, gcb.name );  
1520              return TRUE;      case WM_INITMENUPOPUP:
1521                        if ((UINT)LOWORD (lparam) == 3) {
1522          case ID_GROUP_PASTE:              HMENU h = (HMENU)wparam;
1523              km_groups_add (gc, kmi->lv, km_index);              set_menu_text_bypos (h, 0, _("New"));
1524              break;          }
1525                        /* XXX: before we can use it, we need to find a way to
1526          case ID_GROUP_DELETE:                  update the gpg access timestamp after each operation.
1527              km_groups_del (gc);          if (keyring_check_last_access ())
1528              break;              reload_keylist (kmi);
1529          #endif          */
1530          }          return FALSE;
1531            
1532          break;      case WM_COMMAND:
1533      }          /* Allow at least 'Exit' in such a case. */
1534                if (gnupg_access_keyring (1) && LOWORD (wparam) != ID_KEYMISC_QUIT) {
1535      return FALSE;              msg_box (dlg, _("Could not access public keyring"),
1536  }                       _("Key Manager"), MB_ERR);
1537                return FALSE;
1538            }
1539    
1540            switch (LOWORD (wparam)) {
1541            case ID_KEYMISC_QUIT:
1542                EndDialog (dlg, TRUE);
1543                return TRUE;
1544            
1545            case ID_KEYMISC_FIND:
1546                km_find_key (dlg, kmi->lv);
1547                break;
1548    
1549            case ID_KEYMISC_DELETE:
1550            case ID_KEYMISC_DELETE2:
1551                if (!km_delete_keys (kmi->lv, dlg))
1552                    update_status_bar (kmi->statbar, kmi->lv);
1553                return TRUE;
1554                
1555            case ID_KEYMISC_SIGN:
1556                if (kmi->lv_idx == -1) {
1557                    msg_box (dlg, _("Please select a key."),  
1558                             _("Key Manager"), MB_ERR);
1559                    return TRUE;
1560                }
1561                if (km_check_key_status (kmi->lv, kmi->lv_idx))
1562                    return TRUE;
1563                km_get_key (kmi->lv, kmi->lv_idx, &k);
1564                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,
1565                                  keysign_dlg_proc, (LPARAM)&k,
1566                                  _("Key Signing"), IDS_WINPT_KEYSIGN);
1567                if (k.update)
1568                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1569                return TRUE;
1570                
1571            case ID_KEYMISC_REVCERT:
1572                if (kmi->lv_idx == -1) {
1573                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1574                    return TRUE;
1575                }
1576                    
1577                {
1578                    char state[64];
1579                    listview_get_item_text (kmi->lv, kmi->lv_idx, 5,
1580                                            state, sizeof (state) -1);
1581                    if (strchr (state, 'R' )) {
1582                        msg_box (dlg, _("Key already revoked!"),
1583                                 _("Key Manager"), MB_INFO);
1584                        return TRUE;
1585                    }
1586                }
1587    
1588                km_get_key (kmi->lv, kmi->lv_idx, &k);
1589                if (!k.key_pair) {
1590                    msg_box (dlg, _("There is no secret key available!"),
1591                            _("Key Manager"), MB_ERR);
1592                    return TRUE;
1593                }
1594                dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,
1595                                 key_revoke_dlg_proc, (LPARAM)&k,
1596                                 _("Key Revocation Cert"), IDS_WINPT_KEYREVOKE);
1597                return TRUE;
1598                
1599            case ID_KEYMISC_TRUSTPATH:
1600                if (kmi->lv_idx == -1) {
1601                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1602                    return TRUE;
1603                }
1604                km_get_key (kmi->lv, kmi->lv_idx, &k);
1605                if (!k.key_pair) {
1606                    msg_box (dlg, _("It does not make any sense with a key pair!"),
1607                             _("Key Manager"), MB_ERR);
1608                    return TRUE;
1609                }
1610                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,
1611                                  keytrust_dlg_proc, (LPARAM)&k,
1612                                  _("List Trust Path"), IDS_WINPT_KEYTRUST);
1613                return TRUE;
1614                
1615            case ID_KEYMISC_CHECKSIGS:          
1616                if (kmi->lv_idx == -1) {
1617                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1618                    return TRUE;
1619                }
1620                km_get_key (kmi->lv, kmi->lv_idx, &k);
1621                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG_TREE, dlg,
1622                                  sigtree_dlg_proc, (LPARAM)&k,
1623                                  _("Key Signature List"), IDS_WINPT_KEYSIG);
1624                if (k.update)
1625                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1626                if (updated_keys_avail ())
1627                    refresh_keylist (kmi);
1628                return TRUE;
1629                
1630            case ID_KEYMISC_PROPS:      
1631                if (kmi->lv_idx == -1) {
1632                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1633                    return TRUE;
1634                }
1635                km_get_key (kmi->lv, kmi->lv_idx, &k);
1636                k.callback.ctl = kmi->lv;
1637                k.callback.idx = kmi->lv_idx;
1638                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,
1639                                  keyprops_dlg_proc, (LPARAM)&k,
1640                                  _("Key Properties"), IDS_WINPT_KEYPROPS);
1641                if (k.update)
1642                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, k.key_pair);
1643                return TRUE;
1644                
1645            case ID_KEYMISC_RECACHE:
1646                if (updated_keys_avail ())
1647                    l_idx = IDYES;
1648                else {
1649                    l_idx = log_box (_("Key Manager"), MB_YESNO,
1650                               _("This is only useful when the keyring has been "
1651                                 "modified (sign a key...).\n"
1652                                 "Do you really want to reload the keycache?"));
1653                }
1654                if (l_idx == IDYES)
1655                    reload_keycache (kmi);
1656                return TRUE;
1657                
1658            case ID_KEYMISC_REBUILD:
1659                name = NULL;
1660                gpg_rebuild_cache (&name);
1661                if (name != NULL) {
1662                    char *line = strchr (name, '\n');
1663                    show_msg (dlg, 2000, line? name + (line-name)+1 : name);
1664                    safe_free (name);
1665                }
1666                SetForegroundWindow (dlg);
1667                return TRUE;
1668                
1669            case ID_KEYMISC_NEWKEY:
1670                memset (&genkey, 0, sizeof (genkey));
1671                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,
1672                                  keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),
1673                                  IDS_WINPT_KEYGEN);
1674                if (genkey.cancel == 0)
1675                    refresh_keylist (kmi);
1676                return TRUE;
1677    
1678            case ID_KEYMISC_CARDNEW:
1679                if (!scard_support) {
1680                    msg_box (dlg, _("Smart Card support is not available."),
1681                             _("Key Manager"), MB_INFO);
1682                    return TRUE;
1683                }
1684                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,
1685                                  card_keygen_dlg_proc, 0, _("Card Key Generation"),
1686                                  IDS_WINPT_CARD_KEYGEN);
1687                if (updated_keys_avail ())
1688                    send_cmd_id (dlg, ID_KEYMISC_RECACHE);
1689                return TRUE;
1690    
1691            case ID_KEYMISC_KEYWIZARD:
1692                memset (&genkey, 0, sizeof (genkey));
1693                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg,
1694                                  keygen_wizard_dlg_proc, (LPARAM)&genkey,
1695                                  _("Key Generation Wizard"),
1696                                  IDS_WINPT_KEYWIZARD);
1697                if (genkey.cancel == 0)
1698                    refresh_keylist (kmi);
1699                return TRUE;
1700                
1701            case ID_KEYMISC_SENDRECV:
1702                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,
1703                                  keyserver_dlg_proc, 0, _("Keyserver Access"),
1704                                  IDS_WINPT_KEYSERVER);
1705                refresh_keylist (kmi);
1706                return TRUE;
1707                
1708            case ID_KEYMISC_GPGPREFS:
1709                rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS,
1710                                       dlg, gpgprefs_dlg_proc, 0,
1711                                       _("GnuPG Preferences"), IDS_WINPT_GPGPREFS);
1712                if (rc == TRUE) {
1713                    reload_keycache (kmi);
1714                    update_default_key_str (kmi->statbar);
1715                }
1716                return TRUE;
1717                
1718            case ID_KEYMISC_GPGOPT:
1719                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,
1720                                  gpgopt_dlg_proc, 0, _("GnuPG Options"),
1721                                  IDS_WINPT_GPGOPT);
1722                return TRUE;
1723                
1724            case ID_KEYMISC_IMPORT:
1725                km_gui_import (kmi, LOWORD (wparam), NULL);
1726                return TRUE;
1727    
1728            case ID_KEYMISC_IMPORT_HTTP:
1729                url = (struct URL_ctx_s*)get_http_file_dlg (dlg);
1730                if (url && url->cancel == 0) {
1731                    km_http_import (dlg, url->url);
1732                    refresh_keylist (kmi);
1733                }
1734                free_if_alloc (url);
1735                break;
1736                
1737            case ID_KEYMISC_EXPORT:
1738                if (kmi->lv_idx == -1) {
1739                    msg_box (dlg, _("Please select a key."),
1740                             _("Key Manager"), MB_ERR);
1741                    return TRUE;
1742                }
1743                if (listview_count_items (kmi->lv, 1) > 1)
1744                    name = m_strdup ("Exported_GPG_Keys.asc");
1745                else {
1746                    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1747                    name = km_gen_export_filename (key->subkeys->keyid+8, 0);
1748                }
1749                t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1750                free_if_alloc (name);
1751                if (t == NULL)
1752                    return TRUE;
1753                km_file_export (dlg, kmi->lv, t);
1754                return TRUE;
1755                
1756            case ID_KEYMISC_EXPORT_PRIVKEY:
1757                if (kmi->lv_idx == -1) {
1758                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1759                    return TRUE;
1760                }
1761                if( !km_check_for_seckey( kmi->lv, kmi->lv_idx, NULL ) ) {
1762                    msg_box (dlg, _("There is no corresponding secret key for this key."),
1763                             _("Key Manager"), MB_ERR);
1764                    return TRUE;
1765                }
1766                if (listview_count_items (kmi->lv, 1) > 1) {
1767                    msg_box (dlg, _("You can only export one secret key."),
1768                             _("Key Manager"), MB_ERR);
1769                    return TRUE;
1770                }
1771                i = msg_box (dlg,
1772                              _("This operation will export your *SECRET* key!\n\n"
1773                                "Never send this key to ANYONE, it should be available\n"
1774                                "ONLY on your machine and you may use this function\n"
1775                                "to copy the key to a safe place.\n\n"
1776                                "Do you really want to export the key?"),
1777                              _("WARNING"), MB_INFO|MB_YESNO);
1778                if (i == IDYES) {
1779                    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1780                    name = km_gen_export_filename (key->subkeys->keyid+8, 1);
1781                    t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1782                    if (t != NULL)          
1783                        km_privkey_export (dlg, kmi->lv, t);
1784                }
1785                return TRUE;
1786    
1787            case ID_KEYMISC_INFO:
1788                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, dlg,
1789                                  about_winpt_dlg_proc, 0, _("About WinPT"),
1790                                  IDS_WINPT_ABOUT);
1791                break;
1792    
1793            case ID_KEYMISC_WEBSITE:
1794                ShellExecute (dlg, "open", "http://www.winpt.org",
1795                              NULL, NULL, SW_SHOW);
1796                break;
1797    
1798            case ID_KEYMISC_HELP:
1799                start_help (dlg, 0);
1800                break;
1801    
1802            case ID_KEYMISC_OT:
1803                dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST,
1804                                  dlg, ownertrust_dlg_proc, 0,
1805                                  _("Ownertrust"), IDS_WINPT_OWNERTRUST);
1806                break;
1807    
1808            case ID_KEYMISC_EDITKEY:
1809                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1810                    break;
1811                dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,
1812                                  keyedit_main_dlg_proc, (LPARAM)&k,
1813                                  _("Key Edit"), IDS_KEYCTX_EDIT);
1814                if (k.update)
1815                    update_key (kmi->lv,  kmi->lv_idx, k.tmp_keyid, 1);
1816                break;
1817                
1818            case ID_KEYMISC_COPY:
1819                km_clip_export (dlg, kmi->lv);
1820                break;
1821                
1822            case ID_KEYMISC_SELALL:
1823                listview_select_all (kmi->lv);
1824                break;
1825    
1826            case ID_KEYMISC_PASTE:
1827                km_gui_import (kmi, LOWORD (wparam), NULL);
1828                break;
1829                
1830            case ID_KEYCTX_SETPREFKS:
1831                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1832                    break;
1833                keyedit_set_pref_keyserver (&k, dlg);
1834                break;
1835    
1836            case ID_KEYMISC_REFRESH_KEYS:
1837                if (listview_count_items (kmi->lv, 1) == 0) {
1838                    msg_box (dlg, _("No key was selected, select all by default."),
1839                             _("Key Manager"), MB_INFO);
1840                    listview_select_all (kmi->lv);
1841                }
1842                km_refresh_from_keyserver (kmi->lv, dlg);
1843                msg_box (dlg, _("Keyserver refresh finished."),
1844                         _("Key Manager"), MB_OK);
1845                break;
1846                            
1847            /** Context menu **/
1848            case ID_KEYCTX_EDIT:
1849                send_cmd_id( dlg, ID_KEYMISC_EDITKEY );
1850                break;
1851    
1852            case ID_KEYCTX_PROPS:
1853                send_cmd_id( dlg, ID_KEYMISC_PROPS );
1854                break;
1855    
1856            case ID_KEYCTX_UIDS:
1857                send_cmd_id( dlg, ID_KEYMISC_UID );
1858                break;
1859    
1860            case ID_KEYCTX_SIGN:
1861                send_cmd_id( dlg, ID_KEYMISC_SIGN );
1862                break;
1863    
1864            case ID_KEYCTX_DEL:
1865                send_cmd_id (dlg, ID_KEYMISC_DELETE);
1866                break;
1867    
1868            case ID_KEYCTX_REV:
1869                send_cmd_id( dlg, ID_KEYMISC_REVCERT );
1870                break;
1871    
1872            case ID_KEYCTX_SENDMAIL:
1873                km_send_to_mail_recipient (kmi->lv, dlg);
1874                break;
1875    
1876            case ID_KEYCTX_KS_DEFAULT:
1877                host = kserver_get_hostname (0, -1, &port);
1878                km_send_to_keyserver (kmi->lv, dlg, host, port);
1879                break;
1880    
1881            case ID_KEYCTX_ADDKEY:
1882                km_get_key (kmi->lv, kmi->lv_idx, &k);
1883                keyedit_add_subkey (&k, dlg, NULL);
1884                if (k.update)
1885                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1886                break;
1887    
1888            case ID_KEYCTX_ADDUID:
1889                km_get_key (kmi->lv, kmi->lv_idx, &k);
1890                keyedit_add_userid (&k, dlg, NULL);
1891                if (k.update)
1892                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1893                break;
1894    
1895            case ID_KEYCTX_ADDREV:
1896                km_get_key (kmi->lv, kmi->lv_idx, &k);
1897                keyedit_add_revoker (&k, dlg);
1898                if (k.update)
1899                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1900                break;
1901    
1902            case ID_KEYCTX_ADDPHOTO:
1903                km_get_key (kmi->lv, kmi->lv_idx, &k);
1904                keyedit_add_photo (&k, dlg);
1905                if (k.update)
1906                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1907                break;
1908    
1909            case ID_KEYCTX_RECVFROM:
1910                km_refresh_from_keyserver (kmi->lv, dlg);
1911                if (updated_keys_avail ())
1912                    refresh_keylist (kmi);
1913                break;
1914    
1915            case ID_KEYCTX_UID_COPY:
1916                /* XXX: add generic function to support multiple selection
1917                        with a callback */
1918                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, &kci);
1919                name = kci->uids->name;
1920                set_clip_text (NULL, name, strlen (name));
1921                break;
1922    
1923            case ID_KEYCTX_KEYID_COPY:
1924                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1925                memset (type, 0, sizeof (type));
1926                type[0] = '0'; type[1] = 'x';
1927                memcpy (type+2, key->subkeys->keyid+8, 8);
1928                set_clip_text (NULL, type, strlen (type));
1929                break;
1930    
1931            case ID_KEYCTX_FPR_COPY:
1932                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1933                t = key->subkeys->fpr;
1934                set_clip_text (NULL, t? t : "", t? strlen (t): 0);
1935                break;
1936    
1937            case ID_KEYCTX_KINFO_COPY:
1938                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1939                km_set_clip_info (key->subkeys->keyid+8);
1940                break;
1941    
1942            case ID_KEYCTX_COPY:
1943                send_cmd_id (dlg, ID_KEYMISC_COPY);
1944                break;
1945    
1946            case ID_KEYCTX_PASTE:
1947                send_cmd_id (dlg, ID_KEYMISC_PASTE);
1948                break;
1949    
1950            case ID_KEYCTX_DISABLE:
1951            case ID_KEYCTX_ENABLE:
1952                i = LOWORD (wparam) == ID_KEYCTX_ENABLE? 1 : 0;
1953                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1954                    break;
1955                rc = km_enable_disable_key (kmi->lv, dlg, kmi->lv_idx, i);
1956                if (!rc)
1957                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1958                break;
1959    
1960            case ID_KEYCTX_LISTSIGS:
1961                send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS);
1962                break;
1963    
1964            case ID_KEYCTX_MAXTRUST:
1965                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1966                    break;
1967                rc = km_set_implicit_trust (dlg, kmi->lv, kmi->lv_idx);
1968                if (!rc)
1969                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1970                break;
1971    
1972            case ID_KEYCTX_SETDEFKEY:
1973                if (!km_check_key_status (kmi->lv, kmi->lv_idx)) {
1974                    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1975                    rc = set_gnupg_default_key (key->subkeys->keyid+8);
1976                    if (rc)
1977                        msg_box (dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);
1978                    update_default_key_str (kmi->statbar);
1979                }
1980                break;
1981    
1982            case ID_KEYMISC_VIEWKEYID:
1983            case ID_KEYMISC_VIEWCIPHER:
1984            case ID_KEYMISC_VIEWTYPE:
1985            case ID_KEYMISC_VIEWCREAT:
1986            case ID_KEYMISC_VIEWDESC:
1987                hm = GetMenu (dlg);
1988                i = get_menu_state (hm, LOWORD (wparam));
1989                set_menu_state (hm, LOWORD (wparam),
1990                                i & MFS_CHECKED? MFS_UNCHECKED : MFS_CHECKED);
1991                modify_listview_columns (kmi, LOWORD (wparam), !(i & MFS_CHECKED));
1992                break;
1993    
1994            case ID_GROUP_NEW:
1995            case ID_GROUP_PASTE:
1996            case ID_GROUP_DELETE:
1997            case ID_GROUP_SHOW:
1998                /* XXX: Implement group manager. */
1999                return TRUE;
2000    
2001                /*
2002            case IDCANCEL:
2003                EndDialog (dlg, TRUE);
2004                return TRUE;
2005                */
2006            }
2007            
2008            break;
2009        }
2010        
2011        return FALSE;
2012    }

Legend:
Removed from v.25  
changed lines
  Added in v.217

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26