Start implementation of database functionality, starting with table generation.
This database will be stored in the user's XDG_DATA_HOME directory under a folder called `com.github.joshstrobl.koto`. Refactored Koto Track Listing into a dedicated Disc View component, break apart out CDs / Discs into relevant Disc View components, sorting them by the disc and showing a label if there are more than one discs / CDs. Started using the row-activated event for our Artist GtkListBox instead of having press events on the artist buttons. Makes switching between artists far more reliable. Added a slide left / right stack animation and set its animation to 400ms so it's in the goldilocks zone (IMO) of not being too fast or too slow. Fix a warning related to scale factor fetching in the PlayerBar.
This commit is contained in:
parent
134b4d79a8
commit
eac4940c77
17 changed files with 434 additions and 61 deletions
60
src/db/db.c
Normal file
60
src/db/db.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* db.c
|
||||
*
|
||||
* Copyright 2021 Joshua Strobl
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <glib-2.0/glib.h>
|
||||
#include <sqlite3.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "db.h"
|
||||
|
||||
sqlite3 *koto_db = NULL;
|
||||
|
||||
void close_db() {
|
||||
sqlite3_close(koto_db);
|
||||
}
|
||||
|
||||
void create_db_tables() {
|
||||
char *tables_creation_queries = "CREATE TABLE IF NOT EXISTS artists(id string UNIQUE, path string UNIQUE, type int, name string, art_path string);"
|
||||
"CREATE TABLE IF NOT EXISTS albums(id string UNIQUE, path string UNIQUE, artist_id int, name string, art_path string);"
|
||||
"CREATE TABLE IF NOT EXISTS tracks(id string UNIQUE, path string UNIQUE, type int, artist_id int, album_id int, file_name string, name string, disc int, position int);";
|
||||
|
||||
gchar *create_tables_errmsg = NULL;
|
||||
int rc = sqlite3_exec(koto_db, tables_creation_queries, 0,0, &create_tables_errmsg);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
g_critical("Failed to create required tables: %s", create_tables_errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
void open_db() {
|
||||
const gchar *data_home = g_get_user_data_dir();
|
||||
gchar *data_dir = g_build_path(G_DIR_SEPARATOR_S, data_home, "com.github.joshstrobl.koto", NULL);
|
||||
mkdir(data_home, 0755);
|
||||
mkdir(data_dir, 0755);
|
||||
chown(data_dir, getuid(), getgid());
|
||||
|
||||
gchar *db_path = g_build_filename(data_dir, "db", NULL); // Build out our path using XDG_DATA_HOME (e.g. .local/share/) + our namespace + db as the file name
|
||||
int rc = sqlite3_open(db_path, &koto_db);
|
||||
|
||||
if (rc) {
|
||||
g_critical("Failed to open or create database: %s", sqlite3_errmsg(koto_db));
|
||||
return;
|
||||
}
|
||||
|
||||
create_db_tables(); // Attempt to create our database tables
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue