Add built-in icons.

This commit is contained in:
Felix Geyer 2010-09-19 21:22:24 +02:00
parent b639c43b24
commit 567dd92d4c
88 changed files with 243 additions and 51 deletions

23
COPYING
View File

@ -10,3 +10,26 @@ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
--------------------------------------------------------------------
Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135
Name: KeePassX
Maintainer: Felix Geyer <debfx@fobos.de>
Source: http://www.keepassx.org/
Copyright: 2010, Felix Geyer <debfx@fobos.de>
License: GPL-2 or GPL-3
Files: cmake/FindLibgcrypt.cmake
Copyright: 2006, Pino Toscano <toscano.pino@tiscali.it>
2008, Modestas Vainius <modestas@vainius.eu>
License: BSD
Files: share/icons/entries/*.png
Copyright: 2003-2004, David Vignoni <david@icon-king.com>
License: LGPL-2.1
Files: tests/modeltest.*
Copyright: 2007, Trolltech ASA
License: GPL-2

Binary file not shown.

After

Width:  |  Height:  |  Size: 949 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 937 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 914 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 964 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 874 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1002 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1022 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 897 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 960 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1020 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 987 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 980 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 913 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 954 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 865 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 972 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 883 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 922 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 954 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

View File

@ -19,6 +19,7 @@ configure_file( config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepa
set(keepassx_SOURCES
core/Database.cpp
core/DatabaseIcons.cpp
core/Endian.cpp
core/Entry.cpp
core/Group.cpp

View File

@ -1,3 +1,5 @@
/* config-keepassx.h. Generated by cmake from config-keepassx.h.cmake */
#define KEEPASSX_VERSION "${KEEPASSX_VERSION}"
#define KEEPASSX_SOURCE_DIR "${CMAKE_SOURCE_DIR}"

View File

@ -48,15 +48,9 @@ Metadata* Database::metadata()
return m_metadata;
}
QImage Database::icon(int number)
const Metadata* Database::metadata() const
{
// TODO implement
return QImage();
}
QImage Database::customIcon(const Uuid& uuid) const
{
return m_customIcons[uuid];
return m_metadata;
}
Entry* Database::resolveEntry(const Uuid& uuid)

View File

@ -21,7 +21,7 @@
#include "Group.h"
#include <QtCore/QHash>
#include <QtGui/QImage>
#include <QtGui/QIcon>
class Metadata;
@ -41,8 +41,7 @@ public:
const Group* rootGroup() const;
void setRootGroup(Group* group);
Metadata* metadata();
static QImage icon(int number);
QImage customIcon(const Uuid& uuid) const;
const Metadata* metadata() const;
Entry* resolveEntry(const Uuid& uuid);
Group* resolveGroup(const Uuid& uuid);
QList<DeletedObject> deletedObjects();
@ -61,7 +60,6 @@ private:
Metadata* m_metadata;
Group* m_rootGroup;
QHash<Uuid, QImage> m_customIcons;
QList<DeletedObject> m_deletedObjects;
};

128
src/core/DatabaseIcons.cpp Normal file
View File

@ -0,0 +1,128 @@
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config-keepassx.h"
#include "DatabaseIcons.h"
DatabaseIcons* DatabaseIcons::m_instance(0);
QIcon DatabaseIcons::icon(int index)
{
if (index >= iconCount()) {
return QIcon();
}
if (!m_instance) {
m_instance = new DatabaseIcons();
}
return m_instance->getIconInternal(index);
}
int DatabaseIcons::iconCount()
{
return 69;
}
DatabaseIcons::DatabaseIcons()
{
m_indexToName.append("C00_Password.png");
m_indexToName.append("C01_Package_Network.png");
m_indexToName.append("C02_MessageBox_Warning.png");
m_indexToName.append("C03_Server.png");
m_indexToName.append("C04_Klipper.png");
m_indexToName.append("C05_Edu_Languages.png");
m_indexToName.append("C06_KCMDF.png");
m_indexToName.append("C07_Kate.png");
m_indexToName.append("C08_Socket.png");
m_indexToName.append("C09_Identity.png");
m_indexToName.append("C10_Kontact.png");
m_indexToName.append("C11_Camera.png");
m_indexToName.append("C12_IRKickFlash.png");
m_indexToName.append("C13_KGPG_Key3.png");
m_indexToName.append("C14_Laptop_Power.png");
m_indexToName.append("C15_Scanner.png");
m_indexToName.append("C16_Mozilla_Firebird.png");
m_indexToName.append("C17_CDROM_Unmount.png");
m_indexToName.append("C18_Display.png");
m_indexToName.append("C19_Mail_Generic.png");
m_indexToName.append("C20_Misc.png");
m_indexToName.append("C21_KOrganizer.png");
m_indexToName.append("C22_ASCII.png");
m_indexToName.append("C23_Icons.png");
m_indexToName.append("C24_Connect_Established.png");
m_indexToName.append("C25_Folder_Mail.png");
m_indexToName.append("C26_FileSave.png");
m_indexToName.append("C27_NFS_Unmount.png");
m_indexToName.append("C28_QuickTime.png");
m_indexToName.append("C29_KGPG_Term.png");
m_indexToName.append("C30_Konsole.png");
m_indexToName.append("C31_FilePrint.png");
m_indexToName.append("C32_FSView.png");
m_indexToName.append("C33_Run.png");
m_indexToName.append("C34_Configure.png");
m_indexToName.append("C35_KRFB.png");
m_indexToName.append("C36_Ark.png");
m_indexToName.append("C37_KPercentage.png");
m_indexToName.append("C38_Samba_Unmount.png");
m_indexToName.append("C39_History.png");
m_indexToName.append("C40_Mail_Find.png");
m_indexToName.append("C41_VectorGfx.png");
m_indexToName.append("C42_KCMMemory.png");
m_indexToName.append("C43_EditTrash.png");
m_indexToName.append("C44_KNotes.png");
m_indexToName.append("C45_Cancel.png");
m_indexToName.append("C46_Help.png");
m_indexToName.append("C47_KPackage.png");
m_indexToName.append("C48_Folder.png");
m_indexToName.append("C49_Folder_Blue_Open.png");
m_indexToName.append("C50_Folder_Tar.png");
m_indexToName.append("C51_Decrypted.png");
m_indexToName.append("C52_Encrypted.png");
m_indexToName.append("C53_Apply.png");
m_indexToName.append("C54_Signature.png");
m_indexToName.append("C55_Thumbnail.png");
m_indexToName.append("C56_KAddressBook.png");
m_indexToName.append("C57_View_Text.png");
m_indexToName.append("C58_KGPG.png");
m_indexToName.append("C59_Package_Development.png");
m_indexToName.append("C60_KFM_Home.png");
m_indexToName.append("C61_Services.png");
m_indexToName.append("C62_Tux.png");
m_indexToName.append("C63_Feather.png");
m_indexToName.append("C64_Apple.png");
m_indexToName.append("C65_Apple.png");
m_indexToName.append("C66_Money.png");
m_indexToName.append("C67_Certificate.png");
m_indexToName.append("C68_BlackBerry.png");
Q_ASSERT(m_indexToName.size() == iconCount());
}
#include <QFile>
QIcon DatabaseIcons::getIconInternal(int index)
{
if (m_iconCache.contains(index)) {
return m_iconCache.value(index);
}
else {
// TODO search multiple paths
QIcon icon(QString(KEEPASSX_SOURCE_DIR).append("/share/icons/database/").append(m_indexToName.at(index)));
m_iconCache.insert(index, icon);
return icon;
}
}

37
src/core/DatabaseIcons.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtCore/QHash>
#include <QtGui/QIcon>
class DatabaseIcons
{
public:
static QIcon icon(int index);
static int iconCount();
private:
static DatabaseIcons* m_instance;
private:
DatabaseIcons();
QIcon getIconInternal(int index);
bool m_initalized;
QList<QString> m_indexToName;
QHash<int,QIcon> m_iconCache;
};

View File

@ -18,7 +18,9 @@
#include "Entry.h"
#include "Database.h"
#include "DatabaseIcons.h"
#include "Group.h"
#include "Metadata.h"
Entry::Entry()
{
@ -37,15 +39,13 @@ Uuid Entry::uuid() const
return m_uuid;
}
QImage Entry::icon() const
QIcon Entry::icon() const
{
Q_ASSERT(m_iconNumber != 0 || !m_customIcon.isNull());
if (m_iconNumber == 0) {
return m_db->customIcon(m_customIcon);
if (m_customIcon.isNull()) {
return DatabaseIcons::icon(m_iconNumber);
}
else {
return Database::icon(m_iconNumber);
return m_db->metadata()->customIcon(m_customIcon);
}
}

View File

@ -21,7 +21,7 @@
#include <QtCore/QHash>
#include <QtCore/QUrl>
#include <QtGui/QColor>
#include <QtGui/QImage>
#include <QtGui/QIcon>
#include "TimeInfo.h"
#include "Uuid.h"
@ -43,7 +43,7 @@ public:
Entry();
~Entry();
Uuid uuid() const;
QImage icon() const;
QIcon icon() const;
int iconNumber() const;
Uuid iconUuid() const;
QColor foregroundColor() const;

View File

@ -21,6 +21,8 @@
#include "Group.h"
#include "Database.h"
#include "DatabaseIcons.h"
#include "Metadata.h"
Group::Group()
{
@ -48,13 +50,13 @@ QString Group::notes() const
return m_notes;
}
QImage Group::icon() const
QIcon Group::icon() const
{
if (m_iconNumber == 0) {
return m_db->customIcon(m_customIcon);
if (m_customIcon.isNull()) {
return DatabaseIcons::icon(m_iconNumber);
}
else {
return Database::icon(m_iconNumber);
return m_db->metadata()->customIcon(m_customIcon);
}
}

View File

@ -18,7 +18,7 @@
#ifndef KEEPASSX_GROUP_H
#define KEEPASSX_GROUP_H
#include <QtGui/QImage>
#include <QtGui/QIcon>
#include "Entry.h"
#include "TimeInfo.h"
@ -36,7 +36,7 @@ public:
Uuid uuid() const;
QString name() const;
QString notes() const;
QImage icon() const;
QIcon icon() const;
int iconNumber() const;
Uuid iconUuid() const;
TimeInfo timeInfo() const;

View File

@ -100,7 +100,12 @@ bool Metadata::autoEnableVisualHiding() const
return m_autoEnableVisualHiding;
}
QHash<Uuid, QImage> Metadata::customIcons() const
QIcon Metadata::customIcon(const Uuid& uuid) const
{
return m_customIcons.value(uuid);
}
QHash<Uuid, QIcon> Metadata::customIcons() const
{
return m_customIcons;
}
@ -215,12 +220,12 @@ void Metadata::setAutoEnableVisualHiding(bool value)
m_autoEnableVisualHiding = value;
}
void Metadata::addCustomIcon(const Uuid& uuid, const QImage& image)
void Metadata::addCustomIcon(const Uuid& uuid, const QIcon& icon)
{
Q_ASSERT(!uuid.isNull());
Q_ASSERT(!m_customIcons.contains(uuid));
m_customIcons.insert(uuid, image);
m_customIcons.insert(uuid, icon);
}
void Metadata::removeCustomIcon(const Uuid& uuid)

View File

@ -22,7 +22,7 @@
#include <QtCore/QDateTime>
#include <QtCore/QHash>
#include <QtGui/QImage>
#include <QtGui/QIcon>
class Database;
class Group;
@ -48,7 +48,8 @@ public:
bool protectUrl() const;
bool protectNotes() const;
bool autoEnableVisualHiding() const;
QHash<Uuid, QImage> customIcons() const;
QIcon customIcon(const Uuid& uuid) const;
QHash<Uuid, QIcon> customIcons() const;
bool recycleBinEnabled() const;
const Group* recycleBin() const;
QDateTime recycleBinChanged() const;
@ -72,7 +73,7 @@ public:
void setProtectUrl(bool value);
void setProtectNotes(bool value);
void setAutoEnableVisualHiding(bool value);
void addCustomIcon(const Uuid& uuid, const QImage& image);
void addCustomIcon(const Uuid& uuid, const QIcon& icon);
void removeCustomIcon(const Uuid& uuid);
void setRecycleBinEnabled(bool value);
void setRecycleBin(Group* group);
@ -101,7 +102,7 @@ private:
bool m_protectNotes;
bool m_autoEnableVisualHiding;
QHash<Uuid, QImage> m_customIcons;
QHash<Uuid, QIcon> m_customIcons;
bool m_recycleBinEnabled;
Group* m_recycleBin;

View File

@ -209,9 +209,9 @@ void KeePass2XmlReader::parseIcon()
uuid = readUuid();
}
else if (m_xml.name() == "Data") {
QImage image;
image.loadFromData(readBinary());
m_meta->addCustomIcon(uuid, image);
QPixmap pixmap;
pixmap.loadFromData(readBinary());
m_meta->addCustomIcon(uuid, QIcon(pixmap));
}
else {
skipCurrentElement();
@ -445,8 +445,9 @@ Entry* KeePass2XmlReader::parseEntry(bool history)
}
else if (m_xml.name() == "CustomIconUUID") {
Uuid uuid = readUuid();
if (!uuid.isNull())
if (!uuid.isNull()) {
entry->setIcon(uuid);
}
}
else if (m_xml.name() == "ForegroundColor") {
entry->setForegroundColor(readColor());
@ -755,6 +756,6 @@ void KeePass2XmlReader::raiseError()
void KeePass2XmlReader::skipCurrentElement()
{
qDebug() << "KeePass2XmlReader::skipCurrentElement(): skip: " << m_xml.name();
qWarning() << "KeePass2XmlReader::skipCurrentElement(): skip: " << m_xml.name();
m_xml.skipCurrentElement();
}

View File

@ -101,7 +101,7 @@ void KeePass2XmlWriter::writeCustomIcons()
{
m_xml.writeStartElement("CustomIcons");
QHash<Uuid, QImage> customIcons = m_meta->customIcons();
QHash<Uuid, QIcon> customIcons = m_meta->customIcons();
Q_FOREACH (const Uuid& uuid, customIcons.keys()) {
writeIcon(uuid, customIcons.value(uuid));
}
@ -109,16 +109,18 @@ void KeePass2XmlWriter::writeCustomIcons()
m_xml.writeEndElement();
}
void KeePass2XmlWriter::writeIcon(const Uuid& uuid, const QImage& image)
void KeePass2XmlWriter::writeIcon(const Uuid& uuid, const QIcon& icon)
{
m_xml.writeStartElement("Icon");
writeUuid("UUID", uuid);
QPixmap pixmap = icon.pixmap(16, 16);
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG");
pixmap.save(&buffer, "PNG");
buffer.close();
writeBinary("Data", ba);

View File

@ -21,7 +21,7 @@
#include <QtCore/QDateTime>
#include <QtCore/QXmlStreamWriter>
#include <QtGui/QColor>
#include <QtGui/QImage>
#include <QtGui/QIcon>
#include "core/Database.h"
#include "core/Entry.h"
@ -44,7 +44,7 @@ private:
void writeMetadata();
void writeMemoryProtection();
void writeCustomIcons();
void writeIcon(const Uuid& uuid, const QImage& image);
void writeIcon(const Uuid& uuid, const QIcon& icon);
void writeCustomData();
void writeCustomDataItem(const QString& key, const QString& value);
void writeRoot();

View File

@ -78,9 +78,9 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
if (role == Qt::DisplayRole) {
return entry->title();
}
/*else if (role == Qt::DecorationRole) {
else if (role == Qt::DecorationRole) {
return entry->icon();
}*/
}
else {
return QVariant();
}

View File

@ -108,10 +108,9 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const
if (role == Qt::DisplayRole) {
return group->name();
}
// TODO enable
/*else if (role == Qt::DecorationRole) {
else if (role == Qt::DecorationRole) {
return group->icon();
}*/
}
else {
return QVariant();
}

View File

@ -103,9 +103,8 @@ void TestParser::testCustomIcons()
QCOMPARE(m_db->metadata()->customIcons().size(), 1);
Uuid uuid = Uuid::fromBase64("++vyI+daLk6omox4a6kQGA==");
QVERIFY(m_db->metadata()->customIcons().contains(uuid));
const QImage& img = m_db->metadata()->customIcons()[uuid];
QCOMPARE(img.width(), 16);
QCOMPARE(img.height(), 16);
QIcon icon = m_db->metadata()->customIcon(uuid);
QImage img = icon.pixmap(16, 16).toImage();
for (int x=0; x<16; x++) {
for (int y=0; y<16; y++) {
QRgb rgb = img.pixel(x, y);