Implement koto_utils_is_valid_string to replace repetitive NULL and g_strcmp0 code.

Reduce usage of g_return_if_fail since it results in unnecessary warnings.
This commit is contained in:
Joshua Strobl 2021-05-07 21:52:42 +03:00
parent 0aafa68a35
commit b4ffba62c7
17 changed files with 121 additions and 65 deletions

View file

@ -23,6 +23,7 @@
#include "../playlist/add-remove-track-popover.h"
#include "../playback/engine.h"
#include "../koto-button.h"
#include "../koto-utils.h"
#include "../koto-window.h"
extern KotoAddRemoveTrackPopover *koto_add_remove_track_popup;
@ -246,7 +247,7 @@ void koto_action_bar_handle_remove_from_playlist_button_clicked(GtkButton *butto
goto doclose;
}
if (self->current_playlist_uuid == NULL || (g_strcmp0(self->current_playlist_uuid, "") == 0)) { // Not valid UUID
if (!koto_utils_is_string_valid(self->current_playlist_uuid)) { // Not valid UUID
goto doclose;
}
@ -271,11 +272,11 @@ void koto_action_bar_set_tracks_in_album_selection(KotoActionBar *self, gchar *a
return;
}
if (self->current_album_uuid != NULL && (g_strcmp0(self->current_album_uuid, "") != 0)) { // Album UUID currently set
if (koto_utils_is_string_valid(self->current_album_uuid)) { // Album UUID currently set
g_free(self->current_album_uuid);
}
if (self->current_playlist_uuid != NULL && (g_strcmp0(self->current_playlist_uuid, "") != 0)) { // Playlist UUID currently set
if (koto_utils_is_string_valid(self->current_playlist_uuid)) { // Playlist UUID currently set
g_free(self->current_playlist_uuid);
}
@ -301,11 +302,11 @@ void koto_action_bar_set_tracks_in_playlist_selection(KotoActionBar *self, gchar
return;
}
if (self->current_album_uuid != NULL && (g_strcmp0(self->current_album_uuid, "") != 0)) { // Album UUID currently set
if (koto_utils_is_string_valid(self->current_album_uuid)) { // Album UUID currently set
g_free(self->current_album_uuid);
}
if (self->current_playlist_uuid != NULL && (g_strcmp0(self->current_playlist_uuid, "") != 0)) { // Playlist UUID currently set
if (koto_utils_is_string_valid(self->current_playlist_uuid)) { // Playlist UUID currently set
g_free(self->current_playlist_uuid);
}

View file

@ -120,7 +120,7 @@ static void koto_cover_art_button_set_property(GObject *obj, guint prop_id, cons
switch (prop_id) {
case PROP_ART_PATH:
koto_cover_art_button_set_art_path(self, g_value_get_string(val)); // Get the value and call our set_art_path with it
koto_cover_art_button_set_art_path(self, (gchar*) g_value_get_string(val)); // Get the value and call our set_art_path with it
break;
case PROP_DESIRED_HEIGHT:
koto_cover_art_button_set_dimensions(self, g_value_get_uint(val), 0);
@ -156,12 +156,12 @@ GtkWidget* koto_cover_art_button_get_main(KotoCoverArtButton *self) {
return self->main;
}
void koto_cover_art_button_set_art_path(KotoCoverArtButton *self, const gchar *art_path) {
void koto_cover_art_button_set_art_path(KotoCoverArtButton *self, gchar *art_path) {
if (!KOTO_IS_COVER_ART_BUTTON(self)) {
return;
}
gboolean defined_artwork = (art_path != NULL || (g_strcmp0(art_path, "") != 0));
gboolean defined_artwork = koto_utils_is_string_valid(art_path);
if (GTK_IS_IMAGE(self->art)) { // Already have an image
if (!defined_artwork) { // No art path or empty string
@ -204,7 +204,7 @@ void koto_cover_art_button_show_overlay_controls(GtkEventControllerFocus *contro
gtk_revealer_set_reveal_child(GTK_REVEALER(self->revealer), TRUE);
}
KotoCoverArtButton* koto_cover_art_button_new(guint height, guint width, const gchar *art_path) {
KotoCoverArtButton* koto_cover_art_button_new(guint height, guint width, gchar *art_path) {
return g_object_new(KOTO_TYPE_COVER_ART_BUTTON,
"desired-height",
height,

View file

@ -29,11 +29,11 @@ G_DECLARE_FINAL_TYPE(KotoCoverArtButton, koto_cover_art_button, KOTO, COVER_ART_
* Cover Art Functions
**/
KotoCoverArtButton* koto_cover_art_button_new(guint height, guint width, const gchar *art_path);
KotoCoverArtButton* koto_cover_art_button_new(guint height, guint width, gchar *art_path);
KotoButton* koto_cover_art_button_get_button(KotoCoverArtButton *self);
GtkWidget* koto_cover_art_button_get_main(KotoCoverArtButton *self);
void koto_cover_art_button_hide_overlay_controls(GtkEventControllerFocus *controller, gpointer data);
void koto_cover_art_button_set_art_path(KotoCoverArtButton *self, const gchar *art_path);
void koto_cover_art_button_set_art_path(KotoCoverArtButton *self, gchar *art_path);
void koto_cover_art_button_set_dimensions(KotoCoverArtButton *self, guint height, guint width);
void koto_cover_art_button_show_overlay_controls(GtkEventControllerFocus *controller, gpointer data);