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

Legend:
Removed from v.28  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26