On Mon, 2013-05-27 at 15:10 +0100, Sam Bull wrote:
I'm sure I've seen this before, but searching Google and the development pages, I can't find any modern information. Where is a tutorial on saving preferences for an extension, using Gsettings or something? _______________________________________________ gnome-shell-list mailing list gnome-shell-list gnome org https://mail.gnome.org/mailman/listinfo/gnome-shell-list
Hello Sam: I have not seen a tutorial for settings for gnome shell extensions. There was a lot of questions and answers flying around about a year ago but not many details. I think you might find the following enough to get started providing persistent preferences for your extensions. You will need the automake tools to use it. autogen.sh will tell you if something is missing. You can install the sam.sambull.org.zip in your home directory. I have sent the zip file to you directly. Then in ~/sam.sambull.org: #./autogen.sh #make clean #make #make zip-file Two example extensions which are almost identical will be created in the zip-files directory. Extension settings require: prefs.js - It consists of a UI constructed from gtk widgets and methods to read and write the preferences to a binary database file ~/.config/dconf/users. In your extension you get the preferences from the database file. You can connect to the changed signal of a particular setting in your extension if you want to update the preference when the user changes it in the UI with gnome-shell-extension-prefs. schema - You must create a schema that can be compiled for use in creating the key-value pairs that go into the database. This can be done by hand but it is much more reliable to use the automake tools. I cloned Giovanni Campagna's extension repo a year or so ago and modified it to "fit" my needs. I extracted enough of it to make sam.sambull.org.zip. It should be enough to serve as a starting point for you. The zip file if extracted in your home directory will create example extensions and git repositories with the following directories: ~/sam.sambull.org /.git /zip-files /extensions /example /.git /example2 /.git It takes a little time to get the make system set up for maintaining your extensions but it saves a lot of time ongoing. Creating New Extensions --- Initial setup To create a new extension, add a subdirectory in extensions. Then create a Makefile.am like the one in example, replacing the EXTENSION_ID with the basename of your extension, If you need additional files, add them to EXTRA_MODULES. Then modify configure.ac. It should be self-explanatory. See ENABLED_EXTENSIONS See AC_CONFIG_FILES Create your metadata.json.in file. The metadata.json file is made from metadata.json.in. You can hard code the items or let the make system provide them. I have noted the "source" of the items of the metadata.json.in for the example extension. Note the make system over-writes metadata.json. See sam.sambull.org/extension.mk for how it does the job. extensions/example/metadata.json.in. { "extension-id": "@extension_id@", <- extensions/example/Makefile.am "uuid": "@uuid@", <- sam.sambull.org/include.mk "settings-schema": "@gschemaname@", <- sam.sambull.org/include.mk "gettext-domain": "@gettext_domain@", <- sam.sambull.org/configure.ac GETTEXT_PACKAGE "name": "Hello, World Example!", <- Hard coded. "description": "Shows Hello, world when clicking left button on the top panel.", <- Hard coded. "shell-version": [ "@shell_current@" ], <- sam.sambull.org/configure.ac AC_INIT (This is usually hard coded.) "url": "@url@" <- sam.sambull.com/include.mk } Create schema for settings. The .xml schema is created from the .in file. I usually take the .in from an existing extension and edit to fit the extension. The following is org.gnome.shell.extensions.example.gschema.xml.in . The make system will create org.gnome.shell.extensions.example.gschema.xml and org.gnome.shell.extensions.example.gschema.valid. <?xml version="1.0" encoding="UTF-8"?> <schemalist gettext-domain="sam.sambull.org"> <schema id="org.gnome.shell.extensions.example" path="/org/gnome/shell/extensions/example/"> <key name="hello-text" type="s"> <default>''</default> <_summary>Alternative greeting text.</_summary> <_description>If not empty, it contains the text that will be shown when clicking on the panel.</_description> </key> </schema> </schemalist> The prefs.js file for the example extension "binds" the entry to the settings key "hello-text". When text is typed into the entry the key's value is changed in the settings. You can examine the value with dconf editor. The path is "org/gnome/shell/extensions/example". The settings are stored in ~/.config/dconf/user. You can look at other methods (set_boolean, set_string) to set values in extensions that have a prefs.js. You can look at my extension Activities Configurator for hints. It is simple and does everything with brute force. I setup git for each extension. You can copy the .gitignore from the example into the new extensions directory and then "git init", "git add .". I use git-gui which makes using git a bit easier. Don't forget to add any translatable file to po/POTFILES.in, and then you're done and ready to autogen and make. Finally in ~/sam.sambull.org. #./autogen.sh #make clean #make #make zip-file I have included makezips.sh which you might find handy. I hope this helps. Norman
Attachment:
signature.asc
Description: This is a digitally signed message part