Add-on settings conversion: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
No edit summary
(→‎Structure: Underscoring the need for the version="!" attribute, having just wasted an hour trying to convert an addon before discovering this hitch)
(30 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{mininav|[[Development]]|[[Add-on development]]}}
{{see also|Python development}}
=Converting addon settings=
=Converting addon settings=


Line 5: Line 8:
Due to many initial issues, it is not recommended to convert your settings if your addon is in the Leia addon repo.
Due to many initial issues, it is not recommended to convert your settings if your addon is in the Leia addon repo.


In Kodi 19 Matrix, those bugs have been fixed, so we recommend to convert your addon setting if you plan to submit your addon to the Matrix addon repo (or higher).
In Kodi 19 Matrix, those bugs have been fixed, so we recommend to convert your addon settings if you plan to submit your addon to the Matrix addon repo (or higher).


==Structure==
==Structure==
Line 14: Line 17:
<?xml version="1.0" ?>
<?xml version="1.0" ?>
<settings version="1">
<settings version="1">
<section id="addon">
<section id="my.addon.id">
<category id="1" label="" help="">
<category id="general" label="" help="">
<group id="1" label="">
<group id="1" label="">
<setting id="" type="" label="" help="">
<setting id="" type="" label="" help="">
Line 26: Line 29:
</syntaxhighlight>
</syntaxhighlight>


* your addon settings file can only have one '''<section>''' tag. (the use of multiple sections is reserved for kodi's main settings.xml file)
* The '''<settings>''' tag '''must''' have a '''version="1"''' attribute (or the '''<section>''' tag will not be supported)
* you can use multiple '''<category>''' tags, just like in the old addon settings format.
* your addon settings file can only have one '''<section>''' tag. the id should be the id of your addon. (the use of multiple sections is reserved for kodi's main settings.xml file)
* you can use multiple '''<category>''' tags, just like in the old addon settings format. the id of a category needs to be a string.
* the '''<group>''' tag is a replacement for the old '''sep''' and '''lsep''' types, you can define multiple groups in order to group a number of settings.
* the '''<group>''' tag is a replacement for the old '''sep''' and '''lsep''' types, you can define multiple groups in order to group a number of settings.
==Level==
Similar to Kodi settings, addons can now define a setting level for every setting.<br>
This will show or hide certain settings based on the settings level the user has selected (Basic, Standard, Advanced, Expert).
<syntaxhighlight lang="xml" enclose="div">
<setting id="" type="" label="" help="">
<level>0</level>
</setting>
</syntaxhighlight>
The various levels are defined as such:
* 0 - Basic
* 1 - Standard
* 2 - Advanced
* 3 - Expert
* 4 - Internal (will never be shown in the GUI)


=Setting types=
=Setting types=
Line 40: Line 62:
<level>0</level>
<level>0</level>
<default/>
<default/>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="string">
<control type="edit" format="string">
<heading>32001</heading>
<heading>32001</heading>
Line 54: Line 79:
<level>0</level>
<level>0</level>
<default/>
<default/>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="string">
<control type="edit" format="string">
<heading>32002</heading>
<heading>32002</heading>
Line 69: Line 97:
<level>0</level>
<level>0</level>
<default/>
<default/>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="urlencoded">
<control type="edit" format="urlencoded">
<heading>32003</heading>
<heading>32003</heading>
Line 102: Line 133:
<level>0</level>
<level>0</level>
<default>0</default>
<default>0</default>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="integer">
<control type="edit" format="integer">
<heading>32005</heading>
<heading>32005</heading>
Line 110: Line 138:
</setting>
</setting>
</syntaxhighlight>}}
</syntaxhighlight>}}


==type="date"==
==type="date"==
Line 170: Line 197:
<option label="14">3</option>
<option label="14">3</option>
</options>
</options>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="list" format="string">
<control type="list" format="string">
Line 179: Line 205:




==type="select"==
<syntaxhighlight lang="xml" enclose="div">
<syntaxhighlight lang="xml" enclose="div">
<setting type="select" id="test10" label="32010" values="aa|bb|cc|dd"/>
<setting type="select" id="test10" label="32010" values="aa|bb|cc|dd"/>
Line 189: Line 214:
<constraints>
<constraints>
<options>
<options>
<option label="aa">0</option>
<option>aa</option>
<option label="bb">1</option>
<option>bb</option>
<option label="cc">2</option>
<option>cc</option>
<option label="dd">3</option>
<option>dd</option>
</options>
</options>
<allowempty>true</allowempty>
<allowempty>true</allowempty>
Line 201: Line 226:
</setting>
</setting>
</syntaxhighlight>}}
</syntaxhighlight>}}


==type="addon"==
==type="addon"==
Line 213: Line 237:
<constraints>
<constraints>
<addontype>xbmc.metadata.scraper.movies</addontype>
<addontype>xbmc.metadata.scraper.movies</addontype>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="addon">
<control type="button" format="addon">
Line 231: Line 256:
<constraints>
<constraints>
<addontype>xbmc.metadata.scraper.movies</addontype>
<addontype>xbmc.metadata.scraper.movies</addontype>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="addon">
<control type="button" format="addon">
Line 256: Line 282:
<option label="14">3</option>
<option label="14">3</option>
</options>
</options>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="spinner" format="string"/>
<control type="spinner" format="string"/>
Line 277: Line 302:
<option label="dd">3</option>
<option label="dd">3</option>
</options>
</options>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="spinner" format="string"/>
<control type="spinner" format="string"/>
</setting>
</setting>
</syntaxhighlight>}}
</syntaxhighlight>}}


==type="labelenum"==
==type="labelenum"==
in case you use lvalues in a labelenum control, the saved value will now be the string id, instead of the localized string.
please adapt your python code for this.
<syntaxhighlight lang="xml" enclose="div">
<syntaxhighlight lang="xml" enclose="div">
<setting type="labelenum" id="test15" label="32015" lvalues="11|12|13|14"/>
<setting type="labelenum" id="test15" label="32015" lvalues="11|12|13|14"/>
Line 325: Line 350:
</setting>
</setting>
</syntaxhighlight>}}
</syntaxhighlight>}}


==type="slider"==
==type="slider"==
Line 395: Line 419:
<constraints>
<constraints>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="file">
<control type="button" format="file">
Line 414: Line 439:
<writable>false</writable>
<writable>false</writable>
<masking>audio</masking>
<masking>audio</masking>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="file">
<control type="button" format="file">
Line 433: Line 459:
<writable>false</writable>
<writable>false</writable>
<masking>video</masking>
<masking>video</masking>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="file">
<control type="button" format="file">
Line 452: Line 479:
<writable>false</writable>
<writable>false</writable>
<masking>image</masking>
<masking>image</masking>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="image">
<control type="button" format="image">
Line 471: Line 499:
<writable>false</writable>
<writable>false</writable>
<masking>executable</masking>
<masking>executable</masking>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="file">
<control type="button" format="file">
Line 489: Line 518:
<constraints>
<constraints>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
Line 504: Line 534:
<level>0</level>
<level>0</level>
<default/>
<default/>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
<heading>32026</heading>
<heading>32026</heading>
Line 523: Line 556:
</sources>
</sources>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
Line 543: Line 577:
</sources>
</sources>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
Line 563: Line 598:
</sources>
</sources>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
Line 583: Line 619:
</sources>
</sources>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
Line 603: Line 640:
</sources>
</sources>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
Line 623: Line 661:
</sources>
</sources>
<writable>false</writable>
<writable>false</writable>
<allowempty>true</allowempty>
</constraints>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
Line 639: Line 678:
<level>0</level>
<level>0</level>
<data>RunScript(script.globalsearch)</data>
<data>RunScript(script.globalsearch)</data>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="button" format="action">
<control type="button" format="action">
<close>true</close>
<close>true</close>
Line 650: Line 686:


<syntaxhighlight lang="xml" enclose="div">
<syntaxhighlight lang="xml" enclose="div">
<setting type="action" id="test34" label="32034" action="RunScript(weather.yahoo)" default=""/>
<setting type="action" id="test34" label="32034" action="RunScript(weather.yahoo,Location1)" default=""/>
</syntaxhighlight>
</syntaxhighlight>
{{hidden|style = width: 60%;|headerstyle = background: #cccccc;|contentstyle = text-align: left; border: 0px solid #AAAAAA;|New Setting Format |<syntaxhighlight lang="xml" enclose="div">
{{hidden|style = width: 60%;|headerstyle = background: #cccccc;|contentstyle = text-align: left; border: 0px solid #AAAAAA;|New Setting Format |<syntaxhighlight lang="xml" enclose="div">
<setting id="test34" type="string" label="32034" help="">
<setting id="test34" type="string" label="32034" help="">
<level>0</level>
<level>0</level>
<default/>
<constraints>
<constraints>
<allowempty>true</allowempty>
<allowempty>true</allowempty>
Line 663: Line 700:
</setting>
</setting>
</syntaxhighlight>}}
</syntaxhighlight>}}


==type="fileenum"==
==type="fileenum"==
fileenum type settings (which was basically a spincontrol listing all items) are no longer supported.
these settings can be converted into a file or folder browser.
<syntaxhighlight lang="xml" enclose="div">
<syntaxhighlight lang="xml" enclose="div">
<setting type="fileenum" id="test35" label="32035" values="resources"/>
<setting type="fileenum" id="test35" label="32035" values="resources"/>
Line 673: Line 711:
<level>0</level>
<level>0</level>
<default>/home/ronie/.kodi/addons/script.settings-convert/resources</default>
<default>/home/ronie/.kodi/addons/script.settings-convert/resources</default>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="button" format="file">
<control type="button" format="file">
<heading>32035</heading>
<heading>32035</heading>
Line 690: Line 725:
<level>0</level>
<level>0</level>
<default>/home/ronie/.kodi/addons/script.settings-convert/resources</default>
<default>/home/ronie/.kodi/addons/script.settings-convert/resources</default>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="button" format="path">
<control type="button" format="path">
<heading>32036</heading>
<heading>32036</heading>
Line 708: Line 740:
<default>/home/ronie/.kodi/addons/script.settings-convert/resources</default>
<default>/home/ronie/.kodi/addons/script.settings-convert/resources</default>
<constraints>
<constraints>
<allowempty>true</allowempty>
<masking>*.txt</masking>
<masking>*.txt</masking>
</constraints>
</constraints>
Line 716: Line 747:
</setting>
</setting>
</syntaxhighlight>}}
</syntaxhighlight>}}
=Subsetting=
if you wish to define a subsetting, you can use the '''parent''' attribute with the id of the parent setting as the value.
<syntaxhighlight lang="xml" enclose="div"><setting id="test37" type="path" label="32037" help="" parent="test36"></syntaxhighlight>
=Conditions=
==visible==
if a setting should always be hidden, you can add this to the setting
<syntaxhighlight lang="xml" enclose="div"><visible>false</visible></syntaxhighlight>
if a settings should be conditionallly visible, add a dependencies section to your setting
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="visible" setting=""></dependency>
</dependencies></syntaxhighlight>
==enable==
if a setting should always be disabled, you can add this to the setting
<syntaxhighlight lang="xml" enclose="div"><enable>false</enable></syntaxhighlight>
if a settings should be conditionally enabled, add a dependencies section to your setting
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" setting=""></dependency>
</dependencies>
</syntaxhighlight>
== eq / lt / gt ==
'''eq'''
compare to a bool value of another setting
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" setting="test01">true</dependency>
</dependencies>
</syntaxhighlight>
compare to a int value of another setting
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" setting="test01">5</dependency>
</dependencies>
</syntaxhighlight>
compare to a string value of another setting
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" setting="test01">something</dependency>
</dependencies>
</syntaxhighlight>
'''!eq'''
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" operator="!is" setting="test01">true</dependency>
</dependencies>
</syntaxhighlight>
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" operator="!is" setting="test01">0</dependency>
</dependencies>
</syntaxhighlight>
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" operator="!is" setting="test01"></dependency>
</dependencies>
</syntaxhighlight>
'''lt'''
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" operator="lt" setting="test01">5</dependency>
</dependencies>
</syntaxhighlight>
'''gt'''
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable" operator="gt" setting="test01">0</dependency>
</dependencies>
</syntaxhighlight>
== and / or==
multiple dependencies can be defined as such
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable">
<and>
<condition setting=""></condition>
<condition setting=""></condition>
</and>
</dependency>
</dependencies>
</syntaxhighlight>
<syntaxhighlight lang="xml" enclose="div">
<dependencies>
<dependency type="enable">
<or>
<condition setting=""></condition>
<condition setting=""></condition>
</or>
</dependency>
</dependencies>
</syntaxhighlight>
[[Category:Add-ons|*]]
[[Category:Settings]]
[[Category:Add-on development]]
[[Category:Development]]

Revision as of 11:41, 3 July 2020

Home icon grey.png   ▶ Development ▶ Add-on development ▶ Add-on settings conversion

Converting addon settings

Preface

As of Kodi 18 Leia it is possible to write your addon settings in the same setting format as Kodi uses. Due to many initial issues, it is not recommended to convert your settings if your addon is in the Leia addon repo.

In Kodi 19 Matrix, those bugs have been fixed, so we recommend to convert your addon settings if you plan to submit your addon to the Matrix addon repo (or higher).

Structure

The structure of your settings.xml file should look like this

<?xml version="1.0" ?>
<settings version="1">
	<section id="my.addon.id">
		<category id="general" label="" help="">
			<group id="1" label="">
				<setting id="" type="" label="" help="">
					<control type="" format=""/>
				</setting>
			</group>
		</category>
	</section>
</settings>
  • The <settings> tag must have a version="1" attribute (or the <section> tag will not be supported)
  • your addon settings file can only have one <section> tag. the id should be the id of your addon. (the use of multiple sections is reserved for kodi's main settings.xml file)
  • you can use multiple <category> tags, just like in the old addon settings format. the id of a category needs to be a string.
  • the <group> tag is a replacement for the old sep and lsep types, you can define multiple groups in order to group a number of settings.

Level

Similar to Kodi settings, addons can now define a setting level for every setting.
This will show or hide certain settings based on the settings level the user has selected (Basic, Standard, Advanced, Expert).

<setting id="" type="" label="" help="">
	<level>0</level>
</setting>

The various levels are defined as such:

  • 0 - Basic
  • 1 - Standard
  • 2 - Advanced
  • 3 - Expert
  • 4 - Internal (will never be shown in the GUI)

Setting types

type="text"

<setting type="text" id="test01" label="32001" default=""/>


<setting type="text" id="test02" label="32002" default="" option="hidden"/>


<setting type="text" id="test03" label="32003" default="" option="urlencoded"/>


type="ipaddress"

<setting type="ipaddress" id="test04" label="32004"/>


type="number"

<setting type="number" id="test05" label="32005"/>

type="date"

<setting type="date" id="test06" label="32006" default="2015-03-12"/>


type="time"

<setting type="time" id="test07" label="32007" default="13:13"/>


type="bool"

<setting type="bool" id="test08" label="32008" default="false"/>


type="select"

<setting type="select" id="test09" label="32009" lvalues="11|12|13|14"/>


<setting type="select" id="test10" label="32010" values="aa|bb|cc|dd"/>

type="addon"

<setting type="addon" id="test11" label="32011" default="" addontype="xbmc.metadata.scraper.movies"/>


<setting type="addon" id="test12" label="32012" default="" addontype="xbmc.metadata.scraper.movies" multiselect="true"/>


type="enum"

<setting type="enum" id="test13" label="32013" lvalues="11|12|13|14"/>


<setting type="enum" id="test14" label="32014" values="aa|bb|cc|dd"/>

type="labelenum"

in case you use lvalues in a labelenum control, the saved value will now be the string id, instead of the localized string. please adapt your python code for this.

<setting type="labelenum" id="test15" label="32015" lvalues="11|12|13|14"/>


<setting type="labelenum" id="test16" label="32016" values="bb|aa|dd|cc" sort="yes"/>

type="slider"

<setting type="slider" id="test17" label="32017" default="20" range="5,5,100" option="int"/>


<setting type="slider" id="test18" label="32018" default="0.5" range="0.0,0.1,1.0" option="float"/>


<setting type="slider" id="test19" label="32019" default="20" range="0,1,100" option="percent"/>


type="file"

<setting type="file" id="test20" label="32020" default=""/>


type="audio"

<setting type="audio" id="test21" label="32021" default=""/>


type="video"

<setting type="video" id="test22" label="32022" default=""/>


type="image"

<setting type="image" id="test23" label="32023" default=""/>


type="executable"

<setting type="executable" id="test24" label="32024" default=""/>


type="folder"

<setting type="folder" id="test25" label="32025" default=""/>


<setting type="folder" id="test26" label="32026" default="" option="writeable"/>


<setting type="folder" id="test27" label="32027" default="" source="videos"/>


<setting type="folder" id="test28" label="32028" default="" source="music"/>


<setting type="folder" id="test29" label="32029" default="" source="pictures"/>


<setting type="folder" id="test30" label="32030" default="" source="programs"/>


<setting type="folder" id="test31" label="32031" default="" source="files"/>


<setting type="folder" id="test32" label="32032" default="" source="local"/>


type="action"

<setting type="action" id="test33" label="32033" action="RunScript(script.globalsearch)" option="close"/>


<setting type="action" id="test34" label="32034" action="RunScript(weather.yahoo,Location1)" default=""/>

type="fileenum"

fileenum type settings (which was basically a spincontrol listing all items) are no longer supported. these settings can be converted into a file or folder browser.

<setting type="fileenum" id="test35" label="32035" values="resources"/>


<setting type="fileenum" id="test36" label="32036" values="resources" mask="/"/>


<setting type="fileenum" id="test37" label="32037" values="resources" mask="*.txt"/>

Subsetting

if you wish to define a subsetting, you can use the parent attribute with the id of the parent setting as the value.

<setting id="test37" type="path" label="32037" help="" parent="test36">


Conditions

visible

if a setting should always be hidden, you can add this to the setting

<visible>false</visible>

if a settings should be conditionallly visible, add a dependencies section to your setting

<dependencies>
	<dependency type="visible" setting=""></dependency>
</dependencies>

enable

if a setting should always be disabled, you can add this to the setting

<enable>false</enable>

if a settings should be conditionally enabled, add a dependencies section to your setting

<dependencies>
	<dependency type="enable" setting=""></dependency>
</dependencies>

eq / lt / gt

eq

compare to a bool value of another setting

<dependencies>
	<dependency type="enable" setting="test01">true</dependency>
</dependencies>

compare to a int value of another setting

<dependencies>
	<dependency type="enable" setting="test01">5</dependency>
</dependencies>

compare to a string value of another setting

<dependencies>
	<dependency type="enable" setting="test01">something</dependency>
</dependencies>

!eq

<dependencies>
	<dependency type="enable" operator="!is" setting="test01">true</dependency>
</dependencies>
<dependencies>
	<dependency type="enable" operator="!is" setting="test01">0</dependency>
</dependencies>
<dependencies>
	<dependency type="enable" operator="!is" setting="test01"></dependency>
</dependencies>

lt

<dependencies>
	<dependency type="enable" operator="lt" setting="test01">5</dependency>
</dependencies>

gt

<dependencies>
	<dependency type="enable" operator="gt" setting="test01">0</dependency>
</dependencies>

and / or

multiple dependencies can be defined as such

<dependencies>
	<dependency type="enable">
		<and>
			<condition setting=""></condition>
			<condition setting=""></condition>
		</and>
	</dependency>
</dependencies>
<dependencies>
	<dependency type="enable">
		<or>
			<condition setting=""></condition>
			<condition setting=""></condition>
		</or>
	</dependency>
</dependencies>