aboutsummaryrefslogtreecommitdiff
path: root/src/uplanfahr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uplanfahr.c')
-rw-r--r--src/uplanfahr.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/uplanfahr.c b/src/uplanfahr.c
new file mode 100644
index 0000000..e87d25e
--- /dev/null
+++ b/src/uplanfahr.c
@@ -0,0 +1,117 @@
+#include <gtk/gtk.h>
+
+#include "uplanfahr.h"
+#include "uplanfahrwin.h"
+#include "uplanfahrprefs.h"
+
+struct _UPlanFahr
+{
+ GtkApplication parent;
+};
+
+struct _UPlanFahrClass
+{
+ GtkApplicationClass parent_class;
+};
+
+G_DEFINE_TYPE(UPlanFahr, u_plan_fahr, GTK_TYPE_APPLICATION);
+
+static void
+u_plan_fahr_init (UPlanFahr *app)
+{
+}
+
+static void
+preferences_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer app)
+{
+ UPlanFahrPrefs *prefs;
+ GtkWindow *win;
+
+ win = gtk_application_get_active_window (GTK_APPLICATION (app));
+ prefs = u_plan_fahr_prefs_new (U_PLAN_FAHR_WINDOW (win));
+ gtk_window_present (GTK_WINDOW (prefs));
+}
+
+static void
+quit_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer app)
+{
+ g_application_quit (G_APPLICATION (app));
+}
+
+static GActionEntry app_entries[] =
+{
+ { "preferences", preferences_activated, NULL, NULL, NULL, {0, 0, 0} },
+ { "quit", quit_activated, NULL, NULL, NULL, {0, 0, 0} }
+};
+
+static void
+u_plan_fahr_startup (GApplication *app)
+{
+ GtkBuilder *builder;
+ GMenuModel *app_menu;
+
+ G_APPLICATION_CLASS (u_plan_fahr_parent_class)->startup (app);
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ app_entries, G_N_ELEMENTS (app_entries),
+ app);
+
+ builder = gtk_builder_new_from_resource ("/org/sigxcpu/uplanfahr/app-menu.ui");
+ app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
+ gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
+ g_object_unref (builder);
+}
+
+static void
+u_plan_fahr_activate (GApplication *app)
+{
+ UPlanFahrWindow *win;
+
+ win = u_plan_fahr_window_new (U_PLAN_FAHR (app));
+ gtk_window_present (GTK_WINDOW (win));
+}
+
+static void
+u_plan_fahr_open (GApplication *app,
+ GFile **args,
+ gint n_files,
+ const gchar *hint)
+{
+ GList *windows;
+ UPlanFahrWindow *win;
+ int i;
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+ if (windows)
+ win = U_PLAN_FAHR_WINDOW (windows->data);
+ else
+ win = u_plan_fahr_window_new (U_PLAN_FAHR (app));
+
+ if (n_files % 2 == 0) {
+ for (i = 0; i < n_files; i+=2)
+ u_plan_fahr_window_open (win, args[i], args[i+1]);
+ }
+
+ gtk_window_present (GTK_WINDOW (win));
+}
+
+static void
+u_plan_fahr_class_init (UPlanFahrClass *class)
+{
+ G_APPLICATION_CLASS (class)->startup = u_plan_fahr_startup;
+ G_APPLICATION_CLASS (class)->activate = u_plan_fahr_activate;
+ G_APPLICATION_CLASS (class)->open = u_plan_fahr_open;
+}
+
+UPlanFahr *
+u_plan_fahr_new (void)
+{
+ return g_object_new (U_PLAN_FAHR_TYPE,
+ "application-id", "org.sigxcpu.org.uplanfahr",
+ "flags", G_APPLICATION_HANDLES_OPEN,
+ NULL);
+}