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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 | /*
* This file is part of the Control Center.
*
* Copyright (c) 2006 Novell, Inc.
*
* The Control Center 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 of the License, or (at your option)
* any later version.
*
* The Control Center 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
* the Control Center; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <glib/gi18n.h>
#include <ctk/ctk.h>
#include <gio/gio.h>
#include <libslab/slab.h>
void handle_static_action_clicked(Tile* tile, TileEvent* event, gpointer data);
static GSList* get_actions_list();
#define CONTROL_CENTER_SCHEMA "org.cafe.control-center"
#define CONTROL_CENTER_ACTIONS_LIST_KEY "cc-actions-list"
#define CONTROL_CENTER_ACTIONS_SEPARATOR ";"
#define EXIT_SHELL_ON_STATIC_ACTION "cc-exit-shell-on-static-action"
static GSList* get_actions_list(void)
{
GSettings *settings;
GSList* l;
GSList* key_list = NULL;
GSList* actions_list = NULL;
AppAction* action;<--- The scope of the variable 'action' can be reduced. [+]The scope of the variable 'action' 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.
gchar **array;
gint i;
settings = g_settings_new (CONTROL_CENTER_SCHEMA);
array = g_settings_get_strv (settings, CONTROL_CENTER_ACTIONS_LIST_KEY);
if (array != NULL) {
for (i = 0; array[i]; i++) {
key_list = g_slist_append (key_list, g_strdup (array[i]));
}
}
g_strfreev (array);
g_object_unref (settings);
if (!key_list)
{
g_warning(_("%s key is empty\n"), CONTROL_CENTER_ACTIONS_LIST_KEY);
return NULL;
}
for (l = key_list; l != NULL; l = l->next)
{
gchar* entry = (gchar*) l->data;
gchar** temp;
action = g_new(AppAction, 1);
temp = g_strsplit(entry, CONTROL_CENTER_ACTIONS_SEPARATOR, 2);
action->name = g_strdup(temp[0]);
if ((action->item = load_desktop_item_from_unknown(temp[1])) == NULL)
{
g_free (action->name);
g_free (action);
g_warning("get_actions_list() - PROBLEM - Can't load %s\n", temp[1]);
}
else
{
actions_list = g_slist_prepend(actions_list, action);
}
g_strfreev(temp);
g_free(entry);
}
g_slist_free(key_list);
return g_slist_reverse(actions_list);
}
void handle_static_action_clicked(Tile* tile, TileEvent* event, gpointer data)<--- Parameter 'event' can be declared as pointer to const
{
AppShellData* app_data = (AppShellData*) data;
CafeDesktopItem* item = (CafeDesktopItem*) g_object_get_data(G_OBJECT(tile), APP_ACTION_KEY);
GSettings *settings;
GApplication *app;<--- The scope of the variable 'app' can be reduced. [+]The scope of the variable 'app' 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.
if (event->type == TILE_EVENT_ACTIVATED_DOUBLE_CLICK)
{
return;
}
open_desktop_item_exec(item);
settings = g_settings_new (CONTROL_CENTER_SCHEMA);
if (g_settings_get_boolean(settings, EXIT_SHELL_ON_STATIC_ACTION))
{
if (app_data->exit_on_close)
{
app=g_application_get_default();
g_application_quit(app);
}
else
{
hide_shell(app_data);
}
}
g_object_unref(settings);
}
static void
activate (CtkApplication *app)
{
GList *list;
GSList* actions;
gboolean hidden = FALSE;
list = ctk_application_get_windows (app);
AppShellData* app_data = appshelldata_new("cafecc.menu", CTK_ICON_SIZE_DND, FALSE, TRUE, 0);
generate_categories(app_data);
actions = get_actions_list();
layout_shell(app_data, _("Filter"), _("Groups"), _("Common Tasks"), actions, handle_static_action_clicked);<--- You might need to cast the function pointer here
if (list)
{
ctk_window_present (CTK_WINDOW (list->data));
}
else
{
create_main_window(app_data, "MyControlCenter", _("Control Center"), "preferences-desktop", 975, 600, hidden);
ctk_application_add_window (app, CTK_WINDOW(app_data->main_app));
}
}
static void
quit (GApplication *app)
{
g_application_quit(app);
}
int main(int argc, char* argv[])
{
gboolean hidden = FALSE;
CtkApplication *app;
gint retval;
app = ctk_application_new ("org.cafe.cafe-control-center.shell", 0);
GError* error;
GOptionEntry options[] = {
{"hide", 0, 0, G_OPTION_ARG_NONE, &hidden, N_("Hide on start (useful to preload the shell)"), NULL},
{NULL}
};
#ifdef ENABLE_NLS
bindtextdomain(GETTEXT_PACKAGE, CAFELOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
#endif
error = NULL;
if (!ctk_init_with_args(&argc, &argv, NULL, options, GETTEXT_PACKAGE, &error))
{
g_printerr("%s\n", error->message);
g_error_free(error);
return 1;
}
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
g_signal_connect (app, "window-removed", G_CALLBACK (quit), NULL);
retval = g_application_run (G_APPLICATION (app), argc, argv);
return retval;
}
|