[ekiga/ds-gtk-application: 2/4] GmWindow: Implemented as a GtkApplicationWindow descedant.



commit 66a0078c65650f795bf622f5765ec47eeee563a3
Author: Damien Sandras <dsandras beip be>
Date:   Sun Feb 2 17:24:34 2014 +0100

    GmWindow: Implemented as a GtkApplicationWindow descedant.
    
    This allows Ekiga GmWindows to become GtkApplication windows for the big
    GtkApplication move.

 lib/gui/gmwindow.c |   55 ++++++++++++++++++++++++++++++++++++++++++++-------
 lib/gui/gmwindow.h |   25 ++++++++++++++++++-----
 2 files changed, 66 insertions(+), 14 deletions(-)
---
diff --git a/lib/gui/gmwindow.c b/lib/gui/gmwindow.c
index febda10..7bb9afe 100644
--- a/lib/gui/gmwindow.c
+++ b/lib/gui/gmwindow.c
@@ -31,8 +31,8 @@
  *                         -------------------------
  *   begin                : 16 August 2007
  *   copyright            : (c) 2007 by Damien Sandras
- *   description          : Implementation of a GtkWindow able to restore
- *                          its position and size in a GSettings key.
+ *   description          : Implementation of a GtkApplicationWindow able
+ *                          to restore its position and size in a GmConf key.
  *
  */
 
@@ -47,6 +47,7 @@
 struct _GmWindowPrivate
 {
   GtkAccelGroup *accel;
+  GtkApplication *application;
   GSettings *settings;
   gboolean hide_on_esc;
   gboolean hide_on_delete;
@@ -63,10 +64,11 @@ enum {
   GM_WINDOW_KEY = 1,
   GM_HIDE_ON_ESC = 2,
   GM_HIDE_ON_DELETE = 3,
-  GM_STAY_ON_TOP = 4
+  GM_STAY_ON_TOP = 4,
+  GM_APPLICATION = 5
 };
 
-G_DEFINE_TYPE (GmWindow, gm_window, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE (GmWindow, gm_window, GTK_TYPE_APPLICATION_WINDOW);
 
 static gboolean
 gm_window_delete_event_cb (GtkWidget *w,
@@ -92,7 +94,7 @@ gm_window_configure_event (GtkWidget *widget,
  * GObject stuff
  */
 static void
-gm_window_finalize (GObject *obj)
+gm_window_dispose (GObject *obj)
 {
   GmWindow *self = NULL;
 
@@ -105,7 +107,7 @@ gm_window_finalize (GObject *obj)
     g_clear_object (&self->priv->settings);
   self->priv->settings = NULL;
 
-  G_OBJECT_CLASS (gm_window_parent_class)->finalize (obj);
+  G_OBJECT_CLASS (gm_window_parent_class)->dispose (obj);
 }
 
 
@@ -138,6 +140,10 @@ gm_window_get_property (GObject *obj,
     g_value_set_boolean (value, self->priv->stay_on_top);
     break;
 
+  case GM_APPLICATION:
+    g_value_set_pointer (value, self->priv->application);
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
     break;
@@ -172,7 +178,8 @@ gm_window_set_property (GObject *obj,
   case GM_HIDE_ON_ESC:
     self->priv->hide_on_esc = g_value_get_boolean (value);
     if (!self->priv->hide_on_esc)
-      gtk_accel_group_disconnect_key (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0);
+      gtk_accel_group_connect (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
+                               g_cclosure_new_swap (G_CALLBACK (gtk_widget_destroy), (gpointer) self, NULL));
     else
       gtk_accel_group_connect (self->priv->accel, GDK_KEY_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
                                g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));
@@ -187,6 +194,13 @@ gm_window_set_property (GObject *obj,
     gtk_window_set_keep_above (GTK_WINDOW (self), self->priv->stay_on_top);
     break;
 
+  case GM_APPLICATION:
+    self->priv->application = g_value_get_pointer (value);
+    if (self->priv->application)
+      gtk_application_add_window (GTK_APPLICATION (self->priv->application),
+                                  GTK_WINDOW (self));
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
     break;
@@ -202,7 +216,7 @@ gm_window_class_init (GmWindowClass* klass)
 
   g_type_class_add_private (klass, sizeof (GmWindowPrivate));
 
-  gobject_class->finalize = gm_window_finalize;
+  gobject_class->dispose = gm_window_dispose;
   gobject_class->get_property = gm_window_get_property;
   gobject_class->set_property = gm_window_set_property;
 
@@ -223,6 +237,11 @@ gm_window_class_init (GmWindowClass* klass)
                                "Indicates if the window should stay on top of other windows",
                                FALSE, (GParamFlags) G_PARAM_READWRITE);
   g_object_class_install_property (gobject_class, GM_STAY_ON_TOP, spec);
+
+  spec = g_param_spec_pointer ("application", "GtkApplication",
+                               "GtkApplication to which the GtkApplicationWindow is associated",
+                               (GParamFlags) G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class, GM_APPLICATION, spec);
 }
 
 
@@ -230,6 +249,7 @@ static void
 gm_window_init (GmWindow* self)
 {
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_TYPE_WINDOW, GmWindowPrivate);
+  self->priv->application = NULL;
   self->priv->settings = NULL;
   self->priv->key = g_strdup ("");
   self->priv->hide_on_esc = TRUE;
@@ -511,6 +531,25 @@ gm_window_get_stay_on_top (GmWindow *window)
   return window->priv->stay_on_top;
 }
 
+
+void
+gm_window_set_application (GmWindow *window,
+                           GtkApplication *application)
+{
+  g_return_if_fail (GM_IS_WINDOW (window));
+
+  g_object_set (window, "application", application, NULL);
+}
+
+
+GtkApplication *
+gm_window_get_application (GmWindow *window)
+{
+  g_return_val_if_fail (GM_IS_WINDOW (window), NULL);
+
+  return window->priv->application;
+}
+
 gboolean
 gm_window_is_visible (GtkWidget* w)
 {
diff --git a/lib/gui/gmwindow.h b/lib/gui/gmwindow.h
index 3cac230..ba70191 100644
--- a/lib/gui/gmwindow.h
+++ b/lib/gui/gmwindow.h
@@ -29,10 +29,10 @@
 /*
  *                         gmwindow.h -  description
  *                         -------------------------
- *   begin                : 16 August 2007 
- *   copyright            : (c) 2007 by Damien Sandras 
- *   description          : Implementation of a GtkWindow able to restore
- *                          its position and size in a GmConf key.
+ *   begin                : 16 August 2007
+ *   copyright            : (c) 2007 by Damien Sandras
+ *   description          : Implementation of a GtkApplicationWindow able
+ *                          to restore its position and size in a GmConf key.
  *
  */
 
@@ -52,13 +52,13 @@ typedef struct _GmWindowClass GmWindowClass;
 /* GObject thingies */
 struct _GmWindow
 {
-  GtkWindow parent;
+  GtkApplicationWindow parent;
   GmWindowPrivate *priv;
 };
 
 struct _GmWindowClass
 {
-  GtkWindowClass parent;
+  GtkApplicationWindowClass parent;
 };
 
 /* Public API */
@@ -135,6 +135,19 @@ void gm_window_set_stay_on_top (GmWindow *window,
 gboolean gm_window_get_stay_on_top (GmWindow *window);
 
 
+/** Set the GmWindow GtkApplication
+ * @param window is the GmWindow
+ * @param application is the GtkApplication to link the window with
+ */
+void gm_window_set_application (GmWindow *window,
+                                GtkApplication *application);
+
+/** Get the GmWindow linked GtkApplication
+ * @param window is the GmWindow
+ */
+GtkApplication *gm_window_get_application (GmWindow *window);
+
+
 /** Check whether a window is visible or not
  * @param window is a GtkWidget
  */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]