Verified Commit 7e550aee authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Import NewMailNotifierAttribute and Pop3ResourceAttribute

Those are email-specific attributes so their place is here in Akonadi Mime
rather than the type-agnostic Akonadi repository.
parent a2a822b1
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.14.42")
set(PIM_VERSION "5.14.43")
project(Akonadi-Mime VERSION ${PIM_VERSION})
# ECM setup
......
......@@ -37,3 +37,11 @@ ecm_add_test(mailserializertest.cpp
LINK_LIBRARIES KF5::AkonadiMime KF5::AkonadiCore KF5::AkonadiPrivate KF5::Mime Qt5::Test
TEST_NAME mailserializertest
)
ecm_add_test(newmailnotifierattributetest.cpp
LINK_LIBRARIES KF5::AkonadiMime KF5::AkonadiCore Qt5::Test
TEST_NAME newmailnotifierattributetest
)
ecm_add_test(pop3resourceattributetest.cpp
LINK_LIBRARIES KF5::AkonadiMime KF5::AkonadiCore Qt5::Test
TEST_NAME pop3resourceattributetest
)
/*
Copyright (c) 2014-2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "newmailnotifierattributetest.h"
#include "newmailnotifierattribute.h"
#include <QTest>
using namespace Akonadi;
NewMailNotifierAttributeTest::NewMailNotifierAttributeTest(QObject *parent)
: QObject(parent)
{
}
void NewMailNotifierAttributeTest::shouldHaveDefaultValue()
{
NewMailNotifierAttribute attr;
QVERIFY(!attr.ignoreNewMail());
}
void NewMailNotifierAttributeTest::shouldSetIgnoreNotification()
{
NewMailNotifierAttribute attr;
bool ignore = false;
attr.setIgnoreNewMail(ignore);
QCOMPARE(attr.ignoreNewMail(), ignore);
ignore = true;
attr.setIgnoreNewMail(ignore);
QCOMPARE(attr.ignoreNewMail(), ignore);
}
void NewMailNotifierAttributeTest::shouldSerializedData()
{
NewMailNotifierAttribute attr;
attr.setIgnoreNewMail(true);
QByteArray ba = attr.serialized();
NewMailNotifierAttribute result;
result.deserialize(ba);
QVERIFY(attr == result);
}
void NewMailNotifierAttributeTest::shouldCloneAttribute()
{
NewMailNotifierAttribute attr;
attr.setIgnoreNewMail(true);
NewMailNotifierAttribute *result = attr.clone();
QVERIFY(attr == *result);
delete result;
}
void NewMailNotifierAttributeTest::shouldHaveType()
{
NewMailNotifierAttribute attr;
QCOMPARE(attr.type(), QByteArray("newmailnotifierattribute"));
}
QTEST_MAIN(NewMailNotifierAttributeTest)
/*
Copyright (c) 2014-2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef NEWMAILNOTIFIERATTRIBUTETEST_H
#define NEWMAILNOTIFIERATTRIBUTETEST_H
#include <QObject>
class NewMailNotifierAttributeTest : public QObject
{
Q_OBJECT
public:
explicit NewMailNotifierAttributeTest(QObject *parent = nullptr);
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldSetIgnoreNotification();
void shouldSerializedData();
void shouldCloneAttribute();
void shouldHaveType();
};
#endif // NEWMAILNOTIFIERATTRIBUTETEST_H
/*
Copyright (c) 2014-2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "pop3resourceattributetest.h"
#include "pop3resourceattribute.h"
#include <QTest>
Pop3ResourceAttributeTest::Pop3ResourceAttributeTest(QObject *parent)
: QObject(parent)
{
}
void Pop3ResourceAttributeTest::shouldHaveDefaultValue()
{
Akonadi::Pop3ResourceAttribute attr;
QVERIFY(attr.pop3AccountName().isEmpty());
}
void Pop3ResourceAttributeTest::shouldAssignValue()
{
Akonadi::Pop3ResourceAttribute attr;
QString accountName;
attr.setPop3AccountName(accountName);
QCOMPARE(attr.pop3AccountName(), accountName);
accountName = QStringLiteral("foo");
attr.setPop3AccountName(accountName);
QCOMPARE(attr.pop3AccountName(), accountName);
accountName.clear();
attr.setPop3AccountName(accountName);
QCOMPARE(attr.pop3AccountName(), accountName);
}
void Pop3ResourceAttributeTest::shouldDeserializeValue()
{
Akonadi::Pop3ResourceAttribute attr;
QString accountName = QStringLiteral("foo");
attr.setPop3AccountName(accountName);
const QByteArray ba = attr.serialized();
Akonadi::Pop3ResourceAttribute result;
result.deserialize(ba);
QVERIFY(attr == result);
}
void Pop3ResourceAttributeTest::shouldCloneAttribute()
{
Akonadi::Pop3ResourceAttribute attr;
QString accountName = QStringLiteral("foo");
attr.setPop3AccountName(accountName);
Akonadi::Pop3ResourceAttribute *result = attr.clone();
QVERIFY(attr == *result);
delete result;
}
QTEST_MAIN(Pop3ResourceAttributeTest)
/*
Copyright (c) 2014-2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef POP3RESOURCEATTRIBUTETEST_H
#define POP3RESOURCEATTRIBUTETEST_H
#include <QObject>
class Pop3ResourceAttributeTest : public QObject
{
Q_OBJECT
public:
explicit Pop3ResourceAttributeTest(QObject *parent = nullptr);
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAssignValue();
void shouldDeserializeValue();
void shouldCloneAttribute();
};
#endif // POP3RESOURCEATTRIBUTETEST_H
......@@ -34,6 +34,7 @@ set(akonadimime_SRCS
messageparts.cpp
messageflags.cpp
messagestatus.cpp
newmailnotifierattribute.cpp
commandbase.cpp
util.cpp
......@@ -110,6 +111,8 @@ ecm_generate_headers(AkonadiMime_CamelCase_HEADERS
MessageStatus
MarkAsCommand
MoveCommand
NewMailNotifierAttribute
Pop3ResourceAttribute
RemoveDuplicatesJob
SpecialMailCollections
SpecialMailCollectionsDiscoveryJob
......
/*
Copyright (c) 2013-2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "newmailnotifierattribute.h"
#include <QByteArray>
#include <QIODevice>
#include <QDataStream>
namespace Akonadi
{
class NewMailNotifierAttributePrivate
{
public:
bool ignoreNewMail = false;
};
NewMailNotifierAttribute::NewMailNotifierAttribute()
: d(new NewMailNotifierAttributePrivate)
{
}
NewMailNotifierAttribute::~NewMailNotifierAttribute() = default;
NewMailNotifierAttribute *NewMailNotifierAttribute::clone() const
{
NewMailNotifierAttribute *attr = new NewMailNotifierAttribute();
attr->setIgnoreNewMail(ignoreNewMail());
return attr;
}
QByteArray NewMailNotifierAttribute::type() const
{
static const QByteArray sType("newmailnotifierattribute");
return sType;
}
QByteArray NewMailNotifierAttribute::serialized() const
{
QByteArray result;
QDataStream s(&result, QIODevice::WriteOnly);
s << ignoreNewMail();
return result;
}
void NewMailNotifierAttribute::deserialize(const QByteArray &data)
{
QDataStream s(data);
s >> d->ignoreNewMail;
}
bool NewMailNotifierAttribute::ignoreNewMail() const
{
return d->ignoreNewMail;
}
void NewMailNotifierAttribute::setIgnoreNewMail(bool b)
{
d->ignoreNewMail = b;
}
bool NewMailNotifierAttribute::operator==(const NewMailNotifierAttribute &other) const
{
return d->ignoreNewMail == other.ignoreNewMail();
}
}
/*
Copyright (c) 2013-2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef NEWMAILNOTIFIERATTRIBUTE_H
#define NEWMAILNOTIFIERATTRIBUTE_H
#include "akonadicore_export.h"
#include <AkonadiCore/Attribute>
#include <QScopedPointer>
namespace Akonadi
{
class NewMailNotifierAttributePrivate;
class AKONADICORE_EXPORT NewMailNotifierAttribute : public Akonadi::Attribute
{
public:
explicit NewMailNotifierAttribute();
~NewMailNotifierAttribute() override;
/* reimpl */
NewMailNotifierAttribute *clone() const override;
QByteArray type() const override;
QByteArray serialized() const override;
void deserialize(const QByteArray &data) override;
bool ignoreNewMail() const;
void setIgnoreNewMail(bool b);
bool operator==(const NewMailNotifierAttribute &other) const;
private:
friend class NewMailNotifierAttributePrivate;
QScopedPointer<NewMailNotifierAttributePrivate> const d;
};
}
#endif // NEWMAILNOTIFIERATTRIBUTE_H
/*
Copyright (c) 2013-2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "pop3resourceattribute.h"
#include <QByteArray>
#include <QIODevice>
#include <QDataStream>
namespace Akonadi
{
class Pop3ResourceAttributePrivate
{
public:
QString accountName;
};
Pop3ResourceAttribute::Pop3ResourceAttribute()
: d(new Pop3ResourceAttributePrivate)
{
}
Pop3ResourceAttribute::~Pop3ResourceAttribute() = default;
Pop3ResourceAttribute *Pop3ResourceAttribute::clone() const
{
Pop3ResourceAttribute *attr = new Pop3ResourceAttribute();
attr->setPop3AccountName(pop3AccountName());
return attr;
}
QByteArray Pop3ResourceAttribute::type() const
{
static const QByteArray sType("pop3resourceattribute");
return sType;
}
QByteArray Pop3ResourceAttribute::serialized() const
{
QByteArray result;
QDataStream s(&result, QIODevice::WriteOnly);
s << pop3AccountName();
return result;
}
void Pop3ResourceAttribute::deserialize(const QByteArray &data)
{
QDataStream s(data);
QString value;
s >> value;
d->accountName = value;
}
QString Pop3ResourceAttribute::pop3AccountName() const
{
return d->accountName;
}
void Pop3ResourceAttribute::setPop3AccountName(const QString &accountName)
{
d->accountName = accountName;
}
bool Pop3ResourceAttribute::operator==(const Pop3ResourceAttribute &other) const
{
return d->accountName == other.pop3AccountName();
}
} // namespace Akonadi
/*
Copyright (c) 2013-2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef AKONADICORE_POP3RESOURCEATTRIBUTE_H
#define AKONADICORE_POP3RESOURCEATTRIBUTE_H
#include "akonadi-mime_export.h"
#include <AkonadiCore/Attribute>
#include <QScopedPointer>
namespace Akonadi
{
class Pop3ResourceAttributePrivate;
class AKONADI_MIME_EXPORT Pop3ResourceAttribute : public Akonadi::Attribute
{
public:
explicit Pop3ResourceAttribute();
~Pop3ResourceAttribute() override;
/* reimpl */
Pop3ResourceAttribute *clone() const override;
QByteArray type() const override;
QByteArray serialized() const override;
void deserialize(const QByteArray &data) override;
QString pop3AccountName() const;
void setPop3AccountName(const QString &accountName);
bool operator==(const Pop3ResourceAttribute &other) const;
private:
friend class Pop3ResourceAttributePrivate;
QScopedPointer<Pop3ResourceAttributePrivate> const d;
};
}
#endif // AKONADICORE_POP3RESOURCEATTRIBUTE_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment