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:
parent
0aafa68a35
commit
b4ffba62c7
17 changed files with 121 additions and 65 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -355,7 +355,7 @@ static void koto_indexed_album_set_property(GObject *obj, guint prop_id, const G
|
|||
self->do_initial_index = g_value_get_boolean(val);
|
||||
break;
|
||||
case PROP_PATH: // Path to the album
|
||||
koto_indexed_album_update_path(self, g_value_get_string(val));
|
||||
koto_indexed_album_update_path(self, (gchar*) g_value_get_string(val));
|
||||
break;
|
||||
case PROP_ALBUM_NAME: // Name of album
|
||||
koto_indexed_album_set_album_name(self, g_value_get_string(val));
|
||||
|
@ -377,7 +377,7 @@ gchar* koto_indexed_album_get_album_art(KotoIndexedAlbum *self) {
|
|||
return g_strdup("");
|
||||
}
|
||||
|
||||
return g_strdup((self->has_album_art && (self->art_path != NULL) && (g_strcmp0(self->art_path, "") != 0)) ? self->art_path : "");
|
||||
return g_strdup((self->has_album_art && koto_utils_is_string_valid(self->art_path)) ? self->art_path : "");
|
||||
}
|
||||
|
||||
gchar *koto_indexed_album_get_album_name(KotoIndexedAlbum *self) {
|
||||
|
@ -385,7 +385,7 @@ gchar *koto_indexed_album_get_album_name(KotoIndexedAlbum *self) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if ((self->name == NULL) || g_strcmp0(self->name, "") == 0) { // Not set
|
||||
if (!koto_utils_is_string_valid(self->name)) { // Not set
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,11 @@ gchar *koto_indexed_album_get_album_name(KotoIndexedAlbum *self) {
|
|||
}
|
||||
|
||||
gchar* koto_indexed_album_get_album_uuid(KotoIndexedAlbum *self) {
|
||||
if ((self->uuid == NULL) || g_strcmp0(self->uuid, "") == 0) { // Not set
|
||||
if (!KOTO_IS_INDEXED_ALBUM(self)) { // Not an album
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!koto_utils_is_string_valid(self->uuid)) { // Not set
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -550,16 +554,16 @@ gint koto_indexed_album_sort_tracks(gconstpointer track1_uuid, gconstpointer tra
|
|||
}
|
||||
}
|
||||
|
||||
void koto_indexed_album_update_path(KotoIndexedAlbum *self, const gchar* new_path) {
|
||||
void koto_indexed_album_update_path(KotoIndexedAlbum *self, gchar* new_path) {
|
||||
if (!KOTO_IS_INDEXED_ALBUM(self)) { // Not an album
|
||||
return;
|
||||
}
|
||||
|
||||
if ((new_path == NULL) || g_strcmp0(new_path, "") == 0) {
|
||||
if (!koto_utils_is_string_valid(new_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((self->path != NULL) && g_strcmp0(self->path, "") != 0) {
|
||||
if (koto_utils_is_string_valid(self->path)) { // Path is currently set
|
||||
g_free(self->path);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <sqlite3.h>
|
||||
#include "structs.h"
|
||||
#include "../db/db.h"
|
||||
#include "../koto-utils.h"
|
||||
|
||||
extern sqlite3 *koto_db;
|
||||
|
||||
|
@ -139,10 +140,10 @@ static void koto_indexed_artist_set_property(GObject *obj, guint prop_id, const
|
|||
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_UUID]);
|
||||
break;
|
||||
case PROP_PATH:
|
||||
koto_indexed_artist_update_path(self, g_value_get_string(val));
|
||||
koto_indexed_artist_update_path(self, (gchar*) g_value_get_string(val));
|
||||
break;
|
||||
case PROP_ARTIST_NAME:
|
||||
koto_indexed_artist_set_artist_name(self, g_value_get_string(val));
|
||||
koto_indexed_artist_set_artist_name(self, (gchar*) g_value_get_string(val));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec);
|
||||
|
@ -155,7 +156,7 @@ void koto_indexed_artist_add_album(KotoIndexedArtist *self, gchar *album_uuid) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ((album_uuid == NULL) || g_strcmp0(album_uuid, "") == 0) { // No album UUID really defined
|
||||
if (!koto_utils_is_string_valid(album_uuid)) { // No album UUID really defined
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -179,7 +180,7 @@ gchar* koto_indexed_artist_get_name(KotoIndexedArtist *self) {
|
|||
return g_strdup("");
|
||||
}
|
||||
|
||||
return g_strdup(g_strcmp0(self->artist_name, "") == 0 ? "" : self->artist_name); // Return artist name if set
|
||||
return g_strdup(koto_utils_is_string_valid(self->artist_name) ? self->artist_name : ""); // Return artist name if set
|
||||
}
|
||||
|
||||
void koto_indexed_artist_remove_album(KotoIndexedArtist *self, KotoIndexedAlbum *album) {
|
||||
|
@ -196,16 +197,16 @@ void koto_indexed_artist_remove_album(KotoIndexedArtist *self, KotoIndexedAlbum
|
|||
self->albums = g_list_remove(self->albums, album_uuid);
|
||||
}
|
||||
|
||||
void koto_indexed_artist_update_path(KotoIndexedArtist *self, const gchar *new_path) {
|
||||
void koto_indexed_artist_update_path(KotoIndexedArtist *self, gchar *new_path) {
|
||||
if (!KOTO_IS_INDEXED_ARTIST(self)) { // Not an artist
|
||||
return;
|
||||
}
|
||||
|
||||
if ((new_path == NULL) || g_strcmp0(new_path, "") == 0) { // No path really
|
||||
if (!koto_utils_is_string_valid(new_path)) { // No path really
|
||||
return;
|
||||
}
|
||||
|
||||
if ((self->path != NULL) && g_strcmp0(self->path, "") != 0) { // Already have a path set
|
||||
if (koto_utils_is_string_valid(self->path)) { // Already have a path set
|
||||
g_free(self->path); // Free
|
||||
}
|
||||
|
||||
|
@ -213,16 +214,16 @@ void koto_indexed_artist_update_path(KotoIndexedArtist *self, const gchar *new_p
|
|||
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PATH]);
|
||||
}
|
||||
|
||||
void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, const gchar *artist_name) {
|
||||
void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, gchar *artist_name) {
|
||||
if (!KOTO_IS_INDEXED_ARTIST(self)) { // Not an artist
|
||||
return;
|
||||
}
|
||||
|
||||
if ((artist_name == NULL) || g_strcmp0(artist_name, "") == 0) { // No artist name
|
||||
if (!koto_utils_is_string_valid(artist_name)) { // No artist name
|
||||
return;
|
||||
}
|
||||
|
||||
if ((self->artist_name != NULL) && g_strcmp0(self->artist_name, "") != 0) { // Has artist name
|
||||
if (koto_utils_is_string_valid(self->artist_name)) { // Has artist name
|
||||
g_free(self->artist_name);
|
||||
}
|
||||
|
||||
|
@ -230,7 +231,7 @@ void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, const gchar *a
|
|||
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_ARTIST_NAME]);
|
||||
}
|
||||
|
||||
KotoIndexedArtist* koto_indexed_artist_new(const gchar *path) {
|
||||
KotoIndexedArtist* koto_indexed_artist_new(gchar *path) {
|
||||
KotoIndexedArtist* artist = g_object_new(KOTO_TYPE_INDEXED_ARTIST,
|
||||
"uuid", g_uuid_string_random(),
|
||||
"path", path,
|
||||
|
|
|
@ -66,7 +66,7 @@ void output_track(gpointer data, gpointer user_data);
|
|||
* Artist Functions
|
||||
**/
|
||||
|
||||
KotoIndexedArtist* koto_indexed_artist_new(const gchar *path);
|
||||
KotoIndexedArtist* koto_indexed_artist_new(gchar *path);
|
||||
KotoIndexedArtist* koto_indexed_artist_new_with_uuid(const gchar *uuid);
|
||||
|
||||
void koto_indexed_artist_add_album(KotoIndexedArtist *self, gchar *album_uuid);
|
||||
|
@ -76,8 +76,8 @@ GList* koto_indexed_artist_get_albums(KotoIndexedArtist *self);
|
|||
gchar* koto_indexed_artist_get_name(KotoIndexedArtist *self);
|
||||
void koto_indexed_artist_remove_album(KotoIndexedArtist *self, KotoIndexedAlbum *album);
|
||||
void koto_indexed_artist_remove_album_by_name(KotoIndexedArtist *self, gchar *album_name);
|
||||
void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, const gchar *artist_name);
|
||||
void koto_indexed_artist_update_path(KotoIndexedArtist *self, const gchar *new_path);
|
||||
void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, gchar *artist_name);
|
||||
void koto_indexed_artist_update_path(KotoIndexedArtist *self, gchar *new_path);
|
||||
void output_artists(gpointer artist_key, gpointer artist_ptr, gpointer data);
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,7 @@ void koto_indexed_album_set_album_art(KotoIndexedAlbum *self, const gchar *album
|
|||
void koto_indexed_album_set_album_name(KotoIndexedAlbum *self, const gchar *album_name);
|
||||
void koto_indexed_album_set_artist_uuid(KotoIndexedAlbum *self, const gchar *artist_uuid);
|
||||
void koto_indexed_album_set_as_current_playlist(KotoIndexedAlbum *self);
|
||||
void koto_indexed_album_update_path(KotoIndexedAlbum *self, const gchar *path);
|
||||
void koto_indexed_album_update_path(KotoIndexedAlbum *self, gchar *path);
|
||||
gint koto_indexed_album_sort_tracks(gconstpointer track1_uuid, gconstpointer track2_uuid, gpointer user_data);
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <gtk-4.0/gtk/gtk.h>
|
||||
#include "koto-button.h"
|
||||
#include "koto-config.h"
|
||||
#include "koto-utils.h"
|
||||
|
||||
struct _PixbufSize {
|
||||
guint size;
|
||||
|
@ -311,11 +312,11 @@ void koto_button_set_file_path(KotoButton *self, gchar *file_path) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (file_path == NULL || (g_strcmp0(file_path, "") == 0)) { // Empty string or null
|
||||
if (!koto_utils_is_string_valid(file_path)) { // file path is invalid
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->image_file_path != NULL && (g_strcmp0(self->image_file_path, "") != 0)) { // Not null and not empty
|
||||
if (koto_utils_is_string_valid(self->image_file_path)) { // image file path is valid
|
||||
g_free(self->image_file_path);
|
||||
}
|
||||
|
||||
|
@ -375,7 +376,9 @@ void koto_button_set_image_position(KotoButton *self, KotoButtonImagePosition po
|
|||
}
|
||||
|
||||
void koto_button_set_pixbuf_size(KotoButton *self, guint size) {
|
||||
g_return_if_fail(size != self->pix_size); // If the sizes aren't different, return
|
||||
if (size == self->pix_size) {
|
||||
return;
|
||||
}
|
||||
|
||||
self->pix_size = size;
|
||||
gtk_widget_set_size_request(GTK_WIDGET(self), self->pix_size, self->pix_size);
|
||||
|
@ -395,7 +398,7 @@ void koto_button_set_text(KotoButton *self, gchar *text) {
|
|||
self->text = g_strdup(text);
|
||||
|
||||
if (GTK_IS_LABEL(self->button_label)) { // If we have a button label
|
||||
if (g_strcmp0(self->text, "") != 0) { // Have text set
|
||||
if (koto_utils_is_string_valid(self->text)) { // Have text set
|
||||
gtk_label_set_text(GTK_LABEL(self->button_label), self->text);
|
||||
gtk_widget_show(self->button_label); // Show the label
|
||||
} else { // Have a label but no longer text
|
||||
|
@ -403,7 +406,7 @@ void koto_button_set_text(KotoButton *self, gchar *text) {
|
|||
g_free(self->button_label);
|
||||
}
|
||||
} else { // If we do not have a button label
|
||||
if ((self->text != NULL) && (g_strcmp0(self->text, "") != 0)) { // If we have text
|
||||
if (koto_utils_is_string_valid(self->text)) { // If we have text
|
||||
self->button_label = gtk_label_new(self->text); // Create our label
|
||||
gtk_label_set_xalign(GTK_LABEL(self->button_label), 0);
|
||||
|
||||
|
@ -424,7 +427,7 @@ void koto_button_show_image(KotoButton *self, gboolean use_alt) {
|
|||
}
|
||||
|
||||
if (self->use_from_file) { // Use from a file instead of icon name
|
||||
if ((self->image_file_path == NULL) || g_strcmp0(self->image_file_path, "") == 0) { // Not set
|
||||
if (!koto_utils_is_string_valid(self->image_file_path)) { // Not set
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "koto-button.h"
|
||||
#include "koto-expander.h"
|
||||
#include "koto-nav.h"
|
||||
#include "koto-utils.h"
|
||||
#include "koto-window.h"
|
||||
|
||||
extern KotoCartographer *koto_maps;
|
||||
|
@ -186,10 +187,14 @@ void koto_nav_handle_playlist_button_click(GtkGestureClick *gesture, int n_press
|
|||
|
||||
void koto_nav_handle_playlist_added(KotoCartographer *carto, KotoPlaylist *playlist, gpointer user_data) {
|
||||
(void) carto;
|
||||
g_return_if_fail(KOTO_IS_PLAYLIST(playlist));
|
||||
if (!KOTO_IS_PLAYLIST(playlist)) {
|
||||
return;
|
||||
}
|
||||
|
||||
KotoNav *self = user_data;
|
||||
g_return_if_fail(KOTO_IS_NAV(self));
|
||||
if (!KOTO_IS_NAV(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
gchar *playlist_uuid = koto_playlist_get_uuid(playlist); // Get the UUID for a playlist
|
||||
|
||||
|
@ -202,7 +207,7 @@ void koto_nav_handle_playlist_added(KotoCartographer *carto, KotoPlaylist *playl
|
|||
gchar *playlist_art_path = koto_playlist_get_artwork(playlist); // Get any file path for it
|
||||
KotoButton *playlist_button = NULL;
|
||||
|
||||
if ((playlist_art_path != NULL) && g_strcmp0(playlist_art_path, "") != 0) { // Have a file associated
|
||||
if (koto_utils_is_string_valid(playlist_art_path)) { // Have a file associated
|
||||
playlist_button = koto_button_new_with_file(playlist_name, playlist_art_path, KOTO_BUTTON_PIXBUF_SIZE_NORMAL);
|
||||
} else { // No file associated
|
||||
playlist_button = koto_button_new_with_icon(playlist_name, "audio-x-generic-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_NORMAL);
|
||||
|
|
|
@ -87,6 +87,10 @@ gchar* koto_utils_get_filename_without_extension(gchar *filename) {
|
|||
return stripped_file_name;
|
||||
}
|
||||
|
||||
gboolean koto_utils_is_string_valid(gchar *str) {
|
||||
return ((str != NULL) && (g_strcmp0(str, "") != 0));
|
||||
}
|
||||
|
||||
void koto_utils_push_queue_element_to_store(gpointer data, gpointer user_data) {
|
||||
g_list_store_append(G_LIST_STORE(user_data), data);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ G_BEGIN_DECLS
|
|||
GtkFileChooserNative* koto_utils_create_image_file_chooser(gchar *file_chooser_label);
|
||||
GtkWidget* koto_utils_create_image_from_filepath(gchar *filepath, gchar *fallback_icon, guint width, guint height);
|
||||
gchar* koto_utils_get_filename_without_extension(gchar *filename);
|
||||
gboolean koto_utils_is_string_valid(gchar *str);
|
||||
void koto_utils_push_queue_element_to_store(gpointer data, gpointer user_data);
|
||||
gchar *koto_utils_replace_string_all(gchar *str, gchar *find, gchar *repl);
|
||||
gchar* koto_utils_unquote_string(gchar *s);
|
||||
|
|
|
@ -169,9 +169,11 @@ void koto_window_hide_dialogs(KotoWindow *self) {
|
|||
|
||||
void koto_window_remove_page(KotoWindow *self, gchar *page_name) {
|
||||
GtkWidget *page = gtk_stack_get_child_by_name(GTK_STACK(self->pages), page_name);
|
||||
g_return_if_fail(page != NULL);
|
||||
|
||||
if (GTK_IS_WIDGET(page)) {
|
||||
gtk_stack_remove(GTK_STACK(self->pages), page);
|
||||
}
|
||||
}
|
||||
|
||||
void koto_window_show_dialog(KotoWindow *self, gchar *dialog_name) {
|
||||
koto_dialog_container_show_dialog(self->dialogs, dialog_name);
|
||||
|
@ -216,11 +218,16 @@ void load_library(KotoWindow *self) {
|
|||
|
||||
void set_optimal_default_window_size(KotoWindow *self) {
|
||||
GdkDisplay *default_display = gdk_display_get_default();
|
||||
g_return_if_fail(GDK_IS_X11_DISPLAY(default_display));
|
||||
|
||||
if (!GDK_IS_X11_DISPLAY(default_display)) { // Not an X11 display
|
||||
return;
|
||||
}
|
||||
|
||||
GdkMonitor *default_monitor = gdk_x11_display_get_primary_monitor(GDK_X11_DISPLAY(default_display)); // Get primary monitor for the X11
|
||||
g_return_if_fail(default_monitor);
|
||||
|
||||
if (!GDK_IS_X11_MONITOR(default_monitor)) { // Not an X11 Monitor
|
||||
return;
|
||||
}
|
||||
|
||||
GdkRectangle workarea = {0};
|
||||
gdk_monitor_get_geometry(default_monitor, &workarea);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "../../db/cartographer.h"
|
||||
#include "../../indexer/structs.h"
|
||||
#include "../../koto-track-item.h"
|
||||
#include "../../koto-utils.h"
|
||||
#include "disc-view.h"
|
||||
|
||||
extern KotoActionBar *action_bar;
|
||||
|
@ -156,7 +157,7 @@ void koto_disc_view_handle_selected_rows_changed(GtkListBox *box, gpointer user_
|
|||
|
||||
gchar *album_uuid = koto_indexed_album_get_album_uuid(self->album); // Get the UUID
|
||||
|
||||
if ((album_uuid == NULL) || g_strcmp0(album_uuid, "") == 0) { // Not set
|
||||
if (!koto_utils_is_string_valid(album_uuid)) { // Not set
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "../../indexer/structs.h"
|
||||
#include "koto-button.h"
|
||||
#include "koto-config.h"
|
||||
#include "../../koto-utils.h"
|
||||
#include "music-local.h"
|
||||
|
||||
extern KotoCartographer *koto_maps;
|
||||
|
@ -166,7 +167,7 @@ void koto_page_music_local_go_to_artist_by_uuid(KotoPageMusicLocal *self, gchar
|
|||
NULL
|
||||
);
|
||||
|
||||
if (artist_name == NULL || (g_strcmp0(artist_name, "") == 0)) { // Failed to get the artist name
|
||||
if (!koto_utils_is_string_valid(artist_name)) { // Failed to get the artist name
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,9 @@ void koto_playlist_page_bind_track_item(GtkListItemFactory *factory, GtkListItem
|
|||
|
||||
KotoIndexedTrack *track = gtk_list_item_get_item(item); // Get the track UUID from our model
|
||||
|
||||
g_return_if_fail(KOTO_IS_INDEXED_TRACK(track));
|
||||
if (!KOTO_IS_INDEXED_TRACK(track)) {
|
||||
return;
|
||||
}
|
||||
|
||||
gchar *track_name = NULL;
|
||||
gchar *album_uuid = NULL;
|
||||
|
@ -388,9 +390,21 @@ void koto_playlist_page_handle_tracks_selected(GtkSelectionModel *model, guint p
|
|||
}
|
||||
|
||||
void koto_playlist_page_set_playlist_uuid(KotoPlaylistPage *self, gchar *playlist_uuid) {
|
||||
g_return_if_fail(KOTO_IS_PLAYLIST_PAGE(self));
|
||||
g_return_if_fail(g_strcmp0(playlist_uuid, "") != 0); // Return if empty string
|
||||
g_return_if_fail(koto_cartographer_has_playlist_by_uuid(koto_maps, playlist_uuid)); // Don't have a playlist with this UUID
|
||||
if (!KOTO_IS_PLAYLIST_PAGE(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!KOTO_IS_PLAYLIST_PAGE(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!koto_utils_is_string_valid(playlist_uuid)) { // Provided UUID string is not valid
|
||||
return;
|
||||
}
|
||||
|
||||
if (!koto_cartographer_has_playlist_by_uuid(koto_maps, playlist_uuid)) { // If we don't have this playlist
|
||||
return;
|
||||
}
|
||||
|
||||
self->uuid = g_strdup(playlist_uuid); // Duplicate the playlist UUID
|
||||
KotoPlaylist *playlist = koto_cartographer_get_playlist_by_uuid(koto_maps, self->uuid);
|
||||
|
@ -400,7 +414,9 @@ void koto_playlist_page_set_playlist_uuid(KotoPlaylistPage *self, gchar *playlis
|
|||
}
|
||||
|
||||
void koto_playlist_page_set_playlist_model(KotoPlaylistPage *self, KotoPreferredModelType model) {
|
||||
g_return_if_fail(KOTO_IS_PLAYLIST_PAGE(self));
|
||||
if (!KOTO_IS_PLAYLIST_PAGE(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
koto_playlist_apply_model(self->playlist, model); // Apply our new model
|
||||
self->model = G_LIST_MODEL(koto_playlist_get_store(self->playlist)); // Get the latest generated model / store and cast it as a GListModel
|
||||
|
@ -427,6 +443,10 @@ void koto_playlist_page_setup_track_item(GtkListItemFactory *factory, GtkListIte
|
|||
(void) factory;
|
||||
KotoPlaylistPage *self = user_data;
|
||||
|
||||
if (!KOTO_IS_PLAYLIST_PAGE(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GtkWidget *item_content = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); // Have a horizontal box for our content
|
||||
gtk_widget_add_css_class(item_content, "track-list-columned-item");
|
||||
|
||||
|
@ -472,8 +492,13 @@ void koto_playlist_page_setup_track_item(GtkListItemFactory *factory, GtkListIte
|
|||
}
|
||||
|
||||
void koto_playlist_page_update_header(KotoPlaylistPage *self) {
|
||||
g_return_if_fail(KOTO_IS_PLAYLIST_PAGE(self));
|
||||
g_return_if_fail(KOTO_IS_PLAYLIST(self->playlist)); // Not a valid playlist
|
||||
if (!KOTO_IS_PLAYLIST_PAGE(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!KOTO_IS_PLAYLIST(self->playlist)) { // Not a playlist
|
||||
return;
|
||||
}
|
||||
|
||||
gboolean ephemeral = TRUE;
|
||||
g_object_get(
|
||||
|
@ -491,7 +516,7 @@ void koto_playlist_page_update_header(KotoPlaylistPage *self) {
|
|||
|
||||
gchar *artwork = koto_playlist_get_artwork(self->playlist);
|
||||
|
||||
if ((artwork != NULL) && g_strcmp0(artwork, "") != 0) { // Have artwork
|
||||
if (koto_utils_is_string_valid(artwork)) { // Have artwork
|
||||
koto_cover_art_button_set_art_path(self->playlist_image, artwork); // Update our artwork
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "../db/cartographer.h"
|
||||
#include "../playlist/current.h"
|
||||
#include "../playlist/playlist.h"
|
||||
#include "../koto-utils.h"
|
||||
#include "engine.h"
|
||||
#include "mimes.h"
|
||||
#include "mpris.h"
|
||||
|
@ -316,14 +317,14 @@ void koto_push_track_info_to_builder(GVariantBuilder *builder, KotoIndexedTrack
|
|||
|
||||
g_variant_builder_add(builder, "{sv}", "mpris:trackid", g_variant_new_string(track_uuid));
|
||||
|
||||
if (g_strcmp0(album_art_path, "") != 0) { // Not empty
|
||||
if (koto_utils_is_string_valid(album_art_path)) { // Valid album art path
|
||||
album_art_path = g_strconcat("file://", album_art_path, NULL); // Prepend with file://
|
||||
g_variant_builder_add(builder, "{sv}", "mpris:artUrl", g_variant_new_string(album_art_path));
|
||||
}
|
||||
|
||||
g_variant_builder_add(builder, "{sv}", "xesam:album", g_variant_new_string(album_name));
|
||||
|
||||
if (g_strcmp0(artist_name, "") != 0) { // Got artist name
|
||||
if (koto_utils_is_string_valid(artist_name)) { // Valid artist name
|
||||
GVariant *artist_name_variant;
|
||||
GVariantBuilder *artist_list_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
|
||||
g_variant_builder_add(artist_list_builder, "s", artist_name);
|
||||
|
|
|
@ -171,7 +171,7 @@ void koto_create_modify_playlist_dialog_handle_create_click(GtkButton *button, g
|
|||
}
|
||||
|
||||
KotoPlaylist *playlist = NULL;
|
||||
gboolean modify_existing_playlist = ((self->playlist_uuid != NULL) && (g_strcmp0(self->playlist_uuid, "") != 0));
|
||||
gboolean modify_existing_playlist = koto_utils_is_string_valid(self->playlist_uuid);
|
||||
|
||||
if (modify_existing_playlist) { // Modifying an existing playlist
|
||||
playlist = koto_cartographer_get_playlist_by_uuid(koto_maps, self->playlist_uuid);
|
||||
|
@ -263,7 +263,7 @@ void koto_create_modify_playlist_dialog_reset(KotoCreateModifyPlaylistDialog *se
|
|||
}
|
||||
|
||||
void koto_create_modify_playlist_dialog_set_playlist_uuid(KotoCreateModifyPlaylistDialog *self, gchar *playlist_uuid) {
|
||||
if ((playlist_uuid == NULL) || g_strcmp0(playlist_uuid, "") == 0) { // Is an empty string or not a string at all
|
||||
if (!koto_utils_is_string_valid(playlist_uuid)) { // Not a valid playlist UUID string
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ void koto_create_modify_playlist_dialog_set_playlist_uuid(KotoCreateModifyPlayli
|
|||
|
||||
gchar *art = koto_playlist_get_artwork(playlist);
|
||||
|
||||
if ((art == NULL) || (g_strcmp0(art, "") == 0)) { // Is an empty string or not set
|
||||
if (!koto_utils_is_string_valid(art)) { // If art is not defined
|
||||
gtk_image_set_from_icon_name(GTK_IMAGE(self->playlist_image), "insert-image-symbolic"); // Reset the image
|
||||
} else {
|
||||
gtk_image_set_from_file(GTK_IMAGE(self->playlist_image), art);
|
||||
|
|
|
@ -445,7 +445,7 @@ gchar* koto_playlist_go_to_next(KotoPlaylist *self) {
|
|||
return random_track_uuid;
|
||||
}
|
||||
|
||||
if (self->current_uuid == NULL || (g_strcmp0(self->current_uuid, "") == 0)) {
|
||||
if (!koto_utils_is_string_valid(self->current_uuid)) { // No valid UUID yet
|
||||
self->current_position++;
|
||||
} else { // Have a UUID currently
|
||||
KotoIndexedTrack *track = koto_cartographer_get_track_by_uuid(koto_maps, self->current_uuid);
|
||||
|
@ -474,7 +474,7 @@ gchar* koto_playlist_go_to_previous(KotoPlaylist *self) {
|
|||
return koto_playlist_get_random_track(self); // Get a random track
|
||||
}
|
||||
|
||||
if (self->current_uuid == NULL || (g_strcmp0(self->current_uuid, "") == 0)) {
|
||||
if (!koto_utils_is_string_valid(self->current_uuid)) { // No valid UUID
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -736,9 +736,11 @@ void koto_playlist_set_position(KotoPlaylist *self, gint position) {
|
|||
|
||||
void koto_playlist_set_track_as_current(KotoPlaylist *self, gchar *track_uuid) {
|
||||
gint position_of_track = g_queue_index(self->sorted_tracks, track_uuid); // Get the position of the UUID in our tracks
|
||||
g_return_if_fail(position_of_track != -1);
|
||||
|
||||
if (position_of_track != -1) { // In tracks
|
||||
self->current_position = position_of_track;
|
||||
}
|
||||
}
|
||||
|
||||
void koto_playlist_set_uuid(KotoPlaylist *self, const gchar *uuid) {
|
||||
if (uuid == NULL) { // No actual UUID
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue