Merge pull request #37 from gergelypolonkai/configure-house-system
Make house system configurable
This commit is contained in:
commit
08df34c809
@ -35,7 +35,7 @@ PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.8])
|
|||||||
PKG_CHECK_MODULES([LIBXML], [libxml-2.0])
|
PKG_CHECK_MODULES([LIBXML], [libxml-2.0])
|
||||||
PKG_CHECK_MODULES([LIBXSLT], [libexslt])
|
PKG_CHECK_MODULES([LIBXSLT], [libexslt])
|
||||||
PKG_CHECK_MODULES([WEBKIT], [webkit2gtk-3.0])
|
PKG_CHECK_MODULES([WEBKIT], [webkit2gtk-3.0])
|
||||||
PKG_CHECK_MODULES([SWE_GLIB], [swe-glib >= 2.0.0])
|
PKG_CHECK_MODULES([SWE_GLIB], [swe-glib >= 2.1.0])
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
|
@ -18,5 +18,6 @@
|
|||||||
<second>45</second>
|
<second>45</second>
|
||||||
<timezone>1</timezone>
|
<timezone>1</timezone>
|
||||||
</time>
|
</time>
|
||||||
|
<housesystem>placidus</housesystem>
|
||||||
</data>
|
</data>
|
||||||
</chartinfo>
|
</chartinfo>
|
||||||
|
@ -565,7 +565,9 @@ ag_chart_load_from_file(GFile *file, GError **err)
|
|||||||
*xml = NULL,
|
*xml = NULL,
|
||||||
*name,
|
*name,
|
||||||
*country_name,
|
*country_name,
|
||||||
*city_name;
|
*city_name,
|
||||||
|
*house_system_name,
|
||||||
|
*house_system_enum_name;
|
||||||
gsize length;
|
gsize length;
|
||||||
xmlDocPtr doc;
|
xmlDocPtr doc;
|
||||||
xmlXPathContextPtr xpath_context;
|
xmlXPathContextPtr xpath_context;
|
||||||
@ -582,8 +584,11 @@ ag_chart_load_from_file(GFile *file, GError **err)
|
|||||||
*minute,
|
*minute,
|
||||||
*second,
|
*second,
|
||||||
*timezone,
|
*timezone,
|
||||||
*note;
|
*note,
|
||||||
|
*house_system;
|
||||||
GsweTimestamp *timestamp;
|
GsweTimestamp *timestamp;
|
||||||
|
GEnumClass *house_system_class;
|
||||||
|
GEnumValue *enum_value;
|
||||||
gboolean found_error = FALSE;
|
gboolean found_error = FALSE;
|
||||||
|
|
||||||
uri = g_file_get_uri(file);
|
uri = g_file_get_uri(file);
|
||||||
@ -765,6 +770,17 @@ ag_chart_load_from_file(GFile *file, GError **err)
|
|||||||
found_error = TRUE;
|
found_error = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((house_system = get_by_xpath(
|
||||||
|
xpath_context,
|
||||||
|
uri,
|
||||||
|
"/chartinfo/data/housesystem/text()",
|
||||||
|
TRUE,
|
||||||
|
XML_CONVERT_STRING,
|
||||||
|
err
|
||||||
|
)) == NULL) {
|
||||||
|
found_error = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
note = get_by_xpath(
|
note = get_by_xpath(
|
||||||
xpath_context,
|
xpath_context,
|
||||||
uri,
|
uri,
|
||||||
@ -775,6 +791,7 @@ ag_chart_load_from_file(GFile *file, GError **err)
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (found_error) {
|
if (found_error) {
|
||||||
|
ag_g_variant_unref(house_system);
|
||||||
ag_g_variant_unref(note);
|
ag_g_variant_unref(note);
|
||||||
ag_g_variant_unref(chart_name);
|
ag_g_variant_unref(chart_name);
|
||||||
ag_g_variant_unref(country);
|
ag_g_variant_unref(country);
|
||||||
@ -814,14 +831,47 @@ ag_chart_load_from_file(GFile *file, GError **err)
|
|||||||
g_variant_unref(second);
|
g_variant_unref(second);
|
||||||
g_variant_unref(timezone);
|
g_variant_unref(timezone);
|
||||||
|
|
||||||
// TODO: Make house system configurable (and saveable)
|
g_variant_get(house_system, "ms", &house_system_name);
|
||||||
|
g_variant_unref(house_system);
|
||||||
|
house_system_enum_name = g_utf8_strup(house_system_name, -1);
|
||||||
|
g_free(house_system_name);
|
||||||
|
house_system_name = house_system_enum_name;
|
||||||
|
house_system_enum_name = g_strdup_printf(
|
||||||
|
"GSWE_HOUSE_SYSTEM_%s",
|
||||||
|
house_system_name
|
||||||
|
);
|
||||||
|
g_free(house_system_name);
|
||||||
|
house_system_class = g_type_class_ref(GSWE_TYPE_HOUSE_SYSTEM);
|
||||||
|
if ((enum_value = g_enum_get_value_by_name(
|
||||||
|
G_ENUM_CLASS(house_system_class),
|
||||||
|
house_system_enum_name
|
||||||
|
)) == NULL) {
|
||||||
|
g_variant_unref(longitude);
|
||||||
|
g_variant_unref(latitude);
|
||||||
|
g_variant_unref(altitude);
|
||||||
|
g_variant_unref(chart_name);
|
||||||
|
g_variant_unref(country);
|
||||||
|
g_variant_unref(city);
|
||||||
|
ag_g_variant_unref(note);
|
||||||
|
g_type_class_unref(house_system_class);
|
||||||
|
|
||||||
|
g_set_error(err,
|
||||||
|
AG_CHART_ERROR, AG_CHART_ERROR_CORRUPT_FILE,
|
||||||
|
"Unknown house system in save file"
|
||||||
|
);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
chart = ag_chart_new_full(
|
chart = ag_chart_new_full(
|
||||||
timestamp,
|
timestamp,
|
||||||
g_variant_get_double(longitude),
|
g_variant_get_double(longitude),
|
||||||
g_variant_get_double(latitude),
|
g_variant_get_double(latitude),
|
||||||
g_variant_get_double(altitude),
|
g_variant_get_double(altitude),
|
||||||
GSWE_HOUSE_SYSTEM_PLACIDUS
|
enum_value->value
|
||||||
);
|
);
|
||||||
|
g_type_class_unref(house_system_class);
|
||||||
|
g_free(house_system_enum_name);
|
||||||
g_variant_unref(longitude);
|
g_variant_unref(longitude);
|
||||||
g_variant_unref(latitude);
|
g_variant_unref(latitude);
|
||||||
g_variant_unref(altitude);
|
g_variant_unref(altitude);
|
||||||
|
109
src/ag-window.c
109
src/ag-window.c
@ -29,6 +29,7 @@ struct _AgWindowPrivate {
|
|||||||
GtkWidget *minute;
|
GtkWidget *minute;
|
||||||
GtkWidget *second;
|
GtkWidget *second;
|
||||||
GtkWidget *timezone;
|
GtkWidget *timezone;
|
||||||
|
GtkWidget *house_system;
|
||||||
|
|
||||||
GtkWidget *tab_chart;
|
GtkWidget *tab_chart;
|
||||||
GtkWidget *tab_edit;
|
GtkWidget *tab_edit;
|
||||||
@ -43,6 +44,7 @@ struct _AgWindowPrivate {
|
|||||||
gchar *uri;
|
gchar *uri;
|
||||||
gboolean aspect_table_populated;
|
gboolean aspect_table_populated;
|
||||||
GtkTextBuffer *note_buffer;
|
GtkTextBuffer *note_buffer;
|
||||||
|
GtkListStore *house_system_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_QUARK(ag_window_error_quark, ag_window_error);
|
G_DEFINE_QUARK(ag_window_error_quark, ag_window_error);
|
||||||
@ -633,6 +635,34 @@ ag_window_redraw_chart(AgWindow *window)
|
|||||||
ag_window_redraw_aspect_table(window);
|
ag_window_redraw_aspect_table(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
ag_window_find_house_system(GtkTreeModel *model,
|
||||||
|
GtkTreePath *path,
|
||||||
|
GtkTreeIter *iter,
|
||||||
|
AgWindow *window)
|
||||||
|
{
|
||||||
|
GsweHouseSystem row_house_system;
|
||||||
|
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||||
|
GsweHouseSystem house_system = gswe_moment_get_house_system(
|
||||||
|
GSWE_MOMENT(priv->chart)
|
||||||
|
);
|
||||||
|
|
||||||
|
gtk_tree_model_get(
|
||||||
|
GTK_TREE_MODEL(priv->house_system_model),
|
||||||
|
iter,
|
||||||
|
0, &row_house_system,
|
||||||
|
-1
|
||||||
|
);
|
||||||
|
|
||||||
|
if (house_system == row_house_system) {
|
||||||
|
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(priv->house_system), iter);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ag_window_update_from_chart(AgWindow *window)
|
ag_window_update_from_chart(AgWindow *window)
|
||||||
{
|
{
|
||||||
@ -689,6 +719,12 @@ ag_window_update_from_chart(AgWindow *window)
|
|||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->south_lat), TRUE);
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->south_lat), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_tree_model_foreach(
|
||||||
|
GTK_TREE_MODEL(priv->house_system_model),
|
||||||
|
(GtkTreeModelForeachFunc)ag_window_find_house_system,
|
||||||
|
window
|
||||||
|
);
|
||||||
|
|
||||||
gtk_entry_set_text(GTK_ENTRY(priv->name), ag_chart_get_name(priv->chart));
|
gtk_entry_set_text(GTK_ENTRY(priv->name), ag_chart_get_name(priv->chart));
|
||||||
|
|
||||||
if (ag_chart_get_note(priv->chart)) {
|
if (ag_chart_get_note(priv->chart)) {
|
||||||
@ -717,6 +753,8 @@ recalculate_chart(AgWindow *window)
|
|||||||
GsweTimestamp *timestamp;
|
GsweTimestamp *timestamp;
|
||||||
GtkTextIter start_iter,
|
GtkTextIter start_iter,
|
||||||
end_iter;
|
end_iter;
|
||||||
|
GtkTreeIter house_system_iter;
|
||||||
|
GsweHouseSystem house_system;
|
||||||
gchar *note;
|
gchar *note;
|
||||||
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||||
gint year = gtk_spin_button_get_value_as_int(
|
gint year = gtk_spin_button_get_value_as_int(
|
||||||
@ -760,6 +798,29 @@ recalculate_chart(AgWindow *window)
|
|||||||
longitude = 0 - longitude;
|
longitude = 0 - longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!gtk_combo_box_get_active_iter(
|
||||||
|
GTK_COMBO_BOX(priv->house_system),
|
||||||
|
&house_system_iter
|
||||||
|
)) {
|
||||||
|
// TODO: a better approach must be made here. If there is an error, we
|
||||||
|
// cannot calculate the chart. If we are changing tabs, this should even
|
||||||
|
// prevent it!
|
||||||
|
ag_app_message_dialog(
|
||||||
|
GTK_WIDGET(window),
|
||||||
|
GTK_MESSAGE_ERROR,
|
||||||
|
"House system must be set!"
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_tree_model_get(
|
||||||
|
GTK_TREE_MODEL(priv->house_system_model),
|
||||||
|
&house_system_iter,
|
||||||
|
0, &house_system,
|
||||||
|
-1
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Set timezone according to the city selected!
|
// TODO: Set timezone according to the city selected!
|
||||||
if (priv->chart == NULL) {
|
if (priv->chart == NULL) {
|
||||||
timestamp = gswe_timestamp_new_from_gregorian_full(
|
timestamp = gswe_timestamp_new_from_gregorian_full(
|
||||||
@ -767,11 +828,10 @@ recalculate_chart(AgWindow *window)
|
|||||||
hour, minute, second, 0,
|
hour, minute, second, 0,
|
||||||
1.0
|
1.0
|
||||||
);
|
);
|
||||||
// TODO: make house system configurable
|
|
||||||
priv->chart = ag_chart_new_full(
|
priv->chart = ag_chart_new_full(
|
||||||
timestamp,
|
timestamp,
|
||||||
longitude, latitude, 380.0,
|
longitude, latitude, 380.0,
|
||||||
GSWE_HOUSE_SYSTEM_PLACIDUS
|
house_system
|
||||||
);
|
);
|
||||||
g_signal_connect(
|
g_signal_connect(
|
||||||
priv->chart,
|
priv->chart,
|
||||||
@ -781,6 +841,7 @@ recalculate_chart(AgWindow *window)
|
|||||||
);
|
);
|
||||||
ag_window_redraw_chart(window);
|
ag_window_redraw_chart(window);
|
||||||
} else {
|
} else {
|
||||||
|
gswe_moment_set_house_system(GSWE_MOMENT(priv->chart), house_system);
|
||||||
timestamp = gswe_moment_get_timestamp(GSWE_MOMENT(priv->chart));
|
timestamp = gswe_moment_get_timestamp(GSWE_MOMENT(priv->chart));
|
||||||
gswe_timestamp_set_gregorian_full(
|
gswe_timestamp_set_gregorian_full(
|
||||||
timestamp,
|
timestamp,
|
||||||
@ -871,11 +932,28 @@ ag_window_display_changed(GSettings *settings, gchar *key, AgWindow *window)
|
|||||||
ag_window_redraw_aspect_table(window);
|
ag_window_redraw_aspect_table(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ag_window_add_house_system(GsweHouseSystemInfo *house_system_info,
|
||||||
|
AgWindowPrivate *priv)
|
||||||
|
{
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
|
gtk_list_store_append(priv->house_system_model, &iter);
|
||||||
|
gtk_list_store_set(
|
||||||
|
priv->house_system_model, &iter,
|
||||||
|
0, gswe_house_system_info_get_house_system(house_system_info),
|
||||||
|
1, gswe_house_system_info_get_name(house_system_info),
|
||||||
|
-1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ag_window_init(AgWindow *window)
|
ag_window_init(AgWindow *window)
|
||||||
{
|
{
|
||||||
GtkAccelGroup *accel_group;
|
GtkAccelGroup *accel_group;
|
||||||
GSettings *main_settings;
|
GSettings *main_settings;
|
||||||
|
GList *house_system_list;
|
||||||
|
GtkCellRenderer *house_system_renderer;
|
||||||
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||||
|
|
||||||
gtk_widget_init_template(GTK_WIDGET(window));
|
gtk_widget_init_template(GTK_WIDGET(window));
|
||||||
@ -896,6 +974,23 @@ ag_window_init(AgWindow *window)
|
|||||||
window
|
window
|
||||||
);
|
);
|
||||||
|
|
||||||
|
house_system_list = gswe_all_house_systems();
|
||||||
|
g_list_foreach(house_system_list, (GFunc)ag_window_add_house_system, priv);
|
||||||
|
g_list_free(house_system_list);
|
||||||
|
|
||||||
|
house_system_renderer = gtk_cell_renderer_text_new();
|
||||||
|
gtk_cell_layout_pack_start(
|
||||||
|
GTK_CELL_LAYOUT(priv->house_system),
|
||||||
|
house_system_renderer,
|
||||||
|
TRUE
|
||||||
|
);
|
||||||
|
gtk_cell_layout_set_attributes(
|
||||||
|
GTK_CELL_LAYOUT(priv->house_system),
|
||||||
|
house_system_renderer,
|
||||||
|
"text", 1,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "edit");
|
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "edit");
|
||||||
priv->current_tab = priv->tab_edit;
|
priv->current_tab = priv->tab_edit;
|
||||||
g_object_set(
|
g_object_set(
|
||||||
@ -996,6 +1091,16 @@ ag_window_class_init(AgWindowClass *klass)
|
|||||||
AgWindow,
|
AgWindow,
|
||||||
longitude
|
longitude
|
||||||
);
|
);
|
||||||
|
gtk_widget_class_bind_template_child_private(
|
||||||
|
widget_class,
|
||||||
|
AgWindow,
|
||||||
|
house_system_model
|
||||||
|
);
|
||||||
|
gtk_widget_class_bind_template_child_private(
|
||||||
|
widget_class,
|
||||||
|
AgWindow,
|
||||||
|
house_system
|
||||||
|
);
|
||||||
gtk_widget_class_bind_template_child_private(
|
gtk_widget_class_bind_template_child_private(
|
||||||
widget_class,
|
widget_class,
|
||||||
AgWindow,
|
AgWindow,
|
||||||
|
@ -104,6 +104,14 @@
|
|||||||
<property name="step_increment">1</property>
|
<property name="step_increment">1</property>
|
||||||
<property name="page_increment">10</property>
|
<property name="page_increment">10</property>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="GtkListStore" id="house_system_model">
|
||||||
|
<columns>
|
||||||
|
<!-- column-name house-system-id -->
|
||||||
|
<column type="GsweHouseSystem"/>
|
||||||
|
<!-- column-name house-system-name -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
</columns>
|
||||||
|
</object>
|
||||||
<object class="GtkTextBuffer" id="note_buffer">
|
<object class="GtkTextBuffer" id="note_buffer">
|
||||||
</object>
|
</object>
|
||||||
<template class="AgWindow" parent="GtkApplicationWindow">
|
<template class="AgWindow" parent="GtkApplicationWindow">
|
||||||
@ -510,8 +518,8 @@
|
|||||||
<property name="label" translatable="yes" context="Chart edit, Timezone label">Timezone</property>
|
<property name="label" translatable="yes" context="Chart edit, Timezone label">Timezone</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">4</property>
|
<property name="left_attach">7</property>
|
||||||
<property name="top_attach">5</property>
|
<property name="top_attach">3</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@ -521,6 +529,29 @@
|
|||||||
<property name="adjustment">timezone_adjust</property>
|
<property name="adjustment">timezone_adjust</property>
|
||||||
<property name="digits">1</property>
|
<property name="digits">1</property>
|
||||||
</object>
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">7</property>
|
||||||
|
<property name="top_attach">4</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="house_system_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes" context="Chart edit, House system label">House system</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">4</property>
|
||||||
|
<property name="top_attach">5</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkComboBox" id="house_system">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="model">house_system_model</property>
|
||||||
|
<property name="id_column">0</property>
|
||||||
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">5</property>
|
<property name="left_attach">5</property>
|
||||||
<property name="top_attach">5</property>
|
<property name="top_attach">5</property>
|
||||||
|
Loading…
Reference in New Issue
Block a user