deadbeef icon indicating copy to clipboard operation
deadbeef copied to clipboard

gtkui: use JSON format for layout config and move the configuration to a separate file

Open cboxdoerfer opened this issue 10 years ago • 5 comments

I gave this stuff a few thoughts and came up with the following:

The layout format

{
    "Magic Number": "<magic_number>",
    "Version":" <version>",
    "Layout": [
        {
            "Type": "<widget_type>",
            "Properties": [
                {"<widget_property_01>":"<value_01>"},
                {"<widget_property_02>":"<value_02>"},
                {"<widget_property_03>":"<value_03>"}
            ],
            "Children": [
                {
                    "Type": "<widget_type>",
                    "Properties": [
                        {"<widget_property_01>":"<value_01>"}
                    ],
                    "Children": [
                    ]
                }
            ]
        },
        {
            "Type": "<widget_type>",
            "Properties": [
                {"<widget_property_01>":"<value_01>"},
                {"<widget_property_02>":"<value_02>"}
            ],
            "Children": [
            ]
        }
    ]
}

Location

Layouts are stored like that: ~/.config/deadbeef/layouts/default.ddblayout User-created layouts could be stored there too, this way they would be easy to discover and could be listed in the UI for fast switching.

Compatibility with old formats

I didn't think of that before but of course this format isn't compatible with the old ones, especially regarding the gtkui API. So I'm not sure what to do about the save and load API. Just add a compatiblity layer for the old API and add new save2 and load2?

cboxdoerfer avatar Nov 28 '15 09:11 cboxdoerfer

Hm, I guess adding a compatibility layer for plugins using save/load wouldn't work at all, because it's totally up to the plugin developer in which format those settings are stored. There's no way how to interpret them accurately in all cases.

cboxdoerfer avatar Nov 28 '15 09:11 cboxdoerfer

the format looks good, except a couple of things.

  • The root widget is a container, which can only have 1 widget, so the "layout" element can't be a list -- it should be a widget. Am I wrong in something?
  • The names should always be written in lower case, to match the rest of deadbeef formats (but internally should be case-insensitive).

Location:

Layouts are stored like that: ~/.config/deadbeef/layouts/default.ddblayout

It doesn't look to me that "default" is the right name, unless we store the default layout in there. A better name would be e.g. current.ddblayout. It should also be less hassle if the current layout is stored outside of the "layouts" folder, to avoid having to deal with this filename checking, when a user saves his own layouts under the same name.

User-created layouts could be stored there too, this way they would be easy to discover and could be listed in the UI for fast switching.

This is good.

I didn't think of that before but of course this format isn't compatible with the old ones, especially regarding the gtkui API. So I'm not sure what to do about the save and load API. Just add a compatiblity layer for the old API and add new save2 and load2?

That problem should be resolved separately.. We need to support saving and loading of the old widgets, and loading of the 0.6.2 layouts... most likely we'll need to add code which will be converting old format into the new JSON "on the fly" for old widgets, when saving.

Oleksiy-Yakovenko avatar Nov 28 '15 18:11 Oleksiy-Yakovenko

The root widget is a container, which can only have 1 widget, so the "layout" element can't be a list -- it should be a widget. Am I wrong in something?

The names should always be written in lower case, to match the rest of deadbeef formats (but internally should be case-insensitive).

Yes of course, you're right. Changed both.

It doesn't look to me that "default" is the right name, unless we store the default layout in there. A better name would be e.g. current.ddblayout. It should also be less hassle if the current layout is stored outside of the "layouts" folder, to avoid having to deal with this filename checking, when a user saves his own layouts under the same name.

Yes, "default.ddblayout" is supposed to store the default layout, not the one in use.

We could also store those in the install directory, e.g. /usr/share/deadbeef/layouts/default_01.ddblayout. This way we could always safely restore the defaults and they get automatically updated with deadbeef, and the users can do whatever they like in ~/.config/deadbeef/layouts.

In summary this could look like this:

type path
default layouts /usr/share/deadbeef/layouts/default.ddblayout
user layouts ~/.config/deadbeef/layouts/layout.ddblayout
current layout ~/.config/deadbeef/current.ddblayout

cboxdoerfer avatar Nov 29 '15 15:11 cboxdoerfer

Ok, so I misunderstood.. But then we can also just store the default layout in code as a string. This is usually simpler, then storing it in a separate file.

Other than that, agreed with everything.

Oleksiy-Yakovenko avatar Nov 29 '15 16:11 Oleksiy-Yakovenko

One more thing..

"Magic Number": "<magic_number>",

This seems quite unnecessary. Magic number concept if a thing for binary formats, it doesn't make sense in JSON. But we can e.g. have a field called "format": "deadbeef GTKUI layout"

Oleksiy-Yakovenko avatar Nov 29 '15 16:11 Oleksiy-Yakovenko