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 *
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;
}

View File

@ -3,6 +3,8 @@
#include <gtk/gtk.h>
#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

View File

@ -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;

View File

@ -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;