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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26