[Request] An MVP Plugin example for custom settings in MP2 (1 Viewer)

da3dsoul

Retired Team Member
  • Team MediaPortal
  • August 29, 2020
    86
    45
    Home Country
    United States of America United States of America
    I started looking around in the examples, and I found a lot of things with settings, but I don't actually know what is necessary, as most of them are either skin related, coupled with other internal systems, or so big that it's hard to see what is necessary.
    So my request is for an MVP (minimum viable product) of a plugin that does nothing but display a label that changes according to a setting, which you can change from the plugin settings. I don't actually know if there's a built-in method for plugin settings (like kodi has for example), so just more info about that in general would be nice, too.
    A more complete example would have the different types. I saw a YesNo type referenced. I imagine that there are drop-downs, multi-selects, text inputs of a few kinds, and maybe a date picker or other custom controls. Seeing simple implementations of those would be very useful.

    Unrelated, but a [Request] prefix for the forum would also be useful.
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    There are different layers to handle this. I try to summarize it here, we don't have minimum example yet.

    1. Settings
    First there are settings classes, which are plain C# classes where properties can be decorated with Settings attribute. Example

    There are 2 settings scopes:
    • "User" affects only the currently logged in user (we do have multi-user support in MP2)
    • "Global" affects whole system
    Accessing settings from code is easy, just like here. It's done by SettingsManager.Load<T> call.

    2. Configuration

    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 here.

    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: MediaPortal/MediaPortal-2. 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. MediaPortal/MediaPortal-2

    3. Accessing Settings from UI

    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: MediaPortal/MediaPortal-2

    Rules:
    1. Always use WProperty classes inside Models. They deal with WeakReferences to allow early release of resources.
    2. Only exception to use SProperties are XAML controls. They are using Strong references which keep alive longer/for application runtime.
     

    da3dsoul

    Retired Team Member
  • Team MediaPortal
  • August 29, 2020
    86
    45
    Home Country
    United States of America United States of America
    Okay, thanks. That system could definitely be improved, but that's future stuff...
     

    Users who are viewing this thread

    Top Bottom