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 0b60206..d7673a2 100644
--- a/src/resources/ui/ag-window.ui
+++ b/src/resources/ui/ag-window.ui
@@ -105,6 +105,8 @@
1
10
+
False
False
@@ -219,6 +221,20 @@
1
+
+
+
+ 1
+ 2
+ 3
+
+
+
+
+
+ 1
+ 1
+ 3
+
+
-
-
-
- 6
- 1
-
-
+
+
+
+ 6
+ 1
+
+
-
-
-
- 5
- 3
-
-
-
-
-
- 6
- 3
-
-
-
-
-
- 4
- 5
-
-
+
+
+
+ 5
+ 3
+
+
+
+
+
+ 6
+ 3
+
+
+
+
+
+ 4
+ 5
+
+
-
-
+
+ 300
True
True
- edit-find-symbolic
- False
- False
+ in
+
+
+ True
+ True
+ note_buffer
+
+
- 1
- 2
- 3
+ 0
+ 7
+ 7