Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
ClipboardProvider.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 <QList>
9#include <QPointer>
10#include <QString>
11
12QT_BEGIN_NAMESPACE
13class QAbstractItemModel;
14QT_END_NAMESPACE
15
16namespace PhosphorShellLauncher {
17
18// Clipboard history, from phosphor-service-clipboard's history model.
19// Lists everything on an empty query (most recent first, as the model
20// orders it) and fuzzy-matches the preview text otherwise. Enter copies
21// the entry back to the clipboard; Alt+Enter removes it from history.
22//
23// The service is reached through its `history` QAbstractItemModel and
24// the copy/remove slots by name, not through ClipboardService's C++
25// type, so this library does not link phosphor-service-clipboard: a host
26// that has no clipboard service simply does not register this provider.
27// The role names ("preview", "mimeType", "timestamp") are the contract.
28//
29// Rows are addressed by the entry's timestamp rather than its index,
30// because history shifts under the user between typing and Enter (a copy
31// elsewhere inserts a row at the top); an index captured at query time
32// would then act on the wrong entry.
33class PHOSPHORSHELLLAUNCHER_EXPORT ClipboardProvider : public PhosphorRegistry::ILauncherProvider
34{
35 Q_OBJECT
36
37public:
38 // `service` must expose `history` (QAbstractItemModel*), `copy(int)`
39 // and `remove(int)`. Null makes the provider inert (no rows), never
40 // a crash.
46 explicit ClipboardProvider(QObject* service, QObject* parent = nullptr);
48
49 [[nodiscard]] QString id() const override;
50 [[nodiscard]] QString displayName() const override;
51 [[nodiscard]] QString iconName() const override;
52 [[nodiscard]] bool listsOnEmptyQuery() const override;
53
54 void setQuery(const QString& query) override;
55 [[nodiscard]] QList<PhosphorRegistry::LauncherResult> results() const override;
56 [[nodiscard]] bool activate(const QString& resultId, Activation activation) override;
57
58 void setMaximumResults(int count);
59 [[nodiscard]] int maximumResults() const;
60
61private:
62 void recompute();
63 [[nodiscard]] int rowFor(const QString& resultId) const;
64 [[nodiscard]] int role(const char* name) const;
65
66 QPointer<QObject> m_service;
67 QPointer<QAbstractItemModel> m_history;
68 QString m_query;
69 QList<PhosphorRegistry::LauncherResult> m_results;
70 // Resolved once at construction. role() walks the model's roleNames()
71 // hash, and recompute() needed three of them per rebuild plus one more
72 // per activation, on a path that runs for every keystroke.
73 int m_previewRole = -1;
74 int m_mimeRole = -1;
75 int m_timestampRole = -1;
76 int m_maximumResults = 24;
77};
78
79} // namespace PhosphorShellLauncher
Definition ILauncherProvider.h:106
Activation
Definition ILauncherProvider.h:112
ClipboardProvider(QObject *service, QObject *parent=nullptr)
The service is resolved ONCE, here.
QString displayName() const override
QList< PhosphorRegistry::LauncherResult > results() const override
void setQuery(const QString &query) override
bool activate(const QString &resultId, Activation activation) override
Definition AppsProvider.h:19