KNewStuff

searchrequest.cpp
1// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
2// SPDX-FileCopyrightText: 2024 Harald Sitter <sitter@kde.org>
3
4#include "searchrequest.h"
5#include "searchrequest_p.h"
6
7#include <QDebug>
8
9using namespace KNSCore;
10
11SearchRequest::SearchRequest(SortMode sortMode_, Filter filter_, const QString &searchTerm_, const QStringList &categories_, int page_, int pageSize_)
12 : d(new SearchRequestPrivate{.sortMode = sortMode_,
13 .filter = filter_,
14 .searchTerm = searchTerm_,
15 .categories = categories_,
16 .page = page_,
17 .pageSize = pageSize_,
18 .id = SearchRequestPrivate::searchRequestId()})
19{
20}
21
22SortMode SearchRequest::sortMode() const
23{
24 return d->sortMode;
25}
26
27Filter SearchRequest::filter() const
28{
29 return d->filter;
30}
31
32QString SearchRequest::searchTerm() const
33{
34 return d->searchTerm;
35}
36
37QStringList SearchRequest::categories() const
38{
39 return d->categories;
40}
41
42int SearchRequest::page() const
43{
44 return d->page;
45}
46
47int SearchRequest::pageSize() const
48{
49 return d->page;
50}
51
52SearchRequest SearchRequest::nextPage() const
53{
54 return {sortMode(), filter(), searchTerm(), categories(), page() + 1, pageSize()};
55}
56
57KNEWSTUFFCORE_EXPORT QDebug KNSCore::operator<<(QDebug dbg, const SearchRequest &search)
58{
59 QDebugStateSaver saver(dbg);
60 dbg.nospace();
61 dbg << "SearchRequest(";
62 dbg << "id: " << search.d->id << ',';
63 dbg << "searchTerm: " << search.d->searchTerm << ',';
64 dbg << "categories: " << search.d->categories << ',';
65 dbg << "filter: " << search.d->filter << ',';
66 dbg << "page: " << search.d->page << ',';
67 dbg << "pageSize: " << search.d->pageSize;
68 dbg << ')';
69 return dbg;
70}
71
72KNSCore::SearchRequest KNSCore::searchRequestFromLegacy(const KNSCore::Provider::SearchRequest &request)
73{
74 return {[request] {
75 switch (request.sortMode) {
76 case Provider::SortMode::Alphabetical:
77 return SortMode::Alphabetical;
78 case Provider::SortMode::Downloads:
79 return SortMode::Downloads;
80 case Provider::SortMode::Newest:
81 return SortMode::Newest;
82 case Provider::SortMode::Rating:
83 return SortMode::Rating;
84 }
85 Q_ASSERT(false);
86 return SortMode::Rating;
87 }(),
88 [request] {
89 switch (request.filter) {
90 case Provider::Filter::None:
91 return Filter::None;
92 case Provider::Filter::Installed:
93 return Filter::Installed;
94 case Provider::Filter::Updates:
95 return Filter::Updates;
96 case Provider::Filter::ExactEntryId:
97 return Filter::ExactEntryId;
98 }
99 Q_ASSERT(false);
100 return Filter::None;
101 }(),
102 request.searchTerm,
103 request.categories,
104 request.page,
105 request.pageSize};
106}
A search request.
KREPORT_EXPORT QPageSize::PageSizeId pageSize(const QString &key)
QDebug & nospace()
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
used to keep track of a search
Definition provider.h:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:20:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.