1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwZwStringList.cpp
22 * @brief String list encoding widget.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwZwStringList.h"
30 #include <QDataStream>
33 #include <QVBoxLayout>
34 #include <QPushButton>
37 KwZwStringList::KwZwStringList()
39 , m_edit(new QLineEdit(this))
40 , m_output(new QTextEdit(this))
42 QVBoxLayout
* layout
= new QVBoxLayout(this);
43 layout
->addWidget(m_edit
);
45 QPushButton
* btnAdd
= new QPushButton(i18n("Add string"), this);
46 layout
->addWidget(btnAdd
);
47 connect(btnAdd
, SIGNAL(clicked(bool)), this, SLOT(addItem()));
49 layout
->addWidget(m_output
);
50 m_output
->setReadOnly(true);
53 QByteArray
KwZwStringList::encodeList(const QStringList
& stringlist
)
58 QByteArray type
= "Strings";
59 result
.append((char)type
.size());
62 // Not sure what this byte is for, perhaps the number of bytes to represent something
64 result
.append((char)0x01);
67 foreach (QString item
, stringlist
)
69 /// @todo Check the assumption that lines are encoded in utf-8
70 QByteArray encoded
= item
.toUtf8();
71 /// @todo Find what to do if length >= 255
72 Q_ASSERT(encoded
.size() < 255);
73 // Length followed by string encoding
75 char size
= encoded
.size();
76 result
.append(QByteArray::fromRawData(&size
, 1));
77 result
.append(encoded
);
83 void KwZwStringList::addItem()
85 m_list
+= m_edit
->text();
87 m_output
->setText(m_list
.join("\n"));
89 QByteArray result
= encodeList(m_list
);
92 op
.open(QIODevice::WriteOnly
);
96 QFile
op("dump.base64");
97 op
.open(QIODevice::WriteOnly
);
98 op
.write(result
.toBase64());