home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 2
Plugin Development
[Request] An MVP Plugin example for custom settings in MP2
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="morpheus_xx" data-source="post: 1277215" data-attributes="member: 48495"><p>There are different layers to handle this. I try to summarize it here, we don't have minimum example yet.</p><p></p><p><strong><u>1. Settings</u></strong></p><p>First there are settings classes, which are plain C# classes where properties can be decorated with Settings attribute. <a href="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/Settings/ImagePlayerSettings.cs#L55" target="_blank">Example</a></p><p></p><p>There are 2 settings scopes: </p><ul> <li data-xf-list-type="ul">"User" affects only the currently logged in user (we do have multi-user support in MP2)</li> <li data-xf-list-type="ul">"Global" affects whole system</li> </ul><p>Accessing settings from code is easy, just like <a href="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/Settings/Configuration/SlideShowImageDuration.cs#L44" target="_blank">here</a>. It's done by SettingsManager.Load<T> call.</p><p></p><p><strong><u>2. Configuration</u></strong></p><p></p><p>Settings alone don't have any UI to control them. This happens first, when you add Configuration classes and registration to your plugin. This is done inside the plugin.xml, like <a href="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/plugin.xml#L37-L66" target="_blank">here</a>.</p><p></p><p>The first two tags like <Register Location="/Configuration/Settings"> ..</Register> define the hierarchy in the configuration plugin, where your config items will be displayed. We are using one common generic configuration plugin.</p><p></p><p>Then there are the actual configuration classes: <a href="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/plugin.xml#L56-L65" target="_blank">MediaPortal/MediaPortal-2</a>. They have a localized name and important a ClassName which is dynamically invoked by configuration plugin.</p><p></p><p>For each config item there is a small class which deals with load / save of the changes. All of them derive from basic classes for text input, number input or similar. <a href="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/Settings/Configuration/SlideShowImageDuration.cs" target="_blank">MediaPortal/MediaPortal-2</a></p><p></p><p><strong><u>3. Accessing Settings from UI</u></strong></p><p></p><p>The UI is defined in XAML and from there you can bind to Models. If you like to expose a setting's value to UI, you define Properties in the Model classes.</p><p>Here one example: <a href="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/UiComponents/Media/Models/ImagePlayerUIContributor.cs#L67-L84" target="_blank">MediaPortal/MediaPortal-2</a></p><p></p><p>Rules:</p><ol> <li data-xf-list-type="ol"><u>Always use WProperty</u> classes inside Models. They deal with WeakReferences to allow early release of resources.</li> <li data-xf-list-type="ol">Only exception to use SProperties are XAML controls. They are using Strong references which keep alive longer/for application runtime.</li> </ol></blockquote><p></p>
[QUOTE="morpheus_xx, post: 1277215, member: 48495"] There are different layers to handle this. I try to summarize it here, we don't have minimum example yet. [B][U]1. Settings[/U][/B] First there are settings classes, which are plain C# classes where properties can be decorated with Settings attribute. [URL='https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/Settings/ImagePlayerSettings.cs#L55']Example[/URL] There are 2 settings scopes: [LIST] [*]"User" affects only the currently logged in user (we do have multi-user support in MP2) [*]"Global" affects whole system [/LIST] Accessing settings from code is easy, just like [URL='https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/Settings/Configuration/SlideShowImageDuration.cs#L44']here[/URL]. It's done by SettingsManager.Load<T> call. [B][U]2. Configuration[/U][/B] Settings alone don't have any UI to control them. This happens first, when you add Configuration classes and registration to your plugin. This is done inside the plugin.xml, like [URL='https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/plugin.xml#L37-L66']here[/URL]. The first two tags like <Register Location="/Configuration/Settings"> ..</Register> define the hierarchy in the configuration plugin, where your config items will be displayed. We are using one common generic configuration plugin. Then there are the actual configuration classes: [URL="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/plugin.xml#L56-L65"]MediaPortal/MediaPortal-2[/URL]. They have a localized name and important a ClassName which is dynamically invoked by configuration plugin. For each config item there is a small class which deals with load / save of the changes. All of them derive from basic classes for text input, number input or similar. [URL="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/Players/ImagePlayer/Settings/Configuration/SlideShowImageDuration.cs"]MediaPortal/MediaPortal-2[/URL] [B][U]3. Accessing Settings from UI[/U][/B] The UI is defined in XAML and from there you can bind to Models. If you like to expose a setting's value to UI, you define Properties in the Model classes. Here one example: [URL="https://github.com/MediaPortal/MediaPortal-2/blob/master/MediaPortal/Source/UI/UiComponents/Media/Models/ImagePlayerUIContributor.cs#L67-L84"]MediaPortal/MediaPortal-2[/URL] Rules: [LIST=1] [*][U]Always use WProperty[/U] classes inside Models. They deal with WeakReferences to allow early release of resources. [*]Only exception to use SProperties are XAML controls. They are using Strong references which keep alive longer/for application runtime. [/LIST] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 2
Plugin Development
[Request] An MVP Plugin example for custom settings in MP2
Contact us
RSS
Top
Bottom