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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26