diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ include(AkonadiMacros) set(QT_REQUIRED_VERSION "5.2.0") -set(AKONADI_VERSION "5.1.80") +set(AKONADI_VERSION "5.1.81") set(KF5_VERSION "5.16.0") ecm_setup_version(${AKONADI_VERSION} diff --git a/autotests/libs/CMakeLists.txt b/autotests/libs/CMakeLists.txt --- a/autotests/libs/CMakeLists.txt +++ b/autotests/libs/CMakeLists.txt @@ -90,6 +90,7 @@ add_akonadi_test(entitytreemodeltest.cpp) add_akonadi_test(monitornotificationtest.cpp) add_akonadi_test(collectionutilstest.cpp) +add_akonadi_test(collectioncolorattributetest.cpp) add_akonadi_test(entitydisplayattributetest.cpp) add_akonadi_test(proxymodelstest.cpp) add_akonadi_test(newmailnotifierattributetest.cpp) diff --git a/autotests/libs/collectioncolorattributetest.cpp b/autotests/libs/collectioncolorattributetest.cpp new file mode 100644 --- /dev/null +++ b/autotests/libs/collectioncolorattributetest.cpp @@ -0,0 +1,70 @@ +/* + Copyright (c) 2016 Sandro Knauß + + 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 "collectioncolorattribute.h" + +#include + +#include + +using namespace Akonadi; + +class CollectionColorAttributeTest : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void testDeserialize_data() + { + QTest::addColumn("input"); + QTest::addColumn("color"); + QTest::addColumn("output"); + + QTest::newRow("empty") << QByteArray("") << QColor() << QByteArray(""); + QTest::newRow("white") << QByteArray("white") << QColor("#ffffff") << QByteArray("#ffffffff"); + QTest::newRow("#123") << QByteArray("#123") << QColor("#112233") << QByteArray("#ff112233"); + QTest::newRow("#123456") << QByteArray("#123456") << QColor("#123456") << QByteArray("#ff123456"); + QTest::newRow("#1234567") << QByteArray("#1234567") << QColor() << QByteArray(""); + QTest::newRow("#12345678") << QByteArray("#12345678") << QColor("#12345678") << QByteArray("#12345678"); + QTest::newRow("#ff345678") << QByteArray("#ff123456") << QColor("#123456") << QByteArray("#ff123456"); + } + + void testDeserialize() + { + QFETCH(QByteArray, input); + QFETCH(QColor, color); + QFETCH(QByteArray, output); + + CollectionColorAttribute *attr = new CollectionColorAttribute(); + attr->deserialize(input); + QCOMPARE(attr->color(), color); + + QCOMPARE(attr->serialized(), output); + + CollectionColorAttribute *copy = attr->clone(); + QCOMPARE(copy->serialized(), output); + + delete attr; + delete copy; + } +}; + +QTEST_MAIN(CollectionColorAttributeTest) + +#include "collectioncolorattributetest.moc" + diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,6 +13,7 @@ changerecorder_p.cpp connectionthread.cpp collection.cpp + collectioncolorattribute.cpp collectionfetchscope.cpp collectionpathresolver.cpp collectionquotaattribute.cpp @@ -79,6 +80,7 @@ CachePolicy ChangeRecorder Collection + CollectionColorAttribute CollectionFetchScope CollectionQuotaAttribute CollectionStatistics diff --git a/src/core/collectioncolorattribute.h b/src/core/collectioncolorattribute.h new file mode 100644 --- /dev/null +++ b/src/core/collectioncolorattribute.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 Sandro Knauß + * + * 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 AKONADI_COLLECTIONCOLORATTRIBUTE_H +#define AKONADI_COLLECTIONCOLORATTRIBUTE_H + +#include "akonadicore_export.h" + +#include + +#include + +namespace Akonadi { + +/** + * @short Attribute that stores colors of a collection. + * + * Storing color in Akonadi makes it possible to sync them between client and server. + * + * @author Sandro Knauß + * @since 5.1.81 + */ + +class AKONADICORE_EXPORT CollectionColorAttribute : public Akonadi::Attribute +{ +public: + CollectionColorAttribute(); + CollectionColorAttribute(const QColor &color); + + virtual ~CollectionColorAttribute(); + + void setColor(const QColor &color); + QColor color() const; + + QByteArray type() const Q_DECL_OVERRIDE; + CollectionColorAttribute *clone() const Q_DECL_OVERRIDE; + QByteArray serialized() const Q_DECL_OVERRIDE; + void deserialize(const QByteArray &data) Q_DECL_OVERRIDE; + +private: + QColor mColor; +}; + +} + +#endif diff --git a/src/core/collectioncolorattribute.cpp b/src/core/collectioncolorattribute.cpp new file mode 100644 --- /dev/null +++ b/src/core/collectioncolorattribute.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 Sandro Knauß + * + * 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 "collectioncolorattribute.h" +#include "attributefactory.h" + +#include +#include + +using namespace Akonadi; + +CollectionColorAttribute::CollectionColorAttribute() + : Attribute() +{ +} + +CollectionColorAttribute::CollectionColorAttribute(const QColor &color) + : Attribute() + , mColor(color) +{ +} + +CollectionColorAttribute::~CollectionColorAttribute() +{ +} + +void CollectionColorAttribute::setColor(const QColor &color) +{ + mColor = color; +} + +QColor CollectionColorAttribute::color() const +{ + return mColor; +} + +QByteArray CollectionColorAttribute::type() const +{ + return "collectioncolor"; +} + +CollectionColorAttribute *CollectionColorAttribute::clone() const +{ + return new CollectionColorAttribute(mColor); +} + +QByteArray CollectionColorAttribute::serialized() const +{ + return mColor.isValid() ? mColor.name(QColor::HexArgb).toUtf8() : ""; +} + +void CollectionColorAttribute::deserialize(const QByteArray &data) +{ + mColor = QColor(QString::fromUtf8(data)); +} \ No newline at end of file