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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26