1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998, 1999 Alexander Larsson
4 * Custom Objects -- objects defined in XML rather than C.
5 * Copyright (C) 1999 James Henstridge.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <sys/types.h>
37 #include "shape_info.h"
42 void custom_object_new (ShapeInfo
*info
,
45 gboolean
custom_object_load(gchar
*filename
, ObjectType
**otype
);
47 /* Cannot be static, because we may use this fn later when loading
48 a new shape via the sheets dialog */
51 custom_object_load(gchar
*filename
, ObjectType
**otype
)
57 info
= shape_info_load(filename
);
63 custom_object_new(info
, otype
);
67 static void load_shapes_from_tree(const gchar
*directory
)
73 dp
= opendir(directory
);
77 while ( (dirp
= readdir(dp
)) ) {
78 gchar
*filename
= g_strconcat(directory
, G_DIR_SEPARATOR_S
,
82 if (!strcmp(dirp
->d_name
, ".") || !strcmp(dirp
->d_name
, "..")) {
87 if (stat(filename
, &statbuf
) < 0) {
91 if (S_ISDIR(statbuf
.st_mode
)) {
92 load_shapes_from_tree(filename
);
96 /* if it's not a directory, then it must be a .shape file */
97 if (!S_ISREG(statbuf
.st_mode
) || (strlen(dirp
->d_name
) < 6)) {
103 p
= dirp
->d_name
+ strlen(dirp
->d_name
) - 6;
104 if (0==strcmp(".shape",p
)) {
107 if (!custom_object_load(filename
, &ot
)) {
108 g_warning("could not load shape file %s",filename
);
111 g_assert(ot
->default_user_data
);
112 object_register_type(ot
);
121 DIA_PLUGIN_CHECK_INIT
124 dia_plugin_init(PluginInfo
*info
)
129 if (!dia_plugin_info_init(info
, _("Custom"), _("Custom XML shapes loader"),
131 return DIA_PLUGIN_INIT_ERROR
;
133 home_dir
= g_get_home_dir();
135 home_dir
= dia_config_filename("shapes");
136 load_shapes_from_tree(home_dir
);
140 shape_path
= getenv("DIA_SHAPE_PATH");
142 char **dirs
= g_strsplit(shape_path
, G_SEARCHPATH_SEPARATOR_S
, 0);
145 for (i
= 0; dirs
[i
] != NULL
; i
++)
146 load_shapes_from_tree(dirs
[i
]);
149 char *thedir
= dia_get_data_directory("shapes");
150 load_shapes_from_tree(thedir
);
154 return DIA_PLUGIN_INIT_OK
;