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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26