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

Legend:
Removed from v.28  
changed lines
  Added in v.207

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26