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

Legend:
Removed from v.36  
changed lines
  Added in v.161

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26