## Utilities Utilities — Utility functions |

## Stability Level

Unstable, unless otherwise indicated

## Synopsis

    #include <libanjuta/anjuta-utils.h>

    gboolean            anjuta_util_copy_file               (const gchar *src,
                                                             const gchar *dest,
                                                             gboolean show_error);
    gboolean            anjuta_util_diff                    (const gchar *uri,
                                                             const gchar *text);
    void                anjuta_util_color_from_string       (const gchar *val,
                                                             guint16 *r,
                                                             guint16 *g,
                                                             guint16 *b);
    gchar*              anjuta_util_string_from_color       (guint16 r,
                                                             guint16 g,
                                                             guint16 b);
    GtkWidget*          anjuta_util_button_new_with_stock_image
                                                            (const gchar *text,
                                                             const gchar *stock_id);
    GtkWidget*          anjuta_util_dialog_add_button       (GtkDialog *dialog,
                                                             const gchar *text,
                                                             const gchar *stock_id,
                                                             gint response_id);
    void                anjuta_util_dialog_error            (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);
    void                anjuta_util_dialog_warning          (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);
    void                anjuta_util_dialog_info             (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);
    void                anjuta_util_dialog_error_system     (GtkWindow *parent,
                                                             gint errnum,
                                                             const gchar *mesg,
                                                             ...);
    gboolean            anjuta_util_dialog_boolean_question (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);
    gboolean            anjuta_util_dialog_input            (GtkWindow *parent,
                                                             const gchar *label,
                                                             const gchar *default_value,
                                                             gchar **value);
    gboolean            anjuta_util_install_files           (const gchar * const names);
    gboolean            anjuta_util_package_is_installed    (const gchar *lib,
                                                             gboolean show);
    gboolean            anjuta_util_prog_is_installed       (const gchar *prog,
                                                             gboolean show);
    gchar*              anjuta_util_get_a_tmp_file          (void);
    gchar*              anjuta_util_convert_to_utf8         (const gchar *str);
    GList*              anjuta_util_parse_args_from_string  (const gchar *string);
    int                 anjuta_util_type_from_string        (AnjutaUtilStringMap *map,
                                                             const char *str);
    const char *        anjuta_util_string_from_type        (AnjutaUtilStringMap *map,
                                                             int type);
    GList *             anjuta_util_glist_from_map          (AnjutaUtilStringMap *map);
    void                anjuta_util_glist_strings_free      (GList *list);
    void                anjuta_util_glist_strings_prefix    (GList *list,
                                                             const gchar *prefix);
    void                anjuta_util_glist_strings_sufix     (GList *list,
                                                             const gchar *sufix);
    GList*              anjuta_util_glist_strings_sort      (GList *list);
    gchar*              anjuta_util_glist_strings_join      (GList *list,
                                                             gchar *delimiter);
    GList*              anjuta_util_glist_from_string       (const gchar *id);
    GList*              anjuta_util_glist_strings_dup       (GList *list);
    GList*              anjuta_util_glist_path_dedup        (GList *list);
    GList *             anjuta_util_update_string_list      (GList *p_list,
                                                             const gchar *p_str,
                                                             gint length);
    gboolean            anjuta_util_create_dir              (const gchar *d);
    gchar *             anjuta_util_user_shell              (void);
    gchar **            anjuta_util_user_terminal           (void);
    pid_t               anjuta_util_execute_shell           (const gchar *dir,
                                                             const gchar *command);
    pid_t               anjuta_util_execute_terminal_shell  (const gchar *dir,
                                                             const gchar *command);
    gchar*              anjuta_util_escape_quotes           (const gchar *str);
    gchar*              anjuta_util_get_real_path           (const gchar *path);
    gchar*              anjuta_util_get_current_dir         (void);
    GFile *             anjuta_util_file_new_for_commandline_arg
                                                            (const gchar *arg);
    gchar*              anjuta_util_uri_get_dirname         (const gchar *uri);
    gchar*              anjuta_util_replace_home_dir_with_tilde
                                                            (const gchar *uri);
    gchar*              anjuta_util_shell_expand            (const gchar *string);
    gchar*              anjuta_util_str_middle_truncate     (const gchar *string,
                                                             guint truncate_length);
    gboolean            anjuta_util_is_project_file         (const gchar *filename);
    gboolean            anjuta_util_is_template_file        (const gchar *filename);
    gchar*              anjuta_util_get_file_mime_type      (GFile *file);
    gchar*              anjuta_util_get_local_path_from_uri (const gchar *uri);
    void                anjuta_util_help_display            (GtkWidget *parent,
                                                             const gchar *doc_id,
                                                             const gchar *file_name);
    GFile*              anjuta_util_get_user_data_file      (const gchar *path,
                                                             ...);
    GFile*              anjuta_util_get_user_cache_file     (const gchar *path,
                                                             ...);
    GFile*              anjuta_util_get_user_config_file    (const gchar *path,
                                                             ...);
    gchar*              anjuta_util_get_user_data_file_path (const gchar *path,
                                                             ...);
    gchar*              anjuta_util_get_user_cache_file_path
                                                            (const gchar *path,
                                                             ...);
    gchar*              anjuta_util_get_user_config_file_path
                                                            (const gchar *path,
                                                             ...);
    GList *             anjuta_util_convert_gfile_list_to_path_list
                                                            (GList *list);
    GList *             anjuta_util_convert_gfile_list_to_relative_path_list
                                                            (GList *list,
                                                             const gchar *parent);
    GtkBuilder *        anjuta_util_builder_new             (const gchar *filename,
                                                             GError **error);
    gboolean            anjuta_util_builder_get_objects     (GtkBuilder *builder,
                                                             const gchar *first_widget,
                                                             ...);
    GSList *            anjuta_util_drop_get_files          (GtkSelectionData *selection_data);
    #define             ANJUTA_TYPE_BEGIN                   (class_name,
                                                             prefix,
                                                             parent_type)
    #define             ANJUTA_TYPE_END
    #define             ANJUTA_TYPE_ADD_INTERFACE           (prefix,
                                                             interface_type)
    #define             ANJUTA_TYPE_BOILERPLATE             (class_name,
                                                             prefix,
                                                             parent_type)

## Description

## Details

### anjuta_util_copy_file ()

    gboolean            anjuta_util_copy_file               (const gchar *src,
                                                             const gchar *dest,
                                                             gboolean show_error);

Copies `src` to `dest` and shows a dialog error in case is needed.

`src` : | the file where copy
`dest` : | the path to copy the `src`
`show_error` : | TRUE to show a dialog error
Returns : | TRUE if there was an error copying the file.

### anjuta_util_diff ()

    gboolean            anjuta_util_diff                    (const gchar *uri,
                                                             const gchar *text);

`uri` : |
`text` : |
Returns : |

### anjuta_util_color_from_string ()

    void                anjuta_util_color_from_string       (const gchar *val,
                                                             guint16 *r,
                                                             guint16 *g,
                                                             guint16 *b);

`val` : |
`r` : |
`g` : |
`b` : |

### anjuta_util_string_from_color ()

    gchar*              anjuta_util_string_from_color       (guint16 r,
                                                             guint16 g,
                                                             guint16 b);

`r` : |
`g` : |
`b` : |
Returns : |

### anjuta_util_button_new_with_stock_image ()

    GtkWidget*          anjuta_util_button_new_with_stock_image
                                                            (const gchar *text,
                                                             const gchar *stock_id);

`text` : |
`stock_id` : |
Returns : |

### anjuta_util_dialog_add_button ()

    GtkWidget*          anjuta_util_dialog_add_button       (GtkDialog *dialog,
                                                             const gchar *text,
                                                             const gchar *stock_id,
                                                             gint response_id);

`dialog` : |
`text` : |
`stock_id` : |
`response_id` : |
Returns : |

### anjuta_util_dialog_error ()

    void                anjuta_util_dialog_error            (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);

`parent` : |
`mesg` : |
`...` : |

### anjuta_util_dialog_warning ()

    void                anjuta_util_dialog_warning          (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);

`parent` : |
`mesg` : |
`...` : |

### anjuta_util_dialog_info ()

    void                anjuta_util_dialog_info             (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);

`parent` : |
`mesg` : |
`...` : |

### anjuta_util_dialog_error_system ()

    void                anjuta_util_dialog_error_system     (GtkWindow *parent,
                                                             gint errnum,
                                                             const gchar *mesg,
                                                             ...);

`parent` : |
`errnum` : |
`mesg` : |
`...` : |

### anjuta_util_dialog_boolean_question ()

    gboolean            anjuta_util_dialog_boolean_question (GtkWindow *parent,
                                                             const gchar *mesg,
                                                             ...);

`parent` : |
`mesg` : |
`...` : |
Returns : |

### anjuta_util_dialog_input ()

    gboolean            anjuta_util_dialog_input            (GtkWindow *parent,
                                                             const gchar *label,
                                                             const gchar *default_value,
                                                             gchar **value);

`parent` : |
`label` : |
`default_value` : |
`value` : |
Returns : |

### anjuta_util_install_files ()

    gboolean            anjuta_util_install_files           (const gchar * const names);

`names` : |
Returns : |

### anjuta_util_package_is_installed ()

    gboolean            anjuta_util_package_is_installed    (const gchar *lib,
                                                             gboolean show);

`lib` : |
`show` : |
Returns : |

### anjuta_util_prog_is_installed ()

    gboolean            anjuta_util_prog_is_installed       (const gchar *prog,
                                                             gboolean show);

`prog` : |
`show` : |
Returns : |

### anjuta_util_get_a_tmp_file ()

    gchar*              anjuta_util_get_a_tmp_file          (void);

Returns : |

### anjuta_util_convert_to_utf8 ()

    gchar*              anjuta_util_convert_to_utf8         (const gchar *str);

`str` : |
Returns : |

### anjuta_util_parse_args_from_string ()

    GList*              anjuta_util_parse_args_from_string  (const gchar *string);

`string` : |
Returns : |

### anjuta_util_type_from_string ()

    int                 anjuta_util_type_from_string        (AnjutaUtilStringMap *map,
                                                             const char *str);

`map` : |
`str` : |
Returns : |

### anjuta_util_string_from_type ()

    const char *        anjuta_util_string_from_type        (AnjutaUtilStringMap *map,
                                                             int type);

`map` : |
`type` : |
Returns : |

### anjuta_util_glist_from_map ()

    GList *             anjuta_util_glist_from_map          (AnjutaUtilStringMap *map);

`map` : |
Returns : |

### anjuta_util_glist_strings_free ()

    void                anjuta_util_glist_strings_free      (GList *list);

`list` : |

### anjuta_util_glist_strings_prefix ()

    void                anjuta_util_glist_strings_prefix    (GList *list,
                                                             const gchar *prefix);

`list` : |
`prefix` : |

### anjuta_util_glist_strings_sufix ()

    void                anjuta_util_glist_strings_sufix     (GList *list,
                                                             const gchar *sufix);

`list` : |
`sufix` : |

### anjuta_util_glist_strings_sort ()

    GList*              anjuta_util_glist_strings_sort      (GList *list);

`list` : |
Returns : |

### anjuta_util_glist_strings_join ()

    gchar*              anjuta_util_glist_strings_join      (GList *list,
                                                             gchar *delimiter);

`list` : |
`delimiter` : |
Returns : |

### anjuta_util_glist_from_string ()

    GList*              anjuta_util_glist_from_string       (const gchar *id);

`id` : |
Returns : |

### anjuta_util_glist_strings_dup ()

    GList*              anjuta_util_glist_strings_dup       (GList *list);

`list` : |
Returns : |

### anjuta_util_glist_path_dedup ()

    GList*              anjuta_util_glist_path_dedup        (GList *list);

`list` : |
Returns : |

### anjuta_util_update_string_list ()

    GList *             anjuta_util_update_string_list      (GList *p_list,
                                                             const gchar *p_str,
                                                             gint length);

`p_list` : |
`p_str` : |
`length` : |
Returns : |

### anjuta_util_create_dir ()

    gboolean            anjuta_util_create_dir              (const gchar *d);

`d` : |
Returns : |

### anjuta_util_user_shell ()

    gchar *             anjuta_util_user_shell              (void);

Retrieves the user's preferred shell.

Returns : | A newly allocated string that is the path to the shell.

### anjuta_util_user_terminal ()

    gchar **            anjuta_util_user_terminal           (void);

Retrieves the user's preferred terminal.

Returns : | A newly allocated strings list. The first argument is the terminal program name. The following are the arguments needed to execute a command. The list has to be freed with g_strfreev

### anjuta_util_execute_shell ()

    pid_t               anjuta_util_execute_shell           (const gchar *dir,
                                                             const gchar *command);

`dir` : |
`command` : |
Returns : |

### anjuta_util_execute_terminal_shell ()

    pid_t               anjuta_util_execute_terminal_shell  (const gchar *dir,
                                                             const gchar *command);

`dir` : |
`command` : |
Returns : |

### anjuta_util_escape_quotes ()

    gchar*              anjuta_util_escape_quotes           (const gchar *str);

`str` : |
Returns : |

### anjuta_util_get_real_path ()

    gchar*              anjuta_util_get_real_path           (const gchar *path);

`path` : |
Returns : |

### anjuta_util_get_current_dir ()

    gchar*              anjuta_util_get_current_dir         (void);

Get current working directory, unlike g_get_current_dir, keeps symbolic links in path name.

Returns : | The current working directory.

### anjuta_util_file_new_for_commandline_arg ()

    GFile *             anjuta_util_file_new_for_commandline_arg
                                                            (const gchar *arg);

`arg`: URI or relative or absolute file path

Create a new file corresponding to arg, unlike g_file_new_for_commandline_arg, keeps symbolic links in path name.

`arg` : |
Returns : | A new GFile object

### anjuta_util_uri_get_dirname ()

    gchar*              anjuta_util_uri_get_dirname         (const gchar *uri);

`uri` : |
Returns : |

### anjuta_util_replace_home_dir_with_tilde ()

    gchar*              anjuta_util_replace_home_dir_with_tilde
                                                            (const gchar *uri);

`uri` : |
Returns : |

### anjuta_util_shell_expand ()

    gchar*              anjuta_util_shell_expand            (const gchar *string);

Expand environment variables $(var_name) and tilde (~) in the input string.

`string` : | input string
Returns : | a newly-allocated string that must be freed with `g_free()`.

### anjuta_util_str_middle_truncate ()

    gchar*              anjuta_util_str_middle_truncate     (const gchar *string,
                                                             guint truncate_length);

`string` : |
`truncate_length` : |
Returns : |

### anjuta_util_is_project_file ()

    gboolean            anjuta_util_is_project_file         (const gchar *filename);

Return TRUE if the file is an anjuta project file. It is implemented by checking only the file extension. So it does not check the existence of the file. But it is working on an URI if it does not containt a fragment.

`filename` : | the file name
Returns : | TRUE if the file is a project file, else FALSE

### anjuta_util_is_template_file ()

    gboolean            anjuta_util_is_template_file        (const gchar *filename);

Return TRUE if the file is an template project file. It is implemented by checking only the file extension. So it does not check the existence of the file. But it is working on an URI if it does not containt a fragment.

`filename` : | the file name
Returns : | TRUE if the file is a template file, else FALSE

### anjuta_util_get_file_mime_type ()

    gchar*              anjuta_util_get_file_mime_type      (GFile *file);

`file` : |
Returns : |

### anjuta_util_get_local_path_from_uri ()

    gchar*              anjuta_util_get_local_path_from_uri (const gchar *uri);

`uri` : |
Returns : |

### anjuta_util_help_display ()

    void                anjuta_util_help_display            (GtkWidget *parent,
                                                             const gchar *doc_id,
                                                             const gchar *file_name);

`parent` : |
`doc_id` : |
`file_name` : |

### anjuta_util_get_user_data_file ()

    GFile*              anjuta_util_get_user_data_file      (const gchar *path,
                                                             ...);

`path` : |
`...` : |
Returns : |

### anjuta_util_get_user_cache_file ()

    GFile*              anjuta_util_get_user_cache_file     (const gchar *path,
                                                             ...);

`path` : |
`...` : |
Returns : |

### anjuta_util_get_user_config_file ()

    GFile*              anjuta_util_get_user_config_file    (const gchar *path,
                                                             ...);

`path` : |
`...` : |
Returns : |

### anjuta_util_get_user_data_file_path ()

    gchar*              anjuta_util_get_user_data_file_path (const gchar *path,
                                                             ...);

`path` : |
`...` : |
Returns : |

### anjuta_util_get_user_cache_file_path ()

    gchar*              anjuta_util_get_user_cache_file_path
                                                            (const gchar *path,
                                                             ...);

`path` : |
`...` : |
Returns : |

### anjuta_util_get_user_config_file_path ()

    gchar*              anjuta_util_get_user_config_file_path
                                                            (const gchar *path,
                                                             ...);

`path` : |
`...` : |
Returns : |

### anjuta_util_convert_gfile_list_to_path_list ()

    GList *             anjuta_util_convert_gfile_list_to_path_list
                                                            (GList *list);

`list` : |
Returns : |

### anjuta_util_convert_gfile_list_to_relative_path_list ()

    GList *             anjuta_util_convert_gfile_list_to_relative_path_list
                                                            (GList *list,
                                                             const gchar *parent);

`list` : |
`parent` : |
Returns : |

### anjuta_util_builder_new ()

    GtkBuilder *        anjuta_util_builder_new             (const gchar *filename,
                                                             GError **error);

Create a new GtkBuilder object and load the file in it. Display an error if the file is missing. Use a dialog if error is NULL, just a warning if the error can be reported.

`filename` : | Builder file name to open
`error` : | Optional error object, if NULL display a dialog if the file is missing
Returns : | The new GtkBuilder object

### anjuta_util_builder_get_objects ()

    gboolean            anjuta_util_builder_get_objects     (GtkBuilder *builder,
                                                             const gchar *first_widget,
                                                             ...);

Create a new GtkBuilder object and load the file in it. Display an error if the file is missing. Use a dialog if error is NULL, just a warning if the error can be reported.

`builder` : | Builder object
`first_widget` : | Name of first widget to get ...: Address to store the first widget pointer, followed optionally by more name/pointer pairs, followed by NULL
`...` : |
Returns : | TRUE is everything works as expected.

### anjuta_util_drop_get_files ()

    GSList *            anjuta_util_drop_get_files          (GtkSelectionData *selection_data);

Create a list of valid uri's from a uri-list drop.

`selection_data` : | the GtkSelectionData from drag_data_received
Returns : | a list of GFiles

### ANJUTA_TYPE_BEGIN()

    #define             ANJUTA_TYPE_BEGIN(class_name, prefix, parent_type)

Create a new GObject for Anjuta. You can use ANJUTA_TYPE_ADD_INTERFACE to add interfaces to it and should close it using ANJUTA_TYPE_END

`class_name` : | Name of the object
`prefix` : | Prefix used for object methods
`parent_type` : | The parent type of the object

### ANJUTA_TYPE_END

    #define             ANJUTA_TYPE_END

Ends a declaration that began with ANJUTA_TYPE_BEGIN

### ANJUTA_TYPE_ADD_INTERFACE()

    #define             ANJUTA_TYPE_ADD_INTERFACE(prefix,interface_type)

Adds an interface to a declaration started with ANJUTA_TYPE_BEGIN

`prefix` : | Prefix for the interface methods
`interface_type` : | Type of the interface to implement

### ANJUTA_TYPE_BOILERPLATE()

    #define             ANJUTA_TYPE_BOILERPLATE(class_name, prefix, parent_type)

Simpliefied version of ANJUTA_TYPE_BEGIN that just creates an Object without interfaces and doesn't need ANJUTA_TYPE_END

`class_name` : | Name of the object
`prefix` : | Prefix for the class methods
`parent_type` : | Parent type for object