/[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 47 by werner, Mon Oct 31 14:04:59 2005 UTC revision 211 by twoaday, Sun May 7 12:36:48 2006 UTC
# Line 1  Line 1 
1  /* wptCommonDlg.cpp  /* wptCommonDlg.cpp
2   *      Copyright (C) 2004, 2005 Timo Schulz   *      Copyright (C) 2004, 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 17  Line 17 
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  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
21  #include <config.h>  #include <config.h>
22  #endif  #endif
23    #include <ctype.h>
 #include <windows.h>  
24  #include <windows.h>  #include <windows.h>
25    
26  #include "resource.h"  #include "resource.h"
   
27  #include "wptTypes.h"  #include "wptTypes.h"
28  #include "wptW32API.h"  #include "wptW32API.h"
29  #include "wptVersion.h"  #include "wptVersion.h"
30  #include "wptGPG.h"  #include "wptGPG.h"
31  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
32  #include "wptContext.h"  #include "wptContext.h"
33    #include "wptRegistry.h"
34    
35    
36  /* check if the given buf contains a valid URL. */  /* check if the given buf contains a valid URL. */
37  static int  static int
38  check_URL (const char *buf)  check_URL (const char *buf)
39  {  {
40      /* XXX: be more strict */      size_t i;
41        const char *allowed = "-./#_:~&?=";
42    
43      if (!strchr (buf, ':'))      if (!strchr (buf, ':'))
44          return -1;          return -1;
45      if (!strstr (buf, "//"))      if (!strstr (buf, "//"))
46          return -1;          return -1;
47        if (strstr (buf, " "))
48            return -1;
49        buf += 7;
50        for (i=0; i < strlen (buf); i++) {
51            if (isalpha (buf[i]) || isdigit (buf[i]))
52                continue;
53            if (!strchr (allowed, buf[i]))
54                return -1;
55        }
56    
57      return 0;      return 0;
58  }  }
59    
# Line 63  http_dlg_proc (HWND dlg, UINT msg, WPARA Line 73  http_dlg_proc (HWND dlg, UINT msg, WPARA
73              SetWindowText (dlg, ctx->desc);              SetWindowText (dlg, ctx->desc);
74          if (ctx->title != NULL)          if (ctx->title != NULL)
75              SetDlgItemText (dlg, IDC_HTTP_TITLE, ctx->title);              SetDlgItemText (dlg, IDC_HTTP_TITLE, ctx->title);
76            SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
77          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
78          break;          break;
79    
# Line 100  get_http_file_dlg (HWND root) Line 111  get_http_file_dlg (HWND root)
111      if (!ctx)      if (!ctx)
112          BUG (0);          BUG (0);
113      memset (ctx, 0, sizeof *ctx);      memset (ctx, 0, sizeof *ctx);
114      ctx->check = 1;          ctx->check = 1;
115        ctx->desc = _("HTTP Key Import");
116        ctx->title = _("Enter URL to retrieve the public key");
117      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
118                      http_dlg_proc, (LPARAM)ctx);                      http_dlg_proc, (LPARAM)ctx);
119      return ctx;      return ctx;
# Line 141  get_input_dialog (HWND root, const char Line 154  get_input_dialog (HWND root, const char
154          return NULL;          return NULL;
155      return m_strdup (ctx.url);      return m_strdup (ctx.url);
156  }  }
157    
158    
159    /* Initialize the language list based on the .mo files
160       found in the dirctory @modpath. */
161    static int
162    nls_load_langlist (HWND dlg, const char *modpath)
163    {
164        WIN32_FIND_DATA fnd;
165        HWND cb;
166        HANDLE hd;
167        char *pattern = NULL;    
168        int i;
169    
170        cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST);
171        combox_add_string (cb, lang_list[0].name);
172        SendMessage (cb, CB_SETCURSEL, 0, 0);
173        
174        memset (&fnd, 0, sizeof (fnd));
175        pattern = make_filename (modpath, "*.mo", NULL);
176        hd = FindFirstFile (pattern, &fnd);
177        if (hd == INVALID_HANDLE_VALUE) {
178            free_if_alloc (pattern);
179            return -1;
180        }
181    
182        do {
183            for (i=0; lang_list[i].id != NULL; i++) {
184                if (!strnicmp (fnd.cFileName, lang_list[i].id, 2))
185                    combox_add_string (cb, lang_list[i].name);
186            }
187            memset (&fnd, 0, sizeof (fnd));
188        } while (FindNextFile (hd, &fnd) != FALSE);
189        FindClose (hd);
190        free_if_alloc (pattern);
191        return 0;
192    }
193    
194    
195    /* Set the default language for the program.
196       The $lang.mo file is copied either to the selected
197       folder or the directory specified by @modpath.
198       The output name of the file is winpt.mo (example: de.mo -> winpt.mo). */
199    static int
200    nls_set_language (HWND dlg, const char *modpath)
201    {
202        HWND cb = GetDlgItem (dlg, IDC_LANGUAGE_LIST);
203        int pos = SendMessage (cb, CB_GETCURSEL, 0, 0);
204        const char *folder;
205        char *src, *dst;
206    
207        /* default langauge is English. */
208        if (pos == 0 || pos == CB_ERR)
209            return 0;
210    
211        folder = get_folder_dlg (dlg, _("Choose Locale Directory"), modpath);
212        if (!folder)
213            return 0;
214    
215        src = make_filename (modpath, lang_list[pos].id, "mo");
216        dst = make_filename (folder, "winpt", "mo");
217    
218        if (!CopyFile (src, dst, FALSE)) {
219            msg_box (dlg, _("Could not create winpt.mo file"),
220                     _("WinPT Error"), MB_ERR);
221            pos = -1;
222        }
223        else
224            set_reg_entry_mo (folder);
225        free_if_alloc (src);
226        free_if_alloc (dst);
227        return pos;
228    }
229    
230    
231    static BOOL CALLBACK
232    nls_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
233    {
234        static char modpath[MAX_PATH+1];
235        int langid = 0, n;
236    
237        switch (msg) {
238        case WM_INITDIALOG:
239            if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) {
240                while (n-- > 0) {
241                    if (modpath[n] == '\\') {
242                        modpath[n] = 0;
243                        break;
244                    }
245                }
246            }
247            n = nls_load_langlist (dlg, modpath);
248            if (n == -1)
249                EndDialog (dlg, -1);
250            SetWindowText (dlg, _("Native Language Support"));
251            SetDlgItemText (dlg, IDC_LANGUAGE_INFO, _("Please select a language"));
252            SetDlgItemText (dlg, IDOK, _("&OK"));
253            SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
254            center_window (dlg, NULL);
255            SetForegroundWindow (dlg);
256            break;
257    
258        case WM_COMMAND:
259            switch (LOWORD (wparam)) {
260            case IDOK:
261                langid = nls_set_language (dlg, modpath);
262                EndDialog (dlg, langid);
263                break;
264    
265            case IDCANCEL:
266                EndDialog (dlg, -1);
267                break;
268            }
269            break;
270        }
271    
272        return FALSE;
273    }
274    
275    
276    int
277    select_language (void)
278    {
279        DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_LANGUAGE, GetDesktopWindow (),
280                        nls_dlg_proc, 0);
281        return 0;
282    }
283    

Legend:
Removed from v.47  
changed lines
  Added in v.211

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26