Skip to content

Commit

Permalink
Create a new version of the Store class based on libgda
Browse files Browse the repository at this point in the history
This new Store is still missing quite a bit of functionality, but it'll
come back with time.
Requires a build of libgda from git (5.1.0) with vala bindings and
extensions enabled - which requires a development version of vala.

Good luck building this, anyone except me ;)

References: gh-10
  • Loading branch information
kepstin committed Feb 5, 2012
1 parent 14d0108 commit d9132a7
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 10 deletions.
34 changes: 28 additions & 6 deletions Makefile.am
Expand Up @@ -3,19 +3,17 @@ ACLOCAL_AMFLAGS = -I m4
noinst_HEADERS = store/store.h
noinst_PROGRAMS = tagread add_artist
noinst_LTLIBRARIES = musicbrainz4/libvalamusicbrainz.la
lib_LTLIBRARIES = store/libriker-store.la
lib_LTLIBRARIES = store/libriker-store.la gdastore/libriker-gdastore.la

AM_VALAFLAGS = \
$(UNINSTALLED_VALAFLAGS) \
$(GLIB_VALAFLAGS) \
--vapidir=$(srcdir) \
--vapidir=$(srcdir)/store \
--vapidir=$(srcdir)/musicbrainz4 \
--pkg=config
AM_CFLAGS = \
$(GLIB_CFLAGS) \
-DBUILD_SRCDIR="\"$(abs_srcdir)\"" \
-I $(srcdir)/store \
-I $(srcdir)/musicbrainz4
AM_LIBADD = $(GLIB_LIBS)

Expand Down Expand Up @@ -60,33 +58,57 @@ store_libriker_store_la_LDFLAGS = \
-release $(VERSION)


gdastore_libriker_gdastore_la_SOURCES = \
gdastore/store.vala
gdastore_libriker_gdastore_la_VALAFLAGS = \
$(AM_VALAFLAGS) \
$(GDA_VALAFLAGS) \
$(SQLITE_VALAFLAGS) \
--header=gdastore/store.h \
--vapi=gdastore/store.vapi
gdastore_libriker_gdastore_la_CFLAGS = \
$(AM_CFLAGS) \
$(GDA_CFLAGS) \
$(SQLITE_CFLAGS)
gdastore_libriker_gdastore_la_LIBADD = \
$(AM_LIBADD) \
$(GDA_LIBS) \
$(SQLITE_LIBS)
gdastore_libriker_gdastore_la_LDFLAGS = \
-release $(VERSION)


tagread_SOURCES = \
tagread.vala
tagread_CFLAGS = \
$(AM_CFLAGS) \
$(GSTREAMER_CFLAGS) \
$(GEE_CFLAGS)
$(GEE_CFLAGS) \
-I $(srcdir)/gdastore
tagread_VALAFLAGS = \
$(AM_VALAFLAGS) \
$(GSTREAMER_VALAFLAGS) \
--vapidir=$(srcdir)/gdastore \
--pkg=store \
--pkg=valamusicbrainz
tagread_LDADD = \
$(AM_LIBADD) \
$(GSTREAMER_LIBS) \
store/libriker-store.la \
gdastore/libriker-gdastore.la \
musicbrainz4/libvalamusicbrainz.la


add_artist_SOURCES = \
add_artist.vala
add_artist_VALAFLAGS = \
$(AM_VALAFLAGS) \
--vapidir=$(srcdir)/store \
--pkg=store \
--pkg=valamusicbrainz
add_artist_CFLAGS = \
$(AM_CFLAGS) \
$(GEE_CFLAGS)
$(GEE_CFLAGS) \
-I $(srcdir)/store
add_artist_LDADD = \
$(AM_LIBADD) \
store/libriker-store.la \
Expand Down
7 changes: 5 additions & 2 deletions configure.ac
Expand Up @@ -13,7 +13,7 @@ AC_SUBST([UNINSTALLED_VALAFLAGS], ["-D ENABLE_UNINSTALLED"])
# [Support executing the program from the build directory],
# [AC_SUBST([UNINSTALLED_VALAFLAGS], ["-D ENABLE_UNINSTALLED"])])

AM_PROG_VALAC
AM_PROG_VALAC([0.15.1])

PKG_CHECK_MODULES([GLIB], [glib-2.0 gio-2.0])
AC_SUBST([GLIB_VALAFLAGS], ["--pkg=gio-2.0"])
Expand All @@ -24,12 +24,15 @@ AC_SUBST([GSTREAMER_VALAFLAGS], ["--pkg=gstreamer-0.10 --pkg=gstreamer-tag-0.10"
PKG_CHECK_MODULES([SQLITE], [sqlite3])
AC_SUBST([SQLITE_VALAFLAGS], ["--pkg=sqlite3"])

PKG_CHECK_MODULES([GEE], [gee-1.0])
PKG_CHECK_MODULES([GEE], [gee-0.8])
AC_SUBST([GEE_VALAFLAGS], ["--pkg=gee-1.0"])

PKG_CHECK_MODULES([MB4], [libmusicbrainz4])
AC_SUBST([MB4_VALAFLAGS], ['--vapidir=$(srcdir)/musicbrainz4 --pkg=libmusicbrainz4'])

PKG_CHECK_MODULES([GDA], [libgda-5.0 >= 5.1.0 libgdadata-5.0 >= 5.1.0])
AC_SUBST([GDA_VALAFLAGS], ["--pkg=libgda-5.0 --pkg=gdadata-5.0 --pkg=libxml-2.0 --pkg=gee-0.8"])

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
145 changes: 145 additions & 0 deletions gdastore/store.vala
@@ -0,0 +1,145 @@
/*
* Riker - a MusicBrainz-enhanced audio player
* Copyright © 2011 Calvin Walton
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

namespace Riker {

/**
* Various errors that can happen due to database interactions.
*/
public errordomain StoreError {
OPEN_FAILED,
UNSUPPORTED_SCHEMA,
CORRUPT_DB,
INSTALLATION_ERROR,
BUG
}

/**
* The store represents the database backend where information is stored.
*/
public class Store: Object {

/**
* The database schema version supported by this version of Riker.
*
* If this is 0, then Riker is using an unstable schema.
*/
private const int SCHEMA_VERSION = 0;

/**
* The oldest database schema version supported for upgrades.
*/
private const int MIN_SCHEMA_VERSION = 1;

/**
* The newest schema version supported for upgrades.
*
* This is normally set to SCHEMA_VERSION - 1, unless SCHEMA_VERSION
* is 0
*/
private const int MAX_SCHEMA_VERSION = 1;

private const string DSN_NAME = "RikerStore";

private const string DSN_PROVIDER = "SQLite";

private const string DSN_DB_NAME = "riker-store";

/**
* The Database connection.
*/
private Gda.Connection connection;

/**
* Create a new Store instance using the default database location.
*
* This is normally in a ~/.local/share/riker/store.db, but varies by
* platform.
*/
public Store() {

}

/**
* Open the database, and prepare it for use.
*
* This function will create the database if it doesn't exist,
* initialize the schema, and perform any appropriate upgrades.
*
* @throws StoreError The database could not be initialized. The error
* type and message will provide details. If this error is
* given, the Store object must not be used.
*/
public void open() throws StoreError {
/* A few helpful warnings for testers... */
if (SCHEMA_VERSION == 0) {
stderr.printf(
"This version of Riker uses an unstable database schema. If you update Riker\n" +
"you must delete the database file and either restore a backup from an older\n" +
"stable version or rescan your music collection.\n");
}

/* Attempt to connect using the libgda database configuration */
try {
connection = Gda.Connection.open_from_dsn("RikerStore", null, Gda.ConnectionOptions.NONE);
} catch (Error error) {
if (error.domain == Gda.Connection.error_quark() &&
error.code == Gda.ConnectionError.DSN_NOT_FOUND_ERROR) {
/*
* There is no database configuration for Riker,
* so create a default configuration.
*/
stderr.printf("Database configuration not found, creating default.\n");
create_dsn();
try {
connection = Gda.Connection.open_from_dsn("RikerStore", null, Gda.ConnectionOptions.NONE);
} catch (Error inner_error) {
throw new StoreError.OPEN_FAILED("Failed to connect to database: " + inner_error.message);
}
} else {
throw new StoreError.OPEN_FAILED("Failed to connect to database: " + error.message);
}
}
}

private void create_dsn() throws StoreError {
var dsn_db_dir = Path.build_filename(Environment.get_user_data_dir(), Config.PACKAGE_TARNAME);
var cnc_string = "DB_DIR=%s;DB_NAME=%s;FK=TRUE".printf(dsn_db_dir, DSN_DB_NAME);

Gda.DsnInfo dsn_info = {
DSN_NAME,
DSN_PROVIDER,
null,
cnc_string,
null,
false
};

try {
Gda.Config.define_dsn(dsn_info);
connection = Gda.Connection.open_from_dsn("RikerStore", null, Gda.ConnectionOptions.NONE);
} catch (Error inner_error) {
throw new StoreError.OPEN_FAILED("Failed to create DB configuration: " + inner_error.message);
}
}

/**
* Load the base schema into a fresh database.
*/
private void initialize_schema() throws StoreError {

}
}

}
3 changes: 1 addition & 2 deletions tagread.vala
Expand Up @@ -32,7 +32,6 @@ class TagRead {
if (e is StoreError.CORRUPT_DB) {
stderr.printf("%s\n", e.message);
stderr.printf("To resolve this, try deleting the database file so it can be re-created.\n");
stderr.printf("Database path: %s\n", store.path);
} else {
stderr.printf("%s\n", e.message);
}
Expand Down Expand Up @@ -113,7 +112,7 @@ class TagRead {
duration = (uint) (duration_ns / 1000000);
}

File file = new File.from_data(recording_mbid, release_mbid, track_position, medium_position, codec, bitrate, duration);
/*File file = new File.from_data(recording_mbid, release_mbid, track_position, medium_position, codec, bitrate, duration);*/

print("recording_mbid: %s\n", recording_mbid);
print("release_mbid: %s\n", release_mbid);
Expand Down

0 comments on commit d9132a7

Please sign in to comment.