[tracker/wip/carlosg/domain-ontologies: 7/116] Allow loading domain ontology from .desktop file



commit 1b1c69fc10766b9ba4c2f8575c3453efa49a4574
Author: Philip Van Hoof <philip codeminded be>
Date:   Sat Jan 28 11:11:28 2017 +0100

    Allow loading domain ontology from .desktop file

 src/libtracker-data/tracker-data-manager.c |   24 +++++++-------
 src/libtracker-data/tracker-data-manager.h |    2 +-
 src/libtracker-data/tracker-db-manager.c   |   42 ++++++++++++------------
 src/libtracker-data/tracker-db-manager.h   |    4 +-
 src/tracker-store/tracker-main.vala        |   50 +++++++++++++++++++++++++---
 5 files changed, 81 insertions(+), 41 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 4850a78..bcd81dd 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -67,7 +67,7 @@
 
 static gchar    *ontologies_dir;
 static gchar    *ontology_name_stored;
-static gchar    *domain_stored;
+static gchar    *loc_stored;
 static gboolean  initialized;
 static gboolean  reloading = FALSE;
 #ifndef DISABLE_JOURNAL
@@ -3533,7 +3533,7 @@ tracker_data_manager_reload (TrackerBusyCallback   busy_callback,
 
        /* And initialize it again, this actually triggers index recreation. */
        status = tracker_data_manager_init (flags,
-                                           domain_stored, ontology_name_stored,
+                                           loc_stored, ontology_name_stored,
                                            NULL,
                                            &is_first,
                                            TRUE,
@@ -3674,7 +3674,7 @@ tracker_data_manager_init_fts (TrackerDBInterface *iface,
 
 gboolean
 tracker_data_manager_init (TrackerDBManagerFlags   flags,
-                           const gchar            *domain,
+                           const gchar            *loc,
                            const gchar            *ontology_name,
                            const gchar           **test_schemas,
                            gboolean               *first_time,
@@ -3734,7 +3734,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 #endif
 
        if (!tracker_db_manager_init (flags,
-                                     domain, ontology_name,
+                                     loc, ontology_name,
                                      &is_first_time_index,
                                      restoring_backup,
                                      FALSE,
@@ -3804,8 +3804,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
        env_path = g_getenv ("TRACKER_DB_ONTOLOGIES_DIR");
 
-       g_free (domain_stored);
-       domain_stored = g_strdup(domain);
+       g_free (loc_stored);
+       loc_stored = g_strdup(loc);
        g_free (ontology_name_stored);
        ontology_name_stored = g_strdup(ontology_name);
 
@@ -3816,11 +3816,11 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                           "ontologies",
                                                           NULL);
                } else {
-                       if (domain == NULL) {
-                               domain = "tracker";
+                       if (loc == NULL) {
+                               loc = "tracker";
                        }
                        ontologies_dir = g_build_filename (SHAREDIR,
-                                                          domain,
+                                                          loc,
                                                           "ontologies",
                                                           ontology_name,
                                                           NULL);
@@ -4285,7 +4285,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                tracker_data_manager_shutdown ();
 
                                                return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
-                                                                                 domain, ontology_name,
+                                                                                 loc, ontology_name,
                                                                                  test_schemas,
                                                                                  first_time,
                                                                                  journal_check,
@@ -4376,7 +4376,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                        tracker_data_manager_shutdown ();
 
                                        return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
-                                                                         domain, ontology_name,
+                                                                         loc, ontology_name,
                                                                          test_schemas,
                                                                          first_time,
                                                                          journal_check,
@@ -4484,7 +4484,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                tracker_data_manager_shutdown ();
 
                                return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
-                                                                 domain, ontology_name,
+                                                                 loc, ontology_name,
                                                                  test_schemas,
                                                                  first_time,
                                                                  journal_check,
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index e18c45b..39f05eb 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -46,7 +46,7 @@ typedef enum {
 
 GQuark   tracker_data_ontology_error_quark           (void);
 gboolean tracker_data_manager_init                   (TrackerDBManagerFlags   flags,
-                                                      const gchar            *domain,
+                                                      const gchar            *loc,
                                                       const gchar            *ontology_name,
                                                       const gchar           **test_schema,
                                                       gboolean               *first_time,
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 1efd8c0..feb5e7e 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -156,7 +156,7 @@ static gboolean              locations_initialized;
 static gchar                *data_dir = NULL;
 static gchar                *user_data_dir = NULL;
 static gchar                *in_use_filename = NULL;
-static gchar                *in_use_domain = NULL;
+static gchar                *in_use_loc = NULL;
 static gchar                *in_use_ontology_name = NULL;
 static gpointer              db_type_enum_class_pointer;
 static TrackerDBManagerFlags old_flags = 0;
@@ -665,7 +665,7 @@ tracker_db_manager_locale_changed (GError **error)
         * to check for locale mismatches for initializing the database.
         */
        if (!locations_initialized) {
-               tracker_db_manager_init_locations (in_use_domain, in_use_ontology_name);
+               tracker_db_manager_init_locations (in_use_loc, in_use_ontology_name);
        }
 
        /* Get current collation locale */
@@ -794,7 +794,7 @@ db_recreate_all (GError **error)
 }
 
 void
-tracker_db_manager_init_locations (const char *domain, const char *ontology_name)
+tracker_db_manager_init_locations (const char *loc, const char *ontology_name)
 {
        const gchar *dir;
        guint i;
@@ -803,11 +803,11 @@ tracker_db_manager_init_locations (const char *domain, const char *ontology_name
                return;
        }
 
-       if (domain == NULL) {
-               domain = "tracker";
+       if (loc == NULL) {
+               loc = "tracker";
        }
        user_data_dir = g_build_filename (g_get_user_data_dir (),
-                                         domain,
+                                         loc,
                                          "data",
                                          NULL);
 
@@ -816,11 +816,11 @@ tracker_db_manager_init_locations (const char *domain, const char *ontology_name
 
        if (ontology_name == NULL) {
                data_dir = g_build_filename (g_get_user_cache_dir (),
-                                            domain,
+                                            loc,
                                             NULL);
        } else {
                data_dir = g_build_filename (g_get_user_cache_dir (),
-                                            domain, ontology_name,
+                                            loc, ontology_name,
                                             NULL);
        }
 
@@ -866,7 +866,7 @@ perform_recreate (gboolean *first_time, GError **error)
 
 static gboolean
 db_manager_init_unlocked (TrackerDBManagerFlags   flags,
-                          const gchar            *domain,
+                          const gchar            *loc,
                           const gchar            *ontology_name,
                           gboolean               *first_time,
                           gboolean                restoring_backup,
@@ -916,30 +916,30 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
        old_flags = flags;
 
        g_free (in_use_filename);
-       g_free (in_use_domain);
+       g_free (in_use_loc);
        g_free (in_use_ontology_name);
 
-       if (domain == NULL)
-               domain = "tracker";
-       in_use_domain = g_strdup (domain);
+       if (loc == NULL)
+               loc = "tracker";
+       in_use_loc = g_strdup (loc);
 
        if (ontology_name == NULL)
                in_use_ontology_name = NULL;
        else
                in_use_ontology_name = g_strdup (ontology_name);
 
-       in_use_domain = g_strdup (domain);
+       in_use_loc = g_strdup (loc);
 
-       tracker_db_manager_init_locations (domain, ontology_name);
+       tracker_db_manager_init_locations (loc, ontology_name);
        if (ontology_name == NULL) {
                in_use_filename = g_build_filename (g_get_user_data_dir (),
-                                                   domain,
+                                                   loc,
                                                    "data",
                                                    IN_USE_FILENAME,
                                                    NULL);
        } else {
                in_use_filename = g_build_filename (g_get_user_data_dir (),
-                                                   domain, ontology_name,
+                                                   loc, ontology_name,
                                                    "data",
                                                    IN_USE_FILENAME,
                                                    NULL);
@@ -1071,13 +1071,13 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
 #ifndef DISABLE_JOURNAL
                if (ontology_name == NULL) {
                        journal_filename = g_build_filename (g_get_user_data_dir (),
-                                                            domain,
+                                                            loc,
                                                             "data",
                                                             TRACKER_DB_JOURNAL_FILENAME,
                                                             NULL);
                } else {
                        journal_filename = g_build_filename (g_get_user_data_dir (),
-                                                            domain,
+                                                            loc,
                                                             ontology_name,
                                                             "data",
                                                             TRACKER_DB_JOURNAL_FILENAME,
@@ -1289,7 +1289,7 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
 
 gboolean
 tracker_db_manager_init (TrackerDBManagerFlags   flags,
-                         const gchar            *domain,
+                         const gchar            *loc,
                          const gchar            *ontology_name,
                          gboolean               *first_time,
                          gboolean                restoring_backup,
@@ -1305,7 +1305,7 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 
        g_mutex_lock (&init_mutex);
 
-       retval = db_manager_init_unlocked (flags, domain, ontology_name,
+       retval = db_manager_init_unlocked (flags, loc, ontology_name,
                                           first_time, restoring_backup,
                                           shared_cache,
                                           select_cache_size, update_cache_size,
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index cfe7408..5848fe2 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -53,7 +53,7 @@ typedef enum {
 
 GType               tracker_db_get_type                       (void) G_GNUC_CONST;
 gboolean            tracker_db_manager_init                   (TrackerDBManagerFlags   flags,
-                                                               const gchar            *domain,
+                                                               const gchar            *loc,
                                                                const gchar            *ontology_name,
                                                                gboolean               *first_time,
                                                                gboolean                restoring_backup,
@@ -69,7 +69,7 @@ void                tracker_db_manager_remove_all             (gboolean
 void                tracker_db_manager_optimize               (void);
 const gchar *       tracker_db_manager_get_file               (TrackerDB              db);
 TrackerDBInterface *tracker_db_manager_get_db_interface       (void);
-void                tracker_db_manager_init_locations         (const gchar *domain, const gchar 
*ontology_name);
+void                tracker_db_manager_init_locations         (const gchar *loc, const gchar *ontology_name);
 gboolean            tracker_db_manager_has_enough_space       (void);
 void                tracker_db_manager_create_version_file    (void);
 void                tracker_db_manager_remove_version_file    (void);
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 07a82d9..65b71de 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -22,6 +22,9 @@ class Tracker.Main {
        [CCode (cname = "PACKAGE_VERSION")]
        extern const string PACKAGE_VERSION;
 
+       [CCode (cname = "SHAREDIR")]
+       extern const string SHAREDIR;
+
        const string LICENSE = "This program is free software and comes without any warranty.
 It is licensed under version 2 or later of the General Public
 License which can be viewed at:
@@ -41,6 +44,8 @@ License which can be viewed at:
        static int verbosity;
        static bool force_reindex;
        static bool readonly_mode;
+       static string domain_ontology;
+       static string cache_location;
        static string domain;
        static string ontology_name;
        
@@ -52,8 +57,10 @@ License which can be viewed at:
                /* Indexer options */
                { "force-reindex", 'r', 0, OptionArg.NONE, ref force_reindex, N_("Force a re-index of all 
content"), null },
                { "readonly-mode", 'n', 0, OptionArg.NONE, ref readonly_mode, N_("Only allow read based 
actions on the database"), null },
-               { "domain", 'd', 0, OptionArg.STRING, ref domain, N_("Domain to be used"), null },
-               { "ontology-name", 'o', 0, OptionArg.STRING, ref ontology_name, N_("Ontology to be used"), 
null },
+               { "domain-ontology", 'd', 0, OptionArg.STRING, ref domain_ontology, N_("Load a specified 
domain ontology"), null },
+               { "cache-location", 'd', 0, OptionArg.STRING, ref cache_location, N_("Override cache location 
to be used"), null },
+               { "domain", 'd', 0, OptionArg.STRING, ref domain, N_("Override domain to be used"), null },
+               { "ontology-name", 0, 0, OptionArg.STRING, ref ontology_name, N_("Override ontology to be 
used"), null },
 
                { null }
        };
@@ -65,9 +72,17 @@ License which can be viewed at:
                message ("Store options:");
                message ("  Readonly mode  ........................  %s", readonly_mode ? "yes" : "no");
                message ("  GraphUpdated Delay ....................  %d", config.graphupdated_delay);
-               message ("  Domain         ........................  %s", domain);
-               message ("  Ontology name  ........................  %s", ontology_name);
 
+               if (domain_ontology != null)
+                       message ("  Domain ontology........................  %s", domain_ontology);
+
+               message ("  Cache location.........................  %s",
+                        cache_location != null ? cache_location : "tracker");
+               message ("  Domain ................................  %s",
+                        domain != null ? null : "org.freedesktop.Tracker1");
+
+               if (ontology_name != null)
+                       message ("  Ontology name .........................  %s", ontology_name);
        }
 
        static void do_shutdown () {
@@ -203,6 +218,31 @@ License which can be viewed at:
                        message ("Using log file:'%s'", log_filename);
                }
 
+               if (domain_ontology != null) {
+                       string? loaded_domain;
+                       string? loaded_cache_location;
+                       string? loaded_ontology_name;
+
+                       string keyfile_path = Path.build_filename (SHAREDIR,
+                                                                  "tracker",
+                                                                  "domains",
+                                                                  domain_ontology+".desktop");
+                       try {
+                               GLib.KeyFile keyfile = new GLib.KeyFile ( );
+                               keyfile.load_from_file (keyfile_path, GLib.KeyFileFlags.NONE);
+                               loaded_domain = keyfile.get_string ("DomainOntology", "Domain");
+                               loaded_cache_location = keyfile.get_string ("DomainOntology", 
"CacheLocation");
+                               loaded_ontology_name = keyfile.get_string ("DomainOntology", "OntologyName");
+
+                               if (domain == null)
+                                       domain = loaded_domain;
+                               if (cache_location == null)
+                                       cache_location = loaded_cache_location;
+                               if (ontology_name == null)
+                                       ontology_name = loaded_ontology_name;
+                       } catch { }
+               }
+
                sanity_check_option_values (config);
 
                if (!Tracker.DBus.init (config)) {
@@ -268,7 +308,7 @@ License which can be viewed at:
                bool is_first_time_index;
 
                try {
-                       Tracker.Data.Manager.init (flags, domain, ontology_name,
+                       Tracker.Data.Manager.init (flags, cache_location, ontology_name,
                                                   null,
                                                   out is_first_time_index,
                                                   true,


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