diff options
author | Ernestas Kulik <ernestask@gnome.org> | 2018-02-27 22:03:33 +0200 |
---|---|---|
committer | Carlos Soriano <csoriano1618@gmail.com> | 2018-03-01 08:37:50 +0000 |
commit | 6286e0a07959f171a4bc8d6c4e3dabd52d8ad8ee (patch) | |
tree | 0b91426fa70efeeb90b679f8e8f1d75d74752983 | |
parent | 72df1bb3bbefc48c77b0f532cbf3f5db386c7237 (diff) | |
download | nautilus-6286e0a07959f171a4bc8d6c4e3dabd52d8ad8ee.tar.gz |
general: don’t shadow variables
Shadowing variables is error-prone, since one might mean to refer to a
variable that was declared earlier, but has the same name. Additionally,
being more strict about variable scoping can help make the code more
readable.
-rw-r--r-- | eel/eel-canvas.c | 1 | ||||
-rw-r--r-- | src/nautilus-application.c | 53 | ||||
-rw-r--r-- | src/nautilus-directory.c | 5 | ||||
-rw-r--r-- | src/nautilus-file-operations.c | 21 | ||||
-rw-r--r-- | src/nautilus-files-view.c | 7 | ||||
-rw-r--r-- | src/nautilus-icon-info.c | 2 | ||||
-rw-r--r-- | src/nautilus-mime-actions.c | 3 | ||||
-rw-r--r-- | src/nautilus-preferences-window.c | 2 | ||||
-rw-r--r-- | src/nautilus-tag-manager.c | 23 | ||||
-rw-r--r-- | src/nautilus-thumbnails.c | 11 | ||||
-rw-r--r-- | src/nautilus-view-icon-controller.c | 10 |
11 files changed, 71 insertions, 67 deletions
diff --git a/eel/eel-canvas.c b/eel/eel-canvas.c index b3aa886a0..09220f15a 100644 --- a/eel/eel-canvas.c +++ b/eel/eel-canvas.c @@ -3470,7 +3470,6 @@ eel_canvas_set_pixels_per_unit (EelCanvas *canvas, window = NULL; if (gtk_widget_get_mapped (widget)) { - GtkAllocation allocation; attributes.window_type = GDK_WINDOW_CHILD; gtk_widget_get_allocation (widget, &allocation); attributes.x = allocation.x; diff --git a/src/nautilus-application.c b/src/nautilus-application.c index 3ce6eb9ae..241c809dc 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -927,33 +927,6 @@ nautilus_init_application_actions (NautilusApplication *app) nautilus_application_set_accelerator (G_APPLICATION (app), "app.show-hide-sidebar", "F9"); } -const GOptionEntry options[] = -{ - #ifndef NAUTILUS_OMIT_SELF_CHECK - { "check", 'c', 0, G_OPTION_ARG_NONE, NULL, - N_("Perform a quick set of self-check tests."), NULL }, - #endif - /* dummy, only for compatibility reasons */ - { "browser", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, NULL, - NULL, NULL }, - /* ditto */ - { "geometry", 'g', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, NULL, - N_("Create the initial window with the given geometry."), N_("GEOMETRY") }, - { "version", '\0', 0, G_OPTION_ARG_NONE, NULL, - N_("Show the version of the program."), NULL }, - { "new-window", 'w', 0, G_OPTION_ARG_NONE, NULL, - N_("Always open a new window for browsing specified URIs"), NULL }, - { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, NULL, - N_("Only create windows for explicitly specified URIs."), NULL }, - { "quit", 'q', 0, G_OPTION_ARG_NONE, NULL, - N_("Quit Nautilus."), NULL }, - { "select", 's', 0, G_OPTION_ARG_NONE, NULL, - N_("Select specified URI in parent folder."), NULL }, - { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, N_("[URI…]") }, - - { NULL } -}; - static void nautilus_application_activate (GApplication *app) { @@ -1087,6 +1060,32 @@ out: static void nautilus_application_init (NautilusApplication *self) { + static const GOptionEntry options[] = + { +#ifndef NAUTILUS_OMIT_SELF_CHECK + { "check", 'c', 0, G_OPTION_ARG_NONE, NULL, + N_("Perform a quick set of self-check tests."), NULL }, +#endif + /* dummy, only for compatibility reasons */ + { "browser", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, NULL, + NULL, NULL }, + /* ditto */ + { "geometry", 'g', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, NULL, + N_("Create the initial window with the given geometry."), N_("GEOMETRY") }, + { "version", '\0', 0, G_OPTION_ARG_NONE, NULL, + N_("Show the version of the program."), NULL }, + { "new-window", 'w', 0, G_OPTION_ARG_NONE, NULL, + N_("Always open a new window for browsing specified URIs"), NULL }, + { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, NULL, + N_("Only create windows for explicitly specified URIs."), NULL }, + { "quit", 'q', 0, G_OPTION_ARG_NONE, NULL, + N_("Quit Nautilus."), NULL }, + { "select", 's', 0, G_OPTION_ARG_NONE, NULL, + N_("Select specified URI in parent folder."), NULL }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, N_("[URI…]") }, + + { NULL } + }; NautilusApplicationPrivate *priv; priv = nautilus_application_get_instance_private (self); diff --git a/src/nautilus-directory.c b/src/nautilus-directory.c index 0f6412e34..8bb2ce74f 100644 --- a/src/nautilus-directory.c +++ b/src/nautilus-directory.c @@ -1338,7 +1338,6 @@ nautilus_directory_notify_files_removed (GList *files) { GHashTable *changed_lists; GList *p; - NautilusDirectory *directory; GHashTable *parent_directories; NautilusFile *file; GFile *location; @@ -1352,6 +1351,8 @@ nautilus_directory_notify_files_removed (GList *files) /* Go through all the notifications. */ for (p = files; p != NULL; p = p->next) { + NautilusDirectory *directory; + location = p->data; /* Update file count for parent directory if anyone might care. */ @@ -1366,8 +1367,6 @@ nautilus_directory_notify_files_removed (GList *files) file = nautilus_file_get_existing (location); if (file != NULL && !nautilus_file_rename_in_progress (file)) { - NautilusDirectory *directory; - directory = nautilus_file_get_directory (file); /* Mark it gone and prepare to send the changed signal. */ diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c index 1f3ff7967..4d84b98be 100644 --- a/src/nautilus-file-operations.c +++ b/src/nautilus-file-operations.c @@ -5044,9 +5044,8 @@ copy_move_file (CopyMoveJob *copy_job, GError *error; GFileCopyFlags flags; char *primary, *secondary, *details; - int response; ProgressData pdata; - gboolean would_recurse, is_merge; + gboolean would_recurse; CommonJob *job; gboolean res; int unique_name_nr; @@ -5088,6 +5087,8 @@ copy_move_file (CopyMoveJob *copy_job, * detect and report it at this level) */ if (test_dir_is_parent (dest_dir, src)) { + int response; + if (job->skip_all_error) { goto out; @@ -5128,6 +5129,8 @@ copy_move_file (CopyMoveJob *copy_job, */ if (test_dir_is_parent (src, dest)) { + int response; + if (job->skip_all_error) { goto out; @@ -5375,6 +5378,8 @@ retry: else if (IS_IO_ERROR (error, WOULD_RECURSE) || IS_IO_ERROR (error, WOULD_MERGE)) { + gboolean is_merge; + is_merge = error->code == G_IO_ERROR_WOULD_MERGE; would_recurse = error->code == G_IO_ERROR_WOULD_RECURSE; g_error_free (error); @@ -5389,6 +5394,7 @@ retry: { g_autofree gchar *basename = NULL; g_autofree gchar *filename = NULL; + int response; if (job->skip_all_error) { @@ -5483,6 +5489,7 @@ retry: { g_autofree gchar *basename = NULL; g_autofree gchar *filename = NULL; + int response; if (job->skip_all_error) { @@ -5853,7 +5860,6 @@ move_file_prepare (CopyMoveJob *move_job, CommonJob *job; gboolean overwrite; char *primary, *secondary, *details; - int response; GFileCopyFlags flags; MoveFileCopyFallback *fallback; gboolean handled_invalid_filename; @@ -5871,6 +5877,8 @@ move_file_prepare (CopyMoveJob *move_job, * detect and report it at this level) */ if (test_dir_is_parent (dest_dir, src)) { + int response; + if (job->skip_all_error) { goto out; @@ -6067,6 +6075,7 @@ retry: { g_autofree gchar *basename = NULL; g_autofree gchar *filename = NULL; + int response; if (job->skip_all_error) { @@ -7421,7 +7430,7 @@ retry: else { g_autofree gchar *basename = NULL; - g_autofree gchar *filename = NULL; + g_autofree gchar *parse_name = NULL; basename = get_basename (dest); if (job->make_dir) @@ -7434,9 +7443,9 @@ retry: primary = g_strdup_printf (_("Error while creating file %s."), basename); } - filename = get_truncated_parse_name (job->dest_dir); + parse_name = get_truncated_parse_name (job->dest_dir); secondary = g_strdup_printf (_("There was an error creating the directory in %s."), - filename); + parse_name); details = error->message; diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c index 23bad6d0a..d3595a476 100644 --- a/src/nautilus-files-view.c +++ b/src/nautilus-files-view.c @@ -2769,7 +2769,6 @@ set_up_scripts_directory_global (void) if (!g_file_query_exists (updated, NULL)) { g_autoptr (GFile) parent = NULL; - g_autoptr (GError) error = NULL; parent = g_file_get_parent (scripts_directory); g_file_make_directory_with_parents (parent, NULL, &error); @@ -7233,7 +7232,6 @@ real_update_actions_state (NautilusFilesView *view) NautilusFilesViewPrivate *priv; g_autolist (NautilusFile) selection = NULL; GList *l; - NautilusFile *file; gint selection_count; gboolean zoom_level_is_default; gboolean selection_contains_desktop_or_home_dir; @@ -7478,6 +7476,7 @@ real_update_actions_state (NautilusFilesView *view) || show_detect_media); l = l->next) { + NautilusFile *file; gboolean show_mount_one; gboolean show_unmount_one; gboolean show_eject_one; @@ -7615,6 +7614,8 @@ real_update_actions_state (NautilusFilesView *view) (current_directory_in_xdg_folders || selection_contains_starred); for (l = selection; l != NULL; l = l->next) { + NautilusFile *file; + file = NAUTILUS_FILE (l->data); uri = nautilus_file_get_uri (file); @@ -7663,7 +7664,6 @@ update_selection_menu (NautilusFilesView *view) NautilusFilesViewPrivate *priv; g_autolist (NautilusFile) selection = NULL; GList *l; - NautilusFile *file; gint selection_count; gboolean show_app; gboolean show_run; @@ -7799,6 +7799,7 @@ update_selection_menu (NautilusFilesView *view) || show_detect_media); l = l->next) { + NautilusFile *file; gboolean show_mount_one; gboolean show_unmount_one; gboolean show_eject_one; diff --git a/src/nautilus-icon-info.c b/src/nautilus-icon-info.c index de69a3fbc..412eb0f32 100644 --- a/src/nautilus-icon-info.c +++ b/src/nautilus-icon-info.c @@ -337,10 +337,10 @@ nautilus_icon_info_lookup (GIcon *icon, int scale) { NautilusIconInfo *icon_info; - GdkPixbuf *pixbuf; if (G_IS_LOADABLE_ICON (icon)) { + GdkPixbuf *pixbuf; LoadableIconKey lookup_key; LoadableIconKey *key; GInputStream *stream; diff --git a/src/nautilus-mime-actions.c b/src/nautilus-mime-actions.c index 2f3f9b196..043cb2ae6 100644 --- a/src/nautilus-mime-actions.c +++ b/src/nautilus-mime-actions.c @@ -1607,7 +1607,6 @@ activate_files (ActivateParameters *parameters) g_autoptr (GQueue) open_in_view_files = NULL; GList *l; ActivationAction action; - LaunchLocation *location; launch_desktop_files = g_queue_new (); launch_files = g_queue_new (); @@ -1617,6 +1616,8 @@ activate_files (ActivateParameters *parameters) for (l = parameters->locations; l != NULL; l = l->next) { + LaunchLocation *location; + location = l->data; file = location->file; diff --git a/src/nautilus-preferences-window.c b/src/nautilus-preferences-window.c index 350c189b0..66b5e1782 100644 --- a/src/nautilus-preferences-window.c +++ b/src/nautilus-preferences-window.c @@ -178,7 +178,7 @@ static void create_icon_caption_combo_box_items(GtkComboBoxText *combo_box, (GDestroyNotify) free_column_names_array); } -static void icon_captions_changed_callback(GtkComboBox *combo_box, +static void icon_captions_changed_callback(GtkComboBox *widget, gpointer user_data) { GPtrArray *captions; diff --git a/src/nautilus-tag-manager.c b/src/nautilus-tag-manager.c index e822bea78..c046c641c 100644 --- a/src/nautilus-tag-manager.c +++ b/src/nautilus-tag-manager.c @@ -36,8 +36,6 @@ struct _NautilusTagManager G_DEFINE_TYPE (NautilusTagManager, nautilus_tag_manager, G_TYPE_OBJECT); -static NautilusTagManager *tag_manager = NULL; - typedef enum { GET_STARRED_FILES, @@ -844,6 +842,8 @@ nautilus_tag_manager_class_init (NautilusTagManagerClass *klass) NautilusTagManager * nautilus_tag_manager_get (void) { + static NautilusTagManager *tag_manager = NULL; + if (tag_manager != NULL) { return g_object_ref (tag_manager); @@ -855,20 +855,21 @@ nautilus_tag_manager_get (void) return tag_manager; } -void nautilus_tag_manager_set_cancellable (NautilusTagManager *tag_manager, - GCancellable *cancellable) +void +nautilus_tag_manager_set_cancellable (NautilusTagManager *self, + GCancellable *cancellable) { - nautilus_tag_manager_query_starred_files (tag_manager, cancellable); + nautilus_tag_manager_query_starred_files (self, cancellable); - tag_manager->notifier = tracker_notifier_new (NULL, - TRACKER_NOTIFIER_FLAG_QUERY_LOCATION, - cancellable, - &tag_manager->notifier_error); + self->notifier = tracker_notifier_new (NULL, + TRACKER_NOTIFIER_FLAG_QUERY_LOCATION, + cancellable, + &self->notifier_error); - g_signal_connect (tag_manager->notifier, + g_signal_connect (self->notifier, "events", G_CALLBACK (on_tracker_notifier_events), - tag_manager); + self); } static void diff --git a/src/nautilus-thumbnails.c b/src/nautilus-thumbnails.c index 1917b6364..e714f671d 100644 --- a/src/nautilus-thumbnails.c +++ b/src/nautilus-thumbnails.c @@ -92,8 +92,6 @@ static GHashTable *thumbnails_to_make_hash = NULL; * to avoid adding it again. Lock thumbnails_mutex when accessing this. */ static NautilusThumbnailInfo *currently_thumbnailing = NULL; -static GnomeDesktopThumbnailFactory *thumbnail_factory = NULL; - static gboolean get_file_mtime (const char *file_uri, time_t *mtime) @@ -153,12 +151,6 @@ thumbnail_thread_starter_cb (gpointer data) { GTask *task; - /* Don't do this in thread, since g_object_ref is not threadsafe */ - if (thumbnail_factory == NULL) - { - thumbnail_factory = get_thumbnail_factory (); - } - g_debug ("(Main Thread) Creating thumbnails thread\n"); /* We set a flag to indicate the thread is running, so we don't create @@ -447,12 +439,15 @@ thumbnail_thread_func (GTask *task, gpointer task_data, GCancellable *cancellable) { + GnomeDesktopThumbnailFactory *thumbnail_factory; NautilusThumbnailInfo *info = NULL; GdkPixbuf *pixbuf; time_t current_orig_mtime = 0; time_t current_time; GList *node; + thumbnail_factory = get_thumbnail_factory (); + /* We loop until there are no more thumbails to make, at which point * we exit the thread. */ for (;; ) diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c index a93717d1d..8912ace7d 100644 --- a/src/nautilus-view-icon-controller.c +++ b/src/nautilus-view-icon-controller.c @@ -805,7 +805,7 @@ action_sort_order_changed (GSimpleAction *action, gpointer user_data) { const gchar *target_name; - const SortConstants *sorts_constants; + const SortConstants *sort_constants; NautilusViewModelSortData sort_data; NautilusViewIconController *self; @@ -817,14 +817,14 @@ action_sort_order_changed (GSimpleAction *action, self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data); target_name = g_variant_get_string (value, NULL); - sorts_constants = get_sorts_constants_from_action_target_name (target_name); - sort_data.sort_type = sorts_constants->sort_type; - sort_data.reversed = sorts_constants->reversed; + sort_constants = get_sorts_constants_from_action_target_name (target_name); + sort_data.sort_type = sort_constants->sort_type; + sort_data.reversed = sort_constants->reversed; sort_data.directories_first = nautilus_files_view_should_sort_directories_first (NAUTILUS_FILES_VIEW (self)); nautilus_view_model_set_sort_type (self->model, &sort_data); set_directory_sort_metadata (nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (self)), - sorts_constants); + sort_constants); g_simple_action_set_state (action, value); } |