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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26