[tracker/new-userguides-miner] tracker-user-guides: Split out from tracker-miner-fs, now separate binary



commit 1ff6f9b494a5cd6d6ef23052e9cb7ab189cb3627
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Mar 31 17:38:16 2014 +0100

    tracker-user-guides: Split out from tracker-miner-fs, now separate binary

 configure.ac                                       |   52 +++-
 data/Makefile.am                                   |   10 +
 data/dbus/Makefile.am                              |    9 +-
 ...reedesktop.Tracker1.Miner.Userguides.service.in |    2 +-
 data/miners/Makefile.am                            |    9 +-
 data/tracker-miner-user-guides.desktop.in.in       |   19 ++
 src/libtracker-miner/tracker-file-notifier.c       |    2 +
 src/miners/fs/Makefile.am                          |    9 -
 src/miners/fs/tracker-config.c                     |    6 -
 src/miners/fs/tracker-main.c                       |  203 +---------------
 src/miners/user-guides/Makefile.am                 |   22 ++
 src/miners/user-guides/tracker-main.c              |  266 ++++++++++++++++++++
 .../tracker-miner-user-guides.c}                   |   14 +-
 .../tracker-miner-user-guides.h}                   |    0
 14 files changed, 374 insertions(+), 249 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 791cf5d..379c65e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -347,7 +347,11 @@ TRACKER_MINER_APPS_REQUIRED="glib-2.0     >= $GLIB_REQUIRED"
 
 PKG_CHECK_MODULES(TRACKER_MINER_APPS, [$TRACKER_MINER_APPS_REQUIRED])
 
-#TRACKER_MINER_FS_LIBS="$TRACKER_MINER_FS_LIBS -lz -lm"
+# Check requirements for tracker-miner-user-guides
+TRACKER_MINER_USER_GUIDES_REQUIRED="glib-2.0     >= $GLIB_REQUIRED
+                                    libxml-2.0   >= $LIBXML2_REQUIRED"
+
+PKG_CHECK_MODULES(TRACKER_MINER_USER_GUIDES, [$TRACKER_MINER_USER_GUIDES_REQUIRED])
 
 # Check requirements for tracker-miner-evolution
 evolution_plugin_name=""
@@ -1201,6 +1205,31 @@ fi
 AM_CONDITIONAL(HAVE_TRACKER_MINER_APPS, test "x$have_tracker_miner_apps" = "xyes")
 
 ##################################################################
+# Check for tracker-miner-user-guides
+##################################################################
+
+have_tracker_miner_user_guides="yes"
+
+AC_ARG_ENABLE(miner_user_guides,
+              AS_HELP_STRING([--enable-miner-user-guides],
+                             [enable User guides miner [[default=yes]]]),,
+                             [enable_tracker_miner_user_guides=yes])
+
+enable_tracker_miner_user_guides=$enable_miner_user_guides
+
+if test "x$enable_tracker_miner_user_guides" = "xyes"; then
+   if test "x$have_tracker_miner_user_guides" != "xyes"; then
+      AC_MSG_ERROR([Couldn't find tracker-miner-user-guides dependencies 
($TRACKER_MINER_USER_GUIDES_REQUIRED).])
+   fi
+else
+   if test "x$enable_tracker_miner_user_guides" = "xno"; then
+      have_tracker_miner_user_guides="no  (disabled)"
+   fi
+fi
+
+AM_CONDITIONAL(HAVE_TRACKER_MINER_USER_GUIDES, test "x$have_tracker_miner_user_guides" = "xyes")
+
+##################################################################
 # Check for tracker-miner-rss
 ##################################################################
 
@@ -1542,13 +1571,6 @@ AC_ARG_ENABLE(libxml2,
                              [enable extractor for HTML/XML metadata [[default=yes]]]),,
               [enable_libxml2=yes])
 
-# Force libxml requirement for HAVE_MAEMO,
-# given the miner-fs needs it for the userguide extraction.
-if test "x$enable_maemo" = "xyes" ; then
-  enable_libxml2="yes"
-fi
-
-
 if test "x$enable_libxml2" != "xno"; then
    PKG_CHECK_MODULES(LIBXML2,
                      [libxml-2.0 >= $LIBXML2_REQUIRED],
@@ -2401,6 +2423,7 @@ AC_CONFIG_FILES([
        src/miners/fs/Makefile
        src/miners/apps/Makefile
        src/miners/rss/Makefile
+       src/miners/user-guides/Makefile
        src/tracker-store/Makefile
        src/tracker-control/Makefile
        src/tracker-extract/Makefile
@@ -2563,14 +2586,15 @@ Metadata Extractors:
 
 Data Miners:
 
-       FS:                                     $have_tracker_miner_fs (MeeGo support: $have_meegotouch)
-         Includes File Systems
-         Includes User Guides
+       FS (File System):                       $have_tracker_miner_fs (MeeGo support: $have_meegotouch)
        Applications:                           $have_tracker_miner_apps
        RSS:                                    $have_tracker_miner_rss
-       Evolution:                              $have_tracker_miner_evolution 
($tracker_miner_evolution_install_dir)
-        Thunderbird:                            $have_tracker_miner_thunderbird 
($tracker_miner_thunderbird_install_dir)
-        FireFox:                                $have_tracker_miner_firefox 
($tracker_miner_firefox_install_dir)
+       User Guides:                            $have_tracker_miner_user_guides
+       Email:
+          Evolution:                            $have_tracker_miner_evolution 
($tracker_miner_evolution_install_dir)
+          Thunderbird:                          $have_tracker_miner_thunderbird 
($tracker_miner_thunderbird_install_dir)
+        Bookmarks:
+          FireFox:                              $have_tracker_miner_firefox 
($tracker_miner_firefox_install_dir)
 
 Plugins:
 
diff --git a/data/Makefile.am b/data/Makefile.am
index 84b2c41..4c6f5c4 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -28,11 +28,16 @@ tracker-miner-rss.desktop.in: tracker-miner-rss.desktop.in.in
        @$(SED) -e "s|@libexecdir[ ]|${libexecdir}|"   \
             -e "s|@VERSION[ ]|${VERSION}|" $< > $@
 
+tracker-miner-user-guides.desktop.in: tracker-miner-user-guides.desktop.in.in
+       @sed -e "s|@libexecdir[ ]|${libexecdir}|"      \
+            -e "s|@VERSION[ ]|${VERSION}|" $< > $@
+
 desktop_in_in_files =                                  \
        tracker-extract.desktop.in.in                  \
        tracker-store.desktop.in.in                    \
        tracker-miner-fs.desktop.in.in                 \
        tracker-miner-apps.desktop.in.in               \
+       tracker-miner-user-guides.desktop.in.in        \
        tracker-miner-rss.desktop.in.in
 
 # Second take those new .in files and translate them
@@ -41,6 +46,7 @@ desktop_in_files =                                     \
        tracker-store.desktop.in                       \
        tracker-miner-fs.desktop.in                    \
        tracker-miner-apps.desktop.in                  \
+       tracker-miner-user-guides.desktop.in           \
        tracker-miner-rss.desktop.in
 
 # Third we choose what we want installed based on config
@@ -60,6 +66,10 @@ if HAVE_TRACKER_MINER_RSS
 autostart_DATA += tracker-miner-rss.desktop
 endif
 
+if HAVE_TRACKER_MINER_USER_GUIDES
+autostart_DATA += tracker-miner-user-guides.desktop
+endif
+
 @INTLTOOL_DESKTOP_RULE@
 
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/data/dbus/Makefile.am b/data/dbus/Makefile.am
index c941f6a..402ce17 100644
--- a/data/dbus/Makefile.am
+++ b/data/dbus/Makefile.am
@@ -39,11 +39,6 @@ service_DATA += \
        org.freedesktop.Tracker1.Miner.Extract.service \
        org.freedesktop.Tracker1.Miner.Files.service \
        org.freedesktop.Tracker1.Miner.Applications.service
-
-if HAVE_MAEMO
-# Userguides are done in the miner-fs process
-service_DATA += org.freedesktop.Tracker1.Miner.Userguides.service
-endif
 endif
 
 if HAVE_TRACKER_MINER_EVOLUTION
@@ -54,6 +49,10 @@ if HAVE_TRACKER_MINER_RSS
 service_DATA += org.freedesktop.Tracker1.Miner.RSS.service
 endif
 
+if HAVE_TRACKER_MINER_USER_GUIDES
+service_DATA += org.freedesktop.Tracker1.Miner.Userguides.service
+endif
+
 EXTRA_DIST = \
        $(service_in_files) \
        $(config_DATA) \
diff --git a/data/dbus/org.freedesktop.Tracker1.Miner.Userguides.service.in 
b/data/dbus/org.freedesktop.Tracker1.Miner.Userguides.service.in
index 423d865..23fc34b 100644
--- a/data/dbus/org.freedesktop.Tracker1.Miner.Userguides.service.in
+++ b/data/dbus/org.freedesktop.Tracker1.Miner.Userguides.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.freedesktop.Tracker1.Miner.Userguides
-Exec= libexecdir@/tracker-miner-fs
+Exec= libexecdir@/tracker-user-guides
diff --git a/data/miners/Makefile.am b/data/miners/Makefile.am
index 2e96ebc..18835fb 100644
--- a/data/miners/Makefile.am
+++ b/data/miners/Makefile.am
@@ -22,17 +22,16 @@ if HAVE_TRACKER_MINER_FS
 tracker_miners_DATA +=                                 \
        tracker-miner-extract.desktop                  \
        tracker-miner-files.desktop
-
-if HAVE_MAEMO
-# Userguides are done in the miner-fs process
-tracker_miners_DATA += tracker-miner-userguides.desktop
-endif
 endif
 
 if HAVE_TRACKER_MINER_APPS
 tracker_miners_DATA += tracker-miner-applications.desktop
 endif
 
+if HAVE_TRACKER_MINER_USER_GUIDES
+tracker_miners_DATA += tracker-miner-userguides.desktop
+endif
+
 if HAVE_TRACKER_MINER_EVOLUTION
 tracker_miners_DATA += tracker-miner-evolution.desktop
 endif
diff --git a/data/tracker-miner-user-guides.desktop.in.in b/data/tracker-miner-user-guides.desktop.in.in
new file mode 100644
index 0000000..4274e1a
--- /dev/null
+++ b/data/tracker-miner-user-guides.desktop.in.in
@@ -0,0 +1,19 @@
+[Desktop Entry]
+_Name=Tracker User Guides Miner
+_Comment=Crawls and processes user guides in shared areas
+Icon=
+Exec= libexecdir@/tracker-miner-user-guides
+Terminal=false
+Type=Application
+Categories=Utility;
+X-Meego-Priority=Late
+X-GNOME-Autostart-enabled=true
+X-KDE-autostart-after=panel
+X-KDE-StartupNotify=false
+X-KDE-UniqueApplet=true
+NoDisplay=true
+OnlyShowIn=GNOME;KDE;XFCE;X-MEEGO-HS;X-MEEGO-NB;X-IVI;Unity;
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=tracker
+X-GNOME-Bugzilla-Component=Miners
+X-GNOME-Bugzilla-Version= VERSION@
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 3171921..ace6864 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -1544,6 +1544,8 @@ tracker_file_notifier_start (TrackerFileNotifier *notifier)
 
                if (priv->pending_index_roots) {
                        crawl_directories_start (notifier);
+               } else {
+                       g_signal_emit (notifier, signals[FINISHED], 0);
                }
        }
 
diff --git a/src/miners/fs/Makefile.am b/src/miners/fs/Makefile.am
index b6bfa6e..fbb222c 100644
--- a/src/miners/fs/Makefile.am
+++ b/src/miners/fs/Makefile.am
@@ -49,12 +49,3 @@ tracker_miner_fs_LDADD =                               \
        $(top_builddir)/src/libtracker-common/libtracker-common.la \
        $(BUILD_LIBS)                                  \
        $(TRACKER_MINER_FS_LIBS)
-
-if HAVE_MAEMO
-tracker_miner_fs_SOURCES += \
-       tracker-miner-userguides.c \
-       tracker-miner-userguides.h
-tracker_miner_fs_CFLAGS = $(LIBXML2_CFLAGS)
-tracker_miner_fs_LDADD += $(LIBXML2_LIBS)
-endif
-
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index 45972b5..823710a 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -1038,12 +1038,6 @@ rebuild_filtered_lists (TrackerConfig *config)
                                g_message ("Path '%s' being removed from recursive directories "
                                           "list, as it also exists in single directories list",
                                           (gchar *) l->data);
-#ifdef HAVE_MAEMO
-                       } else if (g_str_has_prefix (l->data, "/usr/share/userguide/contents")) {
-                               g_message ("Path '%s' being removed from recursive directories "
-                                          "list, as it is handled by the userguide miner",
-                                          (gchar *) l->data);
-#endif /* HAVE_MAEMO */
                        } else {
                                checked_dirs = g_slist_prepend (checked_dirs, l->data);
                        }
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 2574d0f..2fc0d8e 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -44,7 +44,6 @@
 #include <libtracker-data/tracker-db-manager.h>
 
 #include "tracker-config.h"
-#include "tracker-miner-userguides.h"
 #include "tracker-miner-files.h"
 #include "tracker-miner-files-index.h"
 #include "tracker-writeback.h"
@@ -61,23 +60,7 @@
 
 #define SECONDS_PER_DAY 60 * 60 * 24
 
-#define OPTION_DISABLE_FILES "files"
-#define OPTION_DISABLE_USERGUIDES "userguides"
-
-typedef enum {
-       DISABLE_NONE,
-       DISABLE_FILES,
-#ifdef HAVE_MAEMO
-       DISABLE_USERGUIDES,
-#endif /* HAVE_MAEMO */
-} DisableOption;
-
-static gboolean miner_disable_option_arg_func (const gchar  *option_value,
-                                               const gchar  *value,
-                                               gpointer      data,
-                                               GError      **error);
-static void     miner_handle_next             (void);
-
+static void miner_handle_next (void);
 
 static GMainLoop *main_loop;
 static GSList *miners;
@@ -88,8 +71,6 @@ static gint verbosity = -1;
 static gint initial_sleep = -1;
 static gboolean no_daemon;
 static gchar *eligible;
-static GArray *disable_options = NULL;
-/* static DisableOption disable_option[] = { 0 }; */
 static gboolean version;
 static guint miners_timeout_id = 0;
 
@@ -112,15 +93,6 @@ static GOptionEntry entries[] = {
          G_OPTION_ARG_FILENAME, &eligible,
          N_("Checks if FILE is eligible for being mined based on configuration"),
          N_("FILE") },
-       { "disable-miner", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
-         G_OPTION_ARG_CALLBACK, miner_disable_option_arg_func,
-         N_("Disable miners started as part of this process, options include"
-            ": '" OPTION_DISABLE_FILES "'"
-#ifdef HAVE_MAEMO
-            ", '" OPTION_DISABLE_USERGUIDES "'"
-#endif /* HAVE_MAEMO */
-         ),
-         N_("MINER") },
        { "version", 'V', 0,
          G_OPTION_ARG_NONE, &version,
          N_("Displays version information"),
@@ -128,70 +100,6 @@ static GOptionEntry entries[] = {
        { NULL }
 };
 
-static gboolean
-miner_disable_option_arg_func (const gchar  *option_value,
-                               const gchar  *value,
-                               gpointer      data,
-                               GError      **error)
-{
-       DisableOption option;
-       gchar *value_casefold;
-       gboolean found = FALSE;
-       gint i;
-
-       if (!value || *value == '\0') {
-               /* Show help */
-#ifdef HAVE_MAEMO
-               g_set_error_literal (error,
-                                    G_OPTION_ERROR,
-                                    G_OPTION_ERROR_FAILED,
-                                    "A value is required, either "
-                                    "'" OPTION_DISABLE_FILES "', "
-                                    "'" OPTION_DISABLE_USERGUIDES "'");
-#else  /* HAVE_MAEMO */
-               g_set_error_literal (error,
-                                    G_OPTION_ERROR,
-                                    G_OPTION_ERROR_FAILED,
-                                    "A value is required, either "
-                                    "'" OPTION_DISABLE_FILES "'");
-#endif /* HAVE_MAEMO */
-               return FALSE;
-       }
-
-       value_casefold = g_utf8_casefold (value, -1);
-
-       if (strcmp (value_casefold, OPTION_DISABLE_FILES) == 0) {
-               option = DISABLE_FILES;
-#ifdef HAVE_MAEMO
-       } else if (strcmp (value_casefold, OPTION_DISABLE_USERGUIDES) == 0) {
-               option = DISABLE_USERGUIDES;
-#endif /* HAVE_MAEMO */
-       } else {
-               g_set_error (error,
-                            G_OPTION_ERROR,
-                            G_OPTION_ERROR_FAILED,
-                            "Miner '%s' is not recognized",
-                            value);
-               return FALSE;
-       }
-
-       g_free (value_casefold);
-
-       /* Check we didn't already disable this miner */
-       for (i = 0; i < disable_options->len; i++) {
-               if (g_array_index (disable_options, gint, i) == option) {
-                       found = TRUE;
-                       break;
-               }
-       }
-
-       if (!found) {
-               g_array_append_val (disable_options, option);
-       }
-
-       return TRUE;
-}
-
 static void
 sanity_check_option_values (TrackerConfig *config)
 {
@@ -344,59 +252,6 @@ should_crawl (TrackerConfig *config,
        }
 }
 
-static gboolean
-miner_disabled_check (void)
-{
-       gchar *name = NULL;
-       gchar *name_casefold;
-       gboolean disabled = FALSE;
-       gint i;
-
-       if (!disable_options || disable_options->len < 1) {
-               return FALSE;
-       }
-
-       g_object_get (current_miner->data, "name", &name, NULL);
-
-       if (!name || *name == '\0') {
-               g_warning ("Expected miner to have 'name' property set. "
-                          "Can not disable this particular miner as a result...");
-               return FALSE;
-       }
-
-       name_casefold = g_utf8_casefold (name, -1);
-
-       for (i = 0; i < disable_options->len && !disabled; i++) {
-               DisableOption o = (gint) g_array_index (disable_options, gint, i);
-
-               switch (o) {
-               case DISABLE_FILES:
-                       disabled = strcmp (name_casefold, OPTION_DISABLE_FILES) == 0;
-                       break;
-
-#ifdef HAVE_MAEMO
-               case DISABLE_USERGUIDES:
-                       disabled = strcmp (name_casefold, OPTION_DISABLE_USERGUIDES) == 0;
-                       break;
-#endif /* HAVE_MAEMO */
-
-               default:
-                       g_assert_not_reached ();
-                       break;
-               }
-       }
-
-       if (disabled) {
-               g_message ("Miner '%s' was disabled on the command line, moving to next...", name);
-               miner_handle_next ();
-       }
-
-       g_free (name_casefold);
-       g_free (name);
-
-       return disabled;
-}
-
 static void
 miner_handle_next (void)
 {
@@ -425,11 +280,6 @@ miner_handle_next (void)
                return;
        }
 
-       /* Check disabled miners */
-       if (miner_disabled_check ()) {
-               return;
-       }
-
        if (!tracker_miner_is_started (current_miner->data)) {
                g_message ("Starting next miner...");
                tracker_miner_start (current_miner->data);
@@ -836,9 +686,6 @@ main (gint argc, gchar *argv[])
        TrackerConfig *config;
        TrackerMiner *miner_files;
        TrackerMinerFilesIndex *miner_files_index;
-#ifdef HAVE_MAEMO
-       TrackerMiner *miner_userguides;
-#endif /* HAVE_MAEMO */
        GOptionContext *context;
        GError *error = NULL;
        gchar *log_filename = NULL;
@@ -863,7 +710,6 @@ main (gint argc, gchar *argv[])
         */
        context = g_option_context_new (_("- start the tracker indexer"));
 
-       disable_options = g_array_new (FALSE, FALSE, sizeof (gint));
        g_option_context_add_main_entries (context, entries, NULL);
        g_option_context_parse (context, &argc, &argv, &error);
        g_option_context_free (context);
@@ -871,19 +717,16 @@ main (gint argc, gchar *argv[])
        if (error) {
                g_printerr ("%s\n", error->message);
                g_error_free (error);
-               g_array_free (disable_options, TRUE);
                return EXIT_FAILURE;
        }
 
        if (version) {
                g_print ("\n" ABOUT "\n" LICENSE "\n");
-               g_array_free (disable_options, TRUE);
                return EXIT_SUCCESS;
        }
 
        if (eligible) {
                check_eligible ();
-               g_array_free (disable_options, TRUE);
                return EXIT_SUCCESS;
        }
 
@@ -927,7 +770,6 @@ main (gint argc, gchar *argv[])
                            error ? error->message : "unknown error");
                g_object_unref (config);
                tracker_log_shutdown ();
-               g_array_free (disable_options, TRUE);
                return EXIT_FAILURE;
        }
 
@@ -941,7 +783,6 @@ main (gint argc, gchar *argv[])
                g_object_unref (config);
                g_object_unref (miner_files);
                tracker_log_shutdown ();
-               g_array_free (disable_options, TRUE);
                return EXIT_FAILURE;
        }
 
@@ -952,25 +793,8 @@ main (gint argc, gchar *argv[])
                tracker_writeback_shutdown ();
                g_object_unref (config);
                tracker_log_shutdown ();
-               g_array_free (disable_options, TRUE);
-               return EXIT_FAILURE;
-       }
-
-#ifdef HAVE_MAEMO
-       /* Create miner for userguides */
-       miner_userguides = tracker_miner_userguides_new (&error);
-       if (!miner_userguides) {
-               g_critical ("Couldn't create new User Guides miner: '%s'",
-                           error ? error->message : "unknown error");
-               g_object_unref (miner_files);
-               g_object_unref (miner_files_index);
-               tracker_writeback_shutdown ();
-               g_object_unref (config);
-               tracker_log_shutdown ();
-               g_array_free (disable_options, TRUE);
                return EXIT_FAILURE;
        }
-#endif /* HAVE_MAEMO */
 
        /* Check if we should crawl and if we should force mtime
         * checking based on the config.
@@ -1009,26 +833,6 @@ main (gint argc, gchar *argv[])
                          G_CALLBACK (miner_finished_cb),
                          NULL);
 
-#ifdef HAVE_MAEMO
-       /* Configure userguides miner */
-       tracker_miner_fs_set_initial_crawling (TRACKER_MINER_FS (miner_userguides), do_crawling);
-
-       /* If a locale change was detected, always do mtime checks */
-       if (tracker_miner_userguides_detect_locale_changed (miner_userguides)) {
-               if (!do_mtime_checking)
-                       g_debug ("Forcing mtime check in userguides miner as locale change was detected");
-               tracker_miner_fs_set_mtime_checking (TRACKER_MINER_FS (miner_userguides), TRUE);
-       } else {
-               tracker_miner_fs_set_mtime_checking (TRACKER_MINER_FS (miner_userguides), do_mtime_checking);
-       }
-
-       g_signal_connect (miner_userguides, "finished",
-                         G_CALLBACK (miner_finished_cb),
-                         NULL);
-
-       miners = g_slist_prepend (miners, miner_userguides);
-#endif /* HAVE_MAEMO */
-
        miners = g_slist_prepend (miners, miner_files);
 
        miner_handle_first (config, do_mtime_checking);
@@ -1041,9 +845,6 @@ main (gint argc, gchar *argv[])
        store_available = store_is_available ();
 
        if (miners_timeout_id == 0 &&
-#ifdef HAVE_MAEMO
-           !miner_needs_check (miner_userguides, store_available) &&
-#endif
            !miner_needs_check (miner_files, store_available)) {
                tracker_db_manager_set_need_mtime_check (FALSE);
        }
@@ -1058,8 +859,6 @@ main (gint argc, gchar *argv[])
        tracker_writeback_shutdown ();
        tracker_log_shutdown ();
 
-       g_array_free (disable_options, TRUE);
-
        g_print ("\nOK\n\n");
 
        return EXIT_SUCCESS;
diff --git a/src/miners/user-guides/Makefile.am b/src/miners/user-guides/Makefile.am
new file mode 100644
index 0000000..5a79012
--- /dev/null
+++ b/src/miners/user-guides/Makefile.am
@@ -0,0 +1,22 @@
+AM_CPPFLAGS =                                          \
+       $(BUILD_CFLAGS)                                \
+       -I$(top_srcdir)/src                            \
+       -I$(top_builddir)/src                          \
+       -DSHAREDIR=\""$(datadir)"\"                    \
+       -DLOCALEDIR=\""$(localedir)"\"                 \
+       -DLIBEXEC_PATH=\""$(libexecdir)"\"             \
+       $(TRACKER_MINER_USER_GUIDES_CFLAGS)
+
+libexec_PROGRAMS = tracker-miner-user-guides
+
+tracker_miner_user_guides_SOURCES =                    \
+       tracker-main.c                                 \
+       tracker-miner-user-guides.c                    \
+       tracker-miner-user-guides.h
+
+tracker_miner_user_guides_LDADD =                      \
+       $(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la \
+       $(top_builddir)/src/libtracker-sparql-backend/libtracker-sparql- TRACKER_API_VERSION@.la \
+       $(top_builddir)/src/libtracker-common/libtracker-common.la \
+       $(BUILD_LIBS)                                  \
+       $(TRACKER_MINER_USER_GUIDES_LIBS)
diff --git a/src/miners/user-guides/tracker-main.c b/src/miners/user-guides/tracker-main.c
new file mode 100644
index 0000000..4f51c24
--- /dev/null
+++ b/src/miners/user-guides/tracker-main.c
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2014, Lanedo GmbH. <martyn lanedo com>
+
+ * This library 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 library 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 library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <locale.h>
+#include <signal.h>
+#include <errno.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include <libtracker-common/tracker-common.h>
+
+#include <libtracker-miner/tracker-miner.h>
+
+#include "tracker-miner-user-guides.h"
+
+#define ABOUT    \
+       "Tracker " PACKAGE_VERSION "\n"
+
+#define LICENSE          \
+       "This program is free software and comes without any warranty.\n" \
+       "It is licensed under version 2 or later of the General Public " \
+       "License which can be viewed at:\n" \
+       "\n" \
+       "  http://www.gnu.org/licenses/gpl.txt\n";
+
+static GMainLoop *main_loop;
+
+static gint verbosity = -1;
+static gboolean no_daemon;
+static gboolean version;
+
+static GOptionEntry entries[] = {
+       { "verbosity", 'v', 0,
+         G_OPTION_ARG_INT, &verbosity,
+         N_("Logging, 0 = errors only, "
+            "1 = minimal, 2 = detailed and 3 = debug (default=0)"),
+         NULL },
+       { "no-daemon", 'n', 0,
+         G_OPTION_ARG_NONE, &no_daemon,
+         N_("Runs until all applications are indexed and then exits"),
+         NULL },
+       { "version", 'V', 0,
+         G_OPTION_ARG_NONE, &version,
+         N_("Displays version information"),
+         NULL },
+       { NULL }
+};
+
+static void
+signal_handler (int signo)
+{
+       static gboolean in_loop = FALSE;
+
+       /* Die if we get re-entrant signals handler calls */
+       if (in_loop) {
+               _exit (EXIT_FAILURE);
+       }
+
+       switch (signo) {
+       case SIGTERM:
+       case SIGINT:
+               in_loop = TRUE;
+               if (main_loop != NULL) {
+                       g_main_loop_quit (main_loop);
+               } else {
+                       exit (0);
+               }
+               /* Fall through */
+       default:
+               if (g_strsignal (signo)) {
+                       g_print ("\n");
+                       g_print ("Received signal:%d->'%s'\n",
+                                signo,
+                                g_strsignal (signo));
+               }
+               break;
+       }
+}
+
+static void
+initialize_signal_handler (void)
+{
+#ifndef G_OS_WIN32
+       struct sigaction act;
+       sigset_t         empty_mask;
+
+       sigemptyset (&empty_mask);
+       act.sa_handler = signal_handler;
+       act.sa_mask    = empty_mask;
+       act.sa_flags   = 0;
+
+       sigaction (SIGTERM, &act, NULL);
+       sigaction (SIGINT,  &act, NULL);
+       sigaction (SIGHUP,  &act, NULL);
+#endif /* G_OS_WIN32 */
+}
+
+static void
+initialize_priority_and_scheduling (TrackerSchedIdle sched_idle,
+                                    gboolean         first_time_index)
+{
+       /* Set CPU priority */
+       if (sched_idle == TRACKER_SCHED_IDLE_ALWAYS ||
+           (sched_idle == TRACKER_SCHED_IDLE_FIRST_INDEX && first_time_index)) {
+               tracker_sched_idle ();
+       }
+
+       /* Set disk IO priority and scheduling */
+       tracker_ioprio_init ();
+
+       /* Set process priority:
+        * The nice() function uses attribute "warn_unused_result" and
+        * so complains if we do not check its returned value. But it
+        * seems that since glibc 2.2.4, nice() can return -1 on a
+        * successful call so we have to check value of errno too.
+        * Stupid...
+        */
+
+       g_message ("Setting priority nice level to 19");
+
+       errno = 0;
+       if (nice (19) == -1 && errno != 0) {
+               const gchar *str = g_strerror (errno);
+
+               g_message ("Couldn't set nice value to 19, %s",
+                          str ? str : "no error given");
+       }
+}
+
+static void
+miner_finished_cb (TrackerMinerFS *fs,
+                   gdouble         seconds_elapsed,
+                   guint           total_directories_found,
+                   guint           total_directories_ignored,
+                   guint           total_files_found,
+                   guint           total_files_ignored,
+                   gpointer        user_data)
+{
+       tracker_info ("Finished mining in seconds:%f, total directories:%d, total files:%d",
+                     seconds_elapsed,
+                     total_directories_found,
+                     total_files_found);
+
+       if (no_daemon && main_loop) {
+               g_main_loop_quit (main_loop);
+       }
+}
+
+static gboolean
+miner_start_cb (gpointer user_data)
+{
+       TrackerMiner *miner = user_data;
+
+       tracker_miner_start (miner);
+
+       return FALSE;
+}
+
+int
+main (gint argc, gchar *argv[])
+{
+       TrackerMiner *miner_user_guides;
+       GOptionContext *context;
+       GError *error = NULL;
+       gchar *log_filename = NULL;
+
+       main_loop = NULL;
+
+       setlocale (LC_ALL, "");
+
+       bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+       textdomain (GETTEXT_PACKAGE);
+
+       /* Set timezone info */
+       tzset ();
+
+       /* Translators: this messagge will apper immediately after the
+        * usage string - Usage: COMMAND <THIS_MESSAGE>
+        */
+       context = g_option_context_new (_("- start the user guides data miner"));
+
+       g_option_context_add_main_entries (context, entries, NULL);
+       g_option_context_parse (context, &argc, &argv, &error);
+       g_option_context_free (context);
+
+       if (error) {
+               g_printerr ("%s\n", error->message);
+               g_error_free (error);
+               return EXIT_FAILURE;
+       }
+
+       if (version) {
+               g_print ("\n" ABOUT "\n" LICENSE "\n");
+               return EXIT_SUCCESS;
+       }
+
+       initialize_signal_handler ();
+
+       tracker_log_init (verbosity, &log_filename);
+       if (log_filename) {
+               g_message ("Using log file:'%s'", log_filename);
+               g_free (log_filename);
+       }
+
+       /* This makes sure we don't steal all the system's resources */
+       initialize_priority_and_scheduling (TRACKER_SCHED_IDLE_ALWAYS, FALSE);
+
+       main_loop = g_main_loop_new (NULL, FALSE);
+
+       g_message ("Checking if we're running as a daemon:");
+       g_message ("  %s %s",
+                  no_daemon ? "No" : "Yes",
+                  no_daemon ? "(forced by command line)" : "");
+
+       /* Create miner for userguides */
+       miner_user_guides = tracker_miner_userguides_new (&error);
+       if (!miner_user_guides) {
+               g_critical ("Couldn't create new user guides miner, '%s'",
+                           error ? error->message : "unknown error");
+               tracker_log_shutdown ();
+               return EXIT_FAILURE;
+       }
+
+       tracker_miner_fs_set_mtime_checking (TRACKER_MINER_FS (miner_user_guides), TRUE);
+
+       g_signal_connect (miner_user_guides, "finished",
+                         G_CALLBACK (miner_finished_cb),
+                         NULL);
+
+       /* Go, go, go! */
+       g_idle_add (miner_start_cb, miner_user_guides);
+       g_main_loop_run (main_loop);
+
+       g_message ("Shutdown started");
+
+       g_main_loop_unref (main_loop);
+       g_object_unref (G_OBJECT (miner_user_guides));
+
+       tracker_log_shutdown ();
+
+       g_print ("\nOK\n\n");
+
+       return EXIT_SUCCESS;
+}
diff --git a/src/miners/fs/tracker-miner-userguides.c b/src/miners/user-guides/tracker-miner-user-guides.c
similarity index 97%
rename from src/miners/fs/tracker-miner-userguides.c
rename to src/miners/user-guides/tracker-miner-user-guides.c
index c30de76..3c513dc 100644
--- a/src/miners/fs/tracker-miner-userguides.c
+++ b/src/miners/user-guides/tracker-miner-user-guides.c
@@ -25,7 +25,7 @@
 
 #include <libtracker-common/tracker-common.h>
 
-#include "tracker-miner-userguides.h"
+#include "tracker-miner-user-guides.h"
 
 // FIXME: get this value from tracker conf
 #define MAX_EXTRACT_SIZE 1024 * 1024 // 1 MiB
@@ -122,7 +122,7 @@ miner_userguides_basedir_add_path (TrackerMinerFS *fs,
                return TRUE;
        }
 
-       g_message ("  No userguide found for locale:'%s' in this prefix", locale);
+       g_message ("  No user guide found for locale:'%s' in this prefix", locale);
 
        return FALSE;
 }
@@ -137,7 +137,7 @@ miner_userguides_basedir_add (TrackerMinerFS *fs,
        /* Do preliminary check on basedir */
        path = g_build_filename (basedir, "userguide", "contents", NULL);
        if (!g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
-               g_message ("  No userguides in prefix:'%s'", path);
+               g_message ("  No user guides in prefix:'%s'", path);
                g_free (path);
                return;
        }
@@ -179,14 +179,14 @@ miner_userguides_basedir_add (TrackerMinerFS *fs,
 
        /* Step 4 */
        if (!added) {
-               g_message ("  Locale has no userguide currently, defaulting to 'en'");
+               g_message ("  Locale has no user guide currently, defaulting to 'en'");
                path = g_build_filename (basedir, "userguide", "contents", "en", NULL);
                added = miner_userguides_basedir_add_path (fs, path, "en");
                g_free (path);
        }
 
        if (!added) {
-               g_message ("  Default locale 'en' has no userguide in this prefix");
+               g_message ("  Default locale 'en' has no user guide in this prefix");
        }
 
        g_free (locale);
@@ -194,7 +194,7 @@ miner_userguides_basedir_add (TrackerMinerFS *fs,
 
        if (!added) {
                /* Add $dir/userguide/contents */
-               g_message ("  MeeGoTouch is disabled, indexing all userguides...");
+               g_message ("  MeeGoTouch is disabled, indexing all user guides...");
                path = g_build_filename (basedir, "userguide", "contents", NULL);
                miner_userguides_basedir_add_path (fs, path, "");
                g_free (path);
@@ -207,7 +207,7 @@ miner_userguides_add_directories (TrackerMinerFS *fs)
        const gchar * const *xdg_dirs;
        gint i;
 
-       g_message ("Setting up userguides to iterate from XDG system directories");
+       g_message ("Setting up user guides to iterate from XDG system directories");
 
        /* Add all XDG system and local dirs */
        xdg_dirs = g_get_system_data_dirs ();
diff --git a/src/miners/fs/tracker-miner-userguides.h b/src/miners/user-guides/tracker-miner-user-guides.h
similarity index 100%
rename from src/miners/fs/tracker-miner-userguides.h
rename to src/miners/user-guides/tracker-miner-user-guides.h


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