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"
|
|
|
|
|
2010-08-14 06:24:35 -04:00
|
|
|
#include "Database.h"
|
2010-08-12 15:38:59 -04:00
|
|
|
#include "Group.h"
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
Entry::Entry()
|
2010-08-12 15:38:59 -04:00
|
|
|
{
|
2010-08-13 12:08:06 -04:00
|
|
|
m_group = 0;
|
2010-08-14 06:24:35 -04:00
|
|
|
m_db = 0;
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
2010-08-18 10:22:48 -04:00
|
|
|
Entry::~Entry()
|
|
|
|
{
|
|
|
|
// TODO notify group
|
|
|
|
}
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
Uuid Entry::uuid() const
|
|
|
|
{
|
|
|
|
return m_uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage Entry::icon() const
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(m_iconNumber != 0 || !m_customIcon.isNull());
|
|
|
|
|
|
|
|
if (m_iconNumber == 0)
|
|
|
|
return m_db->customIcon(m_customIcon);
|
|
|
|
else
|
|
|
|
return Database::icon(m_iconNumber);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QHash<QString, QString>& Entry::attributes() const
|
|
|
|
{
|
|
|
|
return m_attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QHash<QString, QByteArray>& Entry::attachments() const
|
|
|
|
{
|
|
|
|
return m_binaries;
|
|
|
|
}
|
|
|
|
|
2010-08-18 09:08:17 -04:00
|
|
|
QString Entry::title() const
|
|
|
|
{
|
|
|
|
return m_attributes.value("Title");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Entry::url() const
|
|
|
|
{
|
|
|
|
return m_attributes.value("URL");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Entry::username() const
|
|
|
|
{
|
|
|
|
return m_attributes.value("UserName");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Entry::password() const
|
|
|
|
{
|
|
|
|
return m_attributes.value("Password");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Entry::notes() const
|
|
|
|
{
|
|
|
|
return m_attributes.value("Notes");
|
|
|
|
}
|
|
|
|
|
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());
|
2010-08-14 06:24:35 -04:00
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
m_uuid = uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setIcon(int iconNumber)
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(iconNumber >= 0);
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
m_iconNumber = iconNumber;
|
|
|
|
m_customIcon = Uuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setIcon(const Uuid& uuid)
|
|
|
|
{
|
2010-08-14 06:24:35 -04:00
|
|
|
Q_ASSERT(!uuid.isNull());
|
|
|
|
|
2010-08-12 15:38:59 -04:00
|
|
|
m_iconNumber = 0;
|
|
|
|
m_customIcon = uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setForegroundColor(const QColor& color)
|
|
|
|
{
|
|
|
|
m_foregroundColor = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setBackgroundColor(const QColor& color)
|
|
|
|
{
|
|
|
|
m_backgroundColor = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setOverrideUrl(const QString& url)
|
|
|
|
{
|
|
|
|
m_overrideUrl = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setTimeInfo(const TimeInfo& timeInfo)
|
|
|
|
{
|
|
|
|
m_timeInfo = timeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setAutoTypeEnabled(bool enable)
|
|
|
|
{
|
|
|
|
m_autoTypeEnabled = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setAutoTypeObfuscation(int obfuscation)
|
|
|
|
{
|
|
|
|
m_autoTypeObfuscation = obfuscation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setDefaultAutoTypeSequence(const QString& sequence)
|
|
|
|
{
|
|
|
|
m_defaultAutoTypeSequence = sequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::addAutoTypeAssociation(const AutoTypeAssociation& assoc)
|
|
|
|
{
|
|
|
|
m_autoTypeAssociations << assoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::addAttribute(const QString& key, const QString& value)
|
|
|
|
{
|
|
|
|
m_attributes.insert(key, value);
|
2010-08-18 10:22:48 -04:00
|
|
|
|
|
|
|
// TODO add all visible oclumns
|
|
|
|
if (key == "Title") {
|
|
|
|
Q_EMIT dataChanged(this);
|
|
|
|
}
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::addAttachment(const QString& key, const QByteArray& value)
|
|
|
|
{
|
|
|
|
m_binaries.insert(key, value);
|
|
|
|
}
|
|
|
|
|
2010-08-18 09:08:17 -04:00
|
|
|
void Entry::setTitle(const QString& title)
|
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
addAttribute("Title", title);
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setUrl(const QString& url)
|
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
addAttribute("URL", url);
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setUsername(const QString& username)
|
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
addAttribute("UserName", username);
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setPassword(const QString& password)
|
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
addAttribute("Password", password);
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entry::setNotes(const QString& notes)
|
|
|
|
{
|
2010-08-18 10:22:48 -04:00
|
|
|
addAttribute("Notes", notes);
|
2010-08-18 09:08:17 -04:00
|
|
|
}
|
|
|
|
|
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);
|
2010-08-12 15:38:59 -04:00
|
|
|
}
|
|
|
|
group->addEntry(this);
|
|
|
|
m_group = group;
|
2010-08-14 06:24:35 -04:00
|
|
|
m_db = group->database();
|
2010-08-12 15:38:59 -04:00
|
|
|
QObject::setParent(group);
|
2010-08-07 09:10:44 -04:00
|
|
|
}
|