[epiphany/mcatanzaro/g-clear-handler] Use g_clear_handler() when possible
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/g-clear-handler] Use g_clear_handler() when possible
- Date: Fri, 20 Dec 2019 15:03:28 +0000 (UTC)
commit ebc49be3294359570986618836862ffd7a93c614
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Fri Dec 20 09:00:47 2019 -0600
Use g_clear_handler() when possible
Just a cleanup commit. Also, improve weirdness in a couple related
places. E.g. EphyLocationEntry was using the wrong type for its timeout
ID.
embed/ephy-embed.c | 51 +++++++-----------------------------
embed/ephy-find-toolbar.c | 5 +---
embed/ephy-web-view.c | 25 ++++--------------
lib/history/ephy-history-service.c | 5 +---
lib/safe-browsing/ephy-gsb-service.c | 5 +---
lib/sync/ephy-sync-service.c | 5 +---
lib/widgets/ephy-location-entry.c | 30 +++++++--------------
src/ephy-action-bar-start.c | 15 +++--------
src/ephy-history-dialog.c | 5 +---
src/ephy-session.c | 11 +++-----
src/ephy-window.c | 10 ++-----
src/prefs-dialog.c | 7 ++---
12 files changed, 39 insertions(+), 135 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 82e768af8..aaaa5e159 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -341,9 +341,7 @@ ephy_embed_entering_fullscreen (EphyEmbed *embed)
if (!g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, EPHY_PREFS_LOCKDOWN_FULLSCREEN)) {
gtk_widget_show (embed->fullscreen_message_label);
- if (embed->fullscreen_message_id)
- g_source_remove (embed->fullscreen_message_id);
-
+ g_clear_handle_id (&embed->fullscreen_message_id, g_source_remove);
embed->fullscreen_message_id = g_timeout_add_seconds (5,
(GSourceFunc)fullscreen_message_label_hide,
embed);
@@ -362,37 +360,13 @@ ephy_embed_dispose (GObject *object)
{
EphyEmbed *embed = EPHY_EMBED (object);
- if (embed->pop_statusbar_later_source_id) {
- g_source_remove (embed->pop_statusbar_later_source_id);
- embed->pop_statusbar_later_source_id = 0;
- }
+ g_clear_handle_id (&embed->pop_statusbar_later_source_id, g_source_remove);
+ g_clear_handle_id (&embed->clear_progress_source_id, g_source_remove);
+ g_clear_handle_id (&embed->delayed_request_source_id, g_source_remove);
+ g_clear_handle_id (&embed->fullscreen_message_id, g_source_remove);
- if (embed->clear_progress_source_id) {
- g_source_remove (embed->clear_progress_source_id);
- embed->clear_progress_source_id = 0;
- }
-
- if (embed->delayed_request_source_id) {
- g_source_remove (embed->delayed_request_source_id);
- embed->delayed_request_source_id = 0;
- }
-
- /* Do not listen to status message notifications anymore, if we try
- * to update the statusbar after dispose we might crash. */
- if (embed->status_handler_id) {
- g_signal_handler_disconnect (embed->web_view, embed->status_handler_id);
- embed->status_handler_id = 0;
- }
-
- if (embed->progress_update_handler_id) {
- g_signal_handler_disconnect (embed->web_view, embed->progress_update_handler_id);
- embed->progress_update_handler_id = 0;
- }
-
- if (embed->fullscreen_message_id) {
- g_source_remove (embed->fullscreen_message_id);
- embed->fullscreen_message_id = 0;
- }
+ g_clear_signal_handler (&embed->status_handler_id, embed->web_view);
+ g_clear_signal_handler (&embed->progress_update_handler_id, embed->web_view);
g_clear_object (&embed->delayed_request);
g_clear_pointer (&embed->delayed_state, webkit_web_view_session_state_unref);
@@ -599,11 +573,7 @@ status_message_notify_cb (EphyWebView *view,
message = ephy_web_view_get_status_message (view);
if (message) {
- if (embed->pop_statusbar_later_source_id) {
- g_source_remove (embed->pop_statusbar_later_source_id);
- embed->pop_statusbar_later_source_id = 0;
- }
-
+ g_clear_handle_id (&embed->pop_statusbar_later_source_id, g_source_remove);
ephy_embed_statusbar_pop (embed, embed->tab_message_id);
ephy_embed_statusbar_push (embed, embed->tab_message_id, message);
} else {
@@ -634,10 +604,7 @@ progress_update (EphyWebView *view,
gboolean loading;
const char *uri;
- if (embed->clear_progress_source_id) {
- g_source_remove (embed->clear_progress_source_id);
- embed->clear_progress_source_id = 0;
- }
+ g_clear_handle_id (&embed->clear_progress_source_id, g_source_remove);
uri = webkit_web_view_get_uri (embed->web_view);
if (!uri || g_str_has_prefix (uri, "ephy-about:") ||
diff --git a/embed/ephy-find-toolbar.c b/embed/ephy-find-toolbar.c
index 0404a5f07..533b74a06 100644
--- a/embed/ephy-find-toolbar.c
+++ b/embed/ephy-find-toolbar.c
@@ -214,10 +214,7 @@ update_find_string (EphyFindToolbar *toolbar)
g_free (toolbar->find_string);
toolbar->find_string = g_strdup (gtk_entry_get_text (GTK_ENTRY (toolbar->entry)));
- if (toolbar->find_source_id != 0) {
- g_source_remove (toolbar->find_source_id);
- toolbar->find_source_id = 0;
- }
+ g_clear_handle_id (&toolbar->find_source_id, g_source_remove);
if (strlen (toolbar->find_string) == 0) {
clear_status (toolbar);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 59ffb1c98..b92b42908 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1383,10 +1383,7 @@ ephy_web_view_load_changed (WebKitWebView *web_view,
case WEBKIT_LOAD_STARTED: {
view->load_failed = FALSE;
- if (view->snapshot_timeout_id) {
- g_source_remove (view->snapshot_timeout_id);
- view->snapshot_timeout_id = 0;
- }
+ g_clear_handle_id (&view->snapshot_timeout_id, g_source_remove);
if (view->address == NULL || view->address[0] == '\0') {
/* We've probably never loaded any page before. */
@@ -1480,10 +1477,7 @@ ephy_web_view_load_changed (WebKitWebView *web_view,
ephy_web_view_thaw_history (view);
- if (view->reader_js_timeout) {
- g_source_remove (view->reader_js_timeout);
- view->reader_js_timeout = 0;
- }
+ g_clear_handle_id (&view->reader_js_timeout, g_source_remove);
view->reader_loading = FALSE;
if (!view->reader_active)
@@ -3451,8 +3445,8 @@ ephy_web_view_dispose (GObject *object)
untrack_info_bar (&view->password_info_bar);
untrack_info_bar (&view->password_form_info_bar);
+ g_clear_object (&view->certificate);
g_clear_object (&view->file_monitor);
-
g_clear_object (&view->icon);
if (view->cancellable) {
@@ -3460,17 +3454,8 @@ ephy_web_view_dispose (GObject *object)
g_clear_object (&view->cancellable);
}
- if (view->snapshot_timeout_id) {
- g_source_remove (view->snapshot_timeout_id);
- view->snapshot_timeout_id = 0;
- }
-
- if (view->reader_js_timeout) {
- g_source_remove (view->reader_js_timeout);
- view->reader_js_timeout = 0;
- }
-
- g_clear_object (&view->certificate);
+ g_clear_handle_id (&view->snapshot_timeout_id, g_source_remove);
+ g_clear_handle_id (&view->reader_js_timeout, g_source_remove);
G_OBJECT_CLASS (ephy_web_view_parent_class)->dispose (object);
}
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index 340618e6f..9c869825d 100644
--- a/lib/history/ephy-history-service.c
+++ b/lib/history/ephy-history-service.c
@@ -162,10 +162,7 @@ ephy_history_service_dispose (GObject *object)
{
EphyHistoryService *self = EPHY_HISTORY_SERVICE (object);
- if (self->queue_urls_visited_id) {
- g_source_remove (self->queue_urls_visited_id);
- self->queue_urls_visited_id = 0;
- }
+ g_clear_handle_id (&self->queue_urls_visited_id, g_source_remove);
G_OBJECT_CLASS (ephy_history_service_parent_class)->dispose (object);
}
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index ef8e2a446..98d23d3fa 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -385,10 +385,7 @@ ephy_gsb_service_dispose (GObject *object)
g_clear_object (&self->storage);
g_clear_object (&self->session);
- if (self->source_id != 0) {
- g_source_remove (self->source_id);
- self->source_id = 0;
- }
+ g_clear_handle_id (&self->source_id, g_source_remove);
G_OBJECT_CLASS (ephy_gsb_service_parent_class)->dispose (object);
}
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 00f7ae2f5..24f5f433d 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -1670,10 +1670,7 @@ ephy_sync_service_stop_periodical_sync (EphySyncService *self)
{
g_assert (EPHY_IS_SYNC_SERVICE (self));
- if (self->source_id != 0) {
- g_source_remove (self->source_id);
- self->source_id = 0;
- }
+ g_clear_handle_id (&self->source_id, g_source_remove);
}
static void
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 64fcd4038..ab50f9ad6 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -77,7 +77,7 @@ struct _EphyLocationEntry {
guint progress_timeout;
gdouble progress_fraction;
- gulong dns_prefetch_handler;
+ guint dns_prefetch_handle_id;
guint user_changed : 1;
guint can_redo : 1;
@@ -374,10 +374,7 @@ ephy_location_entry_dispose (GObject *object)
{
EphyLocationEntry *entry = EPHY_LOCATION_ENTRY (object);
- if (entry->progress_timeout) {
- g_source_remove (entry->progress_timeout);
- entry->progress_timeout = 0;
- }
+ g_clear_handle_id (&entry->progress_timeout, g_source_remove);
g_clear_object (&entry->css_provider);
@@ -1016,7 +1013,6 @@ ephy_location_entry_init (EphyLocationEntry *le)
le->user_changed = FALSE;
le->block_update = FALSE;
le->saved_text = NULL;
- le->dns_prefetch_handler = 0;
ephy_location_entry_construct_contents (le);
}
@@ -1051,9 +1047,9 @@ do_dns_prefetch (PrefetchHelper *helper)
webkit_web_context_prefetch_dns (ephy_embed_shell_get_web_context (shell), helper->uri->host);
#endif
- helper->entry->dns_prefetch_handler = 0;
+ helper->entry->dns_prefetch_handle_id = 0;
- return FALSE;
+ return G_SOURCE_REMOVE;
}
/*
@@ -1081,16 +1077,14 @@ proxy_resolver_ready_cb (GObject *object,
return;
}
- if (helper->entry->dns_prefetch_handler)
- g_source_remove (helper->entry->dns_prefetch_handler);
-
- helper->entry->dns_prefetch_handler =
+ g_clear_handle_id (&helper->entry->dns_prefetch_handle_id, g_source_remove);
+ helper->entry->dns_prefetch_handle_id =
g_timeout_add_full (G_PRIORITY_DEFAULT,
250,
(GSourceFunc)do_dns_prefetch,
helper,
(GDestroyNotify)free_prefetch_helper);
- g_source_set_name_by_id (helper->entry->dns_prefetch_handler, "[epiphany] do_dns_prefetch");
+ g_source_set_name_by_id (helper->entry->dns_prefetch_handle_id, "[epiphany] do_dns_prefetch");
}
static void
@@ -1354,10 +1348,7 @@ progress_hide (gpointer user_data)
gtk_entry_set_progress_fraction (GTK_ENTRY (entry->url_entry), 0);
- if (entry->progress_timeout) {
- g_source_remove (entry->progress_timeout);
- entry->progress_timeout = 0;
- }
+ g_clear_handle_id (&entry->progress_timeout, g_source_remove);
return G_SOURCE_REMOVE;
}
@@ -1398,10 +1389,7 @@ ephy_location_entry_set_progress (EphyLocationEntry *entry,
{
gdouble current_progress;
- if (entry->progress_timeout) {
- g_source_remove (entry->progress_timeout);
- entry->progress_timeout = 0;
- }
+ g_clear_handle_id (&entry->progress_timeout, g_source_remove);
if (!loading) {
/* Setting progress to 0 when it is already 0 can actually cause the
diff --git a/src/ephy-action-bar-start.c b/src/ephy-action-bar-start.c
index 328bbfec0..eb0821e09 100644
--- a/src/ephy-action-bar-start.c
+++ b/src/ephy-action-bar-start.c
@@ -356,10 +356,7 @@ navigation_button_release_event_cb (GtkButton *button,
EphyNavigationHistoryDirection direction;
const gchar *action_name;
- if (action_bar_start->navigation_buttons_menu_timeout > 0) {
- g_source_remove (action_bar_start->navigation_buttons_menu_timeout);
- action_bar_start->navigation_buttons_menu_timeout = 0;
- }
+ g_clear_handle_id (&action_bar_start->navigation_buttons_menu_timeout, g_source_remove);
action_name = gtk_actionable_get_action_name (GTK_ACTIONABLE (button));
action_group = gtk_widget_get_action_group (gtk_widget_get_ancestor (GTK_WIDGET (action_bar_start),
EPHY_TYPE_WINDOW), "toolbar");
@@ -439,10 +436,7 @@ navigation_leave_notify_event_cb (GtkButton *button,
{
EphyActionBarStart *action_bar_start = EPHY_ACTION_BAR_START (user_data);
- if (action_bar_start->navigation_buttons_menu_timeout > 0) {
- g_source_remove (action_bar_start->navigation_buttons_menu_timeout);
- action_bar_start->navigation_buttons_menu_timeout = 0;
- }
+ g_clear_handle_id (&action_bar_start->navigation_buttons_menu_timeout, g_source_remove);
return GDK_EVENT_PROPAGATE;
}
@@ -467,10 +461,7 @@ ephy_action_bar_start_dispose (GObject *object)
{
EphyActionBarStart *action_bar_start = EPHY_ACTION_BAR_START (object);
- if (action_bar_start->navigation_buttons_menu_timeout > 0) {
- g_source_remove (action_bar_start->navigation_buttons_menu_timeout);
- action_bar_start->navigation_buttons_menu_timeout = 0;
- }
+ g_clear_handle_id (&action_bar_start->navigation_buttons_menu_timeout, g_source_remove);
G_OBJECT_CLASS (ephy_action_bar_start_parent_class)->dispose (object);
}
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index 3a93ac445..66e7ac5f3 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -149,10 +149,7 @@ static void
remove_pending_sorter_source (EphyHistoryDialog *self,
gboolean free_urls)
{
- if (self->sorter_source != 0) {
- g_source_remove (self->sorter_source);
- self->sorter_source = 0;
- }
+ g_clear_handle_id (&self->sorter_source, g_source_remove);
if (free_urls && self->urls) {
g_list_free_full (self->urls, (GDestroyNotify)ephy_history_url_free);
diff --git a/src/ephy-session.c b/src/ephy-session.c
index d677e1cc8..935c40879 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -516,13 +516,10 @@ ephy_session_close (EphySession *session)
LOG ("ephy_session_close");
- if (session->save_source_id) {
- /* There's a save pending, cancel it and save the session now since
- * after closing the session the saving is no longer allowed.
- */
- g_source_remove (session->save_source_id);
- session->save_source_id = 0;
- }
+ /* If there's a save pending, cancel it and save the session now since
+ * after closing the session the saving is no longer allowed.
+ */
+ g_clear_handle_id (&session->save_source_id, g_source_remove);
if (session->closing)
return;
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 8d0abd2fe..825a13c74 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1262,15 +1262,9 @@ static void
_ephy_window_set_context_event (EphyWindow *window,
EphyEmbedEvent *event)
{
- if (window->idle_worker != 0) {
- g_source_remove (window->idle_worker);
- window->idle_worker = 0;
- }
-
- if (window->context_event != NULL) {
- g_object_unref (window->context_event);
- }
+ g_clear_handle_id (&window->idle_worker, g_source_remove);
+ g_clear_object (&window->context_event);
window->context_event = event != NULL ? g_object_ref (event) : NULL;
}
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 4643d561d..d9fe6f345 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -722,8 +722,6 @@ save_web_application (PrefsDialog *dialog)
gboolean changed = FALSE;
const char *text;
- dialog->webapp_save_id = 0;
-
if (!dialog->webapp)
return G_SOURCE_REMOVE;
@@ -760,9 +758,7 @@ prefs_dialog_save_web_application (PrefsDialog *dialog)
if (!dialog->webapp)
return;
- if (dialog->webapp_save_id)
- g_source_remove (dialog->webapp_save_id);
-
+ g_clear_handle_id (&dialog->webapp_save_id, g_source_remove);
dialog->webapp_save_id = g_timeout_add_seconds (1, (GSourceFunc)save_web_application, dialog);
}
@@ -1660,6 +1656,7 @@ prefs_dialog_response_cb (GtkWidget *widget,
{
if (dialog->webapp_save_id) {
g_source_remove (dialog->webapp_save_id);
+ dialog->webapp_save_id = 0;
save_web_application (dialog);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]