mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-09 11:18:39 -05:00
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:
parent
fdf600e09a
commit
00aafa69f5
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QHash>
|
||||||
#include <QtGui/QIcon>
|
|
||||||
|
|
||||||
#include "core/Uuid.h"
|
#include "core/Uuid.h"
|
||||||
#include "keys/CompositeKey.h"
|
#include "keys/CompositeKey.h"
|
||||||
|
@ -19,20 +19,40 @@
|
|||||||
|
|
||||||
#include "core/DataPath.h"
|
#include "core/DataPath.h"
|
||||||
|
|
||||||
DatabaseIcons* DatabaseIcons::m_instance(0);
|
QImage DatabaseIcons::icon(int index)
|
||||||
|
|
||||||
QIcon DatabaseIcons::icon(int index)
|
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= iconCount()) {
|
if (index < 0 || index >= iconCount()) {
|
||||||
qWarning("DatabaseIcons::icon: invalid icon index %d", index);
|
qWarning("DatabaseIcons::icon: invalid icon index %d", index);
|
||||||
return QIcon();
|
return QImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_instance) {
|
if (!m_iconCache[index].isNull()) {
|
||||||
m_instance = new DatabaseIcons();
|
return m_iconCache[index];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QString iconPath = QString("icons/database/").append(m_indexToName.at(index));
|
||||||
|
QImage icon(DataPath::getPath(iconPath));
|
||||||
|
|
||||||
|
m_iconCache[index] = icon;
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap DatabaseIcons::iconPixmap(int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= iconCount()) {
|
||||||
|
qWarning("DatabaseIcons::iconPixmap: invalid icon index %d", index);
|
||||||
|
return QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_instance->getIconInternal(index);
|
QPixmap pixmap;
|
||||||
|
|
||||||
|
if (!QPixmapCache::find(m_pixmapCacheKeys[index], &pixmap)) {
|
||||||
|
pixmap = QPixmap::fromImage(icon(index));
|
||||||
|
m_pixmapCacheKeys[index] = QPixmapCache::insert(pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DatabaseIcons::iconCount()
|
int DatabaseIcons::iconCount()
|
||||||
@ -42,6 +62,7 @@ int DatabaseIcons::iconCount()
|
|||||||
|
|
||||||
DatabaseIcons::DatabaseIcons()
|
DatabaseIcons::DatabaseIcons()
|
||||||
{
|
{
|
||||||
|
m_indexToName.reserve(iconCount());
|
||||||
m_indexToName.append("C00_Password.png");
|
m_indexToName.append("C00_Password.png");
|
||||||
m_indexToName.append("C01_Package_Network.png");
|
m_indexToName.append("C01_Package_Network.png");
|
||||||
m_indexToName.append("C02_MessageBox_Warning.png");
|
m_indexToName.append("C02_MessageBox_Warning.png");
|
||||||
@ -113,18 +134,20 @@ DatabaseIcons::DatabaseIcons()
|
|||||||
m_indexToName.append("C68_BlackBerry.png");
|
m_indexToName.append("C68_BlackBerry.png");
|
||||||
|
|
||||||
Q_ASSERT(m_indexToName.size() == iconCount());
|
Q_ASSERT(m_indexToName.size() == iconCount());
|
||||||
|
|
||||||
|
m_iconCache.reserve(iconCount());
|
||||||
|
m_iconCache.resize(iconCount());
|
||||||
|
m_pixmapCacheKeys.reserve(iconCount());
|
||||||
|
m_pixmapCacheKeys.resize(iconCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon DatabaseIcons::getIconInternal(int index)
|
DatabaseIcons* databaseIcons()
|
||||||
{
|
{
|
||||||
if (m_iconCache.contains(index)) {
|
static DatabaseIcons* instance(0);
|
||||||
return m_iconCache.value(index);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QString iconPath = QString("icons/database/").append(m_indexToName.at(index));
|
|
||||||
QIcon icon(DataPath::getPath(iconPath));
|
|
||||||
|
|
||||||
m_iconCache.insert(index, icon);
|
if (!instance) {
|
||||||
return icon;
|
instance = new DatabaseIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,28 @@
|
|||||||
#ifndef KEEPASSX_DATABASEICONS_H
|
#ifndef KEEPASSX_DATABASEICONS_H
|
||||||
#define KEEPASSX_DATABASEICONS_H
|
#define KEEPASSX_DATABASEICONS_H
|
||||||
|
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QVector>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QImage>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
#include <QtGui/QPixmapCache>
|
||||||
|
|
||||||
class DatabaseIcons
|
class DatabaseIcons
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static QIcon icon(int index);
|
QImage icon(int index);
|
||||||
static int iconCount();
|
QPixmap iconPixmap(int index);
|
||||||
|
int iconCount();
|
||||||
private:
|
|
||||||
static DatabaseIcons* m_instance;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DatabaseIcons();
|
DatabaseIcons();
|
||||||
QIcon getIconInternal(int index);
|
|
||||||
|
|
||||||
bool m_initalized;
|
QVector<QString> m_indexToName;
|
||||||
QList<QString> m_indexToName;
|
QVector<QImage> m_iconCache;
|
||||||
QHash<int,QIcon> m_iconCache;
|
QVector<QPixmapCache::Key> m_pixmapCacheKeys;
|
||||||
|
|
||||||
|
friend DatabaseIcons* databaseIcons();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DatabaseIcons* databaseIcons();
|
||||||
|
|
||||||
#endif // KEEPASSX_DATABASEICONS_H
|
#endif // KEEPASSX_DATABASEICONS_H
|
||||||
|
@ -52,10 +52,10 @@ Uuid Entry::uuid() const
|
|||||||
return m_uuid;
|
return m_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon Entry::icon() const
|
QImage Entry::icon() const
|
||||||
{
|
{
|
||||||
if (m_customIcon.isNull()) {
|
if (m_customIcon.isNull()) {
|
||||||
return DatabaseIcons::icon(m_iconNumber);
|
return databaseIcons()->icon(m_iconNumber);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO check if m_db is 0
|
// TODO check if m_db is 0
|
||||||
@ -63,6 +63,23 @@ QIcon Entry::icon() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap Entry::iconPixmap() const
|
||||||
|
{
|
||||||
|
if (m_customIcon.isNull()) {
|
||||||
|
return databaseIcons()->iconPixmap(m_iconNumber);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QPixmap pixmap;
|
||||||
|
if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
|
||||||
|
// TODO check if m_db is 0
|
||||||
|
pixmap = QPixmap::fromImage(m_db->metadata()->customIcon(m_customIcon));
|
||||||
|
*const_cast<QPixmapCache::Key*>(&m_pixmapCacheKey) = QPixmapCache::insert(pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Entry::iconNumber() const
|
int Entry::iconNumber() const
|
||||||
{
|
{
|
||||||
return m_iconNumber;
|
return m_iconNumber;
|
||||||
@ -176,6 +193,8 @@ void Entry::setIcon(int iconNumber)
|
|||||||
|
|
||||||
m_iconNumber = iconNumber;
|
m_iconNumber = iconNumber;
|
||||||
m_customIcon = Uuid();
|
m_customIcon = Uuid();
|
||||||
|
|
||||||
|
m_pixmapCacheKey = QPixmapCache::Key();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entry::setIcon(const Uuid& uuid)
|
void Entry::setIcon(const Uuid& uuid)
|
||||||
@ -184,6 +203,8 @@ void Entry::setIcon(const Uuid& uuid)
|
|||||||
|
|
||||||
m_iconNumber = 0;
|
m_iconNumber = 0;
|
||||||
m_customIcon = uuid;
|
m_customIcon = uuid;
|
||||||
|
|
||||||
|
m_pixmapCacheKey = QPixmapCache::Key();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entry::setForegroundColor(const QColor& color)
|
void Entry::setForegroundColor(const QColor& color)
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtGui/QColor>
|
#include <QtGui/QColor>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QImage>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
#include <QtGui/QPixmapCache>
|
||||||
|
|
||||||
#include "core/TimeInfo.h"
|
#include "core/TimeInfo.h"
|
||||||
#include "core/Uuid.h"
|
#include "core/Uuid.h"
|
||||||
@ -45,7 +47,8 @@ public:
|
|||||||
Entry();
|
Entry();
|
||||||
~Entry();
|
~Entry();
|
||||||
Uuid uuid() const;
|
Uuid uuid() const;
|
||||||
QIcon icon() const;
|
QImage icon() const;
|
||||||
|
QPixmap iconPixmap() const;
|
||||||
int iconNumber() const;
|
int iconNumber() const;
|
||||||
Uuid iconUuid() const;
|
Uuid iconUuid() const;
|
||||||
QColor foregroundColor() const;
|
QColor foregroundColor() const;
|
||||||
@ -125,6 +128,7 @@ private:
|
|||||||
QList<Entry*> m_history;
|
QList<Entry*> m_history;
|
||||||
QPointer<Group> m_group;
|
QPointer<Group> m_group;
|
||||||
const Database* m_db;
|
const Database* m_db;
|
||||||
|
QPixmapCache::Key m_pixmapCacheKey;
|
||||||
const static QStringList m_defaultAttibutes;
|
const static QStringList m_defaultAttibutes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,16 +55,34 @@ QString Group::notes() const
|
|||||||
return m_notes;
|
return m_notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon Group::icon() const
|
QImage Group::icon() const
|
||||||
{
|
{
|
||||||
if (m_customIcon.isNull()) {
|
if (m_customIcon.isNull()) {
|
||||||
return DatabaseIcons::icon(m_iconNumber);
|
return databaseIcons()->icon(m_iconNumber);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// TODO check if m_db is 0
|
||||||
return m_db->metadata()->customIcon(m_customIcon);
|
return m_db->metadata()->customIcon(m_customIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap Group::iconPixmap() const
|
||||||
|
{
|
||||||
|
if (m_customIcon.isNull()) {
|
||||||
|
return databaseIcons()->iconPixmap(m_iconNumber);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QPixmap pixmap;
|
||||||
|
if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
|
||||||
|
// TODO check if m_db is 0
|
||||||
|
pixmap = QPixmap::fromImage(m_db->metadata()->customIcon(m_customIcon));
|
||||||
|
*const_cast<QPixmapCache::Key*>(&m_pixmapCacheKey) = QPixmapCache::insert(pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Group::iconNumber() const
|
int Group::iconNumber() const
|
||||||
{
|
{
|
||||||
return m_iconNumber;
|
return m_iconNumber;
|
||||||
@ -129,6 +147,8 @@ void Group::setIcon(int iconNumber)
|
|||||||
m_iconNumber = iconNumber;
|
m_iconNumber = iconNumber;
|
||||||
m_customIcon = Uuid();
|
m_customIcon = Uuid();
|
||||||
|
|
||||||
|
m_pixmapCacheKey = QPixmapCache::Key();
|
||||||
|
|
||||||
Q_EMIT dataChanged(this);
|
Q_EMIT dataChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +159,8 @@ void Group::setIcon(const Uuid& uuid)
|
|||||||
m_iconNumber = 0;
|
m_iconNumber = 0;
|
||||||
m_customIcon = uuid;
|
m_customIcon = uuid;
|
||||||
|
|
||||||
|
m_pixmapCacheKey = QPixmapCache::Key();
|
||||||
|
|
||||||
Q_EMIT dataChanged(this);
|
Q_EMIT dataChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
#define KEEPASSX_GROUP_H
|
#define KEEPASSX_GROUP_H
|
||||||
|
|
||||||
#include <QtCore/QPointer>
|
#include <QtCore/QPointer>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QImage>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
#include <QtGui/QPixmapCache>
|
||||||
|
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Entry.h"
|
#include "core/Entry.h"
|
||||||
@ -38,7 +40,8 @@ public:
|
|||||||
Uuid uuid() const;
|
Uuid uuid() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QString notes() const;
|
QString notes() const;
|
||||||
QIcon icon() const;
|
QImage icon() const;
|
||||||
|
QPixmap iconPixmap() const;
|
||||||
int iconNumber() const;
|
int iconNumber() const;
|
||||||
Uuid iconUuid() const;
|
Uuid iconUuid() const;
|
||||||
TimeInfo timeInfo() const;
|
TimeInfo timeInfo() const;
|
||||||
@ -109,6 +112,7 @@ private:
|
|||||||
QList<Entry*> m_entries;
|
QList<Entry*> m_entries;
|
||||||
|
|
||||||
QPointer<Group> m_parent;
|
QPointer<Group> m_parent;
|
||||||
|
QPixmapCache::Key m_pixmapCacheKey;
|
||||||
|
|
||||||
friend void Database::setRootGroup(Group* group);
|
friend void Database::setRootGroup(Group* group);
|
||||||
friend Entry::~Entry();
|
friend Entry::~Entry();
|
||||||
|
@ -120,12 +120,12 @@ bool Metadata::autoEnableVisualHiding() const
|
|||||||
return m_autoEnableVisualHiding;
|
return m_autoEnableVisualHiding;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon Metadata::customIcon(const Uuid& uuid) const
|
QImage Metadata::customIcon(const Uuid& uuid) const
|
||||||
{
|
{
|
||||||
return m_customIcons.value(uuid);
|
return m_customIcons.value(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<Uuid, QIcon> Metadata::customIcons() const
|
QHash<Uuid, QImage> Metadata::customIcons() const
|
||||||
{
|
{
|
||||||
return m_customIcons;
|
return m_customIcons;
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ void Metadata::setAutoEnableVisualHiding(bool value)
|
|||||||
m_autoEnableVisualHiding = value;
|
m_autoEnableVisualHiding = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Metadata::addCustomIcon(const Uuid& uuid, const QIcon& icon)
|
void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!uuid.isNull());
|
Q_ASSERT(!uuid.isNull());
|
||||||
Q_ASSERT(!m_customIcons.contains(uuid));
|
Q_ASSERT(!m_customIcons.contains(uuid));
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QHash>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QImage>
|
||||||
|
|
||||||
#include "core/Uuid.h"
|
#include "core/Uuid.h"
|
||||||
|
|
||||||
@ -48,8 +48,8 @@ public:
|
|||||||
bool protectUrl() const;
|
bool protectUrl() const;
|
||||||
bool protectNotes() const;
|
bool protectNotes() const;
|
||||||
bool autoEnableVisualHiding() const;
|
bool autoEnableVisualHiding() const;
|
||||||
QIcon customIcon(const Uuid& uuid) const;
|
QImage customIcon(const Uuid& uuid) const;
|
||||||
QHash<Uuid, QIcon> customIcons() const;
|
QHash<Uuid, QImage> customIcons() const;
|
||||||
bool recycleBinEnabled() const;
|
bool recycleBinEnabled() const;
|
||||||
const Group* recycleBin() const;
|
const Group* recycleBin() const;
|
||||||
QDateTime recycleBinChanged() const;
|
QDateTime recycleBinChanged() const;
|
||||||
@ -76,7 +76,7 @@ public:
|
|||||||
void setProtectUrl(bool value);
|
void setProtectUrl(bool value);
|
||||||
void setProtectNotes(bool value);
|
void setProtectNotes(bool value);
|
||||||
void setAutoEnableVisualHiding(bool value);
|
void setAutoEnableVisualHiding(bool value);
|
||||||
void addCustomIcon(const Uuid& uuid, const QIcon& icon);
|
void addCustomIcon(const Uuid& uuid, const QImage& icon);
|
||||||
void removeCustomIcon(const Uuid& uuid);
|
void removeCustomIcon(const Uuid& uuid);
|
||||||
void setRecycleBinEnabled(bool value);
|
void setRecycleBinEnabled(bool value);
|
||||||
void setRecycleBin(Group* group);
|
void setRecycleBin(Group* group);
|
||||||
@ -113,7 +113,7 @@ private:
|
|||||||
bool m_protectNotes;
|
bool m_protectNotes;
|
||||||
bool m_autoEnableVisualHiding;
|
bool m_autoEnableVisualHiding;
|
||||||
|
|
||||||
QHash<Uuid, QIcon> m_customIcons;
|
QHash<Uuid, QImage> m_customIcons;
|
||||||
|
|
||||||
bool m_recycleBinEnabled;
|
bool m_recycleBinEnabled;
|
||||||
Group* m_recycleBin;
|
Group* m_recycleBin;
|
||||||
|
@ -227,9 +227,9 @@ void KeePass2XmlReader::parseIcon()
|
|||||||
uuid = readUuid();
|
uuid = readUuid();
|
||||||
}
|
}
|
||||||
else if (m_xml.name() == "Data") {
|
else if (m_xml.name() == "Data") {
|
||||||
QPixmap pixmap;
|
QImage icon;
|
||||||
pixmap.loadFromData(readBinary());
|
icon.loadFromData(readBinary());
|
||||||
m_meta->addCustomIcon(uuid, QIcon(pixmap));
|
m_meta->addCustomIcon(uuid, icon);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipCurrentElement();
|
skipCurrentElement();
|
||||||
@ -318,7 +318,7 @@ Group* KeePass2XmlReader::parseGroup()
|
|||||||
raiseError();
|
raiseError();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (iconId >= DatabaseIcons::iconCount()) {
|
if (iconId >= databaseIcons()->iconCount()) {
|
||||||
qWarning("KeePass2XmlReader::parseGroup: icon id \"%d\" not supported", iconId);
|
qWarning("KeePass2XmlReader::parseGroup: icon id \"%d\" not supported", iconId);
|
||||||
}
|
}
|
||||||
group->setIcon(iconId);
|
group->setIcon(iconId);
|
||||||
|
@ -107,7 +107,7 @@ void KeePass2XmlWriter::writeCustomIcons()
|
|||||||
{
|
{
|
||||||
m_xml.writeStartElement("CustomIcons");
|
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()) {
|
Q_FOREACH (const Uuid& uuid, customIcons.keys()) {
|
||||||
writeIcon(uuid, customIcons.value(uuid));
|
writeIcon(uuid, customIcons.value(uuid));
|
||||||
}
|
}
|
||||||
@ -115,18 +115,17 @@ void KeePass2XmlWriter::writeCustomIcons()
|
|||||||
m_xml.writeEndElement();
|
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");
|
m_xml.writeStartElement("Icon");
|
||||||
|
|
||||||
writeUuid("UUID", uuid);
|
writeUuid("UUID", uuid);
|
||||||
|
|
||||||
QPixmap pixmap = icon.pixmap(16, 16);
|
|
||||||
|
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
QBuffer buffer(&ba);
|
QBuffer buffer(&ba);
|
||||||
buffer.open(QIODevice::WriteOnly);
|
buffer.open(QIODevice::WriteOnly);
|
||||||
pixmap.save(&buffer, "PNG");
|
// TODO check !icon.save()
|
||||||
|
icon.save(&buffer, "PNG");
|
||||||
buffer.close();
|
buffer.close();
|
||||||
writeBinary("Data", ba);
|
writeBinary("Data", ba);
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
#include <QtCore/QXmlStreamWriter>
|
#include <QtCore/QXmlStreamWriter>
|
||||||
#include <QtGui/QColor>
|
#include <QtGui/QColor>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QImage>
|
||||||
|
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
#include "core/Entry.h"
|
#include "core/Entry.h"
|
||||||
@ -46,7 +46,7 @@ private:
|
|||||||
void writeMetadata();
|
void writeMetadata();
|
||||||
void writeMemoryProtection();
|
void writeMemoryProtection();
|
||||||
void writeCustomIcons();
|
void writeCustomIcons();
|
||||||
void writeIcon(const Uuid& uuid, const QIcon& icon);
|
void writeIcon(const Uuid& uuid, const QImage& icon);
|
||||||
void writeCustomData();
|
void writeCustomData();
|
||||||
void writeCustomDataItem(const QString& key, const QString& value);
|
void writeCustomDataItem(const QString& key, const QString& value);
|
||||||
void writeRoot();
|
void writeRoot();
|
||||||
|
@ -85,7 +85,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((role == Qt::DecorationRole) && (index.column() == 0)) {
|
else if ((role == Qt::DecorationRole) && (index.column() == 0)) {
|
||||||
return entry->icon();
|
return entry->iconPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -109,7 +109,7 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const
|
|||||||
return group->name();
|
return group->name();
|
||||||
}
|
}
|
||||||
else if (role == Qt::DecorationRole) {
|
else if (role == Qt::DecorationRole) {
|
||||||
return group->icon();
|
return group->iconPixmap();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -105,11 +105,13 @@ void TestKeePass2XmlReader::testCustomIcons()
|
|||||||
QCOMPARE(m_db->metadata()->customIcons().size(), 1);
|
QCOMPARE(m_db->metadata()->customIcons().size(), 1);
|
||||||
Uuid uuid = Uuid::fromBase64("++vyI+daLk6omox4a6kQGA==");
|
Uuid uuid = Uuid::fromBase64("++vyI+daLk6omox4a6kQGA==");
|
||||||
QVERIFY(m_db->metadata()->customIcons().contains(uuid));
|
QVERIFY(m_db->metadata()->customIcons().contains(uuid));
|
||||||
QIcon icon = m_db->metadata()->customIcon(uuid);
|
QImage icon = m_db->metadata()->customIcon(uuid);
|
||||||
QImage img = icon.pixmap(16, 16).toImage();
|
QCOMPARE(icon.width(), 16);
|
||||||
|
QCOMPARE(icon.height(), 16);
|
||||||
|
|
||||||
for (int x=0; x<16; x++) {
|
for (int x=0; x<16; x++) {
|
||||||
for (int y=0; y<16; y++) {
|
for (int y=0; y<16; y++) {
|
||||||
QRgb rgb = img.pixel(x, y);
|
QRgb rgb = icon.pixel(x, y);
|
||||||
QCOMPARE(qRed(rgb), 128);
|
QCOMPARE(qRed(rgb), 128);
|
||||||
QCOMPARE(qGreen(rgb), 0);
|
QCOMPARE(qGreen(rgb), 0);
|
||||||
QCOMPARE(qBlue(rgb), 128);
|
QCOMPARE(qBlue(rgb), 128);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user