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

Legend:
Removed from v.13  
changed lines
  Added in v.204

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26