Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / libanjuta / anjuta-utils.h
blob44ba7bad69c29ef3993a6683226dd74760cdacef
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta-utils.h
4 * Copyright (C) Naba Kumar <naba@gnome.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef _ANJUTA_UTILS_H_
21 #define _ANJUTA_UTILS_H_
23 #include <glib.h>
24 #include <gtk/gtk.h>
25 #include <sys/types.h>
26 #include <gio/gio.h>
28 #include <libanjuta/anjuta-preferences.h>
30 G_BEGIN_DECLS
32 gboolean anjuta_util_copy_file (gchar * src, gchar * dest, gboolean show_error);
34 gboolean anjuta_util_diff(const gchar* uri, const gchar* text);
36 void anjuta_util_color_from_string (const gchar * val, guint16 * r,
37 guint16 * g, guint16 * b);
39 gchar* anjuta_util_string_from_color (guint16 r, guint16 g, guint16 b);
41 GdkColor* anjuta_util_convert_color(AnjutaPreferences* prefs, const gchar* pref_name);
43 GtkWidget* anjuta_util_button_new_with_stock_image (const gchar* text,
44 const gchar* stock_id);
46 GtkWidget* anjuta_util_dialog_add_button (GtkDialog *dialog, const gchar* text,
47 const gchar* stock_id,
48 gint response_id);
50 void anjuta_util_dialog_error (GtkWindow *parent, const gchar * mesg, ...);
51 void anjuta_util_dialog_warning (GtkWindow *parent, const gchar * mesg, ...);
52 void anjuta_util_dialog_info (GtkWindow *parent, const gchar * mesg, ...);
53 void anjuta_util_dialog_error_system (GtkWindow* parent, gint errnum,
54 const gchar * mesg, ... );
55 gboolean anjuta_util_dialog_boolean_question (GtkWindow *parent,
56 const gchar * mesg, ...);
57 gboolean anjuta_util_dialog_input (GtkWindow *parent, const gchar *label,
58 const gchar *default_value, gchar **value);
60 gboolean anjuta_util_prog_is_installed (const gchar * prog, gboolean show);
62 gchar* anjuta_util_get_a_tmp_file (void);
64 gchar* anjuta_util_convert_to_utf8 (const gchar *str);
66 GList* anjuta_util_parse_args_from_string (const gchar* string);
68 /***********************************************/
69 /* String integer mapping utility functions */
70 /***********************************************/
71 typedef struct _AnjutaUtilStringMap
73 int type;
74 char *name;
75 } AnjutaUtilStringMap;
77 int anjuta_util_type_from_string(AnjutaUtilStringMap *map, const char *str);
78 const char *anjuta_util_string_from_type(AnjutaUtilStringMap *map, int type);
79 GList *anjuta_util_glist_from_map(AnjutaUtilStringMap *map);
81 /***********************************************/
82 /* Functions that operate on list of strings. */
83 /***********************************************/
84 void anjuta_util_glist_strings_free(GList* list);
85 void anjuta_util_glist_strings_prefix (GList * list, const gchar *prefix);
86 void anjuta_util_glist_strings_sufix (GList * list, const gchar *sufix);
87 GList* anjuta_util_glist_strings_sort (GList * list);
88 gchar* anjuta_util_glist_strings_join (GList * list, gchar *delimiter);
90 /**********************************************************/
91 /* Both the returned glist and the data should be g_freed */
92 /* Call g_list_strings_free() to do that. */
93 /**********************************************************/
94 GList* anjuta_util_glist_from_string (const gchar* id);
95 GList* anjuta_util_glist_strings_dup (GList * list);
97 /* Dedup a list of paths - duplicates are removed from the tail.
98 ** Useful for deduping Recent Files and Recent Projects */
99 GList* anjuta_util_glist_path_dedup(GList *list);
101 /* Adds the given string in the list, if it does not already exist. */
102 /* The added string will come at the top of the list */
103 /* The list will be then truncated to (length) items only */
104 GList * anjuta_util_update_string_list (GList *p_list, const gchar *p_str,
105 gint length);
107 gboolean anjuta_util_create_dir (const gchar * d);
108 char * anjuta_util_user_shell (void);
109 pid_t anjuta_util_execute_shell (const gchar *dir, const gchar *command);
111 gchar* anjuta_util_escape_quotes(const gchar* str);
113 gboolean anjuta_util_path_has_extension (const gchar *path, const gchar *ext);
114 gchar* anjuta_util_get_real_path (const gchar *path);
116 gchar* anjuta_util_uri_get_dirname (const gchar *uri);
117 gchar* anjuta_util_replace_home_dir_with_tilde (const gchar *uri);
118 gchar* anjuta_util_str_middle_truncate (const gchar *string,
119 guint truncate_length);
121 gchar* anjuta_util_get_uri_mime_type (const gchar *uri);
123 void anjuta_util_help_display (GtkWindow *parent,
124 const gchar *doc_id,
125 const gchar *file_name);
127 /* XDG BaseDir specifcation functions */
128 GFile* anjuta_util_get_user_data_file (const gchar* path, ...);
129 GFile* anjuta_util_get_user_cache_file (const gchar* path, ...);
130 GFile* anjuta_util_get_user_config_file (const gchar* path, ...);
131 gchar* anjuta_util_get_user_data_file_path (const gchar* path, ...);
132 gchar* anjuta_util_get_user_cache_file_path (const gchar* path, ...);
133 gchar* anjuta_util_get_user_config_file_path (const gchar* path, ...);
135 /* Temporarily copied here */
137 #define ANJUTA_TYPE_BEGIN(class_name, prefix, parent_type) \
138 GType \
139 prefix##_get_type (void) \
141 static GType type = 0; \
142 if (!type) \
144 static const GTypeInfo type_info = \
146 sizeof (class_name##Class), \
147 (GBaseInitFunc) NULL, \
148 (GBaseFinalizeFunc) NULL, \
149 (GClassInitFunc) prefix##_class_init, \
150 (GClassFinalizeFunc) NULL, \
151 NULL, \
152 sizeof (class_name), \
153 0, /* n_preallocs */ \
154 (GInstanceInitFunc) prefix##_instance_init, \
155 }; \
157 type = g_type_register_static (parent_type, \
158 #class_name, \
159 &type_info, 0);
160 #define ANJUTA_TYPE_END \
162 return type; \
165 #define ANJUTA_TYPE_ADD_INTERFACE(prefix,interface_type) \
167 GInterfaceInfo iface_info = { \
168 (GInterfaceInitFunc)prefix##_iface_init, \
169 NULL, \
170 NULL \
171 }; \
172 g_type_add_interface_static (type, \
173 interface_type, \
174 &iface_info); \
177 #define ANJUTA_TYPE_BOILERPLATE(class_name, prefix, parent_type) \
178 ANJUTA_TYPE_BEGIN(class_name, prefix, parent_type); \
179 ANJUTA_TYPE_END
181 G_END_DECLS
183 #endif