Moved run_action() and application_activate_cb() to ag-app.c

This commit is contained in:
Gergely Polonkai 2013-09-20 10:23:02 +02:00
parent 5beb08b500
commit 8407ffadd3
4 changed files with 40 additions and 35 deletions

View File

@ -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 * AgApp *
ag_app_new(void) ag_app_new(void)
{ {
@ -254,6 +275,7 @@ ag_app_new(void)
"flags", G_APPLICATION_HANDLES_OPEN, "flags", G_APPLICATION_HANDLES_OPEN,
"register-session", TRUE, "register-session", TRUE,
NULL); NULL);
g_signal_connect(app, "activate", G_CALLBACK(application_activate_cb), NULL);
return app; return app;
} }

View File

@ -3,6 +3,8 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "astrognome.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define AG_TYPE_APP (ag_app_get_type()) #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_new_window(AgApp *self);
void ag_app_quit(AgApp *self); void ag_app_quit(AgApp *self);
void ag_app_raise(AgApp *self); void ag_app_raise(AgApp *self);
void ag_app_run_action(AgApp *app, gboolean is_remote, const AstrognomeOptions *options);
G_END_DECLS G_END_DECLS

View File

@ -18,9 +18,6 @@
#define UI_FILE PKGDATADIR "/astrognome.ui" #define UI_FILE PKGDATADIR "/astrognome.ui"
GtkBuilder *builder; GtkBuilder *builder;
static gboolean option_version,
option_quit,
option_new_window;
GtkFileFilter *filter_all = NULL, GtkFileFilter *filter_all = NULL,
*filter_chart = NULL; *filter_chart = NULL;
@ -36,27 +33,6 @@ const char *moonStateName[] = {
"Dark Moon" "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 void
init_filters(void) init_filters(void)
{ {
@ -77,11 +53,12 @@ main(int argc, char *argv[])
gint status; gint status;
AgApp *app; AgApp *app;
GError *err = NULL; GError *err = NULL;
AstrognomeOptions options;
GOptionEntry options[] = { GOptionEntry option_entries[] = {
{ "new-window", 'n', 0, G_OPTION_ARG_NONE, &option_new_window, N_("Opens a new Astrognome window"), NULL }, { "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, &option_version, N_("Display version and exit"), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &(options.version), N_("Display version and exit"), NULL },
{ "quit", 'q', 0, G_OPTION_ARG_NONE, &option_quit, N_("Quit any running Astrognome"), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &(options.quit), N_("Quit any running Astrognome"), NULL },
{ NULL } { NULL }
}; };
@ -99,17 +76,15 @@ main(int argc, char *argv[])
exsltRegisterAll(); exsltRegisterAll();
gswe_init(); gswe_init();
option_version = FALSE, memset(&options, 0, sizeof(AstrognomeOptions));
option_quit = FALSE,
option_new_window = FALSE;
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); g_printerr("%s\n", err->message);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (option_version) { if (options.version) {
g_print("%s\n", PACKAGE_STRING); g_print("%s\n", PACKAGE_STRING);
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -118,7 +93,6 @@ main(int argc, char *argv[])
init_filters(); init_filters();
app = ag_app_new(); app = ag_app_new();
g_signal_connect(app, "activate", G_CALLBACK(application_activate_cb), NULL);
g_application_set_default(G_APPLICATION(app)); g_application_set_default(G_APPLICATION(app));
if (!g_application_register(G_APPLICATION(app), NULL, &err)) { 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))) { 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); g_object_unref(app);
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -1,6 +1,12 @@
#ifndef __ASTROGNOME_H__ #ifndef __ASTROGNOME_H__
#define __ASTROGNOME_H__ #define __ASTROGNOME_H__
typedef struct {
gboolean version;
gboolean quit;
gboolean new_window;
} AstrognomeOptions;
extern GtkFileFilter *filter_all, extern GtkFileFilter *filter_all,
*filter_chart; *filter_chart;