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

Annotation of /trunk/Src/wptClipSignDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 6120 byte(s)
WinPT initial checkin.


1 twoaday 2 /* wptClipSignDlg.cpp - WinPT clipboard sign dialog
2     * Copyright (C) 2000, 2001, 2002, 2003 Timo Schulz
3     *
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 "wptAgent.h"
27     #include "wptNLS.h"
28     #include "wptGPG.h"
29     #include "wptCommonCtl.h"
30     #include "wptRegistry.h"
31     #include "wptKeylist.h"
32     #include "wptErrors.h"
33     #include "wptW32API.h"
34     #include "wptVersion.h"
35     #include "wptContext.h" /* for passphrase_s */
36     #include "wptDlgs.h"
37    
38    
39     /* This function is used when only one secret key is available.
40     * it doesn't make sense to offer a dialog for this case.
41     */
42     void
43     one_key_proc (HWND dlg)
44     {
45     char * signer;
46     gpgme_ctx_t ctx;
47     gpgme_error_t err;
48     passphrase_cb_s pwd;
49     int rc = 0, n = reg_prefs.word_wrap;
50    
51     signer = get_gnupg_default_key ();
52     if( !signer )
53     {
54     msg_box( dlg, _("Could not get default key."), _("Signing"), MB_ERR );
55     return;
56     }
57    
58     err = gpgme_new( &ctx );
59     if( err )
60     BUG( dlg );
61     gpgme_enable_logging( ctx );
62     set_gpg_passphrase_cb( ctx, &pwd, GPG_CMD_SIGN, dlg, _("Signing") );
63     err = gpgme_op_clip_sign( ctx, GPGME_SIG_MODE_CLEAR, signer, n );
64     memset( pwd.pwd, 0, sizeof pwd.pwd );
65     if( err == GPGME_Bad_Passphrase )
66     agent_del_cache( pwd.keyid );
67    
68     if( err )
69     gpgme_show_error( dlg, err, ctx, _("Signing"), MB_ERR );
70     else
71     show_msg( dlg, 1500, _("GnuPG Status: Finished") );
72     gpgme_release( ctx );
73     free_if_alloc( signer );
74     } /* one_key_proc */
75    
76    
77     BOOL CALLBACK
78     clip_sign_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
79     {
80     static listview_ctrl_t lv = NULL;
81     gpgme_keycache_t kc, sec_kc;
82     gpgme_ctx_t ctx;
83     gpgme_error_t err;
84     passphrase_cb_s pwd;
85     int lv_idx = 0;
86     int rc = 0, no_signer = 0;
87     char * signer = NULL;
88    
89     switch( msg ) {
90     case WM_INITDIALOG:
91     #ifndef LANG_DE
92     SetWindowText( dlg, _("Signing") );
93     #endif
94     kc = keycache_get_ctx( KEYCACHE_PUB );
95     if( !kc )
96     BUG( NULL );
97     sec_kc = keycache_get_ctx( KEYCACHE_PRV );
98     if( !sec_kc )
99     BUG( dlg );
100     if( gpgme_keycache_count( sec_kc ) == 1 ) {
101     one_key_proc( dlg );
102     EndDialog( dlg, TRUE );
103     return FALSE;
104     }
105     lv = keylist_load( GetDlgItem( dlg, IDC_SIGN_KEYLIST ), kc, sec_kc,
106     KEYLIST_SIGN, GPGME_ATTR_USERID );
107     center_window( dlg );
108     SetForegroundWindow( dlg );
109     set_active_window( dlg );
110     return FALSE;
111    
112     case WM_DESTROY:
113     reset_active_window();
114     if( lv ) {
115     keylist_delete( lv );
116     lv = NULL;
117     }
118     memset( pwd.pwd, 0, sizeof pwd.pwd );
119     return FALSE;
120    
121     case WM_NOTIFY:
122     NMHDR * notify;
123     notify = (NMHDR *)lparam;
124     if( notify && notify->code == NM_DBLCLK
125     && notify->idFrom == IDC_SIGN_KEYLIST )
126     PostMessage( dlg, WM_COMMAND, MAKEWPARAM(IDOK, 0), NULL );
127     return TRUE;
128    
129     case WM_SYSCOMMAND:
130     if( LOWORD (wparam) == SC_CLOSE )
131     EndDialog(dlg, TRUE);
132     return FALSE;
133    
134     case WM_COMMAND:
135     switch ( LOWORD( wparam ) )
136     {
137     case IDOK:
138     signer = get_gnupg_default_key ();
139     if( !signer )
140     {
141     msg_box( dlg, _("Could not get default key."), _("Signing"), MB_ERR );
142     return FALSE;
143     }
144     if( listview_count_items( lv, 0 ) == 1 )
145     {
146     listview_get_item_text( lv, 0, 1, signer, sizeof signer-1 );
147     no_signer = 0;
148     }
149     else if( (lv_idx = listview_get_curr_pos( lv )) == -1 )
150     {
151     rc = log_box( _("Signing"), MB_YESNO,
152     _("No key was chosen.\nUse the GPG default key '%s'?"),
153     signer );
154     if( rc == IDNO )
155     {
156     free_if_alloc (signer);
157     return FALSE;
158     }
159     no_signer = 1;
160     }
161     if (!no_signer)
162     {
163     free_if_alloc (signer);
164     signer = new char[32+1];
165     if (!signer)
166     BUG (NULL);
167     listview_get_item_text (lv, lv_idx, 1, signer, 32);
168     }
169     err = gpgme_new (&ctx);
170     if( err )
171     BUG( dlg );
172     gpgme_enable_logging( ctx );
173     set_gpg_passphrase_cb( ctx, &pwd, GPG_CMD_SIGN, dlg, _("Signing") );
174     err = gpgme_op_clip_sign( ctx, GPGME_SIG_MODE_CLEAR, signer,
175     reg_prefs.word_wrap );
176     free_if_alloc( signer );
177     memset( pwd.pwd, 0, sizeof pwd.pwd );
178     if( pwd.cancel && err == GPGME_Bad_Passphrase ) { /* The user hit the cancel button */
179     gpgme_release( ctx );
180     EndDialog( dlg, TRUE );
181     return TRUE;
182     }
183     if( err ) {
184     gpgme_show_error( dlg, err, ctx, _("Signing"), MB_ERR );
185     gpgme_release( ctx );
186     return FALSE;
187     }
188     else
189     show_msg( dlg, 1500, _("GnuPG Status: Finished") );
190     gpgme_release( ctx );
191     EndDialog( dlg, TRUE );
192     return TRUE;
193    
194     case IDCANCEL:
195     EndDialog( dlg, FALSE );
196     return FALSE;
197     }
198     break;
199     }
200    
201     return FALSE;
202     } /* clip_sign_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26