1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Naba Kumar <naba@gnome.org>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef _ANJUTA_UTILS_H_
21 #define _ANJUTA_UTILS_H_
25 #include <sys/types.h>
27 #include <libanjuta/anjuta-preferences.h>
31 gboolean
anjuta_util_copy_file (gchar
* src
, gchar
* dest
, gboolean show_error
);
33 gboolean
anjuta_util_diff(const gchar
* uri
, const gchar
* text
);
35 void anjuta_util_color_from_string (const gchar
* val
, guint16
* r
,
36 guint16
* g
, guint16
* b
);
38 gchar
* anjuta_util_string_from_color (guint16 r
, guint16 g
, guint16 b
);
40 GdkColor
* anjuta_util_convert_color(AnjutaPreferences
* prefs
, const gchar
* pref_name
);
42 GtkWidget
* anjuta_util_button_new_with_stock_image (const gchar
* text
,
43 const gchar
* stock_id
);
45 GtkWidget
* anjuta_util_dialog_add_button (GtkDialog
*dialog
, const gchar
* text
,
46 const gchar
* stock_id
,
49 void anjuta_util_dialog_error (GtkWindow
*parent
, const gchar
* mesg
, ...);
50 void anjuta_util_dialog_warning (GtkWindow
*parent
, const gchar
* mesg
, ...);
51 void anjuta_util_dialog_info (GtkWindow
*parent
, const gchar
* mesg
, ...);
52 void anjuta_util_dialog_error_system (GtkWindow
* parent
, gint errnum
,
53 const gchar
* mesg
, ... );
54 gboolean
anjuta_util_dialog_boolean_question (GtkWindow
*parent
,
55 const gchar
* mesg
, ...);
56 gboolean
anjuta_util_dialog_input (GtkWindow
*parent
, const gchar
*label
,
57 const gchar
*default_value
, gchar
**value
);
59 gboolean
anjuta_util_prog_is_installed (gchar
* prog
, gboolean show
);
61 gchar
* anjuta_util_get_a_tmp_file (void);
63 gchar
* anjuta_util_convert_to_utf8 (const gchar
*str
);
65 GList
* anjuta_util_parse_args_from_string (const gchar
* string
);
67 /***********************************************/
68 /* String integer mapping utility functions */
69 /***********************************************/
70 typedef struct _AnjutaUtilStringMap
74 } AnjutaUtilStringMap
;
76 int anjuta_util_type_from_string(AnjutaUtilStringMap
*map
, const char *str
);
77 const char *anjuta_util_string_from_type(AnjutaUtilStringMap
*map
, int type
);
78 GList
*anjuta_util_glist_from_map(AnjutaUtilStringMap
*map
);
80 /***********************************************/
81 /* Functions that operate on list of strings. */
82 /***********************************************/
83 void anjuta_util_glist_strings_free(GList
* list
);
84 void anjuta_util_glist_strings_prefix (GList
* list
, const gchar
*prefix
);
85 void anjuta_util_glist_strings_sufix (GList
* list
, const gchar
*sufix
);
86 GList
* anjuta_util_glist_strings_sort (GList
* list
);
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
,
105 gboolean
anjuta_util_create_dir (const gchar
* d
);
106 pid_t
anjuta_util_execute_shell (const gchar
*dir
, const gchar
*command
);
108 gchar
* anjuta_util_escape_quotes(const gchar
* str
);
110 gboolean
anjuta_util_path_has_extension (const gchar
*path
, const gchar
*ext
);
112 gchar
* anjuta_util_get_uri_mime_type (const gchar
*uri
);
114 /* Temporarily copied here */
116 #define ANJUTA_TYPE_BEGIN(class_name, prefix, parent_type) \
118 prefix##_get_type (void) \
120 static GType type = 0; \
123 static const GTypeInfo type_info = \
125 sizeof (class_name##Class), \
126 (GBaseInitFunc) NULL, \
127 (GBaseFinalizeFunc) NULL, \
128 (GClassInitFunc) prefix##_class_init, \
129 (GClassFinalizeFunc) NULL, \
131 sizeof (class_name), \
132 0, /* n_preallocs */ \
133 (GInstanceInitFunc) prefix##_instance_init, \
136 type = g_type_register_static (parent_type, \
139 #define ANJUTA_TYPE_END \
144 #define ANJUTA_TYPE_ADD_INTERFACE(prefix,interface_type) \
146 GInterfaceInfo iface_info = { \
147 (GInterfaceInitFunc)prefix##_iface_init, \
151 g_type_add_interface_static (type, \
156 #define ANJUTA_TYPE_BOILERPLATE(class_name, prefix, parent_type) \
157 ANJUTA_TYPE_BEGIN(class_name, prefix, parent_type); \