astrognome/src/astrognome.c

110 lines
2.3 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <glib.h>
#include <gtk/gtk.h>
2013-09-07 21:17:59 +00:00
#include <glib/gi18n.h>
#include <libgd/gd.h>
#include <swe-glib.h>
#include "ag-app.h"
#include "ag-window.h"
#define UI_FILE PKGDATADIR "/astrognome.ui"
GtkBuilder *builder;
static gboolean option_quit;
static gboolean option_version;
static GOptionEntry options[] = {
{ "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-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"
};
struct print_data {
GString *line;
GswePlanet planet;
};
static void
run_action(AgApp *app, gboolean is_remote)
{
if (option_quit) {
ag_app_quit(app);
} else if (is_remote) {
ag_app_raise(app);
}
}
2013-09-07 21:17:59 +00:00
static void
application_activate_cb(GtkApplication *app, gpointer user_data)
{
ag_app_new_window(AG_APP(app));
run_action(AG_APP(app), FALSE);
2013-09-07 21:17:59 +00:00
}
int
main(int argc, char *argv[])
{
gint status;
AgApp *app;
GError *err = NULL;
setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
2013-09-07 21:17:59 +00:00
gswe_init();
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);
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-09-07 21:17:59 +00:00
return status;
}