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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26