Exemplo n.º 1
0
bool CValidateEmailAddress::Validate(wxWindow *parent) {
    if(!CheckValidator())
        return FALSE;

    wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;

    if (!control->IsEnabled())
        return TRUE;

    bool ok = TRUE;
    wxString val(control->GetValue().Trim().Trim(false));  // trim spaces before and after

    // Regular Expression from Frank S. Thomas
    wxRegEx reEmail(
        wxT("^([^@]+)@([^@\\.]+)\\.([^@]{2,})$"));

    if (val.Length() == 0) {
        ok = FALSE;
        m_errormsg = _("Please specify an email address");
    } else if (!reEmail.Matches(val)) {
        ok = FALSE;
        m_errormsg = _("Invalid email address; please enter a valid email address");
    }

    if (!ok) {
        wxASSERT_MSG(!m_errormsg.empty(), _T("you forgot to set errormsg"));

        m_validatorWindow->SetFocus();

        wxString buf;
        buf.Printf(m_errormsg, control->GetValue().c_str());

        wxGetApp().SafeMessageBox(buf, _("Validation conflict"),
            wxOK | wxICON_EXCLAMATION, parent
        );
    }

    return ok;
}
Exemplo n.º 2
0
void LogOutputWidget::print(const LogEntry &entry)
{
#ifdef _NDEBUG
    const QString timestamp(entry.timestamp().toString("hh:mm:ss"));
#else
    const QString timestamp(entry.timestamp().toString("hh:mm:ss:zzz"));
#endif
    //const QString timestamp(entry.timestamp().toString("hh:mm:ss"));

    m_swap->clear();
    m_swap->setFont(font());

    QString message = entry.message();

    switch(entry.type())
    {
    case LogEntry::INFORMATION_LOG:
        m_swap->textCursor().insertText(QString("%1: %2\n").arg(timestamp).arg(message), m_informationCharFormat);
        break;
    case LogEntry::WARNING_LOG:
        m_swap->textCursor().insertText(QString("%1: %2\n").arg(timestamp).arg(message), m_warningCharFormat);
        break;
    case LogEntry::ERROR_LOG:
        m_swap->textCursor().insertText(QString("%1: %2\n").arg(timestamp).arg(message), m_errorCharFormat);
        break;
    case LogEntry::DEBUG_LOG:
        m_swap->textCursor().insertText(QString("%1 %2 %3: %4\n").arg(timestamp).arg(entry.file()).arg(entry.line()).arg(message), m_debugCharFormat);
        break;
    case LogEntry::MESSAGE_LOG:
        m_swap->textCursor().insertText(QString("%1: %2\n").arg(timestamp).arg(message), m_messageCharFormat);
        break;
    case LogEntry::EMPTYLINE_LOG:
        m_swap->textCursor().insertText("\n");
        break;
    case LogEntry::WORKFLOW_LOG:
    case LogEntry::UNDEFINED_LOG:
    default:
        break;
    };

    QString htmlMessage = m_swap->toHtml();

    QRegExp reEmail("\\b([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4})\\b");
    QRegExp reLink("\\b((ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?)\\b");

    int pos = 0;
    while((pos = reEmail.indexIn(message, pos)) != -1) 
    {
        pos += reEmail.matchedLength();
        const QString email = reEmail.capturedTexts()[0];
        htmlMessage.replace(email, QString("<a href =\"mailto:%1\">%1</a>").arg(email));
    }

    pos = 0;
    while((pos = reLink.indexIn(message, pos)) != -1) 
    {
        pos += reLink.matchedLength();
        const QString link = reLink.capturedTexts()[0];
        htmlMessage.replace(link, QString("<a href =\"%1\">%1</a>").arg(link));
    }

    m_cursor->insertHtml(htmlMessage);

    ensureCursorVisible();
    update();
}