Developer Documentation


As of version 0.4.2, this documentation is outdated. Please use the newer version instead.

Creating a new module


Minimal Module


Every module should contain at least this code:

#include "hardinfo.h"
#include "iconcache.h"

enum {
    MODULE_ENTRY1,
    MODULE_ENTRY2,
    /* (...) */
} Entries;

static ModuleEntry hi_entries[] = {
    {"Entry Name 1",                 "icon1.png"},
    {"Entry Name 2",                 "icon2.png"},
    /* (...) */
};

/* should follow GLib's GKeyFile format */
gchar *
hi_info(gint entry)
{
    switch (entry) {
       case MODULE_ENTRY1:
           return g_strdup("[Entry 1]\n"
                           "Key1=Value1\n"
                           "Key2=Value2");
       case MODULE_ENTRY2:
           return g_strdup("[Entry 2]\n"
                           "Key1=Value1\n"
                           "Key2=Value2");
       default:
           return g_strdup("[Empty]\n"
                           "No info available=\n");
    }
}

gint
hi_n_entries(void)
{
    return G_N_ELEMENTS(hi_entries) - 1;
}

GdkPixbuf *
hi_icon(gint entry)
{
    return icon_cache_get_pixbuf(hi_entries[entry].icon);
}   

gchar *
hi_name(gint entry)
{
    return hi_entries[entry].name;
}


GKeyFile Format


Modules sends to the HardInfo shell a string conforming to the GLib GKeyFile format.

Groups


Modules should return at least one group. Every group will be displayed, except for the $ShellParam$ group, whose keys affects the shell behaviour.

Since the GLib GKeyFile parser does not allow two groups with the same name, you must append a "comment" to the group name (such as Group#1, Group#2). Characters after the hash (inclusive) are not shown.

Keys


All keys are displayed in the shell, except for those in the $ShellParam$ group:

- UpdateInterval: sets a timeout in milisecs to reload a certain field
- LoadGraphInterval: sets a timeout in milisecs to feed the load graph (when ViewType is 2) when certain field is selected
- ReloadInterval: sets a timeout in milisecs to reload the entire group
- ViewType: sets the view type; 0 is the normal, one-paned view, 1 displays the two paned view and 2 displays a load graph
- Icon: sets an icon for another key
- Zebra: enables or disables a zebra-like appearance in the upper information pane
- Every other key is ignored.

Items in bold requires the field name as a parameter, separated by a '$', such as UpdateInterval$Memory=1000 (will update the field 'Memory' every one second).

As is the case with more than one group with the same name, keys may also include a prefix (i.e. Audio Adapter#1=Built-in Audio and Audio Adapter#2=USB Audio). Everything before the hash is not displayed.

Keys may also begin with the '$' character, which will only have effect when ViewType is 1. Those keys should have an "unique" identifier which is used to display detailed information when hi_more_info is called. Example: $USB0$Generic 16MB USB Memory Stick, where USB0 is the identifier and everything else after the second '$' is the displayed key name.

Other Methods


Other available methods are:

void
hi_reload(gint entry)
{
    switch (entry) {
       case MODULE_ENTRY1:
           reload_entry1(); break;
       case MODULE_ENTRY2:
           reload_entry2(); break;
    }
}

gchar *
hi_get_field(gchar *field)
{
    if (g_str_equal(field, "Updated Field")) {
        static gint i = 0;

        return g_strdup_printf("%d", ++i);
    }

    return NULL;
}

gchar *
hi_more_info(gchar * entry)   
{
    gchar *info = (gchar *) g_hash_table_lookup(moreinfo, entry);

    if (info)
        return g_strdup(info);

    return g_strdup_printf("[Empty %s]", entry);
}


Reporting progress


- shell_status_update(const gchar *message) sets the status bar message. Allows Pango markup
- shell_status_pulse(void) pulses the progress bar
- shell_status_set_percentage(gint percentage) sets the progress bar percentage (from 0 to 100)
- shell_status_set_enabled(gboolean setting) shows or hides the progress bar according to setting
- shell_view_set_enabled(gboolean setting) enables or disables most of the user interface, according to setting; to be used only in long operations (such as benchmarking) when the user should not change to another module or section

  • BerliOS Logo
  • Search: