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

Legend:
Removed from v.32  
changed lines
  Added in v.256

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26