Akonadi

commandcontext.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 */
7
8#include "commandcontext.h"
9#include "storage/selectquerybuilder.h"
10
11#include "private/protocol_p.h"
12
13using namespace Akonadi;
14using namespace Akonadi::Server;
15
16void CommandContext::setResource(const Resource &resource)
17{
18 mResource = resource;
19}
20
21Resource CommandContext::resource() const
22{
23 return mResource;
24}
25
26bool CommandContext::setScopeContext(const Protocol::ScopeContext &scopeContext)
27{
28 if (scopeContext.hasContextId(Protocol::ScopeContext::Collection)) {
29 mCollection = Collection::retrieveById(scopeContext.contextId(Protocol::ScopeContext::Collection));
30 } else if (scopeContext.hasContextRID(Protocol::ScopeContext::Collection)) {
31 if (mResource.isValid()) {
33 qb.addValueCondition(Collection::remoteIdColumn(), Query::Equals, scopeContext.contextRID(Protocol::ScopeContext::Collection));
34 qb.addValueCondition(Collection::resourceIdColumn(), Query::Equals, mResource.id());
35 qb.exec();
36 Collection::List cols = qb.result();
37 if (cols.isEmpty()) {
38 // error
39 return false;
40 }
41 mCollection = cols.at(0);
42 } else {
43 return false;
44 }
45 }
46
47 if (scopeContext.hasContextId(Protocol::ScopeContext::Tag)) {
48 mTagId = scopeContext.contextId(Protocol::ScopeContext::Tag);
49 }
50
51 return true;
52}
53
54void CommandContext::setCollection(const Collection &collection)
55{
56 mCollection = collection;
57}
58
59qint64 CommandContext::collectionId() const
60{
61 return mCollection.id();
62}
63
64Collection CommandContext::collection() const
65{
66 return mCollection;
67}
68
69void CommandContext::setTag(std::optional<qint64> tagId)
70{
71 mTagId = tagId;
72}
73
74std::optional<qint64> CommandContext::tagId() const
75{
76 return mTagId;
77}
78
79Tag CommandContext::tag() const
80{
81 return mTagId.has_value() ? Tag::retrieveById(*mTagId) : Tag();
82}
83
84bool CommandContext::isEmpty() const
85{
86 return !mCollection.isValid() && !mTagId.has_value();
87}
Represents a collection of PIM items.
Definition collection.h:62
void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, ConditionType type=WhereCondition)
Add a WHERE or HAVING condition which compares a column with a given value.
bool exec()
Executes the query, returns true on success.
Helper class for creating and executing database SELECT queries.
QList< T > result()
Returns the result of this SELECT query.
An Akonadi Tag.
Definition tag.h:26
Helper integration between Akonadi and Qt.
const_reference at(qsizetype i) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:00:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.