Get to the point where we are fairly happy with our uncrustify config. Fixes #6.
This commit is contained in:
parent
d07d3dfe50
commit
62de9c2032
58 changed files with 4811 additions and 1946 deletions
|
@ -21,16 +21,16 @@
|
|||
#include "../db/db.h"
|
||||
#include "../koto-utils.h"
|
||||
|
||||
extern sqlite3 *koto_db;
|
||||
extern sqlite3 * koto_db;
|
||||
|
||||
struct _KotoIndexedArtist {
|
||||
GObject parent_instance;
|
||||
gchar *uuid;
|
||||
gchar *path;
|
||||
gchar * uuid;
|
||||
gchar * path;
|
||||
|
||||
gboolean has_artist_art;
|
||||
gchar *artist_name;
|
||||
GList *albums;
|
||||
gchar * artist_name;
|
||||
GList * albums;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(KotoIndexedArtist, koto_indexed_artist, G_TYPE_OBJECT);
|
||||
|
@ -43,13 +43,28 @@ enum {
|
|||
N_PROPERTIES
|
||||
};
|
||||
|
||||
static GParamSpec *props[N_PROPERTIES] = { NULL, };
|
||||
static GParamSpec * props[N_PROPERTIES] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
static void koto_indexed_artist_get_property(
|
||||
GObject * obj,
|
||||
guint prop_id,
|
||||
GValue * val,
|
||||
GParamSpec * spec
|
||||
);
|
||||
|
||||
static void koto_indexed_artist_set_property(
|
||||
GObject * obj,
|
||||
guint prop_id,
|
||||
const GValue * val,
|
||||
GParamSpec * spec
|
||||
);
|
||||
|
||||
static void koto_indexed_artist_class_init(KotoIndexedArtistClass * c) {
|
||||
GObjectClass * gobject_class;
|
||||
|
||||
static void koto_indexed_artist_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec);
|
||||
static void koto_indexed_artist_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec);
|
||||
|
||||
static void koto_indexed_artist_class_init(KotoIndexedArtistClass *c) {
|
||||
GObjectClass *gobject_class;
|
||||
gobject_class = G_OBJECT_CLASS(c);
|
||||
gobject_class->set_property = koto_indexed_artist_set_property;
|
||||
gobject_class->get_property = koto_indexed_artist_get_property;
|
||||
|
@ -59,7 +74,7 @@ static void koto_indexed_artist_class_init(KotoIndexedArtistClass *c) {
|
|||
"UUID to Artist in database",
|
||||
"UUID to Artist in database",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
props[PROP_PATH] = g_param_spec_string(
|
||||
|
@ -67,7 +82,7 @@ static void koto_indexed_artist_class_init(KotoIndexedArtistClass *c) {
|
|||
"Path",
|
||||
"Path to Artist",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
props[PROP_ARTIST_NAME] = g_param_spec_string(
|
||||
|
@ -75,19 +90,19 @@ static void koto_indexed_artist_class_init(KotoIndexedArtistClass *c) {
|
|||
"Name",
|
||||
"Name of Artist",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
|
||||
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
|
||||
);
|
||||
|
||||
g_object_class_install_properties(gobject_class, N_PROPERTIES, props);
|
||||
}
|
||||
|
||||
void koto_indexed_artist_commit(KotoIndexedArtist *self) {
|
||||
void koto_indexed_artist_commit(KotoIndexedArtist * self) {
|
||||
if ((self->uuid == NULL) || strcmp(self->uuid, "")) { // UUID not set
|
||||
self->uuid = g_strdup(g_uuid_string_random());
|
||||
}
|
||||
|
||||
// TODO: Support multiple types instead of just local music artist
|
||||
gchar *commit_op = g_strdup_printf(
|
||||
gchar * commit_op = g_strdup_printf(
|
||||
"INSERT INTO artists(id,path,type,name,art_path)"
|
||||
"VALUES ('%s', quote(\"%s\"), 0, quote(\"%s\"), NULL)"
|
||||
"ON CONFLICT(id) DO UPDATE SET path=excluded.path, type=excluded.type, name=excluded.name, art_path=excluded.art_path;",
|
||||
|
@ -96,9 +111,10 @@ void koto_indexed_artist_commit(KotoIndexedArtist *self) {
|
|||
self->artist_name
|
||||
);
|
||||
|
||||
gchar *commit_opt_errmsg = NULL;
|
||||
gchar * commit_opt_errmsg = NULL;
|
||||
int rc = sqlite3_exec(koto_db, commit_op, 0, 0, &commit_opt_errmsg);
|
||||
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
g_warning("Failed to write our artist to the database: %s", commit_opt_errmsg);
|
||||
}
|
||||
|
@ -107,13 +123,19 @@ void koto_indexed_artist_commit(KotoIndexedArtist *self) {
|
|||
g_free(commit_opt_errmsg);
|
||||
}
|
||||
|
||||
static void koto_indexed_artist_init(KotoIndexedArtist *self) {
|
||||
static void koto_indexed_artist_init(KotoIndexedArtist * self) {
|
||||
self->has_artist_art = FALSE;
|
||||
self->albums = NULL; // Create a new GList
|
||||
}
|
||||
|
||||
static void koto_indexed_artist_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) {
|
||||
KotoIndexedArtist *self = KOTO_INDEXED_ARTIST(obj);
|
||||
static void koto_indexed_artist_get_property(
|
||||
GObject * obj,
|
||||
guint prop_id,
|
||||
GValue * val,
|
||||
GParamSpec * spec
|
||||
) {
|
||||
KotoIndexedArtist * self = KOTO_INDEXED_ARTIST(obj);
|
||||
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_UUID:
|
||||
|
@ -131,8 +153,14 @@ static void koto_indexed_artist_get_property(GObject *obj, guint prop_id, GValue
|
|||
}
|
||||
}
|
||||
|
||||
static void koto_indexed_artist_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec) {
|
||||
KotoIndexedArtist *self = KOTO_INDEXED_ARTIST(obj);
|
||||
static void koto_indexed_artist_set_property(
|
||||
GObject * obj,
|
||||
guint prop_id,
|
||||
const GValue * val,
|
||||
GParamSpec * spec
|
||||
) {
|
||||
KotoIndexedArtist * self = KOTO_INDEXED_ARTIST(obj);
|
||||
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_UUID:
|
||||
|
@ -151,7 +179,10 @@ static void koto_indexed_artist_set_property(GObject *obj, guint prop_id, const
|
|||
}
|
||||
}
|
||||
|
||||
void koto_indexed_artist_add_album(KotoIndexedArtist *self, gchar *album_uuid) {
|
||||
void koto_indexed_artist_add_album(
|
||||
KotoIndexedArtist * self,
|
||||
gchar * album_uuid
|
||||
) {
|
||||
if (!KOTO_IS_INDEXED_ARTIST(self)) { // Not an artist
|
||||
return;
|
||||
}
|
||||
|
@ -160,14 +191,15 @@ void koto_indexed_artist_add_album(KotoIndexedArtist *self, gchar *album_uuid) {
|
|||
return;
|
||||
}
|
||||
|
||||
gchar *uuid = g_strdup(album_uuid); // Duplicate our UUID
|
||||
gchar * uuid = g_strdup(album_uuid); // Duplicate our UUID
|
||||
|
||||
|
||||
if (g_list_index(self->albums, uuid) == -1) {
|
||||
self->albums = g_list_append(self->albums, uuid); // Push to end of list
|
||||
}
|
||||
}
|
||||
|
||||
GList* koto_indexed_artist_get_albums(KotoIndexedArtist *self) {
|
||||
GList * koto_indexed_artist_get_albums(KotoIndexedArtist * self) {
|
||||
if (!KOTO_IS_INDEXED_ARTIST(self)) { // Not an artist
|
||||
return NULL;
|
||||
}
|
||||
|
@ -175,7 +207,7 @@ GList* koto_indexed_artist_get_albums(KotoIndexedArtist *self) {
|
|||
return g_list_copy(self->albums);
|
||||
}
|
||||
|
||||
gchar* koto_indexed_artist_get_name(KotoIndexedArtist *self) {
|
||||
gchar * koto_indexed_artist_get_name(KotoIndexedArtist * self) {
|
||||
if (!KOTO_IS_INDEXED_ARTIST(self)) { // Not an artist
|
||||
return g_strdup("");
|
||||
}
|
||||
|
@ -183,7 +215,10 @@ gchar* koto_indexed_artist_get_name(KotoIndexedArtist *self) {
|
|||
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) {
|
||||
void koto_indexed_artist_remove_album(
|
||||
KotoIndexedArtist * self,
|
||||
KotoIndexedAlbum * album
|
||||
) {
|
||||
if (!KOTO_IS_INDEXED_ARTIST(self)) { // Not an artist
|
||||
return;
|
||||
}
|
||||
|
@ -192,12 +227,17 @@ void koto_indexed_artist_remove_album(KotoIndexedArtist *self, KotoIndexedAlbum
|
|||
return;
|
||||
}
|
||||
|
||||
gchar *album_uuid;
|
||||
gchar * album_uuid;
|
||||
|
||||
|
||||
g_object_get(album, "uuid", &album_uuid, NULL);
|
||||
self->albums = g_list_remove(self->albums, album_uuid);
|
||||
}
|
||||
|
||||
void koto_indexed_artist_update_path(KotoIndexedArtist *self, gchar *new_path) {
|
||||
void koto_indexed_artist_update_path(
|
||||
KotoIndexedArtist * self,
|
||||
gchar * new_path
|
||||
) {
|
||||
if (!KOTO_IS_INDEXED_ARTIST(self)) { // Not an artist
|
||||
return;
|
||||
}
|
||||
|
@ -214,7 +254,10 @@ void koto_indexed_artist_update_path(KotoIndexedArtist *self, gchar *new_path) {
|
|||
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PATH]);
|
||||
}
|
||||
|
||||
void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, 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;
|
||||
}
|
||||
|
@ -231,21 +274,28 @@ void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, gchar *artist_
|
|||
g_object_notify_by_pspec(G_OBJECT(self), props[PROP_ARTIST_NAME]);
|
||||
}
|
||||
|
||||
KotoIndexedArtist* koto_indexed_artist_new(gchar *path) {
|
||||
KotoIndexedArtist* artist = g_object_new(KOTO_TYPE_INDEXED_ARTIST,
|
||||
"uuid", g_uuid_string_random(),
|
||||
"path", path,
|
||||
"name", g_path_get_basename(path),
|
||||
KotoIndexedArtist * koto_indexed_artist_new(gchar * path) {
|
||||
KotoIndexedArtist* artist = g_object_new(
|
||||
KOTO_TYPE_INDEXED_ARTIST,
|
||||
"uuid",
|
||||
g_uuid_string_random(),
|
||||
"path",
|
||||
path,
|
||||
"name",
|
||||
g_path_get_basename(path),
|
||||
NULL
|
||||
);
|
||||
|
||||
|
||||
koto_indexed_artist_commit(artist); // Commit the artist immediately to the database
|
||||
return artist;
|
||||
}
|
||||
|
||||
KotoIndexedArtist* koto_indexed_artist_new_with_uuid(const gchar *uuid) {
|
||||
return g_object_new(KOTO_TYPE_INDEXED_ARTIST,
|
||||
"uuid", g_strdup(uuid),
|
||||
KotoIndexedArtist * koto_indexed_artist_new_with_uuid(const gchar * uuid) {
|
||||
return g_object_new(
|
||||
KOTO_TYPE_INDEXED_ARTIST,
|
||||
"uuid",
|
||||
g_strdup(uuid),
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue