From 512897cfd36025e0cc7ea77ea3ea66a8ad10bf19 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 17 Aug 2014 09:36:30 +0200 Subject: [PATCH 1/5] Create a DEFAULT_ALTITUDE macro It is set to 280.0, which is roughly the average altitude of dry land --- configure.ac | 1 + src/ag-chart.c | 3 ++- src/ag-db.c | 3 +-- src/ag-window.c | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 7a9ce88..aef683b 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,7 @@ AC_PATH_PROGS(UNZIP, [unzip]) have_geonames_perl_modules=no AX_PROG_PERL_MODULES([XML::Writer IO::File], [have_geonames_perl_modules=yes], AC_MSG_WARN([XML::Writer and IO::File perl modules are required if you want to regenerate geodata.xml!])) AC_SUBST([have_geonames_perl_modules]) +AC_DEFINE([DEFAULT_ALTITUDE], [280.0], [Set this to the default altitude value, which is used if there is no value in geodata.xml]) IT_PROG_INTLTOOL([0.35.0]) GETTEXT_PACKAGE=astrognome AC_SUBST(GETTEXT_PACKAGE) diff --git a/src/ag-chart.c b/src/ag-chart.c index cad1283..f9279e4 100644 --- a/src/ag-chart.c +++ b/src/ag-chart.c @@ -11,6 +11,7 @@ #include #include +#include "config.h" #include "ag-db.h" #include "ag-chart.h" #include "placidus.h" @@ -1262,7 +1263,7 @@ AgChart *ag_chart_load_from_placidus_file(GFile *file, chart = ag_chart_new_full( timestamp, - real_long, real_lat, 280.0, + real_long, real_lat, DEFAULT_ALTITUDE, GSWE_HOUSE_SYSTEM_PLACIDUS ); diff --git a/src/ag-db.c b/src/ag-db.c index 2e28d93..afa4ac3 100644 --- a/src/ag-db.c +++ b/src/ag-db.c @@ -955,8 +955,7 @@ ag_db_get_chart_data_by_id(AgDb *db, guint row_id, GError **err) attributes = gda_data_model_get_attributes_at(result, COLUMN_ALTITUDE, 0); if (attributes | GDA_VALUE_ATTR_IS_NULL) { - /* TODO: this value should be macroified */ - save_data->altitude = 280.0; + save_data->altitude = DEFAULT_ALTITUDE; } else { save_data->altitude = g_value_get_double(value); } diff --git a/src/ag-window.c b/src/ag-window.c index a2fa189..2f8f90a 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -10,6 +10,7 @@ #include +#include "config.h" #include "ag-app.h" #include "ag-window.h" #include "ag-chart.h" @@ -574,7 +575,7 @@ ag_window_recalculate_chart(AgWindow *window, gboolean set_everything) } // TODO: So as this… - edit_data->altitude = 280.0; + edit_data->altitude = DEFAULT_ALTITUDE; edit_data->year = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(priv->year) ); From 2d10273af86c532a9a8a554ccc7e1990ccf979aa Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 18 Aug 2014 22:17:50 +0200 Subject: [PATCH 2/5] Bind signal callbacks with gtk_widget_class_bind_template_callback() --- src/ag-window.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/ag-window.c b/src/ag-window.c index 2f8f90a..bfdb6d0 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -984,7 +984,7 @@ ag_window_close_action(GSimpleAction *action, } } -gboolean +static gboolean ag_window_delete_event_callback(AgWindow *window, GdkEvent *event, gpointer user_data) @@ -992,7 +992,7 @@ ag_window_delete_event_callback(AgWindow *window, return (!ag_window_can_close(window, TRUE)); } -void +static void ag_window_tab_changed_cb(GtkStack *stack, GParamSpec *pspec, AgWindow *window) { GtkWidget *active_tab; @@ -1495,6 +1495,17 @@ ag_window_dispose(GObject *gobject) G_OBJECT_CLASS(ag_window_parent_class)->dispose(gobject); } +static void +ag_window_name_changed_cb(GtkEntry *name_entry, AgWindow *window) +{ + const gchar *name; + AgWindowPrivate *priv = ag_window_get_instance_private(window); + + name = gtk_entry_get_text(name_entry); + + gtk_header_bar_set_subtitle(GTK_HEADER_BAR(priv->header_bar), name); +} + static void ag_window_class_init(AgWindowClass *klass) { @@ -1618,6 +1629,19 @@ ag_window_class_init(AgWindowClass *klass) AgWindow, selection_toolbar ); + + gtk_widget_class_bind_template_callback( + widget_class, + ag_window_delete_event_callback + ); + gtk_widget_class_bind_template_callback( + widget_class, + ag_window_tab_changed_cb + ); + gtk_widget_class_bind_template_callback( + widget_class, + ag_window_name_changed_cb + ); } gboolean @@ -1787,17 +1811,6 @@ ag_window_change_tab(AgWindow *window, const gchar *tab_name) ); } -void -ag_window_name_changed_cb(GtkEntry *name_entry, AgWindow *window) -{ - const gchar *name; - AgWindowPrivate *priv = ag_window_get_instance_private(window); - - name = gtk_entry_get_text(name_entry); - - gtk_header_bar_set_subtitle(GTK_HEADER_BAR(priv->header_bar), name); -} - static void ag_window_add_chart_to_list(AgDbSave *save_data, AgWindow *window) { From 8aeec229f375bf24c9e295852fb6598f13c1ada2 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 20 Aug 2014 20:23:14 +0200 Subject: [PATCH 3/5] Switch to WebKit 4.0 API --- configure.ac | 2 +- src/ag-app.c | 27 ++++++++++++++------------- src/ag-window.c | 24 ++++++++++++++++++------ src/ag-window.h | 2 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index aef683b..8ba5c3f 100644 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,7 @@ PKG_CHECK_MODULES([GOBJECT], [gobject-2.0]) PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.12]) PKG_CHECK_MODULES([LIBXML], [libxml-2.0]) PKG_CHECK_MODULES([LIBXSLT], [libexslt]) -PKG_CHECK_MODULES([WEBKIT], [webkit2gtk-3.0]) +PKG_CHECK_MODULES([WEBKIT], [webkit2gtk-4.0]) PKG_CHECK_MODULES([GDA], [libgda-5.0 libgda-sqlite-5.0]) PKG_CHECK_MODULES([SWE_GLIB], [swe-glib >= 2.1.0]) diff --git a/src/ag-app.c b/src/ag-app.c index aa6cb9c..d788b0a 100644 --- a/src/ag-app.c +++ b/src/ag-app.c @@ -9,7 +9,7 @@ #include "astrognome.h" typedef struct _AgAppPrivate { - WebKitWebViewGroup *web_view_group; + WebKitUserContentManager *manager; } AgAppPrivate; G_DEFINE_TYPE_WITH_PRIVATE(AgApp, ag_app, GTK_TYPE_APPLICATION); @@ -58,7 +58,7 @@ ag_app_create_window(AgApp *app) GtkWidget *window; AgAppPrivate *priv = ag_app_get_instance_private(app); - window = ag_window_new(app, priv->web_view_group); + window = ag_window_new(app, priv->manager); gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(window)); gtk_widget_show_all(window); @@ -424,13 +424,14 @@ ag_app_new(void) static void ag_app_init(AgApp *app) { - AgAppPrivate *priv; - GBytes *css_data; - const gchar *css_source; - gsize css_length; + AgAppPrivate *priv; + GBytes *css_data; + const gchar *css_source; + gsize css_length; + WebKitUserStyleSheet *stylesheet; priv = ag_app_get_instance_private(app); - priv->web_view_group = webkit_web_view_group_new(NULL); + priv->manager = webkit_user_content_manager_new(); css_data = g_resources_lookup_data( "/eu/polonkai/gergely/Astrognome/ui/chart-default.css", @@ -439,14 +440,14 @@ ag_app_init(AgApp *app) ); if ((css_source = g_bytes_get_data(css_data, &css_length)) != NULL) { - webkit_web_view_group_add_user_style_sheet( - priv->web_view_group, + stylesheet = webkit_user_style_sheet_new( css_source, - NULL, - NULL, - NULL, - WEBKIT_INJECTED_CONTENT_FRAMES_TOP_ONLY + WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, + WEBKIT_USER_STYLE_LEVEL_USER, + NULL, NULL ); + webkit_user_content_manager_add_style_sheet(priv->manager, stylesheet); + webkit_user_style_sheet_unref(stylesheet); } g_bytes_unref(css_data); diff --git a/src/ag-window.c b/src/ag-window.c index bfdb6d0..e722129 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -393,9 +393,14 @@ ag_window_redraw_aspect_table(AgWindow *window) void ag_window_redraw_chart(AgWindow *window) { + gsize length; GError *err = NULL; AgWindowPrivate *priv = ag_window_get_instance_private(window); - gchar *svg_content = ag_chart_create_svg(priv->chart, NULL, &err); + gchar *svg_content = ag_chart_create_svg( + priv->chart, + &length, + &err + ); if (svg_content == NULL) { ag_app_message_dialog( @@ -405,11 +410,16 @@ ag_window_redraw_chart(AgWindow *window) err->message ); } else { - webkit_web_view_load_html( + GBytes *content; + + content = g_bytes_new_take(svg_content, length); + + webkit_web_view_load_bytes( WEBKIT_WEB_VIEW(priv->chart_web_view), - svg_content, NULL + content, "image/svg+xml", + "UTF-8", NULL ); - g_free(svg_content); + g_bytes_unref(content); } ag_window_redraw_aspect_table(window); @@ -1671,12 +1681,14 @@ ag_window_configure_event_cb(GtkWidget *widget, } GtkWidget * -ag_window_new(AgApp *app, WebKitWebViewGroup *web_view_group) +ag_window_new(AgApp *app, WebKitUserContentManager *manager) { AgWindow *window = g_object_new(AG_TYPE_WINDOW, NULL); AgWindowPrivate *priv = ag_window_get_instance_private(window); - priv->chart_web_view = webkit_web_view_new_with_group(web_view_group); + priv->chart_web_view = webkit_web_view_new_with_user_content_manager( + manager + ); gtk_container_add(GTK_CONTAINER(priv->tab_chart), priv->chart_web_view); // TODO: translate this error message! diff --git a/src/ag-window.h b/src/ag-window.h index c4ba531..3ebb563 100644 --- a/src/ag-window.h +++ b/src/ag-window.h @@ -41,7 +41,7 @@ struct _AgWindowClass { GType ag_window_get_type(void) G_GNUC_CONST; -GtkWidget *ag_window_new(AgApp *app, WebKitWebViewGroup *web_view_group); +GtkWidget *ag_window_new(AgApp *app, WebKitUserContentManager *manager); void ag_window_set_chart(AgWindow *window, AgChart *chart); From 6070dc9cc0003f79ba8b4011763dd530c79c2701 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 20 Aug 2014 21:39:33 +0200 Subject: [PATCH 4/5] Add an empty toolbar to the chart tab --- src/ag-window.c | 6 +++++- src/resources/ui/ag-window.ui | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ag-window.c b/src/ag-window.c index e722129..e9ebc0e 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -1689,7 +1689,11 @@ ag_window_new(AgApp *app, WebKitUserContentManager *manager) priv->chart_web_view = webkit_web_view_new_with_user_content_manager( manager ); - gtk_container_add(GTK_CONTAINER(priv->tab_chart), priv->chart_web_view); + gtk_box_pack_end( + GTK_BOX(priv->tab_chart), + priv->chart_web_view, + TRUE, TRUE, 0 + ); // TODO: translate this error message! webkit_web_view_load_html( diff --git a/src/resources/ui/ag-window.ui b/src/resources/ui/ag-window.ui index ee4e41f..7a43f58 100644 --- a/src/resources/ui/ag-window.ui +++ b/src/resources/ui/ag-window.ui @@ -757,9 +757,19 @@ - + True False + vertical + + + True + False + + + start + + chart From 59ac56ba8f22abaa64aa52c13b73bcf4d9125c24 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 20 Aug 2014 23:42:59 +0200 Subject: [PATCH 5/5] Add connection view changer buttons (aspects/antiscia) --- src/ag-window.c | 88 ++++++++++++++++++++++++++++++----- src/resources/ui/ag-window.ui | 21 +++++++++ 2 files changed, 97 insertions(+), 12 deletions(-) diff --git a/src/ag-window.c b/src/ag-window.c index e9ebc0e..31bf686 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -1264,19 +1264,83 @@ ag_window_delete_action(GSimpleAction *action, g_action_group_activate_action(G_ACTION_GROUP(window), "refresh", NULL); } +static void +ag_window_js_callback(GObject *object, GAsyncResult *res, gpointer user_data) +{ + WebKitJavascriptResult *js_result; + GError *err = NULL; + + if ((js_result = webkit_web_view_run_javascript_finish( + WEBKIT_WEB_VIEW(object), + res, + &err + )) != NULL) { + webkit_javascript_result_unref(js_result); + } +} + +static void +ag_window_connection_action(GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GVariant *current_state; + const gchar *state; + gchar *js_code = NULL; + AgWindowPrivate *priv = ag_window_get_instance_private( + AG_WINDOW(user_data) + ); + static gchar *js = "aspects = document.getElementById('aspects');\n" \ + "antiscia = document.getElementById('antiscia');\n" \ + "aspects.setAttribute('visibility', '%s');\n" \ + "antiscia.setAttribute('visibility', '%s');\n"; + + current_state = g_action_get_state(G_ACTION(action)); + + if (g_variant_equal(current_state, parameter)) { + return; + } + + g_action_change_state(G_ACTION(action), parameter); + + state = g_variant_get_string(parameter, NULL); + + if (strcmp("aspects", state) == 0) { + g_debug("Switching to aspects"); + js_code = g_strdup_printf(js, "visible", "hidden"); + } else if (strcmp("antiscia", state) == 0) { + g_debug("Switching to antiscia"); + js_code = g_strdup_printf(js, "hidden", "visible"); + } else { + g_warning("Connection type '%s' is invalid", state); + } + + if (js_code) { + webkit_web_view_run_javascript( + WEBKIT_WEB_VIEW(priv->chart_web_view), + js_code, + NULL, + ag_window_js_callback, + NULL + ); + g_free(js_code); + } +} + static GActionEntry win_entries[] = { - { "close", ag_window_close_action, NULL, NULL, NULL }, - { "save", ag_window_save_action, NULL, NULL, NULL }, - { "export", ag_window_export_action, NULL, NULL, NULL }, - { "export-svg", ag_window_export_svg_action, NULL, NULL, NULL }, - { "view-menu", ag_window_view_menu_action, NULL, "false", NULL }, - { "gear-menu", ag_window_gear_menu_action, NULL, "false", NULL }, - { "change-tab", ag_window_change_tab_action, "s", "'edit'", NULL }, - { "new-chart", ag_window_new_chart_action, NULL, NULL, NULL }, - { "back", ag_window_back_action, NULL, NULL, NULL }, - { "refresh", ag_window_refresh_action, NULL, NULL, NULL }, - { "selection", ag_window_selection_mode_action, NULL, "false", NULL }, - { "delete", ag_window_delete_action, NULL, NULL, NULL }, + { "close", ag_window_close_action, NULL, NULL, NULL }, + { "save", ag_window_save_action, NULL, NULL, NULL }, + { "export", ag_window_export_action, NULL, NULL, NULL }, + { "export-svg", ag_window_export_svg_action, NULL, NULL, NULL }, + { "view-menu", ag_window_view_menu_action, NULL, "false", NULL }, + { "gear-menu", ag_window_gear_menu_action, NULL, "false", NULL }, + { "change-tab", ag_window_change_tab_action, "s", "'edit'", NULL }, + { "new-chart", ag_window_new_chart_action, NULL, NULL, NULL }, + { "back", ag_window_back_action, NULL, NULL, NULL }, + { "refresh", ag_window_refresh_action, NULL, NULL, NULL }, + { "selection", ag_window_selection_mode_action, NULL, "false", NULL }, + { "delete", ag_window_delete_action, NULL, NULL, NULL }, + { "connection", ag_window_connection_action, "s", "'aspects'", NULL }, }; static void diff --git a/src/resources/ui/ag-window.ui b/src/resources/ui/ag-window.ui index 7a43f58..c60a8a1 100644 --- a/src/resources/ui/ag-window.ui +++ b/src/resources/ui/ag-window.ui @@ -765,6 +765,27 @@ True False + + + True + False + Aspects + False + win.connection + 'aspects' + + + + + True + False + Antiscia + False + toolbar_aspect + win.connection + 'antiscia' + + start