Start cleanup of KotoLibrary logic and decoupling other components like Music Local from a specific library.
Fix the displaying of discs and tracks in an album on initial index due to missing cartographer add track call. Cleanup lots of double empty newlines. Updated ptr spacing in uncrustify config to enforce consistency in pointer char (`*`) spacing.
This commit is contained in:
parent
8334323af8
commit
bfe4891620
33 changed files with 146 additions and 623 deletions
|
@ -72,7 +72,6 @@ void koto_add_remove_track_popover_add_playlist(
|
|||
|
||||
gchar * playlist_uuid = koto_playlist_get_uuid(playlist); // Get the UUID of the playlist
|
||||
|
||||
|
||||
if (GTK_IS_CHECK_BUTTON(g_hash_table_lookup(self->playlist_uuid_to_checkbox, playlist_uuid))) { // Already have a check button for this
|
||||
g_free(playlist_uuid);
|
||||
return;
|
||||
|
@ -80,13 +79,11 @@ void koto_add_remove_track_popover_add_playlist(
|
|||
|
||||
GtkWidget * playlist_button = gtk_check_button_new_with_label(koto_playlist_get_name(playlist)); // Create our GtkCheckButton
|
||||
|
||||
|
||||
g_hash_table_insert(self->checkbox_to_playlist_uuid, playlist_button, playlist_uuid);
|
||||
g_hash_table_insert(self->playlist_uuid_to_checkbox, playlist_uuid, playlist_button);
|
||||
|
||||
gulong playlist_sig_id = g_signal_connect(playlist_button, "toggled", G_CALLBACK(koto_add_remove_track_popover_handle_checkbutton_toggle), self);
|
||||
|
||||
|
||||
g_hash_table_insert(self->checkbox_to_signal_ids, playlist_button, GUINT_TO_POINTER(playlist_sig_id)); // Add our GSignal handler ID
|
||||
|
||||
gtk_list_box_append(GTK_LIST_BOX(self->list_box), playlist_button); // Add the playlist to the list box
|
||||
|
@ -117,7 +114,6 @@ void koto_add_remove_track_popover_remove_playlist(
|
|||
|
||||
GtkCheckButton * btn = GTK_CHECK_BUTTON(g_hash_table_lookup(self->playlist_uuid_to_checkbox, playlist_uuid)); // Get the check button
|
||||
|
||||
|
||||
if (GTK_IS_CHECK_BUTTON(btn)) { // Is a check button
|
||||
g_hash_table_remove(self->checkbox_to_playlist_uuid, btn); // Remove uuid based on btn
|
||||
gtk_list_box_remove(GTK_LIST_BOX(self->list_box), GTK_WIDGET(btn)); // Remove the button from the list box
|
||||
|
@ -132,7 +128,6 @@ void koto_add_remove_track_popover_handle_checkbutton_toggle(
|
|||
) {
|
||||
KotoAddRemoveTrackPopover * self = user_data;
|
||||
|
||||
|
||||
if (!KOTO_JS_ADD_REMOVE_TRACK_POPOVER(self)) {
|
||||
return;
|
||||
}
|
||||
|
@ -142,14 +137,12 @@ void koto_add_remove_track_popover_handle_checkbutton_toggle(
|
|||
|
||||
KotoPlaylist * playlist = koto_cartographer_get_playlist_by_uuid(koto_maps, playlist_uuid); // Get the playlist
|
||||
|
||||
|
||||
if (!KOTO_IS_PLAYLIST(playlist)) { // Failed to get the playlist
|
||||
return;
|
||||
}
|
||||
|
||||
GList * pos;
|
||||
|
||||
|
||||
for (pos = self->tracks; pos != NULL; pos = pos->next) { // Iterate over our KotoTracks
|
||||
KotoTrack * track = pos->data;
|
||||
|
||||
|
@ -177,7 +170,6 @@ void koto_add_remove_track_popover_handle_playlist_added(
|
|||
(void) carto;
|
||||
KotoAddRemoveTrackPopover * self = user_data;
|
||||
|
||||
|
||||
if (!KOTO_JS_ADD_REMOVE_TRACK_POPOVER(self)) {
|
||||
return;
|
||||
}
|
||||
|
@ -213,8 +205,7 @@ void koto_add_remove_track_popover_set_pointing_to_widget(
|
|||
return;
|
||||
}
|
||||
|
||||
GtkWidget* existing_parent = gtk_widget_get_parent(GTK_WIDGET(self));
|
||||
|
||||
GtkWidget * existing_parent = gtk_widget_get_parent(GTK_WIDGET(self));
|
||||
|
||||
if (existing_parent != NULL) {
|
||||
g_object_ref(GTK_WIDGET(self)); // Increment widget ref since unparent will do an unref
|
||||
|
@ -235,7 +226,6 @@ void koto_add_remove_track_popover_set_tracks(
|
|||
|
||||
gint tracks_len = g_list_length(tracks);
|
||||
|
||||
|
||||
if (tracks_len == 0) { // No tracks
|
||||
return;
|
||||
}
|
||||
|
@ -245,7 +235,6 @@ void koto_add_remove_track_popover_set_tracks(
|
|||
GHashTableIter playlists_iter;
|
||||
gpointer uuid, playlist_ptr;
|
||||
|
||||
|
||||
g_hash_table_iter_init(&playlists_iter, playlists); // Init our HashTable iterator
|
||||
|
||||
while (g_hash_table_iter_next(&playlists_iter, &uuid, &playlist_ptr)) { // While we are iterating through our playlists
|
||||
|
|
|
@ -37,7 +37,6 @@ static GParamSpec * dialog_props[N_PROPS] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
|
||||
struct _KotoCreateModifyPlaylistDialog {
|
||||
GtkBox parent_instance;
|
||||
GtkWidget * playlist_image;
|
||||
|
@ -70,7 +69,6 @@ static void koto_create_modify_playlist_dialog_set_property(
|
|||
static void koto_create_modify_playlist_dialog_class_init(KotoCreateModifyPlaylistDialogClass * c) {
|
||||
GObjectClass * gobject_class;
|
||||
|
||||
|
||||
gobject_class = G_OBJECT_CLASS(c);
|
||||
gobject_class->set_property = koto_create_modify_playlist_dialog_set_property;
|
||||
gobject_class->get_property = koto_create_modify_playlist_dialog_get_property;
|
||||
|
@ -99,13 +97,11 @@ static void koto_create_modify_playlist_dialog_init(KotoCreateModifyPlaylistDial
|
|||
|
||||
GtkDropTarget * target = gtk_drop_target_new(G_TYPE_FILE, GDK_ACTION_COPY);
|
||||
|
||||
|
||||
g_signal_connect(GTK_EVENT_CONTROLLER(target), "drop", G_CALLBACK(koto_create_modify_playlist_dialog_handle_drop), self);
|
||||
gtk_widget_add_controller(self->playlist_image, GTK_EVENT_CONTROLLER(target));
|
||||
|
||||
GtkGesture * image_click_controller = gtk_gesture_click_new(); // Create a click gesture for the image clicking
|
||||
|
||||
|
||||
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(image_click_controller), 1); // Only allow left click
|
||||
g_signal_connect(GTK_EVENT_CONTROLLER(image_click_controller), "pressed", G_CALLBACK(koto_create_modify_playlist_dialog_handle_image_click), self);
|
||||
|
||||
|
@ -132,7 +128,6 @@ static void koto_create_modify_playlist_dialog_get_property(
|
|||
) {
|
||||
KotoCreateModifyPlaylistDialog * self = KOTO_CREATE_MODIFY_PLAYLIST_DIALOG(obj);
|
||||
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PLAYLIST_UUID:
|
||||
g_value_set_string(val, (self->playlist_uuid != NULL) ? g_strdup(self->playlist_uuid) : NULL);
|
||||
|
@ -151,7 +146,6 @@ static void koto_create_modify_playlist_dialog_set_property(
|
|||
) {
|
||||
KotoCreateModifyPlaylistDialog * self = KOTO_CREATE_MODIFY_PLAYLIST_DIALOG(obj);
|
||||
|
||||
|
||||
(void) self;
|
||||
(void) val;
|
||||
|
||||
|
@ -177,7 +171,6 @@ void koto_create_modify_playlist_dialog_handle_chooser_response(
|
|||
|
||||
KotoCreateModifyPlaylistDialog * self = user_data;
|
||||
|
||||
|
||||
if (!KOTO_IS_CURRENT_MODIFY_PLAYLIST(self)) {
|
||||
return;
|
||||
}
|
||||
|
@ -185,7 +178,6 @@ void koto_create_modify_playlist_dialog_handle_chooser_response(
|
|||
GFile * file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(native));
|
||||
gchar * file_path = g_file_get_path(file); // Get the absolute path
|
||||
|
||||
|
||||
if (file_path != NULL) {
|
||||
self->playlist_image_path = g_strdup(file_path);
|
||||
gtk_image_set_from_file(GTK_IMAGE(self->playlist_image), self->playlist_image_path); // Set the file path
|
||||
|
@ -204,7 +196,6 @@ void koto_create_modify_playlist_dialog_handle_create_click(
|
|||
|
||||
KotoCreateModifyPlaylistDialog * self = user_data;
|
||||
|
||||
|
||||
if (!KOTO_IS_CURRENT_MODIFY_PLAYLIST(self)) {
|
||||
return;
|
||||
}
|
||||
|
@ -217,7 +208,6 @@ void koto_create_modify_playlist_dialog_handle_create_click(
|
|||
KotoPlaylist * playlist = NULL;
|
||||
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);
|
||||
} else { // Creating a new playlist
|
||||
|
@ -258,7 +248,6 @@ gboolean koto_create_modify_playlist_dialog_handle_drop(
|
|||
|
||||
KotoCreateModifyPlaylistDialog * self = user_data;
|
||||
|
||||
|
||||
if (!KOTO_IS_CURRENT_MODIFY_PLAYLIST(self)) { // No dialog
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -266,7 +255,6 @@ gboolean koto_create_modify_playlist_dialog_handle_drop(
|
|||
GFile * dropped_file = g_value_get_object(val); // Get the GValue
|
||||
gchar * file_path = g_file_get_path(dropped_file); // Get the absolute path
|
||||
|
||||
|
||||
g_object_unref(dropped_file); // Unref the file
|
||||
|
||||
if (file_path == NULL) {
|
||||
|
@ -275,7 +263,6 @@ gboolean koto_create_modify_playlist_dialog_handle_drop(
|
|||
|
||||
magic_t magic_cookie = magic_open(MAGIC_MIME);
|
||||
|
||||
|
||||
if (magic_cookie == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -286,7 +273,6 @@ gboolean koto_create_modify_playlist_dialog_handle_drop(
|
|||
|
||||
const char * mime_type = magic_file(magic_cookie, file_path);
|
||||
|
||||
|
||||
if ((mime_type != NULL) && g_str_has_prefix(mime_type, "image/")) { // Is an image
|
||||
self->playlist_image_path = g_strdup(file_path);
|
||||
gtk_image_set_from_file(GTK_IMAGE(self->playlist_image), self->playlist_image_path); // Set the file path
|
||||
|
@ -313,8 +299,7 @@ void koto_create_modify_playlist_dialog_handle_image_click(
|
|||
|
||||
KotoCreateModifyPlaylistDialog * self = user_data;
|
||||
|
||||
GtkFileChooserNative* chooser = koto_utils_create_image_file_chooser("Choose playlist image");
|
||||
|
||||
GtkFileChooserNative * chooser = koto_utils_create_image_file_chooser("Choose playlist image");
|
||||
|
||||
g_signal_connect(chooser, "response", G_CALLBACK(koto_create_modify_playlist_dialog_handle_chooser_response), self);
|
||||
gtk_native_dialog_show(GTK_NATIVE_DIALOG(chooser)); // Show our file chooser
|
||||
|
@ -341,7 +326,6 @@ void koto_create_modify_playlist_dialog_set_playlist_uuid(
|
|||
|
||||
KotoPlaylist * playlist = koto_cartographer_get_playlist_by_uuid(koto_maps, playlist_uuid);
|
||||
|
||||
|
||||
if (!KOTO_IS_PLAYLIST(playlist)) {
|
||||
return;
|
||||
}
|
||||
|
@ -352,7 +336,6 @@ void koto_create_modify_playlist_dialog_set_playlist_uuid(
|
|||
|
||||
gchar * art = koto_playlist_get_artwork(playlist);
|
||||
|
||||
|
||||
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 {
|
||||
|
|
|
@ -54,7 +54,6 @@ static void koto_current_playlist_set_property(
|
|||
static void koto_current_playlist_class_init(KotoCurrentPlaylistClass * c) {
|
||||
GObjectClass * gobject_class;
|
||||
|
||||
|
||||
gobject_class = G_OBJECT_CLASS(c);
|
||||
gobject_class->set_property = koto_current_playlist_set_property;
|
||||
gobject_class->get_property = koto_current_playlist_get_property;
|
||||
|
@ -82,7 +81,6 @@ void koto_current_playlist_get_property(
|
|||
) {
|
||||
KotoCurrentPlaylist * self = KOTO_CURRENT_PLAYLIST(obj);
|
||||
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CURRENT_PLAYLIST:
|
||||
g_value_set_object(val, self->current_playlist);
|
||||
|
@ -101,7 +99,6 @@ void koto_current_playlist_set_property(
|
|||
) {
|
||||
KotoCurrentPlaylist * self = KOTO_CURRENT_PLAYLIST(obj);
|
||||
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CURRENT_PLAYLIST:
|
||||
koto_current_playlist_set_playlist(self, (KotoPlaylist*) g_value_get_object(val));
|
||||
|
|
|
@ -107,7 +107,6 @@ static void koto_playlist_set_property(
|
|||
static void koto_playlist_class_init(KotoPlaylistClass * c) {
|
||||
GObjectClass * gobject_class;
|
||||
|
||||
|
||||
gobject_class = G_OBJECT_CLASS(c);
|
||||
gobject_class->set_property = koto_playlist_set_property;
|
||||
gobject_class->get_property = koto_playlist_get_property;
|
||||
|
@ -213,7 +212,6 @@ static void koto_playlist_get_property(
|
|||
) {
|
||||
KotoPlaylist * self = KOTO_PLAYLIST(obj);
|
||||
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_UUID:
|
||||
g_value_set_string(val, self->uuid);
|
||||
|
@ -244,7 +242,6 @@ static void koto_playlist_set_property(
|
|||
) {
|
||||
KotoPlaylist * self = KOTO_PLAYLIST(obj);
|
||||
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_UUID:
|
||||
koto_playlist_set_uuid(self, g_value_get_string(val));
|
||||
|
@ -378,7 +375,6 @@ void koto_playlist_commit(KotoPlaylist * self) {
|
|||
gchar * commit_op_errmsg = NULL;
|
||||
int rc = sqlite3_exec(koto_db, commit_op, 0, 0, &commit_op_errmsg);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
g_warning("Failed to save playlist: %s", commit_op_errmsg);
|
||||
} else { // Successfully saved our playlist
|
||||
|
@ -395,7 +391,6 @@ void koto_playlist_commit_tracks(
|
|||
) {
|
||||
KotoTrack * track = koto_cartographer_get_track_by_uuid(koto_maps, data); // Get the track
|
||||
|
||||
|
||||
if (track == NULL) { // Not a track
|
||||
KotoPlaylist * self = user_data;
|
||||
gchar * playlist_uuid = self->uuid; // Get the playlist UUID
|
||||
|
@ -457,7 +452,6 @@ gint koto_playlist_get_position_of_track(
|
|||
gint position = -1;
|
||||
guint found_pos = 0;
|
||||
|
||||
|
||||
if (g_list_store_find(self->store, track, &found_pos)) { // Found the item
|
||||
position = (gint) found_pos; // Cast our found position from guint to gint
|
||||
}
|
||||
|
@ -473,7 +467,7 @@ gchar * koto_playlist_get_random_track(KotoPlaylist * self) {
|
|||
track_uuid = g_list_nth_data(self->sorted_tracks->head, 0); // Get the first
|
||||
g_queue_clear(self->played_tracks); // Clear our played tracks
|
||||
} else { // Have not played all tracks
|
||||
GRand* rando_calrissian = g_rand_new(); // Create a new RNG
|
||||
GRand * rando_calrissian = g_rand_new(); // Create a new RNG
|
||||
guint attempt = 0;
|
||||
|
||||
while (track_uuid == NULL) { // Haven't selected a track yet
|
||||
|
@ -556,14 +550,12 @@ gchar * koto_playlist_go_to_previous(KotoPlaylist * self) {
|
|||
|
||||
KotoTrack * track = koto_cartographer_get_track_by_uuid(koto_maps, self->current_uuid);
|
||||
|
||||
|
||||
if (!KOTO_IS_TRACK(track)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gint pos_of_song = koto_playlist_get_position_of_track(self, track); // Get the position of the current track based on the current model
|
||||
|
||||
|
||||
if (pos_of_song == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -597,7 +589,6 @@ gint koto_playlist_model_sort_by_uuid(
|
|||
KotoTrack * first_track = koto_cartographer_get_track_by_uuid(koto_maps, (gchar*) first_item);
|
||||
KotoTrack * second_track = koto_cartographer_get_track_by_uuid(koto_maps, (gchar*) second_item);
|
||||
|
||||
|
||||
return koto_playlist_model_sort_by_track(first_track, second_track, data_list);
|
||||
}
|
||||
|
||||
|
@ -609,11 +600,10 @@ gint koto_playlist_model_sort_by_track(
|
|||
KotoTrack * first_track = (KotoTrack*) first_item;
|
||||
KotoTrack * second_track = (KotoTrack*) second_item;
|
||||
|
||||
GList* ptr_list = data_list;
|
||||
GList * ptr_list = data_list;
|
||||
KotoPlaylist * self = g_list_nth_data(ptr_list, 0); // First item in the GPtrArray is a pointer to our playlist
|
||||
KotoPreferredModelType model = GPOINTER_TO_UINT(g_list_nth_data(ptr_list, 1)); // Second item in the GPtrArray is a pointer to our KotoPreferredModelType
|
||||
|
||||
|
||||
if (
|
||||
(model == KOTO_PREFERRED_MODEL_TYPE_DEFAULT) || // Newest first model
|
||||
(model == KOTO_PREFERRED_MODEL_TYPE_OLDEST_FIRST) // Oldest first
|
||||
|
@ -761,14 +751,12 @@ void koto_playlist_remove_track_by_uuid(
|
|||
|
||||
KotoTrack * track = koto_cartographer_get_track_by_uuid(koto_maps, uuid); // Get the track
|
||||
|
||||
|
||||
if (!KOTO_IS_TRACK(track)) { // Is not a track
|
||||
return;
|
||||
}
|
||||
|
||||
guint position = 0;
|
||||
|
||||
|
||||
if (g_list_store_find(self->store, track, &position)) { // Got the position
|
||||
g_list_store_remove(self->store, position); // Remove from the store
|
||||
}
|
||||
|
@ -793,7 +781,6 @@ void koto_playlist_set_artwork(
|
|||
|
||||
magic_t cookie = magic_open(MAGIC_MIME); // Create our magic cookie so we can validate if what we are setting is an image
|
||||
|
||||
|
||||
if (cookie == NULL) { // Failed to allocate
|
||||
return;
|
||||
}
|
||||
|
@ -804,7 +791,6 @@ void koto_playlist_set_artwork(
|
|||
|
||||
const gchar * mime_type = magic_file(cookie, path); // Get the mimetype for this file
|
||||
|
||||
|
||||
if ((mime_type == NULL) || !g_str_has_prefix(mime_type, "image/")) { // Failed to get our mimetype or not an image
|
||||
goto free_cookie;
|
||||
}
|
||||
|
@ -891,7 +877,6 @@ void koto_playlist_tracks_queue_push_to_store(
|
|||
gchar * track_uuid = (gchar*) data;
|
||||
KotoTrack * track = koto_cartographer_get_track_by_uuid(koto_maps, track_uuid);
|
||||
|
||||
|
||||
if (!KOTO_IS_TRACK(track)) { // Not a track
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue