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

Legend:
Removed from v.30  
changed lines
  Added in v.133

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26