[tracker] libtracker-miner: Fix progress percentage duplicates in signal emissions
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-miner: Fix progress percentage duplicates in signal emissions
- Date: Mon, 27 Dec 2010 19:16:40 +0000 (UTC)
commit 8f8438c3c6d46066a56098afba82351ffc4a1e65
Author: Martyn Russell <martyn lanedo com>
Date: Mon Dec 27 16:33:12 2010 +0000
libtracker-miner: Fix progress percentage duplicates in signal emissions
examples/libtracker-miner/Makefile.am | 12 ++++++------
src/libtracker-miner/Makefile.am | 1 +
src/libtracker-miner/tracker-miner-object.c | 22 +++++++++++++++++++---
3 files changed, 26 insertions(+), 9 deletions(-)
---
diff --git a/examples/libtracker-miner/Makefile.am b/examples/libtracker-miner/Makefile.am
index 36c430d..0681c8a 100644
--- a/examples/libtracker-miner/Makefile.am
+++ b/examples/libtracker-miner/Makefile.am
@@ -10,12 +10,12 @@ AM_CPPFLAGS = \
$(LIBTRACKER_MINER_CFLAGS)
LDADD = \
- $(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la \
- $(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
- $(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
- $(top_builddir)/src/libtracker-common/libtracker-common.la \
- $(BUILD_LIBS) \
- $(LIBTRACKER_MINER_LIBS)
+ $(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la \
+ $(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(BUILD_LIBS) \
+ $(LIBTRACKER_MINER_LIBS)
tracker_miner_test_SOURCES = \
tracker-miner-test.c \
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 10978ef..f429f2c 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -69,6 +69,7 @@ libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS = \
libtracker_miner_ TRACKER_API_VERSION@_la_LIBADD = \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
$(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
+ -lm \
$(BUILD_LIBS) \
$(LIBTRACKER_MINER_LIBS)
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 782b755..2e8a9ee 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -19,6 +19,8 @@
#include "config.h"
+#include <math.h>
+
#include <libtracker-common/tracker-dbus.h>
#include <libtracker-common/tracker-type-utils.h>
@@ -28,6 +30,15 @@
#include "tracker-miner-glue.h"
#include "tracker-dbus.h"
+/* Here we use ceil() to eliminate decimal points beyond what we're
+ * interested in, which is 2 decimal places for the progress. The
+ * ceil() call will also round up the last decimal place.
+ *
+ * The 0.49 value is used for rounding correctness, because ceil()
+ * rounds up if the number is > 0.0.
+ */
+#define PROGRESS_ROUNDED(x) (ceil (((x) * 100) - 0.49) / 100)
+
/**
* SECTION:tracker-miner
* @short_description: Abstract base class for data miners
@@ -303,10 +314,15 @@ miner_set_property (GObject *object,
case PROP_PROGRESS: {
gdouble new_progress;
- new_progress = g_value_get_double (value);
+ new_progress = PROGRESS_ROUNDED (g_value_get_double (value));
- /* Only notify 1% changes */
- if ((gint) (miner->private->progress * 100) == (gint) (new_progress * 100)) {
+ /* NOTE: We don't round the current progress before
+ * comparison because we use the rounded value when
+ * we set it last.
+ *
+ * Only notify 1% changes
+ */
+ if (new_progress == miner->private->progress) {
/* Same, do nothing */
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]