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

Legend:
Removed from v.34  
changed lines
  Added in v.208

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26