2012-04-14 09:38:20 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 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 "EntryAttachments.h"
|
|
|
|
|
|
|
|
EntryAttachments::EntryAttachments(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QString> EntryAttachments::keys() const
|
|
|
|
{
|
|
|
|
return m_attachments.keys();
|
|
|
|
}
|
|
|
|
|
2014-12-03 17:36:24 -05:00
|
|
|
bool EntryAttachments::hasKey(const QString& key) const
|
|
|
|
{
|
|
|
|
return m_attachments.keys().contains(key);
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:45:34 -04:00
|
|
|
QList<QByteArray> EntryAttachments::values() const
|
|
|
|
{
|
|
|
|
return m_attachments.values();
|
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
QByteArray EntryAttachments::value(const QString& key) const
|
|
|
|
{
|
|
|
|
return m_attachments.value(key);
|
|
|
|
}
|
|
|
|
|
2012-04-21 10:45:46 -04:00
|
|
|
void EntryAttachments::set(const QString& key, const QByteArray& value)
|
2012-04-14 09:38:20 -04:00
|
|
|
{
|
|
|
|
bool emitModified = false;
|
|
|
|
bool addAttachment = !m_attachments.contains(key);
|
|
|
|
|
|
|
|
if (addAttachment) {
|
|
|
|
Q_EMIT aboutToBeAdded(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addAttachment || m_attachments.value(key) != value) {
|
|
|
|
m_attachments.insert(key, value);
|
|
|
|
emitModified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addAttachment) {
|
|
|
|
Q_EMIT added(key);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Q_EMIT keyModified(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emitModified) {
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntryAttachments::remove(const QString& key)
|
|
|
|
{
|
|
|
|
if (!m_attachments.contains(key)) {
|
|
|
|
Q_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_EMIT aboutToBeRemoved(key);
|
|
|
|
|
|
|
|
m_attachments.remove(key);
|
|
|
|
|
|
|
|
Q_EMIT removed(key);
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntryAttachments::clear()
|
|
|
|
{
|
2012-04-14 12:47:40 -04:00
|
|
|
if (m_attachments.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
Q_EMIT aboutToBeReset();
|
|
|
|
|
|
|
|
m_attachments.clear();
|
|
|
|
|
|
|
|
Q_EMIT reset();
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:13:26 -04:00
|
|
|
void EntryAttachments::copyDataFrom(const EntryAttachments* other)
|
2012-04-23 15:06:04 -04:00
|
|
|
{
|
2012-07-20 06:13:26 -04:00
|
|
|
if (*this != *other) {
|
2012-04-23 15:06:04 -04:00
|
|
|
Q_EMIT aboutToBeReset();
|
|
|
|
|
2012-07-20 06:13:26 -04:00
|
|
|
m_attachments = other->m_attachments;
|
2012-04-23 15:06:04 -04:00
|
|
|
|
|
|
|
Q_EMIT reset();
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
2012-07-20 06:13:26 -04:00
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
2012-07-20 06:13:26 -04:00
|
|
|
bool EntryAttachments::operator==(const EntryAttachments& other) const
|
|
|
|
{
|
|
|
|
return m_attachments == other.m_attachments;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EntryAttachments::operator!=(const EntryAttachments& other) const
|
|
|
|
{
|
|
|
|
return m_attachments != other.m_attachments;
|
2012-04-23 15:06:04 -04:00
|
|
|
}
|