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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26