2013-09-08 11:39:44 +00:00
|
|
|
#include <stdlib.h>
|
2013-07-27 21:26:12 +00:00
|
|
|
#include <glib.h>
|
2013-09-03 16:10:12 +00:00
|
|
|
#include <gtk/gtk.h>
|
2013-09-07 21:17:59 +00:00
|
|
|
#include <glib/gi18n.h>
|
2013-09-17 16:33:16 +00:00
|
|
|
#include <libxml/xmlversion.h>
|
2013-09-19 15:26:52 +00:00
|
|
|
#include <libxml/parser.h>
|
2013-09-19 21:10:36 +00:00
|
|
|
#include <libxslt/xslt.h>
|
2013-09-20 07:58:31 +00:00
|
|
|
#include <libxslt/transform.h>
|
2013-09-19 15:26:52 +00:00
|
|
|
#include <libexslt/exslt.h>
|
2013-07-14 12:40:26 +00:00
|
|
|
|
2013-09-06 09:34:24 +00:00
|
|
|
#include <swe-glib.h>
|
2013-07-14 12:40:26 +00:00
|
|
|
|
2014-02-25 21:32:54 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
#include "ag-app.h"
|
2013-09-08 21:02:05 +00:00
|
|
|
#include "ag-window.h"
|
2013-09-08 11:39:44 +00:00
|
|
|
|
2013-09-21 16:37:27 +00:00
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkFileFilter *filter_all = NULL;
|
|
|
|
GtkFileFilter *filter_chart = NULL;
|
2014-08-07 22:41:43 +00:00
|
|
|
GtkFileFilter *filter_hor = NULL;
|
2014-07-12 08:27:11 +00:00
|
|
|
GHashTable *xinclude_positions;
|
2013-07-14 12:40:26 +00:00
|
|
|
|
2013-09-21 16:37:27 +00:00
|
|
|
const char *moonStateName[] = {
|
2013-07-26 14:53:08 +00:00
|
|
|
"New Moon",
|
|
|
|
"Waxing Crescent Moon",
|
|
|
|
"Waxing Half Moon",
|
|
|
|
"Waxing Gibbous Moon",
|
|
|
|
"Full Moon",
|
|
|
|
"Waning Gibbous Moon",
|
|
|
|
"Waning Half Moon",
|
|
|
|
"Waning Crescent Moon",
|
|
|
|
"Dark Moon"
|
|
|
|
};
|
|
|
|
|
2013-09-17 12:42:45 +00:00
|
|
|
void
|
|
|
|
init_filters(void)
|
|
|
|
{
|
|
|
|
filter_all = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(filter_all, _("All files"));
|
|
|
|
gtk_file_filter_add_pattern(filter_all, "*");
|
|
|
|
g_object_ref_sink(filter_all);
|
|
|
|
|
|
|
|
filter_chart = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(filter_chart, _("Astrognome charts"));
|
|
|
|
gtk_file_filter_add_pattern(filter_chart, "*.agc");
|
|
|
|
g_object_ref_sink(filter_chart);
|
2014-08-07 22:41:43 +00:00
|
|
|
|
|
|
|
filter_hor = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(filter_hor, _("Placidus charts"));
|
|
|
|
gtk_file_filter_add_pattern(filter_hor, "*.hor");
|
|
|
|
g_object_ref_sink(filter_hor);
|
2013-09-17 12:42:45 +00:00
|
|
|
}
|
|
|
|
|
2014-07-12 08:27:11 +00:00
|
|
|
static int
|
|
|
|
xml_match_gresource(const char *uri)
|
|
|
|
{
|
|
|
|
if ((uri != NULL) && (!strncmp("gres://", uri, 7))) {
|
|
|
|
g_debug("Matched gres:// type link.");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
xml_open_gresource(const gchar *uri)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
GBytes *res_location;
|
|
|
|
gsize *position;
|
|
|
|
|
|
|
|
if ((uri == NULL) || (strncmp("gres://", uri, 7))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = g_strdup_printf("/eu/polonkai/gergely/Astrognome/%s", uri + 7);
|
|
|
|
g_debug("Opening gresource %s", path);
|
|
|
|
|
|
|
|
res_location = g_resources_lookup_data(
|
|
|
|
path,
|
|
|
|
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
g_free(path);
|
|
|
|
|
2014-07-20 21:15:58 +00:00
|
|
|
if ((position = g_hash_table_lookup(
|
|
|
|
xinclude_positions,
|
|
|
|
res_location
|
|
|
|
)) == NULL) {
|
2014-07-12 08:27:11 +00:00
|
|
|
g_hash_table_insert(xinclude_positions, res_location, g_new0(gsize, 1));
|
|
|
|
} else {
|
|
|
|
g_warning("Reopening gres:// link?");
|
|
|
|
*position = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xml_close_gresource(void *context)
|
|
|
|
{
|
|
|
|
if (context == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_debug("Closing gres:// link");
|
|
|
|
|
|
|
|
g_hash_table_remove(xinclude_positions, context);
|
|
|
|
g_bytes_unref((GBytes *)context);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xml_read_gresource(void *context, char *buffer, int len)
|
|
|
|
{
|
|
|
|
const gchar *data;
|
|
|
|
gsize max_length;
|
|
|
|
GBytes *data_holder = (GBytes *)context;
|
|
|
|
gsize *position;
|
|
|
|
|
|
|
|
if ((context == NULL) || (buffer == NULL) || (len < 0)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = g_bytes_get_data(data_holder, &max_length);
|
|
|
|
position = g_hash_table_lookup(xinclude_positions, data_holder);
|
|
|
|
|
|
|
|
if (position == NULL) {
|
|
|
|
g_warning("Trying to read non-opened gres:// link!");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*position >= max_length) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > max_length - *position) {
|
|
|
|
len = max_length - *position;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, data + *position, len);
|
|
|
|
g_debug("Read %d bytes", len);
|
|
|
|
*position += len;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2014-08-03 22:31:25 +00:00
|
|
|
const gchar *
|
|
|
|
ag_house_system_id_to_nick(GsweHouseSystem house_system)
|
|
|
|
{
|
|
|
|
GEnumClass *house_system_class;
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
|
|
|
|
house_system_class = g_type_class_ref(GSWE_TYPE_HOUSE_SYSTEM);
|
|
|
|
enum_value = g_enum_get_value(house_system_class, house_system);
|
|
|
|
|
|
|
|
if (enum_value) {
|
|
|
|
return enum_value->value_nick;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GsweHouseSystem
|
|
|
|
ag_house_system_nick_to_id(const gchar *nick)
|
|
|
|
{
|
|
|
|
GEnumClass *house_system_class;
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
|
|
|
|
house_system_class = g_type_class_ref(GSWE_TYPE_HOUSE_SYSTEM);
|
|
|
|
enum_value = g_enum_get_value_by_nick(house_system_class, nick);
|
|
|
|
|
|
|
|
if (enum_value) {
|
|
|
|
return enum_value->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GSWE_HOUSE_SYSTEM_NONE;
|
|
|
|
}
|
|
|
|
|
2013-09-07 21:17:59 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2013-09-21 16:37:27 +00:00
|
|
|
gint status;
|
|
|
|
AgApp *app;
|
|
|
|
GError *err = NULL;
|
2013-09-20 08:23:02 +00:00
|
|
|
AstrognomeOptions options;
|
2013-09-08 11:39:44 +00:00
|
|
|
|
2013-09-21 16:37:27 +00:00
|
|
|
GOptionEntry option_entries[] = {
|
2014-07-11 08:33:04 +00:00
|
|
|
{
|
|
|
|
"new-window", 'n',
|
|
|
|
0, G_OPTION_ARG_NONE,
|
|
|
|
&(options.new_window),
|
|
|
|
N_("Opens a new Astrognome window"),
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"version", 'v',
|
|
|
|
0, G_OPTION_ARG_NONE,
|
|
|
|
&(options.version),
|
|
|
|
N_("Display version and exit"),
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"quit", 'q',
|
|
|
|
0, G_OPTION_ARG_NONE,
|
|
|
|
&(options.quit),
|
|
|
|
N_("Quit any running Astrognome"),
|
|
|
|
NULL
|
|
|
|
},
|
2013-09-17 10:39:23 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2013-09-17 07:32:16 +00:00
|
|
|
#ifdef ENABLE_NLS
|
2013-09-08 11:39:44 +00:00
|
|
|
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
|
|
|
|
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain(GETTEXT_PACKAGE);
|
2013-09-17 07:32:16 +00:00
|
|
|
#endif
|
2013-09-07 21:17:59 +00:00
|
|
|
|
2013-09-17 16:33:16 +00:00
|
|
|
LIBXML_TEST_VERSION;
|
2013-09-19 15:26:52 +00:00
|
|
|
xmlSubstituteEntitiesDefault(1);
|
|
|
|
xmlLoadExtDtdDefaultValue = 1;
|
2014-07-12 08:27:11 +00:00
|
|
|
xmlRegisterInputCallbacks(
|
|
|
|
xml_match_gresource,
|
|
|
|
xml_open_gresource,
|
|
|
|
xml_read_gresource,
|
|
|
|
xml_close_gresource
|
|
|
|
);
|
2013-09-19 21:10:36 +00:00
|
|
|
xsltInit();
|
2013-09-20 07:58:31 +00:00
|
|
|
xsltSetXIncludeDefault(1);
|
2013-09-19 15:26:52 +00:00
|
|
|
exsltRegisterAll();
|
2013-09-07 21:17:59 +00:00
|
|
|
gswe_init();
|
2014-07-12 08:27:11 +00:00
|
|
|
xinclude_positions = g_hash_table_new_full(
|
|
|
|
g_bytes_hash,
|
|
|
|
g_bytes_equal,
|
|
|
|
(GDestroyNotify)g_bytes_unref,
|
|
|
|
(GDestroyNotify)g_free
|
|
|
|
);
|
2013-09-07 21:17:59 +00:00
|
|
|
|
2013-09-20 08:23:02 +00:00
|
|
|
memset(&options, 0, sizeof(AstrognomeOptions));
|
2013-09-17 10:39:23 +00:00
|
|
|
|
2014-07-11 08:33:04 +00:00
|
|
|
if (!gtk_init_with_args(
|
|
|
|
&argc, &argv,
|
|
|
|
_("[FILE…]"
|
|
|
|
), option_entries, GETTEXT_PACKAGE, &err)) {
|
2013-09-08 11:39:44 +00:00
|
|
|
g_printerr("%s\n", err->message);
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-09-20 08:23:02 +00:00
|
|
|
if (options.version) {
|
2013-09-08 11:39:44 +00:00
|
|
|
g_print("%s\n", PACKAGE_STRING);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-09-17 12:42:45 +00:00
|
|
|
init_filters();
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
app = ag_app_new();
|
|
|
|
g_application_set_default(G_APPLICATION(app));
|
|
|
|
|
|
|
|
if (!g_application_register(G_APPLICATION(app), NULL, &err)) {
|
2014-07-11 08:33:04 +00:00
|
|
|
g_printerr(
|
|
|
|
"Couldn't register Astrognome instance: '%s'\n",
|
|
|
|
(err) ? err->message : ""
|
|
|
|
);
|
2013-09-08 11:39:44 +00:00
|
|
|
g_object_unref(app);
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_application_get_is_remote(G_APPLICATION(app))) {
|
2013-09-20 08:23:02 +00:00
|
|
|
ag_app_run_action(app, TRUE, (const AstrognomeOptions *)&options);
|
2013-09-08 11:39:44 +00:00
|
|
|
g_object_unref(app);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2013-09-07 21:17:59 +00:00
|
|
|
|
|
|
|
status = g_application_run(G_APPLICATION(app), argc, argv);
|
|
|
|
|
2014-07-12 08:27:11 +00:00
|
|
|
g_hash_table_destroy(xinclude_positions);
|
2013-09-07 21:17:59 +00:00
|
|
|
g_object_unref(app);
|
2013-08-19 21:36:54 +00:00
|
|
|
|
2013-09-07 21:17:59 +00:00
|
|
|
return status;
|
2013-07-14 12:40:26 +00:00
|
|
|
}
|