/[winpt]/trunk/Src/wptKeysigDlg.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeysigDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26