[tracker/SCHED_IDLE: 2/3] tracker-miner-fs, tracker-extract: Add config option SchedIdle



commit 783bd7db57d38a299d261e5012a6fb46626138b3
Author: Martyn Russell <martyn lanedo com>
Date:   Fri Sep 23 12:56:14 2011 +0100

    tracker-miner-fs, tracker-extract: Add config option SchedIdle
    
    The config option allows 3 states, 'always', 'first-index' or 'never'. The
    default is 'first-index'.
    
    The tracker-preferences dialog now has 3 radio buttons explaining this too.
    
    This is a first attempt at fixing GB#659422

 .../org.freedesktop.Tracker.Extract.gschema.xml.in |   10 +
 ....freedesktop.Tracker.Miner.Files.gschema.xml.in |   10 +
 src/libtracker-common/tracker-enums.h              |    6 +
 src/miners/fs/tracker-config.c                     |   39 ++++-
 src/miners/fs/tracker-config.h                     |    3 +
 src/miners/fs/tracker-main.c                       |   16 ++-
 src/tracker-extract/tracker-config.c               |   38 ++++
 src/tracker-extract/tracker-config.h               |   21 +-
 src/tracker-extract/tracker-main.c                 |   24 ++-
 src/tracker-preferences/tracker-preferences.ui     |  217 +++++++++++--------
 src/tracker-preferences/tracker-preferences.vala   |  133 ++++++++----
 11 files changed, 363 insertions(+), 154 deletions(-)
---
diff --git a/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in b/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in
index a566834..ea20021 100644
--- a/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in
+++ b/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in
@@ -25,6 +25,16 @@ Boston, MA  02110-1301, USA.
       <_description>Log verbosity.</_description>
     </key>
 
+    <key name="sched-idle" enum="org.freedesktop.Tracker.TrackerSchedIdle">
+      <default>'first-index'</default>
+      <_summary>Scheduler priority when idle</_summary>
+      <_description>
+	The scheduler is the kernel component that decides which
+	runnable application will be executed by the CPU next. Each
+	application has an associated scheduling policy and priority.
+      </_description>
+    </key>
+
     <key name="max-bytes" type="i">
       <_summary>Max bytes to extract</_summary>
       <_description>Maximum number of UTF-8 bytes to extract.</_description>
diff --git a/data/gschemas/org.freedesktop.Tracker.Miner.Files.gschema.xml.in b/data/gschemas/org.freedesktop.Tracker.Miner.Files.gschema.xml.in
index dca8b98..27c8c3d 100644
--- a/data/gschemas/org.freedesktop.Tracker.Miner.Files.gschema.xml.in
+++ b/data/gschemas/org.freedesktop.Tracker.Miner.Files.gschema.xml.in
@@ -32,6 +32,16 @@ Boston, MA  02110-1301, USA.
       <default>15</default>
     </key>
 
+    <key name="sched-idle" enum="org.freedesktop.Tracker.TrackerSchedIdle">
+      <default>'first-index'</default>
+      <_summary>Scheduler priority when idle</_summary>
+      <_description>
+	The scheduler is the kernel component that decides which
+	runnable application will be executed by the CPU next. Each
+	application has an associated scheduling policy and priority.
+      </_description>
+    </key>
+
     <key name="throttle" type="i">
       <_summary>Throttle</_summary>
       <_description>Indexing speed, the higher the slower.</_description>
diff --git a/src/libtracker-common/tracker-enums.h b/src/libtracker-common/tracker-enums.h
index 9121d1a..3fd43d9 100644
--- a/src/libtracker-common/tracker-enums.h
+++ b/src/libtracker-common/tracker-enums.h
@@ -29,6 +29,12 @@ typedef enum {
 	TRACKER_VERBOSITY_DEBUG,
 } TrackerVerbosity;
 
+typedef enum {
+	TRACKER_SCHED_IDLE_ALWAYS,
+	TRACKER_SCHED_IDLE_FIRST_INDEX,
+	TRACKER_SCHED_IDLE_NEVER,
+} TrackerSchedIdle;
+
 G_END_DECLS
 
 #endif /* __TRACKER_ENUMS_H__ */
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index 9d55a42..5301ade 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -34,6 +34,7 @@
 
 /* Default values */
 #define DEFAULT_VERBOSITY                        0
+#define DEFAULT_SCHED_IDLE                       1
 #define DEFAULT_INITIAL_SLEEP                    15       /* 0->1000 */
 #define DEFAULT_ENABLE_MONITORS                  TRUE
 #define DEFAULT_THROTTLE                         0        /* 0->20 */
@@ -78,6 +79,7 @@ enum {
 
 	/* General */
 	PROP_VERBOSITY,
+	PROP_SCHED_IDLE,
 	PROP_INITIAL_SLEEP,
 
 	/* Monitors */
@@ -105,6 +107,7 @@ enum {
 
 static TrackerConfigMigrationEntry migration[] = {
 	{ G_TYPE_ENUM,    "General",   "Verbosity",                     "verbosity"                        },
+	{ G_TYPE_ENUM,    "General",   "SchedIdle",                     "sched-idle"                       },
 	{ G_TYPE_INT,     "General",   "InitialSleep",                  "initial-sleep"                    },
 	{ G_TYPE_BOOLEAN, "Monitors",  "EnableMonitors",                "enable-monitors"                  },
 	{ G_TYPE_INT,     "Indexing",  "Throttle",                      "throttle"                         },
@@ -143,7 +146,15 @@ tracker_config_class_init (TrackerConfigClass *klass)
 	                                                    "Log verbosity",
 	                                                    "Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)",
 	                                                    TRACKER_TYPE_VERBOSITY,
-	                                                    TRACKER_VERBOSITY_ERRORS,
+	                                                    DEFAULT_VERBOSITY,
+	                                                    G_PARAM_READWRITE));
+	g_object_class_install_property (object_class,
+	                                 PROP_SCHED_IDLE,
+	                                 g_param_spec_enum ("sched-idle",
+	                                                    "Scheduler priority when idle",
+	                                                    "Scheduler priority when idle (0=always, 1=first-index, 2=never)",
+	                                                    TRACKER_TYPE_SCHED_IDLE,
+	                                                    DEFAULT_SCHED_IDLE,
 	                                                    G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
 	                                 PROP_INITIAL_SLEEP,
@@ -310,6 +321,10 @@ config_set_property (GObject      *object,
 		tracker_config_set_verbosity (TRACKER_CONFIG (object),
 		                              g_value_get_enum (value));
 		break;
+	case PROP_SCHED_IDLE:
+		tracker_config_set_sched_idle (TRACKER_CONFIG (object),
+		                               g_value_get_enum (value));
+		break;
 	case PROP_INITIAL_SLEEP:
 		tracker_config_set_initial_sleep (TRACKER_CONFIG (object),
 		                                  g_value_get_int (value));
@@ -399,6 +414,9 @@ config_get_property (GObject    *object,
 	case PROP_VERBOSITY:
 		g_value_set_enum (value, tracker_config_get_verbosity (config));
 		break;
+	case PROP_SCHED_IDLE:
+		g_value_set_enum (value, tracker_config_get_sched_idle (config));
+		break;
 	case PROP_INITIAL_SLEEP:
 		g_value_set_int (value, tracker_config_get_initial_sleep (config));
 		break;
@@ -835,6 +853,14 @@ tracker_config_get_verbosity (TrackerConfig *config)
 }
 
 gint
+tracker_config_get_sched_idle (TrackerConfig *config)
+{
+	g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_SCHED_IDLE);
+
+	return g_settings_get_enum (G_SETTINGS (config), "sched-idle");
+}
+
+gint
 tracker_config_get_initial_sleep (TrackerConfig *config)
 {
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_INITIAL_SLEEP);
@@ -1018,6 +1044,17 @@ tracker_config_set_verbosity (TrackerConfig *config,
 }
 
 void
+tracker_config_set_sched_idle (TrackerConfig *config,
+                               gint           value)
+{
+
+	g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+	g_settings_set_enum (G_SETTINGS (config), "sched-idle", value);
+	g_object_notify (G_OBJECT (config), "sched-idle");
+}
+
+void
 tracker_config_set_initial_sleep (TrackerConfig *config,
                                   gint           value)
 {
diff --git a/src/miners/fs/tracker-config.h b/src/miners/fs/tracker-config.h
index 345d41d..fa1fdde 100644
--- a/src/miners/fs/tracker-config.h
+++ b/src/miners/fs/tracker-config.h
@@ -51,6 +51,7 @@ TrackerConfig *tracker_config_new                                  (void);
 gboolean       tracker_config_save                                 (TrackerConfig *config);
 
 gint           tracker_config_get_verbosity                        (TrackerConfig *config);
+gint           tracker_config_get_sched_idle                       (TrackerConfig *config);
 gint           tracker_config_get_initial_sleep                    (TrackerConfig *config);
 gboolean       tracker_config_get_enable_monitors                  (TrackerConfig *config);
 gint           tracker_config_get_throttle                         (TrackerConfig *config);
@@ -73,6 +74,8 @@ gboolean       tracker_config_get_enable_writeback                 (TrackerConfi
 
 void           tracker_config_set_verbosity                        (TrackerConfig *config,
                                                                     gint           value);
+void           tracker_config_set_sched_idle                       (TrackerConfig *config,
+                                                                    gint           value);
 void           tracker_config_set_initial_sleep                    (TrackerConfig *config,
                                                                     gint           value);
 void           tracker_config_set_enable_monitors                  (TrackerConfig *config,
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 775584e..7614a90 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -36,6 +36,7 @@
 #include <libtracker-common/tracker-ontologies.h>
 #include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-sched.h>
+#include <libtracker-common/tracker-enums.h>
 
 #include <libtracker-miner/tracker-miner.h>
 
@@ -104,6 +105,8 @@ sanity_check_option_values (TrackerConfig *config)
 	g_message ("General options:");
 	g_message ("  Verbosity  ............................  %d",
 	           tracker_config_get_verbosity (config));
+	g_message ("  Sched Idle  ...........................  %d",
+	           tracker_config_get_sched_idle (config));
 	g_message ("  Initial Sleep  ........................  %d",
 	           tracker_config_get_initial_sleep (config));
 
@@ -169,10 +172,14 @@ initialize_signal_handler (void)
 }
 
 static void
-initialize_priority_and_scheduling (void)
+initialize_priority_and_scheduling (TrackerSchedIdle sched_idle,
+                                    gboolean         first_time_index)
 {
 	/* Set CPU priority */
-	tracker_sched_idle ();
+	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 ();
@@ -185,6 +192,8 @@ initialize_priority_and_scheduling (void)
 	 * Stupid...
 	 */
 
+	g_message ("Setting priority nice level to 19");
+
 	errno = 0;
 	if (nice (19) == -1 && errno != 0) {
 		const gchar *str = g_strerror (errno);
@@ -733,7 +742,8 @@ main (gint argc, gchar *argv[])
 	sanity_check_option_values (config);
 
 	/* This makes sure we don't steal all the system's resources */
-	initialize_priority_and_scheduling ();
+	initialize_priority_and_scheduling (tracker_config_get_sched_idle (config),
+	                                    tracker_db_manager_get_first_index_done () == FALSE);
 
 	main_loop = g_main_loop_new (NULL, FALSE);
 
diff --git a/src/tracker-extract/tracker-config.c b/src/tracker-extract/tracker-config.c
index fe52279..c16059a 100644
--- a/src/tracker-extract/tracker-config.c
+++ b/src/tracker-extract/tracker-config.c
@@ -39,11 +39,13 @@ static void     config_constructed          (GObject       *object);
 enum {
 	PROP_0,
 	PROP_VERBOSITY,
+	PROP_SCHED_IDLE,
 	PROP_MAX_BYTES
 };
 
 static TrackerConfigMigrationEntry migration[] = {
 	{ G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
+	{ G_TYPE_ENUM, "General", "SchedIdle", "sched-idle" },
 	{ G_TYPE_INT, "General", "MaxBytes", "max-bytes" },
 	{ 0 }
 };
@@ -69,6 +71,14 @@ tracker_config_class_init (TrackerConfigClass *klass)
 	                                                    TRACKER_TYPE_VERBOSITY,
 	                                                    TRACKER_VERBOSITY_ERRORS,
 	                                                    G_PARAM_READWRITE));
+	g_object_class_install_property (object_class,
+	                                 PROP_SCHED_IDLE,
+	                                 g_param_spec_enum ("sched-idle",
+	                                                    "Scheduler priority when idle",
+	                                                    "Scheduler priority when idle (0=always, 1=first-index, 2=never)",
+	                                                    TRACKER_TYPE_SCHED_IDLE,
+	                                                    TRACKER_SCHED_IDLE_FIRST_INDEX,
+	                                                    G_PARAM_READWRITE));
 
 	g_object_class_install_property (object_class,
 	                                 PROP_MAX_BYTES,
@@ -97,6 +107,11 @@ config_set_property (GObject      *object,
 		                     g_value_get_enum (value));
 		break;
 
+	case PROP_SCHED_IDLE:
+		g_settings_set_enum (G_SETTINGS (object), "sched-idle",
+		                     g_value_get_enum (value));
+		break;
+
 	case PROP_MAX_BYTES:
 		g_settings_set_int (G_SETTINGS (object), "max-bytes",
 		                    g_value_get_int (value));
@@ -120,6 +135,11 @@ config_get_property (GObject    *object,
 		                  g_settings_get_enum (G_SETTINGS (object), "verbosity"));
 		break;
 
+	case PROP_SCHED_IDLE:
+		g_value_set_enum (value,
+		                  g_settings_get_enum (G_SETTINGS (object), "sched-idle"));
+		break;
+
 	case PROP_MAX_BYTES:
 		g_value_set_int (value,
 		                 g_settings_get_int (G_SETTINGS (object), "max-bytes"));
@@ -189,6 +209,24 @@ tracker_config_set_verbosity (TrackerConfig *config,
 	g_object_set (G_OBJECT (config), "verbosity", value, NULL);
 }
 
+gint
+tracker_config_get_sched_idle (TrackerConfig *config)
+{
+	g_return_val_if_fail (TRACKER_IS_CONFIG (config), TRACKER_SCHED_IDLE_FIRST_INDEX);
+
+	return g_settings_get_enum (G_SETTINGS (config), "sched-idle");
+}
+
+void
+tracker_config_set_sched_idle (TrackerConfig *config,
+                               gint           value)
+{
+
+	g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+	g_settings_set_enum (G_SETTINGS (config), "sched-idle", value);
+	g_object_notify (G_OBJECT (config), "sched-idle");
+}
 
 gint
 tracker_config_get_max_bytes (TrackerConfig *config)
diff --git a/src/tracker-extract/tracker-config.h b/src/tracker-extract/tracker-config.h
index 0d54bec..5ccc717 100644
--- a/src/tracker-extract/tracker-config.h
+++ b/src/tracker-extract/tracker-config.h
@@ -45,17 +45,18 @@ struct TrackerConfigClass {
 	GSettingsClass parent_class;
 };
 
-GType          tracker_config_get_type      (void) G_GNUC_CONST;
+GType          tracker_config_get_type       (void) G_GNUC_CONST;
 
-TrackerConfig *tracker_config_new           (void);
-
-gint           tracker_config_get_verbosity (TrackerConfig *config);
-gint           tracker_config_get_max_bytes (TrackerConfig *config);
-
-void           tracker_config_set_verbosity (TrackerConfig *config,
-                                             gint           value);
-void           tracker_config_set_max_bytes (TrackerConfig *config,
-                                             gint           value);
+TrackerConfig *tracker_config_new            (void);
+gint           tracker_config_get_verbosity  (TrackerConfig *config);
+gint           tracker_config_get_sched_idle (TrackerConfig *config);
+gint           tracker_config_get_max_bytes  (TrackerConfig *config);
+void           tracker_config_set_verbosity  (TrackerConfig *config,
+                                              gint           value);
+void           tracker_config_set_sched_idle (TrackerConfig *config,
+                                              gint           value);
+void           tracker_config_set_max_bytes  (TrackerConfig *config,
+                                              gint           value);
 
 G_END_DECLS
 
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index dc94675..4b2ea61 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -45,6 +45,8 @@
 #include <libtracker-common/tracker-locale.h>
 #include <libtracker-common/tracker-sched.h>
 
+#include <libtracker-data/tracker-db-manager.h>
+
 #include "tracker-albumart.h"
 #include "tracker-config.h"
 #include "tracker-main.h"
@@ -115,10 +117,14 @@ static GOptionEntry entries[] = {
 };
 
 static void
-initialize_priority_and_scheduling (void)
+initialize_priority_and_scheduling (TrackerSchedIdle sched_idle,
+                                    gboolean         first_time_index)
 {
 	/* Set CPU priority */
-	tracker_sched_idle ();
+	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 ();
@@ -130,7 +136,7 @@ initialize_priority_and_scheduling (void)
 	 * successful call so we have to check value of errno too.
 	 * Stupid...
 	 */
-	g_message ("Setting process priority");
+	g_message ("Setting priority nice level to 19");
 
 	if (nice (19) == -1) {
 		const gchar *str = g_strerror (errno);
@@ -244,6 +250,8 @@ sanity_check_option_values (TrackerConfig *config)
 	g_message ("General options:");
 	g_message ("  Verbosity  ............................  %d",
 	           tracker_config_get_verbosity (config));
+	g_message ("  Sched Idle  ...........................  %d",
+	           tracker_config_get_sched_idle (config));
 	g_message ("  Max bytes (per file)  .................  %d",
 	           tracker_config_get_max_bytes (config));
 }
@@ -255,7 +263,7 @@ tracker_main_get_config (void)
 }
 
 static int
-run_standalone (void)
+run_standalone (TrackerConfig *config)
 {
 	TrackerExtract *object;
 	GFile *file;
@@ -273,7 +281,8 @@ run_standalone (void)
 	tracker_albumart_init ();
 
 	/* This makes sure we don't steal all the system's resources */
-	initialize_priority_and_scheduling ();
+	initialize_priority_and_scheduling (tracker_config_get_sched_idle (config),
+	                                    tracker_db_manager_get_first_index_done () == FALSE);
 
 	file = g_file_new_for_commandline_arg (filename);
 	uri = g_file_get_uri (file);
@@ -380,7 +389,7 @@ main (int argc, char *argv[])
 
 	/* Set conditions when we use stand alone settings */
 	if (filename) {
-		return run_standalone ();
+		return run_standalone (config);
 	}
 
 	/* Initialize subsystems */
@@ -398,7 +407,8 @@ main (int argc, char *argv[])
 	sanity_check_option_values (config);
 
 	/* This makes sure we don't steal all the system's resources */
-	initialize_priority_and_scheduling ();
+	initialize_priority_and_scheduling (tracker_config_get_sched_idle (config),
+	                                    tracker_db_manager_get_first_index_done () == FALSE);
 	tracker_memory_setrlimits ();
 
 	if (disable_shutdown) {
diff --git a/src/tracker-preferences/tracker-preferences.ui b/src/tracker-preferences/tracker-preferences.ui
index af40c68..5fe9cb4 100644
--- a/src/tracker-preferences/tracker-preferences.ui
+++ b/src/tracker-preferences/tracker-preferences.ui
@@ -267,7 +267,6 @@
                           <object class="GtkVBox" id="vbox_indexing">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="spacing">6</property>
                             <child>
                               <object class="GtkCheckButton" id="checkbutton_enable_monitoring">
                                 <property name="label" translatable="yes">_Monitor file and directory changes</property>
@@ -314,7 +313,7 @@
                                 <property name="left_padding">12</property>
                                 <child>
                                   <object class="GtkCheckButton" id="checkbutton_enable_index_on_battery_first_time">
-                                    <property name="label" translatable="yes">Enable for _first time</property>
+                                    <property name="label" translatable="yes">Enable for _initial data population</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">False</property>
@@ -418,61 +417,22 @@
                             <property name="can_focus">False</property>
                             <property name="spacing">18</property>
                             <child>
-                              <object class="GtkVBox" id="vbox13">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <child>
-                                  <object class="GtkLabel" id="label_disk_space_limit">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="xalign">0</property>
-                                    <property name="yalign">0</property>
-                                    <property name="ypad">4</property>
-                                    <property name="label" translatable="yes">Stop indexing when _disk space is below:</property>
-                                    <property name="use_underline">True</property>
-                                  </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">0</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkHScale" id="hscale_disk_space_limit">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="adjustment">adjustment_disk_space_limit</property>
-                                    <property name="round_digits">0</property>
-                                    <property name="digits">0</property>
-                                    <signal name="format-value" handler="tracker_preferences_hscale_disk_space_limit_format_value_cb" swapped="no"/>
-                                  </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">1</property>
-                                  </packing>
-                                </child>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">True</property>
-                                <property name="position">0</property>
-                              </packing>
-                            </child>
-                            <child>
                               <object class="GtkVBox" id="vbox12">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
+                                <property name="spacing">6</property>
                                 <child>
-                                  <object class="GtkLabel" id="label_throttle">
+                                  <object class="GtkLabel" id="label13">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
+                                    <property name="tooltip_text" translatable="yes">The  scheduler  is  the kernel component that decides which runnable application will be executed by the CPU next.  Each application has an associated scheduling  policy and priority.
+
+This option allows you to make Tracker take a back seat and not eat up too much CPU time if you have other applications more deserving of it.</property>
                                     <property name="xalign">0</property>
-                                    <property name="yalign">0</property>
-                                    <property name="ypad">4</property>
-                                    <property name="label" translatable="yes">Indexing s_peed (faster consumes more resources):</property>
-                                    <property name="use_underline">True</property>
-                                    <property name="mnemonic_widget">hscale_throttle</property>
+                                    <property name="label" translatable="yes">Index content in the background:</property>
+                                    <property name="use_markup">True</property>
+                                    <property name="justify">fill</property>
+                                    <property name="wrap">True</property>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
@@ -481,60 +441,69 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkTable" id="table_throttle">
+                                  <object class="GtkVBox" id="vbox7">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
-                                    <property name="n_rows">2</property>
-                                    <property name="n_columns">2</property>
-                                    <property name="column_spacing">12</property>
-                                    <property name="row_spacing">4</property>
                                     <child>
-                                      <object class="GtkLabel" id="label_slower">
+                                      <object class="GtkRadioButton" id="radiobutton_sched_idle_always">
+                                        <property name="label" translatable="yes">O_nly when computer is not being used</property>
                                         <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="xalign">1</property>
-                                        <property name="label" translatable="yes">Faster</property>
-                                        <property name="justify">right</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="tooltip_markup">Indexing content will be &lt;b&gt;much slower&lt;/b&gt; but other applications will have priority.</property>
+                                        <property name="use_action_appearance">False</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="yalign">0.51999998092651367</property>
+                                        <property name="active">True</property>
+                                        <property name="draw_indicator">True</property>
                                       </object>
                                       <packing>
-                                        <property name="left_attach">1</property>
-                                        <property name="right_attach">2</property>
-                                        <property name="top_attach">1</property>
-                                        <property name="bottom_attach">2</property>
-                                        <property name="y_options"></property>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
                                       </packing>
                                     </child>
                                     <child>
-                                      <object class="GtkLabel" id="label_faster">
+                                      <object class="GtkRadioButton" id="radiobutton_sched_idle_first_index">
+                                        <property name="label" translatable="yes">_While other applications are running, except for initial data population</property>
                                         <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="xalign">0</property>
-                                        <property name="label" translatable="yes">Slower</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="tooltip_markup">Indexing content will be &lt;b&gt;much slower&lt;/b&gt; but other applications will have priority. This will only be the case on the &lt;b&gt;first index&lt;/b&gt; of your content after you start your computer from a new install</property>
+                                        <property name="use_action_appearance">False</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="active">True</property>
+                                        <property name="draw_indicator">True</property>
+                                        <property name="group">radiobutton_sched_idle_always</property>
                                       </object>
                                       <packing>
-                                        <property name="top_attach">1</property>
-                                        <property name="bottom_attach">2</property>
-                                        <property name="y_options"></property>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
                                       </packing>
                                     </child>
                                     <child>
-                                      <object class="GtkHScale" id="hscale_throttle">
+                                      <object class="GtkRadioButton" id="radiobutton_sched_idle_never">
+                                        <property name="label" translatable="yes">While _other applications are running</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">True</property>
-                                        <property name="adjustment">adjustment_throttle</property>
-                                        <property name="inverted">True</property>
-                                        <property name="digits">0</property>
-                                        <property name="draw_value">False</property>
-                                        <signal name="format-value" handler="tracker_preferences_hscale_throttle_format_value_cb" swapped="no"/>
+                                        <property name="receives_default">False</property>
+                                        <property name="tooltip_markup">Indexing content will be as &lt;b&gt;fast&lt;/b&gt; as possible but other applications may suffer and be slower as a result.</property>
+                                        <property name="use_action_appearance">False</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="active">True</property>
+                                        <property name="draw_indicator">True</property>
+                                        <property name="group">radiobutton_sched_idle_always</property>
                                       </object>
                                       <packing>
-                                        <property name="right_attach">2</property>
-                                        <property name="y_options">GTK_FILL</property>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">2</property>
                                       </packing>
                                     </child>
                                   </object>
                                   <packing>
-                                    <property name="expand">False</property>
+                                    <property name="expand">True</property>
                                     <property name="fill">True</property>
                                     <property name="position">1</property>
                                   </packing>
@@ -543,24 +512,22 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">True</property>
-                                <property name="position">1</property>
+                                <property name="position">0</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkVBox" id="vbox9">
+                              <object class="GtkVBox" id="vbox13">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                                 <child>
-                                  <object class="GtkLabel" id="label_device_drop_threshold1">
+                                  <object class="GtkLabel" id="label_disk_space_limit">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
                                     <property name="xalign">0</property>
                                     <property name="yalign">0</property>
-                                    <property name="xpad">3</property>
                                     <property name="ypad">4</property>
-                                    <property name="label" translatable="yes">Days before deleting removable devices / files since last mounted:</property>
+                                    <property name="label" translatable="yes">Stop indexing when _disk space is below:</property>
                                     <property name="use_underline">True</property>
-                                    <property name="mnemonic_widget">hscale_drop_device_threshold</property>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
@@ -569,13 +536,13 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkHScale" id="hscale_drop_device_threshold">
+                                  <object class="GtkHScale" id="hscale_disk_space_limit">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="adjustment">adjustment_drop_device_threshold</property>
+                                    <property name="adjustment">adjustment_disk_space_limit</property>
                                     <property name="round_digits">0</property>
                                     <property name="digits">0</property>
-                                    <signal name="format-value" handler="tracker_preferences_hscale_drop_device_threshold_format_value_cb" swapped="no"/>
+                                    <signal name="format-value" handler="tracker_preferences_hscale_disk_space_limit_format_value_cb" swapped="no"/>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
@@ -587,7 +554,7 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">True</property>
-                                <property name="position">2</property>
+                                <property name="position">1</property>
                               </packing>
                             </child>
                           </object>
@@ -612,6 +579,74 @@
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkFrame" id="frame2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <child>
+                      <object class="GtkAlignment" id="alignment5">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="top_padding">6</property>
+                        <property name="left_padding">12</property>
+                        <child>
+                          <object class="GtkVBox" id="vbox9">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <child>
+                              <object class="GtkLabel" id="label_device_drop_threshold1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="yalign">0</property>
+                                <property name="xpad">3</property>
+                                <property name="ypad">4</property>
+                                <property name="label" translatable="yes">Days before deleting removable devices / files since last mounted:</property>
+                                <property name="use_underline">True</property>
+                                <property name="mnemonic_widget">hscale_drop_device_threshold</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkHScale" id="hscale_drop_device_threshold">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="adjustment">adjustment_drop_device_threshold</property>
+                                <property name="round_digits">0</property>
+                                <property name="digits">0</property>
+                                <signal name="format-value" handler="tracker_preferences_hscale_drop_device_threshold_format_value_cb" swapped="no"/>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel" id="label7">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">&lt;b&gt;Garbage Collection&lt;/b&gt;</property>
+                        <property name="use_markup">True</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
                   <placeholder/>
                 </child>
               </object>
diff --git a/src/tracker-preferences/tracker-preferences.vala b/src/tracker-preferences/tracker-preferences.vala
index 06bc6f7..a208b44 100644
--- a/src/tracker-preferences/tracker-preferences.vala
+++ b/src/tracker-preferences/tracker-preferences.vala
@@ -29,7 +29,8 @@ extern static const string UIDIR;
 extern static const string SRCDIR;
 
 public class Tracker.Preferences {
-	private GLib.Settings settings = null;
+	private GLib.Settings settings_miner_fs = null;
+	private GLib.Settings settings_extract = null;
 
 	private const string UI_FILE = "tracker-preferences.ui";
 	private const string HOME_STRING = "$HOME";
@@ -43,7 +44,10 @@ public class Tracker.Preferences {
 	private CheckButton checkbutton_index_removable_media;
 	private CheckButton checkbutton_index_optical_discs;
 	private Scale hscale_disk_space_limit;
-	private Scale hscale_throttle;
+	//private Scale hscale_throttle;
+	private RadioButton radiobutton_sched_idle_always;
+	private RadioButton radiobutton_sched_idle_first_index;
+	private RadioButton radiobutton_sched_idle_never;
 	private Scale hscale_drop_device_threshold;
 	private ListStore liststore_index;
 	private ListStore liststore_ignored_directories;
@@ -69,12 +73,16 @@ public class Tracker.Preferences {
 
 		HOME_STRING_EVALUATED = dir_from_config (HOME_STRING);
 
-		//config = new Config ();
-		settings = new GLib.Settings ("org.freedesktop.Tracker.Miner.Files");
+		settings_miner_fs = new GLib.Settings ("org.freedesktop.Tracker.Miner.Files");
+		settings_extract = new GLib.Settings ("org.freedesktop.Tracker.Extract");
 
 		// Change notification for any key in the schema
-		settings.changed.connect ((key) => {
-		      print ("Key '%s' changed\n", key);
+		settings_miner_fs.changed.connect ((key) => {
+		      print ("tracker-miner-fs: Key '%s' changed\n", key);
+		});
+
+		settings_extract.changed.connect ((key) => {
+		      print ("tracker-extract: Key '%s' changed\n", key);
 		});
 	}
 
@@ -113,7 +121,10 @@ public class Tracker.Preferences {
 		checkbutton_index_optical_discs = builder.get_object ("checkbutton_index_optical_discs") as CheckButton;
 		checkbutton_index_optical_discs.set_sensitive (checkbutton_index_removable_media.active);
 		hscale_disk_space_limit = builder.get_object ("hscale_disk_space_limit") as Scale;
-		hscale_throttle = builder.get_object ("hscale_throttle") as Scale;
+		//hscale_throttle = builder.get_object ("hscale_throttle") as Scale;
+		radiobutton_sched_idle_always = builder.get_object ("radiobutton_sched_idle_always") as RadioButton;
+		radiobutton_sched_idle_first_index = builder.get_object ("radiobutton_sched_idle_first_index") as RadioButton;
+		radiobutton_sched_idle_never = builder.get_object ("radiobutton_sched_idle_never") as RadioButton;
 		hscale_drop_device_threshold = builder.get_object ("hscale_drop_device_threshold") as Scale;
 		togglebutton_home = builder.get_object ("togglebutton_home") as ToggleButton;
 		togglebutton_desktop = builder.get_object ("togglebutton_desktop") as ToggleButton;
@@ -142,23 +153,40 @@ public class Tracker.Preferences {
 		liststore_ignored_directories_with_content = builder.get_object ("liststore_ignored_directories_with_content") as ListStore;
 
 		// Set initial values
-		checkbutton_enable_index_on_battery.active = settings.get_boolean ("index-on-battery");
+		checkbutton_enable_index_on_battery.active = settings_miner_fs.get_boolean ("index-on-battery");
 		checkbutton_enable_index_on_battery_first_time.set_sensitive (!checkbutton_enable_index_on_battery.active);
-		checkbutton_enable_index_on_battery_first_time.active = settings.get_boolean ("index-on-battery-first-time");
+		checkbutton_enable_index_on_battery_first_time.active = settings_miner_fs.get_boolean ("index-on-battery-first-time");
 		spinbutton_delay.set_increments (1, 1);
-		spinbutton_delay.value = (double) settings.get_int ("initial-sleep");
-		checkbutton_enable_monitoring.active = settings.get_boolean ("enable-monitors");
-		checkbutton_index_removable_media.active = settings.get_boolean ("index-removable-devices");
-		checkbutton_index_optical_discs.active = settings.get_boolean ("index-optical-discs");
-		hscale_disk_space_limit.set_value ((double) settings.get_int ("low-disk-space-limit"));
-		hscale_throttle.set_value ((double) settings.get_int ("throttle"));
-		hscale_drop_device_threshold.set_value ((double) settings.get_int ("removable-days-threshold"));
-
-		model_populate (liststore_index, settings.get_strv ("index-recursive-directories"), true, true);
-		model_populate (liststore_index, settings.get_strv ("index-single-directories"), true, false);
-		model_populate (liststore_ignored_directories, settings.get_strv ("ignored-directories"), false, false);
-		model_populate (liststore_ignored_files, settings.get_strv ("ignored-files"), false, false);
-		model_populate (liststore_ignored_directories_with_content, settings.get_strv ("ignored-directories-with-content"), false, false);
+		spinbutton_delay.value = (double) settings_miner_fs.get_int ("initial-sleep");
+		checkbutton_enable_monitoring.active = settings_miner_fs.get_boolean ("enable-monitors");
+		checkbutton_index_removable_media.active = settings_miner_fs.get_boolean ("index-removable-devices");
+		checkbutton_index_optical_discs.active = settings_miner_fs.get_boolean ("index-optical-discs");
+		hscale_disk_space_limit.set_value ((double) settings_miner_fs.get_int ("low-disk-space-limit"));
+		//thscale_throttle.set_value ((double) settings_miner_fs.get_int ("throttle"));
+		hscale_drop_device_threshold.set_value ((double) settings_miner_fs.get_int ("removable-days-threshold"));
+
+		// What do we do here if extract/miner-fs are different, we
+		// could use inconsistent states for radiobuttons, but instead
+		// we're going to just assume miner-fs is the lead here and
+		// overwrite the extract config with anything we change here.
+		int sched_idle = settings_miner_fs.get_enum ("sched-idle");
+
+		if (sched_idle == 0) {
+			radiobutton_sched_idle_always.active = true;
+		} else if (sched_idle == 1) {
+			radiobutton_sched_idle_first_index.active = true;
+		} else if (sched_idle == 2) {
+			radiobutton_sched_idle_never.active = true;
+		} else {
+			// If broken value set, use default.
+			radiobutton_sched_idle_first_index.active = true;
+		}
+
+		model_populate (liststore_index, settings_miner_fs.get_strv ("index-recursive-directories"), true, true);
+		model_populate (liststore_index, settings_miner_fs.get_strv ("index-single-directories"), true, false);
+		model_populate (liststore_ignored_directories, settings_miner_fs.get_strv ("ignored-directories"), false, false);
+		model_populate (liststore_ignored_files, settings_miner_fs.get_strv ("ignored-files"), false, false);
+		model_populate (liststore_ignored_directories_with_content, settings_miner_fs.get_strv ("ignored-directories-with-content"), false, false);
 
 		togglebutton_home.active = model_contains (liststore_index, HOME_STRING_EVALUATED);
 		togglebutton_desktop.active = model_contains (liststore_index, "&DESKTOP");
@@ -208,19 +236,40 @@ public class Tracker.Preferences {
 		case ResponseType.APPLY:
 			debug ("Converting directories for storage");
 
-			settings.set_strv ("index-single-directories", model_to_strv (liststore_index, true, false));
-			settings.set_strv ("index-recursive-directories", model_to_strv (liststore_index, true, true));
-			settings.set_strv ("ignored-directories", model_to_strv (liststore_ignored_directories, false, false));
-			settings.set_strv ("ignored-files", model_to_strv (liststore_ignored_files, false, false));
-			settings.set_strv ("ignored-directories-with-content", model_to_strv (liststore_ignored_directories_with_content, false, false));
+			settings_miner_fs.set_strv ("index-single-directories", model_to_strv (liststore_index, true, false));
+			settings_miner_fs.set_strv ("index-recursive-directories", model_to_strv (liststore_index, true, true));
+			settings_miner_fs.set_strv ("ignored-directories", model_to_strv (liststore_ignored_directories, false, false));
+			settings_miner_fs.set_strv ("ignored-files", model_to_strv (liststore_ignored_files, false, false));
+			settings_miner_fs.set_strv ("ignored-directories-with-content", model_to_strv (liststore_ignored_directories_with_content, false, false));
+
+			settings_miner_fs.set_int ("low-disk-space-limit", (int) hscale_disk_space_limit.get_value ());
+			//settings_miner_fs.set_int ("throttle", (int) hscale_throttle.get_value ());
+			settings_miner_fs.set_int ("removable-days-threshold", (int) hscale_drop_device_threshold.get_value ());
+
+			int sched_idle;
+
+			if (radiobutton_sched_idle_always.active) {
+				sched_idle = 0;
+			} else if (radiobutton_sched_idle_first_index.active) {
+				sched_idle = 1;
+			} else if (radiobutton_sched_idle_never.active) {
+				sched_idle = 2;
+			} else {
+				assert_not_reached ();
+			}
 
-			settings.set_int ("low-disk-space-limit", (int) hscale_disk_space_limit.get_value ());
-			settings.set_int ("throttle", (int) hscale_throttle.get_value ());
-			settings.set_int ("removable-days-threshold", (int) hscale_drop_device_threshold.get_value ());
+			// What do we do here if extract/miner-fs are different, we
+			// could use inconsistent states for radiobuttons, but instead
+			// we're going to just assume miner-fs is the lead here and
+			// overwrite the extract config with anything we change here.
+			settings_miner_fs.set_enum ("sched-idle", sched_idle);
+			settings_extract.set_enum ("sched-idle", sched_idle);
 
 			debug ("Saving settings...");
-			settings.apply ();
-			debug ("Done");
+			settings_miner_fs.apply ();
+			debug ("  tracker-miner-fs: Done");
+			settings_extract.apply ();
+			debug ("  tracker-extract: Done");
 
 			// TODO: restart the Application and Files miner (no idea how to cleanly do this atm)
 			return;
@@ -234,34 +283,34 @@ public class Tracker.Preferences {
 
 	[CCode (instance_pos = -1)]
 	public void spinbutton_delay_value_changed_cb (SpinButton source) {
-		settings.set_int ("initial-sleep", source.get_value_as_int ());
+		settings_miner_fs.set_int ("initial-sleep", source.get_value_as_int ());
 	}
 
 	[CCode (instance_pos = -1)]
 	public void checkbutton_enable_monitoring_toggled_cb (CheckButton source) {
-		settings.set_boolean ("enable-monitors", source.active);
+		settings_miner_fs.set_boolean ("enable-monitors", source.active);
 	}
 
 	[CCode (instance_pos = -1)]
 	public void checkbutton_enable_index_on_battery_toggled_cb (CheckButton source) {
-		settings.set_boolean ("index-on-battery", source.active);
+		settings_miner_fs.set_boolean ("index-on-battery", source.active);
 		checkbutton_enable_index_on_battery_first_time.set_sensitive (!source.active);
 	}
 
 	[CCode (instance_pos = -1)]
 	public void checkbutton_enable_index_on_battery_first_time_toggled_cb (CheckButton source) {
-		settings.set_boolean ("index-on-battery-first-time", source.active);
+		settings_miner_fs.set_boolean ("index-on-battery-first-time", source.active);
 	}
 
 	[CCode (instance_pos = -1)]
 	public void checkbutton_index_removable_media_toggled_cb (CheckButton source) {
-		settings.set_boolean ("index-removable-devices", source.active);
+		settings_miner_fs.set_boolean ("index-removable-devices", source.active);
 		checkbutton_index_optical_discs.set_sensitive (source.active);
 	}
 
 	[CCode (instance_pos = -1)]
 	public void checkbutton_index_optical_discs_toggled_cb (CheckButton source) {
-		settings.set_boolean ("index-optical-discs", source.active);
+		settings_miner_fs.set_boolean ("index-optical-discs", source.active);
 	}
 
 	[CCode (instance_pos = -1)]
@@ -273,10 +322,10 @@ public class Tracker.Preferences {
 		return _("%d%%").printf ((int) value);
 	}
 
-	[CCode (instance_pos = -1)]
-	public string hscale_throttle_format_value_cb (Scale source, double value) {
-		return _("%d/20").printf ((int) value);
-	}
+	//[CCode (instance_pos = -1)]
+	//public string hscale_throttle_format_value_cb (Scale source, double value) {
+	//	return _("%d/20").printf ((int) value);
+	//}
 
 	[CCode (instance_pos = -1)]
 	public string hscale_drop_device_threshold_format_value_cb (Scale source, double value) {



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