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

Legend:
Removed from v.23  
changed lines
  Added in v.176

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26