/[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 13 by twoaday, Mon Apr 25 07:15:30 2005 UTC revision 225 by twoaday, Tue Jun 6 13:37:59 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   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
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.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
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
21  #include <windows.h>  #include <config.h>
22  #include <commctrl.h>  #endif
23  #include <time.h>  
24    #include <windows.h>
25  #include "../resource.h"  #include <commctrl.h>
26  #include "wptGPG.h"  #include <time.h>
27  #include "wptCommonCtl.h"  
28  #include "wptContext.h" /* for passphrase_s */  #include "resource.h"
29  #include "wptDlgs.h"  #include "wptGPG.h"
30  #include "wptW32API.h"  #include "wptCommonCtl.h"
31  #include "wptNLS.h"  #include "wptContext.h" /* for passphrase_s */
32  #include "wptKeyList.h"  #include "wptDlgs.h"
33  #include "wptKeyserver.h"  #include "wptW32API.h"
34  #include "wptUTF8.h"  #include "wptNLS.h"
35  #include "wptTypes.h"  #include "wptKeylist.h"
36  #include "wptVersion.h"  #include "wptKeyserver.h"
37  #include "wptErrors.h"  #include "wptUTF8.h"
38    #include "wptTypes.h"
39  static subclass_s siglist_proc;  #include "wptVersion.h"
40    #include "wptErrors.h"
41    #include "wptKeyEdit.h"
42  static int inline  
43  is_sig (listview_ctrl_t lv, int pos)  static subclass_s siglist_proc;
44  {  
45      char tmpbuf[256];  
46    /* Return -1 if the selected item is a signature. */
47      if (pos == -1)  static int
48          pos = listview_get_curr_pos (lv);  is_sig (listview_ctrl_t lv, int pos)
49      listview_get_item_text (lv, pos, 0, tmpbuf, 200);  {
50      if (*tmpbuf == ' ')      char tmpbuf[200];
51          return -1;  
52      return 0;      if (pos == -1)
53  }          pos = listview_get_curr_pos (lv);
54        if (pos == -1)
55            return 0;
56  static int      listview_get_item_text (lv, pos, SL_COL_UID, tmpbuf, sizeof (tmpbuf)-1);
57  do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key)      if (*tmpbuf == ' ')
58  {          return -1;
59      int pos, npos, id;      return 0;
60      int signo=0, uidno=0;  }
61      gpgme_ctx_t ctx;  
62      gpgme_editkey_t ek;  
63      gpgme_error_t rc;  /* Delete the selected signature from list view @lv. The
64       key is given in @key. */
65      npos = pos = listview_get_curr_pos (lv);  static int
66      if (!is_sig (lv, -1))  do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key)
67          return -1;  {
68      while (pos > 0 && is_sig (lv, pos))      gpgme_error_t err;
69      {      GpgKeyEdit *ke;
70          signo++;      char keyid[32];
71          pos--;      int pos, npos, id, is_selfsig=0;
72      }      int signo=0, uidno=0;
73      pos = npos;  
74      while (npos > 0)      npos = pos = listview_get_curr_pos (lv);
75      {      if (!is_sig (lv, -1))
76          if (!is_sig (lv, npos))          return -1;
77              uidno++;      listview_get_item_text (lv, pos, SL_COL_KEYID, keyid, sizeof (keyid)-1);
78          npos--;      if (!strncmp (key->keyid, keyid+2, 8))
79      }          is_selfsig = 1;
80      uidno++;      
81      id = log_box(_("Key Manager"), MB_YESNO,      while (pos > 0 && is_sig (lv, pos)) {
82                    _("Are you really sure you want to delete this signature from\n"          signo++;
83                      "  \"%s\""), key->uid);          pos--;
84      if (id == IDNO)      }
85          return 0;      pos = npos;
86      rc = gpgme_new (&ctx);      while (npos > 0) {
87      if (rc)          if (!is_sig (lv, npos))
88          BUG (0);              uidno++;
89      rc = gpgme_editkey_new (&ek);          npos--;
90      if (rc)      }
91          BUG (0);      uidno++;
92      gpgme_editkey_delsig_set (ek, uidno, signo);  
93      gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_DELSIG);      /* XXX: do not allow to delete the self signature */
94      rc = gpgme_op_editkey (ctx, key->keyid);      id = log_box (_("Key Manager"), is_selfsig? MB_WARN_ASK : MB_QUEST_ASK,
95      if (rc)                    _("Are you really sure you want to delete this %s from\n\n"
96          msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR);                    "  \"%s\""), is_selfsig? _("self signature") : _("signature"),
97      else                    key->uid);
98          listview_del_item (lv, pos);      if (id == IDNO)
99      gpgme_release (ctx);          return 0;
100      gpgme_editkey_release (ek);  
101      return 0;      ke = new GpgKeyEdit (key->keyid);
102  }      if (!ke)
103            BUG (NULL);    
104        err = ke->delUseridSignature (uidno, signo);
105  static BOOL CALLBACK      if (err)
106  sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR);
107  {      else
108      static listview_ctrl_t lv;          listview_del_item (lv, pos);
109      char tmpbuf[256];      delete ke;
110      int n;      if (!err)
111      struct {          key->update = 1;
112          unsigned int exportable:1;      return err? -1 : 0;
113          unsigned int expired:1;  }
114          unsigned int nrev:1;  
115          unsigned int rev:1;  
116          const char * alg;  /* Dialog box procedure to display the signature properties. */
117          int _class;  BOOL CALLBACK
118      } ctx;  sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
119      const char * fmt_templ = "%s %s signature";  {
120        gpgme_key_sig_t ks;
121      switch (msg)      winpt_key_s issuer;
122      {      char tmpbuf[256];
123      case WM_SYSCOMMAND:      static struct {
124          if (LOWORD (wparam) == SC_CLOSE)          unsigned int exportable:1;
125              EndDialog (dlg, TRUE);          unsigned int expired:1;
126          return FALSE;          unsigned int nrev:1;
127            unsigned int rev:1;
128      case WM_INITDIALOG:          const char *alg;
129          lv = (listview_ctrl_t)lparam;          int _class;
130          if (!lv)      } ctx;
131              dlg_fatal_error (dlg, "could not get dialog param");      const char *fmt_templ = _("%s %s signature");
132          memset (&ctx, 0, sizeof ctx);      const char *s;
133          n = listview_get_curr_pos (lv);  
134          listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1);      switch (msg) {
135          if (!strstr (tmpbuf, "L"))      case WM_INITDIALOG:
136              ctx.exportable = 1;          ks = (gpgme_key_sig_t)lparam;
137          ctx._class = atoi (tmpbuf);          if (!ks)
138          if (ctx._class == 0)              BUG (0);
139              ctx._class = 10;          SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
140          else if (ctx._class < 10)          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
141              ctx._class += 10;          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
142          listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1);          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
143          if (strstr (tmpbuf, "DSA"))                  SetDlgItemText (dlg, IDC_SIGPROPS_CLASSINF, _("Class"));
144              ctx.alg = "DSA";          SetDlgItemText (dlg, IDC_SIGPROPS_EXPSTR, _("Expire date"));
145          else if (strstr (tmpbuf, "RSA"))          SetDlgItemText (dlg, IDC_SIGPROPS_KEYINF, _("Issuer key"));
146              ctx.alg = "RSA";          SetDlgItemText (dlg, IDC_SIGPROPS_KEYIDINF, _("Issuer key ID"));
147          else          SetDlgItemText (dlg, IDC_SIGPROPS_POLICINF, _("Policy URL"));
148              ctx.alg = "ELG";          SetWindowText (dlg, _("Signature Properties"));
149          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,          
150                     ctx.exportable? "Exportable" : "Non-exportable", ctx.alg);          memset (&ctx, 0, sizeof ctx);
151          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);          ctx._class = ks->sig_class;
152          listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);          if (ctx._class == 0)
153          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);              ctx._class = 16;    
154          SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);          ctx._class -= 6;
155          if (ctx.exportable)          if (ks->pubkey_algo == GPGME_PK_DSA)
156              CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);              ctx.alg = "DSA";
157          listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1);          else if (ks->pubkey_algo == GPGME_PK_RSA)
158          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);              ctx.alg = "RSA";
159          tmpbuf[0] = 0;          else
160          listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);              ctx.alg = "ELG";
161          if (strlen (tmpbuf) == 0) {          ctx.exportable = ks->exportable;
162              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
163              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);                     ctx.exportable? _("Exportable") : _("Non-exportable"),
164          }                     ctx.alg);
165          else {          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
166              SYSTEMTIME st;          
167              struct tm * tm;          _snprintf (tmpbuf, DIM (tmpbuf)-1, "0x%s", ks->keyid+8);
168              time_t t = time (NULL);          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);
169            SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);
170              memset (&st, 0, sizeof st);          if (ctx.exportable)
171              st.wYear = atoi (tmpbuf);              CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
172              st.wMonth = atoi (tmpbuf+5);          memset (&issuer, 0, sizeof (issuer));
173              st.wDay = atoi (tmpbuf+8);          if (!winpt_get_pubkey (ks->keyid+8, &issuer))
174              DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE),              s = issuer.ext->uids->uid;
175                                      GDT_VALID, &st);          else
176                s = _("  user ID not found");
177              tm = localtime (&t);          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, s);
178              tm->tm_mon++;          if (ks->expires == 0) {
179              tm->tm_year += 1900;              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
180              if (tm->tm_year > st.wYear)              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
181                  ctx.expired = 1;          }
182              else if (tm->tm_mon > st.wMonth)          else {
183                  ctx.expired = 1;              SYSTEMTIME st;
184              if (ctx.expired)              struct tm *tm;
185                  CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED);              time_t now = time (NULL);
186          }              time_t tmp = ks->expires;
187          SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));  
188          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));              tm = localtime (&tmp);
189          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));              memset (&st, 0, sizeof st);
190          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));              st.wYear = tm->tm_year+1900;
191          SetForegroundWindow (dlg);              st.wMonth = tm->tm_mon+1;
192          center_window (dlg);              st.wDay = tm->tm_mday;
193          return TRUE;              DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE),
194                                        GDT_VALID, &st);
195      case WM_COMMAND:  
196          switch (LOWORD (wparam)) {              if (now > ks->expires)
197          case IDOK:                  ctx.expired = 1;
198              EndDialog (dlg, TRUE);              if (ctx.expired)
199              break;                  CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED);
200          }          }
201      }          /* XXX (gpgme): \r at the end of the notation value. */
202            if (ks->notations && !ks->notations->name && ks->notations->value)
203      return FALSE;              SetDlgItemText (dlg, IDC_SIGPROPS_POLIC, ks->notations->value);
204  }  
205            SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
206            SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
207  static BOOL CALLBACK          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
208  subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
209  {          SetWindowText (dlg, _("Signature Properties"));
210      listview_ctrl_t lv;          SetForegroundWindow (dlg);
211      winpt_key_t key;          center_window (dlg, NULL);
212            return TRUE;
213      switch (msg)  
214      {      case WM_COMMAND:
215      case WM_KEYUP:          if (HIWORD (wparam) == BN_CLICKED) {
216          int virt_key = (int)wparam;              /* Code to prevent the user changes the check buttons. */
217          key = (winpt_key_t)siglist_proc.opaque;              switch (LOWORD (wparam)) {
218          lv = key->callback.ctl;              case IDC_SIGPROPS_EXP:
219          if (virt_key == VK_SPACE)                  CheckDlgButton (dlg, IDC_SIGPROPS_EXP,
220          {                                   ctx.exportable? BST_CHECKED : BST_UNCHECKED);
221              if (is_sig (lv, -1))                  return TRUE;
222                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,  
223                                  sigprops_dlg_proc, (LPARAM)lv);              case IDC_SIGPROPS_EXPIRED:
224          }                  CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED,
225          else if (virt_key == VK_DELETE)                                  ctx.expired? BST_CHECKED : BST_UNCHECKED);
226              do_delsig (dlg, lv, key);                  return TRUE;
227          break;  
228      }              case IDC_SIGPROPS_REV:
229      return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);                  CheckDlgButton (dlg, IDC_SIGPROPS_REV,
230  }                                  ctx.rev? BST_CHECKED : BST_UNCHECKED);
231                    return TRUE;
232    
233  static int              case IDC_SIGPROPS_NREV:
234  check_for_missing_keys (listview_ctrl_t lv)                  CheckDlgButton (dlg, IDC_SIGPROPS_NREV,
235  {                                  ctx.nrev? BST_CHECKED : BST_UNCHECKED);
236      int i, n;                  return TRUE;
237      char id[128];              }
238                }
239      n = listview_count_items( lv, 0 );  
240      for( i = 0; i < n; i++ ) {          switch (LOWORD (wparam)) {
241          listview_get_item_text( lv, i, 1, id, sizeof id - 1 );          case IDOK:
242          if( !strncmp( id, "NOKEY", 5 ) )              EndDialog (dlg, TRUE);
243              return 1;              break;
244      }  
245                case IDCANCEL:
246      return 0;              EndDialog (dlg, FALSE);
247  } /* check_for_missing_keys */              break;
248            }
249        }
250  static int  
251  recv_missing_keys (HWND dlg, listview_ctrl_t lv)      return FALSE;
252  {  }
253      int i, n, rc;  
254      char id[128], keyid[18+1];  
255        /* Subclass window procedure for the list view. */
256      n = listview_count_items (lv, 0);  static BOOL CALLBACK
257      for( i = 0; i < n; i++ ) {  subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
258          listview_get_item_text( lv, i, 1, id, sizeof id - 1 );  {
259          if( !strncmp( id, "NOKEY", 5 ) ) {      listview_ctrl_t lv;
260              listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 );      winpt_key_t key;
261              rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 );      gpgme_key_sig_t ks;
262              if( rc )                
263                  break;      switch (msg) {
264          }      case WM_KEYUP:
265      }          int virt_key = (int)wparam;
266                key = (winpt_key_t)siglist_proc.opaque;
267      return rc;          lv = key->callback.ctl;
268  } /* recv_missing_keys */          if (virt_key == VK_SPACE) {
269                if (is_sig (lv, -1)) {
270                    ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv));
271  static void                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
272  do_create_popup (HWND dlg)                                  sigprops_dlg_proc, (LPARAM)ks);
273  {              }
274      HMENU hm, sm;          }
275      POINT p;          else if (virt_key == VK_DELETE)
276                do_delsig (dlg, lv, key);
277      GetCursorPos (&p);          break;
278      hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));      }
279      sm = GetSubMenu (hm, 0);      return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);
280    }
281      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);  
282    
283      DestroyMenu (hm);  /* Return 1 if the list view @lv contains non-available keys. */
284      DestroyMenu (sm);  static int
285  }  check_for_missing_keys (listview_ctrl_t lv)
286    {
287        int i, n;
288  static void      char id[128];
289  do_load_keyprops (HWND dlg, listview_ctrl_t lv)      
290  {      n = listview_count_items (lv, 0);
291      winpt_key_s k;      for (i = 0; i < n; i++) {
292      gpgme_key_t key;          listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
293      char keyid[32] = {0};          if (!strncmp (id, "NOKEY", 5))
294      char status[64] = {0}, creation[64] = {0};              return 1;
295      int n = listview_get_curr_pos (lv);      }
296        
297      listview_get_item_text (lv, n, 1, status, DIM (status)-1);      return 0;
298      listview_get_item_text (lv, n, 3, creation, DIM (creation)-1);  }
299      listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1);  
300      if (!strcmp (status, "NOKEY")) {  
301          msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."),  /* Receive all missing keys marked in the list @lv. */
302                   _("Key Manager"), MB_INFO);  static int
303          return;  recv_missing_keys (HWND dlg, listview_ctrl_t lv)
304      }  {
305            char id[128], keyid[18+1];
306      if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {      int i, n, cnt=0;
307          if (strlen (creation) > 0)  
308              msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);      i = msg_box (dlg, _("Really receive all missing keys?"),
309          return;                   _("Key Manager"), MB_YESNO|MB_INFO);
310      }      if (i == IDNO)
311      memset (&k, 0, sizeof k);          return 0;
312      k.keyid = keyid;      
313      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,      n = listview_count_items (lv, 0);
314                      keyprops_dlg_proc, (LPARAM)&k);      for (i = 0; i < n; i++) {
315  }          listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
316            if (!strncmp (id, "NOKEY", 5)) {
317                listview_get_item_text (lv, i, SL_COL_KEYID,
318  BOOL CALLBACK                                      keyid, sizeof (keyid) -1);
319  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)              if (!hkp_recv_key (dlg, default_keyserver,
320  {                                 default_keyserver_port, keyid, 0, 0)) {
321      static listview_ctrl_t lv = NULL;                  keycache_update (0, keyid);
322      struct winpt_key_s *k;                  cnt++;
323      char inf[384], keyid[18+1];                  }
324      int idx = 0, id, rc;              else
325      HWND sl;                  break;
326                }
327      switch( msg ) {      }
328      case WM_INITDIALOG:      return cnt;
329          k = (winpt_key_t) lparam;  }
330          if (!k)  
331              BUG (0);  
332          if( k->uid )  /* Create a mini popup with available choices. */
333              _snprintf( inf, sizeof inf - 1, _("Signature List for \"%s\""), k->uid );  static void
334          SetWindowText( dlg, inf );  do_create_popup (HWND dlg)
335          #ifndef LANG_DE  {
336          SetDlgItemText( dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key") );      HMENU hm, sm;
337          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));      POINT p;
338          #endif  
339          lv = siglist_load( GetDlgItem( dlg, IDC_KEYSIG_LIST ), k->keyid );      GetCursorPos (&p);
340          if( !check_for_missing_keys( lv ) )      hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));
341              EnableWindow( GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE );      sm = GetSubMenu (hm, 0);
342          k->callback.ctl = lv;      set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties"));
343          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);      set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties"));
344          siglist_proc.dlg = dlg;      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
345          siglist_proc.opaque = k;      DestroyMenu (hm);
346          siglist_proc.current = (WNDPROC)subclass_dlg_proc;      DestroyMenu (sm);
347          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);  }
348          if (siglist_proc.old)  
349          {  
350              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  /* Fetch a single key and extract the keyid from the listview
351              {     entry at the pos @idx. */
352                  msg_box (dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR);  static int
353                  BUG (0);  recv_single_key (HWND dlg, listview_ctrl_t lv, int idx)
354              }  {
355          }      char keyid[32];
356          SetForegroundWindow (dlg);      int rc;
357          center_window (dlg);  
358          return TRUE;      listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1);      
359                rc = hkp_recv_key (dlg, default_keyserver,
360      case WM_DESTROY:                         default_keyserver_port, keyid, 0, 0);
361          if ( lv ) {      if (!rc)
362              siglist_delete( lv );          keycache_update (0, keyid);
363              lv = NULL;      return rc;
364          }  }
365          return FALSE;  
366            
367      case WM_SYSCOMMAND:  /* Load the key property dialog with the selected key from @lv. */
368          if( LOWORD ( wparam ) == SC_CLOSE )  static void
369              EndDialog( dlg, TRUE );  do_load_keyprops (HWND dlg, listview_ctrl_t lv)
370          return FALSE;  {
371        winpt_key_s k;
372      case WM_NOTIFY:      char keyid[32] = {0};
373          NMHDR * notify;      char status[64] = {0}, creation[64] = {0};
374                int n = listview_get_curr_pos (lv);
375          notify = (NMHDR *)lparam;  
376          if( notify && notify->code == NM_DBLCLK      listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1);
377              && notify->idFrom == IDC_KEYSIG_LIST )      listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1);
378              do_load_keyprops (dlg, lv);      listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1);
379          if (notify && notify->code == NM_RCLICK &&      if (!strcmp (status, "NOKEY")) {
380              notify->idFrom == IDC_KEYSIG_LIST)          int id = msg_box (dlg, _("Key not found in keyring, do you want to fetch it from the keyserver?"),
381              do_create_popup (dlg);                            _("Key Manager"), MB_QUEST_ASK);
382          break;          if (id == IDNO)
383                        return;
384      case WM_COMMAND:          if (recv_single_key (dlg, lv, n))              
385          switch ( LOWORD( wparam ) ) {              return;
386        }
387          case ID_SIGCTX_KEYPROPS:      
388              do_load_keyprops (dlg, lv);      memset (&k, 0, sizeof k);
389              break;      if ((strlen (keyid) < 3 || winpt_get_pubkey (keyid, &k))) {
390            if (strlen (creation) > 0)
391          case ID_SIGCTX_PROPS:              msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);
392              if (is_sig (lv, -1))          return;
393                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,      }
394                                  sigprops_dlg_proc, (LPARAM)lv);      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
395              break;                      keyprops_dlg_proc, (LPARAM)&k);
396    }
397          case IDC_KEYSIG_RECVKEY:  
398              idx = listview_get_curr_pos( lv );  
399              if( idx == -1 ) {  /* Dialog box procedure to list signatures. */
400                  id = msg_box( dlg, _("Really receive all missing keys?"),  BOOL CALLBACK
401                                  _("Key Manager"), MB_YESNO|MB_INFO );  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
402                  if( id == IDYES ) {  {
403                      rc = recv_missing_keys( dlg, lv );      static listview_ctrl_t lv = NULL;
404                      if( !rc )      static struct winpt_key_s *k;
405                          keycache_set_reload( 1 );      gpgme_key_sig_t ks;
406                      return TRUE;      HWND sl;
407                  }      char inf[384];
408                  return FALSE;      int idx = 0;    
409              }      
410              listview_get_item_text (lv, idx, 4, keyid, sizeof keyid - 1);      switch (msg) {
411              rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);      case WM_INITDIALOG:
412              if (!rc)          k = (winpt_key_t) lparam;
413                  keycache_set_reload (1);          if (!k)
414              return TRUE;              BUG (0);
415            if (k->uid)
416          case IDC_KEYSIG_SIGPROPS:              _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
417              if (is_sig (lv, -1))          SetWindowText (dlg, inf);
418                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,          SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
419                                  sigprops_dlg_proc, (LPARAM)lv);          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
420              return TRUE;  
421                        lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);
422          case IDOK:          if (!check_for_missing_keys (lv))
423              EndDialog (dlg, TRUE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE);
424              return TRUE;          EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE);
425          }          k->callback.ctl = lv;
426          break;          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);
427      }          siglist_proc.dlg = dlg;
428      return FALSE;          siglist_proc.opaque = k;
429  } /* keysig_dlg_proc */          siglist_proc.current = (WNDPROC)subclass_dlg_proc;
430            siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);
431            if (siglist_proc.old) {
432                if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  {
433                    msg_box (dlg, "Could not set keylist window procedure.",
434                             _("Key Manager"), MB_ERR);
435                    BUG (0);
436                }
437            }
438            SetForegroundWindow (dlg);
439            center_window (dlg, NULL);
440            return TRUE;
441            
442        case WM_DESTROY:
443            if (lv) {
444                siglist_delete (lv);
445                lv = NULL;
446            }
447            return FALSE;
448    
449        case WM_NOTIFY:
450            NMHDR *notify;
451            
452            notify = (NMHDR *)lparam;
453            if (!notify)
454                return FALSE;
455            if (notify->code == NM_DBLCLK &&
456                notify->idFrom == IDC_KEYSIG_LIST)
457                do_load_keyprops (dlg, lv);
458            if (notify->code == NM_RCLICK &&
459                notify->idFrom == IDC_KEYSIG_LIST &&
460                is_sig (lv, -1))
461                do_create_popup (dlg);
462            if (notify->code == LVN_ITEMCHANGED &&
463                ((LPNMLISTVIEW)lparam)->uNewState) {
464                idx = listview_get_curr_pos (lv);
465                listview_get_item_text (lv, idx, SL_COL_VALID, inf, DIM (inf)-1);
466                EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY),
467                              strcmp (inf, "NOKEY") == 0? TRUE: FALSE);
468                EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS),
469                              is_sig (lv, -1)? TRUE : FALSE);
470            }
471            if (notify->code == LVN_COLUMNCLICK) {
472                NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
473                int sortby = 0;
474                switch (nft->iSubItem) {
475                //case 0:  sortby = KEY_SORT_USERID; break;
476                case 1: sortby = KEY_SORT_VALIDITY; break;
477                case 2: sortby = SIG_SORT_CLASS; break;
478                case 3: sortby = KEY_SORT_CREATED; break;
479                case 4: sortby = KEY_SORT_KEYID; break;
480                case 5: sortby = SIG_SORT_EXPIRE; break;
481                case 6: sortby = KEY_SORT_ALGO; break;
482                default: return TRUE;
483                }
484                siglist_sort (lv, sortby);
485            }
486            break;
487            
488        case WM_COMMAND:
489            switch (LOWORD (wparam)) {
490            case ID_SIGCTX_KEYPROPS:
491                do_load_keyprops (dlg, lv);
492                break;
493    
494            case ID_SIGCTX_PROPS:
495                if (is_sig (lv, -1)) {
496                    ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv));
497                    DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
498                                    sigprops_dlg_proc, (LPARAM)ks);
499                }
500                break;
501    
502            case IDC_KEYSIG_RECVKEY:
503                idx = listview_get_curr_pos (lv);
504                if (idx == -1)
505                    recv_missing_keys (dlg, lv);
506                else
507                    recv_single_key (dlg, lv, idx);
508                return TRUE;
509    
510            case IDC_KEYSIG_SIGPROPS:
511                if (is_sig (lv, -1)) {
512                    ks = ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv));
513                    DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
514                                    sigprops_dlg_proc, (LPARAM)ks);
515                }
516                return TRUE;
517                
518            case IDCANCEL:
519                EndDialog (dlg, FALSE);
520                return TRUE;
521    
522            case IDOK:
523                EndDialog (dlg, TRUE);
524                return TRUE;
525            }
526            break;
527        }
528        return FALSE;
529    }

Legend:
Removed from v.13  
changed lines
  Added in v.225

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26