mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-12 07:49:55 -05:00
Some Writer fixes and add methods to actually make it write.
This commit is contained in:
parent
82afd43f12
commit
707cf1bbe8
@ -18,6 +18,7 @@
|
|||||||
#include "Writer.h"
|
#include "Writer.h"
|
||||||
|
|
||||||
#include <QtCore/QBuffer>
|
#include <QtCore/QBuffer>
|
||||||
|
#include <QtCore/QFile>
|
||||||
|
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Metadata.h"
|
#include "core/Metadata.h"
|
||||||
@ -33,8 +34,10 @@ Writer::Writer(Database* db)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Writer::write(const QString& filename)
|
void Writer::write(QIODevice* device)
|
||||||
{
|
{
|
||||||
|
m_xml.setDevice(device);
|
||||||
|
|
||||||
m_xml.writeStartDocument("1.0", true);
|
m_xml.writeStartDocument("1.0", true);
|
||||||
|
|
||||||
m_xml.writeStartElement("KeePassFile");
|
m_xml.writeStartElement("KeePassFile");
|
||||||
@ -45,8 +48,13 @@ bool Writer::write(const QString& filename)
|
|||||||
m_xml.writeEndElement();
|
m_xml.writeEndElement();
|
||||||
|
|
||||||
m_xml.writeEndDocument();
|
m_xml.writeEndDocument();
|
||||||
|
}
|
||||||
|
|
||||||
return true; // TODO
|
void Writer::write(const QString& filename)
|
||||||
|
{
|
||||||
|
QFile file(filename);
|
||||||
|
file.open(QIODevice::WriteOnly);
|
||||||
|
write(&file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Writer::writeMetadata()
|
void Writer::writeMetadata()
|
||||||
@ -132,6 +140,8 @@ void Writer::writeRoot()
|
|||||||
m_xml.writeStartElement("Root");
|
m_xml.writeStartElement("Root");
|
||||||
|
|
||||||
writeGroup(m_db->rootGroup());
|
writeGroup(m_db->rootGroup());
|
||||||
|
m_xml.writeStartElement("DeletedObjects");
|
||||||
|
m_xml.writeEndElement();
|
||||||
|
|
||||||
m_xml.writeEndElement();
|
m_xml.writeEndElement();
|
||||||
}
|
}
|
||||||
@ -143,7 +153,10 @@ void Writer::writeGroup(const Group* group)
|
|||||||
writeUuid("UUID", group->uuid());
|
writeUuid("UUID", group->uuid());
|
||||||
writeString("Name", group->name());
|
writeString("Name", group->name());
|
||||||
writeNumber("IconID", group->iconNumber());
|
writeNumber("IconID", group->iconNumber());
|
||||||
writeUuid("CustomIconUUID", group->iconUuid());
|
|
||||||
|
if (!group->iconUuid().isNull()) {
|
||||||
|
writeUuid("CustomIconUUID", group->iconUuid());
|
||||||
|
}
|
||||||
writeTimes(group->timeInfo());
|
writeTimes(group->timeInfo());
|
||||||
writeBool("IsExpanded", group->isExpanded());
|
writeBool("IsExpanded", group->isExpanded());
|
||||||
writeString("DefaultAutoTypeSequence", group->defaultAutoTypeSequence());
|
writeString("DefaultAutoTypeSequence", group->defaultAutoTypeSequence());
|
||||||
@ -176,14 +189,14 @@ void Writer::writeGroup(const Group* group)
|
|||||||
|
|
||||||
writeUuid("LastTopVisibleEntry", group->lastTopVisibleEntry());
|
writeUuid("LastTopVisibleEntry", group->lastTopVisibleEntry());
|
||||||
|
|
||||||
Q_FOREACH (const Group* child, group->children()) {
|
|
||||||
writeGroup(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_FOREACH (const Entry* entry, group->entries()) {
|
Q_FOREACH (const Entry* entry, group->entries()) {
|
||||||
writeEntry(entry);
|
writeEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_FOREACH (const Group* child, group->children()) {
|
||||||
|
writeGroup(child);
|
||||||
|
}
|
||||||
|
|
||||||
m_xml.writeEndElement();
|
m_xml.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +221,9 @@ void Writer::writeEntry(const Entry* entry)
|
|||||||
|
|
||||||
writeUuid("UUID", entry->uuid());
|
writeUuid("UUID", entry->uuid());
|
||||||
writeNumber("IconID", entry->iconNumber());
|
writeNumber("IconID", entry->iconNumber());
|
||||||
writeUuid("CustomIconUUID", entry->iconUuid());
|
if (!entry->iconUuid().isNull()) {
|
||||||
|
writeUuid("CustomIconUUID", entry->iconUuid());
|
||||||
|
}
|
||||||
writeColor("ForegroundColor", entry->foregroundColor());
|
writeColor("ForegroundColor", entry->foregroundColor());
|
||||||
writeColor("BackgroundColor", entry->backgroundColor());
|
writeColor("BackgroundColor", entry->backgroundColor());
|
||||||
writeString("OverrideURL", entry->overrideUrl());
|
writeString("OverrideURL", entry->overrideUrl());
|
||||||
@ -291,7 +306,7 @@ void Writer::writeBool(const QString& qualifiedName, bool b)
|
|||||||
|
|
||||||
void Writer::writeDateTime(const QString& qualifiedName, const QDateTime& dateTime)
|
void Writer::writeDateTime(const QString& qualifiedName, const QDateTime& dateTime)
|
||||||
{
|
{
|
||||||
writeString(qualifiedName, dateTime.toString(Qt::ISODate));
|
writeString(qualifiedName, dateTime.toUTC().toString(Qt::ISODate).append('Z'));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Writer::writeUuid(const QString& qualifiedName, const Uuid& uuid)
|
void Writer::writeUuid(const QString& qualifiedName, const Uuid& uuid)
|
||||||
|
@ -37,7 +37,8 @@ class Writer : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Writer(Database* db);
|
Writer(Database* db);
|
||||||
bool write(const QString& filename);
|
void write(QIODevice* device);
|
||||||
|
void write(const QString& filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeMetadata();
|
void writeMetadata();
|
||||||
|
Loading…
Reference in New Issue
Block a user