TextProtocol now allows specifying the end-of-line symbol
Fixes Issue 18
This commit is contained in:
parent
a6c1166a78
commit
599e591907
@ -49,7 +49,7 @@ private:
|
|||||||
// Native file format version
|
// Native file format version
|
||||||
static const uint kFileFormatVersionMajor = 0;
|
static const uint kFileFormatVersionMajor = 0;
|
||||||
static const uint kFileFormatVersionMinor = 1;
|
static const uint kFileFormatVersionMinor = 1;
|
||||||
static const uint kFileFormatVersionRevision = 0;
|
static const uint kFileFormatVersionRevision = 1;
|
||||||
|
|
||||||
void initFileMetaData(OstProto::FileMetaData &metaData);
|
void initFileMetaData(OstProto::FileMetaData &metaData);
|
||||||
};
|
};
|
||||||
|
@ -107,6 +107,7 @@ AbstractProtocol::FieldFlags TextProtocol::fieldFlags(int index) const
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case textProto_portNum:
|
case textProto_portNum:
|
||||||
|
case textProto_eol:
|
||||||
case textProto_encoding:
|
case textProto_encoding:
|
||||||
flags &= ~FrameField;
|
flags &= ~FrameField;
|
||||||
flags |= MetaField;
|
flags |= MetaField;
|
||||||
@ -136,8 +137,18 @@ QVariant TextProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
return QString().fromStdString(data.text());
|
return QString().fromStdString(data.text());
|
||||||
case FieldFrameValue:
|
case FieldFrameValue:
|
||||||
|
{
|
||||||
|
QString text;
|
||||||
Q_ASSERT(data.encoding() == OstProto::TextProtocol::kUtf8);
|
Q_ASSERT(data.encoding() == OstProto::TextProtocol::kUtf8);
|
||||||
return QString().fromStdString(data.text()).toUtf8();
|
text = QString().fromStdString(data.text());
|
||||||
|
|
||||||
|
if (data.eol() == OstProto::TextProtocol::kCrLf)
|
||||||
|
text.replace('\n', "\r\n");
|
||||||
|
else if (data.eol() == OstProto::TextProtocol::kCr)
|
||||||
|
text.replace('\n', '\r');
|
||||||
|
|
||||||
|
return text.toUtf8();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -157,6 +168,17 @@ QVariant TextProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case textProto_eol:
|
||||||
|
{
|
||||||
|
switch(attrib)
|
||||||
|
{
|
||||||
|
case FieldValue:
|
||||||
|
return data.eol();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case textProto_encoding:
|
case textProto_encoding:
|
||||||
{
|
{
|
||||||
switch(attrib)
|
switch(attrib)
|
||||||
@ -200,6 +222,15 @@ bool TextProtocol::setFieldData(int index, const QVariant &value,
|
|||||||
data.set_port_num(portNum);
|
data.set_port_num(portNum);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case textProto_eol:
|
||||||
|
{
|
||||||
|
uint eol = value.toUInt(&isOk);
|
||||||
|
if (isOk && data.EndOfLine_IsValid(eol))
|
||||||
|
data.set_eol((OstProto::TextProtocol::EndOfLine) eol);
|
||||||
|
else
|
||||||
|
isOk = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case textProto_encoding:
|
case textProto_encoding:
|
||||||
{
|
{
|
||||||
uint enc = value.toUInt(&isOk);
|
uint enc = value.toUInt(&isOk);
|
||||||
@ -243,6 +274,8 @@ void TextProtocol::loadConfigWidget()
|
|||||||
|
|
||||||
configForm->portNumCombo->setValue(
|
configForm->portNumCombo->setValue(
|
||||||
fieldData(textProto_portNum, FieldValue).toUInt());
|
fieldData(textProto_portNum, FieldValue).toUInt());
|
||||||
|
configForm->eolCombo->setCurrentIndex(
|
||||||
|
fieldData(textProto_eol, FieldValue).toUInt());
|
||||||
configForm->encodingCombo->setCurrentIndex(
|
configForm->encodingCombo->setCurrentIndex(
|
||||||
fieldData(textProto_encoding, FieldValue).toUInt());
|
fieldData(textProto_encoding, FieldValue).toUInt());
|
||||||
configForm->protoText->setText(
|
configForm->protoText->setText(
|
||||||
@ -254,6 +287,7 @@ void TextProtocol::storeConfigWidget()
|
|||||||
configWidget();
|
configWidget();
|
||||||
|
|
||||||
setFieldData(textProto_portNum, configForm->portNumCombo->currentValue());
|
setFieldData(textProto_portNum, configForm->portNumCombo->currentValue());
|
||||||
|
setFieldData(textProto_eol, configForm->eolCombo->currentIndex());
|
||||||
setFieldData(textProto_encoding, configForm->encodingCombo->currentIndex());
|
setFieldData(textProto_encoding, configForm->encodingCombo->currentIndex());
|
||||||
|
|
||||||
setFieldData(textProto_text, configForm->protoText->toPlainText());
|
setFieldData(textProto_text, configForm->protoText->toPlainText());
|
||||||
|
@ -27,7 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
TextProtocol Protocol Frame Format -
|
TextProtocol Protocol Frame Format -
|
||||||
specified text encoded with the specified encoding
|
specified text with the specified line ending and encoded with the
|
||||||
|
specified encoding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class TextProtocolConfigForm : public QWidget, public Ui::TextProtocol
|
class TextProtocolConfigForm : public QWidget, public Ui::TextProtocol
|
||||||
@ -50,6 +51,7 @@ private:
|
|||||||
|
|
||||||
// Meta Fields
|
// Meta Fields
|
||||||
textProto_portNum,
|
textProto_portNum,
|
||||||
|
textProto_eol,
|
||||||
textProto_encoding,
|
textProto_encoding,
|
||||||
|
|
||||||
textProto_fieldCount
|
textProto_fieldCount
|
||||||
|
@ -26,10 +26,17 @@ message TextProtocol {
|
|||||||
enum TextEncoding {
|
enum TextEncoding {
|
||||||
kUtf8 = 0;
|
kUtf8 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum EndOfLine {
|
||||||
|
kCr = 0;
|
||||||
|
kLf = 1;
|
||||||
|
kCrLf = 2;
|
||||||
|
}
|
||||||
|
|
||||||
optional uint32 port_num = 1 [default = 80];
|
optional uint32 port_num = 1 [default = 80];
|
||||||
optional TextEncoding encoding = 2 [default = kUtf8];
|
optional TextEncoding encoding = 2 [default = kUtf8];
|
||||||
optional string text = 3;
|
optional string text = 3;
|
||||||
|
optional EndOfLine eol = 4 [default = kLf];
|
||||||
}
|
}
|
||||||
|
|
||||||
extend Protocol {
|
extend Protocol {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>493</width>
|
<width>535</width>
|
||||||
<height>300</height>
|
<height>300</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -33,7 +33,36 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="2" >
|
||||||
|
<widget class="QLabel" name="label_3" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Line Ending</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="3" >
|
<item row="0" column="3" >
|
||||||
|
<widget class="QComboBox" name="eolCombo" >
|
||||||
|
<property name="currentIndex" >
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>CR</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>LF</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>CRLF</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="4" >
|
||||||
<widget class="QLabel" name="label" >
|
<widget class="QLabel" name="label" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>Encode as</string>
|
<string>Encode as</string>
|
||||||
@ -43,7 +72,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="4" >
|
<item row="0" column="5" >
|
||||||
<widget class="QComboBox" name="encodingCombo" >
|
<widget class="QComboBox" name="encodingCombo" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
|
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
|
||||||
@ -58,7 +87,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="5" >
|
<item row="1" column="0" colspan="6" >
|
||||||
<widget class="QTextEdit" name="protoText" >
|
<widget class="QTextEdit" name="protoText" >
|
||||||
<property name="acceptRichText" >
|
<property name="acceptRichText" >
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
Loading…
Reference in New Issue
Block a user