|
|
|
@@ -17,8 +17,8 @@
|
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <libxml/encoding.h>
|
|
|
|
|
#include <libxml/xmlwriter.h>
|
|
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
@@ -30,8 +30,8 @@ XMLExportEngine::XMLExportEngine()
|
|
|
|
|
{
|
|
|
|
|
KissCount::RegisterExportEngine(this);
|
|
|
|
|
|
|
|
|
|
_shortExt = "xml";
|
|
|
|
|
_longExt = _("KissCount XML files (*.xml)|*.xml");
|
|
|
|
|
_shortExt = ".xml";
|
|
|
|
|
_longExt = _("KissCount XML files (*.xml)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XMLExportEngine::~XMLExportEngine()
|
|
|
|
@@ -55,17 +55,17 @@ bool XMLExportEngine::SaveAccounts()
|
|
|
|
|
ESCAPE_CHARS(account.name);
|
|
|
|
|
ESCAPE_CHARS(account.number);
|
|
|
|
|
|
|
|
|
|
xmlTextWriterStartElement(_writer, (const xmlChar*) "account");
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "id", (const xmlChar*) QString::number(account.id).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "name", (const xmlChar*) account.name.toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "number", (const xmlChar*) account.number.toStdString().c_str());
|
|
|
|
|
// xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "shared", (const xmlChar*) (account.shared ? "1" : "0"));
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "blocked", (const xmlChar*) (account.blocked ? "1" : "0"));
|
|
|
|
|
// xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "default", (const xmlChar*) (account._default ? "1" : "0"));
|
|
|
|
|
// xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "is_owner", (const xmlChar*) (account.is_owner ? "1" : "0"));
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "virtual", (const xmlChar*) (account._virtual ? "1" : "0"));
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "hidden", (const xmlChar*) (account.hidden ? "1" : "0"));
|
|
|
|
|
xmlTextWriterEndElement(_writer);
|
|
|
|
|
_writer->writeStartElement("account");
|
|
|
|
|
_writer->writeAttribute("id", QString::number(account.id));
|
|
|
|
|
_writer->writeAttribute("name", account.name);
|
|
|
|
|
_writer->writeAttribute("number", account.number);
|
|
|
|
|
// _writer->writeAttribute("shared", (account.shared ? "1" : "0"));
|
|
|
|
|
_writer->writeAttribute("blocked", (account.blocked ? "1" : "0"));
|
|
|
|
|
// _writer->writeAttribute("default", (account._default ? "1" : "0"));
|
|
|
|
|
// _writer->writeAttribute("is_owner", (account.is_owner ? "1" : "0"));
|
|
|
|
|
_writer->writeAttribute("virtual", (account._virtual ? "1" : "0"));
|
|
|
|
|
_writer->writeAttribute("hidden", (account.hidden ? "1" : "0"));
|
|
|
|
|
_writer->writeEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@@ -74,15 +74,16 @@ bool XMLExportEngine::SaveAccounts()
|
|
|
|
|
bool XMLExportEngine::SaveAccountAmounts()
|
|
|
|
|
{
|
|
|
|
|
std::map<AccountAmount, double, AccountAmount>::iterator it;
|
|
|
|
|
QString v;
|
|
|
|
|
|
|
|
|
|
for(it=_accountAmounts.begin(); it!=_accountAmounts.end(); it++)
|
|
|
|
|
{
|
|
|
|
|
xmlTextWriterStartElement(_writer, (const xmlChar*) "account_amount");
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "account", (const xmlChar*) QString::number(it->first.account).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "month", "%d", it->first.month);
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "year", "%d", it->first.year);
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "amount", "%.2lf", it->second);
|
|
|
|
|
xmlTextWriterEndElement(_writer);
|
|
|
|
|
_writer->writeStartElement("account_amount");
|
|
|
|
|
_writer->writeAttribute("account", QString::number(it->first.account));
|
|
|
|
|
_writer->writeAttribute("month", QString::number(it->first.month));
|
|
|
|
|
_writer->writeAttribute("year", QString::number(it->first.year));
|
|
|
|
|
_writer->writeAttribute("amount", v.sprintf("%.2lf", it->second));
|
|
|
|
|
_writer->writeEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@@ -93,6 +94,7 @@ bool XMLExportEngine::SaveCategories()
|
|
|
|
|
Category category;
|
|
|
|
|
std::map<int, int>::iterator it;
|
|
|
|
|
int rgb;
|
|
|
|
|
QString v;
|
|
|
|
|
|
|
|
|
|
for(it=_categories.begin(); it!=_categories.end(); it++)
|
|
|
|
|
{
|
|
|
|
@@ -100,21 +102,21 @@ bool XMLExportEngine::SaveCategories()
|
|
|
|
|
|
|
|
|
|
ESCAPE_CHARS(category.name);
|
|
|
|
|
|
|
|
|
|
xmlTextWriterStartElement(_writer, (const xmlChar*) "category");
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "id", (const xmlChar*) QString::number(category.id).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "parent", (const xmlChar*) QString::number(category.parent).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "name", (const xmlChar*) category.name.toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "font", (const xmlChar*) category.font.toStdString().c_str());
|
|
|
|
|
_writer->writeStartElement("category");
|
|
|
|
|
_writer->writeAttribute("id", QString::number(category.id));
|
|
|
|
|
_writer->writeAttribute("parent", QString::number(category.parent));
|
|
|
|
|
_writer->writeAttribute("name", category.name);
|
|
|
|
|
_writer->writeAttribute("font", category.font);
|
|
|
|
|
rgb = category.backcolor.blue();
|
|
|
|
|
rgb |= category.backcolor.green() << 8;
|
|
|
|
|
rgb |= category.backcolor.red() << 16;
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "backcolor", "0x%08X", rgb);
|
|
|
|
|
_writer->writeAttribute("backcolor", v.sprintf("0x%08X", rgb));
|
|
|
|
|
rgb = category.forecolor.blue();
|
|
|
|
|
rgb |= category.forecolor.green() << 8;
|
|
|
|
|
rgb |= category.forecolor.red() << 16;
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "forecolor", "0x%08X", rgb);
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "fix_cost", (const xmlChar*) (category.fix_cost ? "1" : "0"));
|
|
|
|
|
xmlTextWriterEndElement(_writer);
|
|
|
|
|
_writer->writeAttribute("forecolor", v.sprintf("0x%08X", rgb));
|
|
|
|
|
_writer->writeAttribute("fix_cost", (category.fix_cost ? "1" : "0"));
|
|
|
|
|
_writer->writeEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@@ -123,28 +125,29 @@ bool XMLExportEngine::SaveCategories()
|
|
|
|
|
bool XMLExportEngine::SaveOperations(std::vector<Operation>* operations)
|
|
|
|
|
{
|
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
|
QString v;
|
|
|
|
|
|
|
|
|
|
for(it=operations->begin(); it!=operations->end(); it++)
|
|
|
|
|
{
|
|
|
|
|
ESCAPE_CHARS(it->description);
|
|
|
|
|
|
|
|
|
|
xmlTextWriterStartElement(_writer, (const xmlChar*) "operation");
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "id", (const xmlChar*) QString::number(it->id).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "parent", (const xmlChar*) QString::number(it->parent).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "day", "%d", it->day);
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "month", "%d", it->month);
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "year", "%d", it->year);
|
|
|
|
|
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "amount", "%.2lf", it->amount);
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "description", (const xmlChar*) it->description.toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "category", (const xmlChar*) QString::number(it->category).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "fix_cost", (const xmlChar*) (it->fix_cost ? "1" : "0"));
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "account", (const xmlChar*) QString::number(it->account).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "checked", (const xmlChar*) (it->checked ? "1" : "0"));
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "transfert", (const xmlChar*) QString::number(it->transfert).toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "formula", (const xmlChar*) it->formula.toStdString().c_str());
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "meta", (const xmlChar*) (it->meta ? "1" : "0"));
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "virtual", (const xmlChar*) (it->_virtual ? "1" : "0"));
|
|
|
|
|
xmlTextWriterEndElement(_writer);
|
|
|
|
|
_writer->writeStartElement("operation");
|
|
|
|
|
_writer->writeAttribute("id", QString::number(it->id));
|
|
|
|
|
_writer->writeAttribute("parent", QString::number(it->parent));
|
|
|
|
|
_writer->writeAttribute("day", QString::number(it->day));
|
|
|
|
|
_writer->writeAttribute("month", QString::number(it->month));
|
|
|
|
|
_writer->writeAttribute("year", QString::number(it->year));
|
|
|
|
|
_writer->writeAttribute("amount", v.sprintf("%.2lf", it->amount));
|
|
|
|
|
_writer->writeAttribute("description", it->description);
|
|
|
|
|
_writer->writeAttribute("category", QString::number(it->category));
|
|
|
|
|
_writer->writeAttribute("fix_cost", (it->fix_cost ? "1" : "0"));
|
|
|
|
|
_writer->writeAttribute("account", QString::number(it->account));
|
|
|
|
|
_writer->writeAttribute("checked", (it->checked ? "1" : "0"));
|
|
|
|
|
_writer->writeAttribute("transfert", QString::number(it->transfert));
|
|
|
|
|
_writer->writeAttribute("formula", it->formula);
|
|
|
|
|
_writer->writeAttribute("meta", (it->meta ? "1" : "0"));
|
|
|
|
|
_writer->writeAttribute("virtual", (it->_virtual ? "1" : "0"));
|
|
|
|
|
_writer->writeEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
@@ -152,37 +155,40 @@ bool XMLExportEngine::SaveOperations(std::vector<Operation>* operations)
|
|
|
|
|
|
|
|
|
|
bool XMLExportEngine::SaveFile(std::vector<Operation>* operations)
|
|
|
|
|
{
|
|
|
|
|
QFile file(_path);
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
rc = ExportEngine::SaveFile(operations);
|
|
|
|
|
|
|
|
|
|
if (!rc) return false;
|
|
|
|
|
|
|
|
|
|
_writer = xmlNewTextWriterFilename(_path.toStdString().c_str(), 0);
|
|
|
|
|
|
|
|
|
|
if (!_writer)
|
|
|
|
|
if (!file.open(QIODevice::ReadWrite))
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Error can't open the file" << std::endl;
|
|
|
|
|
std::cout << "Error can't open the file " << _path.toStdString() << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = xmlTextWriterStartDocument(_writer, 0, "UTF-8", 0);
|
|
|
|
|
_writer = new QXmlStreamWriter(&file);
|
|
|
|
|
|
|
|
|
|
if (rc < 0) return false;
|
|
|
|
|
|
|
|
|
|
xmlTextWriterStartElement(_writer, (const xmlChar*) "kisscount");
|
|
|
|
|
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "version", (const xmlChar*) "1");
|
|
|
|
|
_writer->setCodec("UTF-8");
|
|
|
|
|
_writer->setAutoFormatting(true);
|
|
|
|
|
_writer->setAutoFormattingIndent(4);
|
|
|
|
|
_writer->writeStartDocument("1.0");
|
|
|
|
|
_writer->writeStartElement("kisscount");
|
|
|
|
|
_writer->writeAttribute("version", "1");
|
|
|
|
|
|
|
|
|
|
SaveAccounts();
|
|
|
|
|
SaveAccountAmounts();
|
|
|
|
|
SaveCategories();
|
|
|
|
|
SaveOperations(operations);
|
|
|
|
|
|
|
|
|
|
xmlTextWriterEndElement(_writer);
|
|
|
|
|
_writer->writeEndElement();
|
|
|
|
|
_writer->writeEndDocument();
|
|
|
|
|
|
|
|
|
|
xmlTextWriterEndDocument(_writer);
|
|
|
|
|
file.flush();
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
xmlFreeTextWriter(_writer);
|
|
|
|
|
delete _writer;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|