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

Legend:
Removed from v.119  
changed lines
  Added in v.350

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26