1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
3
* Copyright (c) 2010 Intel, Inc.
5
* The Control Center is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by the
7
* Free Software Foundation; either version 2 of the License, or (at your
8
* option) any later version.
10
* The Control Center is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
* You should have received a copy of the GNU General Public License along
16
* with the Control Center; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Author: Thomas Wood <thos@gnome.org>
24
* @short_description: Abstract class representing the Control Center shell
26
* CcShell is an abstract class that represents an instance of a control
27
* center shell. It provides access to some of the properties of the shell
28
* that panels will need to read or change. When a panel is created it has an
29
* instance of CcShell available that represents the current shell.
36
G_DEFINE_ABSTRACT_TYPE (CcShell, cc_shell, G_TYPE_OBJECT)
38
#define SHELL_PRIVATE(o) \
39
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_SHELL, CcShellPrivate))
41
struct _CcShellPrivate
43
CcPanel *active_panel;
53
cc_shell_get_property (GObject *object,
58
CcShell *shell = CC_SHELL (object);
62
case PROP_ACTIVE_PANEL:
63
g_value_set_object (value, shell->priv->active_panel);
67
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
72
cc_shell_set_property (GObject *object,
77
CcShell *shell = CC_SHELL (object);
81
case PROP_ACTIVE_PANEL:
82
cc_shell_set_active_panel (shell, g_value_get_object (value));
86
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
91
cc_shell_dispose (GObject *object)
93
/* remove and unref the active shell */
94
cc_shell_set_active_panel (CC_SHELL (object), NULL);
96
G_OBJECT_CLASS (cc_shell_parent_class)->dispose (object);
100
cc_shell_class_init (CcShellClass *klass)
102
GObjectClass *object_class = G_OBJECT_CLASS (klass);
105
g_type_class_add_private (klass, sizeof (CcShellPrivate));
107
object_class->get_property = cc_shell_get_property;
108
object_class->set_property = cc_shell_set_property;
109
object_class->dispose = cc_shell_dispose;
111
pspec = g_param_spec_object ("active-panel",
113
"The currently active Panel",
115
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
116
g_object_class_install_property (object_class, PROP_ACTIVE_PANEL, pspec);
120
cc_shell_init (CcShell *self)
122
self->priv = SHELL_PRIVATE (self);
126
* cc_shell_get_active_panel:
129
* Get the current active panel
131
* Returns: a #CcPanel or NULL if no panel is active
134
cc_shell_get_active_panel (CcShell *shell)
136
g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
138
return shell->priv->active_panel;
142
* cc_shell_set_active_panel:
146
* Set the current active panel. If @panel is NULL, then the shell is returned
147
* to a state where no panel is being displayed (for example, the list of panels
148
* may be shown instead).
152
cc_shell_set_active_panel (CcShell *shell,
155
g_return_if_fail (CC_IS_SHELL (shell));
156
g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
158
if (panel != shell->priv->active_panel)
160
/* remove the old panel */
161
g_object_unref (shell->priv->active_panel);
162
shell->priv->active_panel = NULL;
164
/* set the new panel */
167
shell->priv->active_panel = g_object_ref (panel);
168
g_object_set (G_OBJECT (panel), "shell", shell, NULL);
170
g_object_notify (G_OBJECT (shell), "active-panel");
175
* cc_shell_set_active_panel_from_id:
177
* @id: the ID of the panel to set as active
180
* Find a panel corresponding to the specified id and set it as active.
182
* Returns: #TRUE if the panel was found and set as the active panel
185
cc_shell_set_active_panel_from_id (CcShell *shell,
192
g_return_val_if_fail (CC_IS_SHELL (shell), FALSE);
195
class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
197
if (!class->set_active_panel_from_id)
199
g_warning ("Object of type \"%s\" does not implement required virtual"
200
" function \"set_active_panel_from_id\",",
201
G_OBJECT_TYPE_NAME (shell));
206
return class->set_active_panel_from_id (shell, id, argv, error);
211
* cc_shell_get_toplevel:
214
* Gets the toplevel window of the shell.
216
* Returns: The #GtkWidget of the shell window, or #NULL on error.
219
cc_shell_get_toplevel (CcShell *shell)
223
g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
225
klass = CC_SHELL_GET_CLASS (shell);
227
if (klass->get_toplevel)
229
return klass->get_toplevel (shell);
232
g_warning ("Object of type \"%s\" does not implement required virtual"
233
" function \"get_toplevel\",",
234
G_OBJECT_TYPE_NAME (shell));
240
cc_shell_embed_widget_in_header (CcShell *shell, GtkWidget *widget)
244
g_return_if_fail (CC_IS_SHELL (shell));
246
class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
248
if (!class->embed_widget_in_header)
250
g_warning ("Object of type \"%s\" does not implement required virtual"
251
" function \"embed_widget_in_header\",",
252
G_OBJECT_TYPE_NAME (shell));
257
return class->embed_widget_in_header (shell, widget);