From 7c745e51a79597a31e9f7bcf31cd3abc728a72a3 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 8 Jul 2014 23:55:54 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Reorder=20Edit=20GtkGrid=E2=80=99s=20childr?= =?UTF-8?q?en=20to=20be=20a=20bit=20more=20logical?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/ui/ag-window.ui | 144 +++++++++++++++++----------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/resources/ui/ag-window.ui b/src/resources/ui/ag-window.ui index 0b60206..156af90 100644 --- a/src/resources/ui/ag-window.ui +++ b/src/resources/ui/ag-window.ui @@ -219,6 +219,20 @@ 1 + + + True + True + edit-find-symbolic + False + False + + + 1 + 2 + 3 + + True @@ -230,6 +244,20 @@ 2 + + + True + True + edit-find-symbolic + False + False + + + 1 + 1 + 3 + + True @@ -375,17 +403,6 @@ 1 - - - True - False - Day - - - 6 - 1 - - True @@ -397,6 +414,17 @@ 2 + + + True + False + Day + + + 6 + 1 + + True @@ -419,39 +447,6 @@ 3 - - - True - False - Minute - - - 5 - 3 - - - - - True - False - Second - - - 6 - 3 - - - - - True - False - Timezone - - - 4 - 5 - - True @@ -463,6 +458,17 @@ 4 + + + True + False + Minute + + + 5 + 3 + + True @@ -474,6 +480,17 @@ 4 + + + True + False + Second + + + 6 + 3 + + True @@ -485,6 +502,17 @@ 4 + + + True + False + Timezone + + + 4 + 5 + + True @@ -498,34 +526,6 @@ 2 - - - True - True - edit-find-symbolic - False - False - - - 1 - 1 - 3 - - - - - True - True - edit-find-symbolic - False - False - - - 1 - 2 - 3 - - edit From 86e5438807282142f6d2681bd69eb1be8af543f5 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 9 Jul 2014 00:38:04 +0200 Subject: [PATCH 2/2] Add chart note support It is saved under /chartinfo/note, and may be non-existant or an empty tag. Fixes #28 --- src/ag-chart.c | 43 +++++++++++++++++++++++++++++++---- src/ag-chart.h | 2 ++ src/ag-window.c | 16 ++++++++++++- src/resources/ui/ag-window.ui | 35 ++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/ag-chart.c b/src/ag-chart.c index 0cf0a2e..1d985b5 100644 --- a/src/ag-chart.c +++ b/src/ag-chart.c @@ -17,6 +17,7 @@ struct _AgChartPrivate { gchar *city; gchar *save_buffer; GList *planet_list; + gchar *note; }; enum { @@ -425,6 +426,7 @@ ag_chart_load_from_file(GFile *file, GError **err) GVariant *minute; GVariant *second; GVariant *timezone; + GVariant *note; GsweTimestamp *timestamp; gboolean found_error = FALSE; @@ -505,7 +507,10 @@ ag_chart_load_from_file(GFile *file, GError **err) found_error = TRUE; } + note = get_by_xpath(xpath_context, uri, "/chartinfo/note/text()", FALSE, XML_CONVERT_STRING, err); + if (found_error) { + ag_g_variant_unref(note); ag_g_variant_unref(chart_name); ag_g_variant_unref(country); ag_g_variant_unref(city); @@ -565,6 +570,14 @@ ag_chart_load_from_file(GFile *file, GError **err) ag_chart_set_city(chart, city_name); g_free(city_name); + if (note) { + gchar *note_text; + + g_variant_get(note, "ms", ¬e_text); + g_variant_unref(note); + ag_chart_set_note(chart, note_text); + } + g_free(xml); g_free(uri); xmlXPathFreeContext(xpath_context); @@ -576,11 +589,11 @@ ag_chart_load_from_file(GFile *file, GError **err) static xmlDocPtr create_save_doc(AgChart *chart) { - xmlDocPtr doc = NULL; - xmlNodePtr root_node = NULL, - data_node = NULL, - place_node = NULL, - time_node = NULL; + xmlDocPtr doc = NULL; + xmlNodePtr root_node = NULL, + data_node = NULL, + place_node = NULL, + time_node = NULL; gchar *value; GsweCoordinates *coordinates; GsweTimestamp *timestamp; @@ -666,6 +679,10 @@ create_save_doc(AgChart *chart) xmlNewChild(time_node, NULL, BAD_CAST "timezone", BAD_CAST value); g_free(value); + if (ag_chart_get_note(chart)) { + xmlNewChild(root_node, NULL, BAD_CAST "note", BAD_CAST ag_chart_get_note(chart)); + } + return doc; } @@ -949,3 +966,19 @@ ag_chart_export_svg_to_file(AgChart *chart, GFile *file, GError **err) g_file_replace_contents(file, (const gchar *)svg, length, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, err); } + +void +ag_chart_set_note(AgChart *chart, const gchar *note) +{ + AgChartPrivate *priv = ag_chart_get_instance_private(chart); + + priv->note = g_strdup(note); +} + +const gchar *ag_chart_get_note(AgChart *chart) +{ + AgChartPrivate *priv = ag_chart_get_instance_private(chart); + + return priv->note; +} + diff --git a/src/ag-chart.h b/src/ag-chart.h index 833d574..be7efef 100644 --- a/src/ag-chart.h +++ b/src/ag-chart.h @@ -60,6 +60,8 @@ gchar *ag_chart_create_svg(AgChart *chart, gsize *length, GError **err); GList *ag_chart_get_planets(AgChart *chart); +void ag_chart_set_note(AgChart *chart, const gchar *note); +const gchar *ag_chart_get_note(AgChart *chart); #define AG_CHART_ERROR (ag_chart_error_quark()) GQuark ag_chart_error_quark(void); diff --git a/src/ag-window.c b/src/ag-window.c index 068aa65..08247b7 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -41,6 +41,7 @@ struct _AgWindowPrivate { AgChart *chart; gchar *uri; gboolean aspect_table_populated; + GtkTextBuffer *note_buffer; }; G_DEFINE_QUARK(ag_window_error_quark, ag_window_error); @@ -548,6 +549,11 @@ ag_window_update_from_chart(AgWindow *window) gtk_entry_set_text(GTK_ENTRY(priv->name), ag_chart_get_name(priv->chart)); + if (ag_chart_get_note(priv->chart)) { + // TODO: maybe setting length to -1 here is not that good of an idea… + gtk_text_buffer_set_text(GTK_TEXT_BUFFER(priv->note_buffer), ag_chart_get_note(priv->chart), -1); + } + g_free(coordinates); ag_window_redraw_chart(window); @@ -562,6 +568,10 @@ chart_changed(AgChart *chart, AgWindow *window) static void recalculate_chart(AgWindow *window) { + GsweTimestamp *timestamp; + GtkTextIter start_iter, + end_iter; + gchar *note; AgWindowPrivate *priv = ag_window_get_instance_private(window); gint year = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(priv->year)), month = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(priv->month)), @@ -573,7 +583,6 @@ recalculate_chart(AgWindow *window) latitude = gtk_spin_button_get_value(GTK_SPIN_BUTTON(priv->latitude)); gboolean south = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->south_lat)), west = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->west_long)); - GsweTimestamp *timestamp; g_debug("Recalculating chart data"); @@ -598,6 +607,10 @@ recalculate_chart(AgWindow *window) } ag_chart_set_name(priv->chart, gtk_entry_get_text(GTK_ENTRY(priv->name))); + gtk_text_buffer_get_bounds(priv->note_buffer, &start_iter, &end_iter); + note = gtk_text_buffer_get_text(priv->note_buffer, &start_iter, &end_iter, TRUE); + ag_chart_set_note(priv->chart, note); + g_free(note); } void @@ -749,6 +762,7 @@ ag_window_class_init(AgWindowClass *klass) gtk_widget_class_bind_template_child_private(widget_class, AgWindow, aspect_table); gtk_widget_class_bind_template_child_private(widget_class, AgWindow, year_adjust); gtk_widget_class_bind_template_child_private(widget_class, AgWindow, stack); + gtk_widget_class_bind_template_child_private(widget_class, AgWindow, note_buffer); } gboolean diff --git a/src/resources/ui/ag-window.ui b/src/resources/ui/ag-window.ui index 156af90..d7673a2 100644 --- a/src/resources/ui/ag-window.ui +++ b/src/resources/ui/ag-window.ui @@ -105,6 +105,8 @@ 1 10 + +