7#include "searchpresetmodel.h"
9#include "knewstuffquick_debug.h"
11#include <KLocalizedString>
13#include "../core/enginebase_p.h"
25SearchPresetModel::~SearchPresetModel() =
default;
29 static const QHash<int, QByteArray> roles{{DisplayNameRole,
"displayName"}, {IconRole,
"iconName"}};
36 const QList<KNSCore::SearchPreset> presets = m_engine->d->searchPresets;
37 const KNSCore::SearchPreset &preset = presets[
index.row()];
39 if (role == DisplayNameRole) {
40 if (QString name = preset.displayName(); !
name.
isEmpty()) {
44 switch (preset.type()) {
46 return i18nc(
"Knewstuff5",
"Back");
48 return i18nc(
"Knewstuff5",
"Popular");
50 return i18nc(
"Knewstuff5",
"Featured");
52 return i18nc(
"Knewstuff5",
"Restart");
54 return i18nc(
"Knewstuff5",
"New");
56 return i18nc(
"Knewstuff5",
"Home");
58 return i18nc(
"Knewstuff5",
"Shelf");
60 return i18nc(
"Knewstuff5",
"Up");
62 return i18nc(
"Knewstuff5",
"Recommended");
64 return i18nc(
"Knewstuff5",
"Subscriptions");
66 return i18nc(
"Knewstuff5",
"All Entries");
67 case KNSCore::SearchPreset::Type::NoPresetType:
70 return i18nc(
"Knewstuff5",
"Search Preset: %1", preset.request().searchTerm());
72 if (role == IconRole) {
73 if (QString name = preset.iconName(); !
name.
isEmpty()) {
77 switch (preset.type()) {
79 return QStringLiteral(
"arrow-left");
83 return QStringLiteral(
"rating");
85 return QStringLiteral(
"change-date-symbolic");
87 return QStringLiteral(
"start-over");
89 return QStringLiteral(
"go-home");
92 return QStringLiteral(
"bookmark");
94 return QStringLiteral(
"arrow-up");
96 case KNSCore::SearchPreset::Type::NoPresetType:
99 return QStringLiteral(
"search");
105int SearchPresetModel::rowCount(
const QModelIndex &parent)
const
110 return m_engine->d->searchPresets.count();
113void SearchPresetModel::loadSearch(
const QModelIndex &index)
115 if (
index.row() >= rowCount() || !
index.isValid()) {
116 qCWarning(KNEWSTUFFQUICK) <<
"index SearchPresetModel::loadSearch invalid" <<
index;
119 const auto preset = m_engine->d->searchPresets.at(
index.row());
120 m_engine->search(preset.request());
123#include "moc_searchpresetmodel.cpp"
void signalSearchPresetsLoaded(const QList< Provider::SearchPreset > &presets)
Fires when the engine has loaded search presets.
@ FolderUp
preset indicating going up in the search result hierarchy.
@ New
preset indicating new items.
@ Featured
preset for featured items.
@ Shelf
preset indicating previously acquired items.
@ Popular
preset indicating popular items.
@ Recommended
preset for recommended. This may be customized by the server per user.
@ AllEntries
preset indicating all possible entries, such as a crawlable list. Might be intense to load.
@ Subscription
preset indicating items that the user is subscribed to.
@ Start
preset indicating the first entry.
@ GoBack
preset representing the previous search.
@ Root
preset indicating a root directory.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString name(StandardAction id)
bool checkIndex(const QModelIndex &index, CheckIndexOptions options) const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual QModelIndex parent(const QModelIndex &index) const const=0
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)