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

Diff of /trunk/Src/wptCommonDlg.cpp

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

revision 327 by twoaday, Sat Sep 30 10:24:34 2006 UTC revision 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 1  Line 1 
1  /* wptCommonDlg.cpp  /* wptCommonDlg.cpp
2   *      Copyright (C) 2004, 2005, 2006 Timo Schulz   *      Copyright (C) 2004, 2005, 2006, 2009 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
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.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  
15   */   */
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
# Line 42  check_URL (const char *buf) Line 38  check_URL (const char *buf)
38      size_t i;      size_t i;
39      const char *allowed = "-./#_:~&?=";      const char *allowed = "-./#_:~&?=";
40    
41      if (strncmp (buf, "http", 4))      if (strncmp (buf, "http", 4) && strncmp (buf, "x-hkp", 5))
42          return -1;          return -1;
43      if (!strchr (buf, ':'))      if (!strchr (buf, ':'))
44          return -1;          return -1;
# Line 65  check_URL (const char *buf) Line 61  check_URL (const char *buf)
61  static BOOL CALLBACK  static BOOL CALLBACK
62  http_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  http_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
63  {  {
64      static struct URL_ctx_s * ctx;      static URL_ctx_t ctx;
65      int n;      int n;
66    
67      switch (msg) {      switch (msg) {
# Line 87  http_dlg_proc (HWND dlg, UINT msg, WPARA Line 83  http_dlg_proc (HWND dlg, UINT msg, WPARA
83              n = GetDlgItemText (dlg, IDC_HTTP_URL, ctx->url, DIM (ctx->url)-1);              n = GetDlgItemText (dlg, IDC_HTTP_URL, ctx->url, DIM (ctx->url)-1);
84              if (ctx->check && (!n || check_URL (ctx->url))) {              if (ctx->check && (!n || check_URL (ctx->url))) {
85                  msg_box (dlg, _("Please enter a valid URL."), "HTTP", MB_ERR);                  msg_box (dlg, _("Please enter a valid URL."), "HTTP", MB_ERR);
86                  return FALSE;                  return FALSE;          
87              }              }
88                if (ctx->check && ctx->url[strlen (ctx->url)-1] == '/')
89                    ctx->url[strlen (ctx->url)-1]=0;
90              ctx->cancel = 0;              ctx->cancel = 0;
91              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
92              break;              break;
# Line 109  http_dlg_proc (HWND dlg, UINT msg, WPARA Line 107  http_dlg_proc (HWND dlg, UINT msg, WPARA
107  void*  void*
108  get_http_file_dlg (HWND root)  get_http_file_dlg (HWND root)
109  {  {
110      struct URL_ctx_s *ctx;      URL_ctx_t ctx;
111    
112      ctx = new URL_ctx_s;      ctx = new URL_ctx_s;
113      if (!ctx)      if (!ctx)
# Line 123  get_http_file_dlg (HWND root) Line 121  get_http_file_dlg (HWND root)
121      return ctx;      return ctx;
122  }  }
123    
124    
125  /* Wrapper to request a preferred keyserver from the user.  /* Wrapper to request a preferred keyserver from the user.
126     Return value is the URL context. */     Return value is the URL context. */
127  void*  void*
128  get_keyserver_URL_dlg (HWND root)  get_keyserver_URL_dlg (HWND root)
129  {  {
130      struct URL_ctx_s *ctx;      URL_ctx_t ctx;
131    
132      ctx = new URL_ctx_s;      ctx = new URL_ctx_s;
133      if (!ctx)      if (!ctx)
# Line 150  get_input_dialog (HWND root, const char Line 149  get_input_dialog (HWND root, const char
149      struct URL_ctx_s ctx;      struct URL_ctx_s ctx;
150    
151      memset (&ctx, 0, sizeof (ctx));      memset (&ctx, 0, sizeof (ctx));
152        ctx.check = 0; /* Do not perform any checks on the data. */
153      ctx.title = title;      ctx.title = title;
154      ctx.desc = desc;      ctx.desc = desc;
155      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
# Line 158  get_input_dialog (HWND root, const char Line 158  get_input_dialog (HWND root, const char
158          return NULL;          return NULL;
159      return m_strdup (ctx.url);      return m_strdup (ctx.url);
160  }  }
   
   
 /* Initialize the language list based on the .mo files  
    found in the dirctory @modpath. */  
 static int  
 nls_load_langlist (HWND dlg, const char *modpath)  
 {  
     WIN32_FIND_DATA fnd;  
     HWND cb;  
     HANDLE hd;  
     char *pattern = NULL;      
     int i;  
   
     cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST);  
     combox_add_string (cb, lang_list[0].name);  
     SendMessage (cb, CB_SETCURSEL, 0, 0);  
       
     memset (&fnd, 0, sizeof (fnd));  
     pattern = make_filename (modpath, "*.mo", NULL);  
     hd = FindFirstFile (pattern, &fnd);  
     if (hd == INVALID_HANDLE_VALUE) {  
         free_if_alloc (pattern);  
         return -1;  
     }  
   
     do {  
         for (i=0; lang_list[i].id != NULL; i++) {  
             if (!strnicmp (fnd.cFileName, lang_list[i].id, 2))  
                 combox_add_string (cb, lang_list[i].name);  
         }  
         memset (&fnd, 0, sizeof (fnd));  
     } while (FindNextFile (hd, &fnd) != FALSE);  
     FindClose (hd);  
     free_if_alloc (pattern);  
     return 0;  
 }  
   
   
 /* Set the default language for the program.  
    The $lang.mo file is copied either to the selected  
    folder or the directory specified by @modpath.  
    The output name of the file is winpt.mo (example: de.mo -> winpt.mo). */  
 static int  
 nls_set_language (HWND dlg, const char *modpath)  
 {  
     HWND cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST);  
     int pos = SendMessage (cb, CB_GETCURSEL, 0, 0);  
     const char *folder;  
     char *src, *dst;  
   
     /* default langauge is English. */  
     if (pos == 0 || pos == CB_ERR)  
         return 0;  
   
     folder = get_folder_dlg (dlg, _("Choose Locale Directory"), modpath);  
     if (!folder)  
         return 0;  
   
     src = make_filename (modpath, lang_list[pos].id, "mo");  
     dst = make_filename (folder, "winpt", "mo");  
   
     if (!CopyFile (src, dst, FALSE)) {  
         msg_box (dlg, _("Could not create winpt.mo file"),  
                  _("WinPT Error"), MB_ERR);  
         pos = -1;  
     }  
     else  
         set_reg_entry_mo (folder);  
     free_if_alloc (src);  
     free_if_alloc (dst);  
     return pos;  
 }  
   
   
 static BOOL CALLBACK  
 nls_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
 {  
     static char modpath[MAX_PATH+1];  
     int langid = 0, n;  
   
     switch (msg) {  
     case WM_INITDIALOG:  
         if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {  
             while (n-- > 0) {  
                 if (modpath[n] == '\\') {  
                     modpath[n] = 0;  
                     break;  
                 }  
             }  
         }  
         n = nls_load_langlist (dlg, modpath);  
         if (n == -1)  
             EndDialog (dlg, -1);  
         SetWindowText (dlg, _("Native Language Support"));  
         SetDlgItemText (dlg, IDC_LANGUAGE_INFO, _("Please select a language"));  
         SetDlgItemText (dlg, IDOK, _("&OK"));  
         SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));  
         center_window (dlg, NULL);  
         SetForegroundWindow (dlg);  
         break;  
   
     case WM_COMMAND:  
         switch (LOWORD (wparam)) {  
         case IDOK:  
             langid = nls_set_language (dlg, modpath);  
             EndDialog (dlg, langid);  
             break;  
   
         case IDCANCEL:  
             EndDialog (dlg, -1);  
             break;  
         }  
         break;  
     }  
   
     return FALSE;  
 }  
   
   
 int  
 select_language (void)  
 {  
     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_LANGUAGE, GetDesktopWindow (),  
                     nls_dlg_proc, 0);  
     return 0;  
 }  
   

Legend:
Removed from v.327  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26