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-07-14 12:40:26 +00:00
|
|
|
|
2013-09-08 11:38:48 +00:00
|
|
|
#include <libgd/gd.h>
|
|
|
|
|
2013-09-06 09:34:24 +00:00
|
|
|
#include <swe-glib.h>
|
2013-07-14 12:40:26 +00:00
|
|
|
|
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-06 14:28:00 +00:00
|
|
|
#define UI_FILE PKGDATADIR "/astrognome.ui"
|
2013-09-03 16:10:12 +00:00
|
|
|
|
|
|
|
GtkBuilder *builder;
|
2013-09-17 10:39:23 +00:00
|
|
|
static gboolean option_version,
|
|
|
|
option_quit,
|
|
|
|
option_new_window;
|
2013-07-14 12:40:26 +00:00
|
|
|
|
2013-07-26 14:53:08 +00:00
|
|
|
const char *moonStateName[] = {
|
|
|
|
"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-08 11:39:44 +00:00
|
|
|
static void
|
|
|
|
run_action(AgApp *app, gboolean is_remote)
|
|
|
|
{
|
2013-09-17 07:32:51 +00:00
|
|
|
if (option_new_window) {
|
|
|
|
if (is_remote) {
|
|
|
|
ag_app_new_window(app);
|
|
|
|
}
|
|
|
|
} else if (option_quit) {
|
2013-09-08 11:39:44 +00:00
|
|
|
ag_app_quit(app);
|
2013-09-17 11:00:03 +00:00
|
|
|
} else if (is_remote) { // Keep this option the last one!
|
2013-09-08 11:39:44 +00:00
|
|
|
ag_app_raise(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-07 21:17:59 +00:00
|
|
|
static void
|
2013-09-17 10:54:33 +00:00
|
|
|
application_activate_cb(AgApp *app, gpointer user_data)
|
2013-09-03 16:10:12 +00:00
|
|
|
{
|
2013-09-17 10:54:33 +00:00
|
|
|
ag_app_new_window(app);
|
|
|
|
run_action(app, FALSE);
|
2013-09-07 21:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
gint status;
|
2013-09-08 11:39:44 +00:00
|
|
|
AgApp *app;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
2013-09-17 10:39:23 +00:00
|
|
|
GOptionEntry options[] = {
|
|
|
|
{ "new-window", 'n', 0, G_OPTION_ARG_NONE, &option_new_window, N_("Opens a new Astrognome window"), NULL },
|
|
|
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version, N_("Display version and exit"), NULL },
|
|
|
|
{ "quit", 'q', 0, G_OPTION_ARG_NONE, &option_quit, N_("Quit any running Astrognome"), NULL },
|
|
|
|
{ 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
|
|
|
|
|
|
|
gswe_init();
|
|
|
|
|
2013-09-17 10:39:23 +00:00
|
|
|
option_version = FALSE,
|
|
|
|
option_quit = FALSE,
|
|
|
|
option_new_window = FALSE;
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
if (!gtk_init_with_args(&argc, &argv, NULL, options, GETTEXT_PACKAGE, &err)) {
|
|
|
|
g_printerr("%s\n", err->message);
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option_version) {
|
|
|
|
g_print("%s\n", PACKAGE_STRING);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
app = ag_app_new();
|
2013-09-07 21:17:59 +00:00
|
|
|
g_signal_connect(app, "activate", G_CALLBACK(application_activate_cb), NULL);
|
2013-09-08 11:39:44 +00:00
|
|
|
g_application_set_default(G_APPLICATION(app));
|
|
|
|
|
|
|
|
if (!g_application_register(G_APPLICATION(app), NULL, &err)) {
|
|
|
|
g_printerr("Couldn't register Astrognome instance: '%s'\n", (err) ? err->message : "");
|
|
|
|
g_object_unref(app);
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_application_get_is_remote(G_APPLICATION(app))) {
|
|
|
|
run_action(app, TRUE);
|
|
|
|
g_object_unref(app);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2013-09-07 21:17:59 +00:00
|
|
|
|
|
|
|
status = g_application_run(G_APPLICATION(app), argc, argv);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|