Commit fe8b9b13 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko
Browse files

Drop Tracker

Introduce library dirs and uri source+iterator that scan them.
parent f5249965
Pipeline #425637 passed with stage
in 31 minutes and 59 seconds
......@@ -5,6 +5,11 @@
<value nick="crt" value="2"/>
</enum>
<schema path="/org/gnome/World/Highscore/" id="org.gnome.World.Highscore" gettext-domain="highscore">
<key name='library-paths' type='as'>
<default>[]</default>
<summary>Library Paths</summary>
<description>The list of the game library paths.</description>
</key>
<key name='fullscreen' type='b'>
<default>false</default>
<summary>Fullscreen</summary>
......
......@@ -15,8 +15,6 @@
"--socket=wayland",
"--device=dri",
"--socket=pulseaudio",
"--talk-name=org.freedesktop.Tracker1",
"--env=TRACKER_SPARQL_BACKEND=bus",
"--share=network",
"--device=all",
"--filesystem=host:ro"
......@@ -75,28 +73,6 @@
"mkdir -p /app/lib/libretro/extra.d"
]
},
{
"name" : "tracker",
"buildsystem" : "meson",
"config-opts" : [
"-Ddocs=false",
"-Dfts=false",
"-Dfunctional_tests=false",
"-Djournal=false",
"-Dnetwork_manager=disabled",
"-Dstemmer=disabled",
"-Dbash_completion=no",
"-Ddbus_services=/app/share/dbus-1/services",
"-Dsystemd_user_services=no"
],
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.gnome.org/GNOME/tracker.git",
"branch" : "tracker-2.3"
}
]
},
{
"name" : "libevdev",
"buildsystem" : "meson",
......
......@@ -44,7 +44,6 @@ manette_dep = dependency ('manette-0.2', version: '>=' + manette_min_version)
retro_gtk_dep = dependency ('retro-gtk-2', version: '>=' + retro_gtk_min_version)
rsvg_dep = dependency ('librsvg-2.0')
sqlite_dep = dependency ('sqlite3')
tracker_sparql_dep = dependency ('tracker-sparql-2.0')
xml_dep = dependency ('libxml-2.0')
srcdir = meson.source_root () / 'src'
......
// This file is part of Highscore. License: GPL-3.0+.
public class Highscore.LibraryIterator : Object, UriIterator {
private Uri uri;
private List<FileEnumerator> stack;
private string[] skip_mime_types;
public LibraryIterator (string path) {
stack = new List<FileEnumerator> ();
skip_mime_types = {};
var register = PlatformRegister.get_register ();
var platforms = register.get_all_platforms ();
foreach (var platform in platforms) {
if (platform.autodiscovery)
continue;
var mime_types = platform.get_mime_types ();
foreach (var mime in mime_types)
skip_mime_types += mime;
}
var root = File.new_for_path (path);
try {
recurse (root);
} catch (Error e) {
critical (e.message);
}
}
private void recurse (File dir) throws Error {
var enumerator = dir.enumerate_children (
FileAttribute.STANDARD_TYPE + "," +
FileAttribute.STANDARD_CONTENT_TYPE,
FileQueryInfoFlags.NONE
);
stack.prepend (enumerator);
}
public new Uri? get () {
return uri;
}
public bool next () {
if (stack.length () == 0)
return false;
var enumerator = stack.first ().data;
FileInfo info;
try {
while ((info = enumerator.next_file (null)) != null) {
var child = enumerator.get_child (info);
if (info.get_file_type () == FileType.DIRECTORY) {
recurse (child);
return next ();
}
if (info.get_content_type () in skip_mime_types)
continue;
uri = new Uri (child.get_uri ());
return true;
}
} catch (Error e) {
critical (e.message);
}
stack.remove (enumerator);
return stack.length () > 0;
}
}
// This file is part of Highscore. License: GPL-3.0+.
public class Highscore.LibrarySource : Object, UriSource {
public string path { get; private set; }
public LibrarySource (string path) {
this.path = path;
}
public UriIterator iterator () {
return new LibraryIterator (path);
}
}
......@@ -19,6 +19,9 @@ vala_sources = [
'collection/recently-played-collection.vala',
'collection/user-collection.vala',
'core/library/library-iterator.vala',
'core/library/library-source.vala',
'core/runner/input-manager.vala',
'core/runner/runner.vala',
'core/runner/runner-error.vala',
......@@ -142,12 +145,6 @@ vala_sources = [
'screen-layout/screen-layout-item.vala',
'screen-layout/screen-layout-switcher.vala',
'tracker/mime-type-tracker-uri-query.vala',
'tracker/tracker-error.vala',
'tracker/tracker-uri-iterator.vala',
'tracker/tracker-uri-query.vala',
'tracker/tracker-uri-source.vala',
'ui/application.vala',
'ui/application-window.vala',
'ui/checkmark-item.vala',
......@@ -230,7 +227,6 @@ dependencies = [
retro_gtk_dep,
rsvg_dep,
sqlite_dep,
tracker_sparql_dep,
xml_dep,
valac.find_library ('linux'),
......
// This file is part of Highscore. License: GPL-3.0+.
public class Highscore.MimeTypeTrackerUriQuery : Object, TrackerUriQuery {
private string mime_type;
public MimeTypeTrackerUriQuery (string mime_type) {
this.mime_type = mime_type;
}
public string get_query () {
return @"SELECT DISTINCT nie:url(?urn) WHERE { ?urn nie:mimeType \"$mime_type\" . }";
}
}
// This file is part of Highscore. License: GPL-3.0+.
public errordomain TrackerError {
FILE_NOT_FOUND,
}
// This file is part of Highscore. License: GPL-3.0+.
private class Highscore.TrackerUriIterator : Object, UriIterator {
private Tracker.Sparql.Connection connection;
private TrackerUriQuery[] queries;
private int query_index;
private Uri? uri;
private Tracker.Sparql.Cursor cursor;
internal TrackerUriIterator (Tracker.Sparql.Connection connection, TrackerUriQuery[] queries) {
this.connection = connection;
this.queries = queries;
query_index = 0;
uri = null;
cursor = null;
}
public new Uri? get () {
return uri;
}
public bool next () {
while (query_index < queries.length) {
if (try_next_for_query (queries[query_index]))
return true;
query_index++;
}
return false;
}
private bool try_next_for_query (TrackerUriQuery query) {
try {
if (next_for_query (query))
return true;
}
catch (Error e) {
debug (e.message);
}
uri = null;
cursor = null;
return false;
}
private bool next_for_query (TrackerUriQuery query) throws Error {
if (cursor == null) {
var sparql = query.get_query ();
cursor = connection.query (sparql);
}
if (!cursor.next ())
return false;
uri = new Uri (cursor.get_string (0));
return true;
}
}
// This file is part of Highscore. License: GPL-3.0+.
public interface Highscore.TrackerUriQuery : Object {
public abstract string get_query ();
}
// This file is part of Highscore. License: GPL-3.0+.
public class Highscore.TrackerUriSource : Object, UriSource {
private Tracker.Sparql.Connection connection { get; private set; }
private TrackerUriQuery[] queries;
public TrackerUriSource (Tracker.Sparql.Connection connection) {
this.connection = connection;
}
construct {
queries = {};
}
public void add_query (TrackerUriQuery query) {
queries += query;
}
public UriIterator iterator () {
return new TrackerUriIterator (connection, queries);
}
}
......@@ -2,7 +2,6 @@
public class Highscore.Application : Adw.Application {
const string HELP_URI = "https://wiki.gnome.org/Apps/Games/Documentation";
const string TEST_QUERY = "SELECT nie:url(?f) WHERE { ?f fts:match 'test query to check tracker' }";
private Database database;
......@@ -18,7 +17,6 @@ public class Highscore.Application : Adw.Application {
private Manette.Monitor manette_monitor;
private bool tracker_failed;
private bool initialized;
private const ActionEntry[] action_entries = {
......@@ -365,7 +363,33 @@ public class Highscore.Application : Adw.Application {
return 0;
}
protected override void activate () {
private async void activate_do () {
var settings = new Settings ("org.gnome.World.Highscore");
var library_paths = settings.get_strv ("library-paths");
if (library_paths.length == 0) {
var chooser = new Gtk.FileChooserNative (
_("Add Library Folder"),
window,
Gtk.FileChooserAction.SELECT_FOLDER,
_("_Add"),
_("_Cancel")
);
var response = yield DialogUtils.run_native_async (chooser);
if (response == Gtk.ResponseType.ACCEPT) {
var path = chooser.get_file ().get_path ();
library_paths += path;
settings.set_strv ("library-paths", library_paths);
} else {
quit ();
}
chooser.destroy ();
}
if (!initialized) {
init_game_sources ();
......@@ -396,10 +420,13 @@ public class Highscore.Application : Adw.Application {
window.present ();
if (tracker_failed) {
string error_msg = _("Couldn't find Tracker, automatic game discovery may not work.");
window.show_error (error_msg);
}
release ();
}
protected override void activate () {
hold ();
activate_do.begin ();
}
private void init_game_sources () {
......@@ -412,39 +439,22 @@ public class Highscore.Application : Adw.Application {
Migrator.apply_migration_if_necessary (database);
database.prepare_statements ();
TrackerUriSource tracker_uri_source = null;
try {
var connection = Tracker.Sparql.Connection.@get ();
connection.query (TEST_QUERY);
tracker_uri_source = new TrackerUriSource (connection);
}
catch (Error e) {
tracker_failed = true;
critical ("Couldn't find Tracker: %s", e.message);
}
game_collection = new GameCollection (database);
if (tracker_uri_source != null)
game_collection.add_source (tracker_uri_source);
var settings = new Settings ("org.gnome.World.Highscore");
var library_paths = settings.get_strv ("library-paths");
foreach (var path in library_paths) {
var source = new LibrarySource (path);
game_collection.add_source (source);
}
var platform_register = PlatformRegister.get_register ();
var mime_types = new GenericSet<string> (str_hash, str_equal);
foreach (var platform in platform_register.get_all_platforms ()) {
var factory = new UriGameFactory (platform);
game_collection.add_factory (factory);
if (platform.autodiscovery && tracker_uri_source != null) {
foreach (var mime_type in platform.get_mime_types ()) {
if (mime_types.contains (mime_type))
continue;
mime_types.add (mime_type);
var query = new MimeTypeTrackerUriQuery (mime_type);
tracker_uri_source.add_query (query);
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment