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

Legend:
Removed from v.36  
changed lines
  Added in v.273

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26