2004-09-22 21:53:07 +00:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
// Revision History:
|
|
|
|
//
|
|
|
|
// $Log$
|
2004-12-08 00:40:19 +00:00
|
|
|
// Revision 1.7 2004/12/08 00:39:12 ballen
|
|
|
|
// Moved RCSID strings to the end of all .c, .C and .cpp files as per
|
|
|
|
// David's request.
|
|
|
|
//
|
2004-12-02 20:17:34 +00:00
|
|
|
// Revision 1.6 2004/12/02 20:17:34 rwalton
|
|
|
|
// *** empty log message ***
|
|
|
|
//
|
2004-11-22 19:17:13 +00:00
|
|
|
// Revision 1.5 2004/11/22 19:17:06 davea
|
|
|
|
// *** empty log message ***
|
|
|
|
//
|
2004-10-26 16:58:34 +00:00
|
|
|
// Revision 1.4 2004/10/26 16:58:34 rwalton
|
|
|
|
// *** empty log message ***
|
|
|
|
//
|
2004-10-22 16:06:10 +00:00
|
|
|
// Revision 1.3 2004/10/22 16:06:10 rwalton
|
|
|
|
// *** empty log message ***
|
|
|
|
//
|
2004-09-30 20:32:16 +00:00
|
|
|
// Revision 1.2 2004/09/30 20:32:15 davea
|
|
|
|
// *** empty log message ***
|
|
|
|
//
|
2004-09-22 21:53:07 +00:00
|
|
|
// Revision 1.1 2004/09/22 21:53:05 rwalton
|
|
|
|
// *** empty log message ***
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
2004-09-30 20:32:16 +00:00
|
|
|
#pragma implementation "ValidateURL.h"
|
2004-09-22 21:53:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
|
|
|
#include "ValidateURL.h"
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CValidateURL, wxValidator)
|
|
|
|
|
|
|
|
|
|
|
|
CValidateURL::CValidateURL(wxString *val)
|
|
|
|
{
|
|
|
|
m_stringValue = val ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CValidateURL::CValidateURL(const CValidateURL& val)
|
|
|
|
: wxValidator()
|
|
|
|
{
|
|
|
|
Copy(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CValidateURL::~CValidateURL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CValidateURL::Copy(const CValidateURL& val)
|
|
|
|
{
|
|
|
|
wxValidator::Copy(val);
|
|
|
|
|
|
|
|
m_stringValue = val.m_stringValue ;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CValidateURL::Validate(wxWindow *parent)
|
|
|
|
{
|
|
|
|
if( !CheckValidator() )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
|
|
|
|
|
|
|
|
if ( !control->IsEnabled() )
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
wxURL val(control->GetValue());
|
|
|
|
|
|
|
|
bool ok = TRUE;
|
|
|
|
|
|
|
|
if ( wxURL_NOERR != val.GetError() )
|
|
|
|
{
|
|
|
|
ok = FALSE;
|
|
|
|
|
|
|
|
if ( wxURL_SNTXERR == val.GetError() )
|
2004-11-22 19:17:13 +00:00
|
|
|
m_errormsg = _("No URL supplied; please enter a valid project URL.");
|
2004-09-22 21:53:07 +00:00
|
|
|
else if ( wxURL_NOPROTO == val.GetError() )
|
2004-11-22 19:17:13 +00:00
|
|
|
m_errormsg = _("'%s' does not start with http://");
|
2004-09-22 21:53:07 +00:00
|
|
|
else if ( wxURL_NOHOST == val.GetError() )
|
2004-11-22 19:17:13 +00:00
|
|
|
m_errormsg = _("'%s' does not contain a valid host name.");
|
2004-09-22 21:53:07 +00:00
|
|
|
else if ( wxURL_NOPATH == val.GetError() )
|
|
|
|
m_errormsg = _("'%s' does not contain a valid path.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( !m_errormsg.empty(), _T("you forgot to set errormsg") );
|
|
|
|
|
|
|
|
m_validatorWindow->SetFocus();
|
|
|
|
|
|
|
|
wxString buf;
|
2004-10-26 16:58:34 +00:00
|
|
|
buf.Printf(m_errormsg, control->GetValue().c_str());
|
2004-09-22 21:53:07 +00:00
|
|
|
|
|
|
|
wxMessageBox(buf, _("Validation conflict"),
|
|
|
|
wxOK | wxICON_EXCLAMATION, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CValidateURL::TransferToWindow(void)
|
|
|
|
{
|
|
|
|
if( !CheckValidator() )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!m_stringValue)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
|
|
|
|
control->SetValue(* m_stringValue) ;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CValidateURL::TransferFromWindow(void)
|
|
|
|
{
|
|
|
|
if( !CheckValidator() )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!m_stringValue)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
|
|
|
|
* m_stringValue = control->GetValue() ;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CValidateURL::CheckValidator() const
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( m_validatorWindow, FALSE,
|
|
|
|
_T("No window associated with validator") );
|
|
|
|
wxCHECK_MSG( m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)), FALSE,
|
|
|
|
_T("wxTextValidator is only for wxTextCtrl's") );
|
|
|
|
wxCHECK_MSG( m_stringValue, FALSE,
|
|
|
|
_T("No variable storage for validator") );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
static volatile const char __attribute__((unused)) *BOINCrcsid="$Id$";
|
|
|
|
#else
|
|
|
|
static volatile const char *BOINCrcsid="$Id$";
|
|
|
|
#endif
|