diff --git a/data/Makefile.am b/data/Makefile.am index 1f86f04..f9838e9 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,22 +1,5 @@ SUBDIRS = icons geonames -chartdatadir = $(pkgdatadir) -chartdata_DATA = chart.xsl \ - chart.css \ - sign_aries.xml \ - sign_taurus.xml \ - sign_gemini.xml \ - sign_cancer.xml \ - sign_leo.xml \ - sign_virgo.xml \ - sign_libra.xml \ - sign_scorpio.xml \ - sign_sagittarius.xml \ - sign_capricorn.xml \ - sign_aquarius.xml \ - sign_pisces.xml \ - $(NULL) - gsettings_SCHEMAS = \ eu.polonkai.gergely.astrognome.gschema.xml \ $(NULL) @@ -29,7 +12,6 @@ desktop_in_files = astrognome.desktop.in desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) EXTRA_DIST = \ - $(chartdata_DATA) \ $(desktop_in_files) \ $(gsettings_SCHEMAS) \ $(NULL) diff --git a/data/chart.xsl b/data/chart.xsl index 3a15447..4211509 100644 --- a/data/chart.xsl +++ b/data/chart.xsl @@ -17,7 +17,6 @@ - href="" type="text/css" ui/ag-window.ui ui/ag-preferences.ui ui/chart-default.css + ui/chart-default.xsl + default-icons/sign-aries.xml + default-icons/sign-taurus.xml + default-icons/sign-gemini.xml + default-icons/sign-cancer.xml + default-icons/sign-leo.xml + default-icons/sign-virgo.xml + default-icons/sign-libra.xml + default-icons/sign-scorpio.xml + default-icons/sign-sagittarius.xml + default-icons/sign-capricorn.xml + default-icons/sign-aquarius.xml + default-icons/sign-pisces.xml default-icons/planet-sun.svg diff --git a/src/astrognome.c b/src/astrognome.c index 658f3a4..ba4797d 100644 --- a/src/astrognome.c +++ b/src/astrognome.c @@ -20,6 +20,7 @@ GtkBuilder *builder; GtkFileFilter *filter_all = NULL; GtkFileFilter *filter_chart = NULL; +GHashTable *xinclude_positions; const char *moonStateName[] = { "New Moon", @@ -47,6 +48,100 @@ init_filters(void) g_object_ref_sink(filter_chart); } +static int +xml_match_gresource(const char *uri) +{ + if ((uri != NULL) && (!strncmp("gres://", uri, 7))) { + g_debug("Matched gres:// type link."); + + return 1; + } else { + return 0; + } +} + +static void * +xml_open_gresource(const gchar *uri) +{ + gchar *path; + GBytes *res_location; + gsize *position; + + if ((uri == NULL) || (strncmp("gres://", uri, 7))) { + return NULL; + } + + path = g_strdup_printf("/eu/polonkai/gergely/Astrognome/%s", uri + 7); + g_debug("Opening gresource %s", path); + + res_location = g_resources_lookup_data( + path, + G_RESOURCE_LOOKUP_FLAGS_NONE, + NULL + ); + g_free(path); + + if ((position = g_hash_table_lookup(xinclude_positions, res_location)) == NULL) { + g_hash_table_insert(xinclude_positions, res_location, g_new0(gsize, 1)); + } else { + g_warning("Reopening gres:// link?"); + *position = 0; + } + + return res_location; +} + +static int +xml_close_gresource(void *context) +{ + if (context == NULL) { + return -1; + } + + g_debug("Closing gres:// link"); + + g_hash_table_remove(xinclude_positions, context); + g_bytes_unref((GBytes *)context); + + return 0; +} + +static int +xml_read_gresource(void *context, char *buffer, int len) +{ + const gchar *data; + gsize max_length; + GBytes *data_holder = (GBytes *)context; + gsize *position; + + if ((context == NULL) || (buffer == NULL) || (len < 0)) { + return -1; + } + + data = g_bytes_get_data(data_holder, &max_length); + position = g_hash_table_lookup(xinclude_positions, data_holder); + + if (position == NULL) { + g_warning("Trying to read non-opened gres:// link!"); + + return -1; + } + + if (*position >= max_length) { + return 0; + } + + if (len > max_length - *position) { + len = max_length - *position; + } + + memcpy(buffer, data + *position, len); + g_debug("Read %d bytes", len); + *position += len; + + return len; +} + int main(int argc, char *argv[]) { @@ -89,10 +184,22 @@ main(int argc, char *argv[]) LIBXML_TEST_VERSION; xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; + xmlRegisterInputCallbacks( + xml_match_gresource, + xml_open_gresource, + xml_read_gresource, + xml_close_gresource + ); xsltInit(); xsltSetXIncludeDefault(1); exsltRegisterAll(); gswe_init(); + xinclude_positions = g_hash_table_new_full( + g_bytes_hash, + g_bytes_equal, + (GDestroyNotify)g_bytes_unref, + (GDestroyNotify)g_free + ); memset(&options, 0, sizeof(AstrognomeOptions)); @@ -135,6 +242,7 @@ main(int argc, char *argv[]) status = g_application_run(G_APPLICATION(app), argc, argv); + g_hash_table_destroy(xinclude_positions); g_object_unref(app); return status; diff --git a/data/sign_aquarius.xml b/src/resources/default-icons/sign-aquarius.xml similarity index 100% rename from data/sign_aquarius.xml rename to src/resources/default-icons/sign-aquarius.xml diff --git a/data/sign_aries.xml b/src/resources/default-icons/sign-aries.xml similarity index 100% rename from data/sign_aries.xml rename to src/resources/default-icons/sign-aries.xml diff --git a/data/sign_cancer.xml b/src/resources/default-icons/sign-cancer.xml similarity index 100% rename from data/sign_cancer.xml rename to src/resources/default-icons/sign-cancer.xml diff --git a/data/sign_capricorn.xml b/src/resources/default-icons/sign-capricorn.xml similarity index 100% rename from data/sign_capricorn.xml rename to src/resources/default-icons/sign-capricorn.xml diff --git a/data/sign_gemini.xml b/src/resources/default-icons/sign-gemini.xml similarity index 100% rename from data/sign_gemini.xml rename to src/resources/default-icons/sign-gemini.xml diff --git a/data/sign_leo.xml b/src/resources/default-icons/sign-leo.xml similarity index 100% rename from data/sign_leo.xml rename to src/resources/default-icons/sign-leo.xml diff --git a/data/sign_libra.xml b/src/resources/default-icons/sign-libra.xml similarity index 100% rename from data/sign_libra.xml rename to src/resources/default-icons/sign-libra.xml diff --git a/data/sign_pisces.xml b/src/resources/default-icons/sign-pisces.xml similarity index 100% rename from data/sign_pisces.xml rename to src/resources/default-icons/sign-pisces.xml diff --git a/data/sign_sagittarius.xml b/src/resources/default-icons/sign-sagittarius.xml similarity index 100% rename from data/sign_sagittarius.xml rename to src/resources/default-icons/sign-sagittarius.xml diff --git a/data/sign_scorpio.xml b/src/resources/default-icons/sign-scorpio.xml similarity index 100% rename from data/sign_scorpio.xml rename to src/resources/default-icons/sign-scorpio.xml diff --git a/data/sign_taurus.xml b/src/resources/default-icons/sign-taurus.xml similarity index 100% rename from data/sign_taurus.xml rename to src/resources/default-icons/sign-taurus.xml diff --git a/data/sign_virgo.xml b/src/resources/default-icons/sign-virgo.xml similarity index 100% rename from data/sign_virgo.xml rename to src/resources/default-icons/sign-virgo.xml diff --git a/src/resources/ui/chart-default.xsl b/src/resources/ui/chart-default.xsl new file mode 100644 index 0000000..ca4c3d9 --- /dev/null +++ b/src/resources/ui/chart-default.xsl @@ -0,0 +1,704 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + point_vertex + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +