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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26