示例#1
0
文件: Form.cpp 项目: jennmat/Cinch
Object Form::serializeFormToObject(Object obj){
	
	Array fields;
	for(int i=0; i<layout.getFieldCount(); i++){
		FormField* fld = layout.getField(i);
		fields.push_back(fld->getName());
	}

	obj["fields"] = fields;

	obj["tabs"] = detail.serializeUIElements();
	obj["cinch_type"] = "template";
	return obj;
}
void
SettingsWindow::reportErrorInField(FormField & fieldOfInterest)
{
    ODL_OBJENTER(); //####
    ODL_P1("fieldOfInterest = ", &fieldOfInterest); //####
    String nameToDisplay;

    if (&fieldOfInterest == _endpointField)
    {
        nameToDisplay = "Endpoint";
    }
    else if (&fieldOfInterest == _portField)
    {
        nameToDisplay = "Port";
    }
    else
    {
        nameToDisplay = fieldOfInterest.getName();
    }
    AlertWindow::showMessageBox(AlertWindow::WarningIcon, getName(),
                                String("The ") + nameToDisplay + " argument is invalid.\n"
                                "Please correct the argument and try again.", String::empty, this);
    ODL_OBJEXIT(); //####
} // SettingsWindow::reportErrorInField
bool
SettingsWindow::fieldsAreValid(void)
{
    ODL_ENTER(); //####
    int    badCount = 0;
    String badArgs;
    String primaryChannel;

    // Counterintuitively, we check the values from the descriptors first, before checking the
    // endpoint, port or tag values.
    _argsToUse.clear();
    for (size_t ii = 0, maxf = _standardFields.size(); maxf > ii; ++ii)
    {
        FormField * aField = _standardFields[static_cast<int>(ii)];

        if (aField && (! aField->validateField(_argsToUse)))
        {
            if (0 < badArgs.length())
            {
                badArgs += "\n";
            }
            badArgs += aField->getName();
            ++badCount;
        }
    }
    if (0 == badCount)
    {
        // Add the extra arguments here.
        for (size_t ii = 0, maxf = _extraFields.size(); maxf > ii; ++ii)
        {
            FormField * aField = _extraFields[static_cast<int>(ii)];

            _argsToUse.add(aField->getText());
        }
    }
    if (_canSetEndpoint)
    {
        if (_endpointField->validateField())
        {
            _endpointToUse = _endpointField->getText();
        }
        else
        {
            if (0 < badArgs.length())
            {
                badArgs += "\n";
            }
            badArgs += "Endpoint";
            ++badCount;
        }
    }
    if (_canSetPort)
    {
        if (_portField->validateField())
        {
            _portToUse = _portField->getText();
        }
        else
        {
            if (0 < badArgs.length())
            {
                badArgs += "\n";
            }
            badArgs += "Port";
            ++badCount;
        }
    }
    if (_canSetTag)
    {
        _tagToUse = _tagField->getText();
    }
    if (_canUseModifier)
    {
        // Determine which of the radio buttons has been selected.
        for (int ii = 0, maxb = _tagModifierGroup->getNumChildComponents(); maxb > ii; ++ii)
        {
            ToggleButton * tb =
                        reinterpret_cast<ToggleButton *>(_tagModifierGroup->getChildComponent(ii));

            if (tb && tb->getToggleState())
            {
                string       id(tb->getComponentID().toStdString());
                const char * startPtr = id.c_str();
                char *       endPtr;
                int          intValue = static_cast<int>(strtol(startPtr, &endPtr, 10));

                if ((startPtr != endPtr) && (! *endPtr))
                {
                    _tagModifierCount = intValue;
                }
                else
                {
                    _tagModifierCount = 0;
                }
            }
        }
    }
    if (0 < badCount)
    {
        String message1((1 < badCount) ? "arguments are" : "argument is");
        String message2((1 < badCount) ? "arguments" : "argument");

        AlertWindow::showMessageBox(AlertWindow::WarningIcon, getName(),
                                    String("The following ") + message1 + " invalid:\n" + badArgs +
                                    "\n" + String("Please correct the ") + message2 + " to the " +
                                    _execType + " and try again.", String::empty, this);
    }
    ODL_EXIT_B(0 == badCount); //####
    return (0 == badCount);
} // SettingsWindow::fieldsAreValid