1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 | /* -*- mode: c; style: linux -*- */
/* cafe-keyboard-properties-xkbpv.c
* Copyright (C) 2003-2007 Sergey V. Udaltsov
*
* Written by: Sergey V. Udaltsov <svu@gnome.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <libcafekbd/cafekbd-keyboard-drawing.h>
#include "capplet-util.h"
#include "cafe-keyboard-properties-xkb.h"
#ifdef HAVE_X11_EXTENSIONS_XKB_H
#include "X11/XKBlib.h"
/**
* BAD STYLE: Taken from xklavier_private_xkb.h
* Any ideas on architectural improvements are WELCOME
*/
extern gboolean xkl_xkb_config_native_prepare (XklEngine * engine,
const XklConfigRec * data,
XkbComponentNamesPtr
component_names);
extern void xkl_xkb_config_native_cleanup (XklEngine * engine,
XkbComponentNamesPtr
component_names);
/* */
#endif
static CafekbdKeyboardDrawingGroupLevel groupsLevels[] =
{ {0, 1}, {0, 3}, {0, 0}, {0, 2} };
static CafekbdKeyboardDrawingGroupLevel *pGroupsLevels[] = {
groupsLevels, groupsLevels + 1, groupsLevels + 2, groupsLevels + 3
};
CtkWidget *
xkb_layout_preview_create_widget (CtkBuilder * chooserDialog)
{
CtkWidget *kbdraw = cafekbd_keyboard_drawing_new ();
cafekbd_keyboard_drawing_set_groups_levels (CAFEKBD_KEYBOARD_DRAWING
(kbdraw), pGroupsLevels);
return kbdraw;
}
void
xkb_layout_preview_update (CtkBuilder * chooser_dialog)
{
#ifdef HAVE_X11_EXTENSIONS_XKB_H
CtkWidget *chooser = CWID ("xkb_layout_chooser");
CtkWidget *kbdraw =
CTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
gchar *id = xkb_layout_chooser_get_selected_id (chooser_dialog);
xkb_layout_preview_set_drawing_layout (kbdraw, id);
g_free (id);
#endif
}
void
xkb_layout_preview_set_drawing_layout (CtkWidget * kbdraw,
const gchar * id)
{
#ifdef HAVE_X11_EXTENSIONS_XKB_H
if (kbdraw != NULL) {
if (id != NULL) {
XklConfigRec *data;
char **p, *layout, *variant;<--- The scope of the variable 'p' can be reduced. [+]The scope of the variable 'p' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
XkbComponentNamesRec component_names;
data = xkl_config_rec_new ();
if (xkl_config_rec_get_from_server (data, engine)) {
if ((p = data->layouts) != NULL)
g_strfreev (data->layouts);
if ((p = data->variants) != NULL)<--- Variable 'p' is assigned a value that is never used.
g_strfreev (data->variants);
data->layouts = g_new0 (char *, 2);
data->variants = g_new0 (char *, 2);
if (cafekbd_keyboard_config_split_items
(id, &layout, &variant)
&& variant != NULL) {
data->layouts[0] =
(layout ==
NULL) ? NULL :
g_strdup (layout);
data->variants[0] =
(variant ==<--- Condition 'variant==NULL' is always false
NULL) ? NULL :
g_strdup (variant);
} else {
data->layouts[0] =
(id ==
NULL) ? NULL : g_strdup (id);
data->variants[0] = NULL;
}
if (xkl_xkb_config_native_prepare
(engine, data, &component_names)) {
cafekbd_keyboard_drawing_set_keyboard
(CAFEKBD_KEYBOARD_DRAWING
(kbdraw), &component_names);
xkl_xkb_config_native_cleanup
(engine, &component_names);
}
}
g_object_unref (G_OBJECT (data));
} else
cafekbd_keyboard_drawing_set_keyboard
(CAFEKBD_KEYBOARD_DRAWING (kbdraw), NULL);
}
#endif
}
|