[libhandy/msvc-1-6: 15/15] examples/: Drop g_auto* usage




commit 92d3f0ff04497438c5fbd25e283b7046d0573fc0
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Apr 28 13:46:48 2022 +0800

    examples/: Drop g_auto* usage
    
    This way, the handy-1-demo sample program will build on Visual Studio builds as
    well

 examples/hdy-demo-window.c          | 37 +++++++++++++++++++++++++++----------
 examples/hdy-tab-view-demo-window.c | 25 +++++++++++++++++++------
 2 files changed, 46 insertions(+), 16 deletions(-)
---
diff --git a/examples/hdy-demo-window.c b/examples/hdy-demo-window.c
index 119b2cd6..60ebeba9 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));
 
@@ -308,20 +310,25 @@ avatar_file_remove_cb (HdyDemoWindow *self)
   if (file)
     gtk_file_chooser_unselect_filename (GTK_FILE_CHOOSER (self->avatar_filechooser), file);
 
+  g_free (file);
+
   hdy_avatar_set_loadable_icon (self->avatar, NULL);
 }
 
 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,18 @@ 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)
+    if (pixbuf != NULL) {
       gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL);
+      g_object_unref (pixbuf);
+    }
+
+    g_free (filename);
   }
 
   g_object_unref (chooser);
@@ -415,13 +426,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 +445,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 +597,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..357909c9 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,16 @@ 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));
+
+  if (icon != NULL)
+    g_object_unref (icon);
 }
 
 static void
@@ -266,9 +271,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 +289,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 +438,7 @@ static void
 indicator_activated_cb (HdyTabViewDemoWindow *self,
                         HdyTabPage           *page)
 {
-  g_autoptr (GIcon) icon = NULL;
+  GIcon *icon;
   gboolean muted;
 
   muted = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (page),
@@ -442,6 +451,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 +463,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 +471,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]