Changeset View
Changeset View
Standalone View
Standalone View
src/drive/teamdrivesearchquery.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 David Barchiesi <david@barchie.si> | ||||
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) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "teamdrivesearchquery.h" | ||||
22 | | ||||
23 | #include <QString> | ||||
24 | #include <QDateTime> | ||||
25 | | ||||
26 | using namespace KGAPI2; | ||||
27 | using namespace KGAPI2::Drive; | ||||
28 | | ||||
29 | | ||||
30 | QString TeamdriveSearchQuery::fieldToString(Field field) | ||||
31 | { | ||||
32 | switch (field) { | ||||
33 | case Name: | ||||
34 | return QStringLiteral("name"); | ||||
35 | case CreatedTime: | ||||
36 | return QStringLiteral("createdTime"); | ||||
37 | case MemberCount: | ||||
38 | return QStringLiteral("memberCount"); | ||||
39 | case OrganizerCount: | ||||
40 | return QStringLiteral("organizerCount"); | ||||
41 | } | ||||
42 | | ||||
43 | Q_ASSERT(false); | ||||
44 | return QString(); | ||||
45 | } | ||||
46 | | ||||
47 | QString TeamdriveSearchQuery::valueToString(TeamdriveSearchQuery::Field field, const QVariant &var) | ||||
48 | { | ||||
49 | switch (field) { | ||||
50 | case Name: | ||||
51 | return QStringLiteral("'%1'").arg(var.toString().replace(QLatin1Char('\''), QLatin1String("\\\'"))); | ||||
52 | case MemberCount: | ||||
53 | case OrganizerCount: | ||||
54 | return var.toString(); | ||||
55 | case CreatedTime: | ||||
56 | return QStringLiteral("'%1'").arg(var.toDateTime().toUTC().toString(QStringLiteral("yyyy-MM-ddThh:mm:ss"))); | ||||
57 | } | ||||
58 | | ||||
59 | Q_ASSERT(false); | ||||
60 | return QString(); | ||||
61 | } | ||||
62 | | ||||
63 | void TeamdriveSearchQuery::addQuery(TeamdriveSearchQuery::Field field, TeamdriveSearchQuery::CompareOperator op, const QVariant &value) | ||||
64 | { | ||||
65 | switch (field) { | ||||
66 | case Name: | ||||
67 | Q_ASSERT(op == Contains || op == Equals || op == NotEquals); | ||||
68 | Q_ASSERT(value.canConvert<QString>()); | ||||
69 | break; | ||||
70 | case MemberCount: | ||||
71 | case OrganizerCount: | ||||
72 | Q_ASSERT(op == LessOrEqual || op == Less || op == Equals || op == NotEquals || op == Greater || op == GreaterOrEqual); | ||||
73 | Q_ASSERT(value.canConvert<int>()); | ||||
74 | break; | ||||
75 | case CreatedTime: | ||||
76 | Q_ASSERT(op == LessOrEqual || op == Less || op == Equals || op == NotEquals || op == Greater || op == GreaterOrEqual); | ||||
77 | Q_ASSERT(value.canConvert<QDateTime>()); | ||||
78 | break; | ||||
79 | } | ||||
80 | | ||||
81 | SearchQuery::addQuery(fieldToString(field), op, valueToString(field, value)); | ||||
82 | } |