// Field.readonly (setter) static void fieldSetReadOnly( KJSContext *context, void *object, KJSObject value ) { #if 0 FormField *field = reinterpret_cast< FormField * >( object ); bool b = value.toBoolean( context ); field->setReadOnly( b ); #else Q_UNUSED( context ); Q_UNUSED( object ); Q_UNUSED( value ); qCDebug(OkularCoreDebug) << "Not implemented: setting readonly property"; #endif }
void Form::RefreshValues(){ if ( hasDocument ){ for(int i=0; i<layout.getFieldCount(); i++){ FormField* field = layout.getField(i); field->clearValue(); field->loadValue(obj); } detail.LoadDocument(obj); } }
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::removeMostRecentlyAddedExtraField(void) { ODL_ENTER(); //#### FormField * lastField = _extraFields.getLast(); _extraFields.removeLast(); lastField->removeFromComponent(_extraArgumentsGroup); recalculateArea(); adjustFields(); if (_removeArgumentsButton) { _removeArgumentsButton->setVisible(0 < _extraFields.size()); } ODL_EXIT(); //#### } // SettingsWindow::removeMostRecentlyAddedExtraField
void SettingsWindow::buttonClicked(Button * aButton) { ODL_OBJENTER(); //#### ODL_P1("aButton = ", aButton); //#### int commandId = aButton->getCommandID(); tellAllFieldsToIgnoreNextFocusLoss(); switch (commandId) { case kConfigurationAddField : addAnExtraField(); break; case kConfigurationRemoveField : removeMostRecentlyAddedExtraField(); break; case kConfigurationOK : if (fieldsAreValid()) { exitModalState(commandId); } break; case kConfigurationFileRequest : for (size_t ii = 0, maxf = _standardFields.size(); maxf > ii; ++ii) { FormField * aField = _standardFields[static_cast<int>(ii)]; if (aField && (aField->getButton() == aButton)) { aField->performButtonAction(); break; } } break; default : exitModalState(commandId); break; } ODL_OBJEXIT(); //#### } // SettingsWindow::buttonClicked
bool JT_Register::take(const QDomElement &x) { if(!iqVerify(x, to, id())) return false; Jid from(x.attribute("from")); if(x.attribute("type") == "result") { if(d->type == 3) { d->form.clear(); d->form.setJid(from); QDomElement q = queryTag(x); for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement i = n.toElement(); if(i.isNull()) continue; if(i.tagName() == "instructions") d->form.setInstructions(tagContent(i)); else if(i.tagName() == "key") d->form.setKey(tagContent(i)); else if(i.tagName() == "x" && i.attribute("xmlns") == "jabber:x:data") { d->xdata.fromXml(i); d->hasXData = true; } else if(i.tagName() == "data" && i.attribute("xmlns") == "urn:xmpp:bob") { client()->bobManager()->append(BoBData(i)); // xep-0231 } else { FormField f; if(f.setType(i.tagName())) { f.setValue(tagContent(i)); d->form += f; } } } } setSuccess(); } else setError(x); return true; }
void Form::SaveDocument(int changedFieldId){ if ( hasDocument == false ) return; for(int i=0; i<layout.getFieldCount(); i++){ FormField* field = layout.getField(i); if ( field->controlChildId == changedFieldId ){ obj = field->storeValue(obj); } } obj = detail.StoreValuesToDocument(changedFieldId, obj); Document updatedDoc = db.createDocument(Value(obj), id); Value v = updatedDoc.getData(); LoadDocument(id, v.getObject(), true); }
// Field.value (getter) static KJSObject fieldGetValue( KJSContext *context, void *object ) { FormField *field = reinterpret_cast< FormField * >( object ); if ( field->isReadOnly() ) { KJSObject value = g_fieldCache->value( field ); if ( g_fieldCache.exists() && g_fieldCache->contains( field ) ) value = g_fieldCache->value( field ); else value = KJSString(""); qCDebug(OkularCoreDebug) << "Getting the value of a readonly field" << field->name() << ":" << value.toString( context ); return value; } switch ( field->type() ) { case FormField::FormButton: { const FormFieldButton *button = static_cast< const FormFieldButton * >( field ); Q_UNUSED( button ); // ### break; } case FormField::FormText: { const FormFieldText *text = static_cast< const FormFieldText * >( field ); return KJSString( text->text() ); } case FormField::FormChoice: { const FormFieldChoice *choice = static_cast< const FormFieldChoice * >( field ); Q_UNUSED( choice ); // ### break; } case FormField::FormSignature: { break; } } return KJSUndefined(); }
// Field.value (setter) static void fieldSetValue( KJSContext *context, void *object, KJSObject value ) { FormField *field = reinterpret_cast< FormField * >( object ); if ( field->isReadOnly() ) { // ### throw exception? qCDebug(OkularCoreDebug) << "Trying to change the readonly field" << field->name() << "to" << value.toString( context ); g_fieldCache->insert( field, value ); return; } switch ( field->type() ) { case FormField::FormButton: { FormFieldButton *button = static_cast< FormFieldButton * >( field ); Q_UNUSED( button ); // ### break; } case FormField::FormText: { FormFieldText *text = static_cast< FormFieldText * >( field ); text->setText( value.toString( context ) ); break; } case FormField::FormChoice: { FormFieldChoice *choice = static_cast< FormFieldChoice * >( field ); Q_UNUSED( choice ); // ### break; } case FormField::FormSignature: { break; } } }
void SettingsWindow::tellAllFieldsToIgnoreNextFocusLoss(void) { ODL_ENTER(); //#### if (_endpointField) { _endpointField->ignoreNextFocusLoss(); } if (_portField) { _portField->ignoreNextFocusLoss(); } if (_tagField) { _tagField->ignoreNextFocusLoss(); } for (size_t ii = 0, maxf = _standardFields.size(); maxf > ii; ++ii) { FormField * aField = _standardFields[static_cast<int>(ii)]; if (aField) { aField->ignoreNextFocusLoss(); } } for (size_t ii = 0, maxf = _extraFields.size(); maxf > ii; ++ii) { FormField * aField = _extraFields[static_cast<int>(ii)]; if (aField) { aField->ignoreNextFocusLoss(); } } ODL_EXIT(); //#### } // SettingsWindow::tellAllFieldsToIgnoreNextFocusLoss
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
void SettingsWindow::recalculateArea(void) { ODL_ENTER(); //#### int heightSoFar = _topText.getY() + _topText.getHeight() + FormField::kButtonGap; int widthSoFar = _topText.getX() + _topText.getWidth(); size_t numExtra = _extraFields.size(); if (_canSetEndpoint) { widthSoFar = jmax(widthSoFar, _endpointField->getMinimumWidth()); heightSoFar = (_endpointField->getY() + _endpointField->getHeight() + (FormField::kButtonGap / 2)); } if (_canSetPort) { widthSoFar = jmax(widthSoFar, _portField->getMinimumWidth()); heightSoFar = _portField->getY() + _portField->getHeight() + (FormField::kButtonGap / 2); } if (_canSetTag) { widthSoFar = jmax(widthSoFar, _tagField->getMinimumWidth()); heightSoFar = _tagField->getY() + _tagField->getHeight() + (FormField::kButtonGap / 2); } if (_canUseModifier && _tagModifierGroup) { //int innerHeight = static_cast<int>(_regularFont.getHeight()) + // (FormField::kButtonGap / 2); //int innerWidth = (2 * jmax(FormField::kFieldInset, FormField::kLabelInset)); _tagModifierGroup->setTopLeftPosition(FormField::kFieldInset, heightSoFar); heightSoFar = _tagModifierGroup->getY() + _tagModifierGroup->getHeight(); widthSoFar = jmax(widthSoFar, _tagModifierGroup->getX() + _tagModifierGroup->getWidth()); } for (size_t ii = 0, numDescriptors = _descriptors.size(), jj = 0; numDescriptors > ii; ++ii) { Utilities::BaseArgumentDescriptor * aDescriptor = _descriptors[ii]; if (aDescriptor) { String argName(aDescriptor->argumentName().c_str()); String argDescription(aDescriptor->argumentDescription().c_str()); if (! aDescriptor->isExtra()) { FormField * aField = _standardFields[static_cast<int>(jj)]; if (aField) { widthSoFar = jmax(widthSoFar, aField->getMinimumWidth()); heightSoFar = (aField->getY() + aField->getHeight() + (FormField::kButtonGap / 2)); ++jj; } } } } if (_extraArgumentsGroup) { int innerHeight = static_cast<int>(_regularFont.getHeight()) + (FormField::kButtonGap / 2); int innerWidth = (2 * jmax(FormField::kFieldInset, FormField::kLabelInset)); _extraArgumentsGroup->setTopLeftPosition(FormField::kFieldInset, heightSoFar); for (size_t ii = 0; numExtra > ii; ++ii) { FormField * aField = _extraFields[static_cast<int>(ii)]; aField->setY(innerHeight); innerHeight = aField->getY() + aField->getHeight() + (FormField::kButtonGap / 2); } if (0 < numExtra) { innerHeight += (3 * FormField::kButtonGap / 4); } else { innerHeight += (FormField::kButtonGap / 2); } _extraArgumentsGroup->setSize(innerWidth, innerHeight); heightSoFar = _extraArgumentsGroup->getY() + _extraArgumentsGroup->getHeight(); widthSoFar = jmax(widthSoFar, _extraArgumentsGroup->getX() + _extraArgumentsGroup->getWidth()); } BorderSize<int> cb = getContentComponentBorder(); int minW = jmax(widthSoFar, _cancelButton.getWidth() + _okButton.getWidth() + (3 * FormField::kButtonGap)); setContentComponentSize(minW + kExtraSpaceInWindow + cb.getLeftAndRight(), heightSoFar + kExtraSpaceInWindow + cb.getTopAndBottom()); ODL_EXIT(); //#### } // SettingsWindow::recalculateArea
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
void SettingsWindow::adjustFields(void) { ODL_OBJENTER(); //#### Component * content = getContentComponent(); int newButtonTop = content->getHeight() - (_cancelButton.getHeight() + FormField::kButtonGap); int newFieldWidth = content->getWidth() - (2 * FormField::kFieldInset); if (_hasFileField) { newFieldWidth -= (FormField::kButtonGap + CaptionedTextField::getFileButtonWidth()); } _cancelButton.setTopLeftPosition(getWidth() - (_cancelButton.getWidth() + FormField::kButtonGap), newButtonTop); _okButton.setTopLeftPosition(_cancelButton.getX() - (_okButton.getWidth() + FormField::kButtonGap), newButtonTop); if (_endpointField) { _endpointField->setWidth(newFieldWidth); } if (_portField) { _portField->setWidth(newFieldWidth); } if (_tagField) { _tagField->setWidth(newFieldWidth); } if (_tagModifierGroup) { int groupWidth = (_cancelButton.getX() + _cancelButton.getWidth() - (_tagModifierGroup->getX() + FormField::kButtonGap)); _tagModifierGroup->setSize(groupWidth, _tagModifierGroup->getHeight()); } if (_addArgumentsButton) { _addArgumentsButton->setTopLeftPosition(_okButton.getX() - (_addArgumentsButton->getWidth() + FormField::kButtonGap), newButtonTop); } if (_removeArgumentsButton) { _removeArgumentsButton->setTopLeftPosition(_addArgumentsButton->getX() - (_removeArgumentsButton->getWidth() + FormField::kButtonGap), newButtonTop); } for (size_t ii = 0, maxf = _standardFields.size(); maxf > ii; ++ii) { FormField * aField = _standardFields[static_cast<int>(ii)]; if (aField) { aField->setWidth(newFieldWidth); } } if (_extraArgumentsGroup) { int groupWidth = (_cancelButton.getX() + _cancelButton.getWidth() - (_extraArgumentsGroup->getX() + FormField::kButtonGap)); int innerWidth = groupWidth - (FormField::kFieldInset + (2 * FormField::kButtonGap)); for (size_t ii = 0, maxf = _extraFields.size(); maxf > ii; ++ii) { FormField * aField = _extraFields[static_cast<int>(ii)]; aField->setWidth(innerWidth); } _extraArgumentsGroup->setSize(groupWidth, _extraArgumentsGroup->getHeight()); } ODL_OBJEXIT(); //#### } // SettingsWindow::adjustFields