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

Diff of /trunk/Src/wptKeyEditDlgs.cpp

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

revision 229 by twoaday, Mon Jun 19 14:04:31 2006 UTC revision 314 by twoaday, Sun May 13 09:44:03 2007 UTC
# Line 1  Line 1 
1  /* wptKeyEditDlgs.cpp - GPG key edit dialogs  /* wptKeyEditDlgs.cpp - GPG key edit dialogs
2   *      Copyright (C) 2002-2006 Timo Schulz   *      Copyright (C) 2002-2007 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * 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  
15   */   */
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
# Line 41  Line 37 
37  #include "wptKeyManager.h"  #include "wptKeyManager.h"
38  #include "wptRegistry.h"  #include "wptRegistry.h"
39  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
40    #include "StringBuffer.h"
41    
42    
43  /* All edit key commands. */  /* All edit key commands. */
44  enum keyedit_commands {      enum keyedit_commands {    
# Line 52  enum keyedit_commands { Line 50  enum keyedit_commands {
50      CMD_DELKEY,      CMD_DELKEY,
51      CMD_EXPIRE,      CMD_EXPIRE,
52      CMD_SHOWPREF,      CMD_SHOWPREF,
53      //CMD_SETPREF,      CMD_SETPREF,
54      CMD_PASSWD,      CMD_PASSWD,
55      CMD_PRIMARY,      CMD_PRIMARY,
56      CMD_TRUST,      CMD_TRUST,
# Line 134  typedef struct keyedit_cb_s *keyedit_cb_ Line 132  typedef struct keyedit_cb_s *keyedit_cb_
132    
133  /* Key generation callback context. */  /* Key generation callback context. */
134  struct keygen_cb_s {  struct keygen_cb_s {
135      int   bits;      int    bits;
136      int   algo;      int    algo;
137      u32   expire;      DWORD  expire; /* date of expiration or '0' for infinite valid. */
138      char *fpr;      char  *fpr;
139      char *name;      char  *name;
140      char *comment;      char  *comment;
141      char *email;      char  *email;
142  };  };
143  typedef struct keygen_cb_s *keygen_cb_t;  typedef struct keygen_cb_s *keygen_cb_t;
144    
# Line 151  static subclass_s keyedit_subkey_proc; Line 149  static subclass_s keyedit_subkey_proc;
149  static subclass_s keyedit_uid_proc;  static subclass_s keyedit_uid_proc;
150    
151  int keygen_check_date (SYSTEMTIME *st);  int keygen_check_date (SYSTEMTIME *st);
152  void get_userid_preflist (char **r_prefs, int *r_flags);  void get_userid_preflist (const char *old_prefs, char **r_prefs, int *r_flags);
153  char* get_subkey_keyid (const char *keyid);  char* get_subkey_keyid (const char *keyid);
154  void ComboBox_AddString_utf8 (HWND cb, const char *txt);  void ComboBox_AddString_utf8 (HWND cb, const char *txt);
155    
156    
 /* Safe wrapper for allocation. */  
 static GpgKeyEdit*  
 create_GpgKeyEdit (const char *keyid)  
 {  
     GpgKeyEdit *ke;  
   
     ke = new GpgKeyEdit (keyid);  
     if (!ke)  
         BUG (NULL);  
     return ke;  
 }  
   
   
157  /* Associate each key with a combo box entry.  /* Associate each key with a combo box entry.
158     Skip the key in @k. */     Skip the key in @k. */
159  static void  static void
# Line 182  do_init_keylist (HWND dlg, const char *k Line 167  do_init_keylist (HWND dlg, const char *k
167      pub = keycache_get_ctx (1);      pub = keycache_get_ctx (1);
168      gpg_keycache_rewind (pub);      gpg_keycache_rewind (pub);
169      while (!gpg_keycache_next_key (pub, 0, &key)) {      while (!gpg_keycache_next_key (pub, 0, &key)) {
170          if (key->expired || key->revoked ||          if (!key_is_useable (key) || key->invalid)
             key->disabled || key->invalid)  
171              continue;              continue;
172          s = key->uids->uid;          s = key->uids->uid;
173          kid = key->subkeys->keyid;          kid = key->subkeys->keyid;
# Line 191  do_init_keylist (HWND dlg, const char *k Line 175  do_init_keylist (HWND dlg, const char *k
175              continue;              continue;
176          ComboBox_AddString_utf8 (GetDlgItem (dlg, IDC_ADDREV_KEYLIST), s);          ComboBox_AddString_utf8 (GetDlgItem (dlg, IDC_ADDREV_KEYLIST), s);
177      }      }
178        
179      gpg_keycache_rewind (pub);      gpg_keycache_rewind (pub);
180        /* In the second loop, we set a key pointer for each element. */
181      n = SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0);      n = SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0);
182      for (i = 0; i < n; i++) {      for (i = 0; i < n; i++) {
183          gpg_keycache_next_key (pub, 0, &key);          gpg_keycache_next_key (pub, 0, &key);
# Line 208  do_add_new_userid (listview_ctrl_t lv, Line 194  do_add_new_userid (listview_ctrl_t lv,
194                     const char *utf8_name, const char *email,                     const char *utf8_name, const char *email,
195                     const char *utf8_comment)                     const char *utf8_comment)
196  {  {
197      char *p, *native;      StringBuffer p;
198      size_t n;      char *native;
199            
200      n = strlen (utf8_name) + strlen (email) + 16;      if (utf8_comment != NULL)
201      if (utf8_comment)          p = p + utf8_name + " (" + utf8_comment + ")";
         n += strlen (utf8_comment);  
     p = new char[n+1];  
     if (!p)  
         BUG (NULL);  
     if (utf8_comment)  
         sprintf (p, "%s (%s)", utf8_name, utf8_comment);  
202      else      else
203          sprintf (p, "%s", utf8_name);          p = p + utf8_name;
204      native = utf8_to_native (p);      native = utf8_to_native (p.getBuffer ());
     free_if_alloc (p);  
205    
206      listview_add_item (lv, "");      listview_add_item (lv, "");
207      listview_add_sub_item (lv, 0, UID_COL_VALID, _("Ultimate" ));      listview_add_sub_item (lv, 0, UID_COL_VALID, _("Ultimate" ));
208      listview_add_sub_item (lv, 0, UID_COL_NAME, native);      listview_add_sub_item (lv, 0, UID_COL_NAME, native);
209      listview_add_sub_item (lv, 0, UID_COL_EMAIL, email && *email? email : "");      listview_add_sub_item (lv, 0, UID_COL_EMAIL, email && *email? email : "");
210      listview_add_sub_item (lv, 0, UID_COL_CREATION, get_key_created (time (NULL)));      listview_add_sub_item (lv, 0, UID_COL_CREATION,
211                               get_key_created (time (NULL)));
212      free_if_alloc (native);      free_if_alloc (native);
213  }  }
214    
# Line 237  static void Line 217  static void
217  do_add_new_subkey (listview_ctrl_t lv, keygen_cb_t keygen, unsigned int flags)  do_add_new_subkey (listview_ctrl_t lv, keygen_cb_t keygen, unsigned int flags)
218  {  {
219      char info[128], keyid[32];      char info[128], keyid[32];
220      const char *expdate, *s;      const char *expdate, *s, *kid;
221      int n;      int n;
222            
223      expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never");      expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never");
224      _snprintf (info, sizeof (info)-1, "%d-bit %s",      _snprintf (info, DIM (info)-1, "%d-bit %s", keygen->bits,
                keygen->bits,  
225                 get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo));                 get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo));
226      _snprintf (keyid, sizeof (keyid)-1, "0x%s", keygen->fpr+8);      kid = get_keyid_from_fpr (keygen->fpr);
227        _snprintf (keyid, DIM (keyid)-1, "0x%s", kid);
228      s = get_key_created (time (NULL));      s = get_key_created (time (NULL));
229      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
230      listview_add_item_pos (lv, n);      listview_add_item_pos (lv, n);
# Line 270  static int Line 250  static int
250  do_find_userid (const char *keyid, const char *email,  do_find_userid (const char *keyid, const char *email,
251                  const char *name, gpg_uid_info_t *r_inf)                  const char *name, gpg_uid_info_t *r_inf)
252  {  {
253      GpgKeyEdit *ke;      GpgKeyEdit ke;
254      gpgme_error_t err;      gpgme_error_t err;
255      gpg_uid_info_t inf, ui;      gpg_uid_info_t inf, ui;
256      int pos = -1;      int pos = -1;
257    
258      ke = create_GpgKeyEdit (keyid);      ke.setKeyID (keyid);
259      err = ke->getUseridInfo (&inf);      err = ke.getUseridInfo (&inf);
     delete ke;  
260      if (err) {      if (err) {
261          log_box (_("user ID"), MB_ERR,          log_box (_("user ID"), MB_ERR,
262                   _("Could not get key information for: \"%s\":\n%s"),                   _("Could not get key information for: \"%s\":\n%s"),
# Line 327  is_jpg_file (const char *fname) Line 306  is_jpg_file (const char *fname)
306      fp = fopen (fname, "rb");      fp = fopen (fname, "rb");
307      if (!fp)      if (!fp)
308          return false;          return false;
309      n = fread (buf, 1, 10, fp);      n = fread (buf, 1, DIM (buf), fp);
310      fclose (fp);      fclose (fp);
311      if (n < 10)      if (n < DIM (buf))
312          return false;          return false;
313      return buf[6] == 'J' && buf[7] == 'F' &&      return buf[6] == 'J' && buf[7] == 'F' &&
314             buf[8] == 'I' && buf[9] == 'F';             buf[8] == 'I' && buf[9] == 'F';
# Line 341  BOOL CALLBACK Line 320  BOOL CALLBACK
320  keyedit_addphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keyedit_addphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
321  {  {
322      static keyedit_cb_t cb;      static keyedit_cb_t cb;
     GpgKeyEdit *ke;  
323      gpgme_error_t err;      gpgme_error_t err;
324      const char *s;          const char *s;    
325      char file[128];      char file[128];
326      int id;      int id;
327    
328      switch( msg ) {      switch (msg) {
329      case WM_INITDIALOG:      case WM_INITDIALOG:
330          cb = (keyedit_cb_t)lparam;          cb = (keyedit_cb_t)lparam;
331          if (!cb)          if (!cb)
332              BUG (NULL);              BUG (NULL);
333          SetDlgItemText (dlg, IDC_ADDPHOTO_INF, _("Remember that the image is stored within your public key.  If you use a very large picture, your key will become very large as well! Keeping the image close to 240x288 is a good size to use."));          SetDlgItemText (dlg, IDC_ADDPHOTO_INF, _("Remember that the image is stored within your public key.  If you use a very large picture, your key will become very large as well! Keeping the image close to 240x288 is advised."));
334          SetDlgItemText (dlg, IDC_ADDPHOTO_FILEINF, _("Pick an image to use for your photo ID.\nThe image must be a JPEG file."));          SetDlgItemText (dlg, IDC_ADDPHOTO_FILEINF, _("Pick an image to use for your photo ID.\nThe image must be a JPEG file."));
335          SetDlgItemText (dlg, IDC_ADDPHOTO_PWDINF, _("Passphrase"));          SetDlgItemText (dlg, IDC_ADDPHOTO_PWDINF, _("Passphrase"));
336          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
# Line 388  keyedit_addphoto_dlg_proc (HWND dlg, UIN Line 366  keyedit_addphoto_dlg_proc (HWND dlg, UIN
366                  if (id == IDNO)                  if (id == IDNO)
367                      return TRUE;                      return TRUE;
368              }              }
369              ke = create_GpgKeyEdit (cb->keyid);              
370              if (cb->pass)              {
371                  ke->setPassphrase (cb->pass);                  GpgKeyEdit ke;
372              else                  
373                  ke->setNoPassphrase (true);                  ke.setKeyID (cb->keyid);
374              err = ke->addPhotoid (file);                  if (cb->pass)
375              delete ke;                      ke.setPassphrase (cb->pass);
376                    else
377                        ke.setNoPassphrase (true);
378                    err = ke.addPhotoid (file);
379                }
380              if (err) {              if (err) {
381                  msg_box (dlg, gpgme_strerror (err), _("Add Photo"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("Add Photo"), MB_ERR);
382                  return FALSE;                  return FALSE;
# Line 423  keyedit_addrevoker_dlg_proc (HWND dlg, U Line 405  keyedit_addrevoker_dlg_proc (HWND dlg, U
405  {  {
406      static keyedit_cb_t cb;      static keyedit_cb_t cb;
407      gpgme_error_t err;      gpgme_error_t err;
     GpgKeyEdit *ke;  
408      char *uid=NULL;      char *uid=NULL;
409    
410      switch (msg) {      switch (msg) {
# Line 450  keyedit_addrevoker_dlg_proc (HWND dlg, U Line 431  keyedit_addrevoker_dlg_proc (HWND dlg, U
431                  return FALSE;                  return FALSE;
432              }              }
433                    
434              ke = create_GpgKeyEdit (cb->keyid);              {
435              if (cb->pass)                  GpgKeyEdit ke;
436                  ke->setPassphrase (cb->pass);                  
437              else                  ke.setKeyID (cb->keyid);
438                  ke->setNoPassphrase (true);                  if (cb->pass)
439              err = ke->addDesignatedRevoker (uid);                      ke.setPassphrase (cb->pass);
440              delete ke;                  else
441                        ke.setNoPassphrase (true);
442                    err = ke.addDesignatedRevoker (uid);
443                }
444    
445              safe_free (uid);              safe_free (uid);
446              if (err) {              if (err) {
447                  msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR);
# Line 487  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 472  keyedit_adduid_dlg_proc (HWND dlg, UINT
472      static keyedit_cb_t ctx;      static keyedit_cb_t ctx;
473      keygen_cb_t keygen;      keygen_cb_t keygen;
474      gpgme_error_t err;      gpgme_error_t err;
     GpgKeyEdit *ke;  
475      char *utf8_name = NULL;      char *utf8_name = NULL;
476      char *utf8_comment = NULL;      char *utf8_comment = NULL;
477      char email[128];      char email[128];
# Line 538  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 522  keyedit_adduid_dlg_proc (HWND dlg, UINT
522                            
523              rc = GetDlgItemText_utf8 (dlg, IDC_ADDUID_COMMENT, &utf8_comment);              rc = GetDlgItemText_utf8 (dlg, IDC_ADDUID_COMMENT, &utf8_comment);
524    
525              ke = create_GpgKeyEdit (ctx->keyid);              {
526              if (ctx->is_protected)                  GpgKeyEdit ke;
527                  ke->setPassphrase (ctx->pass);                  
528              else                  ke.setKeyID (ctx->keyid);
529                  ke->setNoPassphrase (true);                  if (ctx->is_protected)
530              err = ke->addUserid (utf8_name, utf8_comment, email);                      ke.setPassphrase (ctx->pass);
531                    else
532                        ke.setNoPassphrase (true);
533                    err = ke.addUserid (utf8_name, utf8_comment, email);
534                }
535              if (err)              if (err)
536                  msg_box (dlg, gpgme_strerror (err), _("UserID"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("UserID"), MB_ERR);
537              else {              else {
# Line 554  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 542  keyedit_adduid_dlg_proc (HWND dlg, UINT
542                  keygen->comment = utf8_comment;                  keygen->comment = utf8_comment;
543                  keygen->email = m_strdup (email);                  keygen->email = m_strdup (email);
544              }              }
             delete ke;  
545              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
546              return TRUE;              return TRUE;
547                            
# Line 573  keyedit_adduid_dlg_proc (HWND dlg, UINT Line 560  keyedit_adduid_dlg_proc (HWND dlg, UINT
560  static void  static void
561  init_keysize_box (HWND dlg, int ctlid)  init_keysize_box (HWND dlg, int ctlid)
562  {  {
563        /* Array with standard key-length in bits. */
564      const char *sizelist[] = {      const char *sizelist[] = {
565          "1024", "1536",          "1024", "1536",
566          "2048", "3072",          "2048", "3072",
# Line 621  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 609  keyedit_addsubkey_dlg_proc (HWND dlg, UI
609  {  {
610      static keyedit_cb_t ctx;      static keyedit_cb_t ctx;
611      keygen_cb_t keygen;      keygen_cb_t keygen;
     GpgKeyEdit *ke;  
612      gpgme_error_t err;      gpgme_error_t err;
613      SYSTEMTIME st;      SYSTEMTIME st;
614      HWND hwnd;      HWND hwnd;
# Line 631  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 618  keyedit_addsubkey_dlg_proc (HWND dlg, UI
618      case WM_INITDIALOG:      case WM_INITDIALOG:
619          ctx = (keyedit_cb_t)lparam;          ctx = (keyedit_cb_t)lparam;
620          if (!ctx)          if (!ctx)
621              BUG (0);              BUG (NULL);
622          SetWindowText (dlg, _("Add new Subkey"));          SetWindowText (dlg, _("Add new Subkey"));
623          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type"));          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type"));
624          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits"));          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits"));
# Line 661  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 648  keyedit_addsubkey_dlg_proc (HWND dlg, UI
648          }          }
649          if (HIWORD (wparam) == LBN_SELCHANGE &&          if (HIWORD (wparam) == LBN_SELCHANGE &&
650              LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) {              LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) {
651                /* If the selected algorithm is DSA, automatically set the
652                   size to 1024, otherwise use the default keysize. */
653              index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0);              index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0);
654              if (index == 0)              SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL,
655                  SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0);                                  index==0? 0 : 2, 0);
656          }          }
657    
658          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
# Line 671  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 660  keyedit_addsubkey_dlg_proc (HWND dlg, UI
660              keygen = (keygen_cb_t)ctx->opaque;              keygen = (keygen_cb_t)ctx->opaque;
661              assert (keygen);              assert (keygen);
662              hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);              hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
663                /* Map combo box numbers to GPG answers. */
664              switch (listbox_get_cursel (hwnd)) {              switch (listbox_get_cursel (hwnd)) {
665              case 0: index = 2; break;              case 0: index = 2; break;
666              case 1: index = 4; break;              case 1: index = 4; break;
# Line 703  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 693  keyedit_addsubkey_dlg_proc (HWND dlg, UI
693              if (valid > 0)              if (valid > 0)
694                  keygen->expire = time (NULL) + valid*24*60*60;                  keygen->expire = time (NULL) + valid*24*60*60;
695    
696              ke = create_GpgKeyEdit (ctx->keyid);              {
697              ke->setCallback (keygen_cb, NULL);                  GpgKeyEdit ke;
698              if (ctx->is_protected)                  
699                  ke->setPassphrase (ctx->pass);                  ke.setKeyID (ctx->keyid);
700              else                  ke.setCallback (keygen_cb, NULL);
701                  ke->setNoPassphrase (true);                  if (ctx->is_protected)
702              keygen_cb_dlg_create ();                      ke.setPassphrase (ctx->pass);
703                    else
704              err = ke->addSubkey ((gpgme_pubkey_algo_t)index, size, valid);                      ke.setNoPassphrase (true);
705                    keygen_cb_dlg_create ();
706                    err = ke.addSubkey ((gpgme_pubkey_algo_t)index, size, valid);
707                }
708              keygen->fpr = get_subkey_keyid (ctx->keyid);              keygen->fpr = get_subkey_keyid (ctx->keyid);
709              keygen_cb_dlg_destroy (1);              keygen_cb_dlg_destroy (1);
710              if (err)              if (err)
# Line 721  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 714  keyedit_addsubkey_dlg_proc (HWND dlg, UI
714                           _("GnuPG Status"), MB_OK);                           _("GnuPG Status"), MB_OK);
715                  ctx->finished = 1;                  ctx->finished = 1;
716              }              }
             delete ke;  
717              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
718              return TRUE;              return TRUE;
719                            
# Line 757  keyedit_add_userid (winpt_key_t k, HWND Line 749  keyedit_add_userid (winpt_key_t k, HWND
749      }      }
750    
751      memset (&keygen, 0, sizeof (keygen));      memset (&keygen, 0, sizeof (keygen));
752      memset (&cb, 0, sizeof cb);      memset (&cb, 0, sizeof (cb));
753      cb.parent = dlg;      cb.parent = dlg;
754      cb.opaque = &keygen;      cb.opaque = &keygen;
755      cb.is_protected = k->is_protected;      cb.is_protected = k->is_protected;
# Line 849  keyedit_add_subkey (winpt_key_t k, HWND Line 841  keyedit_add_subkey (winpt_key_t k, HWND
841  BOOL  BOOL
842  keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg)  keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg)
843  {  {
844      GpgKeyEdit *ke;      GpgKeyEdit ke;
845      gpgme_error_t err;      gpgme_error_t err;
846      struct URL_ctx_s *url;      struct URL_ctx_s *url;
847      char *pass = NULL;      char *pass = NULL;
# Line 866  keyedit_set_pref_keyserver (winpt_key_t Line 858  keyedit_set_pref_keyserver (winpt_key_t
858          return FALSE;          return FALSE;
859      }      }
860    
861      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
862      if (k->is_protected)      if (k->is_protected)
863          ke->setPassphrase (pass);          ke.setPassphrase (pass);
864      else      else
865          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);
866      err = ke->setPreferredKeyserver (-1, url->url);      err = ke.setPreferredKeyserver (-1, url->url);
867      if (!err)      if (!err)
868          msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK);          msg_box (dlg, _("Preferred keyserver successfully set."),
869                     _("Key Edit"), MB_OK);
870      else      else
871          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);
872    
873      sfree_if_alloc (pass);      sfree_if_alloc (pass);
     delete ke;  
874      delete url;      delete url;
875      return err == 0? 0 : WPTERR_GENERAL;      return err == 0? 0 : WPTERR_GENERAL;
876  }  }
# Line 982  is_idea_protect_algo (const char *keyid) Line 974  is_idea_protect_algo (const char *keyid)
974    
975      memset (&k, 0, sizeof (k));      memset (&k, 0, sizeof (k));
976      if (winpt_get_pubkey (keyid, &k))      if (winpt_get_pubkey (keyid, &k))
977          BUG (0);          BUG (NULL);
978      if (!k.is_v3)      if (!k.is_v3)
979          return 0;          return 0;
980      sym_prefs = k.ext->sym_prefs;      sym_prefs = k.ext->sym_prefs;
981        /* Assume that only v3 keys have no symmetric cipher
982           preferences and thus IDEA is explicit. */
983      if (!sym_prefs)      if (!sym_prefs)
984          return 1; /* assume that only v3 keys have no symmetric cipher preferences          return 1;
                      and thus IDEA is explicit. */  
985      for (n = 0; sym_prefs[n]; n++)      for (n = 0; sym_prefs[n]; n++)
986          ;          ;
987      if ((n == 0 || n == 1) && *sym_prefs == 0x01)      if ((n == 0 || n == 1) && *sym_prefs == 0x01)
# Line 1001  BOOL Line 994  BOOL
994  keyedit_change_passwd (winpt_key_t k, HWND dlg)  keyedit_change_passwd (winpt_key_t k, HWND dlg)
995  {  {
996      gpgme_error_t err;      gpgme_error_t err;
997      GpgKeyEdit *ke;      GpgKeyEdit ke;
998      char *old_pass = NULL;      char *old_pass = NULL;
999      char *new_pass = NULL;      char *new_pass = NULL;
1000      int cancel = 0;      int cancel = 0;
# Line 1034  keyedit_change_passwd (winpt_key_t k, HW Line 1027  keyedit_change_passwd (winpt_key_t k, HW
1027    
1028      if (strlen (new_pass) == 0) {      if (strlen (new_pass) == 0) {
1029          cancel = msg_box (dlg, _("Are you sure that you really don't want a passphrase?\n"          cancel = msg_box (dlg, _("Are you sure that you really don't want a passphrase?\n"
1030                                   "This is propably a bad idea, still proceed?"),                                   "This is propably a bad idea, continue?"),
1031                              _("Key Edit"), MB_WARN_ASK);                              _("Key Edit"), MB_WARN_ASK);
1032          if (cancel != IDYES) {          if (cancel != IDYES) {
1033              sfree_if_alloc (old_pass);              sfree_if_alloc (old_pass);
# Line 1043  keyedit_change_passwd (winpt_key_t k, HW Line 1036  keyedit_change_passwd (winpt_key_t k, HW
1036          }          }
1037      }      }
1038    
1039      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1040      ke->setPassphrase (k->is_protected? old_pass : NULL);      ke.setPassphrase (k->is_protected? old_pass : NULL);
1041      if (!k->is_protected)      if (!k->is_protected)
1042          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);
1043      err = ke->changePassphrase (new_pass, 1);      err = ke.changePassphrase (new_pass, 1);
1044      if (err)      if (err)
1045          msg_box (dlg, gpgme_strerror (err), _("Change Passwd"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Change Password"), MB_ERR);
1046      else      else
1047          msg_box (dlg, _("Passphrase successfully changed."),  _("GnuPG status"), MB_OK);          msg_box (dlg, _("Passphrase successfully changed."),  _("GnuPG status"), MB_OK);
1048      sfree_if_alloc (old_pass);      sfree_if_alloc (old_pass);
1049      sfree_if_alloc (new_pass);      sfree_if_alloc (new_pass);
1050      delete ke;  
1051      return TRUE;      return TRUE;
1052  }  }
1053    
1054                    
1055  /* Initialize sub key list from key @k and return  /* Initialize sub key list from key @k and return
1056     the new listview control. */     the new listview control. */
1057  listview_ctrl_t  listview_ctrl_t
# Line 1081  subkey_list_init (HWND dlg, winpt_key_t Line 1074  subkey_list_init (HWND dlg, winpt_key_t
1074      listview_ctrl_t lv;      listview_ctrl_t lv;
1075      char buf[256], tmp[128];      char buf[256], tmp[128];
1076      const char *t;      const char *t;
1077      int nkeys = 0, i, bits;      int nkeys = 0, i;
1078    
1079      nkeys = count_subkeys (k->ctx);      nkeys = count_subkeys (k->ctx);
1080      if (!nkeys)      if (!nkeys)
1081          BUG (0); /* should never happen. */          BUG (NULL); /* should never happen. */
1082                    
1083      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST));      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST));
1084      for (i = 0; cols[i].fieldname != NULL; i++)      for (i = 0; cols[i].fieldname != NULL; i++)
1085          listview_add_column (lv, &cols[i]);          listview_add_column (lv, &cols[i]);
1086                    
1087      for (i = 0; i < nkeys; i++) {      for (i = 0, sub = k->ctx->subkeys; i < nkeys; i++, sub = sub->next) {
1088          listview_add_item (lv, "");          listview_add_item (lv, "");
1089          listview_add_sub_item (lv, 0, 1, "");          listview_add_sub_item (lv, 0, 1, "");
1090          memset (&lvi, 0, sizeof (lvi));          memset (&lvi, 0, sizeof (lvi));
1091          lvi.mask = LVIF_PARAM;            lvi.mask = LVIF_PARAM;  
1092          lvi.lParam = (LPARAM)k->ext;          lvi.lParam = (LPARAM)sub;
1093          if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)          if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
1094              BUG (0);              BUG (NULL);
1095      }      }
1096                    
1097      listview_set_ext_style( lv );      listview_set_ext_style (lv);
1098      for( i = 0, sub = k->ctx->subkeys; i < nkeys; i++, sub = sub->next ) {      for (i = 0, sub = k->ctx->subkeys; i < nkeys; i++, sub = sub->next) {
1099          memset( buf, 0, sizeof buf );          _snprintf (buf, DIM (buf)-1, "%d-bit %s", sub->length,
1100                                    get_key_pubalgo (sub->pubkey_algo));
1101          bits = sub->length;          listview_add_sub_item (lv, i, SUBK_COL_DESC, buf);
         _snprintf( tmp, sizeof tmp-1, "%d-bit ", bits );  
         strcat( buf, tmp );  
   
         _snprintf( tmp, sizeof tmp-1, "%s", get_key_pubalgo (sub->pubkey_algo));  
         strcat( buf, tmp );  
           
         listview_add_sub_item( lv, i, 0, buf );  
1102          t = sub->keyid;          t = sub->keyid;
1103          if( !t )          assert (t != NULL);
1104              t = "DEADBEEFDEADBEEF";          _snprintf (tmp, DIM (tmp)-1, "0x%s", t+8);
1105          _snprintf( tmp, sizeof tmp-1, "0x%s", t+8 );          listview_add_sub_item (lv, i, SUBK_COL_KEYID, tmp);
         listview_add_sub_item( lv, i, 1, tmp );  
1106    
1107          t = get_key_created (sub->timestamp);          t = get_key_created (sub->timestamp);
1108          if( !t )          if (!t)
1109              t = "????" "-??" "-??";              t = "????" "-??" "-??";
1110          listview_add_sub_item( lv, i, 2, t );          listview_add_sub_item (lv, i, SUBK_COL_CREATION, t);
1111    
1112          if( sub->expires ) {          if (sub->expires) {
1113              t = get_key_created (sub->expires);              t = get_key_created (sub->expires);
1114              listview_add_sub_item( lv, i, 3, t );              listview_add_sub_item (lv, i, SUBK_COL_EXPIRES, t);
1115          }          }
1116          else          else
1117              listview_add_sub_item( lv, i, 3, _("Never") );              listview_add_sub_item (lv, i, SUBK_COL_EXPIRES, _("Never"));
1118            if (sub->expired)
         if( sub->expired )  
1119              t = _("Expired");              t = _("Expired");
1120          else if( sub->revoked )          else if (sub->revoked)
1121              t = _("Revoked");              t = _("Revoked");
1122          else          else
1123              t = _("OK");              t = _("OK");
1124          listview_add_sub_item( lv, i, 4, t );          listview_add_sub_item (lv, i, SUBK_COL_STATUS, t);
1125    
1126          if (sub->can_certify) t = "*"; else t = "";          if (sub->can_certify) t = "*"; else t = "";
1127          listview_add_sub_item (lv, i, 5, t);          listview_add_sub_item (lv, i, SUBK_COL_C_FLAG, t);
1128          if (sub->can_sign) t = "*"; else t = "";          if (sub->can_sign) t = "*"; else t = "";
1129          listview_add_sub_item( lv, i, 6, t );          listview_add_sub_item (lv, i, SUBK_COL_S_FLAG, t);
1130          if (sub->can_encrypt) t = "*"; else t = "";          if (sub->can_encrypt) t = "*"; else t = "";
1131          listview_add_sub_item( lv, i, 7, t );          listview_add_sub_item (lv, i, SUBK_COL_E_FLAG, t);
1132          if (sub->can_authenticate) t = "*"; else t = "";          if (sub->can_authenticate) t = "*"; else t = "";
1133          listview_add_sub_item (lv, i, 8, t);          listview_add_sub_item (lv, i, SUBK_COL_A_FLAG, t);
1134      }      }
1135      return lv;      return lv;
1136  }  }
# Line 1170  userid_list_init (HWND dlg, winpt_key_t Line 1154  userid_list_init (HWND dlg, winpt_key_t
1154            
1155      nuids = count_userids (k->ctx);      nuids = count_userids (k->ctx);
1156      if (!nuids)      if (!nuids)
1157          BUG (0); /* should never happen. */          BUG (NULL); /* should never happen. */
1158                    
1159      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST));      listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST));
1160      for (j = 0; cols[j].fieldname != NULL; j++)      for (j = 0; cols[j].fieldname != NULL; j++)
# Line 1213  static void Line 1197  static void
1197  do_init_cmdlist (HWND dlg, int is_keypair)  do_init_cmdlist (HWND dlg, int is_keypair)
1198  {      {    
1199      const char *s;      const char *s;
1200      int i = 0;      int i;
1201    
1202      for (i = 0; (s=cmdlist[i].name); i++) {      for (i = 0; (s=cmdlist[i].name); i++) {
1203          if (is_keypair)          if (is_keypair)
# Line 1235  is_cmd_openpgp (int cmdid) Line 1219  is_cmd_openpgp (int cmdid)
1219      case CMD_ADDKEY:      case CMD_ADDKEY:
1220      case CMD_ADDPHOTO:      case CMD_ADDPHOTO:
1221      case CMD_ADDREVOKER:      case CMD_ADDREVOKER:
1222      //case CMD_SETPREF:      case CMD_SETPREF:
1223          return 1;          return 1;
1224      }      }
1225      return 0;      return 0;
# Line 1246  is_cmd_openpgp (int cmdid) Line 1230  is_cmd_openpgp (int cmdid)
1230  static void  static void
1231  do_show_help (HWND dlg)  do_show_help (HWND dlg)
1232  {  {
1233      char helptext[2048];      const char *help;
1234    
1235      _snprintf (helptext, sizeof (helptext)-1,      help =
1236          _(          _(
1237           "ADDUID   \t\tadd a user ID\r\n"           "ADDUID      add a user ID\r\n"
1238           "ADDPHOTO  \t\tadd a photo ID\r\n"           "ADDPHOTO    add a photo ID\r\n"
1239           "DELUID    \t\tdelete a user ID\r\n"           "DELUID      delete a user ID\r\n"
1240           "ADDKEY    \t\tadd a secondard key\r\n"           "ADDKEY      add a secondary key\r\n"
1241           "DELKEY    \t\tdelete a secondary key\r\n"           "DELKEY      delete a secondary key\r\n"
1242           "ADDREVOKER\t\tadd a revocation key\r\n"           "ADDREVOKER  add a revocation key\r\n"
1243           "EXPIRE    \t\tchange the expire date\r\n"           "EXPIRE      change the expire date\r\n"
1244           "SHOWPREF  \t\tlist preferences (verbose)\r\n"           "SHOWPREF    list preferences (verbose)\r\n"
1245           "SETPREF   \t\tset preference list\r\n"           /*"SETPREF     update specific algorithm preferences\r\n"*/
1246           "UPDPREF   \t\tupdated preferences\r\n"           "PASSWD      change the passphrase\r\n"
1247           "PASSWD    \t\tchange the passphrase\r\n"           "PRIMARY     flag user ID as primary\r\n"
1248           "PRIMARY   \t\tflag user ID as primary\r\n"           "TRUST       change the ownertrust\r\n"
1249           "TRUST     \t\tchange the ownertrust\r\n"           "REVUID      revoke a user ID\r\n"
1250           "REVUID    \t\trevoke a user ID\r\n"           "REVKEY      revoke a secondary key\r\n"
1251           "REVKEY    \t\trevoke a secondary key\r\n"           "DISABLE     disable a key\r\n"
1252           "DISABLE   \t\tdisable a key\r\n"           "ENABLE      enable a key\r\n"
1253           "ENABLE    \t\tenable a key\r\n"           "SIGN        sign a user-id (exportable)\r\n"
1254           "SIGN      \t\tsign a user-id (exportable)\r\n"           "LSIGN       sign a user-id (non-exportable)\r\n"
1255           "LSIGN     \t\tsign a user-id (non-exportable)\r\n"           "CLEAN       remove unusable signatures from key\r\n"
1256           "CLEAN     \t\tremove unusable signatures from key\r\n"           "MINIMIZE    remove all signatures from key\r\n"
1257           "MINIMIZE  \t\tremove all signatures from key\r\n"           );
1258           ));      msg_box (dlg, help, _("Key Edit Help"), MB_OK);
1259      msg_box (dlg, helptext, _("Key Edit Help"), MB_OK);  }
1260    
1261    
1262    static gpgme_subkey_t
1263    get_subkey_bypos (const char *keyid, int idx)
1264    {
1265        gpgme_key_t key;
1266    
1267        if (get_pubkey (keyid, &key))
1268            return NULL;
1269        return get_nth_key (key, idx);
1270  }  }
1271    
1272    
1273    
1274  static int  static int
1275  do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1276  {  {
1277      gpgme_error_t err;      gpgme_error_t err;
1278      GpgKeyEdit *ke;      gpgme_subkey_t subk;
1279        GpgKeyEdit ke;
1280      int pos, id;      int pos, id;
1281        const char *warn;
1282      char tmp[64];      char tmp[64];
1283    
1284      if (!k->key_pair)      if (!k->key_pair)
# Line 1300  do_editkey_delkey (winpt_key_t k, HWND d Line 1297  do_editkey_delkey (winpt_key_t k, HWND d
1297          msg_box (dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);
1298          return FALSE;          return FALSE;
1299      }      }
1300        
1301      /* XXX: change the warning to make clear that verification won't work      listview_get_item_text (lv, pos, 0, tmp, DIM (tmp) -1);
1302              any longer if this is a sign-only key. */      subk = get_subkey_bypos (k->keyid, pos);
1303      listview_get_item_text (lv, pos, 0, tmp, sizeof (tmp) -1);      /* Issue different warning for the different key capabilities. */
1304      id = log_box (_("Key Edit"), MB_YESNO|MB_ICONWARNING,      if (subk->can_encrypt)
1305                      _("\"Subkey %s.\"\n\n"          warn = _("Anything encrypted to the selected subkey cannot be\n"
1306                        "Anything encrypted to the selected subkey will no longer\n"                   "decrypted any longer.");
1307                        "be able to be decrypted.\n\n"      else if (subk->can_sign || subk->can_certify)
1308                        "Do you really want to delete this subkey?"), tmp);          warn = _("Anything signed by the selected subkey cannot be\n"
1309                     "verified any longer.");
1310        else
1311            warn = ""; /* just get rid of the warning. */
1312    
1313        id = log_box (_("Key Edit"), MB_YESNO|MB_ICONWARNING,
1314                      _("\"Subkey %s.\"\n\n%s\n\n"
1315                        "Do you really want to delete this subkey?"),
1316                      tmp, warn);
1317      if (id == IDNO)      if (id == IDNO)
1318          return FALSE;          return FALSE;
1319    
1320      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1321      err = ke->delKey (pos);      err = ke.delKey (pos);
1322      if (err)      if (err)
1323          msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR);
1324      else {      else {
# Line 1321  do_editkey_delkey (winpt_key_t k, HWND d Line 1326  do_editkey_delkey (winpt_key_t k, HWND d
1326          k->update = 1;          k->update = 1;
1327          status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status"));          status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status"));
1328      }      }
     delete ke;  
1329      return err? FALSE : TRUE;      return err? FALSE : TRUE;
1330  }  }
1331    
# Line 1332  static int Line 1336  static int
1336  do_editkey_expire (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_expire (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1337  {  {
1338      gpgme_error_t err;      gpgme_error_t err;
1339      GpgKeyEdit *ke;      GpgKeyEdit ke;
1340      date_s udd = {0};      date_s udd = {0};
1341      char buf[256], * pass = NULL;      char buf[256], * pass = NULL;
1342      time_t exp;      time_t exp;
# Line 1350  do_editkey_expire (winpt_key_t k, HWND d Line 1354  do_editkey_expire (winpt_key_t k, HWND d
1354    
1355      /* If a key already expired, it is possible the user wants to      /* If a key already expired, it is possible the user wants to
1356         set a new expiration date.. */         set a new expiration date.. */
1357      listview_get_item_text (lv, pos, SUBK_COL_STATUS, buf, sizeof (buf)-1);      listview_get_item_text (lv, pos, SUBK_COL_STATUS, buf, DIM (buf)-1);
1358      if (!strcmp (buf, _("Expired"))) {      if (!strcmp (buf, _("Expired"))) {
1359          cancel = msg_box (dlg, _("Key already expired.\n\n"          cancel = msg_box (dlg, _("Key already expired.\n\n"
1360                            "Do you want to change the expiration date?"),                            "Do you want to change the expiration date?"),
# Line 1360  do_editkey_expire (winpt_key_t k, HWND d Line 1364  do_editkey_expire (winpt_key_t k, HWND d
1364          cancel = 0;          cancel = 0;
1365      }      }
1366    
1367      memset (&udd, 0, sizeof udd);      memset (&udd, 0, sizeof (udd));
1368      udd.text = _("Key Expiration Date");      udd.text = _("Key Expiration Date");
1369      dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg,          dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg,    
1370                        date_dlg_proc, (LPARAM)&udd,                        date_dlg_proc, (LPARAM)&udd,
# Line 1368  do_editkey_expire (winpt_key_t k, HWND d Line 1372  do_editkey_expire (winpt_key_t k, HWND d
1372      if (udd.cancel == 1)      if (udd.cancel == 1)
1373          return FALSE;          return FALSE;
1374      if (!keygen_check_date (&udd.st)) {      if (!keygen_check_date (&udd.st)) {
1375          msg_box (dlg, _("The date you have chosen lies in the past."),          msg_box (dlg, _("The date you have chosen has already passed."),
1376                   _("Key Edit"), MB_ERR);                   _("Key Edit"), MB_ERR);
1377          return FALSE;          return FALSE;
1378      }      }
# Line 1378  do_editkey_expire (winpt_key_t k, HWND d Line 1382  do_editkey_expire (winpt_key_t k, HWND d
1382              return FALSE;              return FALSE;
1383      }      }
1384      exp = w32_mktime (&udd.st);      exp = w32_mktime (&udd.st);
1385      ke = create_GpgKeyEdit (k->keyid);  
1386        ke.setKeyID (k->keyid);
1387      if (k->is_protected)      if (k->is_protected)
1388          ke->setPassphrase (pass);          ke.setPassphrase (pass);
1389      else      else
1390          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);
1391      err = ke->setKeyExpireDate (pos, exp, false);      err = ke.setKeyExpireDate (pos, exp, false);
1392      if (err)      if (err)
1393          msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR);
1394      else {      else {
1395          _snprintf (buf, sizeof (buf)-1, "%s", get_key_created (exp));          _snprintf (buf, DIM (buf)-1, "%s", get_key_created (exp));
1396          listview_add_sub_item (lv, pos, SUBK_COL_EXPIRES, buf);          listview_add_sub_item (lv, pos, SUBK_COL_EXPIRES, buf);
1397          k->update = 1;          k->update = 1;
1398          msg_box (dlg, _("Subkey expire date successfully set."),          msg_box (dlg, _("Subkey expire date successfully set."),
1399                   _("GnuPG status"), MB_OK);                   _("GnuPG status"), MB_OK);
1400      }      }
1401      sfree_if_alloc (pass);      sfree_if_alloc (pass);
     delete ke;  
1402      return TRUE;      return TRUE;
1403  }  }
1404    
# Line 1406  static int Line 1410  static int
1410  do_editkey_revoke (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_revoke (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1411  {  {
1412      gpgme_error_t err;      gpgme_error_t err;
1413      GpgKeyEdit *ke;      GpgKeyEdit ke;
1414      char buf[256];      char buf[256];
1415      char *pass = NULL;      char *pass = NULL;
1416      int j, cancel = 0;      int j, cancel = 0;
# Line 1428  do_editkey_revoke (winpt_key_t k, HWND d Line 1432  do_editkey_revoke (winpt_key_t k, HWND d
1432          return FALSE;          return FALSE;
1433      }      }
1434                            
1435      listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof (buf)-1);      listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, DIM (buf)-1);
1436      if (!strcmp (buf, _("Revoked"))) {      if (!strcmp (buf, _("Revoked"))) {
1437          msg_box (dlg, _("Key already revoked."), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Key already revoked."), _("Key Edit"), MB_ERR);
1438          return FALSE;          return FALSE;
# Line 1440  do_editkey_revoke (winpt_key_t k, HWND d Line 1444  do_editkey_revoke (winpt_key_t k, HWND d
1444              return FALSE;                        return FALSE;          
1445      }      }
1446    
1447      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1448      if (k->is_protected)      if (k->is_protected)
1449          ke->setPassphrase (pass);          ke.setPassphrase (pass);
1450      else      else
1451          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);
1452      err = ke->revokeSubkey (j, 0, NULL);      err = ke.revokeSubkey (j, 0, NULL);
1453      if (err)      if (err)
1454          msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR);          msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR);
1455      else {      else {
# Line 1454  do_editkey_revoke (winpt_key_t k, HWND d Line 1458  do_editkey_revoke (winpt_key_t k, HWND d
1458          msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK );          msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK );
1459      }      }
1460      sfree_if_alloc (pass);      sfree_if_alloc (pass);
     delete ke;  
1461      return TRUE;      return TRUE;
1462  }  }
1463    
# Line 1465  int Line 1468  int
1468  do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1469  {  {
1470      gpgme_error_t err;      gpgme_error_t err;
1471      GpgKeyEdit *ke;      GpgKeyEdit ke;
1472      char buf[128], email[128];      char buf[128], email[128];
1473      char inf[512];      char inf[512];
1474      char *pass = NULL;      char *pass = NULL;
# Line 1483  do_editkey_revuid (winpt_key_t k, HWND d Line 1486  do_editkey_revuid (winpt_key_t k, HWND d
1486      }      }
1487    
1488      if( (j = listview_get_curr_pos( lv )) == -1 ) {      if( (j = listview_get_curr_pos( lv )) == -1 ) {
1489          msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );            msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1490          return FALSE;            return FALSE;  
1491      }      }
1492                            
1493      listview_get_item_text( lv, j, UID_COL_VALID, buf, sizeof buf - 1);      listview_get_item_text( lv, j, UID_COL_VALID, buf, DIM (buf) - 1);
1494      if (strstr (buf, _("Revoked"))) {      if (strstr (buf, _("Revoked"))) {
1495          msg_box (dlg, _("This user ID has been already revoked."),          msg_box (dlg, _("This user ID has been already revoked."),
1496                   _("Key Edit"), MB_INFO);                   _("Key Edit"), MB_INFO);
# Line 1495  do_editkey_revuid (winpt_key_t k, HWND d Line 1498  do_editkey_revuid (winpt_key_t k, HWND d
1498      }      }
1499                            
1500      listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof buf -1);      listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof buf -1);
1501      _snprintf (inf, sizeof (inf) -1, _("user ID \"%s\".\n\n"      _snprintf (inf, DIM (inf) -1, _("user ID \"%s\".\n\n"
1502                 "Do you really want to revoke this user ID?"), buf);                 "Do you really want to revoke this user ID?"), buf);
1503      if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO)      if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO)
1504          return FALSE;          return FALSE;
# Line 1504  do_editkey_revuid (winpt_key_t k, HWND d Line 1507  do_editkey_revuid (winpt_key_t k, HWND d
1507          if (cancel)          if (cancel)
1508              return FALSE;                        return FALSE;          
1509      }      }
1510      listview_get_item_text (lv, j, UID_COL_EMAIL, email, sizeof (email)-1);      listview_get_item_text (lv, j, UID_COL_EMAIL, email, DIM (email)-1);
1511      listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof (buf)-1);      listview_get_item_text (lv, j, UID_COL_NAME, buf, DIM (buf)-1);
1512      id = do_find_userid (k->keyid, email, buf, NULL);      id = do_find_userid (k->keyid, email, buf, NULL);
1513      if (id == -1)      if (id == -1)
1514          BUG (NULL);          BUG (NULL);
1515    
1516      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1517      if (k->is_protected)      if (k->is_protected)
1518          ke->setPassphrase (pass);          ke.setPassphrase (pass);
1519      else      else
1520          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);
1521      err = ke->revokeUserid (id);      err = ke.revokeUserid (id);
1522      if (err)      if (err)
1523          msg_box (dlg, gpgme_strerror (err), _("Revoke User ID"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Revoke User ID"), MB_ERR);
1524      else {      else {
# Line 1524  do_editkey_revuid (winpt_key_t k, HWND d Line 1527  do_editkey_revuid (winpt_key_t k, HWND d
1527          status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status"));          status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status"));
1528      }      }
1529      sfree_if_alloc (pass);      sfree_if_alloc (pass);
     delete ke;  
1530      return err? FALSE : TRUE;      return err? FALSE : TRUE;
1531  }  }
1532    
# Line 1532  do_editkey_revuid (winpt_key_t k, HWND d Line 1534  do_editkey_revuid (winpt_key_t k, HWND d
1534  static int  static int
1535  do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1536  {  {
1537      gpgme_error_t rc;      gpgme_error_t err;
1538      GpgKeyEdit *ke;      GpgKeyEdit ke;
1539      char buf[256], * pass = NULL, * prefs;      gpg_uid_info_t uidinf = NULL;
1540      int j, id, cancel=0, flags=0;      char buf[256], *pass = NULL, *prefs = NULL;
1541        int pos, id, cancel=0, flags=0;
1542    
1543      if ((j = listview_get_curr_pos (lv)) == -1) {      pos = listview_get_curr_pos (lv);
1544        if (pos == -1) {
1545          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1546          return FALSE;          return FALSE;
1547      }      }
1548      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);      listview_get_item_text (lv, pos, 2, buf, DIM (buf)-1);
1549      id = do_find_userid (k->keyid, buf, NULL, NULL);      id = do_find_userid (k->keyid, buf, NULL, &uidinf);
1550      if (id == -1)      if (id == -1)
1551          BUG (NULL);          BUG (NULL);
1552      if (k->is_protected) {      if (k->is_protected) {
1553          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
1554            gpg_uid_info_release (uidinf);
1555          if (cancel)          if (cancel)
1556              return FALSE;              return FALSE;
1557      }      }
1558    
1559      ke = create_GpgKeyEdit (k->keyid);      get_userid_preflist (uidinf->prefs, &prefs, &flags);
1560        gpg_uid_info_release (uidinf);
1561        if (!prefs) {
1562            sfree_if_alloc (pass);
1563            return FALSE;
1564        }
1565    
1566        ke.setKeyID (k->keyid);
1567      if (k->is_protected)      if (k->is_protected)
1568          ke->setPassphrase (pass);          ke.setPassphrase (pass);
1569      else      else
1570          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);    
1571        err = ke.setUseridPreferences (id, prefs);
1572      get_userid_preflist (&prefs, &flags);      if (err)
1573            msg_box (dlg, gpgme_strerror (err), _("Set user ID preferences"), MB_ERR);
1574      rc = ke->setUseridPreferences (id, prefs);      else {
1575      if (rc)          k->update = 1;
1576          msg_box (dlg, _("Could not set user ID preferences"), _("Key Edit"), MB_ERR);          status_box (dlg, _("User ID preferences successfully updated"), _("GnuPG Status"));
1577        }
1578    
1579      sfree_if_alloc (pass);      sfree_if_alloc (pass);
1580      free_if_alloc (prefs);      free_if_alloc (prefs);
1581      delete ke;      return err? FALSE: TRUE;
     return 0;  
1582  }  }
1583    
1584    
# Line 1574  static int Line 1586  static int
1586  do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1587  {  {
1588      gpgme_error_t err;      gpgme_error_t err;
1589      GpgKeyEdit *ke;      GpgKeyEdit ke;
1590      int j, id, cancel=0;      int j, id, cancel=0;
1591      char valid[32];      char valid[32];
1592      char buf[256], *pass = NULL;      char buf[256], *pass = NULL;
# Line 1585  do_editkey_primary (winpt_key_t k, HWND Line 1597  do_editkey_primary (winpt_key_t k, HWND
1597          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1598          return FALSE;          return FALSE;
1599      }      }
1600      listview_get_item_text (lv, j, UID_COL_VALID, valid, sizeof (valid)-1);      listview_get_item_text (lv, j, UID_COL_VALID, valid, DIM (valid)-1);
1601      if (!strcmp (valid, _("Revoked")))      if (!strcmp (valid, _("Revoked")))
1602          return FALSE;          return FALSE;
1603      listview_get_item_text (lv, j, UID_COL_EMAIL, buf, sizeof (buf)-1);      listview_get_item_text (lv, j, UID_COL_EMAIL, buf, DIM (buf)-1);
1604      id = do_find_userid (k->keyid, buf, NULL, NULL);      id = do_find_userid (k->keyid, buf, NULL, NULL);
1605      if (id == -1)      if (id == -1)
1606          BUG (0);          BUG (NULL);
1607      if (k->is_protected) {      if (k->is_protected) {
1608          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);          pass = request_key_passphrase (k->ctx, _("Key Edit"), &cancel);
1609          if (cancel)          if (cancel)
1610              return FALSE;              return FALSE;
1611      }      }
1612    
1613      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1614      if (k->is_protected)      if (k->is_protected)
1615          ke->setPassphrase (pass);          ke.setPassphrase (pass);
1616      else      else
1617          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);
1618      err = ke->setPrimaryUserid (id);      err = ke.setPrimaryUserid (id);
1619      if (err)      if (err)
1620          msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR);
1621      else {      else {
# Line 1612  do_editkey_primary (winpt_key_t k, HWND Line 1624  do_editkey_primary (winpt_key_t k, HWND
1624      }      }
1625    
1626      sfree_if_alloc (pass);      sfree_if_alloc (pass);
     delete ke;  
1627      return err? FALSE : TRUE;      return err? FALSE : TRUE;
1628  }  }
1629    
# Line 1682  showpref_dlg_proc (HWND dlg, UINT msg, W Line 1693  showpref_dlg_proc (HWND dlg, UINT msg, W
1693              BUG (NULL);              BUG (NULL);
1694          key = (gpgme_key_t)cb->opaque;          key = (gpgme_key_t)cb->opaque;
1695          listview_get_item_text (cb->lv, cb->lv_pos,          listview_get_item_text (cb->lv, cb->lv_pos,
1696                                  UID_COL_EMAIL, buf, sizeof (buf)-1);                                  UID_COL_EMAIL, buf, DIM (buf)-1);
1697          pos = do_find_userid (cb->keyid, buf, NULL, &inf);          pos = do_find_userid (cb->keyid, buf, NULL, &inf);
1698          if (pos < 0 || !inf) {          if (pos < 0 || !inf) {
1699              gpg_uid_info_release (inf);              gpg_uid_info_release (inf);
# Line 1691  showpref_dlg_proc (HWND dlg, UINT msg, W Line 1702  showpref_dlg_proc (HWND dlg, UINT msg, W
1702          }          }
1703          for (u=inf; u; u = u->next) {          for (u=inf; u; u = u->next) {
1704              if (u->index == pos && u->prefs && *u->prefs) {              if (u->index == pos && u->prefs && *u->prefs) {
1705                  _snprintf (buf, sizeof (buf)-1, "%s", u->name);                  _snprintf (buf, DIM (buf)-1, "%s", u->name);
1706                  SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);                  SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);
1707                  if (parse_preflist (dlg, u->prefs) <= 0)                  if (parse_preflist (dlg, u->prefs) <= 0)
1708                      pos = -1;                      pos = -1;
# Line 1751  do_editkey_showpref (winpt_key_t k, HWND Line 1762  do_editkey_showpref (winpt_key_t k, HWND
1762      cb.lv_pos = listview_get_curr_pos (lv);      cb.lv_pos = listview_get_curr_pos (lv);
1763    
1764      listview_get_item_text (lv, cb.lv_pos, UID_COL_VALID,      listview_get_item_text (lv, cb.lv_pos, UID_COL_VALID,
1765                              status, sizeof (status)-1);                              status, DIM (status)-1);
1766      if (!strcmp (status, _("Revoked")))      if (!strcmp (status, _("Revoked")))
1767          return TRUE;          return TRUE;
1768            
# Line 1765  static int Line 1776  static int
1776  do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1777  {  {
1778      gpgme_error_t err;      gpgme_error_t err;
1779      GpgKeyEdit *ke;      GpgKeyEdit ke;
1780      char email[128], name[128];      char email[128], name[128];
1781      char inf[384];      char inf[384];
1782      int pos, id = 0;      int pos, id = 0;
# Line 1797  do_editkey_deluid (winpt_key_t k, HWND d Line 1808  do_editkey_deluid (winpt_key_t k, HWND d
1808      listview_get_item_text (lv, pos, UID_COL_NAME, name, DIM (name)-1);      listview_get_item_text (lv, pos, UID_COL_NAME, name, DIM (name)-1);
1809      id = do_find_userid (k->keyid, email, name, NULL);      id = do_find_userid (k->keyid, email, name, NULL);
1810      if (id == -1)      if (id == -1)
1811          BUG (0);          BUG (NULL);
1812    
1813      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1814      err = ke->delUserid (id);      err = ke.delUserid (id);
1815      if (err)      if (err)
1816          msg_box (dlg, gpgme_strerror (err), _("Delete User ID"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Delete User ID"), MB_ERR);
1817      else {      else {
# Line 1808  do_editkey_deluid (winpt_key_t k, HWND d Line 1819  do_editkey_deluid (winpt_key_t k, HWND d
1819          k->update = 1;          k->update = 1;
1820          status_box (dlg, _("User ID successfully deleted"), _("GnuPG Status"));          status_box (dlg, _("User ID successfully deleted"), _("GnuPG Status"));
1821      }      }
     delete ke;  
1822      return err? FALSE : TRUE;      return err? FALSE : TRUE;
1823  }  }
1824    
# Line 1890  static void Line 1900  static void
1900  do_editkey_minimize (winpt_key_t k, HWND dlg)  do_editkey_minimize (winpt_key_t k, HWND dlg)
1901  {  {
1902      gpgme_error_t err;      gpgme_error_t err;
1903      GpgKeyEdit *ke;      GpgKeyEdit ke;
1904    
1905      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1906      err = ke->minimizeKey ();      err = ke.minimizeKey ();
1907      if (err)      if (err)
1908          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);
1909      else {      else {
1910          msg_box (dlg, _("Finished to compact key."), _("Key Edit"), MB_OK);          msg_box (dlg, _("Finished to compact key."), _("Key Edit"), MB_OK);
1911          k->update = 1;          k->update = 1;
1912      }      }
     delete ke;  
1913  }  }
1914    
1915    
# Line 1908  static void Line 1917  static void
1917  do_editkey_clean (winpt_key_t k, HWND dlg)  do_editkey_clean (winpt_key_t k, HWND dlg)
1918  {  {
1919      gpgme_error_t err;      gpgme_error_t err;
1920      GpgKeyEdit *ke;      GpgKeyEdit ke;
1921            
1922      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1923      err = ke->cleanKey ();      err = ke.cleanKey ();
1924      if (err)      if (err)
1925          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);            msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);  
1926      else {      else {
1927          msg_box (dlg, _("Finished to compact key."), _("Key Edit"), MB_OK);          msg_box (dlg, _("Finished to compact key."), _("Key Edit"), MB_OK);
1928          k->update = 1;          k->update = 1;
1929      }      }
     delete ke;  
1930  }  }
1931    
1932    
# Line 1941  do_editkey_sign_userid (winpt_key_t k, H Line 1949  do_editkey_sign_userid (winpt_key_t k, H
1949  {  {
1950      gpgme_error_t err;      gpgme_error_t err;
1951      winpt_key_s signer;      winpt_key_s signer;
1952      GpgKeyEdit *ke;      GpgKeyEdit ke;
1953      char *pass = NULL;      char *pass = NULL;
1954      char *defkey;      char *defkey;
1955      char email[64], name[128], valid[32];      char email[64], name[128], valid[32];
# Line 1953  do_editkey_sign_userid (winpt_key_t k, H Line 1961  do_editkey_sign_userid (winpt_key_t k, H
1961          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1962          return FALSE;          return FALSE;
1963      }      }
1964      listview_get_item_text (lv, uid_index, UID_COL_VALID, valid, sizeof (valid)-1);      listview_get_item_text (lv, uid_index, UID_COL_VALID, valid, DIM (valid)-1);
1965      if (!strcmp (valid, _("Revoked")))      if (!strcmp (valid, _("Revoked")))
1966          return TRUE;          return TRUE;
1967      if (mode == CMD_SIGN) {      if (mode == CMD_SIGN) {
# Line 1962  do_editkey_sign_userid (winpt_key_t k, H Line 1970  do_editkey_sign_userid (winpt_key_t k, H
1970          if (cancel == IDNO)          if (cancel == IDNO)
1971              return FALSE;              return FALSE;
1972      }      }
1973      listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, sizeof (email)-1);      listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, DIM (email)-1);
1974      listview_get_item_text (lv, uid_index, UID_COL_NAME, name, sizeof (name)-1);      listview_get_item_text (lv, uid_index, UID_COL_NAME, name, DIM (name)-1);
1975      uid_index = do_find_userid (k->keyid, email, name, NULL);      uid_index = do_find_userid (k->keyid, email, name, NULL);
1976    
1977      defkey = get_gnupg_default_key ();      defkey = get_gnupg_default_key ();
# Line 1978  do_editkey_sign_userid (winpt_key_t k, H Line 1986  do_editkey_sign_userid (winpt_key_t k, H
1986          if (cancel)          if (cancel)
1987              return FALSE;              return FALSE;
1988      }      }
1989      ke = create_GpgKeyEdit (k->keyid);      ke.setKeyID (k->keyid);
1990      if (signer.is_protected)      if (signer.is_protected)
1991          ke->setPassphrase (pass);          ke.setPassphrase (pass);
1992      else      else
1993          ke->setNoPassphrase (true);          ke.setNoPassphrase (true);
1994      ke->setLocalUser (signer.ctx);      ke.setLocalUser (signer.ctx);
1995      err = ke->signUserid (uid_index,      err = ke.signUserid (uid_index,
1996                            mode == CMD_SIGN? GPG_EDITKEY_SIGN : GPG_EDITKEY_LSIGN,                            mode == CMD_SIGN? GPG_EDITKEY_SIGN : GPG_EDITKEY_LSIGN,
1997                            0, NULL);                            0, NULL);
1998      if (!err) {      if (!err) {
# Line 1993  do_editkey_sign_userid (winpt_key_t k, H Line 2001  do_editkey_sign_userid (winpt_key_t k, H
2001      }      }
2002      else      else
2003          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);
2004      delete ke;  
2005      sfree_if_alloc (pass);      sfree_if_alloc (pass);
2006      return !err? TRUE : FALSE;      return !err? TRUE : FALSE;
2007  }  }
# Line 2008  lookup_cmd (HWND dlg) Line 2016  lookup_cmd (HWND dlg)
2016      i = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0);      i = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0);
2017      if (i == LB_ERR)      if (i == LB_ERR)
2018          return LB_ERR;          return LB_ERR;
2019      GetDlgItemText (dlg, IDC_KEYEDIT_CMD, buf, sizeof (buf)-1);      GetDlgItemText (dlg, IDC_KEYEDIT_CMD, buf, DIM (buf)-1);
2020      for (i=0; cmdlist[i].name != NULL; i++) {      for (i=0; cmdlist[i].name != NULL; i++) {
2021          if (!strcmp (buf, cmdlist[i].name))          if (!strcmp (buf, cmdlist[i].name))
2022              return cmdlist[i].id;              return cmdlist[i].id;
# Line 2054  gen_desig_revoke_cert (winpt_key_t key, Line 2062  gen_desig_revoke_cert (winpt_key_t key,
2062      warn = _("Your keys is listed as a designated revoker for the key\n\n"      warn = _("Your keys is listed as a designated revoker for the key\n\n"
2063               "%s\n\n"               "%s\n\n"
2064               "Are you sure you want to create a revocation certificate\n"               "Are you sure you want to create a revocation certificate\n"
2065               "which allow to revoke the key listed above?");               "which allows you to revoke the key listed above?");
2066      p = new char[strlen (inf)+1+strlen (warn)+1];      p = new char[strlen (inf)+1+strlen (warn)+1];
2067      sprintf (p, warn, inf);      sprintf (p, warn, inf);
2068      free_if_alloc (inf);      free_if_alloc (inf);
# Line 2070  gen_desig_revoke_cert (winpt_key_t key, Line 2078  gen_desig_revoke_cert (winpt_key_t key,
2078  }  }
2079    
2080    
2081    /* Create tooltip control for the listview header. */
2082    static HWND
2083    create_header_tooltip (HWND dlg)
2084    {
2085        TOOLINFO ti;
2086        HWND tt;
2087    
2088        tt = CreateWindow (TOOLTIPS_CLASS, (LPSTR) NULL, TTS_ALWAYSTIP,
2089                            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2090                            CW_USEDEFAULT,
2091                            NULL, (HMENU) NULL, glob_hinst, NULL);
2092        if (!tt)
2093            BUG (NULL);
2094        memset (&ti, 0, sizeof (ti));
2095        ti.cbSize = sizeof (TOOLINFO);
2096        ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;    
2097        ti.hwnd = dlg;    
2098        ti.uId = (UINT) ListView_GetHeader (GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST));
2099        ti.hinst = 0;
2100        ti.lpszText = (char*)_("Capabilties: C = Certify, S = Sign, E = Encrypt, A = Authenticate");
2101        SendMessage(tt, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
2102        return tt;
2103    }
2104    
2105    
2106  /* Dialog box procedure for the edit key dialog. */  /* Dialog box procedure for the edit key dialog. */
2107  BOOL CALLBACK  BOOL CALLBACK
2108  keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
2109  {  {
2110      static winpt_key_t k;      static winpt_key_t k;
2111      static listview_ctrl_t lvsub = NULL, lvuid = NULL;      static listview_ctrl_t lvsub = NULL, lvuid = NULL;
2112        static HWND tt;
2113      int cmd;      int cmd;
2114      HWND item;      HWND item;
2115    
# Line 2093  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 2127  keyedit_main_dlg_proc (HWND dlg, UINT ms
2127          keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc;          keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc;
2128          keyedit_subkey_proc.old = (WNDPROC)GetWindowLong (item, GWL_WNDPROC);          keyedit_subkey_proc.old = (WNDPROC)GetWindowLong (item, GWL_WNDPROC);
2129          if (keyedit_subkey_proc.old) {          if (keyedit_subkey_proc.old) {
2130              if( !SetWindowLong (item, GWL_WNDPROC,              if (!SetWindowLong (item, GWL_WNDPROC,
2131                                  (LONG)keyedit_subkey_proc.current)) {                                  (LONG)keyedit_subkey_proc.current)) {
2132                  msg_box (dlg, _("Could not set subkey window procedure."),                  msg_box (dlg, "Could not set subkey window procedure.",
2133                           _("Key Edit"), MB_ERR);                           _("Key Edit"), MB_ERR);
2134                  BUG (0);                  BUG (NULL);
2135              }              }
2136          }          }
2137            tt = create_header_tooltip (dlg);
2138          item = GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST);          item = GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST);
2139          keyedit_uid_proc.opaque = (void*)k;          keyedit_uid_proc.opaque = (void*)k;
2140          keyedit_uid_proc.dlg = dlg;          keyedit_uid_proc.dlg = dlg;
# Line 2108  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 2143  keyedit_main_dlg_proc (HWND dlg, UINT ms
2143          if (keyedit_uid_proc.old) {          if (keyedit_uid_proc.old) {
2144              if (!SetWindowLong (item, GWL_WNDPROC,              if (!SetWindowLong (item, GWL_WNDPROC,
2145                                  (LONG)keyedit_uid_proc.current)) {                                  (LONG)keyedit_uid_proc.current)) {
2146                  msg_box (dlg, _("Could not set user ID window procedure."),                  msg_box (dlg, "Could not set user ID window procedure.",
2147                           _("Key Edit"), MB_ERR);                           _("Key Edit"), MB_ERR);
2148                  BUG (0);                  BUG (NULL);
2149              }              }
2150          }          }
2151          if (k->ctx->revoked) {          if (k->ctx->revoked) {
# Line 2121  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 2156  keyedit_main_dlg_proc (HWND dlg, UINT ms
2156          SetDlgItemText (dlg, IDCANCEL, _("&Close"));          SetDlgItemText (dlg, IDCANCEL, _("&Close"));
2157          SetDlgItemText (dlg, IDC_KEYEDIT_HELP, _("&Help"));          SetDlgItemText (dlg, IDC_KEYEDIT_HELP, _("&Help"));
2158          SetDlgItemText (dlg, IDC_KEYEDIT_REVOKE, _("&Revoke..."));          SetDlgItemText (dlg, IDC_KEYEDIT_REVOKE, _("&Revoke..."));
2159            SetDlgItemText (dlg, IDOK, _("&OK"));
2160          if (!check_desig_rev (k))          if (!check_desig_rev (k))
2161              ShowWindow (GetDlgItem (dlg, IDC_KEYEDIT_REVOKE), SW_HIDE);              ShowWindow (GetDlgItem (dlg, IDC_KEYEDIT_REVOKE), SW_HIDE);
2162          SetWindowText (dlg, _("Key Edit"));          SetWindowText (dlg, _("Key Edit"));
# Line 2140  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 2176  keyedit_main_dlg_proc (HWND dlg, UINT ms
2176          break;          break;
2177    
2178      case WM_NOTIFY:      case WM_NOTIFY:
2179          NMHDR * notify;          NMHDR *notify;
2180          notify = (NMHDR *)lparam;          notify = (NMHDR *)lparam;
2181          if (!notify || notify->idFrom != IDC_KEYEDIT_UIDLIST)          if (!notify || notify->idFrom != IDC_KEYEDIT_UIDLIST)
2182              break;              break;
2183          if (notify->code == NM_DBLCLK)          if (notify->code == NM_DBLCLK)
2184              do_editkey_showpref (k, dlg, lvuid);              do_editkey_showpref (k, dlg, lvuid);
2185          if (notify->code == NM_RCLICK && k->key_pair) {          else if (notify->code == NM_RCLICK && k->key_pair) {
2186              HMENU hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYEDIT));              HMENU hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYEDIT));
2187              HMENU popup = GetSubMenu (hm, 0);              HMENU popup = GetSubMenu (hm, 0);
2188              POINT p;              POINT p;
# Line 2177  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 2213  keyedit_main_dlg_proc (HWND dlg, UINT ms
2213              case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break;              case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break;
2214              case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break;              case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break;
2215              case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break;              case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break;
2216              /*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/              case CMD_SETPREF:/*do_editkey_setpref (k, dlg, lvuid);*/ break;
2217              case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break;              case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break;
2218              case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break;              case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break;
2219              case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break;              case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break;

Legend:
Removed from v.229  
changed lines
  Added in v.314

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26