/[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 42 by werner, Fri Oct 28 08:25:30 2005 UTC revision 141 by twoaday, Wed Jan 11 12:48:51 2006 UTC
# Line 1  Line 1 
1  /* wptKeysigDlg.cpp - Key signature listing  /* wptKeysigDlg.cpp - Key signature listing
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
   
20  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
21  #include <config.h>  #include <config.h>
22  #endif  #endif
23    
24  #include <windows.h>  #include <windows.h>
 #include <windows.h>  
25  #include <commctrl.h>  #include <commctrl.h>
26  #include <time.h>  #include <time.h>
27    
28  #include "../resource.h"  #include "resource.h"
29  #include "wptGPG.h"  #include "wptGPG.h"
30  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
31  #include "wptContext.h" /* for passphrase_s */  #include "wptContext.h" /* for passphrase_s */
32  #include "wptDlgs.h"  #include "wptDlgs.h"
33  #include "wptW32API.h"  #include "wptW32API.h"
34  #include "wptNLS.h"  #include "wptNLS.h"
35  #include "wptKeyList.h"  #include "wptKeylist.h"
36  #include "wptKeyserver.h"  #include "wptKeyserver.h"
37  #include "wptUTF8.h"  #include "wptUTF8.h"
38  #include "wptTypes.h"  #include "wptTypes.h"
# Line 48  static subclass_s siglist_proc; Line 46  static subclass_s siglist_proc;
46  static int  static int
47  is_sig (listview_ctrl_t lv, int pos)  is_sig (listview_ctrl_t lv, int pos)
48  {  {
49      char tmpbuf[256];      char tmpbuf[200];
50    
51      if (pos == -1)      if (pos == -1)
52          pos = listview_get_curr_pos (lv);          pos = listview_get_curr_pos (lv);
53      if (pos == -1)      if (pos == -1)
54          return 0;          return 0;
55      listview_get_item_text (lv, pos, 0, tmpbuf, 200);      listview_get_item_text (lv, pos, SL_COL_UID, tmpbuf, sizeof (tmpbuf)-1);
56      if (*tmpbuf == ' ')      if (*tmpbuf == ' ')
57          return -1;          return -1;
58      return 0;      return 0;
# Line 131  sigprops_dlg_proc (HWND dlg, UINT msg, W Line 129  sigprops_dlg_proc (HWND dlg, UINT msg, W
129          return FALSE;          return FALSE;
130    
131      case WM_INITDIALOG:      case WM_INITDIALOG:
132            SetWindowText (dlg, _("Signature Properties"));
133            SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
134            SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
135            SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
136            SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
137            SetDlgItemText (dlg, IDC_SIGPROPS_CLASSINF, _("Class"));
138            SetDlgItemText (dlg, IDC_SIGPROPS_EXPSTR, _("Expire date"));
139            SetDlgItemText (dlg, IDC_SIGPROPS_KEYINF, _("Issuer key"));
140            SetDlgItemText (dlg, IDC_SIGPROPS_KEYIDINF, _("Issuer key ID"));
141          lv = (listview_ctrl_t)lparam;          lv = (listview_ctrl_t)lparam;
142          if (!lv)          if (!lv)
143              dlg_fatal_error (dlg, "could not get dialog param");              dlg_fatal_error (dlg, "could not get dialog param");
144          memset (&ctx, 0, sizeof ctx);          memset (&ctx, 0, sizeof ctx);
145          n = listview_get_curr_pos (lv);          n = listview_get_curr_pos (lv);
146          listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1);          listview_get_item_text (lv, n, SL_COL_CLASS, tmpbuf, DIM (tmpbuf)-1);
147          if (!strstr (tmpbuf, "L"))          if (!strstr (tmpbuf, "L"))
148              ctx.exportable = 1;              ctx.exportable = 1;
149          ctx._class = atoi (tmpbuf);          ctx._class = atoi (tmpbuf);
# Line 144  sigprops_dlg_proc (HWND dlg, UINT msg, W Line 151  sigprops_dlg_proc (HWND dlg, UINT msg, W
151              ctx._class = 10;              ctx._class = 10;
152          else if (ctx._class < 10)          else if (ctx._class < 10)
153              ctx._class += 10;              ctx._class += 10;
154          listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1);          listview_get_item_text (lv, n, SL_COL_ALGO, tmpbuf, DIM (tmpbuf)-1);
155          if (strstr (tmpbuf, "DSA"))                  if (strstr (tmpbuf, "DSA"))        
156              ctx.alg = "DSA";              ctx.alg = "DSA";
157          else if (strstr (tmpbuf, "RSA"))          else if (strstr (tmpbuf, "RSA"))
# Line 154  sigprops_dlg_proc (HWND dlg, UINT msg, W Line 161  sigprops_dlg_proc (HWND dlg, UINT msg, W
161          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
162                     ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg);                     ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg);
163          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
164          listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);          listview_get_item_text (lv, n, SL_COL_KEYID, tmpbuf, DIM (tmpbuf)-1);
165          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);
166          SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);          SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);
167          if (ctx.exportable)          if (ctx.exportable)
168              CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);              CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
169          listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1);          listview_get_item_text (lv, n, SL_COL_UID, tmpbuf, DIM (tmpbuf)-1);
170          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);
171          tmpbuf[0] = 0;          tmpbuf[0] = 0;
172          listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);          listview_get_item_text (lv, n, SL_COL_EXPIRE, tmpbuf, DIM (tmpbuf)-1);
173          if (strlen (tmpbuf) == 0) {          if (strlen (tmpbuf) == 0) {
174              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
175              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
# Line 243  check_for_missing_keys (listview_ctrl_t Line 250  check_for_missing_keys (listview_ctrl_t
250            
251      n = listview_count_items( lv, 0 );      n = listview_count_items( lv, 0 );
252      for( i = 0; i < n; i++ ) {      for( i = 0; i < n; i++ ) {
253          listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 );          listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
254          if( !strncmp( id, "NOKEY", 5 ) )          if (!strncmp (id, "NOKEY", 5))
255              return 1;              return 1;
256      }      }
257            
# Line 253  check_for_missing_keys (listview_ctrl_t Line 260  check_for_missing_keys (listview_ctrl_t
260    
261    
262  /* Receive all missing keys marked in the list @lv. */  /* Receive all missing keys marked in the list @lv. */
263  static int  static void
264  recv_missing_keys (HWND dlg, listview_ctrl_t lv)  recv_missing_keys (HWND dlg, listview_ctrl_t lv)
265  {  {
266      int i, n, rc;      int i, n, cnt=0;
267      char id[128], keyid[18+1];      char id[128], keyid[18+1];
268    
269        i = msg_box (dlg, _("Really receive all missing keys?"),
270                     _("Key Manager"), MB_YESNO|MB_INFO);
271        if (i == IDNO)
272            return;
273            
274      n = listview_count_items (lv, 0);      n = listview_count_items (lv, 0);
275      for( i = 0; i < n; i++ ) {      for (i = 0; i < n; i++) {
276          listview_get_item_text( lv, i, 1, id, sizeof id - 1 );          listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
277          if( !strncmp( id, "NOKEY", 5 ) ) {          if (!strncmp (id, "NOKEY", 5)) {
278              listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 );              listview_get_item_text (lv, i, SL_COL_KEYID,
279              rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 );                                      keyid, sizeof (keyid) -1);
280              if( rc )                            if (!hkp_recv_key (dlg, default_keyserver,
281                                   default_keyserver_port, keyid, 0, 0))
282                    cnt++;
283                else
284                  break;                  break;
285          }          }
286      }      }
287            if (cnt > 0)
288      return rc;          keycache_set_reload (1);
289  }  }
290    
291    
# Line 295  do_create_popup (HWND dlg) Line 310  do_create_popup (HWND dlg)
310  }  }
311    
312    
313    /* Fetch a single key and extract the keyid from the listview
314       entry at the pos @idx. */
315    static int
316    recv_single_key (HWND dlg, listview_ctrl_t lv, int idx)
317    {
318        char keyid[32];
319        int rc;
320    
321        listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1);      
322        rc = hkp_recv_key (dlg, default_keyserver,
323                           default_keyserver_port, keyid, 0, 0);
324                    
325        if (!rc)
326            keycache_update (0, keyid);
327        return rc;
328    }
329    
330    
331  /* Load the key property dialog with the selected key from @lv. */  /* Load the key property dialog with the selected key from @lv. */
332  static void  static void
333  do_load_keyprops (HWND dlg, listview_ctrl_t lv)  do_load_keyprops (HWND dlg, listview_ctrl_t lv)
# Line 305  do_load_keyprops (HWND dlg, listview_ctr Line 338  do_load_keyprops (HWND dlg, listview_ctr
338      char status[64] = {0}, creation[64] = {0};      char status[64] = {0}, creation[64] = {0};
339      int n = listview_get_curr_pos (lv);      int n = listview_get_curr_pos (lv);
340    
341      listview_get_item_text (lv, n, 1, status, DIM (status)-1);      listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1);
342      listview_get_item_text (lv, n, 3, creation, DIM (creation)-1);      listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1);
343      listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1);      listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1);
344      if (!strcmp (status, "NOKEY")) {      if (!strcmp (status, "NOKEY")) {
345          msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."),          int id = msg_box (dlg, _("Key not found in keyring, do you want to fetch it from the keyserver?"),
346                   _("Key Manager"), MB_INFO);                   _("Key Manager"), MB_QUEST_ASK);
347          return;          if (id == IDNO)
348                return;
349            if (recv_single_key (dlg, lv, n))              
350                return;
351      }      }
352            
353      if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {      if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {
# Line 332  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 368  keysig_dlg_proc (HWND dlg, UINT msg, WPA
368  {  {
369      static listview_ctrl_t lv = NULL;      static listview_ctrl_t lv = NULL;
370      static struct winpt_key_s *k;      static struct winpt_key_s *k;
371      char inf[384], keyid[18+1];          char inf[384];
372      int idx = 0, id, rc;      int idx = 0;
373      HWND sl;      HWND sl;
374            
375      switch( msg ) {      switch (msg) {
376      case WM_INITDIALOG:      case WM_INITDIALOG:
377          k = (winpt_key_t) lparam;          k = (winpt_key_t) lparam;
378          if (!k)          if (!k)
# Line 344  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 380  keysig_dlg_proc (HWND dlg, UINT msg, WPA
380          if (k->uid)          if (k->uid)
381              _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);              _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
382          SetWindowText (dlg, inf);          SetWindowText (dlg, inf);
         #ifndef LANG_DE  
383          SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));          SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
384          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
385          #endif  
386          lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);          lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);
387          if (!check_for_missing_keys (lv))          if (!check_for_missing_keys (lv))
388              EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE);
389            EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE);
390          k->callback.ctl = lv;          k->callback.ctl = lv;
391          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);
392          siglist_proc.dlg = dlg;          siglist_proc.dlg = dlg;
# Line 359  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 395  keysig_dlg_proc (HWND dlg, UINT msg, WPA
395          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);
396          if (siglist_proc.old) {          if (siglist_proc.old) {
397              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  {              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  {
398                  msg_box (dlg, _("Could not set keylist window procedure."),                  msg_box (dlg, "Could not set keylist window procedure.",
399                           _("Key Manager"), MB_ERR);                           _("Key Manager"), MB_ERR);
400                  BUG (0);                  BUG (0);
401              }              }
# Line 369  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 405  keysig_dlg_proc (HWND dlg, UINT msg, WPA
405          return TRUE;          return TRUE;
406                    
407      case WM_DESTROY:      case WM_DESTROY:
408          if ( lv ) {          if (lv) {
409              siglist_delete( lv );              siglist_delete (lv);
410              lv = NULL;              lv = NULL;
411          }          }
412          return FALSE;          return FALSE;
# Line 387  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 423  keysig_dlg_proc (HWND dlg, UINT msg, WPA
423          NMHDR *notify;          NMHDR *notify;
424                    
425          notify = (NMHDR *)lparam;          notify = (NMHDR *)lparam;
426          if (notify && notify->code == NM_DBLCLK          if (!notify)
427                return FALSE;
428            if (notify->code == NM_DBLCLK
429              && notify->idFrom == IDC_KEYSIG_LIST)              && notify->idFrom == IDC_KEYSIG_LIST)
430              do_load_keyprops (dlg, lv);              do_load_keyprops (dlg, lv);
431          if (notify && notify->code == NM_RCLICK &&          if (notify->code == NM_RCLICK &&
432              notify->idFrom == IDC_KEYSIG_LIST)              notify->idFrom == IDC_KEYSIG_LIST &&
433                is_sig (lv, -1))
434              do_create_popup (dlg);              do_create_popup (dlg);
435          if (notify && notify->code == LVN_ITEMCHANGED &&          if (notify->code == LVN_ITEMCHANGED &&
436              ((LPNMLISTVIEW)lparam)->uNewState) {              ((LPNMLISTVIEW)lparam)->uNewState) {
437              idx = listview_get_curr_pos (lv);              idx = listview_get_curr_pos (lv);
438              listview_get_item_text (lv, idx, 1, inf, DIM (inf)-1);              listview_get_item_text (lv, idx, SL_COL_VALID, inf, DIM (inf)-1);
439              EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY),              EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY),
440                            strcmp (inf, "NOKEY") == 0? TRUE: FALSE);                            strcmp (inf, "NOKEY") == 0? TRUE: FALSE);
441                EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS),
442                              is_sig (lv, -1)? TRUE : FALSE);
443            }
444            if (notify->code == LVN_COLUMNCLICK) {
445                NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
446                int sortby = 0;
447                switch (nft->iSubItem) {
448                //case 0:  sortby = KEY_SORT_USERID; break;
449                case 1: sortby = KEY_SORT_VALIDITY; break;
450                case 2: sortby = SIG_SORT_CLASS; break;
451                case 3: sortby = KEY_SORT_CREATED; break;
452                case 4: sortby = KEY_SORT_KEYID; break;
453                case 5: sortby = SIG_SORT_EXPIRE; break;
454                case 6: sortby = KEY_SORT_ALGO; break;
455                default: return TRUE;
456                }
457                siglist_sort (lv, sortby);
458          }          }
459          break;          break;
460                    
461      case WM_COMMAND:      case WM_COMMAND:
462          switch ( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
   
463          case ID_SIGCTX_KEYPROPS:          case ID_SIGCTX_KEYPROPS:
464              do_load_keyprops (dlg, lv);              do_load_keyprops (dlg, lv);
465              break;              break;
# Line 417  keysig_dlg_proc (HWND dlg, UINT msg, WPA Line 472  keysig_dlg_proc (HWND dlg, UINT msg, WPA
472    
473          case IDC_KEYSIG_RECVKEY:          case IDC_KEYSIG_RECVKEY:
474              idx = listview_get_curr_pos (lv);              idx = listview_get_curr_pos (lv);
475              if (idx == -1) {              if (idx == -1)
476                  id = msg_box( dlg, _("Really receive all missing keys?"),                  recv_missing_keys (dlg, lv);
477                                  _("Key Manager"), MB_YESNO|MB_INFO );              else
478                  if (id == IDYES) {                  recv_single_key (dlg, lv, idx);
                     rc = recv_missing_keys (dlg, lv);  
                     if (!rc)  
                         keycache_set_reload (1);  
                     return TRUE;  
                 }  
                 return TRUE;  
             }  
             listview_get_item_text (lv, idx, 4, keyid, DIM (keyid)-1);  
             rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);  
             if (!rc)  
                 keycache_update (0, keyid);  
479              return TRUE;              return TRUE;
480    
481          case IDC_KEYSIG_SIGPROPS:          case IDC_KEYSIG_SIGPROPS:

Legend:
Removed from v.42  
changed lines
  Added in v.141

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26