[dia] Bundle UML alias icons in gresource
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Bundle UML alias icons in gresource
- Date: Sat, 25 May 2019 10:23:28 +0000 (UTC)
commit aa9d87bcce325132cdc80c1d4011bb9f1dcabd3c
Author: Zander Brown <zbrown gnome org>
Date: Sat May 25 10:34:31 2019 +0100
Bundle UML alias icons in gresource
app/toolbox.c | 6 +++-
lib/sheet.c | 39 +++++++++++++++++---------
lib/widgets.c | 4 ++-
{sheets => objects}/UML/aggregation.png | Bin
objects/UML/dia-uml.gresource.xml | 10 +++++++
{sheets => objects}/UML/eventsink.png | Bin
{sheets => objects}/UML/eventsource.png | Bin
objects/UML/meson.build | 4 +++
{sheets => objects}/UML/receptacle.png | Bin
{sheets => objects}/UML/umlclass_template.png | Bin
sheets/UML.sheet.in | 10 +++----
sheets/meson.build | 5 ----
12 files changed, 53 insertions(+), 25 deletions(-)
---
diff --git a/app/toolbox.c b/app/toolbox.c
index 55534d3d..bd0c5d32 100644
--- a/app/toolbox.c
+++ b/app/toolbox.c
@@ -268,7 +268,11 @@ fill_sheet_wbox(Sheet *sheet)
ToolButtonData *data;
if (sheet_obj->pixmap != NULL) {
- pixbuf = gdk_pixbuf_new_from_xpm_data (sheet_obj->pixmap);
+ if (g_str_has_prefix ((const char *) sheet_obj->pixmap, "res:")) {
+ pixbuf = pixbuf_from_resource ((const char *) sheet_obj->pixmap + 4);
+ } else {
+ pixbuf = gdk_pixbuf_new_from_xpm_data (sheet_obj->pixmap);
+ }
} else if (sheet_obj->pixmap_file != NULL) {
GError* gerror = NULL;
diff --git a/lib/sheet.c b/lib/sheet.c
index d5193b83..8859033d 100644
--- a/lib/sheet.c
+++ b/lib/sheet.c
@@ -402,6 +402,8 @@ load_register_sheet (const gchar *dirname,
xmlChar *ot_name = NULL;
+ gchar *sheetdir = dia_get_data_directory ("sheets");
+
if (xmlIsBlankNode (node)) {
continue;
}
@@ -474,18 +476,20 @@ load_register_sheet (const gchar *dirname,
objdesc = xmlNodeGetContent (subnode);
}
} else if (subnode->ns == ns && !xmlStrcmp (subnode->name, (const xmlChar *) "icon")) {
- tmp = xmlNodeGetContent (subnode);
- iconname = g_strconcat (dirname, G_DIR_SEPARATOR_S, (char *) tmp, NULL);
+ tmp = xmlNodeGetContent (subnode);
+ if (g_str_has_prefix ((char *) tmp, "res:")) {
+ iconname = g_strdup ((char *) tmp);
+ } else {
+ iconname = g_build_filename (dirname, (char *) tmp, NULL);
if (!shadowing_sheet && !g_file_test (iconname, G_FILE_TEST_EXISTS)) {
/* Fall back to system directory if there is no user icon */
- gchar *sheetdir = dia_get_data_directory ("sheets");
- iconname = g_strconcat (sheetdir, G_DIR_SEPARATOR_S, (char *) tmp, NULL);
- g_free (sheetdir);
- }
- has_icon_on_sheet = TRUE;
- if (tmp) {
- xmlFree (tmp);
+ iconname = g_build_filename (sheetdir, (char *) tmp, NULL);
}
+ }
+ has_icon_on_sheet = TRUE;
+ if (tmp) {
+ xmlFree (tmp);
+ }
} else if (subnode->ns == ns && !xmlStrcmp (subnode->name, (const xmlChar *) "alias")) {
if (ot_name) {
object_register_alias_type (object_get_type ((char *) ot_name), subnode);
@@ -493,17 +497,25 @@ load_register_sheet (const gchar *dirname,
}
}
+ g_free (sheetdir);
+
sheet_obj = g_new (SheetObject, 1);
sheet_obj->object_type = g_strdup ((char *) ot_name);
- sheet_obj->description = g_strdup ((gchar *)objdesc);
+ sheet_obj->description = g_strdup ((char *) objdesc);
xmlFree (objdesc);
objdesc = NULL;
- sheet_obj->pixmap = NULL;
sheet_obj->user_data = GINT_TO_POINTER (intdata); /* XXX modify user_data type ? */
sheet_obj->user_data_type = has_intdata ? USER_DATA_IS_INTDATA /* sure, */
: USER_DATA_IS_OTHER; /* why not */
- sheet_obj->pixmap_file = iconname;
+ if (iconname && g_str_has_prefix (iconname, "res:")) {
+ // Apparently we hate the world
+ sheet_obj->pixmap = (const char **) iconname;
+ sheet_obj->pixmap_file = NULL;
+ } else {
+ sheet_obj->pixmap = NULL;
+ sheet_obj->pixmap_file = iconname;
+ }
sheet_obj->has_icon_on_sheet = has_icon_on_sheet;
sheet_obj->line_break = set_line_break;
set_line_break = FALSE;
@@ -524,7 +536,8 @@ load_register_sheet (const gchar *dirname,
}
/* set defaults */
- if (sheet_obj->pixmap_file == NULL) {
+ if (sheet_obj->pixmap_file == NULL &&
+ sheet_obj->pixmap == NULL) {
g_assert (otype->pixmap || otype->pixmap_file);
sheet_obj->pixmap = otype->pixmap;
sheet_obj->pixmap_file = otype->pixmap_file;
diff --git a/lib/widgets.c b/lib/widgets.c
index a1f4f8bf..c1305e10 100644
--- a/lib/widgets.c
+++ b/lib/widgets.c
@@ -783,8 +783,10 @@ pixbuf_from_resource (const gchar *path)
bytes = g_resources_lookup_data (path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
- if (!bytes)
+ if (!bytes) {
+ g_critical ("Missing resource %s", path);
goto out;
+ }
loader = gdk_pixbuf_loader_new ();
diff --git a/sheets/UML/aggregation.png b/objects/UML/aggregation.png
similarity index 100%
rename from sheets/UML/aggregation.png
rename to objects/UML/aggregation.png
diff --git a/objects/UML/dia-uml.gresource.xml b/objects/UML/dia-uml.gresource.xml
new file mode 100644
index 00000000..b704b008
--- /dev/null
+++ b/objects/UML/dia-uml.gresource.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/Dia/UML">
+ <file>umlclass_template.png</file>
+ <file>aggregation.png</file>
+ <file>receptacle.png</file>
+ <file>eventsource.png</file>
+ <file>eventsink.png</file>
+ </gresource>
+</gresources>
diff --git a/sheets/UML/eventsink.png b/objects/UML/eventsink.png
similarity index 100%
rename from sheets/UML/eventsink.png
rename to objects/UML/eventsink.png
diff --git a/sheets/UML/eventsource.png b/objects/UML/eventsource.png
similarity index 100%
rename from sheets/UML/eventsource.png
rename to objects/UML/eventsource.png
diff --git a/objects/UML/meson.build b/objects/UML/meson.build
index 235cedb1..1ce9cb32 100644
--- a/objects/UML/meson.build
+++ b/objects/UML/meson.build
@@ -36,6 +36,10 @@ sources = files(
'umlformalparameter.c'
)
+sources += gnome.compile_resources('dia-uml-resources', 'dia-uml.gresource.xml',
+ source_dir : '.',
+ c_name : 'dia_uml')
+
dia_object_desc += {
'name': 'uml_objects',
'sources': sources,
diff --git a/sheets/UML/receptacle.png b/objects/UML/receptacle.png
similarity index 100%
rename from sheets/UML/receptacle.png
rename to objects/UML/receptacle.png
diff --git a/sheets/UML/umlclass_template.png b/objects/UML/umlclass_template.png
similarity index 100%
rename from sheets/UML/umlclass_template.png
rename to objects/UML/umlclass_template.png
diff --git a/sheets/UML.sheet.in b/sheets/UML.sheet.in
index 5ed182b9..e4c7948f 100644
--- a/sheets/UML.sheet.in
+++ b/sheets/UML.sheet.in
@@ -8,7 +8,7 @@
</object>
<object name="UML - Class" intdata="1">
<_description>Template class</_description>
- <icon>UML/umlclass_template.png</icon>
+ <icon>res:/org/gnome/Dia/UML/umlclass_template.png</icon>
</object>
<object name="UML - Note">
<_description>Note</_description>
@@ -27,7 +27,7 @@
</object>
<object name="UML - Association" intdata="1">
<_description>Aggregation, one class is part of another</_description>
- <icon>UML/aggregation.png</icon>
+ <icon>res:/org/gnome/Dia/UML/aggregation.png</icon>
</object>
<object name="UML - Implements">
<_description>Implements, class implements a specific interface</_description>
@@ -64,15 +64,15 @@
</object>
<object name="UML - Component Feature" intdata="1">
<_description>Receptacle</_description>
- <icon>UML/receptacle.png</icon>
+ <icon>res:/org/gnome/Dia/UML/receptacle.png</icon>
</object>
<object name="UML - Component Feature" intdata="2">
<_description>Event Source</_description>
- <icon>UML/eventsource.png</icon>
+ <icon>res:/org/gnome/Dia/UML/eventsource.png</icon>
</object>
<object name="UML - Component Feature" intdata="3">
<_description>Event Sink</_description>
- <icon>UML/eventsink.png</icon>
+ <icon>res:/org/gnome/Dia/UML/eventsink.png</icon>
</object>
<object name="UML - Node">
<_description>Node</_description>
diff --git a/sheets/meson.build b/sheets/meson.build
index 849bc985..7346bf7d 100644
--- a/sheets/meson.build
+++ b/sheets/meson.build
@@ -1,11 +1,6 @@
sheetsdir = join_paths(pkgdatadir, 'sheets')
sheet_icons_sources = [
- 'UML/umlclass_template.png',
- 'UML/aggregation.png',
- 'UML/receptacle.png',
- 'UML/eventsource.png',
- 'UML/eventsink.png',
'ER/weakentity.png',
'GRAFCET/etapei.png',
'GRAFCET/etapems.png',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]