You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/gettingstarted/extension/cplusplus.md
+26-60Lines changed: 26 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,83 +2,55 @@
2
2
title: C++
3
3
parent: Extension
4
4
grand_parent: Getting started
5
-
nav_order: 1
5
+
nav_order: 0
6
6
---
7
7
8
8
# Extending Albert using C++
9
9
{: .no_toc }
10
10
11
11
{: .note }
12
12
This page focuses on the practical aspects of extending Albert using C++ and its peculiarities.
13
-
To get a high level overview of common concepts of the API refer to the [general](/gettingstarted/extension/general) section.
13
+
To get an overview of the API refer to the general[extension](/gettingstarted/extension/) section.
14
14
15
15
- TOC
16
16
{:toc}
17
17
18
-
A native plugin is a [Qt Plugin](https://doc.qt.io/qt-6/plugins-howto.html#the-low-level-api-extending-qt-applications), i.e. a shared library providing an instance of the class `PluginInstance`.
18
+
A native plugin is a [Qt Plugin](https://doc.qt.io/qt-6/plugins-howto.html#the-low-level-api-extending-qt-applications),
19
+
i.e. a shared library providing an instance of the class `PluginInstance`.
19
20
20
-
Albert provides `C` and `CMake` macros that implement conventions to streamline the plugin development
21
-
process and to reduce the considerable amount of boilerplate code required to a few lines of code.
22
21
23
-
## CMake
22
+
## Writing native C++ plugins
24
23
25
-
Having a standardized plugin project structure the `albert_plugin` macro takes care of most of the CMake boilerplate code.
26
-
It is part of the `albert` CMake module and can be included using `find_package(Albert REQUIRED)`.
27
-
Read its documentation in the header of the [CMake module](https://raw.githubusercontent.com/albertlauncher/albert/main/cmake/albert-macros.cmake) before you proceed.
24
+
Albert provides `C` and `CMake` macros that implement conventions to streamline the plugin development
25
+
process and reduce the boilerplate code required to a few lines of code.
26
+
Read the documentation in the header of the [`Albert`CMake module](https://raw.githubusercontent.com/albertlauncher/albert/main/cmake/albert-macros.cmake) before you proceed.
28
27
29
-
A minimal working CMakeLists.txt (See also the [CMakeLists.txt files of the official plugins](https://github.com/search?q=repo%3Aalbertlauncher%2Fplugins+path%3A**%2FCMakeLists.txt&type=code)):
28
+
A minimal `CMakeLists.txt`:
30
29
31
30
```cmake
32
31
project(my_plugin VERSION 1.0)
33
32
find_package(Albert REQUIRED)
34
33
albert_plugin()
35
34
```
36
35
37
-
This is the standard plugin directory structure of a plugin:
38
-
39
-
```
40
-
─┬─ my_plugin
41
-
├── CMakeLists.txt
42
-
├── metadata.json
43
-
├─┬─ src
44
-
│ └── …
45
-
└─┬─ i18n
46
-
└── …
47
-
```
48
-
49
-
A basic metadata file looks like this (See also the [metadata.json files of the official plugins](https://github.com/search?q=repo%3Aalbertlauncher%2Fplugins+path%3A**%2Fmetadata.json&type=code)):
Albert plugins ultimately have to inherit the `QObject` and [`PluginInstance`](https://albertlauncher.github.io/reference/classalbert_1_1PluginInstance.html) class and
64
-
contain the `ALBERT_PLUGIN` macro in the declaration body.
65
-
66
-
A basic plugin looks like this (See also the [plugin header files of the official plugins](https://github.com/search?q=repo%3Aalbertlauncher%2Fplugins+path%3A**%2FPlugin.h&type=code)):
Usually you dont want to subclass `PluginInstance` directly but rather [`ExtensionPlugin`](https://albertlauncher.github.io/reference/classalbert_1_1ExtensionPlugin.html)
80
-
which implements the [`Extension`](https://albertlauncher.github.io/reference/classalbert_1_1Extension.html) interface using the metadata of the plugin instance.
81
-
47
+
A plugin class has to be default-constructible,
48
+
inherit `QObject` and [`PluginInstance`](https://albertlauncher.github.io/reference/classalbert_1_1PluginInstance.html)
49
+
and contain the [`ALBERT_PLUGIN`](/reference/plugininstance_8h.html#a8787b7c8c0b456d908480300c22d3f5f) macro in its body.
50
+
However, if subclassing an extension interface,
51
+
you'd rather inherit [`util::ExtensionPlugin`](https://albertlauncher.github.io/reference/classalbert_1_1ExtensionPlugin.html) for convenience.
52
+
A minimal trigger query handler plugin:
53
+
82
54
```cpp
83
55
#pragma once
84
56
#include<albert/extensionplugin.h>
@@ -88,31 +60,25 @@ class Plugin : public albert::ExtensionPlugin,
0 commit comments