From 50fc3f6f703b3842fdcbf88d020f275308680a12 Mon Sep 17 00:00:00 2001 From: "Gergely POLONKAI (W00d5t0ck)" Date: Sun, 8 Sep 2013 23:01:37 +0200 Subject: [PATCH] Created the AgWindow class for the chart window --- src/Makefile.am | 2 +- src/ag-window.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++ src/ag-window.h | 35 ++++++++++++++ src/astrognome.ui | 14 ++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/ag-window.c create mode 100644 src/ag-window.h diff --git a/src/Makefile.am b/src/Makefile.am index 5f5a0b4..d19f7b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ EXTRA_DIST = \ AM_CPPFLAGS = -DG_LOG_DOMAIN=\"Astrognome\" -DLOCALEDIR=\"$(localedir)\" -DPKGDATADIR=\"$(pkgdatadir)\" bin_PROGRAMS = astrognome -astrognome_SOURCES = ag-app.c astrognome.c $(BUILT_SOURCES) +astrognome_SOURCES = ag-app.c ag-window.c astrognome.c $(BUILT_SOURCES) astrognome_LDADD = $(SWE_GLIB_LIBS) $(GTK_LIBS) $(top_builddir)/libgd/libgd.la astrognome_LDFLAGS = -rdynamic astrognome_CFLAGS = $(SWE_GLIB_CFLAGS) $(CFLAGS) $(GTK_CFLAGS) -Wall -I$(top_srcdir)/libgd diff --git a/src/ag-window.c b/src/ag-window.c new file mode 100644 index 0000000..c68dd39 --- /dev/null +++ b/src/ag-window.c @@ -0,0 +1,114 @@ +#include + +#include "ag-app.h" +#include "ag-window.h" + +struct _AgWindowPrivate { + GtkWidget *grid; + GtkWidget *header_bar; + GtkWidget *notebook; + GtkBuilder *builder; +}; + +G_DEFINE_TYPE(AgWindow, ag_window, GTK_TYPE_APPLICATION_WINDOW); + +#define GET_PRIVATE(instance) (G_TYPE_INSTANCE_GET_PRIVATE((instance), AG_TYPE_WINDOW, AgWindowPrivate)) + +static void +gear_menu_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) +{ + GVariant *state; + + state = g_action_get_state(G_ACTION(action)); + g_action_change_state(G_ACTION(action), g_variant_new_boolean(!g_variant_get_boolean(state))); + + g_variant_unref(state); +} + +static void +close_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data) +{ + AgWindow *window = user_data; + + // TODO: Save unsaved changes! + gtk_widget_destroy(GTK_WIDGET(window)); +} + +static GActionEntry win_entries[] = { + { "close", close_cb, NULL, NULL, NULL }, + { "gear-menu", gear_menu_cb, NULL, "false", NULL }, +}; + +static void +ag_window_init(AgWindow *window) +{ + AgWindowPrivate *priv; + GtkAccelGroup *accel_group; + GError *err = NULL; + + window->priv = priv = GET_PRIVATE(window); + + gtk_window_set_hide_titlebar_when_maximized(GTK_WINDOW(window), TRUE); + + priv->builder = gtk_builder_new(); + + if (!gtk_builder_add_from_resource(priv->builder, "/eu/polonkai/gergely/astrognome/astrognome.ui", &err)) { + g_error("Cannot add resource to builder: '%s'", (err) ? err->message : "unknown error"); + g_clear_error(&err); + } + + priv->grid = gtk_grid_new(); + gtk_widget_show(priv->grid); + + gtk_container_add(GTK_CONTAINER(window), priv->grid); + + g_action_map_add_action_entries(G_ACTION_MAP(window), win_entries, G_N_ELEMENTS(win_entries), window); + + accel_group = gtk_accel_group_new(); + gtk_window_add_accel_group(GTK_WINDOW(window), accel_group); +} + +static void +ag_window_class_init(AgWindowClass *klass) +{ + g_type_class_add_private(klass, sizeof(AgWindowPrivate)); +} + +static void +window_populate(AgWindow *window) +{ + AgWindowPrivate *priv = window->priv; + GtkWidget *menu_button; + GObject *menu; + + priv->header_bar = gd_header_bar_new(); + menu_button = gd_header_menu_button_new(); + gd_header_button_set_symbolic_icon_name(GD_HEADER_BUTTON(menu_button), "emblem-system-symbolic"); + gtk_actionable_set_action_name(GTK_ACTIONABLE(menu_button), "win.gear-menu"); + + gd_header_bar_pack_end(GD_HEADER_BAR(priv->header_bar), menu_button); + + gtk_grid_attach(GTK_GRID(priv->grid), priv->header_bar, 0, 0, 1, 1); + + menu = gtk_builder_get_object(priv->builder, "window-menu"); + gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menu_button), G_MENU_MODEL(menu)); + + gtk_widget_show_all(priv->grid); +} + +GtkWidget * +ag_window_new(AgApp *app) +{ + AgWindow *window; + + window = g_object_new(AG_TYPE_WINDOW, NULL); + + gtk_window_set_application(GTK_WINDOW(window), GTK_APPLICATION(app)); + + window_populate(window); + + gtk_window_set_icon_name(GTK_WINDOW(window), "astrognome"); + + return GTK_WIDGET(window); +} + diff --git a/src/ag-window.h b/src/ag-window.h new file mode 100644 index 0000000..a1780c4 --- /dev/null +++ b/src/ag-window.h @@ -0,0 +1,35 @@ +#ifndef __AG_WINDOW_H__ +#define __AG_WINDOW_H__ + +#include +#include "ag-app.h" + +G_BEGIN_DECLS + +#define AG_TYPE_WINDOW (ag_window_get_type()) +#define AG_WINDOW(o) (G_TYPE_CHECK_INSTANCE_CAST((o), AG_TYPE_WINDOW, AgWindow)) +#define AG_WINDOW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), AG_TYPE_WINDOW, AgWindowClass)) +#define AG_IS_WINDOW(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), AG_TYPE_WINDOW)) +#define AG_IS_WINDOW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), AG_TYPE_WINDOW)) +#define AG_WINDOW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), AG_TYPE_WINDOW, AgWindowClass)) + +typedef struct _AgWindow AgWindow; +typedef struct _AgWindowClass AgWindowClass; +typedef struct _AgWindowPrivate AgWindowPrivate; + +struct _AgWindow { + GtkApplicationWindow parent_instance; + AgWindowPrivate *priv; +}; + +struct _AgWindowClass { + GtkApplicationWindowClass parent_class; +}; + +GType ag_window_get_type(void) G_GNUC_CONST; +GtkWidget *ag_window_new(AgApp *app); + +G_END_DECLS + +#endif /* __AG_WINDOW_H__ */ + diff --git a/src/astrognome.ui b/src/astrognome.ui index 29f48aa..3c9841a 100644 --- a/src/astrognome.ui +++ b/src/astrognome.ui @@ -28,6 +28,20 @@ + +
+ + Chart + win.tab-chart + F5 + + + Aspects + win.tab-aspects + F9 + +
+
accels