2013-09-08 11:39:44 +00:00
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
#include "ag-app.h"
|
2013-09-08 21:02:05 +00:00
|
|
|
#include "ag-window.h"
|
2013-09-08 11:39:44 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
struct _AgAppPrivate {
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(AgApp, ag_app, GTK_TYPE_APPLICATION);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
for (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)) {
|
|
|
|
return (GTK_WINDOW(l->data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-09-17 09:41:34 +00:00
|
|
|
window = ag_window_new(app);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
new_window_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
{
|
|
|
|
ag_app_create_window(AG_APP(user_data));
|
2013-09-08 11:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
preferences_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
{
|
|
|
|
//ag_preferences_show_dialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
const gchar **documentors = NULL;
|
|
|
|
const gchar *translator_credits = _("translator_credits");
|
|
|
|
|
|
|
|
/* i18n: Please don't translate "Astrognome" (it's marked as translatable for transliteration only */
|
|
|
|
gtk_show_about_dialog(NULL,
|
|
|
|
"name", _("Astrognome"),
|
|
|
|
"version", PACKAGE_VERSION,
|
|
|
|
"comments", _("Astrologers' software for GNOME"),
|
|
|
|
"authors", authors,
|
|
|
|
"documentors", documentors,
|
|
|
|
"translator_credits", ((strcmp(translator_credits, "translator_credits") != 0) ? translator_credits : NULL),
|
|
|
|
"website", PACKAGE_URL,
|
|
|
|
"website-label", _("Astrognome Website"),
|
|
|
|
"logo-icon-name", PACKAGE_TARNAME,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)))) {
|
|
|
|
gtk_application_remove_window(GTK_APPLICATION(user_data), GTK_WINDOW(l->data));
|
2013-09-08 11:39:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
raise_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
|
|
{
|
2013-09-17 09:41:34 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GActionEntry app_entries[] = {
|
|
|
|
{ "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 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-09-17 09:41:34 +00:00
|
|
|
setup_actions(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
{
|
2013-09-17 09:41:34 +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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-17 09:41:34 +00:00
|
|
|
setup_accelerators(AgApp *app)
|
2013-09-08 11:39:44 +00:00
|
|
|
{
|
2013-09-17 09:41:34 +00:00
|
|
|
gtk_application_add_accelerator(GTK_APPLICATION(app), "<Primary>w", "win.close", NULL);
|
|
|
|
gtk_application_add_accelerator(GTK_APPLICATION(app), "F10", "win.gear-menu", NULL);
|
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;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
builder = gtk_builder_new();
|
|
|
|
|
|
|
|
if (!gtk_builder_add_from_resource(builder, "/eu/polonkai/gergely/astrognome/astrognome.ui", &err)) {
|
|
|
|
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
|
|
|
|
ag_app_open(GApplication *gapp, GFile **files, gint n_files, const gchar *hint)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_files; i++) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-08 11:39:44 +00:00
|
|
|
AgApp *
|
|
|
|
ag_app_new(void)
|
|
|
|
{
|
|
|
|
AgApp *app;
|
|
|
|
|
|
|
|
/* i18n: Please don't translate "Astrognome" (it's marked as translatable for transliteration only */
|
|
|
|
g_set_application_name(_("Astrognome"));
|
|
|
|
|
|
|
|
app = g_object_new(AG_TYPE_APP,
|
|
|
|
"application-id", "eu.polonkai.gergely.Astrognome",
|
2013-09-17 11:28:07 +00:00
|
|
|
"flags", G_APPLICATION_HANDLES_OPEN,
|
2013-09-08 11:39:44 +00:00
|
|
|
"register-session", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
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;
|
2013-09-17 11:28:07 +00:00
|
|
|
application_class->open = ag_app_open;
|
2013-09-08 11:39:44 +00:00
|
|
|
}
|
|
|
|
|