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

Clazy fixes in core lib

parent cd02f4f8
......@@ -135,7 +135,7 @@ void CollectionAttributeTest::testAttributes()
CollectionFetchJob *list = new CollectionFetchJob(col, CollectionFetchJob::Base, this);
AKVERIFYEXEC(list);
QCOMPARE(list->collections().count(), 1);
col = list->collections().first();
col = list->collections().at(0);
QVERIFY(col.isValid());
attr = col.attribute<TestAttribute>();
......@@ -166,7 +166,7 @@ void CollectionAttributeTest::testAttributes()
list = new CollectionFetchJob(col, CollectionFetchJob::Base, this);
AKVERIFYEXEC(list);
QCOMPARE(list->collections().count(), 1);
col = list->collections().first();
col = list->collections().at(0);
QVERIFY(col.isValid());
attr = col.attribute<TestAttribute>();
......@@ -181,7 +181,7 @@ void CollectionAttributeTest::testAttributes()
list = new CollectionFetchJob(col, CollectionFetchJob::Base, this);
AKVERIFYEXEC(list);
QCOMPARE(list->collections().count(), 1);
col = list->collections().first();
col = list->collections().at(0);
QVERIFY(col.isValid());
attr = col.attribute<TestAttribute>();
......
......@@ -88,10 +88,10 @@ private Q_SLOTS:
void testAgentServiceName()
{
akTestSetInstanceIdentifier(QString());
QCOMPARE(DBus::agentServiceName(QLatin1String("akonadi_maildir_resource_0"), DBus::Agent), QLatin1String("org.freedesktop.Akonadi.Agent.akonadi_maildir_resource_0"));
QCOMPARE(DBus::agentServiceName(QStringLiteral("akonadi_maildir_resource_0"), DBus::Agent), QStringLiteral("org.freedesktop.Akonadi.Agent.akonadi_maildir_resource_0"));
akTestSetInstanceIdentifier(QStringLiteral("foo"));
QCOMPARE(DBus::agentServiceName(QLatin1String("akonadi_maildir_resource_0"), DBus::Agent), QLatin1String("org.freedesktop.Akonadi.Agent.akonadi_maildir_resource_0.foo"));
QCOMPARE(DBus::agentServiceName(QStringLiteral("akonadi_maildir_resource_0"), DBus::Agent), QStringLiteral("org.freedesktop.Akonadi.Agent.akonadi_maildir_resource_0.foo"));
}
void testParseInstanceIdentifier_data()
......
......@@ -98,7 +98,7 @@ private Q_SLOTS:
QVector<int> in = { 1, 2, 3, 4, 5 };
QCOMPARE(in | Actions::toQList, in.toList());
QCOMPARE(in | Actions::toQList | Actions::toQVector, in);
QCOMPARE(in | Actions::toQSet, in.toList().toSet());
QCOMPARE(in | Actions::toQSet, in.toList().toSet()); // clazy:exclude=container-anti-pattern
}
{
QList<int> in = { 1, 2, 3, 4, 5 };
......@@ -161,6 +161,7 @@ private:
return *this;
}
CopyCounter &operator=(CopyCounter &&other) = default;
~CopyCounter() = default;
int copyCount = 0;
bool transformed = false;
......
......@@ -63,7 +63,6 @@ public:
*/
void cleanup();
public Q_SLOTS:
/**
* Returns the list of identifiers of all available
* agent types.
......
......@@ -267,6 +267,8 @@ qt5_add_dbus_interface(akonadicore_dbus_SRCS ${akonadicore_dbus_xml} notificatio
qt5_add_dbus_interfaces(akonadicore_dbus_SRCS ${Akonadi_SOURCE_DIR}/src/interfaces/org.freedesktop.Akonadi.AgentManager.xml)
qt5_add_dbus_interfaces(akonadicore_dbus_SRCS ${Akonadi_SOURCE_DIR}/src/interfaces/org.freedesktop.Akonadi.Tracer.xml)
qt5_add_dbus_interfaces(akonadicore_dbus_SRCS ${Akonadi_SOURCE_DIR}/src/interfaces/org.freedesktop.Akonadi.Agent.Control.xml)
qt5_add_dbus_interfaces(akonadicore_dbus_SRCS
${Akonadi_SOURCE_DIR}/src/interfaces/org.freedesktop.Akonadi.Resource.xml)
set(akonadicore_SRCS
${akonadicore_base_SRCS}
......
......@@ -106,9 +106,7 @@ public:
/**
* Destroys the abstract differences reporter.
*/
virtual ~AbstractDifferencesReporter()
{
}
virtual ~AbstractDifferencesReporter() = default;
/**
* Sets the @p title of the property name column.
......@@ -137,6 +135,12 @@ public:
* @param rightValue The user visible property value of the right object.
*/
virtual void addProperty(Mode mode, const QString &name, const QString &leftValue, const QString &rightValue) = 0;
protected:
explicit AbstractDifferencesReporter() = default;
private:
Q_DISABLE_COPY_MOVE(AbstractDifferencesReporter);
};
}
......
......@@ -104,10 +104,8 @@ QSize AgentConfigurationBase::restoreDialogSize() const
return {};
}
void AgentConfigurationBase::saveDialogSize(const QSize &size)
{
Q_UNUSED(size);
}
void AgentConfigurationBase::saveDialogSize(QSize)
{}
QDialogButtonBox::StandardButtons AgentConfigurationBase::standardButtons() const
{
......
......@@ -135,7 +135,7 @@ public:
/**
* Reimplement to save dialog size.
*/
virtual void saveDialogSize(const QSize &size);
virtual void saveDialogSize(QSize size);
virtual QDialogButtonBox::StandardButtons standardButtons() const;
......
......@@ -313,32 +313,22 @@ void AgentManagerPrivate::createDBusInterface()
{
mTypes.clear();
mInstances.clear();
delete mManager;
mManager = new org::freedesktop::Akonadi::AgentManager(ServerManager::serviceName(ServerManager::Control),
using AgentManagerIface = org::freedesktop::Akonadi::AgentManager;
mManager = std::make_unique<AgentManagerIface>(ServerManager::serviceName(ServerManager::Control),
QStringLiteral("/AgentManager"),
QDBusConnection::sessionBus(), mParent);
QObject::connect(mManager, SIGNAL(agentTypeAdded(QString)),
mParent, SLOT(agentTypeAdded(QString)));
QObject::connect(mManager, SIGNAL(agentTypeRemoved(QString)),
mParent, SLOT(agentTypeRemoved(QString)));
QObject::connect(mManager, SIGNAL(agentInstanceAdded(QString)),
mParent, SLOT(agentInstanceAdded(QString)));
QObject::connect(mManager, SIGNAL(agentInstanceRemoved(QString)),
mParent, SLOT(agentInstanceRemoved(QString)));
QObject::connect(mManager, SIGNAL(agentInstanceStatusChanged(QString,int,QString)),
mParent, SLOT(agentInstanceStatusChanged(QString,int,QString)));
QObject::connect(mManager, SIGNAL(agentInstanceProgressChanged(QString,uint,QString)),
mParent, SLOT(agentInstanceProgressChanged(QString,uint,QString)));
QObject::connect(mManager, SIGNAL(agentInstanceNameChanged(QString,QString)),
mParent, SLOT(agentInstanceNameChanged(QString,QString)));
QObject::connect(mManager, SIGNAL(agentInstanceWarning(QString,QString)),
mParent, SLOT(agentInstanceWarning(QString,QString)));
QObject::connect(mManager, SIGNAL(agentInstanceError(QString,QString)),
mParent, SLOT(agentInstanceError(QString,QString)));
QObject::connect(mManager, SIGNAL(agentInstanceOnlineChanged(QString,bool)),
mParent, SLOT(agentInstanceOnlineChanged(QString,bool)));
connect(mManager.get(), &AgentManagerIface::agentTypeAdded, this, &AgentManagerPrivate::agentTypeAdded);
connect(mManager.get(), &AgentManagerIface::agentTypeRemoved, this, &AgentManagerPrivate::agentTypeRemoved);
connect(mManager.get(), &AgentManagerIface::agentInstanceAdded, this, &AgentManagerPrivate::agentInstanceAdded);
connect(mManager.get(), &AgentManagerIface::agentInstanceRemoved, this, &AgentManagerPrivate::agentInstanceRemoved);
connect(mManager.get(), &AgentManagerIface::agentInstanceStatusChanged, this, &AgentManagerPrivate::agentInstanceStatusChanged);
connect(mManager.get(), &AgentManagerIface::agentInstanceProgressChanged, this, &AgentManagerPrivate::agentInstanceProgressChanged);
connect(mManager.get(), &AgentManagerIface::agentInstanceNameChanged, this, &AgentManagerPrivate::agentInstanceNameChanged);
connect(mManager.get(), &AgentManagerIface::agentInstanceWarning, this, &AgentManagerPrivate::agentInstanceWarning);
connect(mManager.get(), &AgentManagerIface::agentInstanceError, this, &AgentManagerPrivate::agentInstanceError);
connect(mManager.get(), &AgentManagerIface::agentInstanceOnlineChanged, this, &AgentManagerPrivate::agentInstanceOnlineChanged);
if (mManager->isValid()) {
readAgentTypes();
......@@ -374,10 +364,7 @@ AgentManager::AgentManager()
// @endcond
AgentManager::~AgentManager()
{
delete d;
}
AgentManager::~AgentManager() = default;
AgentManager *AgentManager::self()
{
......
......@@ -27,6 +27,8 @@
#include <QObject>
#include <memory>
namespace Akonadi
{
......@@ -199,20 +201,9 @@ Q_SIGNALS:
private:
//@cond PRIVATE
AgentManager();
AgentManagerPrivate *const d;
Q_PRIVATE_SLOT(d, void agentTypeAdded(const QString &))
Q_PRIVATE_SLOT(d, void agentTypeRemoved(const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceAdded(const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceRemoved(const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceStatusChanged(const QString &, int, const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceProgressChanged(const QString &, uint, const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceNameChanged(const QString &, const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceWarning(const QString &, const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceError(const QString &, const QString &))
Q_PRIVATE_SLOT(d, void agentInstanceOnlineChanged(const QString &, bool))
explicit AgentManager();
std::unique_ptr<AgentManagerPrivate> const d;
//@endcond
};
......
......@@ -39,15 +39,15 @@ class AgentManager;
/**
* @internal
*/
class AgentManagerPrivate
class AgentManagerPrivate : public QObject
{
friend class AgentManager;
Q_OBJECT
public:
explicit AgentManagerPrivate(AgentManager *parent)
: mParent(parent)
{
}
{}
/*
* Used by AgentInstanceCreateJob
......@@ -98,7 +98,7 @@ public:
static AgentManager *mSelf;
AgentManager *mParent = nullptr;
org::freedesktop::Akonadi::AgentManager *mManager = nullptr;
std::unique_ptr<org::freedesktop::Akonadi::AgentManager> mManager;
QHash<QString, AgentType> mTypes;
QHash<QString, AgentInstance> mInstances;
......
......@@ -136,7 +136,7 @@ namespace Akonadi
*
* @author Volker Krause <vkrause@kde.org>
*/
class AKONADICORE_EXPORT Attribute
class AKONADICORE_EXPORT Attribute // clazy:exclude=copyable-polymorphic
{
public:
/**
......@@ -172,6 +172,10 @@ public:
* @param data The encoded attribute data.
*/
virtual void deserialize(const QByteArray &data) = 0;
protected:
explicit Attribute() = default;
Q_DISABLE_COPY_MOVE(Attribute)
};
}
......
......@@ -70,7 +70,7 @@ public:
namespace
{
Braveheart Wallace;
Braveheart Wallace; // clazy:exclude=non-pod-global-static
}
......
......@@ -27,7 +27,11 @@
using namespace Akonadi;
class GlobalChangeMediator : public ChangeMediator {};
class GlobalChangeMediator : public ChangeMediator
{
Q_OBJECT
};
Q_GLOBAL_STATIC(GlobalChangeMediator, s_globalChangeMediator)
ChangeMediator *ChangeMediator::instance()
......@@ -67,7 +71,7 @@ void ChangeMediator::unregisterMonitor(QObject *monitor)
void ChangeMediator::invalidateCollection(const Akonadi::Collection &collection)
{
QMetaObject::invokeMethod(instance(), [colId = collection.id()]() {
for (auto monitor : instance()->m_monitors) {
for (auto *monitor : qAsConst(instance()->m_monitors)) {
const bool ok = QMetaObject::invokeMethod(monitor, "invalidateCollectionCache", Q_ARG(qint64, colId));
Q_ASSERT(ok); Q_UNUSED(ok);
}
......@@ -78,7 +82,7 @@ void ChangeMediator::invalidateCollection(const Akonadi::Collection &collection)
void ChangeMediator::invalidateItem(const Akonadi::Item &item)
{
QMetaObject::invokeMethod(instance(), [itemId = item.id()]() {
for (auto monitor : instance()->m_monitors) {
for (auto monitor : qAsConst(instance()->m_monitors)) {
const bool ok = QMetaObject::invokeMethod(monitor, "invalidateItemCache", Q_ARG(qint64, itemId));
Q_ASSERT(ok); Q_UNUSED(ok);
}
......@@ -89,10 +93,11 @@ void ChangeMediator::invalidateItem(const Akonadi::Item &item)
void ChangeMediator::invalidateTag(const Tag &tag)
{
QMetaObject::invokeMethod(instance(), [tagId = tag.id()]() {
for (auto monitor : instance()->m_monitors) {
for (auto monitor : qAsConst(instance()->m_monitors)) {
const bool ok = QMetaObject::invokeMethod(monitor, "invalidateTagCache", Q_ARG(qint64, tagId));
Q_ASSERT(ok); Q_UNUSED(ok);
}
});
}
#include "changemediator_p.moc"
......@@ -49,6 +49,7 @@ public:
protected:
explicit ChangeMediator(QObject *parent = nullptr);
Q_DISABLE_COPY_MOVE(ChangeMediator)
QList<QObject *> m_monitors;
};
......
......@@ -36,6 +36,7 @@ class CommandBuffer;
class AKONADI_TESTS_EXPORT ChangeNotificationDependenciesFactory
{
public:
explicit ChangeNotificationDependenciesFactory() = default;
virtual ~ChangeNotificationDependenciesFactory() = default;
virtual Connection *createNotificationConnection(Session *parent, CommandBuffer *commandBuffer);
......@@ -49,6 +50,8 @@ public:
virtual Akonadi::TagListCache *createTagListCache(int maxCapacity, Session *session);
protected:
Q_DISABLE_COPY_MOVE(ChangeNotificationDependenciesFactory)
void addConnection(Session *session, Connection *connection);
};
......
......@@ -73,7 +73,8 @@ void ChangeRecorder::replayNext()
// In the case of a move where both source and destination are
// ignored, we ignore the message and process the next one.
d->dequeueNotification();
return replayNext();
replayNext();
return;
}
} else {
// This is necessary when none of the notifications were accepted / processed
......
......@@ -186,7 +186,7 @@ Attribute::List Collection::attributes() const
void Akonadi::Collection::clearAttributes()
{
return d_ptr->mAttributeStorage.clearAttributes();
d_ptr->mAttributeStorage.clearAttributes();
}
Attribute *Collection::attribute(const QByteArray &type)
......
......@@ -453,8 +453,7 @@ public:
if (parentCollection == akonadiRootCollection || parentCollection.id() > 0) {
++pendingJobs;
CollectionCreateJob *create = new CollectionCreateJob(col, currentTransaction);
connect(create, SIGNAL(result(KJob*)),
q, SLOT(createLocalCollectionResult(KJob*)));
QObject::connect(create, &KJob::result, q, [this](KJob *job) { createLocalCollectionResult(job); });
// Commit transaction after every 100 collections are created,
// otherwise it overloads database journal and things get veeery slow
......@@ -585,14 +584,14 @@ public:
c.setParentCollection(local.parentCollection());
++pendingJobs;
CollectionModifyJob *mod = new CollectionModifyJob(c, currentTransaction);
connect(mod, SIGNAL(result(KJob*)), q, SLOT(updateLocalCollectionResult(KJob*)));
QObject::connect(mod, &KJob::result, q, [this](KJob *job) { updateLocalCollectionResult(job); });
// detecting moves is only possible with global RIDs
if (!hierarchicalRIDs) {
if (remote.parentCollection().isValid() && remote.parentCollection().id() != local.parentCollection().id()) {
++pendingJobs;
CollectionMoveJob *move = new CollectionMoveJob(upd, remote.parentCollection(), currentTransaction);
connect(move, SIGNAL(result(KJob*)), q, SLOT(updateLocalCollectionResult(KJob*)));
QObject::connect(move, &KJob::result, q, [this](KJob *job) { updateLocalCollectionResult(job); });
}
}
}
......@@ -630,7 +629,7 @@ public:
++pendingJobs;
Q_ASSERT(currentTransaction);
CollectionDeleteJob *job = new CollectionDeleteJob(col, currentTransaction);
connect(job, SIGNAL(result(KJob*)), q, SLOT(deleteLocalCollectionsResult(KJob*)));
connect(job, &KJob::result, q, [this](KJob *job) { deleteLocalCollectionsResult(job); });
// It can happen that the groupware servers report us deleted collections
// twice, in this case this collection delete job will fail on the second try.
......@@ -694,8 +693,7 @@ public:
{
currentTransaction = new TransactionSequence(q);
currentTransaction->setAutomaticCommittingEnabled(false);
q->connect(currentTransaction, SIGNAL(finished(KJob*)),
q, SLOT(transactionSequenceResult(KJob*)));
q->connect(currentTransaction, &TransactionSequence::finished, q, [this](KJob *job) { transactionSequenceResult(job); });
}
/** After the transaction has finished report we're done as well. */
......@@ -728,10 +726,8 @@ public:
job->fetchScope().setResource(resourceId);
job->fetchScope().setListFilter(CollectionFetchScope::NoFilter);
job->fetchScope().setAncestorRetrieval(CollectionFetchScope::All);
q->connect(job, SIGNAL(collectionsReceived(Akonadi::Collection::List)),
q, SLOT(localCollectionsReceived(Akonadi::Collection::List)));
q->connect(job, SIGNAL(result(KJob*)),
q, SLOT(localCollectionFetchResult(KJob*)));
q->connect(job, &CollectionFetchJob::collectionsReceived, q, [this](const auto &cols) { localCollectionsReceived(cols); });
q->connect(job, &KJob::result, q, [this](KJob *job) { localCollectionFetchResult(job); });
return;
}
......
......@@ -130,13 +130,6 @@ protected:
private:
class Private;
Private *const d;
Q_PRIVATE_SLOT(d, void localCollectionsReceived(const Akonadi::Collection::List &localCols))
Q_PRIVATE_SLOT(d, void localCollectionFetchResult(KJob *job))
Q_PRIVATE_SLOT(d, void updateLocalCollectionResult(KJob *job))
Q_PRIVATE_SLOT(d, void createLocalCollectionResult(KJob *job))
Q_PRIVATE_SLOT(d, void deleteLocalCollectionsResult(KJob *job))
Q_PRIVATE_SLOT(d, void transactionSequenceResult(KJob *job))
};
}
......
......@@ -75,6 +75,8 @@ public:
}
private:
Q_DISABLE_COPY_MOVE(CommandBuffer)
QObject *mParent = nullptr;
QByteArray mNotifySlot;
......@@ -115,6 +117,8 @@ public:
}
private:
Q_DISABLE_COPY_MOVE(CommandBufferLocker)
CommandBuffer *mBuffer = nullptr;
bool mLocked = false;
};
......@@ -138,6 +142,8 @@ public:
mBuffer->mNotify = true;
}
private:
Q_DISABLE_COPY_MOVE(CommandBufferNotifyBlocker)
CommandBuffer *mBuffer;
};
......
......@@ -212,7 +212,7 @@ void Connection::doForceReconnect()
Q_ASSERT(QThread::currentThread() == thread());
if (mSocket) {
mSocket->disconnect(this, SIGNAL(socketDisconnected()));
disconnect(mSocket.get(), &QLocalSocket::disconnected, this, &Connection::socketDisconnected);
mSocket->disconnectFromServer();
mSocket.reset();
}
......
......@@ -34,11 +34,7 @@ namespace Internal
class StaticControl : public Control
{
public:
StaticControl()
: Control()
{
}
Q_OBJECT
};
}
......@@ -57,10 +53,6 @@ public:
{
}
~Private()
{
}
void cleanup()
{
}
......@@ -172,4 +164,4 @@ bool Control::restart()
}
#include "moc_control.cpp"
#include "control.moc"
......@@ -58,19 +58,6 @@ Exception::Exception(const QString &what)
}
}
Exception::Exception(const Akonadi::Exception &other)
: std::exception(other)
{
if (!other.d) {
return;
}
try {
d = std::make_unique<Private>(*other.d);
} catch (...) {
}
}
Exception::Exception(Exception &&other) = default;
Exception::~Exception() = default;
QByteArray Exception::type() const
......
......@@ -40,7 +40,7 @@ namespace Akonadi
/**
Base class for exceptions used by the Akonadi library.
*/
class AKONADICORE_EXPORT Exception : public std::exception //krazy:exclude=dpointer
class AKONADICORE_EXPORT Exception : public std::exception
{
public:
/**
......@@ -58,13 +58,6 @@ public:
*/
explicit Exception(const QString &what);
/**
Copy constructor.
*/
Exception(const Exception &other);
Exception(Exception &&other);
/**
Destructor.
*/
......@@ -81,6 +74,8 @@ public:
virtual QByteArray type() const; // ### Akonadi 2: return const char *
private:
Q_DISABLE_COPY_MOVE(Exception)
class Private;
std::unique_ptr<Private> d;
};
......
......@@ -48,6 +48,12 @@ public:
* If you want to clear the gid from the database return QString("").
*/
virtual QString extractGid(const Item &item) const = 0;
protected:
explicit GidExtractorInterface() = default;
private:
Q_DISABLE_COPY_MOVE(GidExtractorInterface)
};
}
......
......@@ -428,11 +428,14 @@ struct PayloadTrait<std::shared_ptr<T>> {
* Non-template base class for the payload container.
*/
struct PayloadBase {
virtual ~PayloadBase()
{
}
virtual ~PayloadBase() = default;
virtual PayloadBase *clone() const = 0;
virtual const c