/[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 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          {          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
163              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);                     ctx.exportable? _("Exportable") : _("Non-exportable"),
164              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);                     ctx.alg);
165          }          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
166          else          
167          {          _snprintf (tmpbuf, DIM (tmpbuf)-1, "0x%s", ks->keyid+8);
168              SYSTEMTIME st;          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);
169              struct tm * tm;          SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);
170              time_t t = time (NULL);          if (ctx.exportable)
171                CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
172              memset (&st, 0, sizeof st);          memset (&issuer, 0, sizeof (issuer));
173              st.wYear = atoi (tmpbuf);          if (!winpt_get_pubkey (ks->keyid+8, &issuer))
174              st.wMonth = atoi (tmpbuf+5);              s = issuer.ext->uids->uid;
175              st.wDay = atoi (tmpbuf+8);          else
176              DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE),              s = _("  user ID not found");
177                                      GDT_VALID, &st);          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, s);
178            if (ks->expires == 0) {
179              tm = localtime (&t);              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
180              tm->tm_mon++;              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
181              tm->tm_year += 1900;          }
182              if (tm->tm_year > st.wYear)          else {
183                  ctx.expired = 1;              SYSTEMTIME st;
184              else if (tm->tm_mon > st.wMonth)              struct tm *tm;
185                  ctx.expired = 1;              time_t now = time (NULL);
186              if (ctx.expired)              time_t tmp = ks->expires;
187                  CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED);  
188          }              tm = localtime (&tmp);
189          SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));              memset (&st, 0, sizeof st);
190          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));              st.wYear = tm->tm_year+1900;
191          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));              st.wMonth = tm->tm_mon+1;
192          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));              st.wDay = tm->tm_mday;
193          SetForegroundWindow (dlg);              DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE),
194          center_window (dlg);                                      GDT_VALID, &st);
195          return TRUE;  
196                if (now > ks->expires)
197      case WM_COMMAND:                  ctx.expired = 1;
198          switch (LOWORD (wparam))              if (ctx.expired)
199          {                  CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED);
200          case IDOK:          }
201              EndDialog (dlg, TRUE);          /* XXX (gpgme): \r at the end of the notation value. */
202              break;          if (ks->notations && !ks->notations->name && ks->notations->value)
203          }              SetDlgItemText (dlg, IDC_SIGPROPS_POLIC, ks->notations->value);
204      }  
205            SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
206      return FALSE;          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
207  }          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
208            SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
209            SetWindowText (dlg, _("Signature Properties"));
210  static BOOL CALLBACK          SetForegroundWindow (dlg);
211  subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          center_window (dlg, NULL);
212  {          return TRUE;
213      listview_ctrl_t lv;  
214      winpt_key_t key;      case WM_COMMAND:
215            if (HIWORD (wparam) == BN_CLICKED) {
216      switch (msg)              /* Code to prevent the user changes the check buttons. */
217      {              switch (LOWORD (wparam)) {
218      case WM_KEYUP:              case IDC_SIGPROPS_EXP:
219          int virt_key = (int)wparam;                  CheckDlgButton (dlg, IDC_SIGPROPS_EXP,
220          key = (winpt_key_t)siglist_proc.opaque;                                   ctx.exportable? BST_CHECKED : BST_UNCHECKED);
221          lv = key->callback.ctl;                  return TRUE;
222          if (virt_key == VK_SPACE)  
223          {              case IDC_SIGPROPS_EXPIRED:
224              if (is_sig (lv, -1))                  CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED,
225                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,                                  ctx.expired? BST_CHECKED : BST_UNCHECKED);
226                                  sigprops_dlg_proc, (LPARAM)lv);                  return TRUE;
227          }  
228          else if (virt_key == VK_DELETE)              case IDC_SIGPROPS_REV:
229              do_delsig (dlg, lv, key);                  CheckDlgButton (dlg, IDC_SIGPROPS_REV,
230          break;                                  ctx.rev? BST_CHECKED : BST_UNCHECKED);
231      }                  return TRUE;
232      return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);  
233  }              case IDC_SIGPROPS_NREV:
234                    CheckDlgButton (dlg, IDC_SIGPROPS_NREV,
235                                    ctx.nrev? BST_CHECKED : BST_UNCHECKED);
236  static int                  return TRUE;
237  check_for_missing_keys (listview_ctrl_t lv)              }
238  {          }
239      int i, n;  
240      char id[128];          switch (LOWORD (wparam)) {
241                case IDOK:
242      n = listview_count_items( lv, 0 );              EndDialog (dlg, TRUE);
243      for( i = 0; i < n; i++ ) {              break;
244          listview_get_item_text( lv, i, 1, id, sizeof id - 1 );  
245          if( !strncmp( id, "NOKEY", 5 ) )          case IDCANCEL:
246              return 1;              EndDialog (dlg, FALSE);
247      }              break;
248                }
249      return 0;      }
250  } /* check_for_missing_keys */  
251        return FALSE;
252    }
253  static int  
254  recv_missing_keys (HWND dlg, listview_ctrl_t lv)  
255  {  /* Subclass window procedure for the list view. */
256      int i, n, rc;  static BOOL CALLBACK
257      char id[128], keyid[18+1];  subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
258        {
259      n = listview_count_items (lv, 0);      listview_ctrl_t lv;
260      for( i = 0; i < n; i++ ) {      winpt_key_t key;
261          listview_get_item_text( lv, i, 1, id, sizeof id - 1 );      gpgme_key_sig_t ks;
262          if( !strncmp( id, "NOKEY", 5 ) ) {  
263              listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 );      switch (msg) {
264              rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 );      case WM_KEYUP:
265              if( rc )                        int virt_key = (int)wparam;
266                  break;          key = (winpt_key_t)siglist_proc.opaque;
267          }          lv = key->callback.ctl;
268      }          if (virt_key == VK_SPACE) {
269                    if (is_sig (lv, -1)) {
270      return rc;                  ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv));
271  } /* recv_missing_keys */                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
272                                    sigprops_dlg_proc, (LPARAM)ks);
273                }
274  static void          }
275  do_create_popup (HWND dlg)          else if (virt_key == VK_DELETE)
276  {              do_delsig (dlg, lv, key);
277      HMENU hm, sm;          break;
278      POINT p;      }
279        return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);
280      GetCursorPos (&p);  }
281      hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));  
282      sm = GetSubMenu (hm, 0);  
283    /* Return 1 if the list view @lv contains non-available keys. */
284      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);  static int
285    check_for_missing_keys (listview_ctrl_t lv)
286      DestroyMenu (hm);  {
287      DestroyMenu (sm);      int i, n;
288  }      char id[128];
289        
290        n = listview_count_items (lv, 0);
291  static void      for (i = 0; i < n; i++) {
292  do_load_keyprops (HWND dlg, listview_ctrl_t lv)          listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
293  {          if (!strncmp (id, "NOKEY", 5))
294      winpt_key_s k;              return 1;
295      gpgme_key_t key;      }
296      char keyid[32] = {0};      
297      char status[64] = {0}, creation[64] = {0};      return 0;
298      int n = listview_get_curr_pos (lv);  }
299    
300      listview_get_item_text (lv, n, 1, status, DIM (status)-1);  
301      listview_get_item_text (lv, n, 3, creation, DIM (creation)-1);  /* Receive all missing keys marked in the list @lv. */
302      listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1);  static int
303      if (!strcmp (status, "NOKEY")) {  recv_missing_keys (HWND dlg, listview_ctrl_t lv)
304          msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."),  {
305                   _("Key Manager"), MB_INFO);      char id[128], keyid[18+1];
306          return;      int i, n, cnt=0;
307      }  
308            i = msg_box (dlg, _("Really receive all missing keys?"),
309      if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {                   _("Key Manager"), MB_YESNO|MB_INFO);
310          if (strlen (creation) > 0)      if (i == IDNO)
311              msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);          return 0;
312          return;      
313      }      n = listview_count_items (lv, 0);
314      memset (&k, 0, sizeof k);      for (i = 0; i < n; i++) {
315      k.keyid = keyid;          listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
316      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,          if (!strncmp (id, "NOKEY", 5)) {
317                      keyprops_dlg_proc, (LPARAM)&k);              listview_get_item_text (lv, i, SL_COL_KEYID,
318  }                                      keyid, sizeof (keyid) -1);
319                if (!hkp_recv_key (dlg, default_keyserver,
320                                   default_keyserver_port, keyid, 0, 0)) {
321  BOOL CALLBACK                  keycache_update (0, keyid);
322  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)                  cnt++;
323  {              }
324      static listview_ctrl_t lv = NULL;              else
325      struct winpt_key_s *k;                  break;
326      char inf[384], keyid[18+1];              }
327      int idx = 0, id, rc;      }
328      HWND sl;      return cnt;
329        }
330      switch( msg ) {  
331      case WM_INITDIALOG:  
332          k = (winpt_key_t) lparam;  /* Create a mini popup with available choices. */
333          if (!k)  static void
334              BUG (0);  do_create_popup (HWND dlg)
335          if( k->uid )  {
336              _snprintf( inf, sizeof inf - 1, _("Signature List for \"%s\""), k->uid );      HMENU hm, sm;
337          SetWindowText( dlg, inf );      POINT p;
338          #ifndef LANG_DE  
339          SetDlgItemText( dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key") );      GetCursorPos (&p);
340          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));      hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));
341          #endif      sm = GetSubMenu (hm, 0);
342          lv = siglist_load( GetDlgItem( dlg, IDC_KEYSIG_LIST ), k->keyid );      set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties"));
343          if( !check_for_missing_keys( lv ) )      set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties"));
344              EnableWindow( GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE );      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
345          k->callback.ctl = lv;      DestroyMenu (hm);
346          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);      DestroyMenu (sm);
347          siglist_proc.dlg = dlg;  }
348          siglist_proc.opaque = k;  
349          siglist_proc.current = (WNDPROC)subclass_dlg_proc;  
350          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);  /* Fetch a single key and extract the keyid from the listview
351          if (siglist_proc.old)     entry at the pos @idx. */
352          {  static int
353              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  recv_single_key (HWND dlg, listview_ctrl_t lv, int idx)
354              {  {
355                  msg_box (dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR);      char keyid[32];
356                  BUG (0);      int rc;
357              }  
358          }      listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1);      
359          SetForegroundWindow (dlg);      rc = hkp_recv_key (dlg, default_keyserver,
360          center_window (dlg);                         default_keyserver_port, keyid, 0, 0);
361          return TRUE;      if (!rc)
362                    keycache_update (0, keyid);
363      case WM_DESTROY:      return rc;
364          if ( lv ) {  }
365              siglist_delete( lv );  
366              lv = NULL;  
367          }  /* Load the key property dialog with the selected key from @lv. */
368          return FALSE;  static void
369            do_load_keyprops (HWND dlg, listview_ctrl_t lv)
370      case WM_SYSCOMMAND:  {
371          if( LOWORD ( wparam ) == SC_CLOSE )      winpt_key_s k;
372              EndDialog( dlg, TRUE );      char keyid[32] = {0};
373          return FALSE;      char status[64] = {0}, creation[64] = {0};
374        int n = listview_get_curr_pos (lv);
375      case WM_NOTIFY:  
376          NMHDR * notify;      listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1);
377                listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1);
378          notify = (NMHDR *)lparam;      listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1);
379          if( notify && notify->code == NM_DBLCLK      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_load_keyprops (dlg, lv);                            _("Key Manager"), MB_QUEST_ASK);
382          if (notify && notify->code == NM_RCLICK &&          if (id == IDNO)
383              notify->idFrom == IDC_KEYSIG_LIST)              return;
384              do_create_popup (dlg);          if (recv_single_key (dlg, lv, n))              
385          break;              return;
386                }
387      case WM_COMMAND:      
388          switch ( LOWORD( wparam ) ) {      memset (&k, 0, sizeof k);
389        if ((strlen (keyid) < 3 || winpt_get_pubkey (keyid, &k))) {
390          case ID_SIGCTX_KEYPROPS:          if (strlen (creation) > 0)
391              do_load_keyprops (dlg, lv);              msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);
392              break;          return;
393        }
394          case ID_SIGCTX_PROPS:      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
395              if (is_sig (lv, -1))                      keyprops_dlg_proc, (LPARAM)&k);
396                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,  }
397                                  sigprops_dlg_proc, (LPARAM)lv);  
398              break;  
399    /* Dialog box procedure to list signatures. */
400          case IDC_KEYSIG_RECVKEY:  BOOL CALLBACK
401              idx = listview_get_curr_pos( lv );  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
402              if( idx == -1 ) {  {
403                  id = msg_box( dlg, _("Really receive all missing keys?"),      static listview_ctrl_t lv = NULL;
404                                  _("Key Manager"), MB_YESNO|MB_INFO );      static struct winpt_key_s *k;
405                  if( id == IDYES ) {      gpgme_key_sig_t ks;
406                      rc = recv_missing_keys( dlg, lv );      HWND sl;
407                      if( !rc )      char inf[384];
408                          keycache_set_reload( 1 );      int idx = 0;    
409                      return TRUE;      
410                  }      switch (msg) {
411                  return FALSE;      case WM_INITDIALOG:
412              }          k = (winpt_key_t) lparam;
413              listview_get_item_text (lv, idx, 4, keyid, sizeof keyid - 1);          if (!k)
414              rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);              BUG (0);
415              if (!rc)          if (k->uid)
416                  keycache_set_reload (1);              _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
417              return TRUE;          SetWindowText (dlg, inf);
418            SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
419          case IDC_KEYSIG_SIGPROPS:          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
420              if (is_sig (lv, -1))  
421                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,          lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);
422                                  sigprops_dlg_proc, (LPARAM)lv);          if (!check_for_missing_keys (lv))
423              return TRUE;              EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE);
424                        EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE);
425          case IDOK:          k->callback.ctl = lv;
426              EndDialog (dlg, TRUE);          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);
427              return TRUE;          siglist_proc.dlg = dlg;
428          }          siglist_proc.opaque = k;
429          break;          siglist_proc.current = (WNDPROC)subclass_dlg_proc;
430      }          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);
431      return FALSE;          if (siglist_proc.old) {
432  } /* keysig_dlg_proc */              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.2  
changed lines
  Added in v.225

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26