2014-09-26 13:01:19 +00:00
|
|
|
|
/* ag-app.c - Application definition for Astrognome
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2014 Polonkai Gergely
|
|
|
|
|
*
|
|
|
|
|
* Astrognome is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published
|
|
|
|
|
* by the Free Software Foundation; either version 3 of the License,
|
|
|
|
|
* or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* Astrognome is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this software; if not, see
|
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2013-09-08 11:39:44 +00:00
|
|
|
|
#include <glib/gi18n.h>
|
2014-07-10 21:20:23 +00:00
|
|
|
|
#include <webkit2/webkit2.h>
|
|
|
|
|
|
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-17 20:24:26 +00:00
|
|
|
|
#include "ag-chart.h"
|
2013-09-21 19:54:35 +00:00
|
|
|
|
#include "ag-preferences.h"
|
2013-09-08 11:39:44 +00:00
|
|
|
|
#include "config.h"
|
2013-09-17 12:46:09 +00:00
|
|
|
|
#include "astrognome.h"
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
2014-09-04 22:22:04 +00:00
|
|
|
|
G_DEFINE_TYPE(AgApp, ag_app, GTK_TYPE_APPLICATION);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
|
|
|
|
GtkWindow *
|
2013-09-17 09:41:34 +00:00
|
|
|
|
ag_app_peek_first_window(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
|
2014-07-10 21:47:39 +00:00
|
|
|
|
for (
|
2014-07-12 09:06:46 +00:00
|
|
|
|
l = gtk_application_get_windows(GTK_APPLICATION(app));
|
|
|
|
|
l;
|
|
|
|
|
l = g_list_next(l)
|
|
|
|
|
) {
|
2013-09-08 11:39:44 +00:00
|
|
|
|
if (GTK_IS_WINDOW(l->data)) {
|
2013-09-21 16:37:27 +00:00
|
|
|
|
return GTK_WINDOW(l->data);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
|
ag_app_new_window(app);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
|
return ag_app_peek_first_window(app);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
ag_app_new_window(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
2013-09-17 09:41:34 +00:00
|
|
|
|
g_action_group_activate_action(G_ACTION_GROUP(app), "new-window", NULL);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
ag_app_quit(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
2013-09-17 09:41:34 +00:00
|
|
|
|
g_action_group_activate_action(G_ACTION_GROUP(app), "quit", NULL);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
ag_app_raise(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
2013-09-17 09:41:34 +00:00
|
|
|
|
g_action_group_activate_action(G_ACTION_GROUP(app), "raise", NULL);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 11:26:16 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
ag_app_create_window(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *window;
|
|
|
|
|
|
2014-09-04 22:22:04 +00:00
|
|
|
|
window = ag_window_new(app);
|
2013-09-17 09:41:34 +00:00
|
|
|
|
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(window));
|
2013-09-08 11:39:44 +00:00
|
|
|
|
gtk_widget_show_all(window);
|
2013-09-17 11:26:16 +00:00
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 11:23:19 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
ag_app_get_usable_window(AgApp *app)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *window;
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
// Favour current window
|
|
|
|
|
window = GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(app)));
|
|
|
|
|
|
|
|
|
|
if (AG_IS_WINDOW(window) && ag_window_is_usable(AG_WINDOW(window))) {
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise, let’s use the first existing, usable window
|
|
|
|
|
for (
|
|
|
|
|
l = gtk_application_get_windows(GTK_APPLICATION(app));
|
|
|
|
|
l;
|
|
|
|
|
l = g_list_next(l)
|
|
|
|
|
) {
|
|
|
|
|
if (AG_IS_WINDOW(l->data) && ag_window_is_usable(AG_WINDOW(l->data))) {
|
|
|
|
|
return l->data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we are still here, no usable windows were found. Let’s create one
|
|
|
|
|
window = ag_app_create_window(app);
|
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 11:26:16 +00:00
|
|
|
|
static void
|
|
|
|
|
new_window_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
|
{
|
2014-07-22 10:31:41 +00:00
|
|
|
|
AgWindow *window = AG_WINDOW(ag_app_create_window(AG_APP(user_data)));
|
|
|
|
|
|
2014-07-30 22:47:37 +00:00
|
|
|
|
ag_window_load_chart_list(window);
|
2014-07-22 10:31:41 +00:00
|
|
|
|
ag_window_change_tab(window, "list");
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
preferences_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
|
{
|
2014-06-30 20:51:15 +00:00
|
|
|
|
AgApp *app = AG_APP(user_data);
|
|
|
|
|
|
2014-09-02 07:41:55 +00:00
|
|
|
|
ag_preferences_show_dialog(
|
|
|
|
|
gtk_application_get_active_window(GTK_APPLICATION(app))
|
|
|
|
|
);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
about_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
const gchar *authors[] = {
|
|
|
|
|
"Gergely Polonkai <gergely@polonkai.eu>",
|
|
|
|
|
"Jean-André Santoni <jean.andre.santoni@gmail.com>",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2014-07-12 09:07:33 +00:00
|
|
|
|
const gchar *artists[] = {
|
|
|
|
|
"Ákos Szimmer <akos.szimmer@gmail.com>",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2013-09-08 11:39:44 +00:00
|
|
|
|
const gchar *translator_credits = _("translator_credits");
|
2014-09-02 07:41:55 +00:00
|
|
|
|
AgApp *app = AG_APP(user_data);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
2014-07-10 21:47:39 +00:00
|
|
|
|
/* i18n: Please don't translate "Astrognome" (it's marked as translatable
|
|
|
|
|
* for transliteration only */
|
2014-09-02 07:41:55 +00:00
|
|
|
|
gtk_show_about_dialog(
|
|
|
|
|
gtk_application_get_active_window(GTK_APPLICATION(app)),
|
|
|
|
|
"name", _("Astrognome"),
|
|
|
|
|
"version", PACKAGE_VERSION,
|
|
|
|
|
"comments", _("Astrologers' software for GNOME"),
|
|
|
|
|
"authors", authors,
|
|
|
|
|
"artists", artists,
|
|
|
|
|
"translator_credits", ((strcmp(
|
|
|
|
|
translator_credits,
|
|
|
|
|
"translator_credits"
|
|
|
|
|
) != 0)
|
|
|
|
|
? translator_credits
|
|
|
|
|
: NULL),
|
|
|
|
|
"website", PACKAGE_URL,
|
|
|
|
|
"website-label", _("Astrognome Website"),
|
|
|
|
|
"license-type", GTK_LICENSE_GPL_3_0,
|
|
|
|
|
"logo-icon-name", PACKAGE_TARNAME,
|
|
|
|
|
NULL
|
|
|
|
|
);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
|
while ((l = gtk_application_get_windows(GTK_APPLICATION(user_data)))) {
|
2014-07-10 21:47:39 +00:00
|
|
|
|
gtk_application_remove_window(
|
|
|
|
|
GTK_APPLICATION(user_data),
|
|
|
|
|
GTK_WINDOW(l->data)
|
|
|
|
|
);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 12:52:12 +00:00
|
|
|
|
static void
|
2014-08-10 08:15:04 +00:00
|
|
|
|
ag_app_import_file(AgApp *app, GFile *file, AgAppImportType type)
|
2013-09-17 12:52:12 +00:00
|
|
|
|
{
|
2013-09-17 20:24:26 +00:00
|
|
|
|
GtkWidget *window;
|
2013-09-21 16:37:27 +00:00
|
|
|
|
AgChart *chart;
|
|
|
|
|
GError *err = NULL;
|
2013-09-17 20:24:26 +00:00
|
|
|
|
|
2014-08-10 08:15:04 +00:00
|
|
|
|
switch (type) {
|
|
|
|
|
case AG_APP_IMPORT_AGC:
|
|
|
|
|
chart = ag_chart_load_from_agc(file, &err);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2014-08-10 11:54:51 +00:00
|
|
|
|
case AG_APP_IMPORT_HOR:
|
|
|
|
|
chart = ag_chart_load_from_placidus_file(file, &err);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2014-08-10 08:15:04 +00:00
|
|
|
|
default:
|
|
|
|
|
g_error("Unknown import type!");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (chart == NULL) {
|
|
|
|
|
ag_app_message_dialog(
|
2014-09-02 07:41:55 +00:00
|
|
|
|
gtk_application_get_active_window(GTK_APPLICATION(app)),
|
2014-08-10 08:15:04 +00:00
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
|
"Error while loading: %s",
|
|
|
|
|
err->message
|
|
|
|
|
);
|
2013-10-03 22:16:55 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 11:23:19 +00:00
|
|
|
|
window = ag_app_get_usable_window(app);
|
2013-09-17 20:24:26 +00:00
|
|
|
|
ag_window_set_chart(AG_WINDOW(window), chart);
|
|
|
|
|
ag_window_update_from_chart(AG_WINDOW(window));
|
2014-08-03 09:03:23 +00:00
|
|
|
|
g_action_group_activate_action(G_ACTION_GROUP(window), "save", NULL);
|
2014-07-03 12:08:51 +00:00
|
|
|
|
ag_window_change_tab(AG_WINDOW(window), "chart");
|
2014-09-21 11:23:19 +00:00
|
|
|
|
gtk_window_present(GTK_WINDOW(window));
|
2013-09-17 12:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 11:58:49 +00:00
|
|
|
|
static void
|
2014-08-01 23:41:33 +00:00
|
|
|
|
ag_app_import_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
2013-09-17 11:58:49 +00:00
|
|
|
|
{
|
2014-08-10 08:15:04 +00:00
|
|
|
|
gint response;
|
|
|
|
|
GtkWidget *fs;
|
|
|
|
|
GtkFileFilter *filter;
|
|
|
|
|
GSList *filenames = NULL;
|
|
|
|
|
const gchar *target_type = g_variant_get_string(parameter, NULL);
|
|
|
|
|
AgAppImportType type = AG_APP_IMPORT_NONE;
|
2014-09-02 07:41:55 +00:00
|
|
|
|
AgApp *app = AG_APP(user_data);
|
2014-08-10 08:15:04 +00:00
|
|
|
|
|
|
|
|
|
if (strncmp("agc", target_type, 3) == 0) {
|
|
|
|
|
type = AG_APP_IMPORT_AGC;
|
|
|
|
|
filter = filter_chart;
|
2014-08-10 11:54:51 +00:00
|
|
|
|
} else if (strncmp("hor", target_type, 3) == 0) {
|
|
|
|
|
type = AG_APP_IMPORT_HOR;
|
|
|
|
|
filter = filter_hor;
|
2014-08-10 08:15:04 +00:00
|
|
|
|
} else {
|
|
|
|
|
g_error("Unknown import type!");
|
|
|
|
|
}
|
2013-09-17 12:46:09 +00:00
|
|
|
|
|
2014-09-02 07:41:55 +00:00
|
|
|
|
fs = gtk_file_chooser_dialog_new(
|
|
|
|
|
_("Select charts"),
|
|
|
|
|
gtk_application_get_active_window(GTK_APPLICATION(app)),
|
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
|
_("_Import"), GTK_RESPONSE_ACCEPT,
|
|
|
|
|
NULL
|
|
|
|
|
);
|
2013-09-17 12:46:09 +00:00
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter_all);
|
2014-08-10 08:15:04 +00:00
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter);
|
|
|
|
|
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs), filter);
|
2013-09-17 12:46:09 +00:00
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(fs), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(fs), TRUE);
|
|
|
|
|
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(fs), FALSE);
|
|
|
|
|
|
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(fs));
|
|
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT) {
|
|
|
|
|
filenames = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(fs));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filenames != NULL) {
|
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
|
|
for (l = filenames; l; l = g_slist_next(l)) {
|
|
|
|
|
GFile *file;
|
2013-09-21 16:37:27 +00:00
|
|
|
|
char *data = l->data;
|
2013-09-17 12:46:09 +00:00
|
|
|
|
|
|
|
|
|
if (data == NULL) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file = g_file_new_for_commandline_arg(data);
|
2014-08-10 08:15:04 +00:00
|
|
|
|
ag_app_import_file(AG_APP(user_data), file, type);
|
2013-09-17 12:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_widget_destroy(fs);
|
2013-09-17 11:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
|
static void
|
|
|
|
|
raise_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
|
{
|
2013-09-21 16:37:27 +00:00
|
|
|
|
AgApp *app = AG_APP(user_data);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
GtkWindow *window;
|
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
|
window = ag_app_peek_first_window(app);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
gtk_window_present(window);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 11:51:21 +00:00
|
|
|
|
static void
|
|
|
|
|
show_help(const gchar *topic, GtkWindow *parent)
|
|
|
|
|
{
|
|
|
|
|
gchar *uri;
|
|
|
|
|
GdkScreen *screen;
|
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
|
|
if (topic) {
|
|
|
|
|
uri = g_strdup_printf("help:astrognome/%s", topic);
|
|
|
|
|
} else {
|
|
|
|
|
uri = g_strdup("help:astrognome");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
|
screen = gtk_widget_get_screen(GTK_WIDGET(parent));
|
|
|
|
|
} else {
|
|
|
|
|
screen = gdk_screen_get_default();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!gtk_show_uri(screen, uri, gtk_get_current_event_time(), &err)) {
|
2014-07-10 22:34:12 +00:00
|
|
|
|
ag_app_message_dialog(
|
2014-09-02 07:41:55 +00:00
|
|
|
|
GTK_WINDOW(parent),
|
2014-07-10 21:47:39 +00:00
|
|
|
|
GTK_MESSAGE_WARNING,
|
|
|
|
|
"Unable to display help: %s",
|
|
|
|
|
err->message
|
|
|
|
|
);
|
2013-09-22 11:51:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
help_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
show_help(NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
|
static GActionEntry app_entries[] = {
|
2014-08-01 23:41:33 +00:00
|
|
|
|
{ "new-window", new_window_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "preferences", preferences_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "about", about_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "quit", quit_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "raise", raise_cb, NULL, NULL, NULL },
|
2014-08-10 08:15:04 +00:00
|
|
|
|
{ "import", ag_app_import_cb, "s", NULL, NULL },
|
2014-08-01 23:41:33 +00:00
|
|
|
|
{ "help", help_cb, NULL, NULL, NULL },
|
2013-09-08 11:39:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
setup_actions(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
2014-07-10 21:47:39 +00:00
|
|
|
|
g_action_map_add_action_entries(
|
|
|
|
|
G_ACTION_MAP(app),
|
|
|
|
|
app_entries,
|
|
|
|
|
G_N_ELEMENTS(app_entries),
|
|
|
|
|
app
|
|
|
|
|
);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-03 21:32:17 +00:00
|
|
|
|
const gchar *action_accels[] = {
|
2014-08-20 22:51:10 +00:00
|
|
|
|
"win.close", "<Primary>W", NULL,
|
|
|
|
|
"win.save", "<Primary>S", NULL,
|
|
|
|
|
"win.export", "<Primary><Shift>E", NULL,
|
|
|
|
|
"win.gear-menu", "F10", NULL,
|
|
|
|
|
"app.help", "F1", NULL,
|
|
|
|
|
"win.change-tab::chart", "F5", NULL,
|
2014-09-02 08:16:30 +00:00
|
|
|
|
"win.change-tab::aspects", "F6", NULL,
|
|
|
|
|
"win.change-tab::points", "F7", NULL,
|
2014-08-26 20:14:32 +00:00
|
|
|
|
"win.change-tab::edit", "F4", NULL,
|
2014-09-04 13:25:05 +00:00
|
|
|
|
"win.back", "<Alt>Left", "Back", NULL,
|
2014-08-03 21:32:17 +00:00
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
|
static void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
setup_accelerators(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
2014-08-03 21:32:17 +00:00
|
|
|
|
const char **it;
|
|
|
|
|
|
|
|
|
|
for (it = action_accels; it[0]; it += g_strv_length((gchar **)it) + 1) {
|
|
|
|
|
gtk_application_set_accels_for_action(
|
|
|
|
|
GTK_APPLICATION(app),
|
|
|
|
|
it[0],
|
|
|
|
|
&it[1]
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
setup_menu(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkBuilder *builder;
|
|
|
|
|
GMenuModel *model;
|
2013-09-21 16:37:27 +00:00
|
|
|
|
GError *err = NULL;
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
|
|
|
|
builder = gtk_builder_new();
|
|
|
|
|
|
2014-07-10 21:47:39 +00:00
|
|
|
|
if (!gtk_builder_add_from_resource(
|
|
|
|
|
builder,
|
|
|
|
|
"/eu/polonkai/gergely/Astrognome/ui/astrognome.ui",
|
|
|
|
|
&err
|
|
|
|
|
)) {
|
2013-09-08 11:39:44 +00:00
|
|
|
|
g_error("%s", (err) ? err->message : "unknown error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model = G_MENU_MODEL(gtk_builder_get_object(builder, "app-menu"));
|
2013-09-17 09:41:34 +00:00
|
|
|
|
gtk_application_set_app_menu(GTK_APPLICATION(app), model);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref(builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
startup(GApplication *gapp)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
2013-09-17 09:41:34 +00:00
|
|
|
|
AgApp *app = AG_APP(gapp);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
|
G_APPLICATION_CLASS(ag_app_parent_class)->startup(gapp);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
|
setup_actions(app);
|
|
|
|
|
setup_menu(app);
|
|
|
|
|
setup_accelerators(app);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 11:28:07 +00:00
|
|
|
|
static void
|
2014-08-01 23:41:33 +00:00
|
|
|
|
ag_app_import(GApplication *gapp,
|
|
|
|
|
GFile **files,
|
|
|
|
|
gint n_files,
|
|
|
|
|
const gchar *hint)
|
2013-09-17 11:28:07 +00:00
|
|
|
|
{
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_files; i++) {
|
2014-08-10 08:15:04 +00:00
|
|
|
|
ag_app_import_file(AG_APP(gapp), files[i], AG_APP_IMPORT_AGC);
|
2013-09-17 11:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 08:23:02 +00:00
|
|
|
|
void
|
2014-07-10 21:47:39 +00:00
|
|
|
|
ag_app_run_action(AgApp *app,
|
|
|
|
|
gboolean is_remote,
|
|
|
|
|
const AstrognomeOptions *options)
|
2013-09-20 08:23:02 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
|
AgApp *
|
|
|
|
|
ag_app_new(void)
|
|
|
|
|
{
|
|
|
|
|
AgApp *app;
|
|
|
|
|
|
2014-07-10 21:47:39 +00:00
|
|
|
|
/* i18n: Please don't translate "Astrognome" (it's marked as translatable
|
|
|
|
|
* for transliteration only */
|
2013-09-08 11:39:44 +00:00
|
|
|
|
g_set_application_name(_("Astrognome"));
|
|
|
|
|
|
|
|
|
|
app = g_object_new(AG_TYPE_APP,
|
2013-09-21 16:37:27 +00:00
|
|
|
|
"application-id", "eu.polonkai.gergely.Astrognome",
|
|
|
|
|
"flags", G_APPLICATION_HANDLES_OPEN,
|
|
|
|
|
"register-session", TRUE,
|
|
|
|
|
NULL);
|
2014-07-10 21:47:39 +00:00
|
|
|
|
g_signal_connect(
|
|
|
|
|
app,
|
|
|
|
|
"activate",
|
|
|
|
|
G_CALLBACK(application_activate_cb),
|
|
|
|
|
NULL
|
|
|
|
|
);
|
2013-09-08 11:39:44 +00:00
|
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-17 09:41:34 +00:00
|
|
|
|
ag_app_init(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ag_app_class_init(AgAppClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
|
|
|
|
|
|
|
|
|
|
application_class->startup = startup;
|
2014-08-01 23:41:33 +00:00
|
|
|
|
application_class->open = ag_app_import;
|
2013-09-08 11:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 07:41:55 +00:00
|
|
|
|
GtkResponseType
|
|
|
|
|
ag_app_buttoned_dialog(GtkWindow *window,
|
2014-08-01 22:34:07 +00:00
|
|
|
|
GtkMessageType message_type,
|
|
|
|
|
const gchar *message,
|
|
|
|
|
const gchar *first_button_text,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
const gchar *button_text;
|
|
|
|
|
gint response_id;
|
|
|
|
|
GtkWidget *dialog;
|
2014-08-07 22:42:24 +00:00
|
|
|
|
|
2014-09-02 07:41:55 +00:00
|
|
|
|
g_return_val_if_fail(GTK_IS_WINDOW(window), GTK_RESPONSE_NONE);
|
2014-08-01 22:34:07 +00:00
|
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new(
|
2014-09-06 09:01:46 +00:00
|
|
|
|
window,
|
2014-08-01 22:34:07 +00:00
|
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
|
message_type,
|
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
|
"%s",
|
|
|
|
|
message
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (first_button_text) {
|
|
|
|
|
button_text = first_button_text;
|
|
|
|
|
|
|
|
|
|
va_start(ap, first_button_text);
|
|
|
|
|
response_id = va_arg(ap, gint);
|
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(dialog), button_text, response_id);
|
|
|
|
|
|
|
|
|
|
while ((button_text = va_arg(ap, gchar *)) != NULL) {
|
|
|
|
|
response_id = va_arg(ap, gint);
|
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(dialog), button_text, response_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response_id = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
|
|
|
|
|
|
return response_id;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 20:31:59 +00:00
|
|
|
|
void
|
2014-09-02 07:41:55 +00:00
|
|
|
|
ag_app_message_dialog(GtkWindow *window,
|
2014-07-10 21:47:39 +00:00
|
|
|
|
GtkMessageType message_type,
|
|
|
|
|
gchar *fmt, ...)
|
2014-07-04 20:31:59 +00:00
|
|
|
|
{
|
|
|
|
|
gchar *msg;
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
msg = g_strdup_vprintf(fmt, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
2014-08-01 22:34:07 +00:00
|
|
|
|
ag_app_buttoned_dialog(
|
|
|
|
|
window,
|
2014-07-10 21:47:39 +00:00
|
|
|
|
message_type,
|
2014-08-01 22:34:07 +00:00
|
|
|
|
msg,
|
|
|
|
|
_("Close"), GTK_RESPONSE_CLOSE,
|
|
|
|
|
NULL
|
2014-07-10 21:47:39 +00:00
|
|
|
|
);
|
2014-08-01 22:34:07 +00:00
|
|
|
|
|
2014-07-04 20:31:59 +00:00
|
|
|
|
g_free(msg);
|
|
|
|
|
}
|