Kgapi

filesearchquery.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
3 * SPDX-FileCopyrightText: 2019 David Barchiesi <david@barchie.si>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8#include "filesearchquery.h"
9#include "utils.h"
10
11#include <QDateTime>
12#include <QString>
13
14using namespace KGAPI2;
15using namespace KGAPI2::Drive;
16
17QString FileSearchQuery::fieldToString(Field field)
18{
19 switch (field) {
20 case Title:
21 return QStringLiteral("title");
22 case FullText:
23 return QStringLiteral("fullText");
24 case MimeType:
25 return QStringLiteral("mimeType");
26 case ModifiedDate:
27 return QStringLiteral("modifiedDate");
28 case LastViewedByMeDate:
29 return QStringLiteral("lastViewedByMeDate");
30 case Trashed:
31 return QStringLiteral("trashed");
32 case Starred:
33 return QStringLiteral("starred");
34 case Parents:
35 return QStringLiteral("parents");
36 case Owners:
37 return QStringLiteral("owners");
38 case Writers:
39 return QStringLiteral("writers");
40 case Readers:
41 return QStringLiteral("readers");
42 case SharedWithMe:
43 return QStringLiteral("sharedWithMe");
44 }
45
46 Q_ASSERT(false);
47 return QString();
48}
49
50QString FileSearchQuery::valueToString(FileSearchQuery::Field field, const QVariant &var)
51{
52 switch (field) {
53 case Title:
54 case FullText:
55 case MimeType:
56 case Parents:
57 case Owners:
58 case Writers:
59 case Readers:
60 return QStringLiteral("'%1'").arg(var.toString().replace(QLatin1Char('\''), QLatin1StringView("\\\'")));
61 case ModifiedDate:
62 case LastViewedByMeDate:
63 return QStringLiteral("'%1'").arg(var.toDateTime().toUTC().toString(QStringLiteral("yyyy-MM-ddThh:mm:ss")));
64 case Trashed:
65 case Starred:
66 case SharedWithMe:
67 return Utils::bool2Str(var.toBool());
68 }
69
70 Q_ASSERT(false);
71 return QString();
72}
73
74void FileSearchQuery::addQuery(FileSearchQuery::Field field, FileSearchQuery::CompareOperator op, const QVariant &value)
75{
76 switch (field) {
77 case Title:
78 case MimeType:
79 Q_ASSERT(op == Contains || op == Equals || op == NotEquals);
80 Q_ASSERT(value.canConvert<QString>());
81 break;
82 case FullText:
83 Q_ASSERT(op == Contains);
84 Q_ASSERT(value.canConvert<QString>());
85 break;
86 case ModifiedDate:
87 case LastViewedByMeDate:
88 Q_ASSERT(op == LessOrEqual || op == Less || op == Equals || op == NotEquals || op == Greater || op == GreaterOrEqual);
89 Q_ASSERT(value.canConvert<QDateTime>());
90 break;
91 case Trashed:
92 case Starred:
93 case SharedWithMe:
94 Q_ASSERT(op == Equals || op == NotEquals);
95 Q_ASSERT(value.canConvert<bool>());
96 break;
97 case Parents:
98 case Owners:
99 case Writers:
100 case Readers:
101 Q_ASSERT(op == In);
102 Q_ASSERT(value.canConvert<QString>());
103 break;
104 }
105
106 SearchQuery::addQuery(fieldToString(field), op, valueToString(field, value));
107}
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
QString toString(QStringView format, QCalendar cal) const const
QDateTime toUTC() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
bool canConvert() const const
bool toBool() const const
QDateTime toDateTime() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.