2022-04-04 23:04:36 +02:00
|
|
|
# Falkon QML Tutorial - 8. Extension settings
|
|
|
|
|
|
|
|
Hello, in this chapter I will show you how to create a settings dialog.
|
|
|
|
|
|
|
|
These settings are stored as `ini` files in the
|
|
|
|
`profile/extensions/some_extension/settings.ini` and thus are suitable
|
|
|
|
only for small data storage like global user settings.
|
|
|
|
|
|
|
|
## Use Settings
|
|
|
|
|
|
|
|
At first set the settings option `X-Falkon-Settings=true` in the desktop
|
|
|
|
file to tell Falkon the settings for the extension are available.
|
|
|
|
|
2022-04-04 23:41:11 +02:00
|
|
|
metadata.desktop
|
2022-04-04 23:04:36 +02:00
|
|
|
```ini
|
|
|
|
[Desktop Entry]
|
|
|
|
Name=Tutorial8 QML
|
|
|
|
Comment=Example QML extension with settings
|
|
|
|
Icon=
|
|
|
|
Type=Service
|
|
|
|
X-Falkon-Type=Extension/Qml
|
|
|
|
|
|
|
|
X-Falkon-Author=Juraj Oravec
|
|
|
|
X-Falkon-Email=jurajoravec@mailo.com
|
|
|
|
X-Falkon-Version=1.0.0
|
|
|
|
X-Falkon-Settings=true
|
|
|
|
```
|
|
|
|
|
2022-04-04 23:41:11 +02:00
|
|
|
main.qml
|
2022-04-04 23:04:36 +02:00
|
|
|
```qml
|
2022-07-14 10:33:45 +02:00
|
|
|
import QtQuick.Controls 2.3
|
|
|
|
|
2022-04-04 23:04:36 +02:00
|
|
|
Falkon.Settings {
|
|
|
|
id: settings
|
|
|
|
name: 'Tutorial8_settings'
|
|
|
|
}
|
|
|
|
|
2022-07-14 10:33:45 +02:00
|
|
|
settingsWindow: Pane {
|
2022-04-04 23:04:36 +02:00
|
|
|
id: window
|
|
|
|
width: 256
|
|
|
|
height: 200
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
In this example Falkon settings API can be accessed through `settings`
|
|
|
|
object. The available API can be found at
|
|
|
|
[documentation](http://falkon.sgorava.xyz/docs/class_qml_settings.html)
|
|
|
|
or
|
|
|
|
[code](https://github.com/KDE/falkon/blob/master/src/lib/plugins/qml/api/settings/qmlsettings.h)
|
|
|
|
|
2022-04-04 23:41:11 +02:00
|
|
|
The `settingsWindow` is same as button popup and sidebar content. It
|
|
|
|
contains some QMT element to draw stuff.
|
|
|
|
|
2022-04-04 23:04:36 +02:00
|
|
|
## Troubleshooting
|
|
|
|
If you try to use the Qt style settings syntax
|
|
|
|
`settings.value('key', 'default')` you will receive an error message
|
|
|
|
like this one:
|
2022-04-05 10:01:28 +02:00
|
|
|
```
|
|
|
|
"Could not convert argument 0 at"
|
2022-04-04 23:04:36 +02:00
|
|
|
"@file://falkon/plugins/qml_tutorial_8/main.qml:13"
|
|
|
|
"Passing incompatible arguments to C++ functions from JavaScript is dangerous and deprecated."
|
|
|
|
"This will throw a JavaScript TypeError in future releases of Qt!"
|
|
|
|
Unable to get value: key not defined
|
2022-04-05 10:01:28 +02:00
|
|
|
```
|
2022-04-04 23:04:36 +02:00
|
|
|
|
|
|
|
Thus use a proper Falkon settings syntax eg.
|
|
|
|
```qml
|
|
|
|
settings.value({
|
|
|
|
key: 'password'
|
|
|
|
defaultValue: '1234567890'
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
## Limitations
|
|
|
|
I am aware of these potential limitation.
|
|
|
|
- I was unable to find a way to close a settings window from QML script
|
|
|
|
- Try to avoid saving variable of type `bool` with settings. The results
|
|
|
|
might not be as expected.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
The example will create a button which will be placed into the toolbar
|
|
|
|
and though settings optionaly adds icon to the statusbar. The settings
|
|
|
|
for the statusbar icon will change after browser restart.
|
|
|
|
|
|
|
|
The setting window contains an image and a checkbox.
|
|
|
|
|
|
|
|
This example is partialy ripped of from Falkon example extension.
|
|
|
|
|
2022-04-27 22:49:06 +02:00
|
|
|
![Window with sidebar and view menu](../images/qml_tutorial8/settings_window.png)
|
2022-04-04 23:04:36 +02:00
|
|
|
|
|
|
|
### Code
|
|
|
|
The code for this example can be found at
|
|
|
|
[extensions/qml_tutorial_8](../extensions/qml_tutorial_8)
|