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

Legend:
Removed from v.22  
changed lines
  Added in v.150

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26