Helper Functions

Helper Functions — A collection of useful utilities and functions.

Synopsis


#include <hildon/hildon.h>

gulong              hildon_helper_set_logical_font      (GtkWidget *widget,
                                                         const gchar *logicalfontname);
gulong              hildon_helper_set_logical_color     (GtkWidget *widget,
                                                         GtkRcFlags rcflags,
                                                         GtkStateType state,
                                                         const gchar *logicalcolorname);
gboolean            hildon_helper_event_button_is_finger
                                                        (GdkEventButton *event);
void                hildon_helper_set_insensitive_message
                                                        (GtkWidget *widget,
                                                         const gchar *message);
void                hildon_helper_set_insensitive_messagef
                                                        (GtkWidget *widget,
                                                         const gchar *format,
                                                         ...);
void                hildon_helper_set_thumb_scrollbar   (GtkScrolledWindow *win,
                                                         gboolean thumb);
gchar*              hildon_format_file_size_for_display (goffset size);
gunichar*           hildon_helper_strip_string          (const gchar *string);
const gchar*        hildon_helper_utf8_strstrcasedecomp_needle_stripped
                                                        (const gchar *haystack,
                                                         const gunichar *nuni);
gchar*              hildon_helper_normalize_string      (const gchar *string);
gchar*              hildon_helper_smart_match           (const gchar *haystack,
                                                         const gchar *needle);

Description

Hildon provides some helper functions that can be used for commonly performed tasks and functionality blocks. This includes operations on widget styles and probing functions for touch events.

Details

hildon_helper_set_logical_font ()

gulong              hildon_helper_set_logical_font      (GtkWidget *widget,
                                                         const gchar *logicalfontname);

This function assigns a defined logical font to the widget and all its child widgets. it also connects to the "style_set" signal which will retrieve & assign the new font for the given logical name each time the theme is changed The returned signal id can be used to disconnect the signal. When calling multiple times the previous signal (obtained by calling this function) is disconnected automatically and should not be used.

widget : a GtkWidget to assign this logical font for.
logicalfontname : a gchar* with the logical font name to assign to the widget.
Returns : the signal id that is triggered every time theme is changed. 0 if font set failed.

hildon_helper_set_logical_color ()

gulong              hildon_helper_set_logical_color     (GtkWidget *widget,
                                                         GtkRcFlags rcflags,
                                                         GtkStateType state,
                                                         const gchar *logicalcolorname);

This function assigns a defined logical color to the widget and all it's child widgets. It also connects to the "style_set" signal which will retrieve & assign the new color for the given logical name each time the theme is changed. The returned signal id can be used to disconnect the signal. When calling multiple times the previous signal (obtained by calling this function) is disconnected automatically and should not be used.

Example : If the style you want to modify is bg[NORMAL] then set rcflags to GTK_RC_BG and state to GTK_STATE_NORMAL.

widget : A GtkWidget to assign this logical font for.
rcflags : GtkRcFlags enumeration defining whether to assign to FG, BG, TEXT or BASE style.
state : GtkStateType indicating to which state to assign the logical color
logicalcolorname : A gchar* with the logical font name to assign to the widget.
Returns : The signal id that is triggered every time theme is changed. 0 if color set failed.

hildon_helper_event_button_is_finger ()

gboolean            hildon_helper_event_button_is_finger
                                                        (GdkEventButton *event);

Checks if the given button event is a finger event.

event : A GtkEventButton to check
Returns : TRUE if the event is a finger event.

hildon_helper_set_insensitive_message ()

void                hildon_helper_set_insensitive_message
                                                        (GtkWidget *widget,
                                                         const gchar *message);

Warning

hildon_helper_set_insensitive_message is deprecated and should not be used in newly-written code. As of hildon 2.2, it is strongly discouraged to use insensitive messages.

This function assigns an insensitive message to a widget. When the widget is in an insensitive state and the user activates it, the message will be displayed using a standard HildonBanner.

widget : A GtkWidget to assign a banner to
message : A message to display to the user

hildon_helper_set_insensitive_messagef ()

void                hildon_helper_set_insensitive_messagef
                                                        (GtkWidget *widget,
                                                         const gchar *format,
                                                         ...);

Warning

hildon_helper_set_insensitive_messagef is deprecated and should not be used in newly-written code. As of hildon 2.2, it is strongly discouraged to use insensitive messages.

A version of hildon_helper_set_insensitive_message with string formatting.

widget : A GtkWidget to assign a banner to
format : a printf-like format string
... : arguments for the format string

hildon_helper_set_thumb_scrollbar ()

void                hildon_helper_set_thumb_scrollbar   (GtkScrolledWindow *win,
                                                         gboolean thumb);

This function enables a thumb scrollbar on a given scrolled window. It'll convert the existing normal scrollbar into a larger, finger-usable scrollbar that works without a stylus. As fingerable list rows are fairly high, consider using the whole available vertical space of your application for the content in order to have as many rows as possible visible on the screen at once.

Finger-Sized scrollbar should always be used together with finger-sized content.

win : A GtkScrolledWindow to use as target
thumb : TRUE to enable the thumb scrollbar, FALSE to disable

hildon_format_file_size_for_display ()

gchar*              hildon_format_file_size_for_display (goffset size);

Formats a file size in bytes for display in applications.

This function is similar to g_format_file_size_for_display() but the translations are from Maemo so might differ slightly.

size : a size in bytes
Returns :

Since 2.2


hildon_helper_strip_string ()

gunichar*           hildon_helper_strip_string          (const gchar *string);

Strips all capitalization and accentuation marks from a string. The returned Unicode string is NULL-terminated.

string : a string to be stripped off.
Returns : a newly allocated Unicode, lowercase, and without accentuation marks version of string, or NULL if string is an empty string.

Since 2.2.18


hildon_helper_utf8_strstrcasedecomp_needle_stripped ()

const gchar*        hildon_helper_utf8_strstrcasedecomp_needle_stripped
                                                        (const gchar *haystack,
                                                         const gunichar *nuni);

Heavily modified version of e_util_utf8_strstrcasedecomp(). As its original version, it finds the first occurrence of nuni in haystack. However, instead of stripping nuni, it expect it to be already stripped. See hildon_helper_strip_string().

This is done for performance reasons, since this search is done several times for the same string nuni, it is undesired to strip it more than once.

Also, the search is done as a prefix search, starting in the first alphanumeric character after any non-alphanumeric one. Searching for "aba" in "Abasto" will match, searching in "Moraba" will not, and searching in "A tool (abacus)" will do.

haystack : a haystack where to search
nuni : a needle to search for, already stripped with hildon_helper_strip_string()
Returns : the first instance of nuni in haystack

Since 2.2.18


hildon_helper_normalize_string ()

gchar*              hildon_helper_normalize_string      (const gchar *string);

Transform a string into an ascii equivalent representation. This is necessary for hildon_helper_smart_match() to work properly.

string : a string
Returns : a newly allocated string.

hildon_helper_smart_match ()

gchar*              hildon_helper_smart_match           (const gchar *haystack,
                                                         const gchar *needle);

Searches for the first occurence of needle in haystack. The search is performed only in the first alphanumeric character after a sequence of non-alphanumeric ones. This allows smart matching of words inside more complex strings.

If haystack itself doesn't start with an alphanumeric character, then the search is equivalent to strcasecmp().

To make the best of this method, it is recommended that both the needle and the haystack are already normalized as ASCII strings. For this, you should call hildon_helper_normalize_string() on both strings.

haystack : a string where to find a match
needle : what to find
Returns : a pointer to the first occurence of needle in haystack or NULL if not found