From 8407ffadd3550628ad811ab740fa791a51b0b39c Mon Sep 17 00:00:00 2001 From: "Gergely POLONKAI (W00d5t0ck)" Date: Fri, 20 Sep 2013 10:23:02 +0200 Subject: [PATCH] Moved run_action() and application_activate_cb() to ag-app.c --- src/ag-app.c | 22 ++++++++++++++++++++++ src/ag-app.h | 3 +++ src/astrognome.c | 44 +++++++++----------------------------------- src/astrognome.h | 6 ++++++ 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/ag-app.c b/src/ag-app.c index 84eb597..b9d67df 100644 --- a/src/ag-app.c +++ b/src/ag-app.c @@ -241,6 +241,27 @@ ag_app_open(GApplication *gapp, GFile **files, gint n_files, const gchar *hint) } } +void +ag_app_run_action(AgApp *app, gboolean is_remote, const AstrognomeOptions *options) +{ + if (options && options->new_window) { + if (is_remote) { + ag_app_new_window(app); + } + } else if (options && options->quit) { + ag_app_quit(app); + } else if (is_remote) { // Keep this option the last one! + ag_app_raise(app); + } +} + +static void +application_activate_cb(AgApp *app, gpointer user_data) +{ + ag_app_new_window(app); + ag_app_run_action(app, FALSE, NULL); +} + AgApp * ag_app_new(void) { @@ -254,6 +275,7 @@ ag_app_new(void) "flags", G_APPLICATION_HANDLES_OPEN, "register-session", TRUE, NULL); + g_signal_connect(app, "activate", G_CALLBACK(application_activate_cb), NULL); return app; } diff --git a/src/ag-app.h b/src/ag-app.h index bc79b88..d8fd83a 100644 --- a/src/ag-app.h +++ b/src/ag-app.h @@ -3,6 +3,8 @@ #include +#include "astrognome.h" + G_BEGIN_DECLS #define AG_TYPE_APP (ag_app_get_type()) @@ -34,6 +36,7 @@ GtkWindow *ag_app_peek_first_window(AgApp *self); void ag_app_new_window(AgApp *self); void ag_app_quit(AgApp *self); void ag_app_raise(AgApp *self); +void ag_app_run_action(AgApp *app, gboolean is_remote, const AstrognomeOptions *options); G_END_DECLS diff --git a/src/astrognome.c b/src/astrognome.c index 60079fd..b7d154a 100644 --- a/src/astrognome.c +++ b/src/astrognome.c @@ -18,9 +18,6 @@ #define UI_FILE PKGDATADIR "/astrognome.ui" GtkBuilder *builder; -static gboolean option_version, - option_quit, - option_new_window; GtkFileFilter *filter_all = NULL, *filter_chart = NULL; @@ -36,27 +33,6 @@ const char *moonStateName[] = { "Dark Moon" }; -static void -run_action(AgApp *app, gboolean is_remote) -{ - if (option_new_window) { - if (is_remote) { - ag_app_new_window(app); - } - } else if (option_quit) { - ag_app_quit(app); - } else if (is_remote) { // Keep this option the last one! - ag_app_raise(app); - } -} - -static void -application_activate_cb(AgApp *app, gpointer user_data) -{ - ag_app_new_window(app); - run_action(app, FALSE); -} - void init_filters(void) { @@ -77,11 +53,12 @@ main(int argc, char *argv[]) gint status; AgApp *app; GError *err = NULL; + AstrognomeOptions options; - 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 }, + GOptionEntry option_entries[] = { + { "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 }, { NULL } }; @@ -99,17 +76,15 @@ main(int argc, char *argv[]) exsltRegisterAll(); gswe_init(); - option_version = FALSE, - option_quit = FALSE, - option_new_window = FALSE; + memset(&options, 0, sizeof(AstrognomeOptions)); - if (!gtk_init_with_args(&argc, &argv, _("[FILE…]"), options, GETTEXT_PACKAGE, &err)) { + if (!gtk_init_with_args(&argc, &argv, _("[FILE…]"), option_entries, GETTEXT_PACKAGE, &err)) { g_printerr("%s\n", err->message); return EXIT_FAILURE; } - if (option_version) { + if (options.version) { g_print("%s\n", PACKAGE_STRING); return EXIT_SUCCESS; @@ -118,7 +93,6 @@ main(int argc, char *argv[]) init_filters(); app = ag_app_new(); - 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)) { @@ -129,7 +103,7 @@ main(int argc, char *argv[]) } if (g_application_get_is_remote(G_APPLICATION(app))) { - run_action(app, TRUE); + ag_app_run_action(app, TRUE, (const AstrognomeOptions *)&options); g_object_unref(app); return EXIT_SUCCESS; diff --git a/src/astrognome.h b/src/astrognome.h index f935f30..d1d7309 100644 --- a/src/astrognome.h +++ b/src/astrognome.h @@ -1,6 +1,12 @@ #ifndef __ASTROGNOME_H__ #define __ASTROGNOME_H__ +typedef struct { + gboolean version; + gboolean quit; + gboolean new_window; +} AstrognomeOptions; + extern GtkFileFilter *filter_all, *filter_chart;