diff --git a/demos/gtk-demo/listview_clocks.c b/demos/gtk-demo/listview_clocks.c index 4578c229cd..80dcb8505d 100644 --- a/demos/gtk-demo/listview_clocks.c +++ b/demos/gtk-demo/listview_clocks.c @@ -462,7 +462,6 @@ do_listview_clocks (GtkWidget *do_widget) { GtkWidget *gridview, *sw; GtkListItemFactory *factory; - GListModel *model; GtkNoSelection *selection; /* This is the normal window setup code every demo does */ @@ -489,12 +488,10 @@ do_listview_clocks (GtkWidget *do_widget) gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL); gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL); - model = create_clocks_model (); - selection = gtk_no_selection_new (model); + selection = gtk_no_selection_new (create_clocks_model ()); gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), G_LIST_MODEL (selection)); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview); g_object_unref (selection); - g_object_unref (model); } if (!gtk_widget_get_visible (window)) diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c index edbdb75c4d..94210bf9ce 100644 --- a/demos/gtk-demo/listview_colors.c +++ b/demos/gtk-demo/listview_colors.c @@ -970,7 +970,6 @@ do_listview_colors (GtkWidget *do_widget) no_selection = G_LIST_MODEL (gtk_no_selection_new (selection_filter)); gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), no_selection); - g_object_unref (selection_filter); g_object_unref (no_selection); selection_info_toggle = gtk_toggle_button_new (); diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c index 49dca2376a..0ddd61889b 100644 --- a/demos/gtk-demo/listview_settings.c +++ b/demos/gtk-demo/listview_settings.c @@ -214,7 +214,6 @@ transform_settings_to_keys (GBinding *binding, GtkSortListModel *sort_model; GtkFilterListModel *filter_model; GtkFilter *filter; - GtkNoSelection *selection_model; char **keys; guint i; @@ -248,10 +247,7 @@ transform_settings_to_keys (GBinding *binding, g_set_object (¤t_filter, filter); filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter); - selection_model = gtk_no_selection_new (G_LIST_MODEL (filter_model)); - g_object_unref (filter_model); - - g_value_take_object (to_value, selection_model); + g_value_take_object (to_value, gtk_no_selection_new (G_LIST_MODEL (filter_model))); return TRUE; } diff --git a/demos/gtk-demo/listview_weather.c b/demos/gtk-demo/listview_weather.c index 535a9d179b..f17ff08921 100644 --- a/demos/gtk-demo/listview_weather.c +++ b/demos/gtk-demo/listview_weather.c @@ -281,7 +281,7 @@ GtkWidget * create_weather_view (void) { GtkWidget *listview; - GListModel *model, *selection; + GListModel *selection; GtkListItemFactory *factory; factory = gtk_signal_list_item_factory_new (); @@ -290,11 +290,9 @@ create_weather_view (void) listview = gtk_list_view_new_with_factory (factory); gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL); gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE); - model = create_weather_model (); - selection = G_LIST_MODEL (gtk_no_selection_new (model)); + selection = G_LIST_MODEL (gtk_no_selection_new (create_weather_model ())); gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection); g_object_unref (selection); - g_object_unref (model); return listview; } diff --git a/demos/gtk-demo/listview_words.c b/demos/gtk-demo/listview_words.c index 95664ed279..4545ed48aa 100644 --- a/demos/gtk-demo/listview_words.c +++ b/demos/gtk-demo/listview_words.c @@ -226,7 +226,6 @@ do_listview_words (GtkWidget *do_widget) g_signal_connect (filter_model, "notify::pending", G_CALLBACK (update_title_cb), progress); update_title_cb (filter_model); - g_object_unref (filter_model); } if (!gtk_widget_get_visible (window)) diff --git a/gtk/gtknoselection.c b/gtk/gtknoselection.c index 8027d003b2..597eb4af31 100644 --- a/gtk/gtknoselection.c +++ b/gtk/gtknoselection.c @@ -216,7 +216,7 @@ gtk_no_selection_init (GtkNoSelection *self) /** * gtk_no_selection_new: - * @model: (transfer none): the #GListModel to manage + * @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL * * Creates a new selection to handle @model. * @@ -225,11 +225,18 @@ gtk_no_selection_init (GtkNoSelection *self) GtkNoSelection * gtk_no_selection_new (GListModel *model) { + GtkNoSelection *self; + g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL); - return g_object_new (GTK_TYPE_NO_SELECTION, + self = g_object_new (GTK_TYPE_NO_SELECTION, "model", model, NULL); + + /* consume the reference */ + g_clear_object (&model); + + return self; } /** @@ -253,8 +260,8 @@ gtk_no_selection_get_model (GtkNoSelection *self) * @self: a #GtkNoSelection * @model: (allow-none): A #GListModel to wrap * - * Sets the model that @self should wrap. If @model is %NULL, this - * model will be empty. + * Sets the model that @self should wrap. + * If @model is %NULL, this model will be empty. **/ void gtk_no_selection_set_model (GtkNoSelection *self, diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c index 9f68ded33e..339645e590 100644 --- a/gtk/inspector/actions.c +++ b/gtk/inspector/actions.c @@ -400,7 +400,6 @@ constructed (GObject *object) g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list))))); model = G_LIST_MODEL (gtk_no_selection_new (sorted)); gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model); - g_object_unref (sorted); g_object_unref (model); } diff --git a/gtk/inspector/list-data.c b/gtk/inspector/list-data.c index 596a4dbbdd..fe1006edcb 100644 --- a/gtk/inspector/list-data.c +++ b/gtk/inspector/list-data.c @@ -85,7 +85,7 @@ gtk_inspector_list_data_set_object (GtkInspectorListData *sl, g_object_set (page, "visible", TRUE, NULL); sl->object = G_LIST_MODEL (object); - selection = gtk_no_selection_new (sl->object); + selection = gtk_no_selection_new (g_object_ref (sl->object)); gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection)); g_object_unref (selection); } diff --git a/gtk/inspector/prop-list.c b/gtk/inspector/prop-list.c index e7d2aeb21b..970e83cb4a 100644 --- a/gtk/inspector/prop-list.c +++ b/gtk/inspector/prop-list.c @@ -633,7 +633,6 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl, gtk_widget_show (GTK_WIDGET (pl)); g_object_unref (list); - g_object_unref (sorted); return TRUE; }