tracker r2884 - in trunk: . src/tracker-applet src/tracker-indexer src/trackerd



Author: mr
Date: Thu Feb  5 17:37:33 2009
New Revision: 2884
URL: http://svn.gnome.org/viewvc/tracker?rev=2884&view=rev

Log:
	* src/tracker-applet/tracker-applet.c: (set_status_hint),
	(can_auto_pause), (index_state_changed): Added new state (PAUSED)
	and add to the tooltip when paused so it is known that it can also
	be because of heave disk IO OR low disk space. Also uncommented
	the code for the tooltip when we are paused due to low battery.

	* src/tracker-indexer/tracker-indexer.c: Make low disk space
	warning a g_message() instead. Also added a state_to_string()
	function so we can see state changes a bit more clearly in the
	logs.

	* src/trackerd/tracker-daemon.c:
	* src/trackerd/tracker-dbus.c:
	* src/trackerd/tracker-main.c: 
	* src/trackerd/tracker-monitor.c:
	* src/trackerd/tracker-processor.c:
	* src/trackerd/tracker-status.[ch]: Moved all indexer state
	monitoring (paused/continued) to the tracker-status module. Now
	when we use APIs like tracker_status_set_is_paused_manually() it
	will now: 
	  - Tell the indexer to pause/continue
	  - Signal the applet that we are in a new state
	  - Set the state internally.


Modified:
   trunk/ChangeLog
   trunk/src/tracker-applet/tracker-applet.c
   trunk/src/tracker-indexer/tracker-indexer.c
   trunk/src/trackerd/tracker-daemon.c
   trunk/src/trackerd/tracker-dbus.c
   trunk/src/trackerd/tracker-main.c
   trunk/src/trackerd/tracker-monitor.c
   trunk/src/trackerd/tracker-processor.c
   trunk/src/trackerd/tracker-status.c
   trunk/src/trackerd/tracker-status.h

Modified: trunk/src/tracker-applet/tracker-applet.c
==============================================================================
--- trunk/src/tracker-applet/tracker-applet.c	(original)
+++ trunk/src/tracker-applet/tracker-applet.c	Thu Feb  5 17:37:33 2009
@@ -99,6 +99,7 @@
 typedef enum {
 	INDEX_INITIALIZING,
 	INDEX_IDLE,
+	INDEX_PAUSED,
 	INDEX_BUSY,
 	INDEX_MERGING
 } IndexStateEnum;
@@ -281,6 +282,12 @@
                  */
 		index_status = _("Idle");
 		break;
+	case INDEX_PAUSED:
+		/* Translators: this will be a status hint like: 
+                 * Tracker: Idle 
+                 */
+		index_status = _("Paused");
+		break;
 	case INDEX_BUSY:
 		/* Translators: this will be a status hint like: 
                  * Tracker: Indexing 
@@ -293,29 +300,26 @@
                  */
 		index_status = _("Merging");
 		break;
-        default:
-                g_critical ("Unreachable status.");
 	}
 
 	if (priv->user_pause) {
 		/* Translators: this will be a status hint like: 
                  * Tracker: Initializing/Idle/Indexing/Merging (paused by user)
                  */
-		pause_status = _("paused by user");
+		pause_status = _("by user");
 	} else if (priv->auto_pause) {
 		/* Translators: this will be a status hint like: 
                  * Tracker: Initializing/Idle/Indexing/Merging (paused by system) 
                  */
-		pause_status = _("paused by system");
+		pause_status = _("by system");
 	} else {
 		switch (priv->pause_state) {
 		case PAUSE_INTERNAL:
-		/* Translators: this will be a status hint like: 
-                 * Tracker: Initializing/Idle/Indexing/Merging (paused by system)
-                 */
-			pause_status = _("paused by system");
+                        /* Translators: this will be a status hint like: 
+                         * Tracker: Initializing/Idle/Indexing/Merging (paused by system)
+                         */
+			pause_status = _("low disk space or heavy disk use");
 			break;
-#if 0
 		case PAUSE_BATTERY:
 			/* FIXME: We need to check if we are on the
 			 * battery first, this state purely means we
@@ -324,9 +328,8 @@
                         /* Translators: this will be a status hint like: 
                          * Tracker: Initializing/Idle/Indexing/Merging (paused by battery)
                          */
-			pause_status = _("paused by battery");
+			pause_status = _("low battery");
 			break;
-#endif
 		default:
 		case PAUSE_NONE:
 			pause_status = NULL;
@@ -412,8 +415,6 @@
 		return priv->index_state != INDEX_IDLE;
 	case AUTO_PAUSE_MERGING:
 		return priv->index_state == INDEX_MERGING;
-        default:
-                g_critical ("Unreachable state in auto pause.");
 	}
 
 	return TRUE;
@@ -1667,14 +1668,14 @@
 	if (is_manual_paused) {
 		stop_watching_events (icon);
 
+		paused = TRUE;
+
 		if (!priv->auto_pause) {
 			priv->user_pause = TRUE;
 		}
-
-		paused = TRUE;
 	} else if (is_battery_paused) {
-		priv->pause_state = PAUSE_BATTERY;
 		paused = TRUE;
+		priv->pause_state = PAUSE_BATTERY;
 	} else if (is_io_paused) {
 		paused = TRUE;
 		priv->pause_state = PAUSE_INTERNAL;
@@ -1687,6 +1688,8 @@
 		priv->index_state = INDEX_INITIALIZING;
 	} else if (g_ascii_strcasecmp (state, "Idle") == 0) {
 		priv->index_state = INDEX_IDLE;
+	} else if (g_ascii_strcasecmp (state, "Paused") == 0) {
+		priv->index_state = INDEX_PAUSED;
 	} else {
 		priv->index_state = INDEX_BUSY;
 		priv->animated = TRUE;

Modified: trunk/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.c	(original)
+++ trunk/src/tracker-indexer/tracker-indexer.c	Thu Feb  5 17:37:33 2009
@@ -751,7 +751,7 @@
 	}
 
 	if (((long long) st.f_bavail * 100 / st.f_blocks) <= limit) {
-		g_warning ("Disk space is low");
+		g_message ("Disk space is low");
 		return TRUE;
 	}
 
@@ -2605,6 +2605,34 @@
 	}
 }
 
+static gchar *
+state_to_string (TrackerIndexerState state)
+{
+	GString *s;
+
+	s = g_string_new ("");
+	
+	if (state & TRACKER_INDEXER_STATE_FLUSHING) {
+		s = g_string_append (s, "FLUSHING | ");
+	}
+	if (state & TRACKER_INDEXER_STATE_PAUSED) {
+		s = g_string_append (s, "PAUSED | ");
+	}
+	if (state & TRACKER_INDEXER_STATE_DISK_FULL) {
+		s = g_string_append (s, "DISK FULL | ");
+	}
+	if (state & TRACKER_INDEXER_STATE_STOPPED) {
+		s = g_string_append (s, "STOPPED | ");
+	}
+	if (state & TRACKER_INDEXER_STATE_LOW_BATT) {
+		s = g_string_append (s, "LOW BATTERY | ");
+	}
+
+	s->str[s->len - 3] = '\0';
+
+	return g_string_free (s, FALSE);
+}
+
 static void
 state_set_flags (TrackerIndexer      *indexer,
 		 TrackerIndexerState  state)
@@ -2624,14 +2652,29 @@
 	    (state & TRACKER_INDEXER_STATE_PAUSED ||
 	     state & TRACKER_INDEXER_STATE_DISK_FULL ||
 	     state & TRACKER_INDEXER_STATE_LOW_BATT)) {
-		const gchar *reason = NULL;
+		const gchar *reason;
+		gchar *old_state_str;
+		gchar *state_str;
 
 		if (state & TRACKER_INDEXER_STATE_DISK_FULL) {
 			reason = "Disk full";
 		} else if (state & TRACKER_INDEXER_STATE_LOW_BATT) {
 			reason = "Battery low";
+		} else {
+			reason = NULL;
 		}
 
+		old_state_str = state_to_string (old_state);
+		state_str = state_to_string (indexer->private->state);
+
+		g_message ("State change from '%s' --> '%s' (reason:'%s')",
+			   old_state_str,
+			   state_str,
+			   reason ? reason : "None");
+
+		g_free (state_str);
+		g_free (old_state_str);
+
 		g_signal_emit (indexer, signals[PAUSED], 0, reason);
 	}
 }
@@ -2653,6 +2696,19 @@
 	    (! (new_state & TRACKER_INDEXER_STATE_PAUSED)) &&
 	    (! (new_state & TRACKER_INDEXER_STATE_DISK_FULL)) &&
 	    (! (new_state & TRACKER_INDEXER_STATE_LOW_BATT))) {
+		gchar *old_state_str;
+		gchar *state_str;
+
+		old_state_str = state_to_string (old_state);
+		state_str = state_to_string (indexer->private->state);
+
+		g_message ("State change from '%s' --> '%s'",
+			   old_state_str,
+			   state_str);
+
+		g_free (state_str);
+		g_free (old_state_str);
+
 		g_signal_emit (indexer, signals[CONTINUED], 0);
 	}
 }

Modified: trunk/src/trackerd/tracker-daemon.c
==============================================================================
--- trunk/src/trackerd/tracker-daemon.c	(original)
+++ trunk/src/trackerd/tracker-daemon.c	Thu Feb  5 17:37:33 2009
@@ -59,17 +59,6 @@
 };
 
 static void tracker_daemon_finalize (GObject	 *object);
-static void indexer_pause_cb	    (DBusGProxy  *proxy,
-				     GError	 *error,
-				     gpointer	  user_data);
-static void indexer_continue_cb     (DBusGProxy  *proxy,
-				     GError	 *error,
-				     gpointer	  user_data);
-static void indexer_paused_cb	    (DBusGProxy  *proxy,
-				     const gchar *reason,
-				     gpointer	  user_data);
-static void indexer_continued_cb    (DBusGProxy  *proxy,
-				     gpointer	  user_data);
 
 static guint signals[LAST_SIGNAL] = {0};
 
@@ -240,21 +229,13 @@
 	TrackerDaemonPrivate *priv;
 	TrackerDBInterface   *iface;
 	TrackerDBResultSet   *result_set;
-	DBusGProxy	     *proxy;
+	DBusGProxy           *proxy;
 
 	priv = TRACKER_DAEMON_GET_PRIVATE (object);
 
 	proxy = tracker_dbus_indexer_get_proxy ();
 	priv->indexer_proxy = g_object_ref (proxy);
 
-	dbus_g_proxy_connect_signal (proxy, "Paused",
-				     G_CALLBACK (indexer_paused_cb),
-				     object,
-				     NULL);
-	dbus_g_proxy_connect_signal (proxy, "Continued",
-				     G_CALLBACK (indexer_continued_cb),
-				     object,
-				     NULL);
 	dbus_g_proxy_connect_signal (proxy, "Finished",
 				     G_CALLBACK (indexer_finished_cb),
 				     object,
@@ -281,14 +262,8 @@
 
 	clean_last_stats (priv);
 
-	dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Continued",
-					G_CALLBACK (indexer_continued_cb),
-					NULL);
-	dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Paused",
-					G_CALLBACK (indexer_paused_cb),
-					NULL);
 	dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Finished",
-					G_CALLBACK (indexer_continued_cb),
+					G_CALLBACK (indexer_finished_cb),
 					NULL);
 
 	g_object_unref (priv->indexer_proxy);
@@ -319,52 +294,6 @@
 	return object;
 }
 
-static void
-indexer_pause_cb (DBusGProxy *proxy,
-		  GError     *error,
-		  gpointer    user_data)
-{
-	if (error) {
-		g_message ("Could not pause the indexer, %s",
-			   error->message);
-	}
-}
-
-static void
-indexer_continue_cb (DBusGProxy *proxy,
-		     GError	*error,
-		     gpointer	 user_data)
-{
-	if (error) {
-		g_message ("Could not continue the indexer, %s",
-			   error->message);
-	}
-}
-
-static void
-indexer_paused_cb (DBusGProxy  *proxy,
-		   const gchar *reason,
-		   gpointer     user_data)
-{
-	g_message ("The indexer has paused (Reason: %s)", reason);
-
-	if (reason) {
-		if (strcmp (reason, "Disk full") == 0) {
-			tracker_status_set_and_signal (TRACKER_STATUS_DISK_FULL);
-		} else if (strcmp (reason, "Battery low") == 0) {
-			tracker_status_set_and_signal (TRACKER_STATUS_LOW_BATT);
-		}
-	}
-}
-
-static void
-indexer_continued_cb (DBusGProxy *proxy,
-		      gpointer	  user_data)
-{
-	g_message ("The indexer has continued");
-	tracker_status_set_and_signal (TRACKER_STATUS_INDEXING);
-}
-
 /*
  * Functions
  */
@@ -537,19 +466,6 @@
 		 * was the signal from our request.
 		 */
 		tracker_status_set_is_paused_manually (value);
-
-		if (value) {
-			org_freedesktop_Tracker_Indexer_pause_async (priv->indexer_proxy,
-								     indexer_pause_cb,
-								     NULL);
-		} else {
-			/* Don't continue if we are paused from IO */
-			if (!tracker_status_get_is_paused_for_io ()) {
-				org_freedesktop_Tracker_Indexer_continue_async (priv->indexer_proxy,
-										indexer_continue_cb,
-										NULL);
-			}
-		}
 	} else if (strcasecmp (option, "FastMerges") == 0) {
 		tracker_config_set_fast_merges (priv->config, value);
 		g_message ("Fast merges set to %d", value);

Modified: trunk/src/trackerd/tracker-dbus.c
==============================================================================
--- trunk/src/trackerd/tracker-dbus.c	(original)
+++ trunk/src/trackerd/tracker-dbus.c	Thu Feb  5 17:37:33 2009
@@ -180,7 +180,9 @@
 	proxy = user_data;
 
 	if (!tracker_status_get_is_paused_manually () &&
-	    !tracker_status_get_is_paused_for_io ()) {
+	    !tracker_status_get_is_paused_for_batt () && 
+	    !tracker_status_get_is_paused_for_io () && 
+	    !tracker_status_get_is_paused_for_space ()) {
 		org_freedesktop_Tracker_Indexer_continue_async (g_object_ref (proxy),
 								indexer_continue_async_cb,
 								NULL);
@@ -200,16 +202,20 @@
 dbus_request_new_cb (guint    request_id,
 		     gpointer user_data)
 {
-	DBusGProxy *proxy;
-	GError	   *error = NULL;
-	gboolean    set_paused = TRUE;
-	TrackerStatus status;
+	DBusGProxy    *proxy;
+	GError	      *error = NULL;
+	gboolean       set_paused = TRUE;
+	TrackerStatus  status;
 
 	status = tracker_status_get ();
 
-	if (status != TRACKER_STATUS_INDEXING &&
-	    status != TRACKER_STATUS_DISK_FULL &&
-	    status != TRACKER_STATUS_LOW_BATT) {
+	/* Don't pause if already paused */
+	if (status == TRACKER_STATUS_PAUSED) {
+		return;
+	}
+
+	/* Don't try to pause unless we are in particular states */
+	if (status != TRACKER_STATUS_INDEXING) {
 		return;
 	}
 
@@ -234,14 +240,6 @@
 					    g_object_ref (proxy),
 					    indexer_resume_destroy_notify_cb);
 
-	/* Third check if we are already paused, if we are there is
-	 * no need to tell the indexer.
-	 */
-	if (tracker_status_get_is_paused_manually ()) {
-		g_message ("Tracker is already manually paused, doing nothing");
-		return;
-	}
-
 	/* We really only do this because of the chance that we tell
 	 * the indexer to pause but don't get notified until the next
 	 * request. When we are notified of being paused,

Modified: trunk/src/trackerd/tracker-main.c
==============================================================================
--- trunk/src/trackerd/tracker-main.c	(original)
+++ trunk/src/trackerd/tracker-main.c	Thu Feb  5 17:37:33 2009
@@ -846,7 +846,7 @@
 {
 	TrackerMainPrivate *private;
 
-	if (!tracker_status_get_is_running ()) {
+	if (!tracker_status_get_is_ready ()) {
 		return FALSE;
 	}
 
@@ -1012,8 +1012,6 @@
 	initialize_directories ();
 
 	/* Initialize other subsystems */
-	tracker_status_init (config);
-
 	tracker_log_init (private->log_filename, tracker_config_get_verbosity (config));
 	g_print ("Starting log:\n  File:'%s'\n", private->log_filename);
 
@@ -1025,6 +1023,8 @@
 		return EXIT_FAILURE;
 	}
 
+	tracker_status_init (config);
+
 	tracker_module_config_init ();
 
 	tracker_turtle_init ();
@@ -1136,7 +1136,7 @@
 	/* Set our status as running, if this is FALSE, threads stop
 	 * doing what they do and shutdown.
 	 */
-	tracker_status_set_is_running (TRUE);
+	tracker_status_set_is_ready (TRUE);
 
 	if (!tracker_status_get_is_readonly ()) {
 		gint seconds;
@@ -1163,7 +1163,7 @@
 		backup_restore_on_crawling_finished (private->processor);
 	}
 
-	if (tracker_status_get_is_running ()) {
+	if (tracker_status_get_is_ready ()) {
 		private->main_loop = g_main_loop_new (NULL, FALSE);
 		g_main_loop_run (private->main_loop);
 	}
@@ -1250,7 +1250,7 @@
 
 	private = g_static_private_get (&private_key);
 
-	tracker_status_set_is_running (FALSE);
+	tracker_status_set_is_ready (FALSE);
 
 	tracker_processor_stop (private->processor);
 

Modified: trunk/src/trackerd/tracker-monitor.c
==============================================================================
--- trunk/src/trackerd/tracker-monitor.c	(original)
+++ trunk/src/trackerd/tracker-monitor.c	Thu Feb  5 17:37:33 2009
@@ -35,7 +35,6 @@
 
 #include "tracker-monitor.h"
 #include "tracker-dbus.h"
-#include "tracker-indexer-client.h"
 #include "tracker-marshal.h"
 #include "tracker-status.h"
 
@@ -580,28 +579,6 @@
 
 #ifdef PAUSE_ON_IO 
 
-static void
-indexer_pause_cb (DBusGProxy *proxy,
-		  GError     *error,
-		  gpointer    user_data)
-{
-	if (error) {
-		g_message ("Could not pause the indexer, %s",
-			   error->message);
-	}
-}
-
-static void
-indexer_continue_cb (DBusGProxy *proxy,
-		     GError	*error,
-		     gpointer	 user_data)
-{
-	if (error) {
-		g_message ("Could not continue the indexer, %s",
-			   error->message);
-	}
-}
-
 static gboolean
 unpause_cb (gpointer data)
 {
@@ -609,18 +586,12 @@
 
 	monitor = data;
 
-	monitor->private->unpause_timeout_id = 0;
-	tracker_status_set_is_paused_for_io (FALSE);
-
 	g_message ("Resuming indexing now we have stopped "
 		   "receiving monitor events for %d seconds",
 		   PAUSE_ON_IO_SECONDS);
 
-	if (!tracker_status_get_is_paused_manually ()) {
-		org_freedesktop_Tracker_Indexer_continue_async (tracker_dbus_indexer_get_proxy (),
-								indexer_continue_cb,
-								NULL);
-	}
+	monitor->private->unpause_timeout_id = 0;
+	tracker_status_set_is_paused_for_io (FALSE);
 
 	return FALSE;
 }
@@ -1087,10 +1058,6 @@
 			   "receiving monitor events");
 
 		tracker_status_set_is_paused_for_io (TRUE);
-
-		org_freedesktop_Tracker_Indexer_pause_async (tracker_dbus_indexer_get_proxy (),
-							     indexer_pause_cb,
-							     NULL);
 	}
 
 	monitor->private->unpause_timeout_id =
@@ -1397,10 +1364,6 @@
 			   "receiving monitor events");
 
 		tracker_status_set_is_paused_for_io (TRUE);
-
-		org_freedesktop_Tracker_Indexer_pause_async (tracker_dbus_indexer_get_proxy (),
-							     indexer_pause_cb,
-							     NULL);
 	}
 
 	monitor->private->unpause_timeout_id =

Modified: trunk/src/trackerd/tracker-processor.c
==============================================================================
--- trunk/src/trackerd/tracker-processor.c	(original)
+++ trunk/src/trackerd/tracker-processor.c	Thu Feb  5 17:37:33 2009
@@ -600,8 +600,7 @@
 	 * events but we still queue them ready to send when we are
 	 * unpaused.
 	 */
-	if (tracker_status_get_is_paused_manually () ||
-	    tracker_status_get_is_paused_for_io ()) {
+	if (tracker_status_get () == TRACKER_STATUS_PAUSED) {
 		g_message ("We are paused, sending nothing to the index until we are unpaused");
 		return TRUE;
 	}

Modified: trunk/src/trackerd/tracker-status.c
==============================================================================
--- trunk/src/trackerd/tracker-status.c	(original)
+++ trunk/src/trackerd/tracker-status.c	Thu Feb  5 17:37:33 2009
@@ -25,21 +25,37 @@
 #include "tracker-dbus.h"
 #include "tracker-daemon.h"
 #include "tracker-main.h"
+#include "tracker-indexer-client.h"
 
 typedef struct {
 	TrackerStatus  status;
+	TrackerStatus  status_before_paused;
 	gpointer       type_class;
 
 	TrackerConfig *config;
 
-	gboolean       is_running;
+	DBusGProxy    *indexer_proxy;
+
 	gboolean       is_readonly;
+	gboolean       is_ready;
+	gboolean       is_running;
 	gboolean       is_first_time_index;
 	gboolean       is_paused_manually;
+	gboolean       is_paused_for_batt;
 	gboolean       is_paused_for_io;
+	gboolean       is_paused_for_space;
+	gboolean       is_paused_for_unknown;
 	gboolean       in_merge;
 } TrackerStatusPrivate;
 
+static void indexer_continued_cb (DBusGProxy  *proxy,
+				  gpointer     user_data);
+static void indexer_paused_cb    (DBusGProxy  *proxy,
+				  const gchar *reason,
+				  gpointer     user_data);
+static void indexer_continue     (guint        seconds);
+static void indexer_pause        (void);
+
 static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
 
 static void
@@ -57,13 +73,225 @@
 		g_type_class_unref (private->type_class);
 	}
 
+	dbus_g_proxy_disconnect_signal (private->indexer_proxy, "Continued",
+					G_CALLBACK (indexer_continued_cb),
+					NULL);
+	dbus_g_proxy_disconnect_signal (private->indexer_proxy, "Paused",
+					G_CALLBACK (indexer_paused_cb),
+					NULL);
+	dbus_g_proxy_disconnect_signal (private->indexer_proxy, "Finished",
+					G_CALLBACK (indexer_continued_cb),
+					NULL);
+
+	g_object_unref (private->indexer_proxy);
+
 	g_free (private);
 }
 
+/*
+ * Handle Indexer pausing/continuation
+ */
+
+static void
+indexer_recheck (gboolean should_inform_indexer)
+{
+	TrackerStatusPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	/* Are we paused in any way? */
+	if (private->is_paused_manually ||
+	    private->is_paused_for_batt || 
+	    private->is_paused_for_io ||
+	    private->is_paused_for_space) {
+		/* We are paused, but our status is NOT paused? */
+		if (private->status != TRACKER_STATUS_PAUSED) {
+			private->status_before_paused = private->status;
+			private->status = TRACKER_STATUS_PAUSED;
+
+			if (G_LIKELY (should_inform_indexer)) {
+				indexer_pause ();
+			}
+		}
+	} else {
+		/* We are not paused, but our status is paused */
+		if (private->status == TRACKER_STATUS_PAUSED) {
+			private->status = private->status_before_paused;
+
+			if (G_LIKELY (should_inform_indexer)) {
+				indexer_continue (0);
+			}
+		}
+	}
+}
+
+static void
+indexer_paused_cb (DBusGProxy  *proxy,
+		   const gchar *reason,
+		   gpointer     user_data)
+{
+	TrackerStatusPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	/* NOTE: This is when we are told by the indexer, so we don't
+	 * know without checking with the status module if we sent
+	 * this or not - we certainly should not inform the indexer
+	 * again.
+	 */
+	g_message ("The indexer has paused (Reason: %s)", 
+		   reason ? reason : "None");
+
+	if (reason) {
+		if (strcmp (reason, "Disk full") == 0) {
+			private->is_paused_for_space = TRUE;
+			indexer_recheck (FALSE);
+			tracker_status_signal ();
+		} else if (strcmp (reason, "Battery low") == 0) {
+			private->is_paused_for_batt = TRUE;
+		} else {
+			private->is_paused_for_unknown = TRUE;
+		}
+	} else {
+		private->is_paused_for_unknown = TRUE;
+	}
+
+	indexer_recheck (FALSE);
+	tracker_status_signal ();
+}
+
+static void
+indexer_continued_cb (DBusGProxy *proxy,
+		      gpointer	  user_data)
+{
+	TrackerStatusPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	/* NOTE: This is when we are told by the indexer, so we don't
+	 * know without checking with the status module if we sent
+	 * this or not - we certainly should not inform the indexer
+	 * again.
+	 */
+	
+	g_message ("The indexer has continued");
+
+	/* So now the indexer has told us it has continued, we make
+	 * sure that none of the pause states are TRUE.
+	 */
+	private->is_paused_manually = FALSE;
+	private->is_paused_for_batt = FALSE;
+	private->is_paused_for_io = FALSE;
+	private->is_paused_for_space = FALSE;
+	private->is_paused_for_unknown = FALSE;
+
+	/* Set state to what it was before the pause. */
+	private->status = private->status_before_paused;
+
+	/* We signal this to listening apps, but we don't call
+	 * indexer_recheck() because we don't want to tell the indexer
+	 * what it just told us :)
+	 */
+	tracker_status_set_and_signal (private->status);
+}
+
+static void
+indexer_continue_cb (DBusGProxy *proxy,
+		     GError     *error,
+		     gpointer    user_data)
+{
+	if (error) {
+		g_message ("Could not continue the indexer, %s",
+			   error->message);
+
+		/* Return state to paused */
+		tracker_status_set_and_signal (TRACKER_STATUS_PAUSED);
+
+		/* FIXME: Should we set some sort of boolean here for:
+		 * [I couldn't resume because the indexer b0rked]? 
+		 * 
+		 * This is a potential deadlock, since we won't check
+		 * again until we get another dbus request or
+		 * something else sets this off. 
+		 *
+		 * -mr
+		 */
+	}
+}
+
+static void
+indexer_continue (guint seconds)
+{
+	TrackerStatusPrivate *private;
+
+	/* NOTE: We don't need private, but we do this to check we
+	 * are initialised before calling continue.
+	 */
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	if (seconds < 1) {
+		org_freedesktop_Tracker_Indexer_continue_async (private->indexer_proxy,
+								indexer_continue_cb,
+								NULL);
+	} else {
+		/* FIXME: Finish */
+	}
+}
+
+static void
+indexer_pause_cb (DBusGProxy *proxy,
+		  GError     *error,
+		  gpointer    user_data)
+{
+	if (error) {
+		TrackerStatusPrivate *private;
+		
+		private = g_static_private_get (&private_key);
+		g_return_if_fail (private != NULL);
+
+		g_message ("Could not pause the indexer, %s",
+			   error->message);
+
+		/* Return state to before paused */
+		tracker_status_set_and_signal (private->status_before_paused);
+
+		/* FIXME: Should we set some sort of boolean here for:
+		 * [I couldn't resume because the indexer b0rked]? 
+		 * 
+		 * This is a potential deadlock, since we won't check
+		 * again until we get another dbus request or
+		 * something else sets this off. 
+		 *
+		 * -mr
+		 */
+	}
+}
+
+static void
+indexer_pause (void)
+{
+	TrackerStatusPrivate *private;
+
+	/* NOTE: We don't need private, but we do this to check we
+	 * are initialised before calling continue.
+	 */
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	org_freedesktop_Tracker_Indexer_pause_async (private->indexer_proxy,
+						     indexer_pause_cb,
+						     NULL);
+}
+
 gboolean
 tracker_status_init (TrackerConfig *config)
 {
 	GType		      type;
+	DBusGProxy           *proxy;
 	TrackerStatusPrivate *private;
 
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);
@@ -78,6 +306,7 @@
 	private = g_new0 (TrackerStatusPrivate, 1);
 
 	private->status = TRACKER_STATUS_INITIALIZING;
+	private->status_before_paused = private->status;
 
 	/* Since we don't reference this enum anywhere, we do
 	 * it here to make sure it exists when we call
@@ -93,17 +322,34 @@
 
 	private->config = g_object_ref (config);
 
-	private->is_running = FALSE;
 	private->is_readonly = FALSE;
+	private->is_ready = FALSE;
+	private->is_running = FALSE;
 	private->is_first_time_index = FALSE;
 	private->is_paused_manually = FALSE;
+	private->is_paused_for_batt = FALSE;
 	private->is_paused_for_io = FALSE;
+	private->is_paused_for_space = FALSE;
+	private->is_paused_for_unknown = FALSE;
 	private->in_merge = FALSE;
 
 	g_static_private_set (&private_key,
 			      private,
 			      private_free);
 
+	/* Initialize the DBus indexer listening functions */
+	proxy = tracker_dbus_indexer_get_proxy ();
+	private->indexer_proxy = g_object_ref (proxy);
+
+	dbus_g_proxy_connect_signal (proxy, "Paused",
+				     G_CALLBACK (indexer_paused_cb),
+				     NULL,
+				     NULL);
+	dbus_g_proxy_connect_signal (proxy, "Continued",
+				     G_CALLBACK (indexer_continued_cb),
+				     NULL,
+				     NULL);
+	
 	return TRUE;
 }
 
@@ -138,6 +384,9 @@
 			{ TRACKER_STATUS_INDEXING,
 			  "TRACKER_STATUS_INDEXING",
 			  "Indexing" },
+			{ TRACKER_STATUS_PAUSED,
+			  "TRACKER_STATUS_PAUSED",
+			  "Paused" },
 			{ TRACKER_STATUS_PENDING,
 			  "TRACKER_STATUS_PENDING",
 			  "Pending" },
@@ -150,12 +399,6 @@
 			{ TRACKER_STATUS_SHUTDOWN,
 			  "TRACKER_STATUS_SHUTDOWN",
 			  "Shutdown" },
-			{ TRACKER_STATUS_DISK_FULL,
-			  "TRACKER_STATUS_DISK_FULL",
-			  "Disk full" },
-			{ TRACKER_STATUS_LOW_BATT,
-			  "TRACKER_STATUS_LOW_BATT",
-			  "Battery low" },
 			{ 0, NULL, NULL }
 		};
 
@@ -221,6 +464,7 @@
 {
 	TrackerStatusPrivate *private;
 	GObject		     *object;
+	gboolean              pause_for_io;
 
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
@@ -234,14 +478,23 @@
 		return;
 	}
 
+	/* NOTE: We have to combine pausing for IO, pausing for
+	 * space and pausing for unknown reasons here because we can't
+	 * change API yet.
+	 */
+	pause_for_io = 
+		private->is_paused_for_io || 
+		private->is_paused_for_space || 
+		private->is_paused_for_unknown;
+	
 	g_signal_emit_by_name (object,
 			       "index-state-change",
 			       tracker_status_to_string (private->status),
 			       private->is_first_time_index,
 			       private->in_merge,
 			       private->is_paused_manually,
-			       private->status == TRACKER_STATUS_LOW_BATT,
-			       private->is_paused_for_io,
+			       private->is_paused_for_batt,
+			       pause_for_io,
 			       !private->is_readonly);
 }
 
@@ -302,6 +555,39 @@
 }
 
 gboolean
+tracker_status_get_is_ready (void)
+{
+	TrackerStatusPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, FALSE);
+
+	return private->is_ready;
+}
+
+void
+tracker_status_set_is_ready (gboolean value)
+{
+	TrackerStatusPrivate *private;
+	gboolean	      emit;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	emit = private->is_ready != value;
+
+	if (!emit) {
+		return;
+	}
+
+	/* Set value */
+	private->is_ready = value;
+
+	/* Signal the status change */
+	tracker_status_signal ();
+}
+
+gboolean
 tracker_status_get_is_running (void)
 {
 	TrackerStatusPrivate *private;
@@ -420,17 +706,54 @@
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
-	emit = private->is_paused_manually != value;
+	emit  = TRUE;
+	emit |= private->is_paused_manually != value;
+	emit |= private->status != TRACKER_STATUS_PAUSED;
 
-	if (!emit) {
-		return;
+	/* Set value */
+	private->is_paused_manually = value;
+
+	/* Set indexer state and our state to paused or not */ 
+	indexer_recheck (TRUE);
+
+	if (emit) {
+		tracker_status_signal ();
 	}
+}
+
+gboolean
+tracker_status_get_is_paused_for_batt (void)
+{
+	TrackerStatusPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, FALSE);
+
+	return private->is_paused_for_batt;
+}
+
+void
+tracker_status_set_is_paused_for_batt (gboolean value)
+{
+	TrackerStatusPrivate *private;
+	gboolean	      emit;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	emit  = TRUE;
+	emit |= private->is_paused_for_batt != value;
+	emit |= private->status != TRACKER_STATUS_PAUSED;
 
 	/* Set value */
-	private->is_paused_manually = value;
+	private->is_paused_for_batt = value;
 
-	/* Signal the status change */
-	tracker_status_signal ();
+	/* Set indexer state and our state to paused or not */ 
+	indexer_recheck (TRUE);
+
+	if (emit) {
+		tracker_status_signal ();
+	}
 }
 
 gboolean
@@ -455,13 +778,56 @@
 
 	emit = private->is_paused_for_io != value;
 
-	if (!emit) {
-		return;
-	}
+	emit  = TRUE;
+	emit |= private->is_paused_for_batt != value;
+	emit |= private->status != TRACKER_STATUS_PAUSED;
 
 	/* Set value */
 	private->is_paused_for_io = value;
 
-	/* Signal the status change */
-	tracker_status_signal ();
+	/* Set indexer state and our state to paused or not */ 
+	indexer_recheck (TRUE);
+
+	/* Tell the world */
+	if (emit) {
+		tracker_status_signal ();
+	}
+}
+
+gboolean
+tracker_status_get_is_paused_for_space (void)
+{
+	TrackerStatusPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, FALSE);
+
+	return private->is_paused_for_space;
 }
+
+void
+tracker_status_set_is_paused_for_space (gboolean value)
+{
+	TrackerStatusPrivate *private;
+	gboolean	      emit;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	emit = private->is_paused_for_space != value;
+
+	emit  = TRUE;
+	emit |= private->is_paused_for_batt != value;
+	emit |= private->status != TRACKER_STATUS_PAUSED;
+
+	/* Set value */
+	private->is_paused_for_space = value;
+
+	/* Set indexer state and our state to paused or not */ 
+	indexer_recheck (TRUE);
+
+	if (emit) {
+		tracker_status_signal ();
+	}
+}
+

Modified: trunk/src/trackerd/tracker-status.h
==============================================================================
--- trunk/src/trackerd/tracker-status.h	(original)
+++ trunk/src/trackerd/tracker-status.h	Thu Feb  5 17:37:33 2009
@@ -34,12 +34,11 @@
 	TRACKER_STATUS_INITIALIZING,
 	TRACKER_STATUS_WATCHING,
 	TRACKER_STATUS_INDEXING,
+	TRACKER_STATUS_PAUSED,
 	TRACKER_STATUS_PENDING,
 	TRACKER_STATUS_OPTIMIZING,
 	TRACKER_STATUS_IDLE,
-	TRACKER_STATUS_SHUTDOWN,
-	TRACKER_STATUS_DISK_FULL,
-	TRACKER_STATUS_LOW_BATT
+	TRACKER_STATUS_SHUTDOWN
 } TrackerStatus;
 
 
@@ -57,6 +56,9 @@
 gboolean      tracker_status_get_is_readonly	     (void);
 void	      tracker_status_set_is_readonly	     (gboolean	     value);
 
+gboolean      tracker_status_get_is_ready	     (void);
+void	      tracker_status_set_is_ready	     (gboolean	     value);
+
 gboolean      tracker_status_get_is_running	     (void);
 void	      tracker_status_set_is_running	     (gboolean	     value);
 
@@ -69,9 +71,15 @@
 gboolean      tracker_status_get_is_paused_manually  (void);
 void	      tracker_status_set_is_paused_manually  (gboolean	     value);
 
+gboolean      tracker_status_get_is_paused_for_batt  (void);
+void	      tracker_status_set_is_paused_for_batt  (gboolean	     value);
+
 gboolean      tracker_status_get_is_paused_for_io    (void);
 void	      tracker_status_set_is_paused_for_io    (gboolean	     value);
 
+gboolean      tracker_status_get_is_paused_for_space (void);
+void	      tracker_status_set_is_paused_for_space (gboolean	     value);
+
 G_END_DECLS
 
 #endif /* __TRACKERD_STATUS_H__ */



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