Akonadi

commandcontext.cpp
1 /*
2  * SPDX-FileCopyrightText: 2014 Daniel Vr├ítil <[email protected]>
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 
13 using namespace Akonadi;
14 using namespace Akonadi::Server;
15 
16 void CommandContext::setResource(const Resource &resource)
17 {
18  mResource = resource;
19 }
20 
21 Resource CommandContext::resource() const
22 {
23  return mResource;
24 }
25 
26 bool 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 
54 void CommandContext::setCollection(const Collection &collection)
55 {
56  mCollection = collection;
57 }
58 
59 qint64 CommandContext::collectionId() const
60 {
61  return mCollection.id();
62 }
63 
64 Collection CommandContext::collection() const
65 {
66  return mCollection;
67 }
68 
69 void CommandContext::setTag(std::optional<qint64> tagId)
70 {
71  mTagId = tagId;
72 }
73 
74 std::optional<qint64> CommandContext::tagId() const
75 {
76  return mTagId;
77 }
78 
79 Tag CommandContext::tag() const
80 {
81  return mTagId.has_value() ? Tag::retrieveById(*mTagId) : Tag();
82 }
83 
84 bool CommandContext::isEmpty() const
85 {
86  return !mCollection.isValid() && !mTagId.has_value();
87 }
bool isEmpty() const const
An Akonadi Tag.
Definition: tag.h:25
Represents a collection of PIM items.
Definition: collection.h:61
const T & at(int i) const const
QVector< T > result()
Returns the result of this SELECT query.
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.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.