summaryrefslogtreecommitdiff
path: root/endless/window.c
diff options
context:
space:
mode:
authorP. F. Chimento <philip.chimento@gmail.com>2013-04-15 18:04:27 +0200
committerP. F. Chimento <philip.chimento@gmail.com>2013-04-24 14:48:15 +0200
commit096c63f7ed002b99a995c35a407483a0bfa161c5 (patch)
treecf324aae1bce4f5cb9edf42e68bc9c7cb4da0964 /endless/window.c
parent7fc4090461ad888612491814e5a44aaf7e52d7ff (diff)
Application class
Add an EosApplication class. Functionality: - present main application window when activated - warn if more than one application window is added Also add a stub EosWindow class that overrides GtkWindow's "application" property to be a construct-only property. [#4]
Diffstat (limited to 'endless/window.c')
-rw-r--r--endless/window.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/endless/window.c b/endless/window.c
new file mode 100644
index 0000000..86c95fa
--- /dev/null
+++ b/endless/window.c
@@ -0,0 +1,121 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#include "config.h"
+#include "window.h"
+
+#include "application.h"
+
+#include <gtk/gtk.h>
+
+/**
+ * SECTION:window
+ * @short_description: A window for your application
+ * @title: Window
+ *
+ * Stub
+ */
+
+G_DEFINE_TYPE (EosWindow, eos_window, GTK_TYPE_APPLICATION_WINDOW)
+
+#define WINDOW_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), EOS_TYPE_WINDOW, EosWindowPrivate))
+
+struct _EosWindowPrivate
+{
+ EosApplication *application;
+};
+
+enum
+{
+ PROP_0,
+ PROP_APPLICATION,
+ NPROPS
+};
+
+static GParamSpec *eos_window_props[NPROPS] = { NULL, };
+
+static void
+eos_window_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EosWindow *self = EOS_WINDOW (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION:
+ g_value_set_object (value, self->priv->application);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+eos_window_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EosWindow *self = EOS_WINDOW (object);
+
+ switch (property_id)
+ {
+ case PROP_APPLICATION:
+ self->priv->application = g_value_get_object (value);
+ gtk_window_set_application (GTK_WINDOW (self),
+ GTK_APPLICATION (self->priv->application));
+ if (self->priv->application == NULL)
+ g_critical ("In order to create a window, you must have an application "
+ "for it to connect to.");
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+eos_window_class_init (EosWindowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (EosWindowPrivate));
+
+ object_class->get_property = eos_window_get_property;
+ object_class->set_property = eos_window_set_property;
+
+ eos_window_props[PROP_APPLICATION] =
+ g_param_spec_object ("application", "Application",
+ "Application associated with this window",
+ EOS_TYPE_APPLICATION,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, NPROPS, eos_window_props);
+}
+
+static void
+eos_window_init (EosWindow *self)
+{
+ self->priv = WINDOW_PRIVATE (self);
+}
+
+/* Public API */
+
+/**
+ * eos_window_new:
+ * @application: the #EosApplication that the window belongs to.
+ *
+ * Create a window. It is invisible by default.
+ *
+ * Returns: a pointer to the window.
+ */
+GtkWidget *
+eos_window_new (EosApplication *application)
+{
+ return GTK_WIDGET (g_object_new (EOS_TYPE_WINDOW,
+ "application", application,
+ NULL));
+}