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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26