/[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 150 by twoaday, Wed Jan 18 11:52:45 2006 UTC revision 160 by twoaday, Thu Jan 19 09:22:09 2006 UTC
# Line 213  do_add_new_subkey (listview_ctrl_t lv, K Line 213  do_add_new_subkey (listview_ctrl_t lv, K
213    
214    
215  /* Try to find the GPG edit key index which belongs to the user ID  /* Try to find the GPG edit key index which belongs to the user ID
216     given by @name. If @r_inf != NULL, the info context will be returned.     given by the email address @email, @name is used as a fallback.
217       If @r_inf != NULL, the info context will be returned.
218     Return value: index of the user ID or -1 on error. */     Return value: index of the user ID or -1 on error. */
219  static int  static int
220  do_find_userid (const char *keyid, const char *name, gpg_uid_info_t *r_inf)  do_find_userid (const char *keyid, const char *email,
221                    const char *name, gpg_uid_info_t *r_inf)
222  {  {
223      GpgKeyEdit *ke;      GpgKeyEdit *ke;
224      gpgme_error_t err;      gpgme_error_t err;
# Line 236  do_find_userid (const char *keyid, const Line 238  do_find_userid (const char *keyid, const
238      }      }
239    
240      for (ui = inf; ui; ui = ui->next) {      for (ui = inf; ui; ui = ui->next) {
241          if (!strcmp (ui->email, name)) {          if (name && email && ui->email && ui->name) {
242                if (!strcmp (ui->email, email) &&
243                    !strncmp (ui->name, name, strlen (name))) {
244                    pos = ui->index;
245                    break;
246                }
247                continue;
248            }
249            if (ui->email) {
250                if (!strcmp (ui->email, email)) {
251                    pos = ui->index;
252                    break;
253                }
254                /* The email address is more unique, use the name just
255                   as the fallbck when no email address is available. */
256                continue;
257            }
258            if (ui->name && name && !strcmp (ui->name, name)) {
259              pos = ui->index;              pos = ui->index;
260              break;              break;
261          }          }
# Line 1094  userid_list_init (HWND dlg, winpt_key_t Line 1113  userid_list_init (HWND dlg, winpt_key_t
1113          if (attr) {          if (attr) {
1114              char *uid = utf8_to_wincp (attr, strlen (attr));              char *uid = utf8_to_wincp (attr, strlen (attr));
1115              if (uid) {              if (uid) {
1116                  listview_add_sub_item( lv, j, 1, uid );                  listview_add_sub_item (lv, j, 1, uid);
1117                  free( uid );                  free (uid);
1118              }              }
1119          }          }
1120          else          else
1121              listview_add_sub_item( lv, j, 1, _("Invalid user ID") );              listview_add_sub_item (lv, j, 1, _("Invalid user ID"));
1122          attr = u->email;          attr = u->email;
1123          if (attr)          if (attr)
1124              listview_add_sub_item (lv, j, 2, attr);              listview_add_sub_item (lv, j, 2, attr);
# Line 1391  do_editkey_revuid (winpt_key_t k, HWND d Line 1410  do_editkey_revuid (winpt_key_t k, HWND d
1410  {  {
1411      gpgme_error_t err;      gpgme_error_t err;
1412      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1413      char buf[256], t[512];      char buf[128], email[128];
1414      char *pass=NULL;      char inf[512];
1415        char *pass = NULL;
1416      int cancel = 0, id = 0, j;      int cancel = 0, id = 0, j;
1417    
1418      if (!k->key_pair) {      if (!k->key_pair) {
1419          msg_box( dlg, _("There is no secret key available!"), _("Revoke user ID"), MB_ERR );          msg_box (dlg, _("There is no secret key available!"),
1420                     _("Revoke user ID"), MB_ERR);
1421          return FALSE;          return FALSE;
1422      }      }
1423    
1424      if( listview_count_items( lv, 0 ) == 1 ) {      if (listview_count_items (lv, 0) == 1) {
1425          msg_box( dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR );            msg_box (dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR);  
1426          return FALSE;          return FALSE;
1427      }      }
1428    
# Line 1410  do_editkey_revuid (winpt_key_t k, HWND d Line 1431  do_editkey_revuid (winpt_key_t k, HWND d
1431          return FALSE;            return FALSE;  
1432      }      }
1433                            
1434      listview_get_item_text( lv, j, 0, buf, sizeof buf - 1 );      listview_get_item_text( lv, j, UID_COL_VALID, buf, sizeof buf - 1);
1435      if( strstr( buf, _("Revoked") ) ) {      if (strstr (buf, _("Revoked"))) {
1436          msg_box( dlg, _("This user ID has been already revoked."), _("Key Edit"), MB_INFO );          msg_box (dlg, _("This user ID has been already revoked."),
1437                     _("Key Edit"), MB_INFO);
1438          return FALSE;          return FALSE;
1439      }      }
1440                            
1441      listview_get_item_text (lv, j, 1, buf, sizeof buf -1);      listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof buf -1);
1442      _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"      _snprintf (inf, sizeof (inf) -1, _("user ID \"%s\".\n\n"
1443                  "Do you really want to revoke this user ID?"), buf );                 "Do you really want to revoke this user ID?"), buf);
1444      if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO )      if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO)
1445          return FALSE;          return FALSE;
1446      if( k->is_protected ) {      if (k->is_protected) {
1447          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_passphrase (_("Key Edit"), 1, &cancel);
1448          if (cancel)          if (cancel)
1449              return FALSE;                        return FALSE;          
1450      }      }
1451      listview_get_item_text (lv, j, 2, buf, sizeof (buf)-1);      listview_get_item_text (lv, j, UID_COL_EMAIL, email, sizeof (email)-1);
1452      id = do_find_userid (k->keyid, buf, NULL);      listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof (buf)-1);
1453        id = do_find_userid (k->keyid, email, buf, NULL);
1454      if (id == -1)      if (id == -1)
1455          BUG (NULL);          BUG (NULL);
1456    
# Line 1438  do_editkey_revuid (winpt_key_t k, HWND d Line 1461  do_editkey_revuid (winpt_key_t k, HWND d
1461          ke->setPassphrase (pass);          ke->setPassphrase (pass);
1462      err = ke->revokeUserid (id);      err = ke->revokeUserid (id);
1463      if (err)      if (err)
1464          msg_box (dlg, gpgme_strerror (err), _("Revoke Signature"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Revoke User ID"), MB_ERR);
1465      else {      else {
1466          listview_add_sub_item (lv, j, 0, _("Revoked"));          listview_add_sub_item (lv, j, 0, _("Revoked"));
1467          k->update = 1;          k->update = 1;
# Line 1463  do_editkey_setpref (winpt_key_t k, HWND Line 1486  do_editkey_setpref (winpt_key_t k, HWND
1486          return FALSE;          return FALSE;
1487      }      }
1488      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);
1489      id = do_find_userid (k->keyid, buf, NULL);      id = do_find_userid (k->keyid, buf, NULL, NULL);
1490      if (id == -1)      if (id == -1)
1491          BUG (dlg);          BUG (dlg);
1492      if (k->is_protected) {      if (k->is_protected) {
# Line 1505  do_editkey_primary (winpt_key_t k, HWND Line 1528  do_editkey_primary (winpt_key_t k, HWND
1528          return FALSE;          return FALSE;
1529      }      }
1530      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);      listview_get_item_text (lv, j, 2, buf, sizeof buf-1);
1531      id = do_find_userid (k->keyid, buf, NULL);      id = do_find_userid (k->keyid, buf, NULL, NULL);
1532      if (id == -1)      if (id == -1)
1533          BUG (dlg);          BUG (dlg);
1534      if (k->is_protected) {      if (k->is_protected) {
# Line 1596  showpref_dlg_proc (HWND dlg, UINT msg, W Line 1619  showpref_dlg_proc (HWND dlg, UINT msg, W
1619          pos = listview_get_curr_pos (cb->lv);          pos = listview_get_curr_pos (cb->lv);
1620          listview_get_item_text (cb->lv, pos, 2, buf, DIM (buf)-1);          listview_get_item_text (cb->lv, pos, 2, buf, DIM (buf)-1);
1621          SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);          SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);
1622          pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf);          pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid,
1623                                  buf, NULL, &inf);
1624          if (inf) {          if (inf) {
1625              const char *prefs = inf->prefs;              const char *prefs = inf->prefs;
1626              if (prefs && *prefs) {              if (prefs && *prefs) {
# Line 1658  do_editkey_deluid (winpt_key_t k, HWND d Line 1682  do_editkey_deluid (winpt_key_t k, HWND d
1682  {  {
1683      gpgme_error_t err;      gpgme_error_t err;
1684      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1685      char buf[256], t[512];      char email[128], name[128];
1686        char inf[384];
1687      int j, id = 0;      int j, id = 0;
1688    
1689      if (!k->key_pair)      if (!k->key_pair)
1690          return FALSE; /* XXX: see do_editkey_delsubkey */          return FALSE; /* XXX: see do_editkey_delsubkey */
1691    
1692      if( listview_count_items( lv, 0 ) == 1 ) {      if (listview_count_items (lv, 0) == 1) {
1693          msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR );          msg_box (dlg, _("Primary user ID can not be deleted!"),
1694                     _("Key Edit"), MB_ERR);
1695          return FALSE;          return FALSE;
1696      }      }
1697      if( (j = listview_get_curr_pos( lv )) == -1 ) {      if ((j = listview_get_curr_pos (lv)) == -1) {
1698          msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );          msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1699          return FALSE;          return FALSE;
1700      }      }
1701            
1702      /* XXX: add a hint that also all signatures will be deleted? */      /* XXX: add a hint that also all signatures will be deleted? */
1703      listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 );      listview_get_item_text (lv, j, UID_COL_NAME, name, DIM(name) -1);
1704      _snprintf( t, DIM (t)-1, _("user ID \"%s\".\n\n"      _snprintf (inf, DIM (inf)-1, _("user ID \"%s\".\n\n"
1705                                 "Do you really want to delete this user ID?"),                                     "Do you really want to delete this user ID?"),
1706                                 buf);                                 name);
1707      if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO )      if (msg_box (dlg, inf, _("Key Edit"), MB_YESNO|MB_ICONWARNING) == IDNO)
1708          return FALSE;          return FALSE;
1709            
1710      listview_get_item_text (lv, j, 2, buf, DIM (buf)-1);      listview_get_item_text (lv, j, UID_COL_EMAIL, email, DIM (email)-1);
1711      id = do_find_userid (k->keyid, buf, NULL);      listview_get_item_text (lv, j, UID_COL_NAME, name, DIM (name)-1);
1712        id = do_find_userid (k->keyid, email, name, NULL);
1713      if (id == -1)      if (id == -1)
1714          BUG (dlg);          BUG (dlg);
1715    
# Line 1691  do_editkey_deluid (winpt_key_t k, HWND d Line 1718  do_editkey_deluid (winpt_key_t k, HWND d
1718          BUG (NULL);          BUG (NULL);
1719    
1720      err = ke->delUserid (id);      err = ke->delUserid (id);
1721      if( err )      if (err)
1722          msg_box( dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR );          msg_box (dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR);
1723      else {      else {
1724          listview_del_item( lv, j );          listview_del_item (lv, j);
1725          k->update = 1;          k->update = 1;
1726          status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") );          status_box (dlg, _("User ID successfully deleted"), _("GnuPG Status"));
1727      }      }
1728      delete ke;      delete ke;
1729      return err? FALSE : TRUE;      return err? FALSE : TRUE;

Legend:
Removed from v.150  
changed lines
  Added in v.160

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26