1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2004 Sebastien Granjoux
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
22 * header data read in .wiz file, used in the first page (project selection)
24 *---------------------------------------------------------------------------*/
34 #include <glib/gi18n.h>
36 #include <libanjuta/anjuta-utils.h>
38 /*---------------------------------------------------------------------------*/
44 gint description_lang
;
49 GList
* required_programs
;
50 GList
* required_packages
;
54 *---------------------------------------------------------------------------*/
61 self
= g_slice_new0(NPWHeader
);
67 npw_header_free (NPWHeader
* self
)
69 if (self
== NULL
) return;
72 g_free (self
->description
);
73 g_free (self
->iconfile
);
74 g_free (self
->category
);
75 g_free (self
->filename
);
76 g_list_free (self
->required_programs
);
77 g_list_free (self
->required_packages
);
78 g_slice_free (NPWHeader
, self
);
82 npw_header_set_name (NPWHeader
* self
, const gchar
* name
, gint lang
)
84 if (lang
>= self
->name_lang
)
87 self
->name
= g_strdup (name
);
88 self
->name_lang
= lang
;
93 npw_header_get_name (const NPWHeader
* self
)
95 return self
->name_lang
== 0 ? _(self
->name
) : self
->name
;
99 npw_header_set_filename (NPWHeader
* self
, const gchar
* filename
)
101 g_free (self
->filename
);
102 self
->filename
= g_strdup (filename
);
106 npw_header_get_filename (const NPWHeader
* self
)
108 return self
->filename
;
112 npw_header_set_category (NPWHeader
* self
, const gchar
* category
)
114 g_free (self
->category
);
115 self
->category
=g_strdup (category
);
119 npw_header_get_category (const NPWHeader
* self
)
121 return self
->category
;
125 npw_header_set_description (NPWHeader
* self
, const gchar
* description
, gint lang
)
127 if (lang
>= self
->description_lang
)
129 g_free (self
->description
);
130 self
->description
= g_strdup (description
);
131 self
->description_lang
= lang
;
136 npw_header_get_description (const NPWHeader
* self
)
138 return self
->description_lang
== 0 ? _(self
->description
) : self
->description
;
142 npw_header_set_iconfile (NPWHeader
* self
, const gchar
* iconfile
)
144 g_free (self
->iconfile
);
145 self
->iconfile
= g_strdup (iconfile
);
149 npw_header_get_iconfile (const NPWHeader
* self
)
151 return self
->iconfile
;
155 npw_header_set_order (NPWHeader
* self
, const gchar
* order
)
157 self
->order
= strtoul (order
, NULL
, 10);
161 npw_header_get_order (const NPWHeader
* self
)
167 npw_header_add_required_program (NPWHeader
* self
, const gchar
* program
)
169 self
->required_programs
=
170 g_list_prepend (self
->required_programs
,
176 npw_header_add_required_package (NPWHeader
* self
, const gchar
* package
)
178 self
->required_packages
=
179 g_list_prepend (self
->required_packages
,
184 npw_header_check_required_programs (NPWHeader
* self
)
187 GList
*failed_programs
= NULL
;
188 for (node
= self
->required_programs
; node
; node
= g_list_next (node
))
190 if (!anjuta_util_prog_is_installed (node
->data
, FALSE
))
192 const gchar
*const prog
= (const gchar
*) node
->data
;
193 failed_programs
= g_list_prepend (failed_programs
,
197 return failed_programs
;
201 npw_header_check_required_packages (NPWHeader
* self
)
204 GList
*failed_packages
= NULL
;
205 for (node
= self
->required_packages
; node
; node
= g_list_next (node
))
207 if (!anjuta_util_package_is_installed (node
->data
, FALSE
))
209 const gchar
*const pkg
= (const gchar
*) node
->data
;
210 failed_packages
= g_list_prepend (failed_packages
,
214 return failed_packages
;
218 *---------------------------------------------------------------------------*/
221 npw_header_list_new (void)
231 remove_category (GList
*list
)
233 g_list_foreach (list
, (GFunc
)npw_header_free
, NULL
);
238 npw_header_list_free (GList
* list
)
240 g_list_foreach (list
, (GFunc
)remove_category
, NULL
);
245 compare_header_name (NPWHeader
*a
, NPWHeader
*b
)
247 if (npw_header_get_order (a
) == npw_header_get_order (b
))
249 return g_utf8_collate (npw_header_get_name (a
), npw_header_get_name (b
));
251 else if (npw_header_get_order (a
) == 0)
255 else if (npw_header_get_order (b
) == 0)
261 return npw_header_get_order (a
) - npw_header_get_order (b
);
266 npw_header_list_insert_header (GList
*list
, NPWHeader
*header
)
269 GList
*template_list
;
271 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
276 template_list
= (GList
*)node
->data
;
277 first
= (NPWHeader
*)template_list
->data
;
278 res
= g_ascii_strcasecmp (npw_header_get_category (first
), npw_header_get_category (header
));
281 node
->data
= g_list_insert_sorted (template_list
, header
, (GCompareFunc
) compare_header_name
);
290 template_list
= g_list_prepend (NULL
, header
);
292 return g_list_insert_before (list
, node
, template_list
);
296 npw_header_list_find_header (GList
*list
, NPWHeader
*header
)
299 GList
*template_list
;
301 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
306 template_list
= (GList
*)node
->data
;
307 first
= (NPWHeader
*)template_list
->data
;
308 res
= g_ascii_strcasecmp (npw_header_get_category (first
), npw_header_get_category (header
));
313 find
= g_list_find_custom (template_list
, header
, (GCompareFunc
) compare_header_name
);
316 return (NPWHeader
*)find
->data
;