Elementary Prefs

So, the work on Elementary, Enlightenment project’s toolkit, kept going this year. Last I blogged here, I was on my task of rewriting the entire widget set as to factorize common widget patterns in classes and create a widget tree.

So, EFL 1.7 release came and just 2 or 3 widgets didn’t make it to the conversion, up to that time. No big deal, because:

  • This next release is going to be much more awesome, because of the tons of new features (and bug corrections) coming in.
  • People just changed the inheritance infrastructure out there in Elementary.

Yep. They didn’t change the architecture/pattern decisions I made, they just exchanged the classes infrastructure from Evas Smart Objects to Eo — a new library (yep, they keep growing forever) implementing an object system. I’ll leave to that library authors a better post about the matter. This was just a background on what happened since my last post, but let’s talk about a new feature, in Elementary, I was involved with after that — Elementary Prefs.

Prefs is a new widget, along with its infrastructure, providing a mechanism to store and access configuration data, with that access being (if the user wants) in a graphical way. Yep, this is like Android Preferences, but in a EFL way🙂

We designed an Edje-like (EDC-like) declarative language to describe the configuration data to be stored (and retrieved). Its composed by data items, each bound to some type. Items are grouped in pages, that can group other pages themselves. We called these files EPC (Elementary Prefs Data Collections), since they can store one or more pages of items. Here is a valid EPC file:


collection
{
   page
   {
      name: "main";
      version: 1;
      title: "Preferences Widget";
      subtitle: "Test Application";
      widget: "elm/vertical_box";

      items {
         item {
            name: "age";
            type: INT;
            label: "Your age:";
            editable: 1;

            int {
               default: 18;
               min: 0;
               max: 150;
            }
         }

         item {
            name: "save";
            type: SAVE;
            label: "Save";
         }

         item {
            name: "reset";
            type: RESET;
            label: "Reset";
         }

         item {
            name: "subp1";
            type: PAGE;
            label: "Sub Page 1";
            source: "subp";
         }

         item {
            name: "subp2";
            type: PAGE;
            label: "Sub Page 2";
            source: "subp";
         }
      }
   }

   page {
      name: "subp";
      widget: "elm/vertical_frame";

      items {
         item {
            name: "subint1";
            label: "Sub Int 1";
            type: INT;

            int {
               min: 0;
               max: 100;
            }
         }

         item {
            name: "subint2";
            label: "Sub Int 2";
            type: INT;

            int {
               min: 0;
               max: 100;
            }
         }

         item {
            name: "subsubpage";
            type: PAGE;
            label: "A Sub Sub Page";
            source: "inner";
         }
      }
   }

   page {
      name: "inner";
      widget: "elm/horizontal_box";

      items {
         item {
            name: "subfloat1";
            label: "A Sub Float 1";
            type: FLOAT;

            float {
               min: -10;
               max: 10;
            }
         }

         item {
            name: "subfloat2";
            label: "A Sub Float 2";
            type: FLOAT;

            float {
               min: -10;
               max: 10;
            }
         }
      }
   }
}

Here we declare 3 pages of data items. Note that we nest them inside each other with the SOURCE-typed item. It happens that “main” will be chosen as the parent page, and because it sources “subp” twice, we’ll see its items replicated twice on the UI counterpart of this prefs declaration. Now what would that be?

Prefs items are bound to Elementary widgets, when “realized”. We have two entities dealing with prefs data — the prefs widget, which displays that data in a visual form, and the prefs_data handle, used to save and restore back values of prefs items set by an user.

Here’s the common usage:


prefs_data =
  elm_prefs_data_new("./preferences.cfg", "main",
                     EET_FILE_MODE_READ_WRITE);

elm_prefs_file_set(prefs, "./preferences.epb",
                   "main");
elm_prefs_data_set(prefs, prefs_data);

The .epb file is a binary form of an EPC one (just like the one seen above), which we get by using the elm_prefs_cc compiler on it. This is meant to act as “system” preferences — shared by all users.

The .cfg one, on its turn, is also a binary file with prefs data. It will store values for each item of the .epb one, but just the values (no meta-data, like minimum value allowed and such). This is meant to be user preferences on this data set, i.e., values specific to the user.

In short, the former gives life to a prefs widget, which is visual, and the latter loads in it the user values back (saving them back too). For instance, each realization of the “subp” page in this collection will have its values saved separately in the .cfg file.

A screenshot of that file, when live on a prefs widget, would look just like this:

Elementary Prefs Widget
Elementary Prefs Widget

Note that most of the values have been played with in the UI, making them different from the defaults, declared in the .epb file.

As you can see, items are bound to Elementary widgets, and one can even choose widgets to represent items other than the defaults (look at the choices for pages, for example). Elementary now ships with a set of available widgets for each item type, but one can also extend these sets via Elementary modules, with the prefs signature. This is a more advanced usage, in the future I can talk more about this.

So, this is it. Expect it to hit your homes soon, in Elementary’s next release, and enjoy it (right now, if you dare to build from unstable trees).

This was a team work by Murilo Belluzzo, Ricardo de Almeida and yours truly. Gustavo Barbieri was also of key importance, coming up with most of the design.

4 comentários sobre “Elementary Prefs

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s