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

Legend:
Removed from v.104  
changed lines
  Added in v.226

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26