Albert
Loading...
Searching...
No Matches
app.h
1// SPDX-FileCopyrightText: 2025 Manuel Schneider
2// SPDX-License-Identifier: MIT
3
6
10
14
18
21
25
29
33
37
41
42#pragma once
43#include <QObject>
44#include <QString>
45#include <albert/export.h>
46#include <filesystem>
47#include <map>
48#include <memory>
49class QNetworkAccessManager;
50class QSettings;
51class QUrl;
52
54namespace albert
55{
56class Extension;
57class UsageScoring;
58
64class ALBERT_EXPORT App : public QObject
65{
66 Q_OBJECT
67public:
69 static App &instance();
70
71
74
76 virtual void show(const QString &input_text = {}) = 0;
77
79 virtual void showSettings(QString plugin_id = {}) = 0;
80
82
85
87 virtual const std::map<QString,Extension*> &extensions() const = 0;
88
90 template<typename T>
91 std::map<QString, T*> extensions() const
92 {
93 std::map<QString, T*> results;
94 for (auto &[id, extension] : extensions())
95 if (T *t = dynamic_cast<T*>(extension))
96 results.emplace(id, t);
97 return results;
98 }
99
101 template<typename T>
102 T* extension(const QString &id) const
103 {
104 try {
105 return dynamic_cast<T*>(extensions().at(id));
106 } catch (const std::out_of_range &) {
107 return nullptr;
108 }
109 }
110
112
115
121 static void restart();
122
128 static void quit();
129
131
134
142 static std::unique_ptr<QSettings> settings();
143
151 static std::unique_ptr<QSettings> state();
152
158 static const std::filesystem::path &configLocation();
159
165 static const std::filesystem::path &cacheLocation();
166
172 static const std::filesystem::path &dataLocation();
173
175
176signals:
177
180
183
184protected:
185
186 App();
187 virtual ~App();
188
189};
190
191} // namespace albert
The public app instance interface.
Definition app.h:65
static std::unique_ptr< QSettings > settings()
Returns a QSettings object initialized with the application configuration file path.
T * extension(const QString &id) const
Get extension by id implicitly dynamic_cast'ed to type T.
Definition app.h:102
virtual const std::map< QString, Extension * > & extensions() const =0
Get map of all registered extensions.
static const std::filesystem::path & configLocation()
Returns the path to the application config directory.
static const std::filesystem::path & dataLocation()
Returns the path to the application data directory.
static App & instance()
Returns the global app instance.
void removed(albert::Extension *)
Emitted when an extension has been deregistered.
static void quit()
Quits the application.
std::map< QString, T * > extensions() const
Get map of all extensions of type T.
Definition app.h:91
virtual void show(const QString &input_text={})=0
Shows the frontend and optionally sets the text to input_text.
void added(albert::Extension *)
Emitted when an extension has been registered.
virtual void showSettings(QString plugin_id={})=0
Shows the settings window and optionally selects the plugin with plugin_id.
static std::unique_ptr< QSettings > state()
Returns a QSettings object initialized with the application state file path.
static const std::filesystem::path & cacheLocation()
Returns the path to the application cache directory.
static void restart()
Restarts the application.
Abstract extension class.
Definition extension.h:17
Modifies match scores according to user usage history and preferences.
Definition usagescoring.h:29
The Albert namespace.
Definition app.h:55