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

Legend:
Removed from v.48  
changed lines
  Added in v.175

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26