diff options
author | Colomban Wendling <[email protected]> | 2023-11-15 15:10:11 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2024-02-04 18:37:58 +0100 |
commit | 62fabfc793b545250dafaf37f75650cbfdce095f (patch) | |
tree | 813bd86b3926f24be1f17a1830f2f3d65fd4ec8a | |
parent | f98be9734446e1b620312b69dc8fa8ed0f0997d9 (diff) | |
download | mate-panel-62fabfc793b545250dafaf37f75650cbfdce095f.tar.bz2 mate-panel-62fabfc793b545250dafaf37f75650cbfdce095f.tar.xz |
Reduce scope of variables
Mostly found by cppcheck.
origin commit was:
https://github.com/mate-desktop/mate-panel/commit/96c7ebc
-rw-r--r-- | applets/clock/calendar-window.c | 4 | ||||
-rw-r--r-- | applets/clock/clock.c | 15 | ||||
-rw-r--r-- | applets/notification_area/na-grid.c | 5 | ||||
-rw-r--r-- | applets/notification_area/status-notifier/sn-host-v0.c | 3 | ||||
-rw-r--r-- | applets/notification_area/status-notifier/sn-item-v0.c | 3 | ||||
-rw-r--r-- | applets/notification_area/system-tray/na-tray-manager.c | 3 | ||||
-rw-r--r-- | libmate-panel-applet/mate-panel-applet-gsettings.c | 8 | ||||
-rw-r--r-- | mate-panel/button-widget.c | 6 | ||||
-rw-r--r-- | mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c | 13 | ||||
-rw-r--r-- | mate-panel/libpanel-util/panel-color.c | 8 | ||||
-rw-r--r-- | mate-panel/libpanel-util/panel-gtk.c | 3 | ||||
-rw-r--r-- | mate-panel/libpanel-util/panel-keyfile.c | 5 | ||||
-rw-r--r-- | mate-panel/mate-desktop-item-edit.c | 3 | ||||
-rw-r--r-- | mate-panel/panel-lockdown.c | 8 | ||||
-rw-r--r-- | mate-panel/panel-menu-items.c | 24 | ||||
-rw-r--r-- | mate-panel/panel-multimonitor.c | 3 | ||||
-rw-r--r-- | mate-panel/panel-profile.c | 4 | ||||
-rw-r--r-- | mate-panel/panel-test-applets.c | 5 | ||||
-rw-r--r-- | mate-panel/panel-widget.c | 2 |
19 files changed, 55 insertions, 70 deletions
diff --git a/applets/clock/calendar-window.c b/applets/clock/calendar-window.c index cf6ef670..b4157344 100644 --- a/applets/clock/calendar-window.c +++ b/applets/clock/calendar-window.c @@ -543,8 +543,6 @@ void calendar_window_set_show_weeks (CalendarWindow *calwin, gboolean show_weeks) { - GtkCalendarDisplayOptions options; - g_return_if_fail (CALENDAR_IS_WINDOW (calwin)); if (show_weeks == calwin->priv->show_weeks) @@ -553,6 +551,8 @@ calendar_window_set_show_weeks (CalendarWindow *calwin, calwin->priv->show_weeks = show_weeks; if (calwin->priv->calendar) { + GtkCalendarDisplayOptions options; + options = gtk_calendar_get_display_options (GTK_CALENDAR (calwin->priv->calendar)); if (show_weeks) diff --git a/applets/clock/clock.c b/applets/clock/clock.c index 309d4884..f97e56af 100644 --- a/applets/clock/clock.c +++ b/applets/clock/clock.c @@ -2219,9 +2219,6 @@ location_set_current_cb (ClockLocation *loc, static void locations_changed (ClockData *cd) { - GSList *l; - glong id; - if (!cd->locations) { if (cd->weather_obox) gtk_widget_hide (cd->weather_obox); @@ -2236,8 +2233,9 @@ locations_changed (ClockData *cd) gtk_widget_show (cd->weather_obox); } - for (l = cd->locations; l; l = l->next) { + for (GSList *l = cd->locations; l; l = l->next) { ClockLocation *loc = l->data; + glong id; id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (loc), "weather-updated")); if (id == 0) { @@ -2514,7 +2512,6 @@ setup_gsettings (ClockData *cd) static GSList * parse_gsettings_cities (ClockData *cd, gchar **values) { - gint i; LocationParserData data; GMarkupParseContext *context; @@ -2524,7 +2521,7 @@ parse_gsettings_cities (ClockData *cd, gchar **values) context = g_markup_parse_context_new (&location_parser, 0, &data, NULL); if (values) { - for (i = 0; values[i]; i++) { + for (gint i = 0; values[i]; i++) { g_markup_parse_context_parse (context, values[i], strlen(values[i]), NULL); } } @@ -2589,11 +2586,11 @@ system_manager_signal_cb (GDBusProxy *proxy, GVariant *parameters, ClockData *cd) { - GVariant *variant; - gboolean active; - if (g_strcmp0 (signal_name, "PrepareForSleep") == 0) { + GVariant *variant; + gboolean active; + variant = g_variant_get_child_value (parameters, 0); active = g_variant_get_boolean (variant); g_variant_unref (variant); diff --git a/applets/notification_area/na-grid.c b/applets/notification_area/na-grid.c index 9698be6c..9a4c45d9 100644 --- a/applets/notification_area/na-grid.c +++ b/applets/notification_area/na-grid.c @@ -317,8 +317,6 @@ na_grid_realize (GtkWidget *widget) NaGrid *self = NA_GRID (widget); GdkScreen *screen; GdkDisplay *display; - GtkOrientation orientation; - NaHost *tray_host; GSettings *settings; GTK_WIDGET_CLASS (na_grid_parent_class)->realize (widget); @@ -328,6 +326,9 @@ na_grid_realize (GtkWidget *widget) screen = gtk_widget_get_screen (GTK_WIDGET (self)); if (GDK_IS_X11_DISPLAY (display)) { + GtkOrientation orientation; + NaHost *tray_host; + orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (self)); tray_host = na_tray_new_for_screen (screen, orientation); g_object_bind_property (self, "orientation", diff --git a/applets/notification_area/status-notifier/sn-host-v0.c b/applets/notification_area/status-notifier/sn-host-v0.c index 64da5da9..4ad6b359 100644 --- a/applets/notification_area/status-notifier/sn-host-v0.c +++ b/applets/notification_area/status-notifier/sn-host-v0.c @@ -193,7 +193,6 @@ register_host_cb (GObject *source_object, GError *error; SnHostV0 *v0; gchar **items; - gint i; error = NULL; sn_watcher_v0_gen_call_register_host_finish (SN_WATCHER_V0_GEN (source_object), @@ -224,7 +223,7 @@ register_host_cb (GObject *source_object, items = sn_watcher_v0_gen_dup_registered_items (v0->watcher); if (items) { - for (i = 0; items[i] != NULL; i++) + for (gint i = 0; items[i] != NULL; i++) add_registered_item (v0, items[i]); } diff --git a/applets/notification_area/status-notifier/sn-item-v0.c b/applets/notification_area/status-notifier/sn-item-v0.c index fd963c31..9deab9d3 100644 --- a/applets/notification_area/status-notifier/sn-item-v0.c +++ b/applets/notification_area/status-notifier/sn-item-v0.c @@ -244,7 +244,6 @@ update (SnItemV0 *v0) GtkImage *image; SnTooltip *tip; gint icon_size; - gboolean visible; const gchar *icon_name; SnIconPixmap **icon_pixmap; @@ -362,7 +361,7 @@ update (SnItemV0 *v0) /* TODO: hide "Passive" items with a setting? */ /*Special case mate-polkit*/ if (g_strcmp0 (v0->status, "password-dialog") != 0){ - visible = g_strcmp0 (v0->status, "Passive") != 0; + gboolean visible = g_strcmp0 (v0->status, "Passive") != 0; gtk_widget_set_visible (GTK_WIDGET (v0), visible); } else diff --git a/applets/notification_area/system-tray/na-tray-manager.c b/applets/notification_area/system-tray/na-tray-manager.c index d4f27ff3..2bb679d8 100644 --- a/applets/notification_area/system-tray/na-tray-manager.c +++ b/applets/notification_area/system-tray/na-tray-manager.c @@ -537,7 +537,6 @@ na_tray_manager_unmanage (NaTrayManager *manager) { #ifdef GDK_WINDOWING_X11 GdkDisplay *display; - guint32 timestamp; GtkWidget *invisible; GdkWindow *window; @@ -556,7 +555,7 @@ na_tray_manager_unmanage (NaTrayManager *manager) if (gdk_selection_owner_get_for_display (display, manager->selection_atom) == window) { - timestamp = gdk_x11_get_server_time (window); + guint32 timestamp = gdk_x11_get_server_time (window); gdk_selection_owner_set_for_display (display, NULL, manager->selection_atom, diff --git a/libmate-panel-applet/mate-panel-applet-gsettings.c b/libmate-panel-applet/mate-panel-applet-gsettings.c index a4bd3db1..82867639 100644 --- a/libmate-panel-applet/mate-panel-applet-gsettings.c +++ b/libmate-panel-applet/mate-panel-applet-gsettings.c @@ -149,9 +149,9 @@ void mate_panel_applet_settings_set_glist (GSettings *settings, gchar *key, GList *list) { GArray *array; - GList *l; + array = g_array_new (TRUE, TRUE, sizeof (gchar *)); - for (l = list; l; l = l->next) { + for (GList *l = list; l; l = l->next) { array = g_array_append_val (array, l->data); } g_settings_set_strv (settings, key, (const gchar **) array->data); @@ -178,9 +178,9 @@ void mate_panel_applet_settings_set_gslist (GSettings *settings, gchar *key, GSList *list) { GArray *array; - GSList *l; + array = g_array_new (TRUE, TRUE, sizeof (gchar *)); - for (l = list; l; l = l->next) { + for (GSList *l = list; l; l = l->next) { array = g_array_append_val (array, l->data); } g_settings_set_strv (settings, key, (const gchar **) array->data); diff --git a/mate-panel/button-widget.c b/mate-panel/button-widget.c index 43d432a9..00753b99 100644 --- a/mate-panel/button-widget.c +++ b/mate-panel/button-widget.c @@ -161,8 +161,6 @@ button_widget_unset_surfaces (ButtonWidget *button) static void button_widget_reload_surface (ButtonWidget *button) { - GdkDisplay *display; - gint scale; button_widget_unset_surfaces (button); button->priv->needs_move = FALSE; @@ -170,7 +168,9 @@ button_widget_reload_surface (ButtonWidget *button) return; if (button->priv->filename != NULL && button->priv->filename [0] != '\0') { - char *error = NULL; + GdkDisplay *display; + gint scale; + char *error = NULL; /* icons findable in the icon theme can be handled by gtk directly*/ display = gdk_display_get_default (); scale = gtk_widget_get_scale_factor (GTK_WIDGET (button)); diff --git a/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c index 115919b0..b65fe4a7 100644 --- a/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c +++ b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c @@ -159,7 +159,6 @@ mate_panel_applets_manager_get_applet_factory_info_from_file (const gchar *filen { MatePanelAppletFactoryInfo *info; GKeyFile *applet_file; - const char *lib_prefix; gchar **groups; gsize n_groups; gsize i; @@ -189,6 +188,8 @@ mate_panel_applets_manager_get_applet_factory_info_from_file (const gchar *filen info->in_process = g_key_file_get_boolean (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, "InProcess", NULL); if (info->in_process) { + const char *lib_prefix; + info->location = g_key_file_get_string (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP, "Location", NULL); if (!info->location) { @@ -335,15 +336,15 @@ applets_directory_changed (GFileMonitor *monitor, static void mate_panel_applets_manager_dbus_load_applet_infos (MatePanelAppletsManagerDBus *manager) { - GSList *dirs, *d; - GDir *dir; - const gchar *dirent; - GError *error = NULL; + GSList *dirs; dirs = mate_panel_applets_manager_get_applets_dirs (); - for (d = dirs; d; d = g_slist_next (d)) { + for (GSList *d = dirs; d; d = g_slist_next (d)) { + GDir *dir; + const gchar *dirent; GFileMonitor *monitor; GFile *dir_file; + GError *error = NULL; gchar *path = (gchar *) d->data; dir = g_dir_open (path, 0, &error); diff --git a/mate-panel/libpanel-util/panel-color.c b/mate-panel/libpanel-util/panel-color.c index f6148aaa..661e6fb5 100644 --- a/mate-panel/libpanel-util/panel-color.c +++ b/mate-panel/libpanel-util/panel-color.c @@ -17,7 +17,6 @@ rgb_to_hls (gdouble *r, gdouble *g, gdouble *b) gdouble green; gdouble blue; gdouble h, l, s; - gdouble delta; red = *r; green = *g; @@ -50,6 +49,8 @@ rgb_to_hls (gdouble *r, gdouble *g, gdouble *b) h = 0; if (max != min) { + gdouble delta; + if (l <= 0.5) s = (max - min) / (max + min); else @@ -84,11 +85,9 @@ rgb_to_hls (gdouble *r, gdouble *g, gdouble *b) static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s) { - gdouble hue; gdouble lightness; gdouble saturation; gdouble m1, m2; - gdouble r, g, b; lightness = *l; saturation = *s; @@ -104,6 +103,9 @@ hls_to_rgb (gdouble *h, gdouble *l, gdouble *s) *l = lightness; *s = lightness; } else { + gdouble hue; + gdouble r, g, b; + hue = *h + 120; while (hue > 360) hue -= 360; diff --git a/mate-panel/libpanel-util/panel-gtk.c b/mate-panel/libpanel-util/panel-gtk.c index d638d75d..3672fca8 100644 --- a/mate-panel/libpanel-util/panel-gtk.c +++ b/mate-panel/libpanel-util/panel-gtk.c @@ -119,7 +119,6 @@ panel_file_chooser_dialog_new_valist (const gchar *title, { GtkWidget *result; const char *button_text = first_button_text; - gint response_id; result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "title", title, @@ -131,7 +130,7 @@ panel_file_chooser_dialog_new_valist (const gchar *title, while (button_text) { - response_id = va_arg (varargs, gint); + gint response_id = va_arg (varargs, gint); if (g_strcmp0 (button_text, "process-stop") == 0) panel_dialog_add_button (GTK_DIALOG (result), _("_Cancel"), button_text, response_id); diff --git a/mate-panel/libpanel-util/panel-keyfile.c b/mate-panel/libpanel-util/panel-keyfile.c index 0b0104ef..b98058c3 100644 --- a/mate-panel/libpanel-util/panel-keyfile.c +++ b/mate-panel/libpanel-util/panel-keyfile.c @@ -53,8 +53,6 @@ _panel_key_file_make_executable (const gchar *path) { GFile *file; GFileInfo *info; - guint32 current_perms; - guint32 new_perms; file = g_file_new_for_path (path); @@ -72,6 +70,9 @@ _panel_key_file_make_executable (const gchar *path) } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) { + guint32 current_perms; + guint32 new_perms; + current_perms = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE); new_perms = current_perms | S_IXGRP | S_IXUSR | S_IXOTH; diff --git a/mate-panel/mate-desktop-item-edit.c b/mate-panel/mate-desktop-item-edit.c index b0912405..b37f43ed 100644 --- a/mate-panel/mate-desktop-item-edit.c +++ b/mate-panel/mate-desktop-item-edit.c @@ -123,7 +123,6 @@ main (int argc, char * argv[]) for (i = 0; desktops[i] != NULL; i++) { GFile *file; GFileInfo *info; - GFileType type; char *uri; char *path; GtkWidget *dlg = NULL; @@ -136,7 +135,7 @@ main (int argc, char * argv[]) g_object_unref (file); if (info) { - type = g_file_info_get_file_type (info); + GFileType type = g_file_info_get_file_type (info); if (type == G_FILE_TYPE_DIRECTORY && create_new) { diff --git a/mate-panel/panel-lockdown.c b/mate-panel/panel-lockdown.c index 16648ee3..8750be81 100644 --- a/mate-panel/panel-lockdown.c +++ b/mate-panel/panel-lockdown.c @@ -269,12 +269,10 @@ panel_lockdown_get_disable_force_quit (void) gboolean panel_lockdown_is_applet_disabled (const char *iid) { - gint i; - g_assert (panel_lockdown.initialized != FALSE); if (panel_lockdown.disabled_applets) - for (i = 0; panel_lockdown.disabled_applets[i]; i++) + for (gint i = 0; panel_lockdown.disabled_applets[i]; i++) if (!strcmp (panel_lockdown.disabled_applets[i], iid)) return TRUE; @@ -286,9 +284,7 @@ panel_lockdown_notify_find (GSList *closures, GCallback callback_func, gpointer user_data) { - GSList *l; - - for (l = closures; l; l = l->next) { + for (GSList *l = closures; l; l = l->next) { GCClosure *cclosure = l->data; GClosure *closure = l->data; diff --git a/mate-panel/panel-menu-items.c b/mate-panel/panel-menu-items.c index 05af4969..14b58701 100644 --- a/mate-panel/panel-menu-items.c +++ b/mate-panel/panel-menu-items.c @@ -143,7 +143,6 @@ panel_menu_items_append_from_desktop (GtkWidget *menu, char *uri; char *type; gboolean is_application; - char *tryexec; char *icon; char *name; char *comment; @@ -198,7 +197,7 @@ panel_menu_items_append_from_desktop (GtkWidget *menu, g_free (type); if (is_application) { - tryexec = panel_key_file_get_string (key_file, "TryExec"); + char *tryexec = panel_key_file_get_string (key_file, "TryExec"); if (tryexec) { char *prog; @@ -409,7 +408,6 @@ panel_place_menu_item_append_gtk_bookmarks (GtkWidget *menu, guint max_items_or_ char *line = (char*) l->data; if (line[0] && !g_hash_table_lookup (table, line)) { - GFile *file; char *space; char *label; gboolean keep; @@ -430,7 +428,7 @@ panel_place_menu_item_append_gtk_bookmarks (GtkWidget *menu, guint max_items_or_ keep = TRUE; if (!keep) { - file = g_file_new_for_uri (line); + GFile *file = g_file_new_for_uri (line); keep = !g_file_is_native (file) || g_file_query_exists (file, NULL); g_object_unref (file); @@ -544,15 +542,16 @@ drive_poll_for_media_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GdkScreen *screen; - GError *error; - char *primary; - char *name; + GError *error; error = NULL; if (!g_drive_poll_for_media_finish (G_DRIVE (source_object), res, &error)) { if (error->code != G_IO_ERROR_FAILED_HANDLED) { + GdkScreen *screen; + char *primary; + char *name; + screen = GDK_SCREEN (user_data); name = g_drive_get_name (G_DRIVE (source_object)); @@ -633,10 +632,10 @@ volume_mount_cb (GObject *source_object, error = NULL; if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) { - char *primary; - char *name; - if (error->code != G_IO_ERROR_FAILED_HANDLED) { + char *primary; + char *name; + name = g_volume_get_name (G_VOLUME (source_object)); primary = g_strdup_printf (_("Unable to mount %s"), name); @@ -1019,7 +1018,6 @@ static GtkWidget * panel_place_menu_item_create_menu (PanelPlaceMenuItem *place_item) { GtkWidget *places_menu; - GtkWidget *item; char *gsettings_name = NULL; char *name; char *uri; @@ -1101,7 +1099,7 @@ panel_place_menu_item_create_menu (PanelPlaceMenuItem *place_item) if (panel_is_program_in_path ("caja-connect-server") || panel_is_program_in_path ("nautilus-connect-server") || panel_is_program_in_path ("nemo-connect-server")) { - item = panel_menu_items_create_action_item (PANEL_ACTION_CONNECT_SERVER); + GtkWidget *item = panel_menu_items_create_action_item (PANEL_ACTION_CONNECT_SERVER); if (item != NULL) gtk_menu_shell_append (GTK_MENU_SHELL (places_menu), item); diff --git a/mate-panel/panel-multimonitor.c b/mate-panel/panel-multimonitor.c index b2723f12..c7ac14cc 100644 --- a/mate-panel/panel-multimonitor.c +++ b/mate-panel/panel-multimonitor.c @@ -71,7 +71,6 @@ _panel_multimonitor_output_should_be_first (Display *xdisplay, unsigned long nitems; unsigned long bytes_after; unsigned char *prop; - gboolean retval; connector_type_atom = XInternAtom (xdisplay, "ConnectorType", False); @@ -81,7 +80,7 @@ _panel_multimonitor_output_should_be_first (Display *xdisplay, &nitems, &bytes_after, &prop) == Success) { if (actual_type == XA_ATOM && nitems == 1 && actual_format == 32) { char *connector_type = XGetAtomName (xdisplay, prop[0]); - retval = g_strcmp0 (connector_type, "Panel") == 0; + gboolean retval = g_strcmp0 (connector_type, "Panel") == 0; XFree (connector_type); return retval; } diff --git a/mate-panel/panel-profile.c b/mate-panel/panel-profile.c index 5f1013f1..06d096c2 100644 --- a/mate-panel/panel-profile.c +++ b/mate-panel/panel-profile.c @@ -1583,11 +1583,9 @@ panel_profile_load_list (GSettings *settings, PanelProfileLoadFunc load_handler, GCallback notify_handler) { - const gchar *key = key_from_type (type); gchar *changed_signal; gchar **list; - gint i; changed_signal = g_strdup_printf ("changed::%s", key); g_signal_connect (settings, changed_signal, G_CALLBACK (notify_handler), NULL); @@ -1595,7 +1593,7 @@ panel_profile_load_list (GSettings *settings, list = g_settings_get_strv (settings, key); - for (i = 0; list[i]; i++) { + for (gint i = 0; list[i]; i++) { load_handler (list[i]); } diff --git a/mate-panel/panel-test-applets.c b/mate-panel/panel-test-applets.c index f14c3888..79b48d36 100644 --- a/mate-panel/panel-test-applets.c +++ b/mate-panel/panel-test-applets.c @@ -178,13 +178,12 @@ static void load_applet_from_command_line (void) { guint size = 24, orient = PANEL_ORIENTATION_TOP; - gsize i; g_assert (cli_iid != NULL); if (cli_size || cli_orient) { if (cli_size) { - for (i = 0; i < G_N_ELEMENTS (size_items); i++) { + for (gsize i = 0; i < G_N_ELEMENTS (size_items); i++) { if (strcmp (g_dpgettext2 (NULL, "Size", size_items[i].name), cli_size) == 0) { size = size_items[i].value; break; @@ -193,7 +192,7 @@ load_applet_from_command_line (void) } if (cli_orient) { - for (i = 0; i < G_N_ELEMENTS (orient_items); i++) { + for (gsize i = 0; i < G_N_ELEMENTS (orient_items); i++) { if (strcmp (g_dpgettext2 (NULL, "Orientation", orient_items[i].name), cli_orient) == 0) { orient = orient_items[i].value; break; diff --git a/mate-panel/panel-widget.c b/mate-panel/panel-widget.c index a8c01854..ebaf74bf 100644 --- a/mate-panel/panel-widget.c +++ b/mate-panel/panel-widget.c @@ -1449,7 +1449,6 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) list = g_list_next (list)) { AppletData *ad = list->data; GtkRequisition chreq; - gtk_widget_get_preferred_size (ad->applet, &chreq, NULL); if (!ad->expand_major || !ad->size_hints) { @@ -1465,7 +1464,6 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) } ad->constrained = ad->pos; - if (ad->constrained < i) ad->constrained = i; |