[libhandy/msvc: 24/26] examples/*.c: Drop uses of g_auto*()




commit f2159cf987c463141536f8694873985f982ea8bc
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Jan 19 18:03:06 2022 +0800

    examples/*.c: Drop uses of g_auto*()
    
    The g_auto* macros are unfortunately Gccism's, so drop them so that
    things build on Visual Studio.

 examples/hdy-demo-window.c          | 34 +++++++++++++++++++++++++---------
 examples/hdy-tab-view-demo-window.c | 24 ++++++++++++++++++------
 2 files changed, 43 insertions(+), 15 deletions(-)
---
diff --git a/examples/hdy-demo-window.c b/examples/hdy-demo-window.c
index 119b2cd6..4efee7fe 100644
--- a/examples/hdy-demo-window.c
+++ b/examples/hdy-demo-window.c
@@ -284,10 +284,12 @@ static void
 carousel_return_clicked_cb (GtkButton     *btn,
                             HdyDemoWindow *self)
 {
-  g_autoptr (GList) children =
+  GList *children =
     gtk_container_get_children (GTK_CONTAINER (self->carousel));
 
   hdy_carousel_scroll_to (self->carousel, GTK_WIDGET (children->data));
+
+  g_list_free (children);
 }
 
 HdyDemoWindow *
@@ -299,7 +301,7 @@ hdy_demo_window_new (GtkApplication *application)
 static void
 avatar_file_remove_cb (HdyDemoWindow *self)
 {
-  g_autofree gchar *file = NULL;
+  gchar *file;
 
   g_assert (HDY_IS_DEMO_WINDOW (self));
 
@@ -309,19 +311,24 @@ avatar_file_remove_cb (HdyDemoWindow *self)
     gtk_file_chooser_unselect_filename (GTK_FILE_CHOOSER (self->avatar_filechooser), file);
 
   hdy_avatar_set_loadable_icon (self->avatar, NULL);
+
+  g_free (file);
 }
 
 static void
 avatar_file_set_cb (HdyDemoWindow *self)
 {
-  g_autoptr (GFile) file = NULL;
-  g_autoptr (GIcon) icon = NULL;
+  GFile *file;
+  GIcon *icon;
 
   g_assert (HDY_IS_DEMO_WINDOW (self));
 
   file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (self->avatar_filechooser));
   icon = g_file_icon_new (file);
   hdy_avatar_set_loadable_icon (self->avatar, G_LOADABLE_ICON (icon));
+
+  g_object_unref (icon);
+  g_object_unref (file);
 }
 
 static void
@@ -330,14 +337,17 @@ file_chooser_response_cb (HdyDemoWindow  *self,
                           GtkFileChooser *chooser)
 {
   if (response_id == GTK_RESPONSE_ACCEPT) {
-    g_autofree gchar *filename = gtk_file_chooser_get_filename (chooser);
-    g_autoptr (GdkPixbuf) pixbuf =
+    gchar *filename = gtk_file_chooser_get_filename (chooser);
+    GdkPixbuf *pixbuf =
       hdy_avatar_draw_to_pixbuf (self->avatar,
                                  hdy_avatar_get_size (self->avatar),
                                  gtk_widget_get_scale_factor (GTK_WIDGET (self)));
 
     if (pixbuf != NULL)
       gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL);
+
+    g_object_unref (pixbuf);
+    g_free (filename);
   }
 
   g_object_unref (chooser);
@@ -415,13 +425,13 @@ avatar_new_random_name (void)
 static void
 avatar_update_contacts (HdyDemoWindow *self)
 {
-  g_autoptr (GList) children = gtk_container_get_children (GTK_CONTAINER (self->avatar_contacts));
+  GList *children = gtk_container_get_children (GTK_CONTAINER (self->avatar_contacts));
 
   for (GList *child = children; child; child = child->next)
     gtk_container_remove (GTK_CONTAINER (self->avatar_contacts), child->data);
 
   for (int i = 0; i < 30; i++) {
-    g_autofree gchar *name = avatar_new_random_name ();
+    gchar *name = avatar_new_random_name ();
     GtkWidget *contact = hdy_action_row_new ();
     GtkWidget *avatar = hdy_avatar_new (40, name, TRUE);
 
@@ -434,7 +444,11 @@ avatar_update_contacts (HdyDemoWindow *self)
     hdy_preferences_row_set_title (HDY_PREFERENCES_ROW (contact), name);
     hdy_action_row_add_prefix (HDY_ACTION_ROW (contact), avatar);
     gtk_container_add (GTK_CONTAINER (self->avatar_contacts), contact);
+
+    g_free (name);
   }
+
+  g_list_free (children);
 }
 
 static void
@@ -582,11 +596,13 @@ carousel_page_init (HdyDemoWindow *self)
 static void
 avatar_page_init (HdyDemoWindow *self)
 {
-  g_autofree gchar *name = avatar_new_random_name ();
+  gchar *name = avatar_new_random_name ();
 
   gtk_entry_set_text (self->avatar_text, name);
 
   avatar_update_contacts (self);
+
+  g_free (name);
 }
 
 static void
diff --git a/examples/hdy-tab-view-demo-window.c b/examples/hdy-tab-view-demo-window.c
index b66330e9..7819a885 100644
--- a/examples/hdy-tab-view-demo-window.c
+++ b/examples/hdy-tab-view-demo-window.c
@@ -98,7 +98,7 @@ tab_new (GSimpleAction *action,
          gpointer       user_data)
 {
   HdyTabViewDemoWindow *self = HDY_TAB_VIEW_DEMO_WINDOW (user_data);
-  g_autofree gchar *title = NULL;
+  gchar *title;
   HdyTabPage *page;
   GtkWidget *content;
   GIcon *icon;
@@ -115,6 +115,8 @@ tab_new (GSimpleAction *action,
   gtk_widget_grab_focus (content);
 
   next_page++;
+
+  g_free (title);
 }
 
 static HdyTabPage *
@@ -248,13 +250,15 @@ tab_change_indicator (GSimpleAction *action,
 {
   HdyTabViewDemoWindow *self = HDY_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));
 
   hdy_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
@@ -266,9 +270,11 @@ tab_change_icon (GSimpleAction *action,
   gboolean enable_icon = g_variant_get_boolean (parameter);
 
   if (enable_icon) {
-    g_autoptr (GIcon) icon = get_random_icon ();
+    GIcon *icon = get_random_icon ();
 
     hdy_tab_page_set_icon (get_current_page (self), icon);
+
+    g_object_unref (icon);
   } else {
     hdy_tab_page_set_icon (get_current_page (self), NULL);
   }
@@ -282,9 +288,11 @@ tab_refresh_icon (GSimpleAction *action,
                   gpointer       user_data)
 {
   HdyTabViewDemoWindow *self = HDY_TAB_VIEW_DEMO_WINDOW (user_data);
-  g_autoptr (GIcon) icon = get_random_icon ();
+  GIcon *icon = get_random_icon ();
 
   hdy_tab_page_set_icon (get_current_page (self), icon);
+
+  g_object_unref (icon);
 }
 
 static void
@@ -429,7 +437,7 @@ static void
 indicator_activated_cb (HdyTabViewDemoWindow *self,
                         HdyTabPage           *page)
 {
-  g_autoptr (GIcon) icon = NULL;
+  GIcon *icon = NULL;
   gboolean muted;
 
   muted = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (page),
@@ -442,6 +450,8 @@ indicator_activated_cb (HdyTabViewDemoWindow *self,
   icon = get_indicator_icon (page);
 
   hdy_tab_page_set_indicator_icon (page, icon);
+
+  g_object_unref (icon);
 }
 
 static void
@@ -452,7 +462,7 @@ extra_drag_data_received_cb (HdyTabViewDemoWindow *self,
                              guint                 info,
                              guint                 time)
 {
-  g_autofree gchar *text = NULL;
+  gchar *text;
 
   if (gtk_selection_data_get_length (selection_data) < 0)
     return;
@@ -460,6 +470,8 @@ extra_drag_data_received_cb (HdyTabViewDemoWindow *self,
   text = (gchar *) gtk_selection_data_get_text (selection_data);
 
   hdy_tab_page_set_title (page, text);
+
+  g_free (text);
 }
 
 static void


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