Commit 408ae4a8 authored by William Jon McCann's avatar William Jon McCann Committed by Bastien Nocera

shell: Make the main app window a subclass of GtkApplicationWindow

This allows for better encapsulation of window logic. In order to
do this CcShell was made an interface instead of an abstract base
class.

https://bugzilla.gnome.org/show_bug.cgi?id=692174
parent 64467d7f
......@@ -166,7 +166,7 @@ cc_application_command_line (GApplication *application,
cc_shell_log_set_debug (verbose);
gnome_control_center_show (self->priv->window, GTK_APPLICATION (application));
gnome_control_center_show (self->priv->window);
if (search_str)
{
......@@ -222,7 +222,7 @@ cc_application_quit (GSimpleAction *simple,
{
CcApplication *self = CC_APPLICATION (user_data);
g_clear_object (&self->priv->window);
gtk_widget_destroy (GTK_WIDGET (self->priv->window));
}
......@@ -281,7 +281,7 @@ cc_application_startup (GApplication *application)
gtk_application_add_accelerator (GTK_APPLICATION (application),
"F1", "app.help", NULL);
self->priv->window = gnome_control_center_new ();
self->priv->window = gnome_control_center_new (GTK_APPLICATION (application));
}
static GObject *
......
......@@ -21,9 +21,9 @@
/**
* SECTION:cc-shell
* @short_description: Abstract class representing the Control Center shell
* @short_description: Interface representing the Control Center shell
*
* CcShell is an abstract class that represents an instance of a control
* CcShell is an interface that represents an instance of a control
* center shell. It provides access to some of the properties of the shell
* that panels will need to read or change. When a panel is created it has an
* instance of CcShell available that represents the current shell.
......@@ -33,93 +33,17 @@
#include "cc-shell.h"
#include "cc-panel.h"
G_DEFINE_ABSTRACT_TYPE (CcShell, cc_shell, G_TYPE_OBJECT)
#define SHELL_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_SHELL, CcShellPrivate))
struct _CcShellPrivate
{
CcPanel *active_panel;
};
enum
{
PROP_ACTIVE_PANEL = 1
};
static void
cc_shell_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CcShell *shell = CC_SHELL (object);
switch (property_id)
{
case PROP_ACTIVE_PANEL:
g_value_set_object (value, shell->priv->active_panel);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
cc_shell_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CcShell *shell = CC_SHELL (object);
switch (property_id)
{
case PROP_ACTIVE_PANEL:
cc_shell_set_active_panel (shell, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
cc_shell_dispose (GObject *object)
{
/* remove and unref the active shell */
cc_shell_set_active_panel (CC_SHELL (object), NULL);
G_OBJECT_CLASS (cc_shell_parent_class)->dispose (object);
}
static void
cc_shell_class_init (CcShellClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
g_type_class_add_private (klass, sizeof (CcShellPrivate));
object_class->get_property = cc_shell_get_property;
object_class->set_property = cc_shell_set_property;
object_class->dispose = cc_shell_dispose;
pspec = g_param_spec_object ("active-panel",
"active panel",
"The currently active Panel",
CC_TYPE_PANEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_ACTIVE_PANEL, pspec);
}
G_DEFINE_INTERFACE (CcShell, cc_shell, GTK_TYPE_WIDGET)
static void
cc_shell_init (CcShell *self)
cc_shell_default_init (CcShellInterface *iface)
{
self->priv = SHELL_PRIVATE (self);
g_object_interface_install_property (iface,
g_param_spec_object ("active-panel",
"active panel",
"The currently active Panel",
CC_TYPE_PANEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
/**
......@@ -130,12 +54,16 @@ cc_shell_init (CcShell *self)
*
* Returns: a #CcPanel or NULL if no panel is active
*/
CcPanel*
CcPanel *
cc_shell_get_active_panel (CcShell *shell)
{
CcPanel *panel = NULL;
g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
return shell->priv->active_panel;
g_object_get (shell, "active-panel", &panel, NULL);
return panel;
}
/**
......@@ -155,18 +83,7 @@ cc_shell_set_active_panel (CcShell *shell,
g_return_if_fail (CC_IS_SHELL (shell));
g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
if (panel != shell->priv->active_panel)
{
/* remove the old panel */
g_clear_object (&shell->priv->active_panel);
/* set the new panel */
if (panel)
{
shell->priv->active_panel = g_object_ref (panel);
}
g_object_notify (G_OBJECT (shell), "active-panel");
}
g_object_set (shell, "active-panel", panel, NULL);
}
/**
......@@ -185,23 +102,22 @@ cc_shell_set_active_panel_from_id (CcShell *shell,
const gchar **argv,
GError **error)
{
CcShellClass *class;
CcShellInterface *iface;
g_return_val_if_fail (CC_IS_SHELL (shell), FALSE);
iface = CC_SHELL_GET_IFACE (shell);
class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
if (!class->set_active_panel_from_id)
if (!iface->set_active_panel_from_id)
{
g_warning ("Object of type \"%s\" does not implement required virtual"
" function \"set_active_panel_from_id\",",
g_warning ("Object of type \"%s\" does not implement required interface"
" method \"set_active_panel_from_id\",",
G_OBJECT_TYPE_NAME (shell));
return FALSE;
}
else
{
return class->set_active_panel_from_id (shell, id, argv, error);
return iface->set_active_panel_from_id (shell, id, argv, error);
}
}
......@@ -216,19 +132,19 @@ cc_shell_set_active_panel_from_id (CcShell *shell,
GtkWidget *
cc_shell_get_toplevel (CcShell *shell)
{
CcShellClass *klass;
CcShellInterface *iface;
g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
klass = CC_SHELL_GET_CLASS (shell);
iface = CC_SHELL_GET_IFACE (shell);
if (klass->get_toplevel)
if (iface->get_toplevel)
{
return klass->get_toplevel (shell);
return iface->get_toplevel (shell);
}
g_warning ("Object of type \"%s\" does not implement required virtual"
" function \"get_toplevel\",",
g_warning ("Object of type \"%s\" does not implement required interface"
" method \"get_toplevel\",",
G_OBJECT_TYPE_NAME (shell));
return NULL;
......@@ -237,20 +153,20 @@ cc_shell_get_toplevel (CcShell *shell)
void
cc_shell_embed_widget_in_header (CcShell *shell, GtkWidget *widget)
{
CcShellClass *class;
CcShellInterface *iface;
g_return_if_fail (CC_IS_SHELL (shell));
class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
iface = CC_SHELL_GET_IFACE (shell);
if (!class->embed_widget_in_header)
if (!iface->embed_widget_in_header)
{
g_warning ("Object of type \"%s\" does not implement required virtual"
" function \"embed_widget_in_header\",",
g_warning ("Object of type \"%s\" does not implement required interface"
" method \"embed_widget_in_header\",",
G_OBJECT_TYPE_NAME (shell));
}
else
{
class->embed_widget_in_header (shell, widget);
iface->embed_widget_in_header (shell, widget);
}
}
......@@ -26,64 +26,30 @@
G_BEGIN_DECLS
#define CC_TYPE_SHELL cc_shell_get_type()
#define CC_SHELL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
CC_TYPE_SHELL, CcShell))
#define CC_SHELL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
CC_TYPE_SHELL, CcShellClass))
#define CC_IS_SHELL(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
CC_TYPE_SHELL))
#define CC_IS_SHELL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
CC_TYPE_SHELL))
#define CC_SHELL_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
CC_TYPE_SHELL, CcShellClass))
#define CC_TYPE_SHELL (cc_shell_get_type())
#define CC_SHELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CC_TYPE_SHELL, CcShell))
#define CC_IS_SHELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CC_TYPE_SHELL))
#define CC_SHELL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CC_TYPE_SHELL, CcShellInterface))
#define CC_SHELL_PANEL_EXTENSION_POINT "control-center-1"
typedef struct _CcShell CcShell;
typedef struct _CcShellClass CcShellClass;
typedef struct _CcShellPrivate CcShellPrivate;
typedef struct _CcShellInterface CcShellInterface;
/* cc-panel.h requires CcShell, so make sure they are defined first */
#include "cc-panel.h"
/**
* CcShell:
*
* The contents of this struct are private should not be accessed directly.
*/
struct _CcShell
{
/*< private >*/
GObject parent;
CcShellPrivate *priv;
};
/**
* CcShellClass:
* CcShellInterface:
* @set_active_panel_from_id: virtual function to set the active panel from an
* id string
*
*/
struct _CcShellClass
struct _CcShellInterface
{
/*< private >*/
GObjectClass parent_class;
GTypeInterface g_iface;
/*< public >*/
/* vfuncs */
/* methods */
gboolean (*set_active_panel_from_id) (CcShell *shell,
const gchar *id,
const gchar **argv,
......@@ -95,7 +61,7 @@ struct _CcShellClass
GType cc_shell_get_type (void) G_GNUC_CONST;
CcPanel* cc_shell_get_active_panel (CcShell *shell);
CcPanel * cc_shell_get_active_panel (CcShell *shell);
void cc_shell_set_active_panel (CcShell *shell,
CcPanel *panel);
gboolean cc_shell_set_active_panel_from_id (CcShell *shell,
......
This diff is collapsed.
......@@ -54,23 +54,22 @@ typedef struct _GnomeControlCenterPrivate GnomeControlCenterPrivate;
struct _GnomeControlCenter
{
CcShell parent;
GtkApplicationWindow parent;
GnomeControlCenterPrivate *priv;
};
struct _GnomeControlCenterClass
{
CcShellClass parent_class;
GtkApplicationWindowClass parent_class;
};
GType gnome_control_center_get_type (void) G_GNUC_CONST;
GnomeControlCenter *gnome_control_center_new (void);
GnomeControlCenter *gnome_control_center_new (GtkApplication *application);
void gnome_control_center_present (GnomeControlCenter *center);
void gnome_control_center_show (GnomeControlCenter *center, GtkApplication *app);
void gnome_control_center_show (GnomeControlCenter *center);
void gnome_control_center_set_overview_page (GnomeControlCenter *center);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment