diff --git a/data/eu.polonkai.gergely.astrognome.gschema.xml b/data/eu.polonkai.gergely.astrognome.gschema.xml index cff5a2b..2d03e80 100644 --- a/data/eu.polonkai.gergely.astrognome.gschema.xml +++ b/data/eu.polonkai.gergely.astrognome.gschema.xml @@ -1,6 +1,16 @@ + + false + Display planet symbols as UTF-8 characters + Whether to show planet symbols as their UTF-8 representation. Uses less memory, but not all system fonts have them defined. If a planet (like most dwarves) don’t have a character representation, an image fallback will be used. + + + false + Display aspect symbols as UTF-8 characters + Whether to show aspect symbols as their UTF-8 representation. Uses less memory, but not all system fonts have them defined. If an aspect don’t have a character representation, an image fallback will be used. + diff --git a/src/Makefile.am b/src/Makefile.am index 153d8b9..f1e551c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,10 +1,11 @@ -resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/ag.gresource.xml) +RESOURCE_DIR = $(srcdir)/resources +resource_files = $(shell glib-compile-resources --sourcedir=$(RESOURCE_DIR) --generate-dependencies $(srcdir)/ag.gresource.xml) ag-resources.c: ag.gresource.xml $(resource_files) - glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name ag $(srcdir)/ag.gresource.xml + glib-compile-resources --target=$@ --sourcedir=$(RESOURCE_DIR) --generate-source --c-name ag $(srcdir)/ag.gresource.xml ag-resources.h: ag.gresource.xml $(resource_files) - glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name ag $(srcdir)/ag.gresource.xml + glib-compile-resources --target=$@ --sourcedir=$(RESOURCE_DIR) --generate-header --c-name ag $(srcdir)/ag.gresource.xml BUILT_SOURCES = \ ag-resources.h \ @@ -33,7 +34,3 @@ astrognome_LDADD = $(SWE_GLIB_LIBS) $(GTK_LIBS) $(LIBXML_LIBS) $(LIBXSLT_LIBS) $ astrognome_LDFLAGS = -rdynamic astrognome_CFLAGS = $(SWE_GLIB_CFLAGS) $(CFLAGS) $(GTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBXSLT_CFLAGS) $(WEBKIT_CFLAGS) -Wall -guidir = $(pkgdatadir) -gui_DATA = astrognome.ui - -EXTRA_DIST += $(gui_DATA) diff --git a/src/ag-app.c b/src/ag-app.c index c3e83b2..e40e567 100644 --- a/src/ag-app.c +++ b/src/ag-app.c @@ -257,7 +257,7 @@ setup_menu(AgApp *app) builder = gtk_builder_new(); - if (!gtk_builder_add_from_resource(builder, "/eu/polonkai/gergely/astrognome/astrognome.ui", &err)) { + if (!gtk_builder_add_from_resource(builder, "/eu/polonkai/gergely/Astrognome/ui/astrognome.ui", &err)) { g_error("%s", (err) ? err->message : "unknown error"); } diff --git a/src/ag-preferences.c b/src/ag-preferences.c index 5615d4a..ebfd6ca 100644 --- a/src/ag-preferences.c +++ b/src/ag-preferences.c @@ -7,6 +7,9 @@ static GtkWidget *prefs_dialog = NULL; typedef struct _AgPreferencesPrivate { GtkCheckButton *maximized; + GtkCheckButton *planet_chars; + GtkCheckButton *aspect_chars; + AgSettings *settings; } AgPreferencesPrivate; @@ -40,15 +43,18 @@ ag_preferences_class_init(AgPreferencesClass *klass) object_class->finalize = ag_preferences_finalize; dialog_class->response = ag_preferences_response; - gtk_widget_class_set_template_from_resource(widget_class, "/eu/polonkai/gergely/astrognome/ag-preferences.ui"); + gtk_widget_class_set_template_from_resource(widget_class, "/eu/polonkai/gergely/Astrognome/ui/ag-preferences.ui"); gtk_widget_class_bind_template_child_private(widget_class, AgPreferences, maximized); + gtk_widget_class_bind_template_child_private(widget_class, AgPreferences, planet_chars); + gtk_widget_class_bind_template_child_private(widget_class, AgPreferences, aspect_chars); } static void ag_preferences_init(AgPreferences *prefs) { AgPreferencesPrivate *priv; - GSettings *settings_window; + GSettings *settings_window, + *settings_main; priv = ag_preferences_get_instance_private(prefs); gtk_widget_init_template(GTK_WIDGET(prefs)); @@ -57,6 +63,10 @@ ag_preferences_init(AgPreferences *prefs) settings_window = ag_settings_peek_window_settings(priv->settings); g_settings_bind(settings_window, "maximized", priv->maximized, "active", G_SETTINGS_BIND_DEFAULT); + + settings_main = ag_settings_peek_main_settings(priv->settings); + g_settings_bind(settings_main, "planets-char", priv->planet_chars, "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings_main, "aspects-char", priv->aspect_chars, "active", G_SETTINGS_BIND_DEFAULT); } void diff --git a/src/ag-settings.c b/src/ag-settings.c index f73307a..8026015 100644 --- a/src/ag-settings.c +++ b/src/ag-settings.c @@ -1,11 +1,13 @@ #include "ag-settings.h" +#define SETTINGS_SCHEMA_ID_MAIN "eu.polonkai.gergely.Astrognome" #define SETTINGS_SCHEMA_ID_WINDOW "eu.polonkai.gergely.Astrognome.state.window" -#define SETTINGS_SCHEMA_ID_CHART "eu.polonkai.gergely.Astrognome.state.chart" +#define SETTINGS_SCHEMA_ID_CHART "eu.polonkai.gergely.Astrognome.state.chart" static AgSettings *singleton = NULL; struct _AgSettingsPrivate { + GSettings *settings_main; GSettings *settings_window; GSettings *settings_chart; }; @@ -17,6 +19,7 @@ ag_settings_init(AgSettings *settings) { AgSettingsPrivate *priv = ag_settings_get_instance_private(settings); + priv->settings_main = g_settings_new(SETTINGS_SCHEMA_ID_MAIN); priv->settings_window = g_settings_new(SETTINGS_SCHEMA_ID_WINDOW); priv->settings_chart = g_settings_new(SETTINGS_SCHEMA_ID_CHART); } @@ -28,6 +31,7 @@ ag_settings_dispose(GObject *object) g_clear_object(&priv->settings_window); g_clear_object(&priv->settings_chart); + g_clear_object(&priv->settings_main); G_OBJECT_CLASS(ag_settings_parent_class)->dispose(object); } @@ -63,6 +67,14 @@ ag_settings_get(void) return singleton; } +GSettings * +ag_settings_peek_main_settings(AgSettings *settings) +{ + AgSettingsPrivate *priv = ag_settings_get_instance_private(settings); + + return priv->settings_main; +} + GSettings * ag_settings_peek_window_settings(AgSettings *settings) { diff --git a/src/ag-settings.h b/src/ag-settings.h index ac15863..82acc5d 100644 --- a/src/ag-settings.h +++ b/src/ag-settings.h @@ -29,6 +29,7 @@ GType ag_settings_get_type(void); AgSettings *ag_settings_get(void); +GSettings *ag_settings_peek_main_settings(AgSettings *settings); GSettings *ag_settings_peek_window_settings(AgSettings *settings); GSettings *ag_settings_peek_chart_settings(AgSettings *settings); diff --git a/src/ag-window.c b/src/ag-window.c index d5cd5b5..a240e05 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -256,14 +256,244 @@ ag_window_export_svg_action(GSimpleAction *action, GVariant *parameter, gpointer // TODO: Check err! } +const gchar * +ag_window_planet_character(GswePlanet planet) +{ + switch (planet) { + case GSWE_PLANET_ASCENDANT: + return "AC"; + + case GSWE_PLANET_MC: + return "MC"; + + case GSWE_PLANET_VERTEX: + return "Vx"; + + case GSWE_PLANET_SUN: + return "☉"; + + case GSWE_PLANET_MOON: + return "☽"; + + case GSWE_PLANET_MOON_NODE: + return "☊"; + + case GSWE_PLANET_MERCURY: + return "☿"; + + case GSWE_PLANET_VENUS: + return "♀"; + + case GSWE_PLANET_MARS: + return "♂"; + + case GSWE_PLANET_JUPITER: + return "♃"; + + case GSWE_PLANET_SATURN: + return "♄"; + + case GSWE_PLANET_URANUS: + return "♅"; + + case GSWE_PLANET_NEPTUNE: + return "♆"; + + case GSWE_PLANET_PLUTO: + return "♇"; + + case GSWE_PLANET_CERES: + return "⚳"; + + case GSWE_PLANET_PALLAS: + return "⚴"; + + case GSWE_PLANET_JUNO: + return "⚵"; + + case GSWE_PLANET_VESTA: + return "⚶"; + + case GSWE_PLANET_CHIRON: + return "⚷"; + + case GSWE_PLANET_MOON_APOGEE: + return "⚸"; + + default: + return NULL; + } +} + +GtkWidget * +ag_window_create_planet_widget(GswePlanetInfo *planet_info) +{ + const gchar *planet_char; + GswePlanet planet = gswe_planet_info_get_planet(planet_info); + GSettings *settings = ag_settings_peek_main_settings(ag_settings_get()); + + if ( + ((planet_char = ag_window_planet_character(planet)) != NULL) + && (g_settings_get_boolean(settings, "planets-char")) + ) + { + return gtk_label_new(planet_char); + } + + switch (planet) { + case GSWE_PLANET_SUN: + return gtk_image_new_from_resource("/eu/polonkai/gergely/Astrognome/default-icons/planet-sun.svg"); + + default: + return gtk_label_new(gswe_planet_info_get_name(planet_info)); + } +} + +const gchar * +ag_window_aspect_character(GsweAspect aspect) +{ + switch (aspect) { + case GSWE_ASPECT_CONJUCTION: + return "☌"; + + case GSWE_ASPECT_OPPOSITION: + return "☍"; + + case GSWE_ASPECT_QUINTILE: + return "Q"; + + case GSWE_ASPECT_BIQUINTILE: + return "BQ"; + + case GSWE_ASPECT_SQUARE: + return "◽"; + + case GSWE_ASPECT_TRINE: + return "▵"; + + case GSWE_ASPECT_SEXTILE: + return "⚹"; + + case GSWE_ASPECT_SEMISEXTILE: + return "⚺"; + + case GSWE_ASPECT_QUINCUNX: + return "⚻"; + + case GSWE_ASPECT_SESQUISQUARE: + return "⚼"; + + default: + return NULL; + } +} + +GtkWidget * +ag_window_create_aspect_widget(GsweAspectInfo *aspect_info) +{ + const gchar *aspect_char; + GsweAspect aspect = gswe_aspect_info_get_aspect(aspect_info); + GSettings *settings = ag_settings_peek_main_settings(ag_settings_get()); + + if ( + ((aspect_char = ag_window_aspect_character(aspect)) != NULL) + && (g_settings_get_boolean(settings, "aspects-char")) + ) + { + return gtk_label_new(aspect_char); + } + + switch (aspect) { + default: + return gtk_label_new(gswe_aspect_info_get_name(aspect_info)); + } +} + void -ag_window_redraw_chart(AgWindow *window) +ag_window_redraw_aspect_table(AgWindow *window) { GList *planet_list, *planet1, *planet2; guint i, j; + AgWindowPrivate *priv = ag_window_get_instance_private(window); + + planet_list = ag_chart_get_planets(priv->chart); + + if (priv->aspect_table_populated == FALSE) { + GList *planet; + guint i; + + for (planet = planet_list, i = 0; planet; planet = g_list_next(planet), i++) { + GtkWidget *label_hor, + *label_ver, + *current_widget; + GswePlanet planet_id; + GswePlanetData *planet_data; + GswePlanetInfo *planet_info; + + planet_id = GPOINTER_TO_INT(planet->data); + planet_data = gswe_moment_get_planet(GSWE_MOMENT(priv->chart), planet_id, NULL); + planet_info = gswe_planet_data_get_planet_info(planet_data); + + if ((current_widget = gtk_grid_get_child_at(GTK_GRID(priv->aspect_table), i + 1, i)) != NULL) { + gtk_container_remove(GTK_CONTAINER(priv->aspect_table), current_widget); + } + + label_hor = ag_window_create_planet_widget(planet_info); + gtk_grid_attach(GTK_GRID(priv->aspect_table), label_hor, i + 1, i, 1, 1); + + if (i > 0) { + if ((current_widget = gtk_grid_get_child_at(GTK_GRID(priv->aspect_table), 0, i)) != NULL) { + gtk_container_remove(GTK_CONTAINER(priv->aspect_table), current_widget); + } + + label_ver = ag_window_create_planet_widget(planet_info); + gtk_grid_attach(GTK_GRID(priv->aspect_table), label_ver, 0, i, 1, 1); + } + } + + priv->aspect_table_populated = TRUE; + } + + for (planet1 = planet_list, i = 0; planet1; planet1 = g_list_next(planet1), i++) { + for (planet2 = planet_list, j = 0; planet2; planet2 = g_list_next(planet2), j++) { + GsweAspectData *aspect; + GtkWidget *aspect_widget; + GError *err = NULL; + + if (GPOINTER_TO_INT(planet1->data) == GPOINTER_TO_INT(planet2->data)) { + break; + } + + if ((aspect_widget = gtk_grid_get_child_at(GTK_GRID(priv->aspect_table), j + 1, i)) != NULL) { + gtk_container_remove(GTK_CONTAINER(priv->aspect_table), aspect_widget); + } + + if ((aspect = gswe_moment_get_aspect_by_planets(GSWE_MOMENT(priv->chart), GPOINTER_TO_INT(planet1->data), GPOINTER_TO_INT(planet2->data), &err)) != NULL) { + GsweAspectInfo *aspect_info; + + aspect_info = gswe_aspect_data_get_aspect_info(aspect); + + if (gswe_aspect_data_get_aspect(aspect) != GSWE_ASPECT_NONE) { + aspect_widget = ag_window_create_aspect_widget(aspect_info); + gtk_grid_attach(GTK_GRID(priv->aspect_table), aspect_widget, j + 1, i, 1, 1); + } + } else if (err) { + g_warning("%s\n", err->message); + } else { + g_error("No aspect is returned between two planets. This is a bug in SWE-GLib!\n"); + } + } + } + + gtk_widget_show_all(priv->aspect_table); +} + +void +ag_window_redraw_chart(AgWindow *window) +{ GError *err = NULL; AgWindowPrivate *priv = ag_window_get_instance_private(window); gchar *svg_content = ag_chart_create_svg(priv->chart, NULL, &err); @@ -281,72 +511,7 @@ ag_window_redraw_chart(AgWindow *window) g_free(svg_content); } - planet_list = ag_chart_get_planets(priv->chart); - - if (priv->aspect_table_populated == FALSE) { - GList *planet; - guint i; - - for (planet = planet_list, i = 0; planet; planet = g_list_next(planet), i++) { - GtkWidget *label_hor, - *label_ver; - GswePlanet planet_id; - GswePlanetData *planet_data; - GswePlanetInfo *planet_info; - - planet_id = GPOINTER_TO_INT(planet->data); - planet_data = gswe_moment_get_planet(GSWE_MOMENT(priv->chart), planet_id, NULL); - planet_info = gswe_planet_data_get_planet_info(planet_data); - - label_hor = gtk_label_new(gswe_planet_info_get_name(planet_info)); - gtk_grid_attach(GTK_GRID(priv->aspect_table), label_hor, i + 1, i, 1, 1); - - if (i > 0) { - label_ver = gtk_label_new(gswe_planet_info_get_name(planet_info)); - gtk_grid_attach(GTK_GRID(priv->aspect_table), label_ver, 0, i, 1, 1); - } - } - - priv->aspect_table_populated = TRUE; - } - - for (planet1 = planet_list, i = 0; planet1; planet1 = g_list_next(planet1), i++) { - for (planet2 = planet_list, j = 0; planet2; planet2 = g_list_next(planet2), j++) { - GsweAspectData *aspect; - GError *err = NULL; - - if (GPOINTER_TO_INT(planet1->data) == GPOINTER_TO_INT(planet2->data)) { - break; - } - - if ((aspect = gswe_moment_get_aspect_by_planets(GSWE_MOMENT(priv->chart), GPOINTER_TO_INT(planet1->data), GPOINTER_TO_INT(planet2->data), &err)) != NULL) { - GsweAspectInfo *aspect_info; - GtkWidget *aspect_label; - - aspect_info = gswe_aspect_data_get_aspect_info(aspect); - aspect_label = gtk_grid_get_child_at(GTK_GRID(priv->aspect_table), j + 1, i); - - if (gswe_aspect_data_get_aspect(aspect) == GSWE_ASPECT_NONE) { - if (aspect_label != NULL) { - gtk_container_remove(GTK_CONTAINER(priv->aspect_table), aspect_label); - } - } else { - if (aspect_label == NULL) { - aspect_label = gtk_label_new(gswe_aspect_info_get_name(aspect_info)); - gtk_grid_attach(GTK_GRID(priv->aspect_table), aspect_label, j + 1, i, 1, 1); - } else { - gtk_label_set_label(GTK_LABEL(aspect_label), gswe_aspect_info_get_name(aspect_info)); - } - } - } else if (err) { - g_warning("%s\n", err->message); - } else { - g_error("No aspect is returned between two planets. This is a bug in SWE-GLib!\n"); - } - } - } - - gtk_widget_show_all(priv->aspect_table); + ag_window_redraw_aspect_table(window); } void @@ -482,15 +647,34 @@ static GActionEntry win_entries[] = { { "change-tab", ag_window_change_tab_action, "s", "'edit'", NULL }, }; +static void +ag_window_display_changed(GSettings *settings, gchar *key, AgWindow *window) +{ + AgWindowPrivate *priv = ag_window_get_instance_private(window); + + /* The planet symbols are redrawn only if aspect_table_populated is + * set to FALSE */ + if (g_str_equal("planets-char", key)) { + priv->aspect_table_populated = FALSE; + } + + ag_window_redraw_aspect_table(window); +} + static void ag_window_init(AgWindow *window) { - AgWindowPrivate *priv; GtkAccelGroup *accel_group; + GSettings *main_settings; + AgWindowPrivate *priv = ag_window_get_instance_private(window); gtk_widget_init_template(GTK_WIDGET(window)); - priv = ag_window_get_instance_private(window); + priv->settings = ag_settings_get(); + main_settings = ag_settings_peek_main_settings(priv->settings); + + g_signal_connect(G_OBJECT(main_settings), "changed::planets-char", G_CALLBACK(ag_window_display_changed), window); + g_signal_connect(G_OBJECT(main_settings), "changed::aspects-char", G_CALLBACK(ag_window_display_changed), window); webkit_web_view_load_string( WEBKIT_WEB_VIEW(priv->chart_web_view), @@ -540,7 +724,7 @@ ag_window_class_init(AgWindowClass *klass) gobject_class->dispose = ag_window_dispose; - gtk_widget_class_set_template_from_resource(widget_class, "/eu/polonkai/gergely/astrognome/ag-window.ui"); + gtk_widget_class_set_template_from_resource(widget_class, "/eu/polonkai/gergely/Astrognome/ui/ag-window.ui"); gtk_widget_class_bind_template_child_private(widget_class, AgWindow, header_bar); gtk_widget_class_bind_template_child_private(widget_class, AgWindow, name); gtk_widget_class_bind_template_child_private(widget_class, AgWindow, year); diff --git a/src/ag.gresource.xml b/src/ag.gresource.xml index 120a9d7..28f286b 100644 --- a/src/ag.gresource.xml +++ b/src/ag.gresource.xml @@ -1,8 +1,10 @@ - - astrognome.ui - ag-window.ui - ag-preferences.ui + + ui/astrognome.ui + ui/ag-window.ui + ui/ag-preferences.ui + + default-icons/planet-sun.svg diff --git a/src/resources/default-icons/planet-sun.svg b/src/resources/default-icons/planet-sun.svg new file mode 100644 index 0000000..df5c8b1 --- /dev/null +++ b/src/resources/default-icons/planet-sun.svg @@ -0,0 +1,69 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/ag-preferences.ui b/src/resources/ui/ag-preferences.ui similarity index 62% rename from src/ag-preferences.ui rename to src/resources/ui/ag-preferences.ui index 1f5a2a7..54bc099 100644 --- a/src/ag-preferences.ui +++ b/src/resources/ui/ag-preferences.ui @@ -46,6 +46,34 @@ 0 + + + Use UTF-8 characters for planet symbols + True + True + False + 0 + True + + + 0 + 1 + + + + + Use UTF-8 characters for aspect symbols + True + True + False + 0 + True + + + 0 + 2 + + False diff --git a/src/ag-window.ui b/src/resources/ui/ag-window.ui similarity index 100% rename from src/ag-window.ui rename to src/resources/ui/ag-window.ui diff --git a/src/astrognome.ui b/src/resources/ui/astrognome.ui similarity index 100% rename from src/astrognome.ui rename to src/resources/ui/astrognome.ui