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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-10 03:56:41 -04:00
|
|
|
int EntryAttachments::attachmentsSize(QList<QByteArray>* foundAttachements) {
|
2012-05-04 17:45:34 -04:00
|
|
|
int size = 0;
|
|
|
|
|
2012-05-10 03:56:41 -04:00
|
|
|
QMapIterator<QString, QByteArray> i(m_attachments);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
|
|
|
if (!foundAttachements->contains(i.value())) {
|
|
|
|
foundAttachements->append(i.value());
|
|
|
|
size += i.value().size();
|
|
|
|
}
|
2012-05-04 17:45:34 -04:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2012-04-23 15:06:04 -04:00
|
|
|
bool EntryAttachments::operator==(const EntryAttachments& other) const
|
|
|
|
{
|
|
|
|
return m_attachments == other.m_attachments;
|
|
|
|
}
|
|
|
|
|
2012-04-14 09:38:20 -04:00
|
|
|
bool EntryAttachments::operator!=(const EntryAttachments& other) const
|
|
|
|
{
|
2012-04-21 10:45:46 -04:00
|
|
|
return m_attachments != other.m_attachments;
|
2012-04-14 09:38:20 -04:00
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
|
|
|
EntryAttachments& EntryAttachments::operator=(EntryAttachments& other)
|
|
|
|
{
|
|
|
|
if (*this != other) {
|
|
|
|
Q_EMIT aboutToBeReset();
|
|
|
|
|
|
|
|
m_attachments = other.m_attachments;
|
|
|
|
|
|
|
|
Q_EMIT reset();
|
|
|
|
Q_EMIT modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|