Akonadi

commandcontext.cpp
1 /*
2  * Copyright (C) 2014 Daniel Vrátil <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #include "commandcontext.h"
21 #include "storage/selectquerybuilder.h"
22 
23 #include <private/protocol_p.h>
24 
25 using namespace Akonadi;
26 using namespace Akonadi::Server;
27 
28 void CommandContext::setResource(const Resource &resource)
29 {
30  mResource = resource;
31 }
32 
33 Resource CommandContext::resource() const
34 {
35  return mResource;
36 }
37 
38 bool CommandContext::setScopeContext(const Protocol::ScopeContext &scopeContext)
39 {
40  if (scopeContext.hasContextId(Protocol::ScopeContext::Collection)) {
41  mCollection = Collection::retrieveById(scopeContext.contextId(Protocol::ScopeContext::Collection));
42  } else if (scopeContext.hasContextRID(Protocol::ScopeContext::Collection)) {
43  if (mResource.isValid()) {
45  qb.addValueCondition(Collection::remoteIdColumn(), Query::Equals, scopeContext.contextRID(Protocol::ScopeContext::Collection));
46  qb.addValueCondition(Collection::resourceIdColumn(), Query::Equals, mResource.id());
47  qb.exec();
48  Collection::List cols = qb.result();
49  if (cols.isEmpty()) {
50  // error
51  return false;
52  }
53  mCollection = cols.at(0);
54  } else {
55  return false;
56  }
57  }
58 
59  if (scopeContext.hasContextId(Protocol::ScopeContext::Tag)) {
60  mTagId = scopeContext.contextId(Protocol::ScopeContext::Tag);
61  }
62 
63  return true;
64 }
65 
66 void CommandContext::setCollection(const Collection &collection)
67 {
68  mCollection = collection;
69 }
70 
71 qint64 CommandContext::collectionId() const
72 {
73  return mCollection.id();
74 }
75 
76 Collection CommandContext::collection() const
77 {
78  return mCollection;
79 }
80 
81 void CommandContext::setTag(std::optional<qint64> tagId)
82 {
83  mTagId = std::move(tagId);
84 }
85 
86 std::optional<qint64> CommandContext::tagId() const
87 {
88  return mTagId;
89 }
90 
91 Tag CommandContext::tag() const
92 {
93  return mTagId.has_value() ? Tag::retrieveById(mTagId.value()) : Tag();
94 }
95 
96 bool CommandContext::isEmpty() const
97 {
98  return !mCollection.isValid() && !mTagId.has_value();
99 }
100 
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.
Represents a collection of PIM items.
Definition: collection.h:76
QVector< T > result()
Returns the result of this SELECT query.
const T & at(int i) const const
Helper class for creating and executing database SELECT queries.
static Tag retrieveById(qint64 id)
Returns the record with id id.
Definition: entities.cpp:8535
Id id() const
Returns the unique identifier of the collection.
Definition: collection.cpp:112
bool isEmpty() const const
Helper integration between Akonadi and Qt.
static Collection retrieveById(qint64 id)
Returns the record with id id.
Definition: entities.cpp:2037
An Akonadi Tag.
Definition: tag.h:39
Representation of a record in the Resource table.
Definition: entities.h:246
bool exec()
Executes the query, returns true on success.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue May 26 2020 22:46:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.