1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2  *
3  * Copyright (c) 2010 Intel, Inc.
4  *
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.
9  *
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
13  * for more details.
14  *
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
18  *
19  * Author: Thomas Wood <thos@gnome.org>
20  */
21 
22 /**
23  * SECTION:cc-shell
24  * @short_description: Interface representing the Control Center shell
25  *
26  * CcShell is an interface 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.
30  */
31 
32 
33 #include "cc-shell.h"
34 #include "cc-panel.h"
35 
G_DEFINE_INTERFACE(CcShell,cc_shell,GTK_TYPE_WIDGET)36 G_DEFINE_INTERFACE (CcShell, cc_shell, GTK_TYPE_WIDGET)
37 
38 static void
39 cc_shell_default_init (CcShellInterface *iface)
40 {
41   g_object_interface_install_property (iface,
42                                        g_param_spec_object ("active-panel",
43                                                             "active panel",
44                                                             "The currently active Panel",
45                                                             CC_TYPE_PANEL,
46                                                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
47 }
48 
49 /**
50  * cc_shell_get_active_panel:
51  * @shell: A #CcShell
52  *
53  * Get the current active panel
54  *
55  * Returns: a #CcPanel or NULL if no panel is active
56  */
57 CcPanel *
cc_shell_get_active_panel(CcShell * shell)58 cc_shell_get_active_panel (CcShell *shell)
59 {
60   CcPanel *panel = NULL;
61 
62   g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
63 
64   g_object_get (shell, "active-panel", &panel, NULL);
65 
66   return panel;
67 }
68 
69 /**
70  * cc_shell_set_active_panel:
71  * @shell: A #CcShell
72  * @panel: A #CcPanel
73  *
74  * Set the current active panel. If @panel is NULL, then the shell is returned
75  * to a state where no panel is being displayed (for example, the list of panels
76  * may be shown instead).
77  *
78  */
79 void
cc_shell_set_active_panel(CcShell * shell,CcPanel * panel)80 cc_shell_set_active_panel (CcShell *shell,
81                            CcPanel *panel)
82 {
83   g_return_if_fail (CC_IS_SHELL (shell));
84   g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
85 
86   g_object_set (shell, "active-panel", panel, NULL);
87 }
88 
89 /**
90  * cc_shell_set_active_panel_from_id:
91  * @shell: A #CcShell
92  * @id: The ID of the panel to set as active
93  * @parameters: A #GVariant with additional parameters
94  * @error: A #GError
95  *
96  * Find a panel corresponding to the specified id and set it as active.
97  *
98  * Returns: #TRUE if the panel was found and set as the active panel
99  */
100 gboolean
cc_shell_set_active_panel_from_id(CcShell * shell,const gchar * id,GVariant * parameters,GError ** error)101 cc_shell_set_active_panel_from_id (CcShell      *shell,
102                                    const gchar  *id,
103                                    GVariant     *parameters,
104                                    GError      **error)
105 {
106   CcShellInterface *iface;
107 
108   g_return_val_if_fail (CC_IS_SHELL (shell), FALSE);
109 
110   iface = CC_SHELL_GET_IFACE (shell);
111 
112   if (!iface->set_active_panel_from_id)
113     {
114       g_warning ("Object of type \"%s\" does not implement required interface"
115                  " method \"set_active_panel_from_id\",",
116                  G_OBJECT_TYPE_NAME (shell));
117       return FALSE;
118     }
119   else
120     {
121       return iface->set_active_panel_from_id (shell, id, parameters, error);
122     }
123 }
124 
125 /**
126  * cc_shell_get_toplevel:
127  * @shell: A #CcShell
128  *
129  * Gets the toplevel window of the shell.
130  *
131  * Returns: The #GtkWidget of the shell window, or #NULL on error.
132  */
133 GtkWidget *
cc_shell_get_toplevel(CcShell * shell)134 cc_shell_get_toplevel (CcShell *shell)
135 {
136   CcShellInterface *iface;
137 
138   g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
139 
140   iface = CC_SHELL_GET_IFACE (shell);
141 
142   if (iface->get_toplevel)
143     {
144         return iface->get_toplevel (shell);
145     }
146 
147   g_warning ("Object of type \"%s\" does not implement required interface"
148              " method \"get_toplevel\",",
149              G_OBJECT_TYPE_NAME (shell));
150 
151   return NULL;
152 }
153 
154 void
cc_shell_embed_widget_in_header(CcShell * shell,GtkWidget * widget,GtkPositionType position)155 cc_shell_embed_widget_in_header (CcShell         *shell,
156                                  GtkWidget       *widget,
157                                  GtkPositionType  position)
158 {
159   CcShellInterface *iface;
160 
161   g_return_if_fail (CC_IS_SHELL (shell));
162 
163   iface = CC_SHELL_GET_IFACE (shell);
164 
165   if (!iface->embed_widget_in_header)
166     {
167       g_warning ("Object of type \"%s\" does not implement required interface"
168                  " method \"embed_widget_in_header\",",
169                  G_OBJECT_TYPE_NAME (shell));
170     }
171   else
172     {
173       iface->embed_widget_in_header (shell, widget, position);
174     }
175 }
176