~ubuntu-branches/ubuntu/trusty/unity-control-center/trusty

« back to all changes in this revision

Viewing changes to shell/cc-shell.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-01-08 16:29:18 UTC
  • Revision ID: package-import@ubuntu.com-20140108162918-g29dd08tr913y2qh
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: Abstract class representing the Control Center shell
 
25
 *
 
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.
 
30
 */
 
31
 
 
32
 
 
33
#include "cc-shell.h"
 
34
#include "cc-panel.h"
 
35
 
 
36
G_DEFINE_ABSTRACT_TYPE (CcShell, cc_shell, G_TYPE_OBJECT)
 
37
 
 
38
#define SHELL_PRIVATE(o) \
 
39
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_SHELL, CcShellPrivate))
 
40
 
 
41
struct _CcShellPrivate
 
42
{
 
43
  CcPanel *active_panel;
 
44
};
 
45
 
 
46
enum
 
47
{
 
48
  PROP_ACTIVE_PANEL = 1
 
49
};
 
50
 
 
51
 
 
52
static void
 
53
cc_shell_get_property (GObject    *object,
 
54
                       guint       property_id,
 
55
                       GValue     *value,
 
56
                       GParamSpec *pspec)
 
57
{
 
58
  CcShell *shell = CC_SHELL (object);
 
59
 
 
60
  switch (property_id)
 
61
    {
 
62
    case PROP_ACTIVE_PANEL:
 
63
      g_value_set_object (value, shell->priv->active_panel);
 
64
      break;
 
65
 
 
66
    default:
 
67
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
68
    }
 
69
}
 
70
 
 
71
static void
 
72
cc_shell_set_property (GObject      *object,
 
73
                       guint         property_id,
 
74
                       const GValue *value,
 
75
                       GParamSpec   *pspec)
 
76
{
 
77
  CcShell *shell = CC_SHELL (object);
 
78
 
 
79
  switch (property_id)
 
80
    {
 
81
    case PROP_ACTIVE_PANEL:
 
82
      cc_shell_set_active_panel (shell, g_value_get_object (value));
 
83
      break;
 
84
 
 
85
    default:
 
86
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
87
    }
 
88
}
 
89
 
 
90
static void
 
91
cc_shell_dispose (GObject *object)
 
92
{
 
93
  /* remove and unref the active shell */
 
94
  cc_shell_set_active_panel (CC_SHELL (object), NULL);
 
95
 
 
96
  G_OBJECT_CLASS (cc_shell_parent_class)->dispose (object);
 
97
}
 
98
 
 
99
static void
 
100
cc_shell_class_init (CcShellClass *klass)
 
101
{
 
102
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
103
  GParamSpec *pspec;
 
104
 
 
105
  g_type_class_add_private (klass, sizeof (CcShellPrivate));
 
106
 
 
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;
 
110
 
 
111
  pspec = g_param_spec_object ("active-panel",
 
112
                               "active panel",
 
113
                               "The currently active Panel",
 
114
                               CC_TYPE_PANEL,
 
115
                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
116
  g_object_class_install_property (object_class, PROP_ACTIVE_PANEL, pspec);
 
117
}
 
118
 
 
119
static void
 
120
cc_shell_init (CcShell *self)
 
121
{
 
122
  self->priv = SHELL_PRIVATE (self);
 
123
}
 
124
 
 
125
/**
 
126
 * cc_shell_get_active_panel:
 
127
 * @shell: A #CcShell
 
128
 *
 
129
 * Get the current active panel
 
130
 *
 
131
 * Returns: a #CcPanel or NULL if no panel is active
 
132
 */
 
133
CcPanel*
 
134
cc_shell_get_active_panel (CcShell *shell)
 
135
{
 
136
  g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
 
137
 
 
138
  return shell->priv->active_panel;
 
139
}
 
140
 
 
141
/**
 
142
 * cc_shell_set_active_panel:
 
143
 * @shell: A #CcShell
 
144
 * @panel: A #CcPanel
 
145
 *
 
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).
 
149
 *
 
150
 */
 
151
void
 
152
cc_shell_set_active_panel (CcShell *shell,
 
153
                           CcPanel *panel)
 
154
{
 
155
  g_return_if_fail (CC_IS_SHELL (shell));
 
156
  g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
 
157
 
 
158
  if (panel != shell->priv->active_panel)
 
159
    {
 
160
      /* remove the old panel */
 
161
      g_clear_object (&shell->priv->active_panel);
 
162
 
 
163
      /* set the new panel */
 
164
      if (panel)
 
165
        {
 
166
          shell->priv->active_panel = g_object_ref (panel);
 
167
        }
 
168
      g_object_notify (G_OBJECT (shell), "active-panel");
 
169
    }
 
170
}
 
171
 
 
172
/**
 
173
 * cc_shell_set_active_panel_from_id:
 
174
 * @shell: A #CcShell
 
175
 * @id: the ID of the panel to set as active
 
176
 * @error: A #GError
 
177
 *
 
178
 * Find a panel corresponding to the specified id and set it as active.
 
179
 *
 
180
 * Returns: #TRUE if the panel was found and set as the active panel
 
181
 */
 
182
gboolean
 
183
cc_shell_set_active_panel_from_id (CcShell      *shell,
 
184
                                   const gchar  *id,
 
185
                                   const gchar **argv,
 
186
                                   GError      **error)
 
187
{
 
188
  CcShellClass *class;
 
189
 
 
190
  g_return_val_if_fail (CC_IS_SHELL (shell), FALSE);
 
191
 
 
192
 
 
193
  class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
 
194
 
 
195
  if (!class->set_active_panel_from_id)
 
196
    {
 
197
      g_warning ("Object of type \"%s\" does not implement required virtual"
 
198
                 " function \"set_active_panel_from_id\",",
 
199
                 G_OBJECT_TYPE_NAME (shell));
 
200
      return FALSE;
 
201
    }
 
202
  else
 
203
    {
 
204
      return class->set_active_panel_from_id (shell, id, argv, error);
 
205
    }
 
206
}
 
207
 
 
208
/**
 
209
 * cc_shell_get_toplevel:
 
210
 * @shell: A #CcShell
 
211
 *
 
212
 * Gets the toplevel window of the shell.
 
213
 *
 
214
 * Returns: The #GtkWidget of the shell window, or #NULL on error.
 
215
 */
 
216
GtkWidget *
 
217
cc_shell_get_toplevel (CcShell *shell)
 
218
{
 
219
  CcShellClass *klass;
 
220
 
 
221
  g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
 
222
 
 
223
  klass = CC_SHELL_GET_CLASS (shell);
 
224
 
 
225
  if (klass->get_toplevel)
 
226
    {
 
227
        return klass->get_toplevel (shell);
 
228
    }
 
229
 
 
230
  g_warning ("Object of type \"%s\" does not implement required virtual"
 
231
             " function \"get_toplevel\",",
 
232
             G_OBJECT_TYPE_NAME (shell));
 
233
 
 
234
  return NULL;
 
235
}
 
236
 
 
237
void
 
238
cc_shell_embed_widget_in_header (CcShell *shell, GtkWidget *widget)
 
239
{
 
240
  CcShellClass *class;
 
241
 
 
242
  g_return_if_fail (CC_IS_SHELL (shell));
 
243
 
 
244
  class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
 
245
 
 
246
  if (!class->embed_widget_in_header)
 
247
    {
 
248
      g_warning ("Object of type \"%s\" does not implement required virtual"
 
249
                 " function \"embed_widget_in_header\",",
 
250
                 G_OBJECT_TYPE_NAME (shell));
 
251
    }
 
252
  else
 
253
    {
 
254
      class->embed_widget_in_header (shell, widget);
 
255
    }
 
256
}