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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26