/[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 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC revision 48 by werner, Mon Oct 31 21:14:11 2005 UTC
# Line 1  Line 1 
1  /* wptCommonDlg.cpp  /* wptCommonDlg.cpp
2   *      Copyright (C) 2004 Timo Schulz   *      Copyright (C) 2004, 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    
25  #include "wptTypes.h"  #include <windows.h>
26  #include "wptW32API.h"  
27  #include "wptVersion.h"  #include "resource.h"
28  #include "wptGPG.h"  
29  #include "wptCommonCtl.h"  #include "wptTypes.h"
30  #include "wptContext.h"  #include "wptW32API.h"
31    #include "wptVersion.h"
32    #include "wptGPG.h"
33  static int  #include "wptCommonCtl.h"
34  check_URL (const char *buf)  #include "wptContext.h"
35  {  
36      /* XXX: be more strict */  
37      if (!strchr (buf, ':'))  /* check if the given buf contains a valid URL. */
38          return -1;  static int
39      if (!strstr (buf, "//"))  check_URL (const char *buf)
40          return -1;  {
41      return 0;      /* XXX: be more strict */
42  }      if (!strchr (buf, ':'))
43            return -1;
44        if (!strstr (buf, "//"))
45  static BOOL CALLBACK          return -1;
46  http_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)      return 0;
47  {  }
48      static struct URL_ctx_s * ctx;  
49      int n;  
50    static BOOL CALLBACK
51      switch (msg) {  http_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
52      case WM_INITDIALOG:  {
53          ctx = (struct URL_ctx_s*)lparam;      static struct URL_ctx_s * ctx;
54          if (!ctx)      int n;
55              BUG (0);  
56          if (ctx->desc != NULL)      switch (msg) {
57              SetWindowText (dlg, ctx->desc);      case WM_INITDIALOG:
58          if (ctx->title != NULL)          ctx = (struct URL_ctx_s*)lparam;
59              SetDlgItemText (dlg, IDC_HTTP_TITLE, ctx->title);          if (!ctx)
60          SetForegroundWindow (dlg);              BUG (0);
61          break;          if (ctx->desc != NULL)
62                SetWindowText (dlg, ctx->desc);
63      case WM_COMMAND:          if (ctx->title != NULL)
64          switch (LOWORD (wparam)) {              SetDlgItemText (dlg, IDC_HTTP_TITLE, ctx->title);
65          case IDOK:          SetForegroundWindow (dlg);
66              n = GetDlgItemText (dlg, IDC_HTTP_URL, ctx->url, DIM (ctx->url)-1);          break;
67              if (ctx->check && (!n || check_URL (ctx->url))) {  
68                  msg_box (dlg, _("Please enter a valid URL."), _("HTTP"), MB_ERR);      case WM_COMMAND:
69                  return FALSE;          switch (LOWORD (wparam)) {
70              }          case IDOK:
71              ctx->cancel = 0;              n = GetDlgItemText (dlg, IDC_HTTP_URL, ctx->url, DIM (ctx->url)-1);
72              EndDialog (dlg, TRUE);              if (ctx->check && (!n || check_URL (ctx->url))) {
73              break;                  msg_box (dlg, _("Please enter a valid URL."), "HTTP", MB_ERR);
74                    return FALSE;
75          case IDCANCEL:              }
76              ctx->cancel = 1;              ctx->cancel = 0;
77              EndDialog (dlg, FALSE);              EndDialog (dlg, TRUE);
78              break;              break;
79          }  
80      }          case IDCANCEL:
81                ctx->cancel = 1;
82      return FALSE;              EndDialog (dlg, FALSE);
83  }              break;
84            }
85        }
86  void*  
87  get_http_file_dlg (HWND root)      return FALSE;
88  {  }
89      struct URL_ctx_s *ctx;  
90    
91      ctx = new URL_ctx_s;  /* Common dialog to request a URL from the user.
92      if (!ctx)     Return value is the URL context. */
93          BUG (0);  void*
94      memset (ctx, 0, sizeof *ctx);  get_http_file_dlg (HWND root)
95      ctx->check = 1;      {
96      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,      struct URL_ctx_s *ctx;
97                      http_dlg_proc, (LPARAM)ctx);  
98      return ctx;      ctx = new URL_ctx_s;
99  }      if (!ctx)
100            BUG (0);
101        memset (ctx, 0, sizeof *ctx);
102  void*      ctx->check = 1;    
103  get_keyserver_URL_dlg (HWND root)      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
104  {                      http_dlg_proc, (LPARAM)ctx);
105      struct URL_ctx_s *ctx;      return ctx;
106    }
107      ctx = new URL_ctx_s;  
108      if (!ctx)  /* Wrapper to request a preferred keyserver from the user.
109          BUG (0);     Return value is the URL context. */
110      memset (ctx, 0, sizeof *ctx);  void*
111      ctx->check = 1;  get_keyserver_URL_dlg (HWND root)
112      ctx->desc = "Key Edit";  {
113      ctx->title = "Enter preferred keyserver URL";      struct URL_ctx_s *ctx;
114      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,  
115                      http_dlg_proc, (LPARAM)ctx);      ctx = new URL_ctx_s;
116      return ctx;      if (!ctx)
117  }          BUG (0);
118        memset (ctx, 0, sizeof *ctx);
119        ctx->check = 1;
120  char*      ctx->desc = _("Key Edit");
121  get_input_dialog (HWND root, const char *title, const char *desc)      ctx->title = _("Enter preferred keyserver URL");
122  {      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
123      struct URL_ctx_s ctx;                      http_dlg_proc, (LPARAM)ctx);
124        return ctx;
125      memset (&ctx, 0, sizeof (ctx));  }
126      ctx.title = title;  
127      ctx.desc = desc;  
128      DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,  /* Generic text input dialog. */
129                      http_dlg_proc, (LPARAM)&ctx);  char*
130      if (ctx.cancel || strlen (ctx.url) == 0)  get_input_dialog (HWND root, const char *title, const char *desc)
131          return NULL;  {
132      return m_strdup (ctx.url);      struct URL_ctx_s ctx;
133  }  
134        memset (&ctx, 0, sizeof (ctx));
135        ctx.title = title;
136        ctx.desc = desc;
137        DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_HTTP, root,
138                        http_dlg_proc, (LPARAM)&ctx);
139        if (ctx.cancel || strlen (ctx.url) == 0)
140            return NULL;
141        return m_strdup (ctx.url);
142    }

Legend:
Removed from v.22  
changed lines
  Added in v.48

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26