2010-08-07 09:10:44 -04:00
|
|
|
/*
|
|
|
|
* 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 "Entry.h"
|
|
|
|
|
2011-07-08 08:51:14 -04:00
|
|
|
#include "core/Database.h"
|
|
|
|
#include "core/DatabaseIcons.h"
|
|
|
|
#include "core/Group.h"
|
|
|
|
#include "core/Metadata.h"
|
2010-08-12 15:38:59 -04:00
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
Entry::Entry()
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
m_updateTimeinfo = true;
|
2011-06-29 10:47:05 -04:00
|
|
|
|
2011-07-07 06:52:30 -04:00
|
|
|
m_iconNumber = 0;
|
|
|
|
m_autoTypeEnabled = true;
|
|
|
|
m_autoTypeObfuscation = 0;
|
2011-07-07 06:42:08 -04:00
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
m_attributes = new EntryAttributes(this);
|
|
|
|
connect(m_attributes, SIGNAL(modified()), this, SIGNAL(modified()));
|
|
|
|
connect(m_attributes, SIGNAL(defaultKeyModified()), SLOT(emitDataChanged()));
|
|
|
|
|
|
|
|
m_attachments = new EntryAttachments(this);
|
|
|
|
connect(m_attachments, SIGNAL(modified()), this, SIGNAL(modified()));
|
2012-04-16 19:02:02 -04:00
|
|
|
connect(this, SIGNAL(modified()), this, SLOT(updateTimeinfo()));
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2010-08-18 10:22:48 -04:00
|
|
|
Entry::~Entry()
|
|
|
|
{
|
2011-07-09 15:54:01 -04:00
|
|
|
if (m_group) {
|
|
|
|
m_group->removeEntry(this);
|
2012-04-21 13:06:28 -04:00
|
|
|
|
2012-04-21 18:29:39 -04:00
|
|
|
if (m_group->database()) {
|
|
|
|
m_group->database()->addDeletedObject(m_uuid);
|
|
|
|
}
|
2011-07-09 15:54:01 -04:00
|
|
|
}
|
|
|
|
|
2010-08-25 07:52:59 -04:00
|
|
|
qDeleteAll(m_history);
|
2010-08-18 10:22:48 -04:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:02:02 -04:00
|
|
|
template <class T> bool Entry::set(T& property, const T& value)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
if (property != value) {
|
|
|
|
property = value;
|
|
|
|
Q_EMIT modified();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 19:02:02 -04:00
|
|
|
void Entry::updateTimeinfo()
|
|
|
|
{
|
|
|
|
if (m_updateTimeinfo) {
|
2012-04-16 20:22:48 -04:00
|
|
|
m_timeInfo.setLastModificationTime(QDateTime::currentDateTimeUtc());
|
|
|
|
m_timeInfo.setLastAccessTime(QDateTime::currentDateTimeUtc());
|
2012-04-16 19:02:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Entry::setUpdateTimeinfo(bool value)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
m_updateTimeinfo = value;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
Uuid Entry::uuid() const
|
|
|
|
{
|
|
|
|
return m_uuid;
|
|
|
|
}
|
|
|
|
|
2012-01-01 15:52:54 -05:00
|
|
|
QImage Entry::icon() const
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-09-19 15:22:24 -04:00
|
|
|
if (m_customIcon.isNull()) {
|
2012-01-01 15:52:54 -05:00
|
|
|
return databaseIcons()->icon(m_iconNumber);
|
2010-08-24 17:12:01 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-04-18 07:57:57 -04:00
|
|
|
// TODO check if database() is 0
|
|
|
|
return database()->metadata()->customIcon(m_customIcon);
|
2010-08-24 17:12:01 -04:00
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2012-01-01 15:52:54 -05:00
|
|
|
QPixmap Entry::iconPixmap() const
|
|
|
|
{
|
|
|
|
if (m_customIcon.isNull()) {
|
|
|
|
return databaseIcons()->iconPixmap(m_iconNumber);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QPixmap pixmap;
|
|
|
|
if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
|
2012-04-18 07:57:57 -04:00
|
|
|
// TODO check if database() is 0
|
|
|
|
pixmap = QPixmap::fromImage(database()->metadata()->customIcon(m_customIcon));
|
2012-01-01 15:52:54 -05:00
|
|
|
*const_cast<QPixmapCache::Key*>(&m_pixmapCacheKey) = QPixmapCache::insert(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 16:57:26 -04:00
|
|
|
int Entry::iconNumber() const
|
|
|
|
{
|
|
|
|
return m_iconNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
Uuid Entry::iconUuid() const
|
|
|
|
{
|
|
|
|
return m_customIcon;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
QColor Entry::foregroundColor() const
|
|
|
|
{
|
|
|
|
return m_foregroundColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor Entry::backgroundColor() const
|
|
|
|
{
|
|
|
|
return m_backgroundColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Entry::overrideUrl() const
|
|
|
|
{
|
|
|
|
return m_overrideUrl;
|
|
|
|
}
|
|
|
|
|
2010-09-25 06:41:00 -04:00
|
|
|
QString Entry::tags() const
|
|
|
|
{
|
|
|
|
return m_tags;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
TimeInfo Entry::timeInfo() const
|
|
|
|
{
|
|
|
|
return m_timeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Entry::autoTypeEnabled() const
|
|
|
|
{
|
|
|
|
return m_autoTypeEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Entry::autoTypeObfuscation() const
|
|
|
|
{
|
|
|
|
return m_autoTypeObfuscation;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Entry::defaultAutoTypeSequence() const
|
|
|
|
{
|
|
|
|
return m_defaultAutoTypeSequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<AutoTypeAssociation>& Entry::autoTypeAssociations() const
|
|
|
|
{
|
|
|
|
return m_autoTypeAssociations;
|
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QString Entry::title() const
|
2012-04-06 13:33:29 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attributes->value("Title");
|
2012-04-06 13:33:29 -04:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QString Entry::url() const
|
2012-04-06 13:33:29 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attributes->value("URL");
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QString Entry::username() const
|
2011-01-13 16:31:17 -05:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attributes->value("UserName");
|
2011-01-13 16:31:17 -05:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QString Entry::password() const
|
2011-01-13 16:31:17 -05:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attributes->value("Password");
|
2011-01-13 16:31:17 -05:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QString Entry::notes() const
|
2010-08-18 09:08:17 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attributes->value("Notes");
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
EntryAttributes* Entry::attributes()
|
2010-08-18 09:08:17 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attributes;
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
const EntryAttributes* Entry::attributes() const
|
2010-08-18 09:08:17 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attributes;
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
EntryAttachments* Entry::attachments()
|
2010-08-18 09:08:17 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attachments;
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
const EntryAttachments* Entry::attachments() const
|
2010-08-18 09:08:17 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
return m_attachments;
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Entry::setUuid(const Uuid& uuid)
|
|
|
|
{
|
2010-08-13 12:08:06 -04:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_uuid, uuid);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setIcon(int iconNumber)
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(iconNumber >= 0);
|
|
|
|
|
2012-04-11 13:51:54 -04:00
|
|
|
if (m_iconNumber != iconNumber || !m_customIcon.isNull()) {
|
|
|
|
m_iconNumber = iconNumber;
|
|
|
|
m_customIcon = Uuid();
|
|
|
|
|
|
|
|
m_pixmapCacheKey = QPixmapCache::Key();
|
2012-01-01 15:52:54 -05:00
|
|
|
|
2012-04-11 13:51:54 -04:00
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setIcon(const Uuid& uuid)
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
|
|
|
|
2012-04-11 16:05:24 -04:00
|
|
|
if (m_customIcon != uuid) {
|
|
|
|
m_customIcon = uuid;
|
2012-04-11 13:51:54 -04:00
|
|
|
m_iconNumber = 0;
|
2012-01-01 15:52:54 -05:00
|
|
|
|
2012-04-11 13:51:54 -04:00
|
|
|
m_pixmapCacheKey = QPixmapCache::Key();
|
2012-04-11 16:05:24 -04:00
|
|
|
|
|
|
|
Q_EMIT modified();
|
2012-04-11 13:51:54 -04:00
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setForegroundColor(const QColor& color)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_foregroundColor, color);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setBackgroundColor(const QColor& color)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_backgroundColor, color);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setOverrideUrl(const QString& url)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_overrideUrl, url);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2010-09-25 06:41:00 -04:00
|
|
|
void Entry::setTags(const QString& tags)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_tags, tags);
|
2010-09-25 06:41:00 -04:00
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Entry::setTimeInfo(const TimeInfo& timeInfo)
|
|
|
|
{
|
|
|
|
m_timeInfo = timeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setAutoTypeEnabled(bool enable)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_autoTypeEnabled, enable);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setAutoTypeObfuscation(int obfuscation)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_autoTypeObfuscation, obfuscation);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setDefaultAutoTypeSequence(const QString& sequence)
|
|
|
|
{
|
2012-04-11 13:51:54 -04:00
|
|
|
set(m_defaultAutoTypeSequence, sequence);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc)
|
|
|
|
{
|
|
|
|
m_autoTypeAssociations << assoc;
|
2012-04-11 13:51:54 -04:00
|
|
|
Q_EMIT modified();
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2010-08-18 09:08:17 -04:00
|
|
|
void Entry::setTitle(const QString& title)
|
|
|
|
{
|
2012-04-14 13:41:56 -04:00
|
|
|
m_attributes->set("Title", title, m_attributes->isProtected("Title"));
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setUrl(const QString& url)
|
|
|
|
{
|
2012-04-14 13:41:56 -04:00
|
|
|
m_attributes->set("URL", url, m_attributes->isProtected("URL"));
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setUsername(const QString& username)
|
|
|
|
{
|
2012-04-14 13:41:56 -04:00
|
|
|
m_attributes->set("UserName", username, m_attributes->isProtected("UserName"));
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setPassword(const QString& password)
|
|
|
|
{
|
2012-04-14 13:41:56 -04:00
|
|
|
m_attributes->set("Password", password, m_attributes->isProtected("Password"));
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setNotes(const QString& notes)
|
|
|
|
{
|
2012-04-14 13:41:56 -04:00
|
|
|
m_attributes->set("Notes", notes, m_attributes->isProtected("Notes"));
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
2012-04-16 20:27:38 -04:00
|
|
|
void Entry::setExpires(const bool& value)
|
|
|
|
{
|
|
|
|
if (m_timeInfo.expires() != value) {
|
|
|
|
m_timeInfo.setExpires(value);
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setExpiryTime(const QDateTime& dateTime)
|
|
|
|
{
|
|
|
|
if (m_timeInfo.expiryTime() != dateTime) {
|
|
|
|
m_timeInfo.setExpiryTime(dateTime);
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 07:52:59 -04:00
|
|
|
QList<Entry*> Entry::historyItems()
|
|
|
|
{
|
|
|
|
return m_history;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<Entry*>& Entry::historyItems() const
|
|
|
|
{
|
|
|
|
return m_history;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::addHistoryItem(Entry* entry)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!entry->parent());
|
|
|
|
|
|
|
|
m_history.append(entry);
|
2012-04-11 13:51:54 -04:00
|
|
|
Q_EMIT modified();
|
2010-08-25 07:52:59 -04:00
|
|
|
}
|
|
|
|
|
2010-10-06 16:54:07 -04:00
|
|
|
Group* Entry::group()
|
|
|
|
{
|
|
|
|
return m_group;
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
void Entry::setGroup(Group* group)
|
2010-08-07 09:10:44 -04:00
|
|
|
{
|
2010-08-12 15:38:59 -04:00
|
|
|
if (m_group) {
|
2010-08-13 12:08:06 -04:00
|
|
|
m_group->removeEntry(this);
|
2012-04-21 18:58:35 -04:00
|
|
|
if (m_group->database() != group->database() && m_group->database()) {
|
2012-04-21 18:29:39 -04:00
|
|
|
m_group->database()->addDeletedObject(m_uuid);
|
2012-04-21 13:06:28 -04:00
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
2012-04-21 13:06:28 -04:00
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
group->addEntry(this);
|
|
|
|
m_group = group;
|
|
|
|
QObject::setParent(group);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|
2011-07-07 06:42:08 -04:00
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
void Entry::emitDataChanged()
|
2011-07-07 06:42:08 -04:00
|
|
|
{
|
2012-04-14 09:38:20 -04:00
|
|
|
Q_EMIT dataChanged(this);
|
2011-07-07 06:42:08 -04:00
|
|
|
}
|
2012-04-18 07:57:57 -04:00
|
|
|
|
|
|
|
const Database* Entry::database() const
|
|
|
|
{
|
|
|
|
if (m_group) {
|
|
|
|
return m_group->database();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|