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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26