/[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 123 by twoaday, Wed Dec 14 09:01:45 2005 UTC revision 255 by twoaday, Tue Aug 1 16:37:23 2006 UTC
# Line 1  Line 1 
1  /* wptKeyManagerDlg.cpp - WinPT Key Manager  /* wptKeyManagerDlg.cpp - WinPT Key Manager
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 Timo Schulz
3   *      Copyright (C) 2004 Andreas Jobs   *      Copyright (C) 2004 Andreas Jobs
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 41  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  /* Name and ID of the separator window. */  /* Name and ID of the separator window. */
47  #define KM_SEPARATOR_ID                10000  #define KM_SEPARATOR_ID                 10000
48  #define WINDOWCLASS_SEPARATOR_CHILD "WINPT_SEP_CHILD"  #define WINDOWCLASS_SEPARATOR_CHILD     "WINPT_SEP_CHILD"
49    
50  /* Virtual key codes. */  /* Virtual key codes. */
51  #ifndef VK_F  #ifndef VK_F
# Line 62  Line 63 
63    
64  static subclass_s keylist_proc;  static subclass_s keylist_proc;
65    
66    /* Handle to the global image list. */
67  HIMAGELIST glob_imagelist;  HIMAGELIST glob_imagelist;
68    
69  struct km_info {  struct km_info_s {
70      /* Window positions */      /* Window positions */
71      int pos_x, pos_y;      int pos_x, pos_y;
72      int ypos_sep;      int ypos_sep;
73      int ypercent_sep;      int ypercent_sep;
74    
75        /* Different kind of windows. */
76        HWND dlg;
77      HWND hwnd_sep;      HWND hwnd_sep;
78      HWND toolbar;      HWND toolbar;
79      HWND statbar;      HWND statbar;
# Line 77  struct km_info { Line 81  struct km_info {
81      listview_ctrl_t lv;      listview_ctrl_t lv;
82      int             lv_idx;      int             lv_idx;
83      int keylist_sortby;      int keylist_sortby;
84        int magic;
85    
86        unsigned int enable_groups:1;
87  };  };
88    typedef struct km_info_s *km_info_t;
89    
90  /* Toolbar button structure. */  /* Toolbar button structure. */
91  struct mybuttons {  struct tb_button_s {
92      long icon;      long icon;
93      long command;      long command;
94      char *text;      char *text;
95  };  };
96    
97  struct mybuttons myb[] = {  /* The buttons in the toolbar. */
98    struct tb_button_s tbb[] = {
99      {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},      {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},
100      {IMI_KEY_PROPS,  ID_KEYMISC_PROPS,  "Properties"},      {IMI_KEY_PROPS,  ID_KEYMISC_PROPS,  "Properties"},
101      {IMI_KEY_SIGN,   ID_KEYMISC_SIGN,   "Sign"},      {IMI_KEY_SIGN,   ID_KEYMISC_SIGN,   "Sign"},
# Line 95  struct mybuttons myb[] = { Line 104  struct mybuttons myb[] = {
104  };  };
105    
106    
107    static void km_gui_import (struct km_info_s *kmi, int cmd_id, void *param);
108    void key_get_clip_info (const char *keyid, char *buf, size_t buflen);
109    
110    
111  /* Subclass the keylist listview control to allow extended commands. */  /* Subclass the keylist listview control to allow extended commands. */
112  static BOOL CALLBACK  static BOOL CALLBACK
113  keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
114  {  {
115      struct listview_ctrl_s lv;      struct listview_ctrl_s lv;
116        struct km_info_s *kmi;
117    
118      switch (msg) {      switch (msg) {
119        case WM_DROPFILES:
120            kmi = (km_info_s *)keylist_proc.opaque;
121            km_gui_import (kmi, WM_DROPFILES, (void*)wparam);
122            break;
123    
124      case WM_LBUTTONDBLCLK:      case WM_LBUTTONDBLCLK:
125          send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);          send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
126          break;          break;
# Line 136  keylist_subclass_proc (HWND dlg, UINT ms Line 155  keylist_subclass_proc (HWND dlg, UINT ms
155              break;              break;
156    
157          case VK_P:          case VK_P:
158              if (GetAsyncKeyState (VK_CONTROL))                        if (GetAsyncKeyState (VK_CONTROL))
159                  km_clip_import (keylist_proc.dlg);                  send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
160              break;              break;
161    
162          case VK_F:          case VK_F:
# Line 154  keylist_subclass_proc (HWND dlg, UINT ms Line 173  keylist_subclass_proc (HWND dlg, UINT ms
173  }  }
174    
175    
176    #define ico2idx(ico) imagelist_getindex ((ico))
177    
178    /* Create a new toolbar window with a pre-defined list of buttons. */
179  static HWND  static HWND
180  load_toolbar (HWND dlg, struct km_info *kmi)  create_toolbar (HWND dlg, struct km_info_s *kmi)
181  {  {    
182      HWND tbwnd;      HWND tbwnd;
183      TBSAVEPARAMS tbsp;      TBSAVEPARAMS tbsp;
184      TBBUTTON tb_buttons[] = {      TBBUTTON tb_buttons[] = {
185          /*{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},
186          {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},
187          {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},
188          {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},
189            {ico2idx (IMI_KEY_SEARCH), ID_KEYMISC_SENDRECV, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
190          {0,                                  0,                 0,               TBSTYLE_SEP,    {0}, 0L, 0},          {0,                                  0,                 0,               TBSTYLE_SEP,    {0}, 0L, 0},
191          {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},
192          {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},
193       };          {ico2idx (IMI_KEY_IMPORT), ID_KEYCTX_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
194                {ico2idx (IMI_KEY_EXPORT), ID_KEYCTX_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
195        };
196    
197      tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,      tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,
198                              WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,                              WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,
199                              0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);                              0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);
200      if (tbwnd) {      if (!tbwnd)
201          SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);          BUG (0);
202          SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);      SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
203                  SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);      SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);
204          ShowWindow (tbwnd, SW_SHOW);      SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);
205        ShowWindow (tbwnd, SW_SHOW);
206          /* Restore toolbar */  
207          tbsp.hkr = HKEY_CURRENT_USER;      /* Restore toolbar */
208          tbsp.pszSubKey = "Software\\WinPT";      tbsp.hkr = HKEY_CURRENT_USER;
209          tbsp.pszValueName = "KM_toolbar";      tbsp.pszSubKey = "Software\\WinPT";
210          if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0)      tbsp.pszValueName = "KM_toolbar";
211              SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]),      if (SendMessage (tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp) == 0)
212                           (LONG)&tb_buttons[0]);          SendMessage (tbwnd, TB_ADDBUTTONS,
213       }                       sizeof (tb_buttons) / sizeof (tb_buttons[0]),
214       return tbwnd;                       (LONG)&tb_buttons[0]);
215    
216        return tbwnd;
217    }
218    
219    
220    /* Restore the width of the columns from the registry.
221       If no bitstring was found, the default size is used. */
222    int
223    restore_column_info (struct km_info_s *kmi)
224    {
225        WORD *buf;
226        HKEY root;
227        DWORD type, size, i;
228        LONG ec;
229    
230        size = kmi->lv->cols*sizeof (WORD);
231        ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
232                           KEY_ALL_ACCESS, &root);
233        if (ec != ERROR_SUCCESS)
234            return -1;
235    
236        buf = new WORD[size/2];
237        if (!buf)
238            BUG (NULL);
239        ec = RegQueryValueEx (root, "KMColumnSize", NULL, &type,
240                              (BYTE*)buf, &size);    
241        if (ec != ERROR_SUCCESS) {
242            RegCloseKey (root);
243            free_if_alloc (buf);
244            return -1;
245        }
246    
247        /* check for garbled values. */
248        for (i=0; i < size/2; i++) {
249            if (buf[i] == 0 || buf[i] > 512) {
250                free_if_alloc (buf);
251                return -1;
252            }
253        }
254        for (i=0; i < size/2; i++)
255            listview_set_column_width (kmi->lv, i, buf[i]);
256        free_if_alloc (buf);
257    
258        size = sizeof (kmi->keylist_sortby);
259        ec = RegQueryValueEx (root, "KMSortBy", NULL, &type,
260                              (BYTE*)&kmi->keylist_sortby, &size);
261        if (ec != ERROR_SUCCESS)
262            kmi->keylist_sortby = KEY_SORT_USERID;
263        RegCloseKey (root);
264        return 0;
265    }
266    
267    
268    /* Save the current column width to the registry. */
269    int
270    save_column_info (struct km_info_s *kmi)
271    {    
272        HKEY root;
273        WORD *buf;
274        LONG ec;
275        int i;
276    
277        buf = new WORD[kmi->lv->cols];
278        if (!buf)
279            BUG (NULL);
280        for (i=0; i < kmi->lv->cols; i++) {
281            LVCOLUMN lvc;
282    
283            memset (&lvc, 0, sizeof (lvc));
284            lvc.mask = LVCF_WIDTH;
285            ListView_GetColumn (kmi->lv->ctrl, i, &lvc);
286            buf[i] = lvc.cx;
287        }
288    
289        ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
290                           KEY_ALL_ACCESS, &root);
291        if (ec != ERROR_SUCCESS) {
292            free_if_alloc (buf);
293            return -1;
294        }
295    
296        ec = RegSetValueEx (root, "KMColumnSize", 0, REG_BINARY,
297                            (const BYTE*)buf, 2*kmi->lv->cols);
298        if (ec == ERROR_SUCCESS) {
299            ec = RegSetValueEx (root, "KMSortBy", 0, REG_DWORD_BIG_ENDIAN,
300                                (const BYTE*)&kmi->keylist_sortby,
301                                sizeof (kmi->keylist_sortby));
302        }
303        RegCloseKey (root);
304        free_if_alloc (buf);
305        return ec == ERROR_SUCCESS? 0 : -1;
306    }
307    
308    
309    /* Restore the original size of the dialog. */
310    static void
311    restore_window_size (HWND dlg, struct km_info_s *kmi)
312    {
313        char *p;
314        int height = 0, width = 0;
315    
316        /* Restore the original window size. */
317        p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Width");
318        if (p) {
319            width = atoi (p);
320            free_if_alloc (p);
321        }
322        p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Height");
323        if (p) {
324            height = atoi (p);
325            free_if_alloc (p);
326        }
327        if (height > 0 && width > 0)
328            SetWindowPos (dlg, HWND_TOP, kmi->pos_x, kmi->pos_y,
329                          height, width, SWP_SHOWWINDOW);
330  }  }
331    
332    
333  /* Center window @dlg. */  /* Center window @dlg. */
334  static void  static void
335  do_center_window (HWND dlg, struct km_info *kmi)  do_center_window (HWND dlg, struct km_info_s *kmi)
336  {  {
337      RECT rect;      RECT rect;
338      char *p;      char *p;
339      int pos_x = 0, pos_y = 0;      int pos_x = 0;
340        int pos_y = 0;
341                    
342      /* Find bottom of keylist */      /* Find bottom of keylist */
343      GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);      GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);
# Line 211  do_center_window (HWND dlg, struct km_in Line 352  do_center_window (HWND dlg, struct km_in
352          return;          return;
353      }      }
354      else if (p)      else if (p)
355          pos_x = atol (p);          pos_x = atoi (p);
356    
357      p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y");      p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y");
358      if (p && !strcmp (p, " ")) {      if (p && !strcmp (p, " ")) {
# Line 220  do_center_window (HWND dlg, struct km_in Line 361  do_center_window (HWND dlg, struct km_in
361          return;          return;
362      }      }
363      else if (p)      else if (p)
364          pos_y = atol (p);          pos_y = atoi (p);
365    
366      if (!pos_y && !pos_x) {      if (!pos_y && !pos_x) {
367          center_window (dlg, NULL);          center_window (dlg, NULL);
# Line 233  do_center_window (HWND dlg, struct km_in Line 374  do_center_window (HWND dlg, struct km_in
374          || pos_y > GetSystemMetrics (SM_CYSCREEN)) {          || pos_y > GetSystemMetrics (SM_CYSCREEN)) {
375          pos_x = pos_y = 0;          pos_x = pos_y = 0;
376      }      }
377        kmi->pos_x = pos_x;
378        kmi->pos_y = pos_y;
379    
380      GetClientRect (dlg, &rect);      GetClientRect (dlg, &rect);
381      MoveWindow (dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE);      MoveWindow (dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE);
382  }  }
# Line 240  do_center_window (HWND dlg, struct km_in Line 384  do_center_window (HWND dlg, struct km_in
384    
385  /* Resize the key manager window with the information from @kmi. */  /* Resize the key manager window with the information from @kmi. */
386  static void  static void
387  do_resize_window (HWND dlg, struct km_info *kmi)  do_resize_window (HWND dlg, struct km_info_s *kmi)
388  {  {
389      HWND h;      HWND h;
390      RECT rclient, rect;      RECT rclient, rect;
# Line 288  do_resize_window (HWND dlg, struct km_in Line 432  do_resize_window (HWND dlg, struct km_in
432                    
433      /* Place the keylist above the separator */      /* Place the keylist above the separator */
434      h = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);      h = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
435      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,
436                  kmi->ypos_sep - rclient.top, bRepaint);                  kmi->ypos_sep - rclient.top, bRepaint);
437      rclient.top = kmi->ypos_sep + 5 + 8;      rclient.top = kmi->ypos_sep + 5 + 8;
438    
439      /* Place the group text and the group box below the separator */      if (kmi->enable_groups != 0) {
440      h = GetDlgItem (dlg, IDC_KEYMISC_GTEXT);          /* Place the group text and the group box below the separator */
441      MoveWindow (h, rclient.left, rclient.top, 100, 14, bRepaint);          h = GetDlgItem (dlg, IDC_KEYMISC_GTEXT);
442      rclient.top += 18;          MoveWindow (h, rclient.left, rclient.top, 100, 14, bRepaint);
443            rclient.top += 18;
444      h = GetDlgItem (dlg, IDC_KEYMISC_GROUP);  
445      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,          h = GetDlgItem (dlg, IDC_KEYMISC_GROUP);
446                  (rclient.bottom < rclient.top) ?          MoveWindow (h, rclient.left, rclient.top,
447                  0 : rclient.bottom - rclient.top, bRepaint);                      rclient.right - rclient.left,
448                        (rclient.bottom < rclient.top) ?
449                        0 : rclient.bottom - rclient.top, bRepaint);
450        }
451            
452      /* Repaint the whole thing */      /* Repaint the whole thing */
453      InvalidateRect (dlg, NULL, TRUE);      InvalidateRect (dlg, NULL, TRUE);
# Line 330  static void Line 477  static void
477  do_create_minpopup (HWND dlg)  do_create_minpopup (HWND dlg)
478  {  {
479      HMENU hm;      HMENU hm;
     MENUITEMINFO mi;  
     char * s;  
480      POINT p;      POINT p;
481            
482      if (gpg_read_only || !clip_contains_pgpkey ())      if (gpg_read_only || !clip_contains_pgpkey ())
483          return;          return;
484      hm = CreatePopupMenu ();      hm = CreatePopupMenu ();
485      if (!hm)      if (!hm)
486          BUG( NULL );          BUG (0);
487      memset (&mi, 0, sizeof mi);      insert_menu_item (hm, 0, ID_KEYCTX_PASTE, _("Paste Key from Clipboard"));
     mi.cbSize = sizeof mi;  
     s = (char *)_("Paste Key from Clipboard");  
     mi.fType = MF_STRING;  
     mi.dwTypeData = s;  
     mi.cch = strlen (s);  
     mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;  
     mi.wID = ID_KEYCTX_PASTE;  
     InsertMenuItem (hm, 0, FALSE, &mi);  
488      GetCursorPos (&p);      GetCursorPos (&p);
489      TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);      TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);
490      DestroyMenu (hm);      DestroyMenu (hm);
491  }  }
492    
493    
494  /* Reload the key cache if requested. */  /* Update the default key entry in the status bar for dialog @dlg. */
495  static void  void
496  do_check_cache (listview_ctrl_t lv, HWND dlg, HWND sb)  update_default_key_str (HWND dlg)
497    {
498        const char *fmt;
499        char *keyid;
500        char defkeyinf[128];
501    
502        keyid = get_gnupg_default_key ();
503        if (!keyid)
504            return;
505        if ((keyid[0] >= 'A' && keyid[0] <= 'Z') ||
506            (keyid[0] >= 'a' && keyid[0] <= 'z') ||
507            (keyid[0] == '0' && keyid[1] == 'x'))
508            fmt = _("Default Key: %s");
509        else
510            fmt = _("Default Key: 0x%s");
511        _snprintf (defkeyinf, sizeof (defkeyinf) - 1, fmt, keyid);
512        SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf);
513        gpg_keycache_set_default_key (keycache_get_ctx (0), keyid);
514        free_if_alloc (keyid);
515    }
516    
517    
518    /* Count all keys and show from @lv results in the status bar @sb. */
519    void
520    update_status_bar (HWND sb, listview_ctrl_t lv)
521  {  {
522      gpg_keycache_t cache;      char txt_sec[128];
523        char txt_pub[128];
524        int nkeys = 0, nsec = 0;
525        int i;
526    
527      if (keycache_get_reload ()) {      nkeys = listview_count_items (lv, 0);
528          keycache_reload (dlg);      for (i = 0; i < nkeys; i++) {
529          keycache_set_reload (0);          if (km_check_for_seckey (lv, i, NULL))
530          cache = keycache_get_ctx (1);              nsec++;
         if (!cache)  
             BUG (dlg);  
         keylist_reload (lv, cache, KEYLIST_LIST, KEY_SORT_USERID);  
         km_update_status_bar (sb, lv);  
531      }      }
532        _snprintf (txt_sec, sizeof (txt_sec)-1, _("%d secret keys"), nsec);
533        _snprintf (txt_pub, sizeof (txt_pub)-1, _("%d keys"), nkeys);
534        SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec);
535        SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub);
536  }  }
537    
538    
# Line 376  long CALLBACK Line 540  long CALLBACK
540  separator_wnd_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)  separator_wnd_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
541  {  {
542      static POINT last_mouse_pos;      static POINT last_mouse_pos;
543        PAINTSTRUCT ps;
544        RECT rect;
545        HPEN hpen;
546    
547      if (msg == WM_CREATE)      if (msg == WM_CREATE)
548          SetWindowLong (hwnd, GWL_USERDATA,          SetWindowLong (hwnd, GWL_USERDATA,
# Line 383  separator_wnd_proc (HWND hwnd, UINT msg, Line 550  separator_wnd_proc (HWND hwnd, UINT msg,
550    
551      switch (msg) {      switch (msg) {
552      case WM_PAINT:      case WM_PAINT:
         PAINTSTRUCT ps;  
         RECT rect;  
         HPEN hpen;  
   
553          GetClientRect (hwnd, &rect);          GetClientRect (hwnd, &rect);
554          BeginPaint (hwnd, &ps);          BeginPaint (hwnd, &ps);
555    
# Line 394  separator_wnd_proc (HWND hwnd, UINT msg, Line 557  separator_wnd_proc (HWND hwnd, UINT msg,
557          FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));          FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));
558    
559          /* The lines from the light into the dark */          /* The lines from the light into the dark */
560          MoveToEx(ps.hdc, 0,0, NULL);          MoveToEx (ps.hdc, 0,0, NULL);
561          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT))) != NULL) {          hpen = CreatePen (PS_SOLID, 0, GetSysColor (COLOR_3DHILIGHT));
562            if (hpen != NULL) {
563              SelectObject (ps.hdc, (LPVOID)hpen);              SelectObject (ps.hdc, (LPVOID)hpen);
564              LineTo (ps.hdc, rect.right, 0);              LineTo (ps.hdc, rect.right, 0);
565              DeleteObject (hpen);              DeleteObject (hpen);
566          }          }
567          MoveToEx(ps.hdc, 0, 1, NULL);          MoveToEx (ps.hdc, 0, 1, NULL);
568          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) {          hpen = CreatePen (PS_SOLID, 0, GetSysColor (COLOR_3DLIGHT));
569            if (hpen != NULL) {
570               SelectObject (ps.hdc, (LPVOID)hpen);               SelectObject (ps.hdc, (LPVOID)hpen);
571               LineTo (ps.hdc, rect.right, rect.bottom);               LineTo (ps.hdc, rect.right, rect.bottom);
572               DeleteObject (hpen);               DeleteObject (hpen);
573           }           }
574    
575          MoveToEx(ps.hdc, 0, rect.bottom-1, NULL);          MoveToEx (ps.hdc, 0, rect.bottom-1, NULL);
576          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) {          hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW));
577            if (hpen != NULL) {
578              SelectObject (ps.hdc, (LPVOID)hpen);              SelectObject (ps.hdc, (LPVOID)hpen);
579              LineTo (ps.hdc, rect.right, rect.bottom-1);              LineTo (ps.hdc, rect.right, rect.bottom-1);
580              DeleteObject (hpen);              DeleteObject (hpen);
581          }          }
582          MoveToEx(ps.hdc, 0, rect.bottom, NULL);          MoveToEx (ps.hdc, 0, rect.bottom, NULL);
583          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) {          hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW));
584            if (hpen != NULL) {
585              SelectObject (ps.hdc, (LPVOID)hpen);              SelectObject (ps.hdc, (LPVOID)hpen);
586              LineTo (ps.hdc, rect.right, rect.bottom);              LineTo (ps.hdc, rect.right, rect.bottom);
587              DeleteObject (hpen);              DeleteObject (hpen);
# Line 436  separator_wnd_proc (HWND hwnd, UINT msg, Line 603  separator_wnd_proc (HWND hwnd, UINT msg,
603    
604      case WM_MOUSEMOVE:      case WM_MOUSEMOVE:
605          if (wparam == MK_LBUTTON) {          if (wparam == MK_LBUTTON) {
606              struct km_info *kmi;              struct km_info_s *kmi;
607              POINT p;              POINT p;
             RECT r;  
608    
609              kmi = (struct km_info *)GetWindowLong (hwnd, GWL_USERDATA);              kmi = (struct km_info_s *)GetWindowLong (hwnd, GWL_USERDATA);
610              if (kmi == NULL)              if (kmi == NULL)
611                  break;                  break;
612    
613              /* Calculate mouse movement */              /* Calculate mouse movement */
614              p.x = LOWORD(lparam);              p.x = LOWORD (lparam);
615              p.y = HIWORD(lparam);              p.y = HIWORD (lparam);
616              ClientToScreen (hwnd, &p);              ClientToScreen (hwnd, &p);
617    
618              GetWindowRect (hwnd, &r);              GetWindowRect (hwnd, &rect);
619              r.top += (short)(p.y - last_mouse_pos.y);              rect.top += (short)(p.y - last_mouse_pos.y);
620              r.bottom += (short)(p.y - last_mouse_pos.y);              rect.bottom += (short)(p.y - last_mouse_pos.y);
621    
622              last_mouse_pos.y = p.y;              last_mouse_pos.y = p.y;
623    
624              /* Apply mouse movement to window. Beware the MoveWindow is relaive              /* Apply mouse movement to window. Beware the MoveWindow is relaive
625                 to parent NOT screen */                 to parent NOT screen */
626              MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&r, 2);              MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&rect, 2);
627              kmi->ypos_sep = r.top;              kmi->ypos_sep = rect.top;
628              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 */
629              do_resize_window (GetParent(hwnd), kmi);              do_resize_window (GetParent (hwnd), kmi);
630              return 0;              return 0;
631          }          }
632      }      }
# Line 471  separator_wnd_proc (HWND hwnd, UINT msg, Line 637  separator_wnd_proc (HWND hwnd, UINT msg,
637    
638  /* Register the separator window with @dlg as the parent window. */  /* Register the separator window with @dlg as the parent window. */
639  static HWND  static HWND
640  regist_sep_wnd (HWND dlg, struct km_info * kmi)  regist_sep_wnd (HWND dlg, struct km_info_s *kmi)
641  {  {
642      WNDCLASS wndclass;      WNDCLASS wndclass;
643      HWND h;      HWND h;
644    
645        memset (&wndclass, 0, sizeof (wndclass));
646      wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;      wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
647      wndclass.lpfnWndProc   = separator_wnd_proc;      wndclass.lpfnWndProc   = separator_wnd_proc;
648      wndclass.cbClsExtra    = 0;      wndclass.cbClsExtra    = 0;
# Line 490  regist_sep_wnd (HWND dlg, struct km_info Line 657  regist_sep_wnd (HWND dlg, struct km_info
657    
658      h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,      h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,
659                          WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,                          WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
660                          0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);                              0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);
661        if (!h)
662            BUG (NULL);
663      ShowWindow (h, SW_SHOW);      ShowWindow (h, SW_SHOW);
664      return h;      return h;
665  }  }
666    
667    
668  #define enable_button(hwnd, cid) \  #define enable_button(hwnd, cid, item_selected) \
669      SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG (key_selected, 0))      SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG ((item_selected), 0))
670    
671    
672  /* Interactive modification of the dialog item which depend if an item  /* Interactive modification of the dialog item which depend if an item
# Line 506  regist_sep_wnd (HWND dlg, struct km_info Line 675  regist_sep_wnd (HWND dlg, struct km_info
675  void  void
676  update_ui_items (HWND hwnd, listview_ctrl_t lv)  update_ui_items (HWND hwnd, listview_ctrl_t lv)
677  {  {
678      HWND hwnd_child;      HWND tb_hwnd;
679      HMENU hmenu;      HMENU hmenu;
     int key_selected = 0;  
     int key_has_sec = 0;  
     int key_inv = 0;  
680      int mult_resids[] = {ID_KEYMISC_PROPS, ID_KEYMISC_SIGN, ID_KEYMISC_EDITKEY,      int mult_resids[] = {ID_KEYMISC_PROPS, ID_KEYMISC_SIGN, ID_KEYMISC_EDITKEY,
681                           ID_KEYMISC_CHECKSIGS, ID_KEYMISC_REVCERT, 0};                           ID_KEYMISC_CHECKSIGS, ID_KEYMISC_REVCERT, 0};
682      int i;      int key_selected;
683            int key_has_sec;
684        int key_inv = 0;
685        int i, state=0;
686    
687      /* Get some states */      /* Get some states */
688      key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),      key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),
689                                             LVM_GETSELECTEDCOUNT, 0, 0)                                             LVM_GETSELECTEDCOUNT, 0, 0)
# Line 528  update_ui_items (HWND hwnd, listview_ctr Line 697  update_ui_items (HWND hwnd, listview_ctr
697      }      }
698    
699      /* Enable / disable toolbar buttons */      /* Enable / disable toolbar buttons */
700      hwnd_child = GetDlgItem (hwnd, IDR_WINPT_KMTB);      tb_hwnd = GetDlgItem (hwnd, IDR_WINPT_KMTB);
701      enable_button (hwnd_child, ID_KEYMISC_DELETE);      enable_button (tb_hwnd, ID_KEYMISC_DELETE, key_selected);
702      enable_button (hwnd_child, ID_KEYMISC_PROPS);      enable_button (tb_hwnd, ID_KEYMISC_PROPS, key_selected);
703      enable_button (hwnd_child, ID_KEYMISC_SIGN);      enable_button (tb_hwnd, ID_KEYMISC_SIGN, key_selected && !key_inv);
704      enable_button (hwnd_child, ID_KEYMISC_EXPORT);      enable_button (tb_hwnd, ID_KEYMISC_EXPORT, key_selected);
705        enable_button (tb_hwnd, ID_KEYCTX_COPY, key_selected);
706        enable_button (tb_hwnd, ID_KEYCTX_PASTE, clip_contains_pgpkey ());
707    
708      /* Enable / disable menu items */      /* Enable / disable menu items */
709        state = key_selected? MF_ENABLED : MF_DISABLED|MF_GRAYED;
710      hmenu = GetMenu (hwnd);      hmenu = GetMenu (hwnd);
711      set_menu_state (hmenu, ID_KEYMISC_EXPORT, key_selected ? MF_ENABLED : MF_GRAYED);      set_menu_state (hmenu, ID_KEYMISC_EXPORT, state);
712      set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY, key_has_sec ? MF_ENABLED : MF_GRAYED);      set_menu_state (hmenu, ID_KEYMISC_DELETE, state);
713      set_menu_state (hmenu, ID_KEYMISC_REVCERT, key_has_sec ? MF_ENABLED : MF_GRAYED);      set_menu_state (hmenu, ID_KEYMISC_PROPS, state);
714      set_menu_state (hmenu, ID_KEYMISC_DELETE, key_selected ? MF_ENABLED : MF_GRAYED);      set_menu_state (hmenu, ID_KEYMISC_EDITKEY, state);
715      set_menu_state (hmenu, ID_KEYMISC_PROPS, key_selected ? MF_ENABLED : MF_GRAYED);      set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, state);
716      set_menu_state (hmenu, ID_KEYMISC_SIGN, key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);      set_menu_state (hmenu, ID_KEYMISC_SIGN,
717      set_menu_state (hmenu, ID_KEYMISC_EDITKEY, key_selected? MF_ENABLED : MF_GRAYED);                      key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);
718      set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, key_selected? MF_ENABLED : MF_GRAYED);      set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY,
719                        key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
720        set_menu_state (hmenu, ID_KEYMISC_REVCERT,
721                        key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
722    
723      /* Disable some menu items when multiple keys are selected. */      /* Disable some menu items when multiple keys are selected. */
724      if (listview_count_items (lv, 1) > 1) {      if (listview_count_items (lv, 1) > 1) {
725          for (i=0; mult_resids[i] != 0; i++)          for (i=0; mult_resids[i] != 0; i++)
726              set_menu_state (hmenu, mult_resids[i], MF_GRAYED);              set_menu_state (hmenu, mult_resids[i], MF_GRAYED);
727      }      }
728    
729        /* Disable all secret-key functions when no secret key is available. */
730        if (!secret_key_available ()) {
731            enable_button (tb_hwnd, ID_KEYMISC_SIGN, FALSE);
732            set_menu_state (hmenu, ID_KEYMISC_SIGN, MF_GRAYED);
733        }
734  }  }
735    
736    
# Line 610  popup_gpg_readonly (HWND dlg, HMENU hm) Line 791  popup_gpg_readonly (HWND dlg, HMENU hm)
791  static void  static void
792  change_edit_menu (listview_ctrl_t lv, HMENU hm, int id)  change_edit_menu (listview_ctrl_t lv, HMENU hm, int id)
793  {  {
794        enum item { EDIT_MENU = 1 };
795      int no_sel;      int no_sel;
796    
797      if (id != 1 /*EDIT_MENU*/)      if (id != EDIT_MENU)
798          return;          return;
799    
800      if (!clip_contains_pgpkey ())      if (!clip_contains_pgpkey ())
# Line 667  change_key_menu (HMENU hm, int id) Line 849  change_key_menu (HMENU hm, int id)
849  }  }
850    
851    
 /* Return a user-friendly name for a key derrived from  
    name. If @is_secret is 1, a secret key name will be generated. */  
 static char*  
 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;  
 }  
   
   
852  /* Reload a single key in the cache. */  /* Reload a single key in the cache. */
853  static void  static void
854  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)
855  {  {
856      gpgme_key_t key;      struct winpt_key_s key;
857    
858      keycache_update (0, keyid);      keycache_update (0, keyid);
859      if (keypair)      if (keypair)
# Line 705  update_key (listview_ctrl_t lv, int pos, Line 861  update_key (listview_ctrl_t lv, int pos,
861    
862      /* because we replaced the key item, we need to update the      /* because we replaced the key item, we need to update the
863         address of the pointer in the ListView control. */         address of the pointer in the ListView control. */
864      get_pubkey (keyid, &key);      memset (&key, 0, sizeof (key));
865      keylist_upd_key (lv, pos, key);      winpt_get_pubkey (keyid, &key);
866        keylist_upd_key (lv, pos, key.ext, key.ctx);
867        keyring_check_last_access ();
868  }  }
869    
870    
# Line 723  setup_status_bar (HWND dlg, listview_ctr Line 881  setup_status_bar (HWND dlg, listview_ctr
881      for (i=1; i <= 3; i++)      for (i=1; i <= 3; i++)
882          partpos[i-1] = r.right/3*i;          partpos[i-1] = r.right/3*i;
883      statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,      statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,
884                                    "status bar", dlg, KM_SEPARATOR_ID);                                    "WinPT_Status_Bar", dlg, KM_SEPARATOR_ID);
885        if (!statbar)
886            BUG (NULL);
887      ShowWindow (statbar, SW_SHOW);      ShowWindow (statbar, SW_SHOW);
888      SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);      SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);
889    
890      km_update_default_key_str (statbar);      update_default_key_str (statbar);
891      km_update_status_bar (statbar, lv);      update_status_bar (statbar, lv);
   
892      return statbar;      return statbar;
893  }  }
894    
895    
896    /* Remove or add columns which depends on the state of @checked. */
897    void
898    modify_listview_columns (km_info_s *kmi, UINT m_uid, BOOL checked)
899    {
900        UINT resids[] = {
901            0,
902            ID_KEYMISC_VIEWKEYID,
903            ID_KEYMISC_VIEWTYPE,
904            0,
905            ID_KEYMISC_VIEWCIPHER,
906            0,
907            0,
908            ID_KEYMISC_VIEWCREAT,
909            ID_KEYMISC_VIEWDESC,
910            -1
911        };
912        listview_column_s cols[] = {
913        {0, 240, (char *)_("User ID")},
914        {1, 78, (char *)_("Key ID")},
915        {2, 52, (char *)_("Type")},    
916        {3, 66, (char *)_("Size")},
917        {4, 60, (char *)_("Cipher")},
918        {5, 66, (char *)_("Validity")},
919        {6, 58, (char *)_("Trust")},
920        {7, 72, (char *)_("Creation")},
921        {8, 160,(char *)_("Description")},
922        {0, 0, NULL}
923        };
924        UINT pos;
925    
926        for (pos=0; resids[pos] != -1; pos++) {
927            if (m_uid == resids[pos])
928                break;
929        }
930        if (!checked)
931            listview_del_column (kmi->lv, (int)pos);
932        else {      
933            listview_add_column (kmi->lv, &cols[pos]);
934            keylist_upd_col (kmi->lv, pos);
935        }
936    }
937    
938    
939    /* Helper to handle the help file. If @check is 1
940       the existence of the file is checked.
941       Otherwise the help file will be loaded. */
942    static bool
943    start_help (HWND dlg, int check)
944    {
945        DWORD n;
946        char path[MAX_PATH+1+32];
947    
948        n = GetModuleFileName (NULL, path, sizeof (path)-1-32);
949        if (!n)
950            return false;
951        path[n] = 0;
952        while (n-- && path[n] != '\\')
953            ;
954        path[n+1] = 0;
955        strcat (path, "winpt.chm");
956        if (!check)
957            ShellExecute (dlg, "open", path, NULL, NULL, SW_SHOW);
958        return file_exist_check (path) == 0? true : false;
959    }
960    
961    
962    /* Translate all menu strings. */
963    static void
964    translate_menu_strings (HWND dlg)
965    {
966        HMENU menu;
967    
968        menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC);
969        set_menu_text_bypos (menu, 0, _("File"));
970        set_menu_text_bypos (menu, 1, _("Edit"));
971        set_menu_text_bypos (menu, 2, _("View"));
972        set_menu_text_bypos (menu, 3, _("Key"));
973        set_menu_text_bypos (menu, 4, _("Groups"));
974    
975        set_menu_text (menu, ID_KEYMISC_EDITKEY, _("Edit"));
976        set_menu_text (menu, ID_KEYMISC_MAIL, _("Send Mail..."));
977        set_menu_text (menu, ID_KEYMISC_OT, _("Ownertrust")); /* XXX */
978        set_menu_text (menu, ID_KEYMISC_COPY, _("&Copy\tCtrl+C"));
979        set_menu_text (menu, ID_KEYMISC_PASTE, _("&Paste\tCtrl+V"));
980        set_menu_text (menu, ID_KEYMISC_FIND, _("Search...\tCtrl+F"));
981        set_menu_text (menu, ID_KEYMISC_SELALL, _("Select All\tCtrl+A"));
982        set_menu_text (menu, ID_KEYMISC_QUIT, _("&Quit"));
983        set_menu_text (menu, ID_KEYMISC_UID, _("User ID"));
984        set_menu_text (menu, ID_KEYMISC_NEWKEY, _("&Expert"));
985        set_menu_text (menu, ID_KEYMISC_KEYWIZARD, _("&Normal"));
986        set_menu_text (menu, ID_KEYMISC_EDIT, _("Edit"));
987        set_menu_text (menu, ID_KEYMISC_SIGN, _("&Sign"));
988        set_menu_text (menu, ID_KEYMISC_DELETE, _("&Delete"));
989        set_menu_text (menu, ID_KEYMISC_DELETE2, _("&Delete"));
990        set_menu_text (menu, ID_KEYMISC_REVCERT, _("&Revoke Cert"));
991        set_menu_text (menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures"));
992        set_menu_text (menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path"));
993        set_menu_text (menu, ID_KEYMISC_EXPORT, _("&Export..."));
994        set_menu_text (menu, ID_KEYMISC_IMPORT, _("&Import..."));
995        set_menu_text (menu, ID_KEYMISC_PROPS, _("&Properties"));
996        set_menu_text (menu, ID_KEYMISC_GPGOPT, _("GPG &Options"));
997        set_menu_text (menu, ID_KEYMISC_GPGPREFS, _("&GPG Preferences"));
998        set_menu_text (menu, ID_KEYMISC_WINPTPREFS, _("&WinPT Preferences"));
999        set_menu_text (menu, ID_KEYMISC_SENDRECV, _("Keyserver") );
1000        set_menu_text (menu, ID_KEYMISC_EXPORT_PRIVKEY, _("E&xport Secret Key"));
1001        set_menu_text (menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache"));
1002        set_menu_text (menu, ID_KEYMISC_REBUILD, _("R&everify Signatures"));
1003        set_menu_text (menu, ID_KEYMISC_REFRESH_KEYS, _("Refresh &Keys (Keyserver)"));
1004        set_menu_text (menu, ID_KEYMISC_INFO, _("Info") );
1005        set_menu_text (menu, ID_KEYMISC_HELP, _("&Help"));
1006    
1007        set_menu_text (menu, ID_KEYMISC_VIEWKEYID, _("Key ID"));
1008        set_menu_text (menu, ID_KEYMISC_VIEWCIPHER, _("Cipher"));
1009        set_menu_text (menu, ID_KEYMISC_VIEWTYPE, _("Type"));
1010        set_menu_text (menu, ID_KEYMISC_VIEWCREAT, _("Creation"));
1011    
1012        if (!start_help (NULL, 1))
1013            set_menu_state (menu, ID_KEYMISC_HELP, MF_GRAYED);
1014    
1015        SetMenu (dlg, menu);
1016    }
1017    
1018    
1019    /* Translate popup menu strings. */
1020    static void
1021    translate_popupmenu_strings (HMENU popup)
1022    {
1023        set_menu_text (popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard"));
1024        set_menu_text (popup, ID_KEYCTX_KEYID_COPY, _("Copy Key ID to Clipboard"));
1025        set_menu_text (popup, ID_KEYCTX_FPR_COPY, _("Copy Fingerprint to Clipboard"));
1026        set_menu_text (popup, ID_KEYCTX_KINFO_COPY, _("Copy Key Info to Clipboard"));
1027        set_menu_text (popup, ID_KEYCTX_EMAIL_COPY, _("Copy E-Mail to Clipboard"));
1028        set_menu_text (popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard"));
1029        set_menu_text (popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard"));
1030        set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver"));
1031        set_menu_text (popup, ID_KEYCTX_MAXTRUST, _("Set Implicit &Trust"));
1032        set_menu_text (popup, ID_KEYCTX_LISTSIGS, _("&List Signatures"));
1033        set_menu_text (popup, ID_KEYCTX_PROPS, _("&Properties"));
1034        set_menu_text (popup, ID_KEYCTX_EDIT, _("Key Edit"));
1035        set_menu_text (popup, ID_KEYCTX_DEL, _("&Delete"));
1036        set_menu_text (popup, ID_KEYCTX_REV, _("&Revoke Cert"));
1037        set_menu_text (popup, ID_KEYCTX_SIGN, _("&Sign"));
1038        set_menu_text (popup, ID_KEYCTX_ENABLE, _("&Enable"));
1039        set_menu_text (popup, ID_KEYCTX_DISABLE, _("&Disable"));
1040        set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Re&fresh from Keyserver"));
1041        set_menu_text (popup, ID_KEYCTX_SETPREFKS, _("Set preferred Keyserver URL"));
1042        set_menu_text (popup, ID_KEYCTX_SENDMAIL, _("Send Key to Mail Recipient"));
1043        set_menu_text (popup, ID_KEYCTX_SETDEFKEY, _("Set as Default Key"));
1044    
1045        set_menu_text (popup, ID_KEYCTX_ADDKEY, _("Key..."));
1046        set_menu_text (popup, ID_KEYCTX_ADDUID, _("User ID..."));
1047        set_menu_text (popup, ID_KEYCTX_ADDPHOTO, _("Photo ID..."));
1048        set_menu_text (popup, ID_KEYCTX_ADDREV, _("Revoker..."));
1049    
1050        /* change popup texts */
1051        set_menu_text_bypos (popup, 0, _("Key Attributes"));
1052        set_menu_text_bypos (popup, 6, _("Add"));
1053        set_menu_text_bypos (popup, 19, _("Send to Keyserver"));
1054    }
1055    
1056    
1057    /* Return true if the cache contain marked keys. */
1058    static bool
1059    updated_keys_avail (void)
1060    {
1061        gpg_keycache_t kc = keycache_get_ctx (1);
1062        struct keycache_s *k;
1063    
1064        for (k = kc->item; k; k = k->next) {
1065            if (k->flags)
1066                return true;
1067        }
1068        return false;
1069    }
1070    
1071    
1072    /* Find the index of the key identified by @key. */
1073    static int
1074    find_keypos (listview_ctrl_t lv, gpgme_key_t key)
1075    {
1076        char keyid[32+1];
1077        int i;
1078    
1079        for (i=0; i < listview_count_items (lv, 0); i++) {
1080            listview_get_item_text (lv, i, KM_COL_KEYID, keyid, sizeof (keyid)-1);
1081            if (!strcmp (key->subkeys->keyid+8, keyid+2))
1082                return i;
1083        }
1084        return -1;
1085    }
1086    
1087    
1088    /* Add all recently updated keys in the cache to the list
1089       and refresh all GUI elements. */
1090    static void
1091    refresh_keylist (struct km_info_s *kmi)
1092    {
1093        struct keycache_s *ctx;
1094        gpg_keycache_t kc;
1095        int status=0, pos;
1096    
1097        kc = keycache_get_ctx (1);
1098        while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) {
1099            if (status == KC_FLAG_ADD)
1100                keylist_add_key (kmi->lv, KEYLIST_LIST, ctx, ctx->key);
1101            else {
1102                pos = find_keypos (kmi->lv, ctx->key);
1103                if (pos != -1)
1104                    keylist_upd_key (kmi->lv, pos, ctx, ctx->key);
1105            }
1106        }
1107        keylist_sort (kmi->lv, kmi->keylist_sortby);
1108        update_status_bar (kmi->statbar, kmi->lv);
1109        keyring_check_last_access ();
1110    }
1111    
1112    
1113    /* Reload the key cache. */
1114    static void
1115    keycache_reload (HWND dlg)
1116    {      
1117        refresh_cache_s rcs;
1118    
1119        memset (&rcs, 0, sizeof rcs);
1120        rcs.kr_reload = rcs.kr_update = 1;
1121        rcs.tr_update = 0;
1122        DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,                                        
1123                        keycache_dlg_proc, (LPARAM)&rcs);
1124    }
1125    
1126    
1127    /* Check if the secret keyring contains at least one
1128       key with ultimate trust.
1129       Return value: 0 on success. */
1130    int
1131    check_ultimate_trusted_key (gpg_keycache_t _sec)
1132    {
1133        struct keycache_s *n;
1134        int nkeys = 0;
1135    
1136        for (n = _sec->item; n; n = n->next) {
1137            if (n->pubpart &&
1138                n->pubpart->key->owner_trust == GPGME_VALIDITY_ULTIMATE)
1139                return 0;
1140            nkeys++;
1141        }
1142    
1143        /* if we do not have any secret keys, it does not make sense
1144           to return an error. */
1145        if (nkeys == 0)
1146            return 0;
1147        return -1;
1148    }
1149    
1150    
1151    static void
1152    reload_keylist (struct km_info_s *kmi)
1153    {
1154        gpg_keycache_t c;
1155    
1156        c = keycache_get_ctx (1);
1157        keycache_reload (kmi->dlg);
1158        keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby);
1159        update_status_bar (kmi->statbar, kmi->lv);
1160        keyring_check_last_access ();
1161    }
1162    
1163    
1164    /* Reload the entire key cache and update the listview. */
1165    static void
1166    reload_keycache (struct km_info_s *kmi)
1167    {
1168        refresh_cache_s rcs = {0};
1169        gpg_keycache_t c;
1170    
1171        rcs.kr_reload = rcs.kr_update = 1;
1172        rcs.tr_update = 0;
1173        DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, kmi->dlg,
1174                        keycache_dlg_proc, (LPARAM)&rcs);
1175        c = keycache_get_ctx (1);
1176        keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby);
1177        update_status_bar (kmi->statbar, kmi->lv);
1178        SetForegroundWindow (kmi->dlg);
1179    }
1180    
1181    
1182    /* Handle all import request. */
1183    static void
1184    km_gui_import (struct km_info_s *kmi, int cmd_id, void *param)
1185    {
1186        int newkeys=0, newsks=0;
1187        int err = 0;
1188    
1189        switch (cmd_id) {
1190        case ID_KEYMISC_PASTE:
1191            err = km_clip_import (kmi->dlg, &newkeys, &newsks);
1192            break;
1193    
1194        case ID_KEYMISC_IMPORT:
1195            err = km_file_import (kmi->dlg, NULL, &newkeys, &newsks);
1196            break;
1197    
1198        case WM_DROPFILES:
1199            err = km_dropped_file_import (kmi->dlg, (HDROP)param,
1200                                          &newkeys, &newsks);
1201            break;
1202    
1203        default:
1204            err = 1;
1205            break;
1206        }
1207    
1208        if (!err && !newsks && (newkeys > 0 && newkeys < KM_PRELOAD_KEYS))
1209            refresh_keylist (kmi);
1210        else if (!err) /* avoid to spawn too much processes. */
1211            reload_keylist (kmi);
1212    
1213        SetForegroundWindow (kmi->dlg);
1214    }
1215    
1216    
1217    /* Copy the requested key information (@what) to the clipboard.
1218       If multiple items were selected, each key info is copied to
1219       the clipboard. The data is separated by \r\n. */
1220    static void
1221    copy_key_info (int what, struct km_info_s *kmi)
1222    {
1223        gpgme_data_t out;
1224        gpgme_key_t key;
1225        struct keycache_s *kci = NULL;
1226        size_t n=0;
1227        char *p, tmp[256];
1228        int i=0, end = listview_count_items (kmi->lv, 0);
1229        bool single = false;
1230    
1231        /* Do not iterate over the entire list if just one item is selected. */
1232        n = listview_count_items (kmi->lv, 1);
1233        if (n == 1) {
1234            i = kmi->lv_idx;
1235            end = i+1;
1236            single = true;
1237        }
1238    
1239        gpgme_data_new (&out);
1240        for (; i < end; i++) {
1241            if (!listview_get_item_state (kmi->lv, i))
1242                continue;
1243            switch (what) {
1244    
1245            case ID_KEYCTX_EMAIL_COPY:
1246                key = km_get_key_ptr (kmi->lv, i, NULL);
1247                gpgme_data_write (out, key->uids->email, strlen (key->uids->email));
1248                if (!single) gpgme_data_write (out, "\r\n", 2);
1249                break;
1250    
1251            case ID_KEYCTX_UID_COPY:
1252                key = km_get_key_ptr (kmi->lv, i, &kci);
1253                gpgme_data_write (out, kci->uids->uid, strlen (kci->uids->uid));
1254                if (!single) gpgme_data_write (out, "\r\n", 2);
1255                break;
1256    
1257            case ID_KEYCTX_KEYID_COPY:
1258                key = km_get_key_ptr (kmi->lv, i, NULL);
1259                gpgme_data_write (out, "0x", 2);
1260                gpgme_data_write (out, key->subkeys->keyid+8, 8);
1261                if (!single) gpgme_data_write (out, "\r\n", 2);
1262                break;
1263    
1264            case ID_KEYCTX_FPR_COPY:
1265                key = km_get_key_ptr (kmi->lv, i, NULL);
1266                gpgme_data_write (out, key->subkeys->fpr, strlen (key->subkeys->fpr));
1267                if (!single) gpgme_data_write (out, "\r\n", 2);
1268                break;
1269    
1270            case ID_KEYCTX_KINFO_COPY:
1271                key = km_get_key_ptr (kmi->lv, i, NULL);
1272                key_get_clip_info (key->subkeys->keyid+8, tmp, sizeof (tmp)-1);
1273                gpgme_data_write (out, tmp, strlen (tmp));
1274                if (!single) gpgme_data_write (out, "\r\n", 2);
1275                break;
1276            }
1277        }
1278        gpgme_data_write (out, "\0", 1);
1279        p = gpgme_data_release_and_get_mem (out, &n);
1280        set_clip_text (NULL, p, n);
1281        gpgme_free (p);
1282    }
1283    
1284    
1285  /* Dialog box procedure for the Key Manager. */  /* Dialog box procedure for the Key Manager. */
1286  BOOL CALLBACK  BOOL CALLBACK
1287  keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1288  {  {
     struct km_info *kmi;  
     static HMENU menu = NULL;  
     static int refresh_keys = 0;      
     INITCOMMONCONTROLSEX icex;  
1289      HWND kl;      HWND kl;
1290      HMENU hm;      HMENU hm;
1291        RECT r;
1292      gpg_keycache_t c;      gpg_keycache_t c;
1293      gpgme_key_t key;      gpgme_key_t key;
1294        km_info_t kmi = NULL;    
1295      struct genkey_s genkey;      struct genkey_s genkey;
1296      struct winpt_key_s k = {0};      struct winpt_key_s k = {0};
1297      struct URL_ctx_s *url;      struct URL_ctx_s *url;
1298      refresh_cache_s rcs = {0};      char type[32], *name;
     char keyid[48], uid[128], type[32], *name;  
1299      const char *t, *host;      const char *t, *host;
1300      u16 port = 0;      WORD port = 0;
1301      int l_idx = 0, i=0, rc;      int l_idx = 0, i=0, rc;
1302    
1303      if ((msg != WM_INITDIALOG)      if ((msg != WM_INITDIALOG)
1304          && ((kmi = (struct km_info*)GetWindowLong (dlg, GWL_USERDATA)) == NULL))          && ((kmi = (km_info_t)GetWindowLong (dlg, GWL_USERDATA)) == NULL))
1305          return FALSE;          return FALSE;
1306        
1307        /* handle dynamic popup items in the keyserver menu. */
1308        if (msg == WM_COMMAND && LOWORD (wparam) >= WM_APP &&
1309                                 LOWORD (wparam) <= WM_APP+MAX_KEYSERVERS) {
1310            l_idx = LOWORD (wparam)-WM_APP;
1311            if (l_idx < 0)
1312                return TRUE;
1313            host = kserver_get_hostname (l_idx, 0, &port);
1314            if (host != NULL)
1315                km_send_to_keyserver (kmi->lv, dlg, host, port);
1316            return TRUE;
1317        }
1318    
1319      switch (msg) {      switch (msg) {
1320      case WM_INITDIALOG:      case WM_INITDIALOG:
1321          kmi = new struct km_info;          kmi = new struct km_info_s;
1322          memset (kmi, 0, sizeof (struct km_info));          memset (kmi, 0, sizeof (struct km_info_s));
1323          kmi->lv_idx = -1;          kmi->lv_idx = -1;
         icex.dwSize = sizeof (INITCOMMONCONTROLSEX);  
         icex.dwICC  = ICC_BAR_CLASSES;  
         InitCommonControlsEx (&icex);  
1324          kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);          kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);
1325          imagelist_load (dlg);          imagelist_load (dlg);
1326            translate_menu_strings (dlg);
1327          SetWindowText (dlg, _("Key Manager"));          SetWindowText (dlg, _("Key Manager"));
1328          menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC);  
         set_menu_text_bypos (menu, 0, _("File"));  
         set_menu_text_bypos (menu, 1, _("Edit"));  
         set_menu_text_bypos (menu, 2, _("View"));  
         set_menu_text_bypos (menu, 3, _("Key"));  
         set_menu_text_bypos (menu, 4, _("Groups"));  
         set_menu_text (menu, ID_KEYMISC_EDITKEY, _("Edit"));  
         set_menu_text (menu, ID_KEYMISC_MAIL, _("Send Mail..."));  
         set_menu_text (menu, ID_KEYMISC_OT, _("Ownertrust")); /* XXX */  
         set_menu_text (menu, ID_KEYMISC_COPY, _("&Copy\tCtrl+C"));  
         set_menu_text (menu, ID_KEYMISC_PASTE, _("&Paste\tCtrl+V"));  
         set_menu_text (menu, ID_KEYMISC_FIND, _("Search...\tCtrl+F"));  
         set_menu_text (menu, ID_KEYMISC_SELALL, _("Select All\tCtrl+A"));  
         set_menu_text (menu, ID_KEYMISC_QUIT, _("&Quit"));  
         set_menu_text (menu, ID_KEYMISC_UID, _("User ID"));  
         set_menu_text (menu, ID_KEYMISC_NEWKEY, _("&Expert"));  
         set_menu_text (menu, ID_KEYMISC_KEYWIZARD, _("&Normal"));  
         set_menu_text (menu, ID_KEYMISC_EDIT, _("Edit"));  
         set_menu_text (menu, ID_KEYMISC_SIGN, _("&Sign"));  
         set_menu_text (menu, ID_KEYMISC_DELETE, _("&Delete"));  
         set_menu_text (menu, ID_KEYMISC_DELETE2, _("&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"));  
           
         /* XXX: implement help code. */  
         set_menu_state (menu, ID_KEYMISC_HELP, MF_GRAYED);  
           
         SetMenu (dlg, menu);  
         if (keyring_check_last_access ())  
             keycache_set_reload (1);  
         if (keycache_get_reload ())  
             keycache_reload (dlg);  
1329          c = keycache_get_ctx (KEYCACHE_PUB);          c = keycache_get_ctx (KEYCACHE_PUB);
1330          if (!c)          kl = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
             BUG (NULL);  
1331          kmi->keylist_sortby = KEY_SORT_USERID;          kmi->keylist_sortby = KEY_SORT_USERID;
1332          Header_SetImageList(ListView_GetHeader (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST)),          Header_SetImageList(ListView_GetHeader (kl), glob_imagelist);
                             glob_imagelist);  
1333          kmi->lv = keylist_load (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST), c,          kmi->lv = keylist_load (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST), c,
1334                                  NULL, KEYLIST_LIST, kmi->keylist_sortby);                                  NULL, KEYLIST_LIST, kmi->keylist_sortby);
1335            if (check_ultimate_trusted_key (keycache_get_ctx (0))) {
1336                msg_box (dlg, _("No ultimately trusted key found.\n"
1337                                "Please set at least one secret key to ultimate trust."),
1338                                _("Key Manager"), MB_WARN);
1339            }
1340          /* init subclassing for the listview */          /* init subclassing for the listview */
1341          kl = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);          keylist_proc.opaque = kmi;
1342          keylist_proc.dlg = dlg;          keylist_proc.dlg = dlg;
1343          keylist_proc.current = (WNDPROC)keylist_subclass_proc;          keylist_proc.current = (WNDPROC)keylist_subclass_proc;
1344          keylist_proc.old = (WNDPROC)GetWindowLong( kl, GWL_WNDPROC );          keylist_proc.old = (WNDPROC)GetWindowLong(kl, GWL_WNDPROC);
1345          if (keylist_proc.old) {          if (keylist_proc.old) {
1346              if( !SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) {              if (!SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) {
1347                  msg_box (dlg, _("Could not set keylist window procedure."),                  msg_box (dlg, "Could not set keylist window procedure.",
1348                           _("Key Manager"), MB_ERR);                           _("Key Manager"), MB_ERR);
1349                  BUG (NULL);                  BUG (NULL);
1350              }              }
1351          }          }
         #if 0  
         km_groups_new (&gc, GetDlgItem (dlg, IDC_KEYMISC_GROUP));  
         km_groups_load (gc);  
         #endif  
1352          kmi->statbar = setup_status_bar (dlg, kmi->lv);          kmi->statbar = setup_status_bar (dlg, kmi->lv);
1353          SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);          SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);
1354          kmi->toolbar = load_toolbar (dlg, kmi);          kmi->toolbar = create_toolbar (dlg, kmi);
1355            kmi->dlg = dlg;
1356    
1357          do_center_window (dlg, kmi);          do_center_window (dlg, kmi);
1358          do_resize_window (dlg, kmi);          do_resize_window (dlg, kmi);
1359            restore_window_size (dlg, kmi);
1360          update_ui_items (dlg, kmi->lv);          update_ui_items (dlg, kmi->lv);
1361            restore_column_info (kmi);
1362            keylist_sort (kmi->lv, kmi->keylist_sortby);
1363    
1364          SetDlgItemText (dlg, IDC_KEYMISC_GTEXT, _("Groups"));          SetDlgItemText (dlg, IDC_KEYMISC_GTEXT, _("Groups"));
1365            SetDlgItemText (dlg, ID_GROUP_SHOW, _("&Show"));
1366            SetDlgItemText (dlg, ID_GROUP_NEW, _("&New..."));
1367          SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst,          SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst,
1368                        (LPCTSTR)IDI_WINPT));                        (LPCTSTR)IDI_WINPT));
1369          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
1370            kmi->magic = SetTimer (dlg, 1, 1000, NULL);
1371          return TRUE;          return TRUE;
1372    
1373        case WM_TIMER:
1374            KillTimer (dlg, kmi->magic);
1375            SetForegroundWindow (dlg);
1376            break;
1377                    
1378      case WM_DESTROY:      case WM_DESTROY:
1379            save_column_info (kmi);
1380          if (kmi->lv) {          if (kmi->lv) {
1381              keylist_delete (kmi->lv);              keylist_delete (kmi->lv);
1382              kmi->lv = NULL;                    kmi->lv = NULL;      
# Line 865  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1387  keymanager_dlg_proc (HWND dlg, UINT msg,
1387          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type);          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type);
1388          ltoa (kmi->pos_y, type, 10);          ltoa (kmi->pos_y, type, 10);
1389          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type);          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type);
1390          /* Remove runtime information. This should be the last action taken here. */  
1391          delete kmi; kmi = NULL;          GetWindowRect (dlg, &r);
1392            sprintf (type, "%d", (int)(r.bottom-r.top));
1393            set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Width",
1394                               type);
1395            sprintf (type, "%d", (int)(r.right-r.left));
1396            set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Height",
1397                            type);
1398    
1399            /* Remove runtime information.
1400               This should be the last action taken here. */
1401            delete kmi;
1402            kmi = NULL;
1403          SetWindowLong (dlg, GWL_USERDATA, 0);          SetWindowLong (dlg, GWL_USERDATA, 0);
         keycache_set_reload (refresh_keys);  
1404          return FALSE;          return FALSE;
1405    
1406      case WM_MOVE:      case WM_MOVE:
         RECT r;  
1407          GetWindowRect (dlg, &r);          GetWindowRect (dlg, &r);
1408          kmi->pos_x = r.left;          kmi->pos_x = r.left;
1409          kmi->pos_y = r.top;              kmi->pos_y = r.top;    
# Line 903  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1434  keymanager_dlg_proc (HWND dlg, UINT msg,
1434          case TBN_GETBUTTONINFO:          case TBN_GETBUTTONINFO:
1435              LPTBNOTIFY lpTbNotify;              LPTBNOTIFY lpTbNotify;
1436              lpTbNotify = (LPTBNOTIFY)lparam;              lpTbNotify = (LPTBNOTIFY)lparam;
1437              if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) {              if (lpTbNotify->iItem < (sizeof(tbb) / sizeof(tb_button_s))) {
1438                  lpTbNotify->tbButton.iBitmap = imagelist_getindex(myb[lpTbNotify->iItem].icon);                  lpTbNotify->tbButton.iBitmap = imagelist_getindex (tbb[lpTbNotify->iItem].icon);
1439                  lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command;                  lpTbNotify->tbButton.idCommand = tbb[lpTbNotify->iItem].command;
1440                  lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;                  lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;
1441                  lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;                  lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;
1442                  lpTbNotify->tbButton.iString = 0;                  lpTbNotify->tbButton.iString = 0;
1443                  strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText);                  strncpy (lpTbNotify->pszText, tbb[lpTbNotify->iItem].text, lpTbNotify->cchText);
1444                  SetWindowLong(dlg, DWL_MSGRESULT, TRUE);                  SetWindowLong(dlg, DWL_MSGRESULT, TRUE);
1445              }              }
1446              return TRUE;              return TRUE;
# Line 943  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1474  keymanager_dlg_proc (HWND dlg, UINT msg,
1474    
1475              lpttt->hinst = NULL;              lpttt->hinst = NULL;
1476              switch (lpttt->hdr.idFrom) {              switch (lpttt->hdr.idFrom) {
1477                case ID_KEYMISC_KEYWIZARD:
1478                    lpttt->lpszText = (char*)_("Generate new key pair");
1479                    break;
1480    
1481                case ID_KEYMISC_SENDRECV:
1482                    lpttt->lpszText = (char*)_("Search for a specific key");
1483                    break;
1484    
1485              case ID_KEYMISC_DELETE:              case ID_KEYMISC_DELETE:
1486                  lpttt->lpszText = (char *)_("Delete key from keyring");                  lpttt->lpszText = (char *)_("Delete key from keyring");
1487                  break;                  break;
# Line 955  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1494  keymanager_dlg_proc (HWND dlg, UINT msg,
1494                  lpttt->lpszText = (char *)_("Sign key");                  lpttt->lpszText = (char *)_("Sign key");
1495                  break;                  break;
1496    
1497                case ID_KEYCTX_COPY:
1498                    lpttt->lpszText = (char *)_("Copy key to clipboard");
1499                    break;
1500    
1501                case ID_KEYCTX_PASTE:
1502                    lpttt->lpszText = (char*)_("Paste key from clipboard");
1503                    break;
1504    
1505              case ID_KEYMISC_IMPORT:              case ID_KEYMISC_IMPORT:
1506                  lpttt->lpszText = (char *)_("Import key to keyring");                  lpttt->lpszText = (char *)_("Import key to keyring");
1507                  break;                  break;
# Line 974  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1521  keymanager_dlg_proc (HWND dlg, UINT msg,
1521              break;              break;
1522    
1523          case NM_RCLICK:          case NM_RCLICK:
1524                if (!wait_for_progress_cb (0))
1525                    break;
1526              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1527                  l_idx =listview_get_curr_pos (kmi->lv);                  l_idx =listview_get_curr_pos (kmi->lv);
1528                  if (l_idx == -1)                  if (l_idx == -1)
1529                      return TRUE; /* Popup only when a item was selected */                      return TRUE; /* Popup only when a item was selected */              
                 do_check_cache (kmi->lv, dlg, kmi->statbar);  
1530                  GetCursorPos (&p);                  GetCursorPos (&p);
1531                  hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));                  hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));
1532                  popup = GetSubMenu (hm, 0);                  popup = GetSubMenu (hm, 0);
1533                    translate_popupmenu_strings (popup);
                 set_menu_text (popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard"));  
                 set_menu_text (popup, ID_KEYCTX_KEYID_COPY, _("Copy Key ID to Clipboard"));  
                 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"));  
   
                 set_menu_text (popup, ID_KEYCTX_ADDKEY, _("Key..."));  
                 set_menu_text (popup, ID_KEYCTX_ADDUID, _("User ID..."));  
                 set_menu_text (popup, ID_KEYCTX_ADDPHOTO, _("Photo ID..."));  
                 set_menu_text (popup, ID_KEYCTX_ADDREV, _("Revoker..."));  
   
                 /* 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"));  
1534    
1535                  if (km_check_for_seckey (kmi->lv, l_idx, &i))                  if (km_check_for_seckey (kmi->lv, l_idx, &i))
1536                      set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);                      set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);
1537                  if (i == 0)                  if (i == 0)
1538                      set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);                      set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);
1539                  if (!km_check_for_seckey (kmi->lv, l_idx, NULL)) {                  if (!km_check_for_seckey (kmi->lv, l_idx, NULL) ||
1540                        (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED)) {
1541                      set_menu_state (popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED);                      set_menu_state (popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED);
1542                      set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);                      set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
1543                      set_menu_state (popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED);                      set_menu_state (popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED);
# Line 1045  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1564  keymanager_dlg_proc (HWND dlg, UINT msg,
1564                      set_menu_state (popup, ID_KEYCTX_PASTE, MF_DISABLED|MF_GRAYED);                      set_menu_state (popup, ID_KEYCTX_PASTE, MF_DISABLED|MF_GRAYED);
1565                  if (mapi_init ())                  if (mapi_init ())
1566                      set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);                      set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);
1567                    if (!secret_key_available ())
1568                        set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);
1569    
1570                  /* Override 'Default Keyserver' with the actual name. */                  /* Override 'Default Keyserver' with the actual name. */
1571                  host = kserver_get_hostname (0, -1, &port);                  host = kserver_get_hostname (0, -1, &port);
1572                    if (!host)
1573                        host = DEF_HKP_KEYSERVER;
1574                  set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);                  set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);
1575                    {
1576                        HMENU ks = GetSubMenu (popup, 19);
1577                        for (i=0; server[i].name != NULL; i++)                      
1578                            insert_menu_item (ks, i+2, WM_APP+i, server[i].name);
1579                    }
1580                  popup_gpg_readonly (dlg, popup);                  popup_gpg_readonly (dlg, popup);
1581                  if (listview_count_items (kmi->lv, 1) > 1)                  if (listview_count_items (kmi->lv, 1) > 1)
1582                      popup_multiple (dlg, popup);                      popup_multiple (dlg, popup);
# Line 1056  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1585  keymanager_dlg_proc (HWND dlg, UINT msg,
1585                  DestroyMenu (hm);                  DestroyMenu (hm);
1586                  return TRUE;                  return TRUE;
1587              }              }
             #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) /* XXX */  
                         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  
1588              break;              break;
1589    
1590          case LVN_COLUMNCLICK:          case LVN_COLUMNCLICK:
1591              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1592                  NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;                  NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
1593                  int sortby = 0;                  int sortby = 0;
1594    
1595                    if (!wait_for_progress_cb (0))
1596                        break;
1597                  switch (nft->iSubItem) {                  switch (nft->iSubItem) {
1598                  case 0:  sortby = KEY_SORT_USERID; break;                  case 0:  sortby = KEY_SORT_USERID; break;
1599                  case 1:  sortby = KEY_SORT_KEYID; break;                  case 1:  sortby = KEY_SORT_KEYID; break;
# Line 1089  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1603  keymanager_dlg_proc (HWND dlg, UINT msg,
1603                  case 6:  sortby = KEY_SORT_OTRUST; break;                  case 6:  sortby = KEY_SORT_OTRUST; break;
1604                  case 7:  sortby = KEY_SORT_CREATED; break;                  case 7:  sortby = KEY_SORT_CREATED; break;
1605                  case 8:  sortby = KEY_SORT_ALGO; break;                  case 8:  sortby = KEY_SORT_ALGO; break;
1606                  default: return TRUE; //sortby = KEY_SORT_USERID; break;                  default: return TRUE; /*sortby userid.*/
1607                  }                  }
1608    
1609                  if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)                  if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)
# Line 1125  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1639  keymanager_dlg_proc (HWND dlg, UINT msg,
1639          break;          break;
1640    
1641      case WM_INITMENUPOPUP:      case WM_INITMENUPOPUP:
1642          if ((UINT)LOWORD (lparam) == 3) {          hm = (HMENU)wparam;
1643              HMENU h = (HMENU)wparam;          if ((UINT)LOWORD (lparam) == 3)
1644              set_menu_text_bypos (h, 0, _("New"));              set_menu_text_bypos (hm, 0, _("New"));
1645          }          else if ((UINT)LOWORD (lparam) == 1)
1646                set_menu_text_bypos (hm, 8, _("Preferences..."));
1647          return FALSE;          return FALSE;
1648    
1649      case WM_COMMAND:      case WM_COMMAND:
# Line 1138  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1653  keymanager_dlg_proc (HWND dlg, UINT msg,
1653                       _("Key Manager"), MB_ERR);                       _("Key Manager"), MB_ERR);
1654              return FALSE;              return FALSE;
1655          }          }
1656          do_check_cache (kmi->lv, dlg, kmi->statbar);  
1657          switch( LOWORD (wparam)) {          /*wait_for_progress_cb ();*/
1658            switch (LOWORD (wparam)) {
1659          case ID_KEYMISC_QUIT:          case ID_KEYMISC_QUIT:
1660              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
1661              return TRUE;              return TRUE;
               
         case ID_KEYMISC_MAIL:  
             /* XXX  
             DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_MAIL, GetDesktopWindow (),  
                             winpt_mail_proc, NULL);*/  
             break;  
1662                    
1663          case ID_KEYMISC_FIND:          case ID_KEYMISC_FIND:
1664              km_find_key (dlg, kmi->lv);              km_find_key (dlg, kmi->lv);
# Line 1157  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1667  keymanager_dlg_proc (HWND dlg, UINT msg,
1667          case ID_KEYMISC_DELETE:          case ID_KEYMISC_DELETE:
1668          case ID_KEYMISC_DELETE2:          case ID_KEYMISC_DELETE2:
1669              if (!km_delete_keys (kmi->lv, dlg))              if (!km_delete_keys (kmi->lv, dlg))
1670                  km_update_status_bar (kmi->statbar, kmi->lv);                  update_status_bar (kmi->statbar, kmi->lv);
1671              return TRUE;              return TRUE;
1672                            
1673          case ID_KEYMISC_SIGN:          case ID_KEYMISC_SIGN:
1674              if (kmi->lv_idx == -1) {              if (kmi->lv_idx == -1) {
1675                  msg_box (dlg, _("Please select a key."),                    msg_box (dlg, _("Please select a key."),  
1676                           _("Key Manager"), MB_ERR);                           _("Key Manager"), MB_ERR);
1677                  return TRUE;;                  return TRUE;
1678              }              }
1679              if (km_check_key_status (kmi->lv, kmi->lv_idx))              if (km_check_key_status (kmi->lv, kmi->lv_idx))
1680                  return TRUE;                  return TRUE;
1681              key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);              km_get_key (kmi->lv, kmi->lv_idx, &k);
             listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);  
             memset (&k, 0, sizeof (k));  
             k.ctx = key;  
             k.keyid = keyid;  
1682              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,
1683                                keysign_dlg_proc, (LPARAM)&k,                                keysign_dlg_proc, (LPARAM)&k,
1684                                _("Key Signing"), IDS_WINPT_KEYSIGN);                                _("Key Signing"), IDS_WINPT_KEYSIGN);
1685              if (k.update)              if (k.update)
1686                  update_key (kmi->lv, kmi->lv_idx, k.keyid, 0);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1687              return TRUE;              return TRUE;
1688                            
1689          case ID_KEYMISC_REVCERT:          case ID_KEYMISC_REVCERT:
# Line 1185  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1691  keymanager_dlg_proc (HWND dlg, UINT msg,
1691                  msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);                  msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1692                  return TRUE;                  return TRUE;
1693              }              }
1694              listview_get_item_text (kmi->lv, kmi->lv_idx, 0, uid, sizeof uid-1);                  
             listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, sizeof keyid-1);  
             if ( !km_check_for_seckey( kmi->lv, kmi->lv_idx, NULL ) ) {  
                 msg_box (dlg, _("There is no secret key available!"),  
                         _("Key Manager"), MB_ERR);  
                 return TRUE;  
             }  
               
1695              {              {
1696                  char state[64];                  char state[64];
1697                  listview_get_item_text (kmi->lv, kmi->lv_idx, 5,                  listview_get_item_text (kmi->lv, kmi->lv_idx, 5,
1698                                          state, sizeof (state) -1);                                          state, sizeof (state) -1);
1699                  if( strchr (state, 'R' )) {                  if (strchr (state, 'R' )) {
1700                      msg_box (dlg, _("Key already revoked!"),                      msg_box (dlg, _("Key already revoked!"),
1701                               _("Key Manager"), MB_INFO);                               _("Key Manager"), MB_INFO);
1702                      return TRUE;                      return TRUE;
1703                  }                  }
1704              }              }
1705                
1706              memset (&k, 0, sizeof (k));              km_get_key (kmi->lv, kmi->lv_idx, &k);
1707              k.key_pair = 1;              if (!k.key_pair) {
1708              k.keyid = keyid;                  msg_box (dlg, _("There is no secret key available!"),
1709              k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);                          _("Key Manager"), MB_ERR);
1710                    return TRUE;
1711                }
1712              dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,              dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,
1713                               key_revoke_dlg_proc, (LPARAM)&k,                               key_revoke_dlg_proc, (LPARAM)&k,
1714                               _("Key Revocation"), IDS_WINPT_KEYREVOKE);                               _("Key Revocation Cert"), IDS_WINPT_KEYREVOKE);
1715              return TRUE;              return TRUE;
1716                            
1717          case ID_KEYMISC_TRUSTPATH:          case ID_KEYMISC_TRUSTPATH:
# Line 1218  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1719  keymanager_dlg_proc (HWND dlg, UINT msg,
1719                  msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);                  msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1720                  return TRUE;                  return TRUE;
1721              }              }
1722              listview_get_item_text( kmi->lv, kmi->lv_idx, 0, uid, sizeof uid -1 );              km_get_key (kmi->lv, kmi->lv_idx, &k);
1723              listview_get_item_text( kmi->lv, kmi->lv_idx, 1, keyid, sizeof keyid -1 );              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,
             if( km_check_for_seckey( kmi->lv, kmi->lv_idx, NULL ) ) {  
                 msg_box( dlg, _("It does not make any sense with a key pair!"), _("Key Manager"), MB_OK );  
                 return TRUE;  
             }  
             memset (&k, 0, sizeof (k));  
             k.keyid = keyid;  
             k.uid = uid;  
             dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,  
1724                                keytrust_dlg_proc, (LPARAM)&k,                                keytrust_dlg_proc, (LPARAM)&k,
1725                                _("List Trust Path"), IDS_WINPT_KEYTRUST );                                _("List Trust Path"), IDS_WINPT_KEYTRUST);
1726              return TRUE;              return TRUE;
1727                            
1728          case ID_KEYMISC_CHECKSIGS:                    case ID_KEYMISC_CHECKSIGS:          
# Line 1237  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1730  keymanager_dlg_proc (HWND dlg, UINT msg,
1730                  msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);                  msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1731                  return TRUE;                  return TRUE;
1732              }              }
1733              listview_get_item_text (kmi->lv, kmi->lv_idx, 0, uid, DIM (uid)-1);              km_get_key (kmi->lv, kmi->lv_idx, &k);
1734              listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG_TREE, dlg,
1735              memset (&k, 0, sizeof (k));                                sigtree_dlg_proc, (LPARAM)&k,
1736              k.keyid = keyid;                                _("Key Signature List"), IDS_WINPT_KEYSIG);
1737              k.uid = uid;              if (k.update)
1738              k.ctx = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1739              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG, dlg,              if (updated_keys_avail ())
1740                                keysig_dlg_proc, (LPARAM)&k,                  refresh_keylist (kmi);
                               _("Key Signature List" ), IDS_WINPT_KEYSIG);  
1741              return TRUE;              return TRUE;
1742                            
1743          case ID_KEYMISC_PROPS:                case ID_KEYMISC_PROPS:      
1744              if (kmi->lv_idx == -1) {              if (kmi->lv_idx == -1) {
1745                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );                  msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1746                  return TRUE;                  return TRUE;
1747              }              }
1748              listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);              km_get_key (kmi->lv, kmi->lv_idx, &k);
             listview_get_item_text (kmi->lv, kmi->lv_idx, 2, type, DIM (type)-1);  
             memset (&k, 0, sizeof (k));  
             k.key_pair = 0;  
             k.keyid = keyid;  
             if( !strcmp( type, "pub/sec" ) || !strcmp( type, "pub/crd" ) )  
                 k.key_pair = 1;  
1749              k.callback.ctl = kmi->lv;              k.callback.ctl = kmi->lv;
1750              k.callback.idx = kmi->lv_idx;              k.callback.idx = kmi->lv_idx;
1751              k.is_v3 = km_key_is_v3 (kmi->lv, kmi->lv_idx);              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,
             dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,  
1752                                keyprops_dlg_proc, (LPARAM)&k,                                keyprops_dlg_proc, (LPARAM)&k,
1753                                _("Key Properties"), IDS_WINPT_KEYPROPS );                                _("Key Properties"), IDS_WINPT_KEYPROPS);
1754              if (k.callback.new_val != 0) {              if (k.update)
1755                  t = get_key_trust_str (k.callback.new_val);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, k.key_pair);
                 listview_add_sub_item (kmi->lv, kmi->lv_idx, 6, t);  
             }  
1756              return TRUE;              return TRUE;
1757                            
1758          case ID_KEYMISC_RECACHE:          case ID_KEYMISC_RECACHE:
1759              /* If there is already a reload request, don't bother the user with a message. */              if (updated_keys_avail ())
             if (keycache_get_reload() == 1)  
1760                  l_idx = IDYES;                  l_idx = IDYES;
1761              else {              else {
1762                  char inf[256];                  l_idx = log_box (_("Key Manager"), MB_YESNO,
                 _snprintf (inf, sizeof (inf) -1,  
1763                             _("This is only useful when the keyring has been "                             _("This is only useful when the keyring has been "
1764                               "modified (sign a key...).\n"                               "modified (sign a key...).\n"
1765                               "Do you really want to reload the keycache?"));                               "Do you really want to reload the keycache?"));
                 l_idx = msg_box (dlg, inf, _("Key Manager"), MB_YESNO);  
             }  
             if (l_idx == IDYES) {  
                 rcs.kr_reload = rcs.kr_update = 1;  
                 rcs.tr_update = 0;  
                 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,  
                                 keycache_dlg_proc, (LPARAM)&rcs);  
                 c = keycache_get_ctx (1);  
                 if (!c)  
                     BUG (dlg);  
                 keylist_reload (kmi->lv, c, KEYLIST_LIST, KEY_SORT_USERID);  
                 refresh_keys = 0;  
1766              }              }
1767                if (l_idx == IDYES)
1768                    reload_keycache (kmi);
1769              return TRUE;              return TRUE;
1770                            
1771          case ID_KEYMISC_REBUILD:          case ID_KEYMISC_REBUILD:
# Line 1305  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1776  keymanager_dlg_proc (HWND dlg, UINT msg,
1776                  show_msg (dlg, 2000, line? name + (line-name)+1 : name);                  show_msg (dlg, 2000, line? name + (line-name)+1 : name);
1777                  safe_free (name);                  safe_free (name);
1778              }              }
1779                SetForegroundWindow (dlg);
1780              return TRUE;              return TRUE;
1781                            
1782          case ID_KEYMISC_NEWKEY:          case ID_KEYMISC_NEWKEY:
# Line 1312  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1784  keymanager_dlg_proc (HWND dlg, UINT msg,
1784              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,
1785                                keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),                                keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),
1786                                IDS_WINPT_KEYGEN);                                IDS_WINPT_KEYGEN);
1787              if (genkey.newkey != NULL) {              if (genkey.cancel == 0)
1788                  keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);                  refresh_keylist (kmi);
                 keylist_sort (kmi->lv, KEY_SORT_USERID);  
             }  
1789              return TRUE;              return TRUE;
1790    
1791          case ID_KEYMISC_CARDNEW:          case ID_KEYMISC_CARDNEW:
# Line 1327  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1797  keymanager_dlg_proc (HWND dlg, UINT msg,
1797              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,
1798                                card_keygen_dlg_proc, 0, _("Card Key Generation"),                                card_keygen_dlg_proc, 0, _("Card Key Generation"),
1799                                IDS_WINPT_CARD_KEYGEN);                                IDS_WINPT_CARD_KEYGEN);
1800              /* XXX: use new code */              if (updated_keys_avail ())
             if (keycache_get_reload ())  
1801                  send_cmd_id (dlg, ID_KEYMISC_RECACHE);                  send_cmd_id (dlg, ID_KEYMISC_RECACHE);
1802              return TRUE;              return TRUE;
1803    
# Line 1338  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1807  keymanager_dlg_proc (HWND dlg, UINT msg,
1807                                keygen_wizard_dlg_proc, (LPARAM)&genkey,                                keygen_wizard_dlg_proc, (LPARAM)&genkey,
1808                                _("Key Generation Wizard"),                                _("Key Generation Wizard"),
1809                                IDS_WINPT_KEYWIZARD);                                IDS_WINPT_KEYWIZARD);
1810              if (genkey.newkey != NULL) {              if (genkey.cancel == 0)
1811                  keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);                  refresh_keylist (kmi);
                 keylist_sort (kmi->lv, KEY_SORT_USERID);  
             }  
1812              return TRUE;              return TRUE;
1813                            
1814          case ID_KEYMISC_SENDRECV:          case ID_KEYMISC_SENDRECV:
             memset (&genkey, 0, sizeof (genkey));  
1815              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,
1816                                keyserver_dlg_proc, (LPARAM)&genkey, _("Keyserver Access"),                                keyserver_dlg_proc, 0, _("Keyserver Access"),
1817                                IDS_WINPT_KEYSERVER);                                IDS_WINPT_KEYSERVER);
1818              if (genkey.newkey != NULL) {              refresh_keylist (kmi);
                 keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);  
                 keylist_sort (kmi->lv, KEY_SORT_USERID);  
             }  
1819              return TRUE;              return TRUE;
1820                            
1821            case ID_KEYMISC_WINPTPREFS:
1822                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_PREFS,
1823                                  dlg, prefs_dlg_proc, 0,
1824                                  _("WinPT Preferences"), 0);
1825                break;
1826    
1827          case ID_KEYMISC_GPGPREFS:          case ID_KEYMISC_GPGPREFS:
1828              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg,              rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS,
1829                                gpgprefs_dlg_proc, 0, _("GnuPG Preferences"),                                     dlg, gpgprefs_dlg_proc, 0,
1830                                IDS_WINPT_GPGPREFS );                                     _("GnuPG Preferences"), IDS_WINPT_GPGPREFS);
1831                if (rc == TRUE) {
1832                    reload_keycache (kmi);
1833                    update_default_key_str (kmi->statbar);
1834                }
1835              return TRUE;              return TRUE;
1836                            
1837          case ID_KEYMISC_GPGOPT:          case ID_KEYMISC_GPGOPT:
1838              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,
1839                                gpgopt_dlg_proc, 0, _("GnuPG Options" ),                                gpgopt_dlg_proc, 0, _("GnuPG Options"),
1840                                IDS_WINPT_GPGOPT );                                IDS_WINPT_GPGOPT);
1841              return TRUE;              return TRUE;
1842                            
1843          case ID_KEYMISC_IMPORT:          case ID_KEYMISC_IMPORT:
1844              t = get_fileopen_dlg (dlg, _("Choose Name of the Key File"), NULL, NULL);              km_gui_import (kmi, LOWORD (wparam), NULL);
             if (t)  
                 km_file_import (dlg, t);  
1845              return TRUE;              return TRUE;
1846    
1847          case ID_KEYMISC_IMPORT_HTTP:          case ID_KEYMISC_IMPORT_HTTP:
1848              url = (struct URL_ctx_s*)get_http_file_dlg (dlg);              url = (struct URL_ctx_s*)get_http_file_dlg (dlg);
1849              if (url->cancel == 0)              if (url && url->cancel == 0) {
1850                  km_http_import (dlg, url->url);                  km_http_import (dlg, url->url);
1851              delete url; url=NULL;                  refresh_keylist (kmi);
1852                }
1853                free_if_alloc (url);
1854              break;              break;
1855                            
1856          case ID_KEYMISC_EXPORT:          case ID_KEYMISC_EXPORT:
1857              if (kmi->lv_idx == -1) {              if (kmi->lv_idx == -1) {
1858                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );                  msg_box (dlg, _("Please select a key."),
1859                             _("Key Manager"), MB_ERR);
1860                  return TRUE;                  return TRUE;
1861              }              }
1862              if (listview_count_items (kmi->lv, 1) > 1)              if (listview_count_items (kmi->lv, 1) > 1)
1863                  name = m_strdup ("Exported_GPG_Keys.asc");                  name = m_strdup ("Exported_GPG_Keys.asc");
1864              else {              else {
1865                  listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);                  key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1866                  name = gen_export_filename (keyid, 0);                  name = km_gen_export_filename (key->subkeys->keyid+8, 0);
1867              }              }
1868              t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);              t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1869              free_if_alloc (name);              free_if_alloc (name);
# Line 1420  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1894  keymanager_dlg_proc (HWND dlg, UINT msg,
1894                              "to copy the key to a safe place.\n\n"                              "to copy the key to a safe place.\n\n"
1895                              "Do you really want to export the key?"),                              "Do you really want to export the key?"),
1896                            _("WARNING"), MB_INFO|MB_YESNO);                            _("WARNING"), MB_INFO|MB_YESNO);
1897              if( i == IDYES ) {              if (i == IDYES) {
1898                  listview_get_item_text( kmi->lv, kmi->lv_idx, 1, keyid, sizeof (keyid)-8 );                  key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1899                  name = gen_export_filename (keyid, 1);                  name = km_gen_export_filename (key->subkeys->keyid+8, 1);
1900                  t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);                  t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1901                  if (t != NULL)                            if (t != NULL)          
1902                      km_privkey_export (dlg, kmi->lv, t);                      km_privkey_export (dlg, kmi->lv, t);
# Line 1430  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1904  keymanager_dlg_proc (HWND dlg, UINT msg,
1904              return TRUE;              return TRUE;
1905    
1906          case ID_KEYMISC_INFO:          case ID_KEYMISC_INFO:
1907              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, dlg,
1908                                about_winpt_dlg_proc, 0, _("About WinPT"),                                about_winpt_dlg_proc, 0, _("About WinPT"),
1909                                IDS_WINPT_ABOUT);                                IDS_WINPT_ABOUT);
1910              break;              break;
1911    
1912            case ID_KEYMISC_DEVWWW:
1913                ShellExecute (dlg, "open", "http://wald.intevation.org/projects/winpt",
1914                              NULL, NULL, SW_SHOW);
1915                break;
1916    
1917            case ID_KEYMISC_WEBSITE:
1918                ShellExecute (dlg, "open", "http://www.winpt.org",
1919                              NULL, NULL, SW_SHOW);
1920                break;
1921    
1922          case ID_KEYMISC_HELP:          case ID_KEYMISC_HELP:
1923              ShellExecute (dlg, "open", "winpt.chm", NULL, NULL, SW_SHOW);              start_help (dlg, 0);
1924              break;              break;
1925    
1926          case ID_KEYMISC_OT:          case ID_KEYMISC_OT:
1927              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST, glob_hwnd,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST,
1928                                ownertrust_dlg_proc, 0,                                dlg, ownertrust_dlg_proc, 0,
1929                                _("Ownertrust"), IDS_WINPT_OWNERTRUST );                                _("Ownertrust"), IDS_WINPT_OWNERTRUST);
1930              break;              break;
1931    
1932          case ID_KEYMISC_EDITKEY:                    case ID_KEYMISC_EDITKEY:
1933              if (kmi->lv_idx == -1)              if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1934                  break;                  break;
             listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, sizeof (keyid)-1);  
             /* XXX: pub/crd = secret key does not work */  
             memset (&k, 0, sizeof (k));  
             k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);  
             k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);  
             k.keyid = keyid;  
             k.is_v3 = km_key_is_v3 (kmi->lv, kmi->lv_idx);  
             k.flags = km_get_key_status (kmi->lv, kmi->lv_idx);  
1935              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,
1936                                keyedit_main_dlg_proc, (LPARAM)&k,                                keyedit_main_dlg_proc, (LPARAM)&k,
1937                                _("Key Edit"), IDS_KEYCTX_EDIT);                                _("Key Edit"), IDS_KEYCTX_EDIT);
1938              if (k.update)              if (k.update)
1939                  update_key (kmi->lv,  kmi->lv_idx, keyid, 1);                  update_key (kmi->lv,  kmi->lv_idx, k.tmp_keyid, 1);
1940              break;              break;
1941                            
1942          case ID_KEYMISC_COPY:          case ID_KEYMISC_COPY:
# Line 1472  keymanager_dlg_proc (HWND dlg, UINT msg, Line 1948  keymanager_dlg_proc (HWND dlg, UINT msg,
1948              break;              break;
1949    
1950          case ID_KEYMISC_PASTE:          case ID_KEYMISC_PASTE:
1951              km_clip_import (dlg);              km_gui_import (kmi, LOWORD (wparam), NULL);
1952              break;              break;
1953                            
1954          case ID_KEYCTX_SETPREFKS:          case ID_KEYCTX_SETPREFKS:
1955              listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM(keyid)-1);              if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1956              memset (&k, 0, sizeof (k));                  break;
             k.keyid = keyid;  
1957              keyedit_set_pref_keyserver (&k, dlg);              keyedit_set_pref_keyserver (&k, dlg);
1958              break;              break;
1959    
1960          case ID_KEYMISC_REFRESH_KEYS:          case ID_KEYMISC_REFRESH_KEYS:
1961              if (listview_count_items (kmi->lv, 1) == 0) {              if (listview_count_items (kmi->lv, 1) == 0) {
1962                  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."),
1963                             _("Key Manager"), MB_INFO);
1964                  listview_select_all (kmi->lv);                  listview_select_all (kmi->lv);
1965              }              }
1966              km_refresh_from_keyserver (kmi->lv, dlg);              if (!km_refresh_from_keyserver (kmi->lv, dlg))
1967                    msg_box (dlg, _("Keyserver refresh finished."),
1968                             _("Key Manager"), MB_OK);
1969              break;              break;
1970                                                    
1971          /** Context menu **/          /** Context menu **/
# Line 1525  keymanager_dlg_proc (HWND dlg, UINT msg, Line 2003  keymanager_dlg_proc (HWND dlg, UINT msg,
2003              break;              break;
2004    
2005          case ID_KEYCTX_ADDKEY:          case ID_KEYCTX_ADDKEY:
2006              listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);              km_get_key (kmi->lv, kmi->lv_idx, &k);
             memset (&k, 0, sizeof (k));  
             k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);  
             k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);  
             k.keyid = keyid;  
2007              keyedit_add_subkey (&k, dlg, NULL);              keyedit_add_subkey (&k, dlg, NULL);
2008              if (k.update)              if (k.update)
2009                  update_key (kmi->lv, kmi->lv_idx, keyid, 1);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
2010              break;              break;
2011    
2012          case ID_KEYCTX_ADDUID:          case ID_KEYCTX_ADDUID:
2013              listview_get_item_text( kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);              km_get_key (kmi->lv, kmi->lv_idx, &k);
             memset (&k, 0, sizeof (k));  
             k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);  
             k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);  
             k.keyid = keyid;  
2014              keyedit_add_userid (&k, dlg, NULL);              keyedit_add_userid (&k, dlg, NULL);
2015              if (k.update)              if (k.update)
2016                  update_key (kmi->lv, kmi->lv_idx, keyid, 1);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
2017              break;              break;
2018    
2019          case ID_KEYCTX_ADDREV:          case ID_KEYCTX_ADDREV:
2020              listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);              km_get_key (kmi->lv, kmi->lv_idx, &k);
             memset (&k, 0, sizeof (k));  
             k.keyid = keyid;  
             k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);  
             k.key_pair = km_check_for_seckey( kmi->lv, kmi->lv_idx, NULL );  
2021              keyedit_add_revoker (&k, dlg);              keyedit_add_revoker (&k, dlg);
2022              if (k.update)              if (k.update)
2023                  update_key (kmi->lv, kmi->lv_idx, keyid, 1);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
2024              break;              break;
2025    
2026          case ID_KEYCTX_ADDPHOTO:          case ID_KEYCTX_ADDPHOTO:
2027              listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);              km_get_key (kmi->lv, kmi->lv_idx, &k);
             memset (&k, 0, sizeof (k));  
             k.keyid = keyid;  
             k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);  
             k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);  
2028              keyedit_add_photo (&k, dlg);              keyedit_add_photo (&k, dlg);
2029              if (k.update)              if (k.update)
2030                  update_key (kmi->lv, kmi->lv_idx, keyid, 1);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
2031              break;              break;
2032    
2033          case ID_KEYCTX_KS_NL:          case ID_KEYCTX_RECVFROM:
         case ID_KEYCTX_KS_PL:  
         case ID_KEYCTX_KS_AT:  
         case ID_KEYCTX_KS_DE:  
         case ID_KEYCTX_KS_DK:  
         case ID_KEYCTX_KS_CZ:  
         case ID_KEYCTX_KS_ES:  
         case ID_KEYCTX_KS_UK:  
             host = kserver_get_hostname (LOWORD (wparam) - 40107, 0, &port);  
             km_send_to_keyserver (kmi->lv, dlg, host, port);  
             break;  
   
         case ID_KEYCTX_RECVFROM:  
2034              km_refresh_from_keyserver (kmi->lv, dlg);              km_refresh_from_keyserver (kmi->lv, dlg);
2035                if (updated_keys_avail ())
2036                    refresh_keylist (kmi);
2037              break;              break;
2038    
2039          case ID_KEYCTX_UID_COPY:          case ID_KEYCTX_UID_COPY:
             /* XXX: add generic function to support multiple selection  
                     with a callback */  
             listview_get_item_text( kmi->lv, kmi->lv_idx, 0, uid, sizeof uid-1 );  
             set_clip_text( NULL, uid, strlen( uid ) );  
             break;  
   
2040          case ID_KEYCTX_KEYID_COPY:          case ID_KEYCTX_KEYID_COPY:
             listview_get_item_text (kmi->lv, kmi->lv_idx, 1, uid, sizeof uid-1);  
             set_clip_text (NULL, uid, strlen (uid));  
             break;  
   
2041          case ID_KEYCTX_FPR_COPY:          case ID_KEYCTX_FPR_COPY:
             key = (gpgme_key_t) listview_get_item2 (kmi->lv, kmi->lv_idx);          
             if (key) {  
                 t = get_key_fpr (key);  
                 set_clip_text (NULL, t? t : "", t? strlen (t): 0);  
             }  
             break;  
   
2042          case ID_KEYCTX_KINFO_COPY:          case ID_KEYCTX_KINFO_COPY:
2043              listview_get_item_text( kmi->lv, kmi->lv_idx, 1, uid, sizeof uid-1 );          case ID_KEYCTX_EMAIL_COPY:
2044              km_set_clip_info( uid );                      copy_key_info (LOWORD (wparam), kmi);
2045              break;              break;
2046    
2047          case ID_KEYCTX_COPY:          case ID_KEYCTX_COPY:
2048              km_clip_export (dlg, kmi->lv);              send_cmd_id (dlg, ID_KEYMISC_COPY);
2049              break;              break;
2050    
2051          case ID_KEYCTX_PASTE:          case ID_KEYCTX_PASTE:
2052              km_clip_import (dlg);              send_cmd_id (dlg, ID_KEYMISC_PASTE);
2053              break;              break;
2054    
2055          case ID_KEYCTX_DISABLE:          case ID_KEYCTX_DISABLE:
2056          case ID_KEYCTX_ENABLE:          case ID_KEYCTX_ENABLE:
2057              i = LOWORD (wparam) == ID_KEYCTX_ENABLE? 1 : 0;              i = LOWORD (wparam) == ID_KEYCTX_ENABLE? 1 : 0;
2058              listview_get_item_text (kmi->lv, kmi->lv_idx, KM_COL_KEYID,              if (km_get_key (kmi->lv, kmi->lv_idx, &k))
2059                                      keyid, DIM (keyid)-1);                  break;
2060              rc = km_enable_disable_key (kmi->lv, dlg, kmi->lv_idx, i);              rc = km_enable_disable_key (kmi->lv, dlg, kmi->lv_idx, i);
2061              if (!rc)              if (!rc)
2062                  update_key (kmi->lv, kmi->lv_idx, keyid, 0);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
             /* XXX: switching a key from disabled -> enabled. does not  
                change the validity field in the KM. */  
2063              break;              break;
2064    
2065          case ID_KEYCTX_LISTSIGS:          case ID_KEYCTX_LISTSIGS:
# Line 1634  keymanager_dlg_proc (HWND dlg, UINT msg, Line 2067  keymanager_dlg_proc (HWND dlg, UINT msg,
2067              break;              break;
2068    
2069          case ID_KEYCTX_MAXTRUST:          case ID_KEYCTX_MAXTRUST:
2070              listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);              if (km_get_key (kmi->lv, kmi->lv_idx, &k))
2071                    break;
2072              rc = km_set_implicit_trust (dlg, kmi->lv, kmi->lv_idx);              rc = km_set_implicit_trust (dlg, kmi->lv, kmi->lv_idx);
2073              if (!rc)              if (!rc)
2074                  update_key (kmi->lv, kmi->lv_idx, keyid, 0);                  update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
2075              break;              break;
2076    
2077          case ID_KEYCTX_SETDEFKEY:          case ID_KEYCTX_SETDEFKEY:
2078              if (!km_check_key_status (kmi->lv, kmi->lv_idx)) {              if (!km_check_key_status (kmi->lv, kmi->lv_idx)) {
2079                  listview_get_item_text (kmi->lv, kmi->lv_idx, 1, keyid, DIM (keyid)-1);                  key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
2080                  rc = set_gnupg_default_key (keyid);                  rc = set_gnupg_default_key (key->subkeys->keyid+8);
2081                  if (rc)                  if (rc)
2082                      msg_box (dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);                      msg_box (dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);
2083                  km_update_default_key_str (kmi->statbar);                  update_default_key_str (kmi->statbar);
2084              }              }
2085              break;              break;
2086    
2087            case ID_KEYMISC_VIEWKEYID:
2088            case ID_KEYMISC_VIEWCIPHER:
2089            case ID_KEYMISC_VIEWTYPE:
2090            case ID_KEYMISC_VIEWCREAT:
2091            case ID_KEYMISC_VIEWDESC:
2092                hm = GetMenu (dlg);
2093                i = get_menu_state (hm, LOWORD (wparam));
2094                set_menu_state (hm, LOWORD (wparam),
2095                                i & MFS_CHECKED? MFS_UNCHECKED : MFS_CHECKED);
2096                modify_listview_columns (kmi, LOWORD (wparam), !(i & MFS_CHECKED));
2097                break;
2098    
2099          case ID_GROUP_NEW:          case ID_GROUP_NEW:
2100          case ID_GROUP_PASTE:          case ID_GROUP_PASTE:
2101          case ID_GROUP_DELETE:          case ID_GROUP_DELETE:
2102            case ID_GROUP_SHOW:
2103              /* XXX: Implement group manager. */              /* XXX: Implement group manager. */
2104              return TRUE;              return TRUE;
2105          }          }
# Line 1662  keymanager_dlg_proc (HWND dlg, UINT msg, Line 2109  keymanager_dlg_proc (HWND dlg, UINT msg,
2109            
2110      return FALSE;      return FALSE;
2111  }  }
   
   
   

Legend:
Removed from v.123  
changed lines
  Added in v.255

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26