[libadwaita/msvc: 271/271] examples: Remove g_auto* usage




commit 719973088e47f86c0548fd7c650e9c24ac53ae14
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jul 26 19:00:25 2021 +0800

    examples: Remove g_auto* usage
    
    It is unfortunately a GCCism, so use the traditional method instead.
    Unfortunately the autocleanup compiler extensions are not standard across the
    board.

 examples/adw-demo-window.c          | 34 ++++++++++++++++++++++++----------
 examples/adw-tab-view-demo-window.c | 17 ++++++++++++-----
 2 files changed, 36 insertions(+), 15 deletions(-)
---
diff --git a/examples/adw-demo-window.c b/examples/adw-demo-window.c
index a8aa1110..363bdeb9 100644
--- a/examples/adw-demo-window.c
+++ b/examples/adw-demo-window.c
@@ -225,10 +225,10 @@ static void
 avatar_file_chooser_response_cb (AdwDemoWindow *self,
                                  int            response)
 {
-  g_autoptr (GFile) file = NULL;
-  g_autoptr (GFileInfo) info = NULL;
-  g_autoptr (GdkTexture) texture = NULL;
-  g_autoptr (GError) error = NULL;
+  GFile *file = NULL;
+  GFileInfo *info = NULL;
+  GdkTexture *texture = NULL;
+  GError *error = NULL;
 
   g_assert (ADW_IS_DEMO_WINDOW (self));
 
@@ -250,9 +250,16 @@ avatar_file_chooser_response_cb (AdwDemoWindow *self,
 
   texture = gdk_texture_new_from_file (file, &error);
   if (error)
-    g_critical ("Failed to create texture from file: %s", error->message);
+    {
+      g_critical ("Failed to create texture from file: %s", error->message);
+      g_clear_error (&error);
+    }
 
   adw_avatar_set_custom_image (self->avatar, texture ? GDK_PAINTABLE (texture) : NULL);
+
+  g_object_unref (texture);
+  g_object_unref (info);
+  g_object_unref (file);
 }
 
 static void
@@ -267,14 +274,18 @@ file_chooser_response_cb (AdwDemoWindow  *self,
                           GtkFileChooser *chooser)
 {
   if (response_id == GTK_RESPONSE_ACCEPT) {
-    g_autoptr (GFile) file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
-    g_autoptr (GdkTexture) texture =
+    GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
+    GdkTexture *texture =
       adw_avatar_draw_to_texture (self->avatar,
                                   gtk_widget_get_scale_factor (GTK_WIDGET (self)));
 
-    g_autofree char *path = g_file_get_path (file);
+    char *path = g_file_get_path (file);
 
     gdk_texture_save_to_png (texture, path);
+
+    g_free (path);
+    g_object_unref (texture);
+    g_object_unref (file);
   }
 
   g_object_unref (chooser);
@@ -357,7 +368,7 @@ avatar_update_contacts (AdwDemoWindow *self)
     gtk_list_box_remove (self->avatar_contacts, row);
 
   for (int i = 0; i < 30; i++) {
-    g_autofree char *name = avatar_new_random_name ();
+    char *name = avatar_new_random_name ();
     GtkWidget *contact = adw_action_row_new ();
     GtkWidget *avatar = adw_avatar_new (40, name, TRUE);
 
@@ -367,6 +378,7 @@ avatar_update_contacts (AdwDemoWindow *self)
     adw_preferences_row_set_title (ADW_PREFERENCES_ROW (contact), name);
     adw_action_row_add_prefix (ADW_ACTION_ROW (contact), avatar);
     gtk_list_box_append (self->avatar_contacts, contact);
+    g_free (name);
   }
 }
 
@@ -440,7 +452,7 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
 static void
 avatar_page_init (AdwDemoWindow *self)
 {
-  g_autofree char *name = avatar_new_random_name ();
+  char *name = avatar_new_random_name ();
 
   gtk_editable_set_text (GTK_EDITABLE (self->avatar_text), name);
 
@@ -459,6 +471,8 @@ avatar_page_init (AdwDemoWindow *self)
                            G_CONNECT_SWAPPED);
 
   avatar_file_remove_cb (self);
+
+  g_free (name);
 }
 
 static void
diff --git a/examples/adw-tab-view-demo-window.c b/examples/adw-tab-view-demo-window.c
index 2de60b79..aabcf7e2 100644
--- a/examples/adw-tab-view-demo-window.c
+++ b/examples/adw-tab-view-demo-window.c
@@ -106,7 +106,7 @@ tab_new (GSimpleAction *action,
          gpointer       user_data)
 {
   AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (user_data);
-  g_autofree char *title = NULL;
+  char *title = NULL;
   AdwTabPage *page;
   GtkWidget *content;
   GIcon *icon;
@@ -116,6 +116,7 @@ tab_new (GSimpleAction *action,
   icon = get_random_icon (self);
 
   page = add_page (self, NULL, title, icon);
+  g_free (title);
   content = adw_tab_page_get_child (page);
 
   adw_tab_view_set_selected_page (self->view, page);
@@ -256,13 +257,15 @@ tab_change_indicator (GSimpleAction *action,
 {
   AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (user_data);
   gboolean indicator = g_variant_get_boolean (parameter);
-  g_autoptr (GIcon) icon = NULL;
+  GIcon *icon = NULL;
 
   if (indicator)
     icon = get_indicator_icon (get_current_page (self));
 
   adw_tab_page_set_indicator_icon (get_current_page (self), icon);
   g_simple_action_set_state (action, g_variant_new_boolean (indicator));
+
+  g_object_unref (icon);
 }
 
 static void
@@ -274,9 +277,11 @@ tab_change_icon (GSimpleAction *action,
   gboolean enable_icon = g_variant_get_boolean (parameter);
 
   if (enable_icon) {
-    g_autoptr (GIcon) icon = get_random_icon (self);
+    GIcon *icon = get_random_icon (self);
 
     adw_tab_page_set_icon (get_current_page (self), icon);
+
+    g_object_unref (icon);
   } else {
     adw_tab_page_set_icon (get_current_page (self), NULL);
   }
@@ -290,9 +295,11 @@ tab_refresh_icon (GSimpleAction *action,
                   gpointer       user_data)
 {
   AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (user_data);
-  g_autoptr (GIcon) icon = get_random_icon (self);
+  GIcon * icon = get_random_icon (self);
 
   adw_tab_page_set_icon (get_current_page (self), icon);
+
+  g_object_unref (icon);
 }
 
 static void
@@ -436,7 +443,7 @@ static void
 indicator_activated_cb (AdwTabViewDemoWindow *self,
                         AdwTabPage           *page)
 {
-  g_autoptr (GIcon) icon = NULL;
+  GIcon *icon = NULL;
   gboolean muted;
 
   muted = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (page),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]