tracker r3090 - in trunk: . src/libtracker-db src/tracker-applet src/trackerd



Author: mr
Date: Mon Mar 16 16:41:06 2009
New Revision: 3090
URL: http://svn.gnome.org/viewvc/tracker?rev=3090&view=rev

Log:
	* src/libtracker-db/tracker-db-dbus.c: Don't check each string for
	utf8 validity in tracker_dbus_query_result_to_ptr_array() since we
	call tracker_dbus_slist_to_strv() which does this for us anyway.

	* src/tracker-applet/tracker-applet.c: Fixed crasher here and
	added a refresh button so the user can request updates more
	frequently than they are signalled to us.

	* src/trackerd/tracker-daemon.c: Fixed the
	"service-statistics-updated" signal here so we actually send the
	GType that is expected based on the dbus XML introspection file.


Modified:
   trunk/ChangeLog
   trunk/src/libtracker-db/tracker-db-dbus.c
   trunk/src/tracker-applet/tracker-applet.c
   trunk/src/trackerd/tracker-daemon.c

Modified: trunk/src/libtracker-db/tracker-db-dbus.c
==============================================================================
--- trunk/src/libtracker-db/tracker-db-dbus.c	(original)
+++ trunk/src/libtracker-db/tracker-db-dbus.c	Mon Mar 16 16:41:06 2009
@@ -433,7 +433,7 @@
 		for (i = 0; i < columns; i++) {
 			GValue	transform = { 0, };
 			GValue	value = { 0, };
-			gchar  *str;
+			gchar  *str = NULL;
 
 			g_value_init (&transform, G_TYPE_STRING);
 
@@ -441,15 +441,9 @@
 
 			if (g_value_transform (&value, &transform)) {
 				str = g_value_dup_string (&transform);
+			}
 
-				if (!str) {
-					str = g_strdup ("");
-				} else if (!g_utf8_validate (str, -1, NULL)) {
-					g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
-					g_free (str);
-					str = g_strdup ("");
-				}
-			} else {
+			if (!str) {
 				str = g_strdup ("");
 			}
 
@@ -545,7 +539,6 @@
 			g_value_unset (&transform);
 		}
 
-
 		if (add) {
 			rows_add (rows, key, row);
 		}
@@ -553,7 +546,7 @@
 		valid = tracker_db_result_set_iter_next (result_set);
 	}
 
-	result = g_ptr_array_new();
+	result = g_ptr_array_new ();
 
 	rows_migrate (rows, result);
 	rows_destroy (rows);

Modified: trunk/src/tracker-applet/tracker-applet.c
==============================================================================
--- trunk/src/tracker-applet/tracker-applet.c	(original)
+++ trunk/src/tracker-applet/tracker-applet.c	Mon Mar 16 16:41:06 2009
@@ -67,6 +67,8 @@
 #define DBUS_PATH_TRACKER	"/org/freedesktop/tracker"
 #define DBUS_INTERFACE_TRACKER	"org.freedesktop.Tracker"
 
+#define TRACKER_TYPE_G_STRV_ARRAY  (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV))
+
 #define DISABLE_DEBUG
 
 #ifdef G_HAVE_ISO_VARARGS
@@ -194,19 +196,21 @@
 };
 
 static Stat_Info stat_info[13] = {
-	{"Files", NULL, NULL},
-	{"Folders", NULL, NULL},
-	{"Documents", NULL, NULL},
-	{"Images", NULL, NULL},
-	{"Music", NULL, NULL},
-	{"Videos", NULL, NULL},
-	{"Text", NULL, NULL},
-	{"Development", NULL, NULL},
-	{"Other", NULL, NULL},
-	{"Applications", NULL, NULL},
-	{"Conversations", NULL, NULL},
-	{"Emails", NULL, NULL},
-	{NULL, NULL, NULL},
+	{ "Files", NULL, NULL },
+	{ "Folders", NULL, NULL },
+	{ "Documents", NULL, NULL },
+	{ "Images", NULL, NULL },
+	{ "Music", NULL, NULL},
+	{ "Videos", NULL, NULL },
+	{ "Text", NULL, NULL },
+	{ "Development", NULL, NULL },
+	{ "Other", NULL, NULL },
+	{ "Applications", NULL, NULL },
+
+        /* These are particular supported apps */
+	{ "GaimConversations", NULL, NULL },
+	{ "EvolutionEmails", NULL, NULL },
+	{ NULL, NULL, NULL },
 };
 
 static gboolean disable_daemon_start;
@@ -1131,7 +1135,6 @@
 	g_signal_connect (G_OBJECT (dialog), "response",
 			  G_CALLBACK (restart_tracker), icon);
 	gtk_widget_show (dialog);
-
 }
 
 static void
@@ -1167,83 +1170,52 @@
 }
 
 static void
-stat_window_free (GtkWidget *widget,
-		  gint	     arg,
-		  gpointer   data)
-{
-	TrayIcon *icon;
-	TrayIconPrivate *priv;
-
-	icon = data;
-	priv = TRAY_ICON_GET_PRIVATE (icon);
-
-	priv->stat_window_active = FALSE;
-
-	gtk_widget_destroy (widget);
-}
-
-static gchar *
-get_stat_value (gchar	    ***stat_array,
-		const gchar   *stat)
-{
-	gchar **array;
-	gint i = 0;
-
-	while (stat_array[i][0]) {
-		array = stat_array[i];
-
-		if (array[0] && strcasecmp (stat, array[0]) == 0) {
-			return array[1];
-		}
-
-		i++;
-	}
-
-	return NULL;
-}
-
-static void
-update_stats (GPtrArray *array,
+update_stats (GPtrArray *new_stats,
 	      GError	*error,
 	      gpointer	 data)
 {
 	TrayIcon *icon;
 	TrayIconPrivate *priv;
-	gchar ***pdata;
-	guint i;
+	gint i, j;
 
 	icon = data;
 	priv = TRAY_ICON_GET_PRIVATE (icon);
 
+        priv->stat_request_pending = FALSE;
+
 	if (error) {
 		g_warning ("Could not update statistics, %s",
 			   error->message);
 		g_error_free (error);
-		priv->stat_request_pending = FALSE;
-		return;
-	}
-
-	if (!array) {
-		return;
-	}
-
-	i = array->len;
-
-	if (i < 1 || !priv->stat_window_active) {
-		g_ptr_array_free (array, TRUE);
 		return;
 	}
 
-	pdata = (gchar ***) array->pdata;
-
-	for (i = 0; i < 12; i++) {
-		gtk_label_set_text (GTK_LABEL (stat_info[i].stat_label),
-				    get_stat_value (pdata, stat_info[i].name));
-	}
+        if (!new_stats) {
+                return;
+        }
 
-	g_ptr_array_free (array, TRUE);
+        if (new_stats->len < 1 || !priv->stat_window_active) {
+                return;
+        }
 
-	priv->stat_request_pending = FALSE;
+        for (i = 0; i < new_stats->len; i++) {
+                const gchar **p;
+                const gchar  *service_type = NULL;
+                
+                p = g_ptr_array_index (new_stats, i);
+                
+                service_type = p[1];
+		
+                if (!service_type) {
+                        continue;
+                }
+
+                for (j = 0; j < G_N_ELEMENTS (stat_info); j++) {
+                        if (g_strcmp0 (stat_info[j].name, service_type) == 0) {
+                                gtk_label_set_text (GTK_LABEL (stat_info[j].stat_label), p[0]);
+                        }
+                }
+        }
 }
 
 static void
@@ -1265,6 +1237,28 @@
 }
 
 static void
+statistics_dialog_response (GtkWidget *widget,
+                            gint       arg,
+                            gpointer   data)
+{
+	TrayIcon *icon;
+	TrayIconPrivate *priv;
+
+	icon = data;
+	priv = TRAY_ICON_GET_PRIVATE (icon);
+
+        /* Refresh stats */
+        if (arg == GTK_RESPONSE_APPLY) {
+                refresh_stats (icon);
+                return;
+        }
+
+	priv->stat_window_active = FALSE;
+
+	gtk_widget_destroy (widget);
+}
+
+static void
 statistics_menu_activated (GtkMenuItem *item,
 			   gpointer	data)
 {
@@ -1272,80 +1266,82 @@
 	TrayIconPrivate *priv;
 	GtkWidget *dialog;
 	GtkWidget *table;
-	GtkWidget *title_label;
-	GtkWidget *label_to_add;
-	GtkWidget *dialog_hbox;
-	GtkWidget *info_icon;
+	GtkWidget *hbox;
+	GtkWidget *image;
+	GtkWidget *label;
 	gint i;
 
 	icon = data;
 	priv = TRAY_ICON_GET_PRIVATE (icon);
 
-	dialog = gtk_dialog_new_with_buttons (_("Statistics"),
+	dialog = gtk_dialog_new_with_buttons (_("Tracker Statistics"),
 					      NULL,
-					      GTK_DIALOG_NO_SEPARATOR
-					      |
+					      GTK_DIALOG_NO_SEPARATOR |
 					      GTK_DIALOG_DESTROY_WITH_PARENT,
+					      GTK_STOCK_REFRESH,
+					      GTK_RESPONSE_APPLY,
 					      GTK_STOCK_CLOSE,
 					      GTK_RESPONSE_CLOSE,
 					      NULL);
 
 	gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+        gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 18);
+
 	gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
 	gtk_window_set_icon_name (GTK_WINDOW (dialog), "gtk-info");
-	gtk_window_set_type_hint (GTK_WINDOW (dialog),
-				  GDK_WINDOW_TYPE_HINT_DIALOG);
-	gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+	gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+	g_signal_connect (G_OBJECT (dialog), "response",
+			  G_CALLBACK (statistics_dialog_response),
+			  icon);
 
-	table = gtk_table_new (13, 2, TRUE);
-	gtk_table_set_row_spacings (GTK_TABLE (table), 4);
+        /* Containers */
+	hbox = gtk_hbox_new (FALSE, 12);
+	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), hbox);
+
+        /* Icon */
+	image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO,
+                                          GTK_ICON_SIZE_DIALOG);
+	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+	gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
+
+        /* Stats */
+	table = gtk_table_new (G_N_ELEMENTS (stat_info), 2, TRUE);
+	gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, TRUE, 0);
+
+	gtk_table_set_row_spacings (GTK_TABLE (table), 6);
 	gtk_table_set_col_spacings (GTK_TABLE (table), 65);
-	gtk_container_set_border_width (GTK_CONTAINER (table), 8);
 
-	title_label = gtk_label_new (NULL);
-	gtk_label_set_markup (GTK_LABEL (title_label),
-			      _("<span weight=\"bold\" size=\"larger\">Index statistics</span>"));
-	gtk_misc_set_alignment (GTK_MISC (title_label), 0, 0);
-	gtk_table_attach_defaults (GTK_TABLE (table), title_label, 0, 2, 0,
-				   1);
-
-	for (i = 0; i < 12; i++) {
-		label_to_add = gtk_label_new (stat_info[i].label);
-
-		gtk_label_set_selectable (GTK_LABEL (label_to_add), TRUE);
-		gtk_misc_set_alignment (GTK_MISC (label_to_add), 0, 0);
-		gtk_table_attach_defaults (GTK_TABLE (table), label_to_add, 0,
-					   1, i + 1, i + 2);
-
-		stat_info[i].stat_label = gtk_label_new ("");
-
-		gtk_label_set_selectable (GTK_LABEL (stat_info[i].stat_label),
-					  TRUE);
-		gtk_misc_set_alignment (GTK_MISC (stat_info[i].stat_label), 0,
-					0);
-		gtk_table_attach_defaults (GTK_TABLE (table),
-					   stat_info[i].stat_label, 1, 2,
-					   i + 1, i + 2);
+	for (i = 0; i < G_N_ELEMENTS (stat_info); i++) {
+                if (stat_info[i].label == NULL) {
+                        continue;
+                }
+                
+		label = gtk_label_new (stat_info[i].label);
+		gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+
+		gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
+		gtk_table_attach_defaults (GTK_TABLE (table), 
+                                           label, 
+                                           0, 1, i + 1, i + 2);
+
+                if (g_strcmp0 (stat_info[i].name, "Files") != 0) {
+                        stat_info[i].stat_label = gtk_label_new ("0");
+
+                        gtk_label_set_selectable (GTK_LABEL (stat_info[i].stat_label), TRUE);
+                        gtk_misc_set_alignment (GTK_MISC (stat_info[i].stat_label), 0, 0);
+                        gtk_table_attach_defaults (GTK_TABLE (table),
+                                                   stat_info[i].stat_label,
+                                                   1, 2,
+                                                   i + 1, i + 2);
+                }
 	}
 
+        /* Set flags and get stats */
 	priv->stat_window_active = TRUE;
-
 	refresh_stats (icon);
 
-	dialog_hbox = gtk_hbox_new (FALSE, 12);
-	info_icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO,
-					      GTK_ICON_SIZE_DIALOG);
-	gtk_misc_set_alignment (GTK_MISC (info_icon), 0, 0);
-	gtk_container_add (GTK_CONTAINER (dialog_hbox), info_icon);
-	gtk_container_add (GTK_CONTAINER (dialog_hbox), table);
-
-	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
-			   dialog_hbox);
-
-	g_signal_connect (G_OBJECT (dialog), "response",
-			  G_CALLBACK (stat_window_free),
-			  icon);
-
+        /* Show */
 	gtk_widget_show_all (dialog);
 }
 
@@ -1598,12 +1594,18 @@
 	set_icon (priv);
 	set_status_hint (icon);
 
-	refresh_stats (icon);
-
 	stop_watching_events (icon);
 }
 
 static void
+index_service_stats_updated (DBusGProxy *proxy,
+                             GPtrArray  *new_stats,
+                             TrayIcon   *icon)
+{
+        update_stats (new_stats, NULL, icon);
+}
+
+static void
 index_state_changed (DBusGProxy  *proxy,
 		     const gchar *state,
 		     gboolean	  initial_index,
@@ -1659,6 +1661,24 @@
 					"%s\n",
 					initial_index_1,
 					initial_index_2);
+
+                /* Reset stats if shown */
+                if (priv->stat_window_active) {
+                        gint i;
+                        
+                        for (i = 0; i < G_N_ELEMENTS (stat_info); i++) {
+                                if (!stat_info[i].name ||
+                                    !stat_info[i].stat_label) {
+                                        continue;
+                                }
+                                
+                                if (g_strcmp0 (stat_info[i].name, "Files") == 0) {
+                                        continue;
+                                }
+                                
+                                gtk_label_set_text (GTK_LABEL (stat_info[i].stat_label), "0");
+                        }
+                }
 	}
 
 	priv->animated = FALSE;
@@ -1735,15 +1755,12 @@
 	priv->email_indexing = strcmp (service, "Emails") == 0;
 
 	debug ("Indexed %d/%d, seconds elapsed:%f\n",
-		 items_done,
-		 items_total,
-		 seconds_elapsed);
+               items_done,
+               items_total,
+               seconds_elapsed);
 
 	set_status_hint (icon);
 	set_icon (priv);
-
-	/* Update stat window if its active */
-	refresh_stats (icon);
 }
 
 static void
@@ -1796,7 +1813,7 @@
 		priv->indexer_stopped = TRUE;
 
 		debug ("The Tracker daemon has exited (%s)\n",
-			 priv->reindex ? "reindexing" : "not reindexing");
+                       priv->reindex ? "reindexing" : "not reindexing");
 
 		if (priv->reindex) {
 			GError *error = NULL;
@@ -1885,6 +1902,11 @@
 				 G_TYPE_DOUBLE,
 				 G_TYPE_INVALID);
 
+	dbus_g_proxy_add_signal (priv->tracker->proxy,
+				 "ServiceStatisticsUpdated",
+				 TRACKER_TYPE_G_STRV_ARRAY,
+				 G_TYPE_INVALID);
+
 	dbus_g_proxy_connect_signal (priv->tracker->proxy,
 				     "IndexStateChange",
 				     G_CALLBACK (index_state_changed),
@@ -1903,6 +1925,12 @@
 				     icon,
 				     NULL);
 
+	dbus_g_proxy_connect_signal (priv->tracker->proxy,
+				     "ServiceStatisticsUpdated",
+				     G_CALLBACK (index_service_stats_updated),
+				     icon,
+				     NULL);
+
 	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
 	dbus_proxy = dbus_g_proxy_new_for_name (connection,
 						DBUS_SERVICE_DBUS,

Modified: trunk/src/trackerd/tracker-daemon.c
==============================================================================
--- trunk/src/trackerd/tracker-daemon.c	(original)
+++ trunk/src/trackerd/tracker-daemon.c	Mon Mar 16 16:41:06 2009
@@ -43,6 +43,8 @@
 
 #define TRACKER_DAEMON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_DAEMON, TrackerDaemonPrivate))
 
+#define TRACKER_TYPE_G_STRV_ARRAY  (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV))
+
 typedef struct {
 	TrackerConfig	 *config;
 	TrackerProcessor *processor;
@@ -58,7 +60,7 @@
 	LAST_SIGNAL
 };
 
-static void tracker_daemon_finalize (GObject	 *object);
+static void tracker_daemon_finalize (GObject *object);
 
 static guint signals[LAST_SIGNAL] = {0};
 
@@ -120,10 +122,10 @@
 			      G_SIGNAL_RUN_LAST,
 			      0,
 			      NULL, NULL,
-			      tracker_marshal_VOID__BOXED,
+			      g_cclosure_marshal_VOID__POINTER,
 			      G_TYPE_NONE,
 			      1,
-			      G_TYPE_STRV);
+			      TRACKER_TYPE_G_STRV_ARRAY);
 
 	g_type_class_add_private (object_class, sizeof (TrackerDaemonPrivate));
 }
@@ -595,19 +597,15 @@
 	g_message ("Checking for statistics changes and signalling clients...");
 
 	/* Situation #1 */
-	if (!new_stats) {
+	if (!new_stats || new_stats->len < 1) {
 		g_message ("  No new statistics, doing nothing");
 		return;
 	}
 
 	if (g_hash_table_size (priv->last_stats) < 1) {
-		GStrv strv;
 		gint i;
 
 		/* Situation #2 */
-		strv = g_new0 (gchar*, new_stats->len + 1);
-		strv[new_stats->len] = NULL;
-
 		g_message ("  No previous statistics");
 
 		for (i = 0; i < new_stats->len; i++) {
@@ -624,28 +622,22 @@
 				continue;
 			}
 
-			g_hash_table_insert (priv->last_stats, 
-					     g_strdup (service_type), 
-					     GINT_TO_POINTER (new_count));
-
-			/* GStrv for signal emission */
 			g_message ("  Adding '%s' with count:%d", 
 				   service_type,
 				   new_count);
-			strv[i] = g_strdup (service_type);
+			g_hash_table_insert (priv->last_stats, 
+					     g_strdup (service_type), 
+					     GINT_TO_POINTER (new_count));
 		}
 
 		/* Emit signal */
-		g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, strv);
-		g_strfreev (strv);
+		g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, new_stats);
 	} else {
-		GStrv strv = NULL;
-		GSList *l = NULL;
 		gint i;
 
 		/* Situation #3 */
 		for (i = 0; i < new_stats->len; i++) {
-			const gchar **p;
+			gchar       **p;
 			const gchar  *service_type = NULL;
 			gpointer      data;
 			gint          old_count, new_count;
@@ -668,25 +660,22 @@
 					   old_count,
 					   new_count - old_count);
 
-				l = g_slist_prepend (l, (gpointer) service_type);
-
 				g_hash_table_replace (priv->last_stats, 
 						      g_strdup (service_type), 
 						      GINT_TO_POINTER (new_count));
+			} else {
+				/* Remove from new_stats since the value is the same */
+				g_strfreev (p);
+				g_ptr_array_remove (new_stats, p);
 			}
 		}
 
-		if (l) {
-			l = g_slist_reverse (l);
-			strv = tracker_dbus_slist_to_strv (l);
-			g_slist_free (l);
-
-			g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, strv);
-			g_strfreev (strv);
+		if (new_stats->len > 0) {
+			g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, new_stats);
 		} else {
 			g_message ("  No changes in the statistics");
-
 		}
+
 	}
 
 	g_ptr_array_foreach (new_stats, (GFunc) g_strfreev, NULL);



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