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>
34 #include "shape_info.h"
39 void custom_object_new (ShapeInfo
*info
,
40 DiaObjectType
**otype
);
42 G_MODULE_EXPORT gboolean
custom_object_load(gchar
*filename
,
43 DiaObjectType
**otype
);
45 /* Cannot be static, because we may use this fn later when loading
46 a new shape via the sheets dialog */
48 G_MODULE_EXPORT gboolean
49 custom_object_load(gchar
*filename
, DiaObjectType
**otype
)
55 info
= shape_info_load(filename
);
61 custom_object_new(info
, otype
);
65 static void load_shapes_from_tree(const gchar
*directory
)
70 dp
= g_dir_open(directory
, 0, NULL
);
74 while ( (dentry
= g_dir_read_name(dp
)) ) {
75 gchar
*filename
= g_strconcat(directory
, G_DIR_SEPARATOR_S
,
79 if (g_file_test(filename
, G_FILE_TEST_IS_DIR
)) {
80 load_shapes_from_tree(filename
);
84 /* if it's not a directory, then it must be a .shape file */
85 if ( !g_file_test(filename
, G_FILE_TEST_IS_REGULAR
)
86 || (strlen(dentry
) < 6)) {
91 p
= dentry
+ strlen(dentry
) - 6;
92 if (0==strcmp(".shape",p
)) {
95 if (!custom_object_load(filename
, &ot
)) {
96 g_warning("could not load shape file %s",filename
);
99 g_assert(ot
->default_user_data
);
100 object_register_type(ot
);
109 DIA_PLUGIN_CHECK_INIT
112 dia_plugin_init(PluginInfo
*info
)
115 const char *home_dir
;
117 if (!dia_plugin_info_init(info
, _("Custom"), _("Custom XML shapes loader"),
119 return DIA_PLUGIN_INIT_ERROR
;
121 home_dir
= g_get_home_dir();
123 home_dir
= dia_config_filename("shapes");
124 load_shapes_from_tree(home_dir
);
125 g_free((char *)home_dir
);
128 shape_path
= getenv("DIA_SHAPE_PATH");
130 char **dirs
= g_strsplit(shape_path
, G_SEARCHPATH_SEPARATOR_S
, 0);
133 for (i
= 0; dirs
[i
] != NULL
; i
++)
134 load_shapes_from_tree(dirs
[i
]);
137 char *thedir
= dia_get_data_directory("shapes");
138 load_shapes_from_tree(thedir
);
142 return DIA_PLUGIN_INIT_OK
;