Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright © 2018 Canonical Ltd. |
3 |
|
|
* |
4 |
|
|
* This program is free software; you can redistribute it and/or |
5 |
|
|
* modify it under the terms of the GNU General Public License as |
6 |
|
|
* published by the Free Software Foundation; either version 2 of the |
7 |
|
|
* License, or (at your option) any later version. |
8 |
|
|
* |
9 |
|
|
* This program is distributed in the hope that it will be useful, but |
10 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
|
|
* 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, see <http://www.gnu.org/licenses/>. |
16 |
|
|
*/ |
17 |
|
|
|
18 |
|
|
#include <config.h> |
19 |
|
|
#include "cc-input-source-xkb.h" |
20 |
|
|
|
21 |
|
|
struct _CcInputSourceXkb |
22 |
|
|
{ |
23 |
|
|
CcInputSource parent_instance; |
24 |
|
|
|
25 |
|
|
GnomeXkbInfo *xkb_info; |
26 |
|
|
gchar *layout; |
27 |
|
|
gchar *variant; |
28 |
|
|
}; |
29 |
|
|
|
30 |
|
✗ |
G_DEFINE_TYPE (CcInputSourceXkb, cc_input_source_xkb, CC_TYPE_INPUT_SOURCE) |
31 |
|
|
|
32 |
|
|
static gchar * |
33 |
|
✗ |
cc_input_source_xkb_get_label (CcInputSource *source) |
34 |
|
|
{ |
35 |
|
✗ |
CcInputSourceXkb *self = CC_INPUT_SOURCE_XKB (source); |
36 |
|
✗ |
g_autofree gchar *id = NULL; |
37 |
|
|
const gchar *name; |
38 |
|
|
|
39 |
|
✗ |
id = cc_input_source_xkb_get_id (self); |
40 |
|
✗ |
gnome_xkb_info_get_layout_info (self->xkb_info, id, &name, NULL, NULL, NULL); |
41 |
|
✗ |
if (name) |
42 |
|
✗ |
return g_strdup (name); |
43 |
|
|
else |
44 |
|
✗ |
return g_strdup (id); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
static gboolean |
48 |
|
✗ |
cc_input_source_xkb_matches (CcInputSource *source, |
49 |
|
|
CcInputSource *source2) |
50 |
|
|
{ |
51 |
|
✗ |
if (!CC_IS_INPUT_SOURCE_XKB (source2)) |
52 |
|
✗ |
return FALSE; |
53 |
|
|
|
54 |
|
✗ |
return g_strcmp0 (CC_INPUT_SOURCE_XKB (source)->layout, CC_INPUT_SOURCE_XKB (source2)->layout) == 0 && |
55 |
|
✗ |
g_strcmp0 (CC_INPUT_SOURCE_XKB (source)->variant, CC_INPUT_SOURCE_XKB (source2)->variant) == 0; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
static void |
59 |
|
✗ |
cc_input_source_xkb_dispose (GObject *object) |
60 |
|
|
{ |
61 |
|
✗ |
CcInputSourceXkb *self = CC_INPUT_SOURCE_XKB (object); |
62 |
|
|
|
63 |
|
✗ |
g_clear_object (&self->xkb_info); |
64 |
|
✗ |
g_clear_pointer (&self->layout, g_free); |
65 |
|
✗ |
g_clear_pointer (&self->variant, g_free); |
66 |
|
|
|
67 |
|
✗ |
G_OBJECT_CLASS (cc_input_source_xkb_parent_class)->dispose (object); |
68 |
|
✗ |
} |
69 |
|
|
|
70 |
|
|
static const gchar * |
71 |
|
✗ |
cc_input_source_xkb_get_layout (CcInputSource *source) |
72 |
|
|
{ |
73 |
|
✗ |
return CC_INPUT_SOURCE_XKB (source)->layout; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
static const gchar * |
77 |
|
✗ |
cc_input_source_xkb_get_layout_variant (CcInputSource *source) |
78 |
|
|
{ |
79 |
|
✗ |
return CC_INPUT_SOURCE_XKB (source)->variant; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
void |
83 |
|
✗ |
cc_input_source_xkb_class_init (CcInputSourceXkbClass *klass) |
84 |
|
|
{ |
85 |
|
✗ |
CcInputSourceClass *input_source_class = CC_INPUT_SOURCE_CLASS (klass); |
86 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
87 |
|
|
|
88 |
|
✗ |
input_source_class->get_label = cc_input_source_xkb_get_label; |
89 |
|
✗ |
input_source_class->matches = cc_input_source_xkb_matches; |
90 |
|
✗ |
input_source_class->get_layout = cc_input_source_xkb_get_layout; |
91 |
|
✗ |
input_source_class->get_layout_variant = cc_input_source_xkb_get_layout_variant; |
92 |
|
✗ |
object_class->dispose = cc_input_source_xkb_dispose; |
93 |
|
✗ |
} |
94 |
|
|
|
95 |
|
|
void |
96 |
|
✗ |
cc_input_source_xkb_init (CcInputSourceXkb *source) |
97 |
|
|
{ |
98 |
|
✗ |
} |
99 |
|
|
|
100 |
|
|
CcInputSourceXkb * |
101 |
|
✗ |
cc_input_source_xkb_new (GnomeXkbInfo *xkb_info, |
102 |
|
|
const gchar *layout, |
103 |
|
|
const gchar *variant) |
104 |
|
|
{ |
105 |
|
|
CcInputSourceXkb *source; |
106 |
|
|
|
107 |
|
✗ |
source = g_object_new (CC_TYPE_INPUT_SOURCE_XKB, NULL); |
108 |
|
✗ |
source->xkb_info = g_object_ref (xkb_info); |
109 |
|
✗ |
source->layout = g_strdup (layout); |
110 |
|
✗ |
source->variant = g_strdup (variant); |
111 |
|
|
|
112 |
|
✗ |
return source; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
CcInputSourceXkb * |
116 |
|
✗ |
cc_input_source_xkb_new_from_id (GnomeXkbInfo *xkb_info, |
117 |
|
|
const gchar *id) |
118 |
|
|
{ |
119 |
|
✗ |
g_auto(GStrv) tokens = NULL; |
120 |
|
|
|
121 |
|
✗ |
tokens = g_strsplit (id, "+", 2); |
122 |
|
|
|
123 |
|
✗ |
return cc_input_source_xkb_new (xkb_info, tokens[0], tokens[1]); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
gchar * |
127 |
|
✗ |
cc_input_source_xkb_get_id (CcInputSourceXkb *source) |
128 |
|
|
{ |
129 |
|
✗ |
g_return_val_if_fail (CC_IS_INPUT_SOURCE_XKB (source), NULL); |
130 |
|
✗ |
if (source->variant != NULL) |
131 |
|
✗ |
return g_strdup_printf ("%s+%s", source->layout, source->variant); |
132 |
|
|
else |
133 |
|
✗ |
return g_strdup (source->layout); |
134 |
|
|
} |
135 |
|
|
|