/[winpt]/trunk/Src/wptKeyManagerDlg.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeyManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26