keepassxc/src/core/Entry.h

195 lines
5.8 KiB
C++
Raw Normal View History

2010-08-07 09:10:44 -04:00
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
2017-06-09 17:40:36 -04:00
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
2010-08-07 09:10:44 -04:00
*
* 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/>.
*/
#ifndef KEEPASSX_ENTRY_H
#define KEEPASSX_ENTRY_H
#include <QColor>
#include <QImage>
#include <QMap>
#include <QPixmap>
#include <QPointer>
#include <QSet>
#include <QUrl>
#include "core/AutoTypeAssociations.h"
#include "core/EntryAttachments.h"
#include "core/EntryAttributes.h"
2011-07-08 08:51:14 -04:00
#include "core/TimeInfo.h"
#include "core/Uuid.h"
2010-08-07 09:10:44 -04:00
2010-08-14 06:24:35 -04:00
class Database;
class Group;
struct EntryData
{
int iconNumber;
Uuid customIcon;
QColor foregroundColor;
QColor backgroundColor;
QString overrideUrl;
QString tags;
bool autoTypeEnabled;
int autoTypeObfuscation;
QString defaultAutoTypeSequence;
TimeInfo timeInfo;
2017-04-13 06:05:36 -04:00
mutable quint8 totpDigits;
mutable quint8 totpStep;
};
class Entry : public QObject
2010-08-07 09:10:44 -04:00
{
Q_OBJECT
2010-08-07 09:10:44 -04:00
public:
Entry();
2010-08-18 10:22:48 -04:00
~Entry();
Uuid uuid() const;
QImage icon() const;
QPixmap iconPixmap() const;
QPixmap iconScaledPixmap() const;
int iconNumber() const;
Uuid iconUuid() const;
QColor foregroundColor() const;
QColor backgroundColor() const;
QString overrideUrl() const;
QString tags() const;
TimeInfo timeInfo() const;
bool autoTypeEnabled() const;
int autoTypeObfuscation() const;
QString defaultAutoTypeSequence() const;
QString effectiveAutoTypeSequence() const;
AutoTypeAssociations* autoTypeAssociations();
const AutoTypeAssociations* autoTypeAssociations() const;
QString title() const;
QString url() const;
QString webUrl() const;
QString username() const;
QString password() const;
QString notes() const;
2017-04-13 06:05:36 -04:00
QString totp() const;
QString totpSeed() const;
quint8 totpDigits() const;
quint8 totpStep() const;
bool hasTotp() const;
bool isExpired() const;
bool hasReferences() const;
EntryAttributes* attributes();
const EntryAttributes* attributes() const;
EntryAttachments* attachments();
const EntryAttachments* attachments() const;
static const int DefaultIconNumber;
void setUuid(const Uuid& uuid);
void setIcon(int iconNumber);
void setIcon(const Uuid& uuid);
void setForegroundColor(const QColor& color);
void setBackgroundColor(const QColor& color);
void setOverrideUrl(const QString& url);
void setTags(const QString& tags);
void setTimeInfo(const TimeInfo& timeInfo);
void setAutoTypeEnabled(bool enable);
void setAutoTypeObfuscation(int obfuscation);
void setDefaultAutoTypeSequence(const QString& sequence);
void setTitle(const QString& title);
void setUrl(const QString& url);
void setUsername(const QString& username);
void setPassword(const QString& password);
void setNotes(const QString& notes);
void setExpires(const bool& value);
void setExpiryTime(const QDateTime& dateTime);
2017-04-13 06:05:36 -04:00
void setTotp(const QString& seed, quint8& step, quint8& digits);
QList<Entry*> historyItems();
const QList<Entry*>& historyItems() const;
void addHistoryItem(Entry* entry);
2013-03-26 18:53:34 -04:00
void removeHistoryItems(const QList<Entry*>& historyEntries);
2012-05-04 17:45:34 -04:00
void truncateHistory();
enum CloneFlag {
CloneNoFlags = 0,
CloneNewUuid = 1, // generate a random uuid for the clone
CloneResetTimeInfo = 2, // set all TimeInfo attributes to the current time
CloneIncludeHistory = 4, // clone the history items
CloneRenameTitle = 8, // add "-Clone" after the original title
CloneUserAsRef = 16, // Add the user as a refrence to the origional entry
ClonePassAsRef = 32, // Add the password as a refrence to the origional entry
};
Q_DECLARE_FLAGS(CloneFlags, CloneFlag)
2013-07-04 07:59:32 -04:00
/**
* Creates a duplicate of this entry except that the returned entry isn't
* part of any group.
2013-07-04 07:59:32 -04:00
* Note that you need to copy the custom icons manually when inserting the
* new entry into another database.
*/
Entry* clone(CloneFlags flags) const;
2013-04-14 08:21:42 -04:00
void copyDataFrom(const Entry* other);
QString resolveMultiplePlaceholders(const QString& str) const;
QString resolvePlaceholder(const QString& str) const;
QString resolveUrl(const QString& url) const;
2012-05-04 17:45:34 -04:00
/**
* Call before and after set*() methods to create a history item
* if the entry has been changed.
*/
void beginUpdate();
bool endUpdate();
2010-10-06 16:54:07 -04:00
Group* group();
const Group* group() const;
void setGroup(Group* group);
2010-08-07 09:10:44 -04:00
2012-04-11 13:51:54 -04:00
void setUpdateTimeinfo(bool value);
signals:
2011-07-08 07:57:02 -04:00
/**
* Emitted when a default attribute has been changed.
*/
void dataChanged(Entry* entry);
2010-08-18 10:22:48 -04:00
2012-04-11 13:51:54 -04:00
void modified();
private slots:
void emitDataChanged();
void updateTimeinfo();
void updateModifiedSinceBegin();
2010-08-07 09:10:44 -04:00
private:
const Database* database() const;
template <class T> bool set(T& property, const T& value);
2010-08-07 09:10:44 -04:00
Uuid m_uuid;
EntryData m_data;
EntryAttributes* const m_attributes;
EntryAttachments* const m_attachments;
AutoTypeAssociations* const m_autoTypeAssociations;
QList<Entry*> m_history;
Entry* m_tmpHistoryItem;
bool m_modifiedSinceBegin;
QPointer<Group> m_group;
2012-04-11 13:51:54 -04:00
bool m_updateTimeinfo;
2010-08-07 09:10:44 -04:00
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Entry::CloneFlags)
2010-08-07 09:10:44 -04:00
#endif // KEEPASSX_ENTRY_H