The code and content of a plug is stored in an executable binary. This binary has three basic goals:
If you've worked with GTK+ before, you're probably thinking that this sounds very much like the workflow of a normal GTK+ standalone application. That's because it is :). The Switchboard API is designed to be easy to understand for GTK+ novices, yet still familiar to hardcore GTK+ veterans.
Generally speaking, plugs (and thus plug binaries) abstract a low-level settings backend, such as KeyFiles, gconf, dconf, or other APIs like ALSA and GStreamer, to a graphical user interface that is as adherent to the elementary HIG has possible.
The following is a very simple skeleton of a plug for changing the Desktop wallpaper. It is very well-commented, and provides a good starting point for just about every Plug.
// Sub-class the base plug from libpantheon.
public class WallpapersPlug : Pantheon.Switchboard.Plug {
public WallpapersPlug () {
// Add a normal GTK+ Label to the window.
var l = new Gtk.Label("Wallpaper settings go here!");
this.add(l);
}
}
public static int main (string[] args) {
Gtk.init (ref args);
// Instantiate the plug, which handles
// connecting to Switchboard.
var plug = new WallpapersPlug ();
// Connect to Switchboard and identify
// as "Wallpapers". (For debugging)
plug.register ("Wallpapers");
plug.show_all ();
// Start the GTK+ main loop.
Gtk.main ();
return 0;
}
Plugs are described (in a metadata sense) not by the binary, but rather by .plug files which reside in the same directory as the executable. Plug files are discussed in-depth in the next section.