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:
68
71
73 virtual void show(const QString &input_text = {}) = 0;
74
76 virtual void showSettings(QString plugin_id = {}) = 0;
77
79
82
84 virtual bool localizationEnabled() const = 0;
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 virtual std::unique_ptr<QSettings> settings() = 0;
143
151 virtual std::unique_ptr<QSettings> state() = 0;
152
158 virtual const std::filesystem::path &cacheLocation() = 0;
159
165 virtual const std::filesystem::path &configLocation() = 0;
166
172 virtual const std::filesystem::path &dataLocation() = 0;
173
175
176signals:
177
180
183
184protected:
185
186 App();
187 virtual ~App();
188
189};
190
196ALBERT_EXPORT App &app();
197
198} // namespace albert
The public app instance interface.
Definition app.h:65
T * extension(const QString &id) const
Get extension by id implicitly dynamic_cast'ed to type T.
Definition app.h:102
virtual const std::filesystem::path & dataLocation()=0
Returns the path to the application data directory.
virtual const std::map< QString, Extension * > & extensions() const =0
Get map of all registered extensions.
void removed(albert::Extension *)
Emitted when an extension has been deregistered.
static void quit()
Quits the application.
virtual std::unique_ptr< QSettings > settings()=0
Returns a QSettings object initialized with the application configuration file path.
virtual bool localizationEnabled() const =0
Returns true when a PluginLoader should load translations, false otherwise.
virtual const std::filesystem::path & cacheLocation()=0
Returns the path to the application cache directory.
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 void restart()
Restarts the application.
virtual std::unique_ptr< QSettings > state()=0
Returns a QSettings object initialized with the application state file path.
virtual const std::filesystem::path & configLocation()=0
Returns the path to the application config directory.
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
App & app()
Returns the global app instance.