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

« back to all changes in this revision

Viewing changes to panels/keyboard/cc-keyboard-panel.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
/*
 
2
 * Copyright (C) 2010 Intel, Inc
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 *
 
18
 * Author: Thomas Wood <thomas.wood@intel.com>
 
19
 *
 
20
 */
 
21
 
 
22
#include "cc-keyboard-panel.h"
 
23
#include "keyboard-general.h"
 
24
#include "keyboard-shortcuts.h"
 
25
 
 
26
CC_PANEL_REGISTER (CcKeyboardPanel, cc_keyboard_panel)
 
27
 
 
28
#define KEYBOARD_PANEL_PRIVATE(o) \
 
29
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_KEYBOARD_PANEL, CcKeyboardPanelPrivate))
 
30
 
 
31
struct _CcKeyboardPanelPrivate
 
32
{
 
33
  GtkBuilder *builder;
 
34
};
 
35
 
 
36
 
 
37
static void
 
38
cc_keyboard_panel_get_property (GObject    *object,
 
39
                               guint       property_id,
 
40
                               GValue     *value,
 
41
                               GParamSpec *pspec)
 
42
{
 
43
  switch (property_id)
 
44
    {
 
45
    default:
 
46
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
47
    }
 
48
}
 
49
 
 
50
enum {
 
51
  PROP_0,
 
52
  PROP_ARGV
 
53
};
 
54
 
 
55
enum {
 
56
  TYPING_PAGE,
 
57
  SHORTCUTS_PAGE
 
58
};
 
59
 
 
60
static void
 
61
cc_keyboard_panel_set_page (CcKeyboardPanel *panel,
 
62
                            const gchar     *page,
 
63
                            const gchar     *section)
 
64
{
 
65
  GtkWidget *notebook;
 
66
  gint page_num;
 
67
 
 
68
  if (g_strcmp0 (page, "typing") == 0)
 
69
    page_num = TYPING_PAGE;
 
70
  else if (g_strcmp0 (page, "shortcuts") == 0)
 
71
    page_num = SHORTCUTS_PAGE;
 
72
  else {
 
73
    g_warning ("Could not switch to non-existent page '%s'", page);
 
74
    return;
 
75
  }
 
76
 
 
77
  notebook = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "keyboard_notebook"));
 
78
  gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num);
 
79
 
 
80
  if (page_num == SHORTCUTS_PAGE &&
 
81
      section != NULL) {
 
82
    keyboard_shortcuts_set_section (CC_PANEL (panel), section);
 
83
  }
 
84
}
 
85
 
 
86
static void
 
87
cc_keyboard_panel_set_property (GObject      *object,
 
88
                               guint         property_id,
 
89
                               const GValue *value,
 
90
                               GParamSpec   *pspec)
 
91
{
 
92
  CcKeyboardPanel *panel = CC_KEYBOARD_PANEL (object);
 
93
 
 
94
  switch (property_id)
 
95
    {
 
96
    case PROP_ARGV: {
 
97
      gchar **args;
 
98
 
 
99
      args = g_value_get_boxed (value);
 
100
 
 
101
      if (args && args[0]) {
 
102
        cc_keyboard_panel_set_page (panel, args[0], args[1]);
 
103
      }
 
104
      break;
 
105
    }
 
106
 
 
107
    default:
 
108
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
109
    }
 
110
}
 
111
 
 
112
static GObject *
 
113
cc_keyboard_panel_constructor (GType                  gtype,
 
114
                               guint                  n_properties,
 
115
                               GObjectConstructParam *properties)
 
116
{
 
117
  GObject *obj;
 
118
  CcKeyboardPanel *self;
 
119
  CcKeyboardPanelPrivate *priv;
 
120
  GtkWidget *widget;
 
121
 
 
122
  obj = G_OBJECT_CLASS (cc_keyboard_panel_parent_class)->constructor (gtype, n_properties, properties);
 
123
 
 
124
  self = CC_KEYBOARD_PANEL (obj);
 
125
  priv = self->priv;
 
126
 
 
127
  keyboard_general_init (CC_PANEL (self), priv->builder);
 
128
  keyboard_shortcuts_init (CC_PANEL (self), priv->builder);
 
129
 
 
130
  widget = (GtkWidget *) gtk_builder_get_object (priv->builder,
 
131
                                                 "keyboard_notebook");
 
132
 
 
133
  gtk_widget_reparent (widget, (GtkWidget *) self);
 
134
 
 
135
  return obj;
 
136
}
 
137
 
 
138
static const char *
 
139
cc_keyboard_panel_get_help_uri (CcPanel *panel)
 
140
{
 
141
  return "help:gnome-help/keyboard";
 
142
}
 
143
 
 
144
static void
 
145
cc_keyboard_panel_dispose (GObject *object)
 
146
{
 
147
  keyboard_general_dispose (CC_PANEL (object));
 
148
  keyboard_shortcuts_dispose (CC_PANEL (object));
 
149
 
 
150
  G_OBJECT_CLASS (cc_keyboard_panel_parent_class)->dispose (object);
 
151
}
 
152
 
 
153
static void
 
154
cc_keyboard_panel_finalize (GObject *object)
 
155
{
 
156
  CcKeyboardPanel *panel = CC_KEYBOARD_PANEL (object);
 
157
 
 
158
  if (panel->priv->builder)
 
159
    g_object_unref (panel->priv->builder);
 
160
 
 
161
  G_OBJECT_CLASS (cc_keyboard_panel_parent_class)->finalize (object);
 
162
}
 
163
 
 
164
static void
 
165
cc_keyboard_panel_class_init (CcKeyboardPanelClass *klass)
 
166
{
 
167
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
168
  CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
 
169
 
 
170
  g_type_class_add_private (klass, sizeof (CcKeyboardPanelPrivate));
 
171
 
 
172
  panel_class->get_help_uri = cc_keyboard_panel_get_help_uri;
 
173
 
 
174
  object_class->constructor = cc_keyboard_panel_constructor;
 
175
  object_class->get_property = cc_keyboard_panel_get_property;
 
176
  object_class->set_property = cc_keyboard_panel_set_property;
 
177
  object_class->dispose = cc_keyboard_panel_dispose;
 
178
  object_class->finalize = cc_keyboard_panel_finalize;
 
179
 
 
180
  g_object_class_override_property (object_class, PROP_ARGV, "argv");
 
181
}
 
182
 
 
183
static void
 
184
cc_keyboard_panel_init (CcKeyboardPanel *self)
 
185
{
 
186
  const gchar *uifile = GNOMECC_UI_DIR "/gnome-keyboard-panel.ui";
 
187
  CcKeyboardPanelPrivate *priv;
 
188
  GError *error = NULL;
 
189
 
 
190
  priv = self->priv = KEYBOARD_PANEL_PRIVATE (self);
 
191
 
 
192
  priv->builder = gtk_builder_new ();
 
193
 
 
194
  if (gtk_builder_add_from_file (priv->builder, uifile, &error) == 0)
 
195
    {
 
196
      g_warning ("Could not load UI: %s", error->message);
 
197
      g_clear_error (&error);
 
198
      g_object_unref (priv->builder);
 
199
      priv->builder = NULL;
 
200
    }
 
201
}
 
202
 
 
203
void
 
204
cc_keyboard_panel_register (GIOModule *module)
 
205
{
 
206
  cc_keyboard_panel_register_type (G_TYPE_MODULE (module));
 
207
  g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
 
208
                                  CC_TYPE_KEYBOARD_PANEL,
 
209
                                  "keyboard", 0);
 
210
}
 
211