Store database icons as QImage instead of QIcon.

This has the advantage that they can be used without a running X server.
Add methods to retrieve QPixmaps that are converted from the stored QImages
and cached by QPixmapCache.
This commit is contained in:
Felix Geyer committed 2012-01-01 21:52:54 +01:00
1 parent fdf600e09a
commit 00aafa69f5
15 files changed
+137 -60

No files matched your search

+4 -4
View File
@@ -227,9 +227,9 @@ void KeePass2XmlReader::parseIcon()
uuid = readUuid();
}
else if (m_xml.name() == "Data") {
QPixmap pixmap;
pixmap.loadFromData(readBinary());
m_meta->addCustomIcon(uuid, QIcon(pixmap));
QImage icon;
icon.loadFromData(readBinary());
m_meta->addCustomIcon(uuid, icon);
}
else {
skipCurrentElement();
@@ -318,7 +318,7 @@ Group* KeePass2XmlReader::parseGroup()
raiseError();
}
else {
if (iconId >= DatabaseIcons::iconCount()) {
if (iconId >= databaseIcons()->iconCount()) {
qWarning("KeePass2XmlReader::parseGroup: icon id \"%d\" not supported", iconId);
}
group->setIcon(iconId);
+4 -5
View File
@@ -107,7 +107,7 @@ void KeePass2XmlWriter::writeCustomIcons()
{
m_xml.writeStartElement("CustomIcons");
QHash<Uuid, QIcon> customIcons = m_meta->customIcons();
QHash<Uuid, QImage> customIcons = m_meta->customIcons();
Q_FOREACH (const Uuid& uuid, customIcons.keys()) {
writeIcon(uuid, customIcons.value(uuid));
}
@@ -115,18 +115,17 @@ void KeePass2XmlWriter::writeCustomIcons()
m_xml.writeEndElement();
}
void KeePass2XmlWriter::writeIcon(const Uuid& uuid, const QIcon& icon)
void KeePass2XmlWriter::writeIcon(const Uuid& uuid, const QImage& icon)
{
m_xml.writeStartElement("Icon");
writeUuid("UUID", uuid);
QPixmap pixmap = icon.pixmap(16, 16);
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");
// TODO check !icon.save()
icon.save(&buffer, "PNG");
buffer.close();
writeBinary("Data", ba);
+2 -2
View File
@@ -21,7 +21,7 @@
#include <QtCore/QDateTime>
#include <QtCore/QXmlStreamWriter>
#include <QtGui/QColor>
#include <QtGui/QIcon>
#include <QtGui/QImage>
#include "core/Database.h"
#include "core/Entry.h"
@@ -46,7 +46,7 @@ private:
void writeMetadata();
void writeMemoryProtection();
void writeCustomIcons();
void writeIcon(const Uuid& uuid, const QIcon& icon);
void writeIcon(const Uuid& uuid, const QImage& icon);
void writeCustomData();
void writeCustomDataItem(const QString& key, const QString& value);
void writeRoot();