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

Annotation of /trunk/Src/wptClipEncryptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (hide annotations)
Wed Aug 10 11:33:35 2005 UTC (19 years, 6 months ago) by twoaday
File size: 5304 byte(s)
2005-08-06  Timo Schulz  <twoaday@freakmail.de>
 
        * wptGPGME.cpp (keycache_update): Reload OpenPGP parts
        of the secret key.
        (keycache_init): cache name of secret keyring.
        * wptKeyList.cpp (keylist_upd_key): Do not add long keyid.
        (get_key_type): Do not assume 'ultimate' means key pair.
        * wptKeyEditDlgs.cpp (diff_time): New.
        (keyedit_addsubkey_dlg_proc): Changed design and use
        diff_time. Drop checks for invalid keylength (< 1024, > 4096)
        because the combo box automatically handles this.
        * wptKeyManager.cpp (km_set_implicit_trust): Return error code.
        * wptGPG.cpp (get_backup_name): New.
        (gnupg_backup_keyrings): Rotate backup names, from 0..3.
        * wptClipImportDialog.cpp (clip_import_dlg_proc): Free memory.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Use 0x short keyid and
        not the long keyid.


1 twoaday 2 /* wptClipEncryptDlg.cpp - Clipboard encrypt dialog
2 twoaday 22 * Copyright (C) 2000-2005 Timo Schulz
3 twoaday 2 *
4     * This file is part of WinPT.
5     *
6     * 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
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #include <windows.h>
22     #include <commctrl.h>
23    
24     #include "../resource.h"
25     #include "wptTypes.h"
26     #include "wptW32API.h"
27     #include "wptVersion.h"
28     #include "wptErrors.h"
29     #include "wptCommonCtl.h"
30     #include "wptGPG.h"
31     #include "wptKeylist.h"
32     #include "wptNLS.h"
33     #include "wptContext.h" /* for passphrase_s */
34     #include "wptRegistry.h"
35     #include "wptDlgs.h"
36    
37    
38     BOOL CALLBACK
39     clip_encrypt_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
40     {
41     static listview_ctrl_t lv = NULL;
42     gpgme_keycache_t kc;
43     gpgme_recipients_t rset;
44     gpgme_ctx_t ctx;
45     gpgme_error_t err;
46     refresh_cache_s rcs = {0};
47     int force_trust = 0, opt = 0;
48     int kmode = reg_prefs.keylist_mode? KEYLIST_ENCRYPT_MIN : KEYLIST_ENCRYPT;
49    
50     switch( msg ) {
51     case WM_INITDIALOG:
52     SetWindowText( dlg, _("Encryption") );
53     kc = keycache_get_ctx( KEYCACHE_PUB );
54     if( !kc )
55     BUG( NULL );
56     lv = keylist_load( GetDlgItem( dlg, IDC_ENCRYPT_KEYLIST ), kc, NULL,
57     kmode, GPGME_ATTR_USERID );
58     center_window( dlg );
59     SetForegroundWindow( dlg );
60     set_active_window( dlg );
61     return TRUE;
62    
63     case WM_DESTROY:
64     reset_active_window( );
65     if( lv ) {
66     keylist_delete( lv );
67     lv = NULL;
68     }
69     return FALSE;
70    
71     case WM_NOTIFY:
72     NMHDR *notify;
73    
74     notify = (NMHDR *)lparam;
75     if( notify && notify->code == NM_DBLCLK && notify->idFrom == IDC_ENCRYPT_KEYLIST )
76     PostMessage( dlg, WM_COMMAND, MAKEWPARAM( IDOK, 0 ), NULL );
77     if( notify && notify->code == LVN_COLUMNCLICK && notify->idFrom == IDC_ENCRYPT_KEYLIST ) {
78     NMLISTVIEW *p = (LPNMLISTVIEW) lparam;
79     int sortby = 0;
80    
81     switch( p->iSubItem ) {
82     case 0: sortby = GPGME_ATTR_USERID; break;
83     case 1: sortby = GPGME_ATTR_KEYID; break;
84     case 2: sortby = GPGME_ATTR_LEN; break;
85     case 4: sortby = GPGME_ATTR_VALIDITY; break;
86     default: sortby = GPGME_ATTR_USERID; break;
87     }
88     keylist_sort( lv, sortby );
89     }
90     return TRUE;
91    
92     case WM_SYSCOMMAND:
93     if( LOWORD( wparam ) == SC_CLOSE )
94     EndDialog( dlg, TRUE );
95     return FALSE;
96    
97     case WM_COMMAND:
98     switch( LOWORD( wparam ) ) {
99     case IDOK:
100 twoaday 20 rset = keylist_get_recipients (lv, &force_trust, NULL);
101 twoaday 2 if( !gpgme_recipients_count( rset ) ) {
102     msg_box( dlg, _("You must select at least one key."), _("Encryption"), MB_ERR );
103     gpgme_recipients_release( rset );
104     return FALSE;
105     }
106     if( force_trust )
107     opt |= GPGME_CTRL_FORCETRUST;
108     if( reg_prefs.use_tmpfiles )
109     opt |= GPGME_CTRL_TMPFILES;
110     err = gpgme_op_clip_encrypt( rset, opt, &ctx );
111     if( err && err != GPGME_Inv_Recipients ) {
112 twoaday 6 if( err == GPGME_Internal_GPG_Problem )
113 twoaday 2 gnupg_display_error ();
114     else
115     msg_box( dlg, gpgme_strerror( err ), _("Encryption"), MB_ERR );
116     gpgme_release( ctx );
117     gpgme_recipients_release( rset );
118     return FALSE;
119     }
120     else if( err == GPGME_Inv_Recipients ) {
121     int ncount = gpgme_recperr_count_items( ctx );
122     gpgme_error_t code = GPGME_No_Error;
123    
124     while( ncount-- ) {
125     const char *s = gpgme_recperr_get( ctx, ncount, &code );
126     if( s )
127     log_box( _("Encryption"), MB_ERR,
128     _("Unusable recipient \"%s\": %s"), s,
129     gpgme_strerror( code ) );
130     }
131     }
132     else
133     show_msg( dlg, 1500, _("GnuPG Status: Finished") );
134     gpgme_recipients_release( rset );
135     gpgme_release( ctx );
136     EndDialog( dlg, TRUE );
137     return TRUE;
138    
139     case IDCANCEL:
140     EndDialog( dlg, FALSE );
141     return FALSE;
142    
143     case IDC_ENCRYPT_FNDCMD:
144     {
145     char tmpbuf[64];
146     int n;
147    
148     n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1);
149     if (!n)
150     break;
151     n = listview_find (lv, tmpbuf);
152 twoaday 22 if (n != -1) {
153     int oldpos = listview_get_curr_pos (lv);
154 twoaday 2 listview_select_one (lv, n);
155 twoaday 22 listview_scroll (lv, oldpos, n);
156     }
157 twoaday 2 else
158     log_box (_("Encryption"), MB_ERR, _("No recipient found with '%s'"), tmpbuf);
159     break;
160     }
161     }
162     break;
163     }
164    
165     return FALSE;
166     } /* clip_encrypt_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26