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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26