mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-03 20:14:17 -04:00
Add built-in icons.
This commit is contained in:
parent
b639c43b24
commit
567dd92d4c
88 changed files with 243 additions and 51 deletions
|
@ -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
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
128
src/core/DatabaseIcons.cpp
Normal 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
37
src/core/DatabaseIcons.h
Normal 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;
|
||||
};
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue