[totem/sam/tracker3-flatpak-bundle: 13/14] Run Tracker Miners inside the Flatpak sandbox




commit 356d372ed0144c6203e5a65177590aa167531ed7
Author: Sam Thursfield <sam afuera me uk>
Date:   Sun Aug 2 12:28:11 2020 +0200

    Run Tracker Miners inside the Flatpak sandbox
    
    The Flatpak version of Totem will now run a local tracker-miner-fs-3
    instance instead of using the host instance, in all cases.
    
    For background, see:
    https://gitlab.gnome.org/GNOME/totem/-/merge_requests/154#note_881125

 data/meson.build                                   |   2 +
 data/tracker/meson.build                           |  32 ++++++
 ...g.gnome.Totem.Tracker3.Miner.Extract.service.in |   7 ++
 ...org.gnome.Totem.Tracker3.Miner.Files.service.in |   7 ++
 data/tracker/org.gnome.Totem.domain.rule.in        |  20 ++++
 flatpak/org.gnome.Totem.Devel.json                 |  25 ++++-
 meson.build                                        |   1 +
 src/meson.build                                    |   5 +-
 src/totem-grilo.c                                  |   6 ++
 src/totem-tracker.c                                | 116 +++++++++++++++++++++
 src/totem-tracker.h                                |  33 ++++++
 11 files changed, 250 insertions(+), 4 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 32f2f8450..3190e733b 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -180,3 +180,5 @@ install_data(
   'totem.convert',
   install_dir: join_paths(totem_datadir, 'GConf', 'gsettings')
 )
+
+subdir('tracker')
diff --git a/data/tracker/meson.build b/data/tracker/meson.build
new file mode 100644
index 000000000..594ab3778
--- /dev/null
+++ b/data/tracker/meson.build
@@ -0,0 +1,32 @@
+# Files needed for running Tracker inside the Flatpak sandbox, for systems
+# which don't have a suitable version of Tracker in the host OS.
+#
+# We must export the .service files from the sandbox so they work on the
+# session bus. This means the Tracker domain name must correspond with the
+# application ID.
+
+
+domain_ontologies_dir = get_option('datadir') / 'tracker3' / 'domain-ontologies'
+dbus_services_dir = get_option('datadir') / 'dbus-1' / 'services'
+
+tracker_domain_config = configuration_data()
+tracker_domain_config.set('application_id', application_id)
+tracker_domain_config.set('domain_rule', get_option('prefix') / domain_ontologies_dir / application_id + 
'.domain.rule')
+
+configure_file(
+  input: 'org.gnome.Totem.domain.rule.in',
+  output: application_id + '.domain.rule',
+  configuration: tracker_domain_config,
+  install_dir: domain_ontologies_dir)
+
+configure_file(
+  input: 'org.gnome.Totem.Tracker3.Miner.Extract.service.in',
+  output: application_id + '.Tracker3.Miner.Extract.service',
+  configuration: tracker_domain_config,
+  install_dir: dbus_services_dir)
+
+configure_file(
+  input: 'org.gnome.Totem.Tracker3.Miner.Files.service.in',
+  output: application_id + '.Tracker3.Miner.Files.service',
+  configuration: tracker_domain_config,
+  install_dir: dbus_services_dir)
diff --git a/data/tracker/org.gnome.Totem.Tracker3.Miner.Extract.service.in 
b/data/tracker/org.gnome.Totem.Tracker3.Miner.Extract.service.in
new file mode 100644
index 000000000..eb7a87aa6
--- /dev/null
+++ b/data/tracker/org.gnome.Totem.Tracker3.Miner.Extract.service.in
@@ -0,0 +1,7 @@
+[D-BUS Service]
+Name=@application_id@.Tracker3.Miner.Extract
+Exec=/app/libexec/tracker-extract-3 --domain-ontology @domain_rule@
+
+# Miner details needed for tracker-control
+Path=/org/freedesktop/Tracker3/Miner/Extract
+NameSuffix=Miner.Files
diff --git a/data/tracker/org.gnome.Totem.Tracker3.Miner.Files.service.in 
b/data/tracker/org.gnome.Totem.Tracker3.Miner.Files.service.in
new file mode 100644
index 000000000..4fa7371d1
--- /dev/null
+++ b/data/tracker/org.gnome.Totem.Tracker3.Miner.Files.service.in
@@ -0,0 +1,7 @@
+[D-BUS Service]
+Name=@application_id@.Tracker3.Miner.Files
+Exec=/app/libexec/tracker-miner-fs-3 --domain-ontology @domain_rule@ --initial-sleep 0
+
+# Miner details needed for tracker-control
+Path=/org/freedesktop/Tracker3/Miner/Files
+NameSuffix=Miner.Files
diff --git a/data/tracker/org.gnome.Totem.domain.rule.in b/data/tracker/org.gnome.Totem.domain.rule.in
new file mode 100644
index 000000000..d1ce398d3
--- /dev/null
+++ b/data/tracker/org.gnome.Totem.domain.rule.in
@@ -0,0 +1,20 @@
+# This defines a private Tracker domain for GNOME Totem.
+#
+# It's used to run the Tracker indexer inside a Flatpak sandbox, when Totem is
+# running on a host that doesn't have a suitable version of Tracker installed.
+
+[DomainOntology]
+# Location for the Tracker database
+CacheLocation=$XDG_CACHE_HOME/totem/miner/files
+
+# Name of the ontology to use, must be one located in
+# $(sharedir)/tracker/ontologies
+OntologyName=nepomuk
+
+# DBus name for the owner (not optional). Tracker will use
+# the domain as the prefix of the DBus name for all the
+# services related to this domain ontology.
+Domain=@application_id@
+
+# List of miners we expect to run in this domain.
+Miners=Miner.Files;Miner.Extract
diff --git a/flatpak/org.gnome.Totem.Devel.json b/flatpak/org.gnome.Totem.Devel.json
index 5f6550080..8426538bb 100644
--- a/flatpak/org.gnome.Totem.Devel.json
+++ b/flatpak/org.gnome.Totem.Devel.json
@@ -45,8 +45,9 @@
         "--own-name=org.mpris.MediaPlayer2.totem",
         /* im-status plugin */
         "--talk-name=org.gnome.SessionManager",
-        /* Tracker 3 policy */
-        "--add-policy=Tracker3.dbus:org.freedesktop.Tracker3.Miner.Files=tracker:Video"
+        /* Private Tracker Miner FS running inside the sandbox */
+        "--own-name=org.gnome.Totem.Devel.Tracker3.Miner.Files",
+        "--own-name=org.gnome.Totem.Devel.Tracker3.Miner.Extract"
     ],
     "cleanup": [ "/include", "/share/bash-completion" ],
     "modules": [
@@ -165,6 +166,24 @@
                 }
             ]
         },
+        {
+            "name": "tracker-miners",
+            "cleanup": [ "/bin", "/etc", "/share/dbus-1/services" ],
+            "buildsystem": "meson",
+            "config-opts" : [
+                "-Dman=false",
+                "-Dminer_fs=true",
+                "-Dminer_rss=false",
+                "-Dsystemd_user_services=false",
+                "-Dwriteback=false"
+            ],
+            "sources": [
+                {
+                    "type": "git",
+                    "url": "https://gitlab.gnome.org/GNOME/tracker-miners.git";
+                }
+            ]
+        },
         {
             "name": "libmediaart",
             "cleanup": [ "/bin", "/etc", "/libexec" ],
@@ -213,7 +232,7 @@
                 "-Denable-lua-factory=yes",
                 "-Denable-metadata-store=yes",
                 "-Denable-vimeo=yes",
-                "-Denable-tracker=yes",
+                "-Denable-tracker3=yes",
                 "-Denable-local-metadata=yes",
                 "-Denable-dleyna=yes",
                 "-Denable-thetvdb=yes",
diff --git a/meson.build b/meson.build
index af8aa7953..b9d0e716c 100644
--- a/meson.build
+++ b/meson.build
@@ -141,6 +141,7 @@ gst_pbutils_dep = dependency('gstreamer-pbutils-1.0')
 peas_dep = dependency('libpeas-1.0', version: peas_req_version)
 peas_gtk_dep = dependency('libpeas-gtk-1.0', version: peas_req_version)
 totem_plparser_dep = dependency('totem-plparser', version: totem_plparser_req_version)
+tracker_dep = dependency('tracker-sparql-3.0', version: '>= 2.99')
 clutter_gtk_dep = dependency('clutter-gtk-1.0', version: '>= 1.8.1')
 m_dep = cc.find_library('m', required: true)
 
diff --git a/src/meson.build b/src/meson.build
index 1ad816adf..6ce058f4a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -28,6 +28,7 @@ enum_headers = files(
   'totem-selection-toolbar.h',
   'totem-session.h',
   'totem-subtitle-encoding.h',
+  'totem-tracker.h',
   'totem-uri.h',
   'totem.h'
 )
@@ -61,7 +62,8 @@ totem_common_deps = libbacon_video_widget_deps + python_deps + [
   peas_gtk_dep,
   dependency('grilo-0.3', version: grilo_req_version),
   dependency('grilo-pls-0.3', version: grilo_req_version),
-  dependency('gnome-desktop-3.0')
+  dependency('gnome-desktop-3.0'),
+  tracker_dep
 ]
 
 totem_common_cflags = common_flags + warn_flags + [
@@ -126,6 +128,7 @@ libtotem_sources = files(
   'totem-selection-toolbar.c',
   'totem-session.c',
   'totem-subtitle-encoding.c',
+  'totem-tracker.c',
   'totem-uri.c'
 )
 
diff --git a/src/totem-grilo.c b/src/totem-grilo.c
index ec0b68041..36b6c609c 100644
--- a/src/totem-grilo.c
+++ b/src/totem-grilo.c
@@ -44,6 +44,7 @@
 #include <totem-time-helpers.h>
 
 #include "totem-grilo.h"
+#include "totem-tracker.h"
 #include "totem-search-entry.h"
 #include "totem-main-toolbar.h"
 #include "totem-selection-toolbar.h"
@@ -1473,6 +1474,11 @@ load_grilo_plugins (TotemGrilo *self)
        grl_config_set_string (config, "ignored-scheme", "vcd");
        grl_registry_add_config (registry, config, NULL);
 
+       /* Connect to host or Flatpak-local Tracker Miners service */
+       config = grl_config_new ("grl-tracker3", NULL);
+       grl_config_set_string (config, "miner-service", totem_tracker_get_miner_fs_busname (NULL));
+       grl_registry_add_config (registry, config, NULL);
+
        g_signal_connect (registry, "source-added",
                          G_CALLBACK (source_added_cb), self);
        g_signal_connect (registry, "source-removed",
diff --git a/src/totem-tracker.c b/src/totem-tracker.c
new file mode 100644
index 000000000..89cec4fda
--- /dev/null
+++ b/src/totem-tracker.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2020, Sam Thursfield <sam afuera me uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ * The Totem project hereby grant permission for non-GPL compatible GStreamer
+ * plugins to be used and distributed together with GStreamer and Totem. This
+ * permission are above and beyond the permissions granted by the GPL license
+ * Totem is covered by.
+ *
+ * See license_change file for details.
+ */
+
+#include "config.h"
+#include "totem-tracker.h"
+#include <libtracker-sparql/tracker-sparql.h>
+
+/* Shared global connection to Tracker Miner FS */
+static const gchar *tracker_miner_fs_busname = NULL;
+static GError *tracker_miner_fs_error = NULL;
+
+static gboolean
+get_host_tracker_miner_fs (GError **error)
+{
+       TrackerSparqlConnection *connection;
+       const gchar *busname = "org.freedesktop.Tracker3.Miner.Files";
+
+       g_message ("Connecting to %s", busname);
+       connection = tracker_sparql_connection_bus_new (busname, NULL, NULL, error);
+       if (*error) {
+               g_warning ("Unable to create connection for session-wide Tracker indexer: %s", 
(*error)->message);
+               return FALSE;
+       }
+
+       tracker_miner_fs_busname = busname;
+       g_object_unref (connection);
+       return TRUE;
+}
+
+static gboolean
+start_local_tracker_miner_fs (GError **error)
+{
+       TrackerSparqlConnection *connection;
+       const gchar *busname = APPLICATION_ID ".Tracker3.Miner.Files";
+
+       g_message ("Starting %s", busname);
+       connection = tracker_sparql_connection_bus_new (busname, NULL, NULL, error);
+       if (*error) {
+               g_critical ("Could not start local Tracker indexer at %s: %s", busname, (*error)->message);
+               return FALSE;
+       }
+
+       tracker_miner_fs_busname = busname;
+       g_object_unref (connection);
+       return TRUE;
+}
+
+static gboolean
+inside_flatpak (void)
+{
+       return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
+}
+
+static void
+setup_tracker_miner_fs_connection (void)
+{
+       static gsize tried_tracker_init = FALSE;
+
+       if (g_once_init_enter (&tried_tracker_init)) {
+               gboolean success;
+
+               if (inside_flatpak ()) {
+                       success = start_local_tracker_miner_fs (&tracker_miner_fs_error);
+               } else {
+                       success = get_host_tracker_miner_fs (&tracker_miner_fs_error);
+               }
+
+               g_once_init_leave (&tried_tracker_init, TRUE);
+       }
+}
+
+/**
+ * totem_tracker_get_miner_fs_busname:
+ * @error: return location for a #GError
+ *
+ * This function returns a DBus name that can be used to talk to
+ * tracker-miner-fs, or %NULL if there is no Tracker Miner FS available.
+ *
+ * The first time you call it, this function will block while trying to connect.
+ * This may take some time if starting Tracker Miners from a Flatpak bundle.
+ *
+ * Returns: a string
+ */
+const gchar *
+totem_tracker_get_miner_fs_busname (GError **error)
+{
+       setup_tracker_miner_fs_connection ();
+
+       if (tracker_miner_fs_error && error) {
+               *error = g_error_copy (tracker_miner_fs_error);
+       }
+
+       return tracker_miner_fs_busname;
+}
diff --git a/src/totem-tracker.h b/src/totem-tracker.h
new file mode 100644
index 000000000..60742bc68
--- /dev/null
+++ b/src/totem-tracker.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2020, Sam Thursfield <sam afuera me uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ * The Totem project hereby grant permission for non-GPL compatible GStreamer
+ * plugins to be used and distributed together with GStreamer and Totem. This
+ * permission are above and beyond the permissions granted by the GPL license
+ * Totem is covered by.
+ *
+ * See license_change file for details.
+ */
+
+#ifndef TOTEM_TRACKER_H
+#define TOTEM_TRACKER_H
+
+#include <glib.h>
+
+const gchar *totem_tracker_get_miner_fs_busname (GError **error);
+
+#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]