Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
LauncherModel.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3#pragma once
4
6#include <PhosphorShellLauncher/phosphorshelllauncher_export.h>
7
8#include <QAbstractListModel>
9#include <QHash>
10#include <QList>
11#include <QString>
12#include <QStringList>
13#include <QVariantList>
14
15namespace PhosphorShellLauncher {
16
17// The one model the launcher surface binds: every provider's rows for
18// the current query, ranked, grouped by provider, filterable to one.
19//
20// Ranking is by score within a provider, and providers are ordered by
21// their best row, so the section with the most relevant hit comes first
22// while rows stay grouped under their provider header (the mockup's
23// layout). Across providers the scores are comparable because every
24// fuzzy-matching provider scores through the same FuzzyMatcher, and an
25// exact-answer provider uses FuzzyMatcher::perfectScore to place itself.
26//
27// Owns no providers. A host creates them (through the registry) and
28// addProvider()s each; the model connects to resultsChanged and rebuilds.
29// It is registry-agnostic so a test can feed it any ILauncherProvider.
30class PHOSPHORSHELLLAUNCHER_EXPORT LauncherModel : public QAbstractListModel
31{
32 Q_OBJECT
33 Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged)
34 // Empty shows every provider; a provider id shows only that one.
35 // The pills in the surface set this; Tab cycles it.
36 Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
37 Q_PROPERTY(QString providerFilter READ providerFilter WRITE setProviderFilter NOTIFY providerFilterChanged)
38 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
39 // One entry per registered provider, in registration order, each a
40 // map {id, name, iconName, count} where count is that provider's rows
41 // for the current query (before the filter). For the pill strip.
42 Q_PROPERTY(QVariantList providers READ providers NOTIFY providersChanged)
43
44public:
58 Q_ENUM(Role)
59
60 explicit LauncherModel(QObject* parent = nullptr);
61 ~LauncherModel() override;
62
63 // Not owned. Registration order is the pill order and the tie-break
64 // between providers with equal best scores.
65 void addProvider(PhosphorRegistry::ILauncherProvider* provider);
66 [[nodiscard]] QList<PhosphorRegistry::ILauncherProvider*> providerObjects() const;
67
68 [[nodiscard]] QString query() const;
69 void setQuery(const QString& query);
70
82 [[nodiscard]] bool active() const;
83 void setActive(bool active);
84
85 [[nodiscard]] QString providerFilter() const;
86 void setProviderFilter(const QString& providerId);
87 // Step the filter through "all" and each provider that has rows, in
88 // order; +1 forward, -1 back. Tab and Shift+Tab.
89 Q_INVOKABLE void cycleProviderFilter(int direction);
90
91 [[nodiscard]] QVariantList providers() const;
92
93 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
94 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
95 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
96
97 // Perform row's primary (or alternate) action. False when the row is
98 // out of range, the alternate was asked for but not offered, or the
99 // provider refused; the surface stays open in that case.
100 [[nodiscard]] Q_INVOKABLE bool activate(int row, bool alternate = false);
101
110 [[nodiscard]] Q_INVOKABLE bool alternateIsRepeatable(int row) const;
111
112Q_SIGNALS:
118
119private:
120 struct Row
121 {
124 };
125 void rebuild();
126
127 QList<PhosphorRegistry::ILauncherProvider*> m_providers;
128 QString m_query;
129 // Up only while setQuery is pushing the query to every provider, so
130 // their synchronous answers coalesce into one rebuild instead of one
131 // each. See setQuery.
132 bool m_batchingQuery = false;
133 bool m_active = true;
134 // A rebuild that was skipped because the surface was not on screen.
135 bool m_rebuildDeferred = false;
136 QString m_providerFilter;
137 QList<Row> m_rows;
138 // Per-provider row counts for the current query, unfiltered.
139 QHash<QString, int> m_counts;
140};
141
142} // namespace PhosphorShellLauncher
Definition ILauncherProvider.h:106
bool activate(int row, bool alternate=false)
QHash< int, QByteArray > roleNames() const override
void cycleProviderFilter(int direction)
LauncherModel(QObject *parent=nullptr)
void setQuery(const QString &query)
bool active() const
Whether the surface showing this model is on screen.
Role
Definition LauncherModel.h:45
@ SubtitleRole
Definition LauncherModel.h:47
@ AlternateActionLabelRole
Definition LauncherModel.h:54
@ ProviderNameRole
Definition LauncherModel.h:50
@ TitleRole
Definition LauncherModel.h:46
@ ProviderIconRole
Definition LauncherModel.h:51
@ ProviderIdRole
Definition LauncherModel.h:49
@ ScoreRole
Definition LauncherModel.h:56
@ HasAlternateActionRole
Definition LauncherModel.h:55
@ IconNameRole
Definition LauncherModel.h:48
@ ResultIdRole
Definition LauncherModel.h:52
@ PrimaryActionLabelRole
Definition LauncherModel.h:53
void setProviderFilter(const QString &providerId)
QList< PhosphorRegistry::ILauncherProvider * > providerObjects() const
bool alternateIsRepeatable(int row) const
Whether row's ALTERNATE action can sensibly be repeated on the same list, which is what decides wheth...
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void addProvider(PhosphorRegistry::ILauncherProvider *provider)
QVariant data(const QModelIndex &index, int role) const override
Definition IBarWidgetFactory.h:16
Definition AppsProvider.h:19
Definition ILauncherProvider.h:22