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

Diff of /trunk/Src/wptKeysigDlg.cpp

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

revision 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 32 by twoaday, Mon Oct 24 08:03:48 2005 UTC
# Line 35  Line 35 
35  #include "wptTypes.h"  #include "wptTypes.h"
36  #include "wptVersion.h"  #include "wptVersion.h"
37  #include "wptErrors.h"  #include "wptErrors.h"
38    #include "wptKeyEdit.h"
39    
40  static subclass_s siglist_proc;  static subclass_s siglist_proc;
41    
# Line 53  is_sig (listview_ctrl_t lv, int pos) Line 54  is_sig (listview_ctrl_t lv, int pos)
54  }  }
55    
56    
57    /* Delete the selected signature from list view @lv. The
58       key is given in @key. */
59  static int  static int
60  do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key)  do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key)
61  {  {
62      int pos, npos, id;      int pos, npos, id;
63      int signo=0, uidno=0;      int signo=0, uidno=0;
64      gpgme_ctx_t ctx;      GpgKeyEdit *ke;
65      gpgme_editkey_t ek;      gpgme_error_t err;
     gpgme_error_t rc;  
66    
67      npos = pos = listview_get_curr_pos (lv);      npos = pos = listview_get_curr_pos (lv);
68      if (!is_sig (lv, -1))      if (!is_sig (lv, -1))
69          return -1;          return -1;
70      while (pos > 0 && is_sig (lv, pos))      while (pos > 0 && is_sig (lv, pos)) {
     {  
71          signo++;          signo++;
72          pos--;          pos--;
73      }      }
74      pos = npos;      pos = npos;
75      while (npos > 0)      while (npos > 0) {
     {  
76          if (!is_sig (lv, npos))          if (!is_sig (lv, npos))
77              uidno++;              uidno++;
78          npos--;          npos--;
79      }      }
80      uidno++;      uidno++;
81      id = log_box(_("Key Manager"), MB_YESNO,  
82        /* XXX: do not allow to delete the self signature */
83        id = log_box (_("Key Manager"), MB_YESNO,
84                    _("Are you really sure you want to delete this signature from\n"                    _("Are you really sure you want to delete this signature from\n"
85                      "  \"%s\""), key->uid);                      "  \"%s\""), key->uid);
86      if (id == IDNO)      if (id == IDNO)
87          return 0;          return 0;
88      rc = gpgme_new (&ctx);  
89      if (rc)      ke = new GpgKeyEdit (key->keyid);
90          BUG (0);      if (!ke)
91      rc = gpgme_editkey_new (&ek);          BUG (NULL);    
92      if (rc)      err = ke->delUseridSignature (uidno, signo);
93          BUG (0);      if (err)
94      gpgme_editkey_delsig_set (ek, uidno, signo);          msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR);
     gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_DELSIG);  
     rc = gpgme_op_editkey (ctx, key->keyid);  
     if (rc)  
         msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR);  
95      else      else
96          listview_del_item (lv, pos);          listview_del_item (lv, pos);
97      gpgme_release (ctx);      delete ke;
98      gpgme_editkey_release (ek);      key->update = 1; /*update*/
99      return 0;      return err? -1 : 0;
100  }  }
101    
102    
103    /* Dialog box procedure to display the signature properties. */
104  static BOOL CALLBACK  static BOOL CALLBACK
105  sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
106  {  {
# Line 116  sigprops_dlg_proc (HWND dlg, UINT msg, W Line 115  sigprops_dlg_proc (HWND dlg, UINT msg, W
115          const char * alg;          const char * alg;
116          int _class;          int _class;
117      } ctx;      } ctx;
118      const char * fmt_templ = "%s %s signature";      const char *fmt_templ = _("%s %s signature");
119    
120      switch (msg)      switch (msg) {
     {  
121      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
122          if (LOWORD (wparam) == SC_CLOSE)          if (LOWORD (wparam) == SC_CLOSE)
123              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
# Line 146  sigprops_dlg_proc (HWND dlg, UINT msg, W Line 144  sigprops_dlg_proc (HWND dlg, UINT msg, W
144              ctx.alg = "RSA";              ctx.alg = "RSA";
145          else          else
146              ctx.alg = "ELG";              ctx.alg = "ELG";
147          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
148                     ctx.exportable? "Exportable" : "Non-exportable", ctx.alg);                     ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg);
149          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
150          listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);          listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);
151          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);
# Line 158  sigprops_dlg_proc (HWND dlg, UINT msg, W Line 156  sigprops_dlg_proc (HWND dlg, UINT msg, W
156          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);
157          tmpbuf[0] = 0;          tmpbuf[0] = 0;
158          listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);          listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);
159          if (strlen (tmpbuf) == 0)          if (strlen (tmpbuf) == 0) {
         {  
160              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
161              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
162          }          }
163          else          else {
         {  
164              SYSTEMTIME st;              SYSTEMTIME st;
165              struct tm * tm;              struct tm * tm;
166              time_t t = time (NULL);              time_t t = time (NULL);
# Line 190  sigprops_dlg_proc (HWND dlg, UINT msg, W Line 186  sigprops_dlg_proc (HWND dlg, UINT msg, W
186          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
187          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
188          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
189            SetWindowText (dlg, _("Signature Properties"));
190          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
191          center_window (dlg);          center_window (dlg, NULL);
192          return TRUE;          return TRUE;
193    
194      case WM_COMMAND:      case WM_COMMAND:
195          switch (LOWORD (wparam))          switch (LOWORD (wparam)) {
         {  
196          case IDOK:          case IDOK:
197              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
198              break;              break;
# Line 213  subclass_dlg_proc (HWND dlg, UINT msg, W Line 209  subclass_dlg_proc (HWND dlg, UINT msg, W
209      listview_ctrl_t lv;      listview_ctrl_t lv;
210      winpt_key_t key;      winpt_key_t key;
211    
212      switch (msg)      switch (msg) {
     {  
213      case WM_KEYUP:      case WM_KEYUP:
214          int virt_key = (int)wparam;          int virt_key = (int)wparam;
215          key = (winpt_key_t)siglist_proc.opaque;          key = (winpt_key_t)siglist_proc.opaque;
216          lv = key->callback.ctl;          lv = key->callback.ctl;
217          if (virt_key == VK_SPACE)          if (virt_key == VK_SPACE) {
         {  
218              if (is_sig (lv, -1))              if (is_sig (lv, -1))
219                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
220                                  sigprops_dlg_proc, (LPARAM)lv);                                  sigprops_dlg_proc, (LPARAM)lv);
# Line 233  subclass_dlg_proc (HWND dlg, UINT msg, W Line 227  subclass_dlg_proc (HWND dlg, UINT msg, W
227  }  }
228    
229    
230    /* Return 1 if the list view @lv contains non-available keys. */
231  static int  static int
232  check_for_missing_keys (listview_ctrl_t lv)  check_for_missing_keys (listview_ctrl_t lv)
233  {  {
# Line 241  check_for_missing_keys (listview_ctrl_t Line 236  check_for_missing_keys (listview_ctrl_t
236            
237      n = listview_count_items( lv, 0 );      n = listview_count_items( lv, 0 );
238      for( i = 0; i < n; i++ ) {      for( i = 0; i < n; i++ ) {
239          listview_get_item_text( lv, i, 1, id, sizeof id - 1 );          listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 );
240          if( !strncmp( id, "NOKEY", 5 ) )          if( !strncmp( id, "NOKEY", 5 ) )
241              return 1;              return 1;
242      }      }
243            
244      return 0;      return 0;
245  } /* check_for_missing_keys */  }
246    
247    
248    /* Receive all missing keys marked in the list @lv. */
249  static int  static int
250  recv_missing_keys (HWND dlg, listview_ctrl_t lv)  recv_missing_keys (HWND dlg, listview_ctrl_t lv)
251  {  {
# Line 268  recv_missing_keys (HWND dlg, listview_ct Line 264  recv_missing_keys (HWND dlg, listview_ct
264      }      }
265            
266      return rc;      return rc;
267  } /* recv_missing_keys */  }
268    
269    
270    /* Create a mini popup with available choices. */
271  static void  static void
272  do_create_popup (HWND dlg)  do_create_popup (HWND dlg)
273  {  {
# Line 281  do_create_popup (HWND dlg) Line 278  do_create_popup (HWND dlg)
278      hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));      hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));
279      sm = GetSubMenu (hm, 0);      sm = GetSubMenu (hm, 0);
280    
281        set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties"));
282        set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties"));
283    
284      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
285    
286      DestroyMenu (hm);      DestroyMenu (hm);
# Line 288  do_create_popup (HWND dlg) Line 288  do_create_popup (HWND dlg)
288  }  }
289    
290    
291    /* Load the key property dialog with the selected key from @lv. */
292  static void  static void
293  do_load_keyprops (HWND dlg, listview_ctrl_t lv)  do_load_keyprops (HWND dlg, listview_ctrl_t lv)
294  {  {
# Line 318  do_load_keyprops (HWND dlg, listview_ctr Line 319  do_load_keyprops (HWND dlg, listview_ctr
319  }  }
320    
321    
322    /* Dialog box procedure to list signatures. */
323  BOOL CALLBACK  BOOL CALLBACK
324  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
325  {  {
326      static listview_ctrl_t lv = NULL;      static listview_ctrl_t lv = NULL;
327      struct winpt_key_s *k;      static struct winpt_key_s *k;
328      char inf[384], keyid[18+1];          char inf[384], keyid[18+1];    
329      int idx = 0, id, rc;      int idx = 0, id, rc;
330      HWND sl;      HWND sl;
# Line 332  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 334  keysig_dlg_proc (HWND dlg, UINT msg, WPA
334          k = (winpt_key_t) lparam;          k = (winpt_key_t) lparam;
335          if (!k)          if (!k)
336              BUG (0);              BUG (0);
337          if( k->uid )          if (k->uid)
338              _snprintf( inf, sizeof inf - 1, _("Signature List for \"%s\""), k->uid );              _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
339          SetWindowText( dlg, inf );          SetWindowText (dlg, inf);
340          #ifndef LANG_DE          #ifndef LANG_DE
341          SetDlgItemText( dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key") );          SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
342          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
343          #endif          #endif
344          lv = siglist_load( GetDlgItem( dlg, IDC_KEYSIG_LIST ), k->keyid );          lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);
345          if( !check_for_missing_keys( lv ) )          if (!check_for_missing_keys (lv))
346              EnableWindow( GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE );              EnableWindow (GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE);
347          k->callback.ctl = lv;          k->callback.ctl = lv;
348          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);
349          siglist_proc.dlg = dlg;          siglist_proc.dlg = dlg;
350          siglist_proc.opaque = k;          siglist_proc.opaque = k;
351          siglist_proc.current = (WNDPROC)subclass_dlg_proc;          siglist_proc.current = (WNDPROC)subclass_dlg_proc;
352          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);
353          if (siglist_proc.old)          if (siglist_proc.old) {
354          {              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  {
355              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))                  msg_box (dlg, _("Could not set keylist window procedure."),
356              {                           _("Key Manager"), MB_ERR);
                 msg_box (dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR);  
357                  BUG (0);                  BUG (0);
358              }              }
359          }          }
360          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
361          center_window (dlg);          center_window (dlg, NULL);
362          return TRUE;          return TRUE;
363                    
364      case WM_DESTROY:      case WM_DESTROY:
# Line 368  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 369  keysig_dlg_proc (HWND dlg, UINT msg, WPA
369          return FALSE;          return FALSE;
370                    
371      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
372          if( LOWORD ( wparam ) == SC_CLOSE )          if (LOWORD (wparam) == SC_CLOSE) {
373              EndDialog( dlg, TRUE );              if (k->update)
374                    keycache_update (0, k->keyid);
375                EndDialog (dlg, TRUE);
376            }
377          return FALSE;          return FALSE;
378    
379      case WM_NOTIFY:      case WM_NOTIFY:
# Line 398  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 402  keysig_dlg_proc (HWND dlg, UINT msg, WPA
402              break;              break;
403    
404          case IDC_KEYSIG_RECVKEY:          case IDC_KEYSIG_RECVKEY:
405              idx = listview_get_curr_pos( lv );              idx = listview_get_curr_pos (lv);
406              if( idx == -1 ) {              if (idx == -1) {
407                  id = msg_box( dlg, _("Really receive all missing keys?"),                  id = msg_box( dlg, _("Really receive all missing keys?"),
408                                  _("Key Manager"), MB_YESNO|MB_INFO );                                  _("Key Manager"), MB_YESNO|MB_INFO );
409                  if( id == IDYES ) {                  if (id == IDYES) {
410                      rc = recv_missing_keys( dlg, lv );                      rc = recv_missing_keys (dlg, lv);
411                      if( !rc )                      if( !rc )
412                          keycache_set_reload( 1 );                          keycache_set_reload (1);
413                      return TRUE;                      return TRUE;
414                  }                  }
415                  return FALSE;                  return TRUE;
416              }              }
417              listview_get_item_text (lv, idx, 4, keyid, sizeof keyid - 1);              listview_get_item_text (lv, idx, 1, inf, DIM (inf)-1);
418                if (strcmp (inf, "NOKEY"))
419                    return FALSE;
420                listview_get_item_text (lv, idx, 4, keyid, DIM (keyid)-1);
421              rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);              rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);
422              if (!rc)              if (!rc)
423                  keycache_set_reload (1);                  keycache_set_reload (1);
# Line 423  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 430  keysig_dlg_proc (HWND dlg, UINT msg, WPA
430              return TRUE;              return TRUE;
431                            
432          case IDOK:          case IDOK:
433                if (k->update)
434                    keycache_update (0, k->keyid);
435              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
436              return TRUE;              return TRUE;
437          }          }
438          break;          break;
439      }      }
440      return FALSE;      return FALSE;
441  } /* keysig_dlg_proc */  }

Legend:
Removed from v.2  
changed lines
  Added in v.32

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26