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

Legend:
Removed from v.24  
changed lines
  Added in v.164

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26