[gnome-initial-setup/shell/4765: 217/362] driver: separate out application window in its own class
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/shell/4765: 217/362] driver: separate out application window in its own class
- Date: Thu, 19 Mar 2015 01:39:19 +0000 (UTC)
commit e12fd8d111c8b18adce96f5fea9f79c76621c0b6
Author: Cosimo Cecchi <cosimo endlessm com>
Date: Mon Sep 15 14:24:00 2014 -0700
driver: separate out application window in its own class
We need to override one method on the window implementation. Start by
separating out the window functionality into a separate class.
[endlessm/eos-shell#3683]
gnome-initial-setup/Makefile.am | 3 +-
gnome-initial-setup/gis-driver.c | 57 ++-------------------
gnome-initial-setup/gis-window.c | 104 ++++++++++++++++++++++++++++++++++++++
gnome-initial-setup/gis-window.h | 62 ++++++++++++++++++++++
4 files changed, 172 insertions(+), 54 deletions(-)
---
diff --git a/gnome-initial-setup/Makefile.am b/gnome-initial-setup/Makefile.am
index 9b59681..ba8557a 100644
--- a/gnome-initial-setup/Makefile.am
+++ b/gnome-initial-setup/Makefile.am
@@ -28,7 +28,8 @@ gnome_initial_setup_SOURCES = \
gis-assistant.c gis-assistant.h \
gis-page.c gis-page.h \
gis-driver.c gis-driver.h \
- gis-keyring.c gis-keyring.h
+ gis-keyring.c gis-keyring.h \
+ gis-window.c gis-window.h
gnome_initial_setup_LDADD = \
pages/language/libgislanguage.la \
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index fffddb6..f929bbc 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -29,6 +29,7 @@
#include <locale.h>
#include "gis-assistant.h"
+#include "gis-window.h"
#define GIS_TYPE_DRIVER_MODE (gis_driver_mode_get_type ())
@@ -74,7 +75,7 @@ enum {
static GParamSpec *obj_props[PROP_LAST];
struct _GisDriverPrivate {
- GtkWindow *main_window;
+ GtkWidget *main_window;
GisAssistant *assistant;
ActUser *user_account;
@@ -107,27 +108,6 @@ gis_driver_finalize (GObject *object)
G_OBJECT_CLASS (gis_driver_parent_class)->finalize (object);
}
-static void
-prepare_main_window (GisDriver *driver)
-{
- GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
- GdkGeometry size_hints;
-
- size_hints.min_width = 747;
- size_hints.min_height = 539;
- size_hints.max_width = 747;
- size_hints.max_height = 539;
- size_hints.win_gravity = GDK_GRAVITY_CENTER;
-
- gtk_window_set_geometry_hints (priv->main_window,
- GTK_WIDGET (priv->main_window),
- &size_hints,
- GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_WIN_GRAVITY);
-
- gtk_window_set_titlebar (priv->main_window,
- gis_assistant_get_titlebar (priv->assistant));
-}
-
static gboolean
rebuild_pages (GisDriver *driver)
{
@@ -284,17 +264,6 @@ gis_driver_activate (GApplication *app)
}
static void
-window_realize_cb (GtkWidget *widget, gpointer user_data)
-{
- GisDriver *driver = GIS_DRIVER (user_data);
- GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
- GdkWindow *window;
- window = gtk_widget_get_window (GTK_WIDGET (priv->main_window));
- /* disable WM functions except move */
- gdk_window_set_functions (window, GDK_FUNC_MOVE);
-}
-
-static void
gis_driver_read_personality_file (GisDriver *driver)
{
GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
@@ -341,29 +310,11 @@ gis_driver_startup (GApplication *app)
gis_driver_read_personality_file (driver);
- priv->main_window = g_object_new (GTK_TYPE_APPLICATION_WINDOW,
- "application", app,
- "type", GTK_WINDOW_TOPLEVEL,
- "border-width", 12,
- "icon-name", "preferences-system",
- "resizable", TRUE,
- "window-position", GTK_WIN_POS_CENTER_ALWAYS,
- "deletable", FALSE,
- NULL);
-
- g_signal_connect (priv->main_window,
- "realize",
- G_CALLBACK (window_realize_cb),
- (gpointer)app);
-
- priv->assistant = g_object_new (GIS_TYPE_ASSISTANT, NULL);
- gtk_container_add (GTK_CONTAINER (priv->main_window), GTK_WIDGET (priv->assistant));
-
- gtk_widget_show (GTK_WIDGET (priv->assistant));
+ priv->main_window = gis_window_new (driver);
+ priv->assistant = gis_window_get_assistant (GIS_WINDOW (priv->main_window));
gis_driver_set_user_language (driver, setlocale (LC_MESSAGES, NULL));
- prepare_main_window (driver);
rebuild_pages (driver);
}
diff --git a/gnome-initial-setup/gis-window.c b/gnome-initial-setup/gis-window.c
new file mode 100644
index 0000000..f454173
--- /dev/null
+++ b/gnome-initial-setup/gis-window.c
@@ -0,0 +1,104 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2012 Red Hat
+ * Copyright (C) 2014 Endless Mobile, Inc.
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre mecheye net>
+ * Cosimo Cecchi <cosimo endlessm com>
+ */
+
+#include "config.h"
+
+#include "gis-assistant.h"
+#include "gis-window.h"
+
+struct _GisWindowPrivate {
+ GisAssistant *assistant;
+};
+typedef struct _GisWindowPrivate GisWindowPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE(GisWindow, gis_window, GTK_TYPE_APPLICATION_WINDOW)
+
+static void
+gis_window_realize (GtkWidget *widget)
+{
+ GdkWindow *window;
+
+ GTK_WIDGET_CLASS (gis_window_parent_class)->realize (widget);
+
+ window = gtk_widget_get_window (widget);
+ /* disable WM functions except move */
+ gdk_window_set_functions (window, GDK_FUNC_MOVE);
+}
+
+static void
+gis_window_class_init (GisWindowClass *klass)
+{
+ GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+
+ wclass->realize = gis_window_realize;
+}
+
+static void
+gis_window_init (GisWindow *window)
+{
+ GisWindowPrivate *priv = gis_window_get_instance_private (window);
+ GdkGeometry size_hints;
+
+ size_hints.min_width = 747;
+ size_hints.min_height = 539;
+ size_hints.max_width = 747;
+ size_hints.max_height = 539;
+ size_hints.win_gravity = GDK_GRAVITY_CENTER;
+
+ gtk_window_set_geometry_hints (GTK_WINDOW (window),
+ GTK_WIDGET (window),
+ &size_hints,
+ GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_WIN_GRAVITY);
+
+ priv->assistant = g_object_new (GIS_TYPE_ASSISTANT, NULL);
+ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (priv->assistant));
+ gtk_widget_show (GTK_WIDGET (priv->assistant));
+ gtk_window_set_titlebar (GTK_WINDOW (window), gis_assistant_get_titlebar (priv->assistant));
+}
+
+GisAssistant *
+gis_window_get_assistant (GisWindow *window)
+{
+ GisWindowPrivate *priv;
+
+ g_return_val_if_fail (GIS_IS_WINDOW (window), NULL);
+
+ priv = gis_window_get_instance_private (window);
+ return priv->assistant;
+}
+
+GtkWidget *
+gis_window_new (GisDriver *driver)
+{
+ return g_object_new (GIS_TYPE_WINDOW,
+ "application", driver,
+ "type", GTK_WINDOW_TOPLEVEL,
+ "border-width", 12,
+ "icon-name", "preferences-system",
+ "resizable", TRUE,
+ "window-position", GTK_WIN_POS_CENTER_ALWAYS,
+ "deletable", FALSE,
+ NULL);
+}
diff --git a/gnome-initial-setup/gis-window.h b/gnome-initial-setup/gis-window.h
new file mode 100644
index 0000000..2856765
--- /dev/null
+++ b/gnome-initial-setup/gis-window.h
@@ -0,0 +1,62 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2012 Red Hat
+ * Copyright (C) 2014 Endless Mobile, Inc.
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre mecheye net>
+ * Cosimo Cecchi <cosimo endlessm com>
+ */
+
+#ifndef __GIS_WINDOW_H__
+#define __GIS_WINDOW_H__
+
+#include <gtk/gtk.h>
+
+#include "gis-driver.h"
+
+G_BEGIN_DECLS
+
+#define GIS_TYPE_WINDOW (gis_window_get_type ())
+#define GIS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIS_TYPE_WINDOW, GisWindow))
+#define GIS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIS_TYPE_WINDOW, GisWindowClass))
+#define GIS_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIS_TYPE_WINDOW))
+#define GIS_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIS_TYPE_WINDOW))
+#define GIS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIS_TYPE_WINDOW, GisWindowClass))
+
+typedef struct _GisWindow GisWindow;
+typedef struct _GisWindowClass GisWindowClass;
+
+struct _GisWindow
+{
+ GtkApplicationWindow parent;
+};
+
+struct _GisWindowClass
+{
+ GtkApplicationWindowClass parent_class;
+};
+
+GType gis_window_get_type (void);
+
+GtkWidget *gis_window_new (GisDriver *driver);
+GisAssistant * gis_window_get_assistant (GisWindow *window);
+
+G_END_DECLS
+
+#endif /* __GIS_WINDOW_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]