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

Diff of /trunk/Src/wptKeyPropsDlg.cpp

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

revision 33 by twoaday, Tue Oct 25 07:46:20 2005 UTC revision 34 by twoaday, Wed Oct 26 11:20:09 2005 UTC
# Line 79  ownertrust_to_string (int val) Line 79  ownertrust_to_string (int val)
79  }  }
80    
81    
82  #define PHOTO_TMPNAME "winpt_temp_photo.jpg"  /* Generate a unique temp name for the photo which
83       depends on the dialog handle and return it. */
84    static const char*
85    get_photo_tmpname (HWND dlg)
86    {
87        static char buf[64];
88    
89        _snprintf (buf, sizeof (buf)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg);
90        return buf;
91    }
92    
93    
94  /* Load the photo from the key @key */  /* Load the photo from the key @key */
95  static int  static int
96  keyprops_load_photo (gpgme_key_t key, gpgme_validity_t *r_valid)  keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid)
97  {  {
98      winpt_key_s k;      winpt_key_s k;
99      FILE *f;      FILE *f;
# Line 93  keyprops_load_photo (gpgme_key_t key, gp Line 103  keyprops_load_photo (gpgme_key_t key, gp
103    
104      winpt_get_pubkey (key->subkeys->keyid, &k);      winpt_get_pubkey (key->subkeys->keyid, &k);
105      img = k.ext->attrib.d;      img = k.ext->attrib.d;
106      imglen = k.ext->attrib.len;          imglen = k.ext->attrib.len;
107      if (!k.ext->attrib.validity)      if (!k.ext->attrib.validity)
108          get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);          get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);
109      *r_valid = k.ext->attrib.validity;      *r_valid = k.ext->attrib.validity;
110    
111      if (!img || !imglen)      if (!img || !imglen)
112          return -1;          return -1;
113      f = fopen (PHOTO_TMPNAME, "wb");      f = fopen (get_photo_tmpname (dlg), "wb");
114      if (f) {      if (f) {
115          for (pos = 0; img[pos] != 0x10; pos++)          for (pos = 0; img[pos] != 0x10; pos++)
116                  ;                  ;
# Line 126  keyprops_show_photo (HWND dlg) Line 136  keyprops_show_photo (HWND dlg)
136      p.x = r.left + 5;      p.x = r.left + 5;
137      p.y = r.top - 2;      p.y = r.top - 2;
138      memset (&p, 0, sizeof (p));      memset (&p, 0, sizeof (p));
139      PTD_jpg_show (h, &p, PHOTO_TMPNAME);      PTD_jpg_show (h, &p, get_photo_tmpname (dlg));
140            
141      return 0;      return 0;
142  }  }
# Line 254  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 264  keyprops_dlg_proc (HWND dlg, UINT msg, W
264  {  {
265      static winpt_key_t k;      static winpt_key_t k;
266      static gpgme_key_t key;      static gpgme_key_t key;
     static int has_photo = 0;  
267      gpgme_validity_t valid;      gpgme_validity_t valid;
268      refresh_cache_s rcs = {0};      refresh_cache_s rcs = {0};
269      const char *inf;      const char *inf;
270      int cancel = 0;      int cancel = 0;
271      int rc;      int rc;
272            
273        /* XXX: static variable (k) prevent that the dialog can
274                be opened twice. */
275      switch (msg) {      switch (msg) {
276      case WM_INITDIALOG:      case WM_INITDIALOG:
277          if (!lparam)          if (!lparam)
# Line 275  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 286  keyprops_dlg_proc (HWND dlg, UINT msg, W
286          #endif            #endif  
287    
288          display_key_info (dlg, k, &key);          display_key_info (dlg, k, &key);
289          if (!keyprops_load_photo (key, &valid)) {          if (!keyprops_load_photo (dlg, key, &valid)) {
290              has_photo = 1;                    k->has_photo = 1;  
291              if (valid != 0 && valid < GPGME_VALIDITY_MARGINAL)              if (valid < GPGME_VALIDITY_MARGINAL)
292                  SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not checked."));                  SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));
293          }          }
294          if (k->key_pair)          if (k->key_pair)
295              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
# Line 289  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 300  keyprops_dlg_proc (HWND dlg, UINT msg, W
300          return TRUE;          return TRUE;
301    
302      case WM_DESTROY:      case WM_DESTROY:
303          has_photo = 0;          unlink (get_photo_tmpname (dlg));
         unlink (PHOTO_TMPNAME);  
304          break;          break;
305                
306      case WM_PAINT:      case WM_PAINT:
307          if (has_photo)          if (k->has_photo)
308              keyprops_show_photo (dlg);              keyprops_show_photo (dlg);
309          break;          break;
310    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26