symbol-db: fixed icons retrieving for model-project.
[anjuta.git] / libanjuta / anjuta-utils.h
blobb091494a8ea9fc5fbf79fe69bdc0202a8a8f114d
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 G_BEGIN_DECLS
30 gboolean anjuta_util_copy_file (const gchar * src, const gchar * dest, gboolean show_error);
32 gboolean anjuta_util_diff(const gchar* uri, const gchar* text);
34 void anjuta_util_color_from_string (const gchar * val, guint16 * r,
35 guint16 * g, guint16 * b);
37 gchar* anjuta_util_string_from_color (guint16 r, guint16 g, guint16 b);
39 GtkWidget* anjuta_util_button_new_with_stock_image (const gchar* text,
40 const gchar* stock_id);
42 GtkWidget* anjuta_util_dialog_add_button (GtkDialog *dialog, const gchar* text,
43 const gchar* stock_id,
44 gint response_id);
46 void anjuta_util_dialog_error (GtkWindow *parent, const gchar * mesg, ...);
47 void anjuta_util_dialog_warning (GtkWindow *parent, const gchar * mesg, ...);
48 void anjuta_util_dialog_info (GtkWindow *parent, const gchar * mesg, ...);
49 void anjuta_util_dialog_error_system (GtkWindow* parent, gint errnum,
50 const gchar * mesg, ... );
51 gboolean anjuta_util_dialog_boolean_question (GtkWindow *parent,
52 const gchar * mesg, ...);
53 gboolean anjuta_util_dialog_input (GtkWindow *parent, const gchar *label,
54 const gchar *default_value, gchar **value);
56 gboolean anjuta_util_install_files (const gchar * const names);
57 gboolean anjuta_util_package_is_installed (const gchar * lib, gboolean show);
58 gboolean anjuta_util_prog_is_installed (const gchar * prog, gboolean show);
60 gchar* anjuta_util_get_a_tmp_file (void);
62 gchar* anjuta_util_convert_to_utf8 (const gchar *str);
64 GList* anjuta_util_parse_args_from_string (const gchar* string);
66 /***********************************************/
67 /* String integer mapping utility functions */
68 /***********************************************/
69 typedef struct _AnjutaUtilStringMap
71 int type;
72 char *name;
73 } AnjutaUtilStringMap;
75 int anjuta_util_type_from_string(AnjutaUtilStringMap *map, const char *str);
76 const char *anjuta_util_string_from_type(AnjutaUtilStringMap *map, int type);
77 GList *anjuta_util_glist_from_map(AnjutaUtilStringMap *map);
79 /***********************************************/
80 /* Functions that operate on list of strings. */
81 /***********************************************/
82 void anjuta_util_glist_strings_free(GList* list);
83 void anjuta_util_glist_strings_prefix (GList * list, const gchar *prefix);
84 void anjuta_util_glist_strings_sufix (GList * list, const gchar *sufix);
85 GList* anjuta_util_glist_strings_sort (GList * list);
86 gchar* anjuta_util_glist_strings_join (GList * list, gchar *delimiter);
88 /**********************************************************/
89 /* Both the returned glist and the data should be g_freed */
90 /* Call g_list_strings_free() to do that. */
91 /**********************************************************/
92 GList* anjuta_util_glist_from_string (const gchar* id);
93 GList* anjuta_util_glist_strings_dup (GList * list);
95 /* Dedup a list of paths - duplicates are removed from the tail.
96 ** Useful for deduping Recent Files and Recent Projects */
97 GList* anjuta_util_glist_path_dedup(GList *list);
99 /* Adds the given string in the list, if it does not already exist. */
100 /* The added string will come at the top of the list */
101 /* The list will be then truncated to (length) items only */
102 GList * anjuta_util_update_string_list (GList *p_list, const gchar *p_str,
103 gint length);
105 gboolean anjuta_util_create_dir (const gchar * d);
106 gchar * anjuta_util_user_shell (void);
107 gchar ** anjuta_util_user_terminal (void);
108 pid_t anjuta_util_execute_shell (const gchar *dir, const gchar *command);
109 pid_t anjuta_util_execute_terminal_shell (const gchar *dir, const gchar *command);
111 gchar* anjuta_util_escape_quotes(const gchar* str);
113 gchar* anjuta_util_get_real_path (const gchar *path);
114 gchar* anjuta_util_get_current_dir (void);
115 GFile *anjuta_util_file_new_for_commandline_arg (const gchar *arg);
117 gchar* anjuta_util_uri_get_dirname (const gchar *uri);
118 gchar* anjuta_util_replace_home_dir_with_tilde (const gchar *uri);
119 gchar* anjuta_util_shell_expand (const gchar *string);
120 gchar* anjuta_util_str_middle_truncate (const gchar *string,
121 guint truncate_length);
123 gboolean anjuta_util_is_project_file (const gchar *filename);
124 gboolean anjuta_util_is_template_file (const gchar *filename);
125 gchar* anjuta_util_get_file_mime_type (GFile *file);
126 gchar* anjuta_util_get_local_path_from_uri (const gchar *uri);
128 void anjuta_util_help_display (GtkWidget *parent,
129 const gchar *doc_id,
130 const gchar *file_name);
132 /* XDG BaseDir specifcation functions */
133 GFile* anjuta_util_get_user_data_file (const gchar* path, ...);
134 GFile* anjuta_util_get_user_cache_file (const gchar* path, ...);
135 GFile* anjuta_util_get_user_config_file (const gchar* path, ...);
136 gchar* anjuta_util_get_user_data_file_path (const gchar* path, ...);
137 gchar* anjuta_util_get_user_cache_file_path (const gchar* path, ...);
138 gchar* anjuta_util_get_user_config_file_path (const gchar* path, ...);
140 /* Function for converting GFile objects to string paths
141 * Free the returned list with anjuta_util_glist_strings_free. */
142 GList *anjuta_util_convert_gfile_list_to_path_list (GList *list);
143 GList *anjuta_util_convert_gfile_list_to_relative_path_list (GList *list,
144 const gchar *parent);
146 /* Helper functions to load a GtkBuilder file and get widgets */
147 GtkBuilder *anjuta_util_builder_new (const gchar *filename, GError **error);
148 gboolean anjuta_util_builder_get_objects (GtkBuilder *builder, const gchar *first_widget,...);
150 /* Helper for drag and drop */
151 GSList *anjuta_utils_drop_get_files (GtkSelectionData *selection_data);
153 /* Temporarily copied here */
156 * ANJUTA_TYPE_BEGIN:
157 * @class_name: Name of the object
158 * @prefix: Prefix used for object methods
159 * @parent_type: The parent type of the object
161 * Create a new GObject for Anjuta. You can use ANJUTA_TYPE_ADD_INTERFACE
162 * to add interfaces to it and should close it using ANJUTA_TYPE_END
164 #define ANJUTA_TYPE_BEGIN(class_name, prefix, parent_type) \
165 GType \
166 prefix##_get_type (void) \
168 static GType type = 0; \
169 if (!type) \
171 static const GTypeInfo type_info = \
173 sizeof (class_name##Class), \
174 (GBaseInitFunc) NULL, \
175 (GBaseFinalizeFunc) NULL, \
176 (GClassInitFunc) prefix##_class_init, \
177 (GClassFinalizeFunc) NULL, \
178 NULL, \
179 sizeof (class_name), \
180 0, /* n_preallocs */ \
181 (GInstanceInitFunc) prefix##_instance_init, \
182 }; \
184 type = g_type_register_static (parent_type, \
185 #class_name, \
186 &type_info, 0);
189 * ANJUTA_TYPE_END
191 * Ends a declaration that began with ANJUTA_TYPE_BEGIN
193 #define ANJUTA_TYPE_END \
195 return type; \
199 * ANJUTA_TYPE_ADD_INTERFACE:
200 * @prefix: Prefix for the interface methods
201 * @interface_type: Type of the interface to implement
203 * Adds an interface to a declaration started with ANJUTA_TYPE_BEGIN
205 #define ANJUTA_TYPE_ADD_INTERFACE(prefix,interface_type) \
207 GInterfaceInfo iface_info = { \
208 (GInterfaceInitFunc)prefix##_iface_init, \
209 NULL, \
210 NULL \
211 }; \
212 g_type_add_interface_static (type, \
213 interface_type, \
214 &iface_info); \
218 * ANJUTA_TYPE_BOILERPLATE:
219 * @class_name: Name of the object
220 * @prefix: Prefix for the class methods
221 * @parent_type: Parent type for object
223 * Simpliefied version of ANJUTA_TYPE_BEGIN that just creates an Object
224 * without interfaces and doesn't need ANJUTA_TYPE_END
226 #define ANJUTA_TYPE_BOILERPLATE(class_name, prefix, parent_type) \
227 ANJUTA_TYPE_BEGIN(class_name, prefix, parent_type); \
228 ANJUTA_TYPE_END
230 G_END_DECLS
232 #endif