/[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 20 by twoaday, Wed Jul 27 11:17:22 2005 UTC revision 176 by twoaday, Mon Feb 13 09:38:03 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      key->update = 1; /*update*/      if (!ke)
102      return 0;          BUG (NULL);    
103  }      err = ke->delUseridSignature (uidno, signo);
104        if (err)
105            msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR);
106  static BOOL CALLBACK      else
107  sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          listview_del_item (lv, pos);
108  {      delete ke;
109      static listview_ctrl_t lv;      if (!err)
110      char tmpbuf[256];          key->update = 1;
111      int n;      return err? -1 : 0;
112      struct {  }
113          unsigned int exportable:1;  
114          unsigned int expired:1;  
115          unsigned int nrev:1;  /* Dialog box procedure to display the signature properties. */
116          unsigned int rev:1;  BOOL CALLBACK
117          const char * alg;  sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
118          int _class;  {
119      } ctx;      static gpgme_key_sig_t ks;
120      const char * fmt_templ = "%s %s signature";      gpgme_key_t issuer;
121        char tmpbuf[256];
122      switch (msg) {      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");  
132          memset (&ctx, 0, sizeof ctx);      switch (msg) {
133          n = listview_get_curr_pos (lv);      case WM_SYSCOMMAND:
134          listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1);          if (LOWORD (wparam) == SC_CLOSE)
135          if (!strstr (tmpbuf, "L"))              EndDialog (dlg, TRUE);
136              ctx.exportable = 1;          return FALSE;
137          ctx._class = atoi (tmpbuf);  
138          if (ctx._class == 0)      case WM_INITDIALOG:
139              ctx._class = 10;          SetWindowText (dlg, _("Signature Properties"));
140          else if (ctx._class < 10)          SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
141              ctx._class += 10;          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
142          listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1);          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
143          if (strstr (tmpbuf, "DSA"))                  SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
144              ctx.alg = "DSA";          SetDlgItemText (dlg, IDC_SIGPROPS_CLASSINF, _("Class"));
145          else if (strstr (tmpbuf, "RSA"))          SetDlgItemText (dlg, IDC_SIGPROPS_EXPSTR, _("Expire date"));
146              ctx.alg = "RSA";          SetDlgItemText (dlg, IDC_SIGPROPS_KEYINF, _("Issuer key"));
147          else          SetDlgItemText (dlg, IDC_SIGPROPS_KEYIDINF, _("Issuer key ID"));
148              ctx.alg = "ELG";          ks = (gpgme_key_sig_t)lparam;
149          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,          if (!ks)
150                     ctx.exportable? "Exportable" : "Non-exportable", ctx.alg);              BUG (0);
151          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);          memset (&ctx, 0, sizeof ctx);
152          listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);          ctx._class = ks->sig_class;
153          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);          if (ctx._class == 0)
154          SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);              ctx._class = 16;    
155          if (ctx.exportable)          ctx._class -= 6;
156              CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);          if (ks->pubkey_algo == GPGME_PK_DSA)
157          listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1);              ctx.alg = "DSA";
158          SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);          else if (ks->pubkey_algo == GPGME_PK_RSA)
159          tmpbuf[0] = 0;              ctx.alg = "RSA";
160          listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);          else
161          if (strlen (tmpbuf) == 0) {              ctx.alg = "ELG";
162              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);          ctx.exportable = ks->exportable;
163              ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);          _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
164          }                     ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg);
165          else {          SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
166              SYSTEMTIME st;          
167              struct tm * tm;          SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, ks->keyid+8);
168              time_t t = time (NULL);          SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);
169            if (ctx.exportable)
170              memset (&st, 0, sizeof st);              CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
171              st.wYear = atoi (tmpbuf);          if (!get_pubkey (ks->keyid+8, &issuer)) {
172              st.wMonth = atoi (tmpbuf+5);              char *uid = utf8_to_wincp2 (issuer->uids->uid);
173              st.wDay = atoi (tmpbuf+8);              SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, uid);
174              DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE),              safe_free (uid);
175                                      GDT_VALID, &st);          }
176            else
177              tm = localtime (&t);              SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, _("  user ID not found"));
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 t = 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;
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)) {              tm = localtime (&t);
197          case IDOK:              tm->tm_mon++;
198              EndDialog (dlg, TRUE);              tm->tm_year += 1900;
199              break;              if (tm->tm_year > st.wYear)
200          }                  ctx.expired = 1;
201      }              else if (tm->tm_mon > st.wMonth)
202                    ctx.expired = 1;
203      return FALSE;              if (ctx.expired)
204  }                  CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED);
205            }
206            SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
207  static BOOL CALLBACK          SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
208  subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
209  {          SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
210      listview_ctrl_t lv;          SetWindowText (dlg, _("Signature Properties"));
211      winpt_key_t key;          SetForegroundWindow (dlg);
212            center_window (dlg, NULL);
213      switch (msg) {          return TRUE;
214      case WM_KEYUP:  
215          int virt_key = (int)wparam;      case WM_COMMAND:
216          key = (winpt_key_t)siglist_proc.opaque;          switch (LOWORD (wparam)) {
217          lv = key->callback.ctl;          case IDOK:
218          if (virt_key == VK_SPACE) {              EndDialog (dlg, TRUE);
219              if (is_sig (lv, -1))              break;
220                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,  
221                                  sigprops_dlg_proc, (LPARAM)lv);          case IDCANCEL:
222          }              EndDialog (dlg, FALSE);
223          else if (virt_key == VK_DELETE)              break;
224              do_delsig (dlg, lv, key);          }
225          break;      }
226      }  
227      return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);      return FALSE;
228  }  }
229    
230    
231  static int  static BOOL CALLBACK
232  check_for_missing_keys (listview_ctrl_t lv)  subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
233  {  {
234      int i, n;      listview_ctrl_t lv;
235      char id[128];      winpt_key_t key;
236            gpgme_key_sig_t ks;
237      n = listview_count_items( lv, 0 );  
238      for( i = 0; i < n; i++ ) {      switch (msg) {
239          listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 );      case WM_KEYUP:
240          if( !strncmp( id, "NOKEY", 5 ) )          int virt_key = (int)wparam;
241              return 1;          key = (winpt_key_t)siglist_proc.opaque;
242      }          lv = key->callback.ctl;
243                if (virt_key == VK_SPACE) {
244      return 0;              if (is_sig (lv, -1)) {
245  } /* check_for_missing_keys */                  ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv));
246                    DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
247                                    sigprops_dlg_proc, (LPARAM)ks);
248  static int              }
249  recv_missing_keys (HWND dlg, listview_ctrl_t lv)          }
250  {          else if (virt_key == VK_DELETE)
251      int i, n, rc;              do_delsig (dlg, lv, key);
252      char id[128], keyid[18+1];          break;
253            }
254      n = listview_count_items (lv, 0);      return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);
255      for( i = 0; i < n; i++ ) {  }
256          listview_get_item_text( lv, i, 1, id, sizeof id - 1 );  
257          if( !strncmp( id, "NOKEY", 5 ) ) {  
258              listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 );  /* Return 1 if the list view @lv contains non-available keys. */
259              rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 );  static int
260              if( rc )                check_for_missing_keys (listview_ctrl_t lv)
261                  break;  {
262          }      int i, n;
263      }      char id[128];
264            
265      return rc;      n = listview_count_items( lv, 0 );
266  } /* recv_missing_keys */      for( i = 0; i < n; i++ ) {
267            listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
268            if (!strncmp (id, "NOKEY", 5))
269  static void              return 1;
270  do_create_popup (HWND dlg)      }
271  {      
272      HMENU hm, sm;      return 0;
273      POINT p;  }
274    
275      GetCursorPos (&p);  
276      hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));  /* Receive all missing keys marked in the list @lv. */
277      sm = GetSubMenu (hm, 0);  static int
278    recv_missing_keys (HWND dlg, listview_ctrl_t lv)
279      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);  {
280        char id[128], keyid[18+1];
281      DestroyMenu (hm);      int i, n, cnt=0;
282      DestroyMenu (sm);  
283  }      i = msg_box (dlg, _("Really receive all missing keys?"),
284                     _("Key Manager"), MB_YESNO|MB_INFO);
285        if (i == IDNO)
286  static void          return 0;
287  do_load_keyprops (HWND dlg, listview_ctrl_t lv)      
288  {      n = listview_count_items (lv, 0);
289      winpt_key_s k;      for (i = 0; i < n; i++) {
290      gpgme_key_t key;          listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1);
291      char keyid[32] = {0};          if (!strncmp (id, "NOKEY", 5)) {
292      char status[64] = {0}, creation[64] = {0};              listview_get_item_text (lv, i, SL_COL_KEYID,
293      int n = listview_get_curr_pos (lv);                                      keyid, sizeof (keyid) -1);
294                if (!hkp_recv_key (dlg, default_keyserver,
295      listview_get_item_text (lv, n, 1, status, DIM (status)-1);                                 default_keyserver_port, keyid, 0, 0)) {
296      listview_get_item_text (lv, n, 3, creation, DIM (creation)-1);                  keycache_update (0, keyid);
297      listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1);                  cnt++;
298      if (!strcmp (status, "NOKEY")) {              }
299          msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."),              else
300                   _("Key Manager"), MB_INFO);                  break;
301          return;          }
302      }      }
303            return cnt;
304      if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {  }
305          if (strlen (creation) > 0)  
306              msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);  
307          return;  /* Create a mini popup with available choices. */
308      }  static void
309      memset (&k, 0, sizeof k);  do_create_popup (HWND dlg)
310      k.keyid = keyid;  {
311      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,      HMENU hm, sm;
312                      keyprops_dlg_proc, (LPARAM)&k);      POINT p;
313  }  
314        GetCursorPos (&p);
315          hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));
316  BOOL CALLBACK      sm = GetSubMenu (hm, 0);
317  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)      set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties"));
318  {      set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties"));
319      static listview_ctrl_t lv = NULL;      TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
320      static struct winpt_key_s *k;      DestroyMenu (hm);
321      char inf[384], keyid[18+1];          DestroyMenu (sm);
322      int idx = 0, id, rc;  }
323      HWND sl;  
324        
325      switch( msg ) {  /* Fetch a single key and extract the keyid from the listview
326      case WM_INITDIALOG:     entry at the pos @idx. */
327          k = (winpt_key_t) lparam;  static int
328          if (!k)  recv_single_key (HWND dlg, listview_ctrl_t lv, int idx)
329              BUG (0);  {
330          if (k->uid)      char keyid[32];
331              _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);      int rc;
332          SetWindowText (dlg, inf);  
333          #ifndef LANG_DE      listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1);      
334          SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));      rc = hkp_recv_key (dlg, default_keyserver,
335          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));                         default_keyserver_port, keyid, 0, 0);
336          #endif                  
337          lv = siglist_load( GetDlgItem( dlg, IDC_KEYSIG_LIST ), k->keyid );      if (!rc)
338          if( !check_for_missing_keys( lv ) )          keycache_update (0, keyid);
339              EnableWindow( GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE );      return rc;
340          k->callback.ctl = lv;  }
341          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);  
342          siglist_proc.dlg = dlg;  
343          siglist_proc.opaque = k;  /* Load the key property dialog with the selected key from @lv. */
344          siglist_proc.current = (WNDPROC)subclass_dlg_proc;  static void
345          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);  do_load_keyprops (HWND dlg, listview_ctrl_t lv)
346          if (siglist_proc.old) {  {
347              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  {      winpt_key_s k;
348                  msg_box (dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR);      gpgme_key_t key;
349                  BUG (0);      char keyid[32] = {0};
350              }      char status[64] = {0}, creation[64] = {0};
351          }      int n = listview_get_curr_pos (lv);
352          SetForegroundWindow (dlg);  
353          center_window (dlg);      listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1);
354          return TRUE;      listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1);
355                listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1);
356      case WM_DESTROY:      if (!strcmp (status, "NOKEY")) {
357          if ( lv ) {          int id = msg_box (dlg, _("Key not found in keyring, do you want to fetch it from the keyserver?"),
358              siglist_delete( lv );                            _("Key Manager"), MB_QUEST_ASK);
359              lv = NULL;          if (id == IDNO)
360          }              return;
361          return FALSE;          if (recv_single_key (dlg, lv, n))              
362                        return;
363      case WM_SYSCOMMAND:      }
364          if (LOWORD (wparam) == SC_CLOSE) {      
365              if (k->update)      if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {
366                  keycache_update (0, k->keyid);          if (strlen (creation) > 0)
367              EndDialog (dlg, TRUE);              msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);
368          }          return;
369          return FALSE;      }
370        memset (&k, 0, sizeof k);
371      case WM_NOTIFY:      k.keyid = keyid;
372          NMHDR * notify;      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
373                                keyprops_dlg_proc, (LPARAM)&k);
374          notify = (NMHDR *)lparam;  }
375          if( notify && notify->code == NM_DBLCLK  
376              && notify->idFrom == IDC_KEYSIG_LIST )  
377              do_load_keyprops (dlg, lv);  /* Dialog box procedure to list signatures. */
378          if (notify && notify->code == NM_RCLICK &&  BOOL CALLBACK
379              notify->idFrom == IDC_KEYSIG_LIST)  keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
380              do_create_popup (dlg);  {
381          break;      static listview_ctrl_t lv = NULL;
382                static struct winpt_key_s *k;
383      case WM_COMMAND:      gpgme_key_sig_t ks;
384          switch ( LOWORD( wparam ) ) {      HWND sl;
385        char inf[384];
386          case ID_SIGCTX_KEYPROPS:      int idx = 0;    
387              do_load_keyprops (dlg, lv);      
388              break;      switch (msg) {
389        case WM_INITDIALOG:
390          case ID_SIGCTX_PROPS:          k = (winpt_key_t) lparam;
391              if (is_sig (lv, -1))          if (!k)
392                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,              BUG (0);
393                                  sigprops_dlg_proc, (LPARAM)lv);          if (k->uid)
394              break;              _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
395            SetWindowText (dlg, inf);
396          case IDC_KEYSIG_RECVKEY:          SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
397              idx = listview_get_curr_pos( lv );          SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
398              if( idx == -1 ) {  
399                  id = msg_box( dlg, _("Really receive all missing keys?"),          lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);
400                                  _("Key Manager"), MB_YESNO|MB_INFO );          if (!check_for_missing_keys (lv))
401                  if (id == IDYES) {              EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE);
402                      rc = recv_missing_keys (dlg, lv);          EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE);
403                      if( !rc )          k->callback.ctl = lv;
404                          keycache_set_reload (1);          sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);
405                      return TRUE;          siglist_proc.dlg = dlg;
406                  }          siglist_proc.opaque = k;
407                  return FALSE;          siglist_proc.current = (WNDPROC)subclass_dlg_proc;
408              }          siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);
409              listview_get_item_text (lv, idx, 4, keyid, sizeof keyid - 1);          if (siglist_proc.old) {
410              rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);              if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current))  {
411              if (!rc)                  msg_box (dlg, "Could not set keylist window procedure.",
412                  keycache_set_reload (1);                           _("Key Manager"), MB_ERR);
413              return TRUE;                  BUG (0);
414                }
415          case IDC_KEYSIG_SIGPROPS:          }
416              if (is_sig (lv, -1))          SetForegroundWindow (dlg);
417                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,          center_window (dlg, NULL);
418                                  sigprops_dlg_proc, (LPARAM)lv);          return TRUE;
419              return TRUE;          
420                    case WM_DESTROY:
421          case IDOK:          if (lv) {
422              if (k->update)              siglist_delete (lv);
423                  keycache_update (0, k->keyid);              lv = NULL;
424              EndDialog (dlg, TRUE);          }
425              return TRUE;          return FALSE;
426          }          
427          break;      case WM_SYSCOMMAND:
428      }          if (LOWORD (wparam) == SC_CLOSE)
429      return FALSE;              EndDialog (dlg, TRUE);
430  } /* keysig_dlg_proc */          return FALSE;
431    
432        case WM_NOTIFY:
433            NMHDR *notify;
434            
435            notify = (NMHDR *)lparam;
436            if (!notify)
437                return FALSE;
438            if (notify->code == NM_DBLCLK
439                && notify->idFrom == IDC_KEYSIG_LIST)
440                do_load_keyprops (dlg, lv);
441            if (notify->code == NM_RCLICK &&
442                notify->idFrom == IDC_KEYSIG_LIST &&
443                is_sig (lv, -1))
444                do_create_popup (dlg);
445            if (notify->code == LVN_ITEMCHANGED &&
446                ((LPNMLISTVIEW)lparam)->uNewState) {
447                idx = listview_get_curr_pos (lv);
448                listview_get_item_text (lv, idx, SL_COL_VALID, inf, DIM (inf)-1);
449                EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY),
450                              strcmp (inf, "NOKEY") == 0? TRUE: FALSE);
451                EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS),
452                              is_sig (lv, -1)? TRUE : FALSE);
453            }
454            if (notify->code == LVN_COLUMNCLICK) {
455                NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
456                int sortby = 0;
457                switch (nft->iSubItem) {
458                //case 0:  sortby = KEY_SORT_USERID; break;
459                case 1: sortby = KEY_SORT_VALIDITY; break;
460                case 2: sortby = SIG_SORT_CLASS; break;
461                case 3: sortby = KEY_SORT_CREATED; break;
462                case 4: sortby = KEY_SORT_KEYID; break;
463                case 5: sortby = SIG_SORT_EXPIRE; break;
464                case 6: sortby = KEY_SORT_ALGO; break;
465                default: return TRUE;
466                }
467                siglist_sort (lv, sortby);
468            }
469            break;
470            
471        case WM_COMMAND:
472            switch (LOWORD (wparam)) {
473            case ID_SIGCTX_KEYPROPS:
474                do_load_keyprops (dlg, lv);
475                break;
476    
477            case ID_SIGCTX_PROPS:
478                if (is_sig (lv, -1)) {
479                    ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv));
480                    DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
481                                    sigprops_dlg_proc, (LPARAM)ks);
482                }
483                break;
484    
485            case IDC_KEYSIG_RECVKEY:
486                idx = listview_get_curr_pos (lv);
487                if (idx == -1)
488                    recv_missing_keys (dlg, lv);
489                else
490                    recv_single_key (dlg, lv, idx);
491                return TRUE;
492    
493            case IDC_KEYSIG_SIGPROPS:
494                if (is_sig (lv, -1)) {
495                    ks = ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv));
496                    DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
497                                    sigprops_dlg_proc, (LPARAM)ks);
498                }
499                return TRUE;
500                
501            case IDOK:
502                EndDialog (dlg, TRUE);
503                return TRUE;
504            }
505            break;
506        }
507        return FALSE;
508    }

Legend:
Removed from v.20  
changed lines
  Added in v.176

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26