TextProtocol now allows specifying the end-of-line symbol

Fixes Issue 18
This commit is contained in:
Srivats P. 2010-11-04 23:05:26 +05:30
parent a6c1166a78
commit 599e591907
5 changed files with 78 additions and 6 deletions

View File

@ -49,7 +49,7 @@ private:
// Native file format version
static const uint kFileFormatVersionMajor = 0;
static const uint kFileFormatVersionMinor = 1;
static const uint kFileFormatVersionRevision = 0;
static const uint kFileFormatVersionRevision = 1;
void initFileMetaData(OstProto::FileMetaData &metaData);
};

View File

@ -107,6 +107,7 @@ AbstractProtocol::FieldFlags TextProtocol::fieldFlags(int index) const
break;
case textProto_portNum:
case textProto_eol:
case textProto_encoding:
flags &= ~FrameField;
flags |= MetaField;
@ -136,8 +137,18 @@ QVariant TextProtocol::fieldData(int index, FieldAttrib attrib,
case FieldTextValue:
return QString().fromStdString(data.text());
case FieldFrameValue:
{
QString text;
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:
break;
}
@ -157,6 +168,17 @@ QVariant TextProtocol::fieldData(int index, FieldAttrib attrib,
}
break;
}
case textProto_eol:
{
switch(attrib)
{
case FieldValue:
return data.eol();
default:
break;
}
break;
}
case textProto_encoding:
{
switch(attrib)
@ -200,6 +222,15 @@ bool TextProtocol::setFieldData(int index, const QVariant &value,
data.set_port_num(portNum);
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:
{
uint enc = value.toUInt(&isOk);
@ -243,6 +274,8 @@ void TextProtocol::loadConfigWidget()
configForm->portNumCombo->setValue(
fieldData(textProto_portNum, FieldValue).toUInt());
configForm->eolCombo->setCurrentIndex(
fieldData(textProto_eol, FieldValue).toUInt());
configForm->encodingCombo->setCurrentIndex(
fieldData(textProto_encoding, FieldValue).toUInt());
configForm->protoText->setText(
@ -254,6 +287,7 @@ void TextProtocol::storeConfigWidget()
configWidget();
setFieldData(textProto_portNum, configForm->portNumCombo->currentValue());
setFieldData(textProto_eol, configForm->eolCombo->currentIndex());
setFieldData(textProto_encoding, configForm->encodingCombo->currentIndex());
setFieldData(textProto_text, configForm->protoText->toPlainText());

View File

@ -27,7 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
/*
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
@ -50,6 +51,7 @@ private:
// Meta Fields
textProto_portNum,
textProto_eol,
textProto_encoding,
textProto_fieldCount

View File

@ -26,10 +26,17 @@ message TextProtocol {
enum TextEncoding {
kUtf8 = 0;
}
enum EndOfLine {
kCr = 0;
kLf = 1;
kCrLf = 2;
}
optional uint32 port_num = 1 [default = 80];
optional TextEncoding encoding = 2 [default = kUtf8];
optional string text = 3;
optional EndOfLine eol = 4 [default = kLf];
}
extend Protocol {

View File

@ -5,7 +5,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<width>535</width>
<height>300</height>
</rect>
</property>
@ -33,7 +33,36 @@
</property>
</widget>
</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" >
<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" >
<property name="text" >
<string>Encode as</string>
@ -43,7 +72,7 @@
</property>
</widget>
</item>
<item row="0" column="4" >
<item row="0" column="5" >
<widget class="QComboBox" name="encodingCombo" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
@ -58,7 +87,7 @@
</item>
</widget>
</item>
<item row="1" column="0" colspan="5" >
<item row="1" column="0" colspan="6" >
<widget class="QTextEdit" name="protoText" >
<property name="acceptRichText" >
<bool>false</bool>