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

Diff of /trunk/Src/wptGPGPrefsDlg.cpp

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

revision 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC revision 66 by twoaday, Thu Nov 3 17:55:18 2005 UTC
# Line 1  Line 1 
1  /* wptGPGPrefsDlg.cpp - WinPT GnuPG Preferences  /* wptGPGPrefsDlg.cpp - WinPT GnuPG Preferences
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2005 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    
21  #include <windows.h>  #ifdef HAVE_CONFIG_H
22    #include <config.h>
23  #include "../resource.h"  #endif
24  #include "wptNLS.h"  
25  #include "wptTypes.h"  #include <windows.h>
26  #include "wptErrors.h"  
27  #include "wptGPG.h"  #include "resource.h"
28  #include "wptRegistry.h"  #include "wptNLS.h"
29  #include "wptCommonCtl.h"  #include "wptTypes.h"
30  #include "wptContext.h" /* for passphrase_s */  #include "wptErrors.h"
31  #include "wptDlgs.h"  #include "wptGPG.h"
32  #include "wptW32API.h"  #include "wptRegistry.h"
33  #include "wptVersion.h"  #include "wptCommonCtl.h"
34    #include "wptContext.h" /* for passphrase_s */
35  static struct {  #include "wptDlgs.h"
36      const char * name;  #include "wptW32API.h"
37      int id;  #include "wptVersion.h"
38  } opts[] = {  
39      {"HomeDir",    IDC_GPGPREFS_HOMEDIR},  static struct {
40      {"gpgProgram", IDC_GPGPREFS_EXEDIR},      const char *name;
41      {"OptFile",    IDC_GPGPREFS_OPTFILE},      int id;
42      {0}  } opts[] = {
43  };      {"HomeDir",    IDC_GPGPREFS_HOMEDIR},
44        {"gpgProgram", IDC_GPGPREFS_EXEDIR},
45        {"OptFile",    IDC_GPGPREFS_OPTFILE},
46  BOOL CALLBACK      {NULL, 0}
47  gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  };
48  {  
49      char exedir[1024], homedir[1024], optfile[1024];  /* Dialog box procedure for the GPG preferences. */
50      char locale_dir[1024];  BOOL CALLBACK
51      char * p = NULL, t[512];  gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
52      const char * s;  {
53      int have_optfile = 0;      char exedir[512], homedir[512], optfile[512];
54      gpg_optfile_t opt = NULL;      char locale_dir[512];
55      gpg_option_t e;      char *p = NULL, t[256];
56      UINT n;      const char *s;
57            int have_optfile = 0;
58      switch ( msg ) {      gpg_optfile_t opt = NULL;
59      case WM_INITDIALOG:      gpg_option_t e;
60  #ifndef LANG_DE      UINT n;
61          SetWindowText( dlg, _("GnuPG Preferences") );      
62          SetDlgItemText( dlg, IDC_GPGPREFS_HOMEINF,      switch (msg) {
63                         _("GnuPG home directory  (where both keyrings are located)") );      case WM_INITDIALOG:
64          SetDlgItemText( dlg, IDC_GPGPREFS_OPTINF,          SetWindowText (dlg, _("GnuPG Preferences"));
65                         _("GnuPG config file (default: use gpg.conf)") );          SetDlgItemText( dlg, IDC_GPGPREFS_HOMEINF,
66          SetDlgItemText( dlg, IDC_GPGPREFS_EXEINF,                         _("GnuPG home directory  (where both keyrings are located)") );
67                         _("GnuPG exe file location (full path with added gpg.exe)") );          SetDlgItemText( dlg, IDC_GPGPREFS_OPTINF,
68          SetDlgItemText( dlg, IDC_GPGPREFS_LOCALINF,                         _("GnuPG config file (default: use gpg.conf)") );
69                         _("Locale directory (to access the translation files)") );          SetDlgItemText( dlg, IDC_GPGPREFS_EXEINF,
70  #endif                         _("GnuPG exe file location (full path with added gpg.exe)") );
71          for( n=0; (s = opts[n].name); n++ ) {          SetDlgItemText( dlg, IDC_GPGPREFS_LOCALINF,
72              p = get_reg_entry_gpg( s );                         _("Locale directory (to access the translation files)") );
73              if( p ) {          SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign"));
74                  SetDlgItemText( dlg, opts[n].id, p );  
75                  free_if_alloc( p );          for( n=0; (s = opts[n].name); n++ ) {
76              }              p = get_reg_entry_gpg( s );
77          }              if( p ) {
78                            SetDlgItemText( dlg, opts[n].id, p );
79          if( (p = get_reg_entry_mo( )) ) {                  free_if_alloc( p );
80              SetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, p );              }
81              free_if_alloc( p );          }
82          }          
83          p = get_gnupg_cfgfile( );          p = get_reg_entry_mo ();
84          if( p ) {          if (p) {
85              parse_gpg_options( p, &opt );              SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p);
86              free_if_alloc( p );              free_if_alloc (p);
87              if( opt && find_option( opt, "force-v3-sigs" ) )          }
88                  CheckDlgButton( dlg, IDC_GPGPREFS_V3SIGS, BST_CHECKED );          p = get_gnupg_cfgfile ();
89              if( opt && (e=find_option( opt, "comment" )) )          if (p) {
90                  SetDlgItemText( dlg, IDC_GPGPREFS_COMMENT, e->val );              parse_gpg_options (p, &opt);
91              if( opt && (e=find_option( opt, "encrypt-to" )) )              free_if_alloc (p);
92                  SetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, e->val );                        if (opt && find_option( opt, "ask-cert-level" ) )
93          }                  CheckDlgButton( dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED );
94          center_window( dlg, NULL );              if (opt && (e=find_option( opt, "comment" )) )
95          SetForegroundWindow( dlg );                  SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);
96          return TRUE;              if (opt && (e=find_option( opt, "encrypt-to")))
97                            SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);
98      case WM_SYSCOMMAND:              if (opt)
99          if( LOWORD( wparam ) == SC_CLOSE )                  release_gpg_options (opt);
100              EndDialog( dlg, TRUE );          }
101          return FALSE;          center_window (dlg, NULL);
102                    SetForegroundWindow (dlg);
103      case WM_COMMAND:          return TRUE;
104          switch ( LOWORD( wparam ) ) {          
105          case IDC_GPGPREFS_SAVE:      case WM_SYSCOMMAND:
106              if( !GetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, homedir, sizeof homedir -1 ) ) {          if( LOWORD( wparam ) == SC_CLOSE )
107                  msg_box( dlg, _("Please enter the GnuPG home directory."), _("Preferences"), MB_ERR );              EndDialog( dlg, TRUE );
108                  return FALSE;          return FALSE;
109              }          
110              if( dir_exist_check( homedir ) ) {      case WM_COMMAND:
111                  _snprintf( t, sizeof t - 1, "%s: %s", homedir, winpt_strerror(WPTERR_DIR_OPEN) );          switch ( LOWORD( wparam ) ) {
112                  msg_box( dlg, t, _("Preferences"), MB_ERR );          case IDC_GPGPREFS_SAVE:
113                  return FALSE;              if( !GetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, homedir, sizeof homedir -1 ) ) {
114              }                  msg_box( dlg, _("Please enter the GnuPG home directory."), _("Preferences"), MB_ERR );
115                                return FALSE;
116              if( GetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, optfile, sizeof optfile - 1 ) ) {              }
117                  if ( file_exist_check( optfile ) ) {              if( dir_exist_check( homedir ) ) {
118                      n = msg_box(dlg, _("Could not find GPG config file.\n"                  _snprintf( t, sizeof t - 1, "%s: %s", homedir, winpt_strerror(WPTERR_DIR_OPEN) );
119                                         "Do you want to create a config file?"),                  msg_box( dlg, t, _("Preferences"), MB_ERR );
120                                  _("Preferences"), MB_INFO|MB_YESNO );                  return FALSE;
121                      if( n == IDNO ) {              }
122                          SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, "" );              
123                          return FALSE;              if( GetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, optfile, sizeof optfile - 1 ) ) {
124                      }                  if ( file_exist_check( optfile ) ) {
125                      else if( n == IDYES ) {                      n = msg_box(dlg, _("Could not find GPG config file.\n"
126                          FILE * fp = fopen( optfile, "wb" );                                         "Do you want to create a config file?"),
127                          if( fp )                                  _("Preferences"), MB_INFO|MB_YESNO );
128                              fclose( fp );                      if( n == IDNO ) {
129                          if( file_exist_check( optfile ) ) {                          SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, "" );
130                              log_box( _("Preferences"), MB_ERR, "%s: %s", optfile, winpt_strerror( WPTERR_FILE_CREAT ) );                          return FALSE;
131                              return FALSE;                      }
132                          }                      else if( n == IDYES ) {
133                          have_optfile = 1;                          FILE * fp = fopen( optfile, "wb" );
134                      }                          if( fp )
135                  }                              fclose( fp );
136                  else                          if( file_exist_check( optfile ) ) {
137                      have_optfile = 1;                              log_box( _("Preferences"), MB_ERR, "%s: %s", optfile, winpt_strerror( WPTERR_FILE_CREAT ) );
138                  if( have_optfile ) {                              return FALSE;
139                      if( set_reg_entry_gpg( "OptFile", optfile ) ) {                          }
140                          msg_box( dlg, _("Could not save 'OptFile' in the registry."), _("Preferences"), MB_ERR );                          have_optfile = 1;
141                          return FALSE;                      }
142                      }                  }
143                  }                  else
144              }                      have_optfile = 1;
145              else {                  if( have_optfile ) {
146                  char * t = get_gnupg_cfgfile ();                      if( set_reg_entry_gpg( "OptFile", optfile ) ) {
147                  if (t && !file_exist_check (t))                          msg_box( dlg, _("Could not save 'OptFile' in the registry."), _("Preferences"), MB_ERR );
148                      set_reg_entry_gpg( "OptFile", t );                          return FALSE;
149                  free_if_alloc (t);                      }
150              }                  }
151              if ( set_reg_entry_gpg( "HomeDir", homedir ) ) {                                  }
152                  msg_box( dlg, _("Could not save 'HomeDir' in the registry."), _("Preferences"), MB_ERR );              else {
153                  return FALSE;                  char * t = get_gnupg_cfgfile ();
154              }                  if (t && !file_exist_check (t))
155              if( !GetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, exedir, sizeof exedir -1 ) ) {                      set_reg_entry_gpg( "OptFile", t );
156                  msg_box( dlg, _("Please enter where GPG.exe is located."), _("Preferences"), MB_ERR );                  free_if_alloc (t);
157                  return FALSE;              }
158              }              if ( set_reg_entry_gpg( "HomeDir", homedir ) ) {                    
159              if( file_exist_check( exedir ) ) {                  msg_box( dlg, _("Could not save 'HomeDir' in the registry."), _("Preferences"), MB_ERR );
160                  msg_box( dlg, _("Could not find the GPG program in this directory."), _("Preferences"), MB_ERR );                  return FALSE;
161                  return FALSE;              }
162              }              if( !GetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, exedir, sizeof exedir -1 ) ) {
163              if( set_reg_entry_gpg("gpgProgram", exedir ) ) {                  msg_box( dlg, _("Please enter where GPG.exe is located."), _("Preferences"), MB_ERR );
164                  msg_box( dlg, _("Could not save 'gpgProgram' in the registry"), _("Preferences"), MB_ERR );                  return FALSE;
165                  return FALSE;              }
166              }              if( file_exist_check( exedir ) ) {
167              if( GetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1 ) ) {                  msg_box( dlg, _("Could not find the GPG program in this directory."), _("Preferences"), MB_ERR );
168                  if (dir_exist_check (locale_dir)) {                  return FALSE;
169                      log_box( _("Preferences"), MB_ERR, "%s: %s", locale_dir, winpt_strerror (WPTERR_DIR_OPEN));              }
170                      return FALSE;              if( set_reg_entry_gpg("gpgProgram", exedir ) ) {
171                  }                  msg_box( dlg, _("Could not save 'gpgProgram' in the registry"), _("Preferences"), MB_ERR );
172                  set_reg_entry_mo (locale_dir);                  return FALSE;
173                  set_gettext_file ("winpt", locale_dir);              }
174              }              if( GetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1 ) ) {
175              else                  if (dir_exist_check (locale_dir)) {
176                  set_reg_entry_mo ("");                      log_box( _("Preferences"), MB_ERR, "%s: %s", locale_dir, winpt_strerror (WPTERR_DIR_OPEN));
177                        return FALSE;
178              p = get_gnupg_cfgfile ();                  }
179              if( !p ) {                  set_reg_entry_mo (locale_dir);
180                  msg_box( dlg, _("Could not get GPG config file"), _("Preferences"), MB_ERR );                  set_gettext_file ("winpt", locale_dir);
181                  EndDialog( dlg, FALSE );              }
182              }              else
183              parse_gpg_options( p, &opt );                  set_reg_entry_mo ("");
184    
185              if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_V3SIGS ) )              p = get_gnupg_cfgfile ();
186                  modify_entry( opt, ENTRY_SINGLE, "force-v3-sigs", NULL );              if( !p ) {
187              else                  msg_box( dlg, _("Could not get GPG config file"), _("Preferences"), MB_ERR );
188                  delete_option( opt, "force-v3-sigs" );                  EndDialog( dlg, FALSE );
189                }
190              if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))              parse_gpg_options( p, &opt );
191                  modify_entry( opt, ENTRY_MULTI, "comment", t );  
192              else if( n == 0 )              if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_ASKLEVEL ) ) {
193                  modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );                  modify_entry( opt, ENTRY_SINGLE, "ask-cert-level", NULL );
194              else                  reg_prefs.gpg.ask_cert_level = 1;
195                  delete_option( opt, "comment" );              }
196                else {
197              if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )                  delete_option( opt, "ask-cert-level" );
198                  modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );                  reg_prefs.gpg.ask_cert_level = 0;
199              else              }
200                  delete_option( opt, "encrypt-to" );  
201                if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))
202              commit_gpg_options( p, opt );                  modify_entry( opt, ENTRY_MULTI, "comment", t );
203              release_gpg_options( opt );              else if( n == 0 )
204              EndDialog( dlg, TRUE );                  modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );
205              return TRUE;              else
206                                delete_option( opt, "comment" );
207          case IDC_GPGPREFS_HOMEDLG:  
208              const char * home;              if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )
209              home = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);                  modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );
210              if (home) {              else
211                  SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, home);                  delete_option( opt, "encrypt-to" );
212                  if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)  
213                      break;              commit_gpg_options( p, opt );
214                  char *name = make_filename (home, "gpg", "exe");              release_gpg_options (opt);
215                  if (file_exist_check (name) == 0)              EndDialog( dlg, TRUE );
216                      SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);              return TRUE;
217                  free_if_alloc (name);              
218                  name = make_filename (home, "gpg", "conf");          case IDC_GPGPREFS_HOMEDLG:
219                  if (file_exist_check (name) == 0)              const char * home;
220                      SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);              home = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);
221                  free_if_alloc (name);              if (home) {
222              }                  SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, home);
223              break;                  if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)
224                        break;
225          case IDC_GPGREFS_EXEDLG:                  char *name = make_filename (home, "gpg", "exe");
226              const char * bin;                  if (file_exist_check (name) == 0)
227              bin = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG binary"), _("Executable Files (*.exe)\0*.exe\0\0"), NULL );                      SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
228              if( bin )                  free_if_alloc (name);
229                  SetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, bin );                  name = make_filename (home, "gpg", "conf");
230              return TRUE;                  if (file_exist_check (name) == 0)
231                                    SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);
232          case IDC_GPGPREFS_OPTDLG:                  free_if_alloc (name);
233              const char * opt;              }
234              opt = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG config file"), NULL, NULL );              break;
235              if( opt )  
236                  SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, opt );          case IDC_GPGREFS_EXEDLG:
237              return TRUE;              const char * bin;
238          }              bin = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG binary"), _("Executable Files (*.exe)\0*.exe\0\0"), NULL );
239          break;              if( bin )
240      }                  SetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, bin );
241                    return TRUE;
242      return FALSE;              
243  } /* gpgprefs_dlg_proc */          case IDC_GPGPREFS_OPTDLG:
244                const char * opt;
245                opt = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG config file"), NULL, NULL );
246                if( opt )
247                    SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, opt);
248                return TRUE;
249            }
250            break;
251        }
252        
253        return FALSE;
254    }

Legend:
Removed from v.23  
changed lines
  Added in v.66

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26