[libadwaita] Unify get/set of most strings to none-nullable



commit 6929ede0611634776e6490f71a7463512afed33f
Author: Sophie Herold <sophie hemio de>
Date:   Mon Jul 5 18:00:20 2021 +0200

    Unify get/set of most strings to none-nullable
    
    - gtk_label_set_label() does not (officially) accept NULL
    - there is no need to accept/return NULL
    - it was not consistent between types before

 src/adw-action-row.c          |  4 ++--
 src/adw-avatar.c              |  6 ++++--
 src/adw-expander-row.c        |  4 ++--
 src/adw-preferences-group.c   |  4 ++--
 src/adw-preferences-page.c    |  9 ++++++---
 src/adw-preferences-row.c     |  8 +++++---
 src/adw-status-page.c         |  4 ++--
 src/adw-tab-view.c            | 16 +++++++++-------
 src/adw-tab.c                 |  2 +-
 src/adw-view-switcher-title.c | 12 ++++++------
 src/adw-window-title.c        | 16 ++++++++--------
 tests/test-avatar.c           |  2 +-
 tests/test-preferences-page.c |  4 ++--
 tests/test-preferences-row.c  |  4 ++--
 tests/test-tab-view.c         |  4 ++--
 15 files changed, 54 insertions(+), 45 deletions(-)
---
diff --git a/src/adw-action-row.c b/src/adw-action-row.c
index 55863ecf..a8f61659 100644
--- a/src/adw-action-row.c
+++ b/src/adw-action-row.c
@@ -460,7 +460,7 @@ adw_action_row_get_subtitle (AdwActionRow *self)
 /**
  * adw_action_row_set_subtitle: (attributes org.gtk.Method.set_property=subtitle)
  * @self: a `AdwActionRow`
- * @subtitle: (nullable): the subtitle
+ * @subtitle: the subtitle
  *
  * Sets the subtitle for @self.
  *
@@ -479,7 +479,7 @@ adw_action_row_set_subtitle (AdwActionRow *self,
   if (g_strcmp0 (gtk_label_get_text (priv->subtitle), subtitle) == 0)
     return;
 
-  gtk_label_set_text (priv->subtitle, subtitle);
+  gtk_label_set_label (priv->subtitle, subtitle);
   gtk_widget_set_visible (GTK_WIDGET (priv->subtitle),
                           subtitle != NULL && g_strcmp0 (subtitle, "") != 0);
 
diff --git a/src/adw-avatar.c b/src/adw-avatar.c
index dbbd7e06..a72f5bf6 100644
--- a/src/adw-avatar.c
+++ b/src/adw-avatar.c
@@ -331,7 +331,7 @@ adw_avatar_class_init (AdwAvatarClass *klass)
     g_param_spec_string ("text",
                          "Text",
                          "The text used to generate the color and the initials",
-                         NULL,
+                         "",
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   /**
@@ -402,6 +402,8 @@ adw_avatar_init (AdwAvatar *self)
   self->custom_image = GTK_IMAGE (gtk_image_new ());
   gtk_widget_set_parent (GTK_WIDGET (self->custom_image), self->gizmo);
 
+  self->text = g_strdup ("");
+
   set_class_color (self);
   update_initials (self);
   update_font_size (self);
@@ -519,7 +521,7 @@ adw_avatar_set_text (AdwAvatar  *self,
     return;
 
   g_clear_pointer (&self->text, g_free);
-  self->text = g_strdup (text);
+  self->text = g_strdup (text ? text : "");
 
   set_class_color (self);
 
diff --git a/src/adw-expander-row.c b/src/adw-expander-row.c
index b4b40ec6..b227a00d 100644
--- a/src/adw-expander-row.c
+++ b/src/adw-expander-row.c
@@ -355,7 +355,7 @@ adw_expander_row_new (void)
  *
  * Gets the subtitle for @self.
  *
- * Returns: (nullable): the subtitle for @self
+ * Returns: the subtitle for @self
  *
  * Since: 1.0
  */
@@ -374,7 +374,7 @@ adw_expander_row_get_subtitle (AdwExpanderRow *self)
 /**
  * adw_expander_row_set_subtitle: (attributes org.gtk.Method.set_property=subtitle)
  * @self: a `AdwExpanderRow`
- * @subtitle: (nullable): the subtitle
+ * @subtitle: the subtitle
  *
  * Sets the subtitle for @self.
  *
diff --git a/src/adw-preferences-group.c b/src/adw-preferences-group.c
index 28d61080..1727f698 100644
--- a/src/adw-preferences-group.c
+++ b/src/adw-preferences-group.c
@@ -274,7 +274,7 @@ adw_preferences_group_new (void)
  *
  * Gets the title of @self.
  *
- * Returns: (nullable): the title of @self
+ * Returns: the title of @self
  *
  * Since: 1.0
  */
@@ -293,7 +293,7 @@ adw_preferences_group_get_title (AdwPreferencesGroup *self)
 /**
  * adw_preferences_group_set_title: (attributes org.gtk.Method.set_property=title)
  * @self: a `AdwPreferencesGroup`
- * @title: (nullable): the title
+ * @title: the title
  *
  * Sets the title for @self.
  *
diff --git a/src/adw-preferences-page.c b/src/adw-preferences-page.c
index 363133d0..24978f74 100644
--- a/src/adw-preferences-page.c
+++ b/src/adw-preferences-page.c
@@ -192,6 +192,9 @@ adw_preferences_page_class_init (AdwPreferencesPageClass *klass)
 static void
 adw_preferences_page_init (AdwPreferencesPage *self)
 {
+  AdwPreferencesPagePrivate *priv = adw_preferences_page_get_instance_private (self);
+  priv->title = g_strdup ("");
+
   gtk_widget_init_template (GTK_WIDGET (self));
 }
 
@@ -288,7 +291,7 @@ adw_preferences_page_set_icon_name (AdwPreferencesPage *self,
  *
  * Gets the title of @self.
  *
- * Returns: (nullable): the title of @self.
+ * Returns: the title of @self.
  *
  * Since: 1.0
  */
@@ -307,7 +310,7 @@ adw_preferences_page_get_title (AdwPreferencesPage *self)
 /**
  * adw_preferences_page_set_title: (attributes org.gtk.Method.set_property=title)
  * @self: a `AdwPreferencesPage`
- * @title: (nullable): the title
+ * @title: the title
  *
  * Sets the title of @self.
  *
@@ -327,7 +330,7 @@ adw_preferences_page_set_title (AdwPreferencesPage *self,
     return;
 
   g_clear_pointer (&priv->title, g_free);
-  priv->title = g_strdup (title);
+  priv->title = g_strdup (title ? title : "");
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TITLE]);
 }
diff --git a/src/adw-preferences-row.c b/src/adw-preferences-row.c
index 31d46d3d..3ccbc042 100644
--- a/src/adw-preferences-row.c
+++ b/src/adw-preferences-row.c
@@ -136,6 +136,8 @@ adw_preferences_row_class_init (AdwPreferencesRowClass *klass)
 static void
 adw_preferences_row_init (AdwPreferencesRow *self)
 {
+    AdwPreferencesRowPrivate *priv = adw_preferences_row_get_instance_private (self);
+    priv->title = g_strdup ("");
 }
 
 /**
@@ -159,7 +161,7 @@ adw_preferences_row_new (void)
  *
  * Gets the title of the preference represented by @self.
  *
- * Returns:(nullable): the title
+ * Returns: the title
  *
  * Since: 1.0
  */
@@ -178,7 +180,7 @@ adw_preferences_row_get_title (AdwPreferencesRow *self)
 /**
  * adw_preferences_row_set_title: (attributes org.gtk.Method.set_property=title)
  * @self: a `AdwPreferencesRow`
- * @title: (nullable): the title
+ * @title: the title
  *
  * Sets the title of the preference represented by @self.
  *
@@ -198,7 +200,7 @@ adw_preferences_row_set_title (AdwPreferencesRow *self,
     return;
 
   g_free (priv->title);
-  priv->title = g_strdup (title);
+  priv->title = g_strdup (title ? title : "");
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TITLE]);
 }
diff --git a/src/adw-status-page.c b/src/adw-status-page.c
index fdb9c52a..3dd61ce5 100644
--- a/src/adw-status-page.c
+++ b/src/adw-status-page.c
@@ -333,7 +333,7 @@ adw_status_page_set_icon_name (AdwStatusPage *self,
  *
  * Gets the title for @self.
  *
- * Returns: (nullable): the title
+ * Returns: the title
  *
  * Since: 1.0
  */
@@ -348,7 +348,7 @@ adw_status_page_get_title (AdwStatusPage *self)
 /**
  * adw_status_page_set_title: (attributes org.gtk.Method.set_property=title)
  * @self: a `AdwStatusPage`
- * @title: (nullable): the title
+ * @title: the title
  *
  * Sets the title for @self.
  *
diff --git a/src/adw-tab-view.c b/src/adw-tab-view.c
index 02720586..8d99e17c 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -431,7 +431,7 @@ adw_tab_page_class_init (AdwTabPageClass *klass)
     g_param_spec_string ("title",
                          "Title",
                          "The title of the page",
-                         NULL,
+                         "",
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   /**
@@ -450,7 +450,7 @@ adw_tab_page_class_init (AdwTabPageClass *klass)
     g_param_spec_string ("tooltip",
                          "Tooltip",
                          "The tooltip of the page",
-                         NULL,
+                         "",
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   /**
@@ -561,6 +561,8 @@ adw_tab_page_class_init (AdwTabPageClass *klass)
 static void
 adw_tab_page_init (AdwTabPage *self)
 {
+  self->title = g_strdup ("");
+  self->tooltip = g_strdup ("");
 }
 
 #define ADW_TYPE_TAB_PAGES (adw_tab_pages_get_type ())
@@ -1844,7 +1846,7 @@ adw_tab_page_get_pinned (AdwTabPage *self)
  *
  * Gets the title of @self.
  *
- * Returns: (nullable): the title of @self
+ * Returns: the title of @self
  *
  * Since: 1.0
  */
@@ -1859,7 +1861,7 @@ adw_tab_page_get_title (AdwTabPage *self)
 /**
  * adw_tab_page_set_title: (attributes org.gtk.Method.set_property=title)
  * @self: a `AdwTabPage`
- * @title: (nullable): the title of @self
+ * @title: the title of @self
  *
  * Sets the title of @self.
  *
@@ -1875,7 +1877,7 @@ adw_tab_page_set_title (AdwTabPage *self,
     return;
 
   g_clear_pointer (&self->title, g_free);
-  self->title = g_strdup (title);
+  self->title = g_strdup (title ? title : "");
 
   g_object_notify_by_pspec (G_OBJECT (self), page_props[PAGE_PROP_TITLE]);
 }
@@ -1901,7 +1903,7 @@ adw_tab_page_get_tooltip (AdwTabPage *self)
 /**
  * adw_tab_page_set_tooltip: (attributes org.gtk.Method.set_property=tooltip)
  * @self: a `AdwTabPage`
- * @tooltip: (nullable): the tooltip of @self
+ * @tooltip: the tooltip of @self
  *
  * Sets the tooltip of @self.
  *
@@ -1917,7 +1919,7 @@ adw_tab_page_set_tooltip (AdwTabPage *self,
     return;
 
   g_clear_pointer (&self->tooltip, g_free);
-  self->tooltip = g_strdup (tooltip);
+  self->tooltip = g_strdup (tooltip ? tooltip : "");
 
   g_object_notify_by_pspec (G_OBJECT (self), page_props[PAGE_PROP_TOOLTIP]);
 }
diff --git a/src/adw-tab.c b/src/adw-tab.c
index 47e36020..efaf5c6e 100644
--- a/src/adw-tab.c
+++ b/src/adw-tab.c
@@ -148,7 +148,7 @@ update_tooltip (AdwTab *self)
 {
   const char *tooltip = adw_tab_page_get_tooltip (self->page);
 
-  if (tooltip)
+  if (tooltip && g_strcmp0 (tooltip, "") != 0)
     gtk_widget_set_tooltip_markup (GTK_WIDGET (self), tooltip);
   else
     gtk_widget_set_tooltip_text (GTK_WIDGET (self),
diff --git a/src/adw-view-switcher-title.c b/src/adw-view-switcher-title.c
index 8ea65c44..bd2b396c 100644
--- a/src/adw-view-switcher-title.c
+++ b/src/adw-view-switcher-title.c
@@ -254,7 +254,7 @@ adw_view_switcher_title_class_init (AdwViewSwitcherTitleClass *klass)
     g_param_spec_string ("title",
                          "Title",
                          "The title to display",
-                         NULL,
+                         "",
                          G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   /**
@@ -270,7 +270,7 @@ adw_view_switcher_title_class_init (AdwViewSwitcherTitleClass *klass)
     g_param_spec_string ("subtitle",
                          "Subtitle",
                          "The subtitle to display",
-                         NULL,
+                         "",
                          G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   /**
@@ -460,7 +460,7 @@ adw_view_switcher_title_set_stack (AdwViewSwitcherTitle *self,
  *
  * Gets the title of @self.
  *
- * Returns: (nullable): the title
+ * Returns: the title
  *
  * Since: 1.0
  */
@@ -475,7 +475,7 @@ adw_view_switcher_title_get_title (AdwViewSwitcherTitle *self)
 /**
  * adw_view_switcher_title_set_title: (attributes org.gtk.Method.set_property=title)
  * @self: a `AdwViewSwitcherTitle`
- * @title: (nullable): a title
+ * @title: a title
  *
  * Sets the title of @self.
  *
@@ -501,7 +501,7 @@ adw_view_switcher_title_set_title (AdwViewSwitcherTitle *self,
  *
  * Gets the subtitle of @self.
  *
- * Returns: (nullable): the subtitle
+ * Returns: the subtitle
  *
  * Since: 1.0
  */
@@ -516,7 +516,7 @@ adw_view_switcher_title_get_subtitle (AdwViewSwitcherTitle *self)
 /**
  * adw_view_switcher_title_set_subtitle: (attributes org.gtk.Method.get_property=subtitle)
  * @self: a `AdwViewSwitcherTitle`
- * @subtitle: (nullable): a subtitle
+ * @subtitle: a subtitle
  *
  * Sets the subtitle of @self.
  *
diff --git a/src/adw-window-title.c b/src/adw-window-title.c
index fe9e51a0..84034ebb 100644
--- a/src/adw-window-title.c
+++ b/src/adw-window-title.c
@@ -126,7 +126,7 @@ adw_window_title_class_init (AdwWindowTitleClass *klass)
     g_param_spec_string ("title",
                          "Title",
                          "The title to display",
-                         NULL,
+                         "",
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
   /**
@@ -142,7 +142,7 @@ adw_window_title_class_init (AdwWindowTitleClass *klass)
     g_param_spec_string ("subtitle",
                          "Subtitle",
                          "The subtitle to display",
-                         NULL,
+                         "",
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
   g_object_class_install_properties (object_class, LAST_PROP, props);
@@ -159,8 +159,8 @@ adw_window_title_class_init (AdwWindowTitleClass *klass)
 
 /**
  * adw_window_title_new:
- * @title: (nullable): a title
- * @subtitle: (nullable): a subtitle
+ * @title: a title
+ * @subtitle: a subtitle
  *
  * Creates a new `AdwWindowTitle`.
  *
@@ -184,7 +184,7 @@ adw_window_title_new (const char *title,
  *
  * Gets the title of @self.
  *
- * Returns: (nullable): the title
+ * Returns: the title
  *
  * Since: 1.0
  */
@@ -199,7 +199,7 @@ adw_window_title_get_title (AdwWindowTitle *self)
 /**
  * adw_window_title_set_title: (attributes org.gtk.Method.set_property=title)
  * @self: a `AdwWindowTitle`
- * @title: (nullable): a title
+ * @title: a title
  *
  * Sets the title of @self.
  *
@@ -227,7 +227,7 @@ adw_window_title_set_title (AdwWindowTitle *self,
  *
  * Gets the subtitle of @self.
  *
- * Returns: (nullable): the subtitle
+ * Returns: the subtitle
  *
  * Since: 1.0
  */
@@ -242,7 +242,7 @@ adw_window_title_get_subtitle (AdwWindowTitle *self)
 /**
  * adw_window_title_set_subtitle: (attributes org.gtk.Method.set_property=subtitle)
  * @self: a `AdwWindowTitle`
- * @subtitle: (nullable): a subtitle
+ * @subtitle: a subtitle
  *
  * Sets the subtitle of @self.
  *
diff --git a/tests/test-avatar.c b/tests/test-avatar.c
index 63aabcc3..56b27a14 100644
--- a/tests/test-avatar.c
+++ b/tests/test-avatar.c
@@ -26,7 +26,7 @@ test_adw_avatar_text (void)
 {
   AdwAvatar *avatar = ADW_AVATAR (adw_avatar_new (128, NULL, TRUE));
 
-  g_assert_null (adw_avatar_get_text (avatar));
+  g_assert_cmpstr (adw_avatar_get_text (avatar), ==, "");
   adw_avatar_set_text (avatar, TEST_STRING);
   g_assert_cmpstr (adw_avatar_get_text (avatar), ==, TEST_STRING);
 }
diff --git a/tests/test-preferences-page.c b/tests/test-preferences-page.c
index e7ce1156..44d67357 100644
--- a/tests/test-preferences-page.c
+++ b/tests/test-preferences-page.c
@@ -32,13 +32,13 @@ test_adw_preferences_page_title (void)
   page = g_object_ref_sink (ADW_PREFERENCES_PAGE (adw_preferences_page_new ()));
   g_assert_nonnull (page);
 
-  g_assert_null (adw_preferences_page_get_title (page));
+  g_assert_cmpstr (adw_preferences_page_get_title (page), ==, "");
 
   adw_preferences_page_set_title (page, "Dummy title");
   g_assert_cmpstr (adw_preferences_page_get_title (page), ==, "Dummy title");
 
   adw_preferences_page_set_title (page, NULL);
-  g_assert_null (adw_preferences_page_get_title (page));
+  g_assert_cmpstr (adw_preferences_page_get_title (page), ==, "");
 }
 
 
diff --git a/tests/test-preferences-row.c b/tests/test-preferences-row.c
index d3fbe325..b7fbf7cc 100644
--- a/tests/test-preferences-row.c
+++ b/tests/test-preferences-row.c
@@ -15,13 +15,13 @@ test_adw_preferences_row_title (void)
   row = g_object_ref_sink (ADW_PREFERENCES_ROW (adw_preferences_row_new ()));
   g_assert_nonnull (row);
 
-  g_assert_null (adw_preferences_row_get_title (row));
+  g_assert_cmpstr (adw_preferences_row_get_title (row), ==, "");
 
   adw_preferences_row_set_title (row, "Dummy title");
   g_assert_cmpstr (adw_preferences_row_get_title (row), ==, "Dummy title");
 
   adw_preferences_row_set_title (row, NULL);
-  g_assert_null (adw_preferences_row_get_title (row));
+  g_assert_cmpstr (adw_preferences_row_get_title (row), ==, "");
 }
 
 
diff --git a/tests/test-tab-view.c b/tests/test-tab-view.c
index 8be59db0..68e32a29 100644
--- a/tests/test-tab-view.c
+++ b/tests/test-tab-view.c
@@ -959,7 +959,7 @@ test_adw_tab_page_title (void)
   g_signal_connect (page, "notify::title", G_CALLBACK (notify_cb), NULL);
 
   g_object_get (page, "title", &title, NULL);
-  g_assert_null (title);
+  g_assert_cmpstr (title, ==, "");
   g_assert_cmpint (notified, ==, 0);
 
   adw_tab_page_set_title (page, "Some title");
@@ -989,7 +989,7 @@ test_adw_tab_page_tooltip (void)
   g_signal_connect (page, "notify::tooltip", G_CALLBACK (notify_cb), NULL);
 
   g_object_get (page, "tooltip", &tooltip, NULL);
-  g_assert_null (tooltip);
+  g_assert_cmpstr (tooltip, ==, "");
   g_assert_cmpint (notified, ==, 0);
 
   adw_tab_page_set_tooltip (page, "Some tooltip");


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