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

Legend:
Removed from v.77  
changed lines
  Added in v.144

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26