Convert from CSS to SCSS. Make a multitude of refinements to styling along the way.

Remove unused glade UI file. Added CSS classes to various components. Fix some alignment issues. Renamed our albums_strip to favorites_list.

Implement recursive file parsing in KotoIndexedAlbum with the intent of using it for "discs" / CD, useful for albums like Foo Fighters: In Your Honor that have 2 or more CDs. Still need to work on refining this further.

Add stub function in our album view for a planned separation of the track listing so we can do it based on discs and other depth-of-3 sub-folders.
This commit is contained in:
Joshua Strobl 2021-02-25 18:15:36 +02:00
parent 588a68b2cc
commit 56dd6b45b4
27 changed files with 359 additions and 104 deletions

View file

@ -151,6 +151,90 @@ void koto_indexed_album_set_album_art(KotoIndexedAlbum *self, const gchar *album
self->has_album_art = TRUE;
}
void koto_indexed_album_read_path(KotoIndexedAlbum *self, magic_t cookie, const gchar* path) {
DIR *dir = opendir(path); // Attempt to open our directory
if (dir == NULL) {
return;
}
struct dirent *entry;
while ((entry = readdir(dir))) {
if (g_str_has_prefix(entry->d_name, ".")) { // Reference to parent dir, self, or a hidden item
continue; // Skip
}
gchar *full_path = g_strdup_printf("%s%s%s", path, G_DIR_SEPARATOR_S, entry->d_name);
if (entry->d_type == DT_DIR) { // If this is a directory
koto_indexed_album_read_path(self, cookie, full_path); // Read this directory as well
continue;
}
if (entry->d_type != DT_REG) { // If this is not a regular file
continue; // Skip
}
const char *mime_type = magic_file(cookie, full_path);
if (mime_type == NULL) { // Failed to get the mimetype
g_free(full_path);
continue; // Skip
}
if (g_str_has_prefix(mime_type, "image/") && !self->has_album_art) { // Is an image file and doesn't have album art yet
gchar *album_art_no_ext = g_strdup(koto_utils_get_filename_without_extension(entry->d_name)); // Get the name of the file without the extension
gchar *lower_art = g_strdup(g_utf8_strdown(album_art_no_ext, -1)); // Lowercase
if (
(g_strrstr(lower_art, "Small") == NULL) && // Not Small
(g_strrstr(lower_art, "back") == NULL) // Not back
) {
koto_indexed_album_set_album_art(self, full_path);
}
g_free(album_art_no_ext);
g_free(lower_art);
} else if (g_str_has_prefix(mime_type, "audio/") || g_str_has_prefix(mime_type, "video/ogg")) { // Is an audio file or ogg because it is special
gchar *appended_slash_to_path = g_strdup_printf("%s%s", g_strdup(self->path), G_DIR_SEPARATOR_S);
gchar **possible_cd_split = g_strsplit(full_path, appended_slash_to_path, -1); // Split based on the album path
guint *cd = 0;
gchar *file_with_cd_sep = g_strdup(possible_cd_split[1]); // Duplicate
gchar **split_on_cd = g_strsplit(file_with_cd_sep, G_DIR_SEPARATOR_S, -1); // Split based on separator (e.g. / )
if (g_strv_length(split_on_cd) > 1) {
gchar *cdd = g_strdup(split_on_cd[0]);
gchar **cd_sep = g_strsplit(g_utf8_strdown(cdd, -1), "cd", -1);
if (g_strv_length(cd_sep) > 1) {
gchar *pos_str = g_strdup(cd_sep[1]);
cd = (guint*) g_ascii_strtoull(pos_str, NULL, 10); // Attempt to convert
g_free(pos_str);
}
g_strfreev(cd_sep);
g_free(cdd);
}
g_strfreev(split_on_cd);
g_free(file_with_cd_sep);
g_strfreev(possible_cd_split);
g_free(appended_slash_to_path);
KotoIndexedFile *file = koto_indexed_file_new(full_path, cd);
if (file != NULL) { // Is a file
koto_indexed_album_add_file(self, file); // Add our file
}
}
g_free(full_path);
}
}
void koto_indexed_album_remove_file(KotoIndexedAlbum *self, KotoIndexedFile *file) {
if (file == NULL) { // Not a file
return;
@ -235,48 +319,7 @@ void koto_indexed_album_update_path(KotoIndexedAlbum *self, const gchar* new_pat
return;
}
struct dirent *entry;
while ((entry = readdir(dir))) {
if (g_str_has_prefix(entry->d_name, ".")) { // Reference to parent dir, self, or a hidden item
continue; // Skip
}
if (entry->d_type != DT_REG) { // If this is not a regular file
continue; // Skip
}
gchar *full_path = g_strdup_printf("%s%s%s", self->path, G_DIR_SEPARATOR_S, entry->d_name);
const char *mime_type = magic_file(magic_cookie, full_path);
if (mime_type == NULL) { // Failed to get the mimetype
g_free(full_path);
continue; // Skip
}
if (g_str_has_prefix(mime_type, "image/") && !self->has_album_art) { // Is an image file and doesn't have album art yet
gchar *album_art_no_ext = g_strdup(koto_utils_get_filename_without_extension(entry->d_name)); // Get the name of the file without the extension
gchar *lower_art = g_strdup(g_utf8_strdown(album_art_no_ext, -1)); // Lowercase
if (
(g_strrstr(lower_art, "Small") == NULL) && // Not Small
(g_strrstr(lower_art, "back") == NULL) // Not back
) {
koto_indexed_album_set_album_art(self, full_path);
}
g_free(album_art_no_ext);
g_free(lower_art);
} else if (g_str_has_prefix(mime_type, "audio/") || g_str_has_prefix(mime_type, "video/ogg")) { // Is an audio file or ogg because it is special
KotoIndexedFile *file = koto_indexed_file_new(full_path);
if (file != NULL) { // Is a file
koto_indexed_album_add_file(self, file); // Add our file
}
}
g_free(full_path);
}
koto_indexed_album_read_path(self, magic_cookie, self->path);
magic_close(magic_cookie);
}

View file

@ -28,6 +28,7 @@ struct _KotoIndexedFile {
gchar *parsed_name;
gchar *artist;
gchar *album;
guint *cd;
guint *position;
gboolean acquired_metadata_from_id3;
};
@ -41,6 +42,7 @@ enum {
PROP_ALBUM,
PROP_FILE_NAME,
PROP_PARSED_NAME,
PROP_CD,
PROP_POSITION,
N_PROPERTIES
};
@ -96,6 +98,16 @@ static void koto_indexed_file_class_init(KotoIndexedFileClass *c) {
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
);
props[PROP_CD] = g_param_spec_uint(
"cd",
"CD the Track belongs to",
"CD the Track belongs to",
0,
G_MAXUINT16,
1,
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
);
props[PROP_POSITION] = g_param_spec_uint(
"position",
"Position in Audiobook, Album, etc.",
@ -132,6 +144,9 @@ static void koto_indexed_file_get_property(GObject *obj, guint prop_id, GValue *
case PROP_PARSED_NAME:
g_value_set_string(val, self->parsed_name);
break;
case PROP_CD:
g_value_set_uint(val, GPOINTER_TO_UINT(self->cd));
break;
case PROP_POSITION:
g_value_set_uint(val, GPOINTER_TO_UINT(self->position));
break;
@ -160,6 +175,9 @@ static void koto_indexed_file_set_property(GObject *obj, guint prop_id, const GV
case PROP_PARSED_NAME:
koto_indexed_file_set_parsed_name(self, g_strdup(g_value_get_string(val)));
break;
case PROP_CD:
koto_indexed_file_set_cd(self, g_value_get_uint(val));
break;
case PROP_POSITION:
koto_indexed_file_set_position(self, g_value_get_uint(val));
break;
@ -249,6 +267,15 @@ void koto_indexed_file_set_file_name(KotoIndexedFile *self, gchar *new_file_name
}
}
void koto_indexed_file_set_cd(KotoIndexedFile *self, guint cd) {
if (cd <= 1) { // No change really
return;
}
self->cd = GUINT_TO_POINTER(cd);
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_CD]);
}
void koto_indexed_file_set_parsed_name(KotoIndexedFile *self, gchar *new_parsed_name) {
if (new_parsed_name == NULL) {
return;
@ -307,9 +334,10 @@ void koto_indexed_file_update_path(KotoIndexedFile *self, const gchar *new_path)
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PATH]);
}
KotoIndexedFile* koto_indexed_file_new(const gchar *path) {
KotoIndexedFile* koto_indexed_file_new(const gchar *path, guint *cd) {
return g_object_new(KOTO_TYPE_INDEXED_FILE,
"path", path,
"cd", cd,
NULL
);
}

View file

@ -23,10 +23,11 @@ G_BEGIN_DECLS
#define KOTO_TYPE_INDEXED_FILE koto_indexed_file_get_type()
G_DECLARE_FINAL_TYPE(KotoIndexedFile, koto_indexed_file, KOTO, INDEXED_FILE, GObject);
KotoIndexedFile* koto_indexed_file_new(const gchar *path);
KotoIndexedFile* koto_indexed_file_new(const gchar *path, guint *cd);
void koto_indexed_file_parse_name(KotoIndexedFile *self);
void koto_indexed_file_set_file_name(KotoIndexedFile *self, gchar *new_file_name);
void koto_indexed_file_set_cd(KotoIndexedFile *self, guint cd);
void koto_indexed_file_set_parsed_name(KotoIndexedFile *self, gchar *new_parsed_name);
void koto_indexed_file_set_position(KotoIndexedFile *self, guint pos);
void koto_indexed_file_update_metadata(KotoIndexedFile *self);