[tracker/miner-fs-initable-iface: 4/8] tracker-miner-fs: Make TrackerMinerFiles and TrackerMinerApplications objects initable
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-fs-initable-iface: 4/8] tracker-miner-fs: Make TrackerMinerFiles and TrackerMinerApplications objects initable
- Date: Tue, 1 Feb 2011 11:37:57 +0000 (UTC)
commit 62bef69e79287418055d9bbada26a14b15938746
Author: Aleksander Morgado <aleksander lanedo com>
Date: Mon Jan 31 20:25:09 2011 +0100
tracker-miner-fs: Make TrackerMinerFiles and TrackerMinerApplications objects initable
src/miners/fs/tracker-miner-applications.c | 66 +++++--
src/miners/fs/tracker-miner-files.c | 265 ++++++++++++++++------------
2 files changed, 197 insertions(+), 134 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-applications.c b/src/miners/fs/tracker-miner-applications.c
index b2eecfb..f4fbf05 100644
--- a/src/miners/fs/tracker-miner-applications.c
+++ b/src/miners/fs/tracker-miner-applications.c
@@ -38,8 +38,10 @@
#define THEME_ICON_URN_PREFIX "urn:theme-icon:"
static void miner_applications_finalize (GObject *object);
-static void miner_applications_constructed (GObject *object);
-
+static void miner_applications_initable_iface_init (GInitableIface *iface);
+static gboolean miner_applications_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error);
static gboolean miner_applications_check_file (TrackerMinerFS *fs,
GFile *file);
static gboolean miner_applications_check_directory (TrackerMinerFS *fs,
@@ -68,7 +70,9 @@ struct ProcessApplicationData {
gchar *type;
};
-G_DEFINE_TYPE (TrackerMinerApplications, tracker_miner_applications, TRACKER_TYPE_MINER_FS)
+G_DEFINE_TYPE_WITH_CODE (TrackerMinerApplications, tracker_miner_applications, TRACKER_TYPE_MINER_FS,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ miner_applications_initable_iface_init));
static void
tracker_miner_applications_class_init (TrackerMinerApplicationsClass *klass)
@@ -77,7 +81,6 @@ tracker_miner_applications_class_init (TrackerMinerApplicationsClass *klass)
TrackerMinerFSClass *miner_fs_class = TRACKER_MINER_FS_CLASS (klass);
object_class->finalize = miner_applications_finalize;
- object_class->constructed = miner_applications_constructed;
miner_fs_class->check_file = miner_applications_check_file;
miner_fs_class->check_directory = miner_applications_check_directory;
@@ -94,33 +97,53 @@ tracker_miner_applications_init (TrackerMinerApplications *ma)
}
static void
-miner_applications_finalize (GObject *object)
+miner_applications_initable_iface_init (GInitableIface *iface)
{
- G_OBJECT_CLASS (tracker_miner_applications_parent_class)->finalize (object);
+ iface->init = miner_applications_initable_init;
}
-static void
-miner_applications_constructed (GObject *object)
+static gboolean
+miner_applications_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
+ GInitableIface *parent_iface;
+ TrackerMinerApplications *ma;
+ TrackerMinerFS *fs;
GFile *file;
- G_OBJECT_CLASS (tracker_miner_applications_parent_class)->constructed (object);
+ ma = TRACKER_MINER_APPLICATIONS (initable);
+ fs = TRACKER_MINER_FS (initable);
+
+ /* Chain up parent's initable callback before calling child's one */
+ parent_iface = g_type_interface_peek_parent (TRACKER_MINER_GET_INITABLE_IFACE (initable));
+ if (!parent_iface->init (initable, cancellable, error)) {
+ return FALSE;
+ }
file = g_file_new_for_path ("/usr/share/applications/");
- tracker_miner_fs_directory_add (TRACKER_MINER_FS (object), file, TRUE);
+ tracker_miner_fs_directory_add (fs, file, TRUE);
g_object_unref (file);
file = g_file_new_for_path ("/usr/share/desktop-directories/");
- tracker_miner_fs_directory_add (TRACKER_MINER_FS (object), file, TRUE);
+ tracker_miner_fs_directory_add (fs, file, TRUE);
g_object_unref (file);
#ifdef HAVE_MEEGOTOUCH
file = g_file_new_for_path ("/usr/lib/duicontrolpanel/");
- tracker_miner_fs_directory_add (TRACKER_MINER_FS (object), file, TRUE);
+ tracker_miner_fs_directory_add (fs, file, TRUE);
g_object_unref (file);
#endif /* HAVE_MEEGOTOUCH */
/* FIXME: Check XDG_DATA_DIRS and also process applications in there */
+
+ return TRUE;
+}
+
+static void
+miner_applications_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (tracker_miner_applications_parent_class)->finalize (object);
}
static void
@@ -840,15 +863,20 @@ miner_applications_reset (TrackerMiner *miner)
TrackerMiner *
tracker_miner_applications_new (void)
{
+ GError *error = NULL;
TrackerMiner *miner;
- miner = g_object_new (TRACKER_TYPE_MINER_APPLICATIONS,
- "name", "Applications",
- NULL);
-
- /* Before returning the newly created miner, check if we need
- * to reset it */
- if (tracker_miner_applications_locale_changed ()) {
+ miner = g_initable_new (TRACKER_TYPE_MINER_APPLICATIONS,
+ NULL,
+ &error,
+ "name", "Applications",
+ NULL);
+ if (!miner) {
+ g_critical ("Couldn't create new TrackerMinerApplications object: '%s'",
+ error ? error->message : "Unknown error");
+ } else if (tracker_miner_applications_locale_changed ()) {
+ /* Before returning the newly created miner, check if we need
+ * to reset it */
g_message ("Locale change detected, so resetting miner to "
"remove all previously created items...");
miner_applications_reset (miner);
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 53ef349..b855236 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -154,7 +154,10 @@ static void miner_files_get_property (GObject *o
GValue *value,
GParamSpec *pspec);
static void miner_files_finalize (GObject *object);
-static void miner_files_constructed (GObject *object);
+static void miner_files_initable_iface_init (GInitableIface *iface);
+static gboolean miner_files_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error);
static void mount_pre_unmount_cb (GVolumeMonitor *volume_monitor,
GMount *mount,
TrackerMinerFiles *mf);
@@ -241,7 +244,9 @@ static void miner_files_add_removable_or_optical_directory (TrackerMinerF
const gchar *mount_path,
const gchar *uuid);
-G_DEFINE_TYPE (TrackerMinerFiles, tracker_miner_files, TRACKER_TYPE_MINER_FS)
+G_DEFINE_TYPE_WITH_CODE (TrackerMinerFiles, tracker_miner_files, TRACKER_TYPE_MINER_FS,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ miner_files_initable_iface_init));
static void
tracker_miner_files_class_init (TrackerMinerFilesClass *klass)
@@ -252,7 +257,6 @@ tracker_miner_files_class_init (TrackerMinerFilesClass *klass)
object_class->finalize = miner_files_finalize;
object_class->get_property = miner_files_get_property;
object_class->set_property = miner_files_set_property;
- object_class->constructed = miner_files_constructed;
miner_fs_class->check_file = miner_files_check_file;
miner_fs_class->check_directory = miner_files_check_directory;
@@ -280,7 +284,6 @@ static void
tracker_miner_files_init (TrackerMinerFiles *mf)
{
TrackerMinerFilesPrivate *priv;
- GError *error = NULL;
priv = mf->private = TRACKER_MINER_FILES_GET_PRIVATE (mf);
@@ -314,128 +317,56 @@ tracker_miner_files_init (TrackerMinerFiles *mf)
G_CALLBACK (mount_pre_unmount_cb),
mf);
- /* Set up extractor and signals */
- priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-
- if (!priv->connection) {
- g_critical ("Could not connect to the D-Bus session bus, %s",
- error ? error->message : "no error given.");
- g_error_free (error);
- }
-
priv->quark_mount_point_uuid = g_quark_from_static_string ("tracker-mount-point-uuid");
priv->quark_directory_config_root = g_quark_from_static_string ("tracker-directory-config-root");
-
- init_mount_points (mf);
-}
-
-static void
-miner_files_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- TrackerMinerFilesPrivate *priv;
-
- priv = TRACKER_MINER_FILES_GET_PRIVATE (object);
-
- switch (prop_id) {
- case PROP_CONFIG:
- priv->config = g_value_dup_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
}
static void
-miner_files_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+miner_files_initable_iface_init (GInitableIface *iface)
{
- TrackerMinerFilesPrivate *priv;
-
- priv = TRACKER_MINER_FILES_GET_PRIVATE (object);
-
- switch (prop_id) {
- case PROP_CONFIG:
- g_value_set_object (value, priv->config);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ iface->init = miner_files_initable_init;
}
-static void
-miner_files_finalize (GObject *object)
+static gboolean
+miner_files_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
+ GInitableIface *parent_iface;
TrackerMinerFiles *mf;
- TrackerMinerFilesPrivate *priv;
-
- mf = TRACKER_MINER_FILES (object);
- priv = mf->private;
-
- g_signal_handlers_disconnect_by_func (priv->config,
- low_disk_space_limit_cb,
- NULL);
-
- g_object_unref (priv->config);
-
- disk_space_check_stop (TRACKER_MINER_FILES (object));
-
- if (priv->index_recursive_directories) {
- g_slist_foreach (priv->index_recursive_directories, (GFunc) g_free, NULL);
- g_slist_free (priv->index_recursive_directories);
- }
-
- if (priv->index_single_directories) {
- g_slist_foreach (priv->index_single_directories, (GFunc) g_free, NULL);
- g_slist_free (priv->index_single_directories);
- }
-
-#if defined(HAVE_UPOWER) || defined(HAVE_HAL)
- g_object_unref (priv->power);
-#endif /* defined(HAVE_UPOWER) || defined(HAVE_HAL) */
-
- g_object_unref (priv->storage);
+ TrackerMinerFS *fs;
+ GSList *mounts = NULL;
+ GSList *dirs;
+ GSList *m;
- g_signal_handlers_disconnect_by_func (priv->volume_monitor,
- mount_pre_unmount_cb,
- object);
- g_object_unref (priv->volume_monitor);
+ mf = TRACKER_MINER_FILES (initable);
+ fs = TRACKER_MINER_FS (initable);
- if (priv->force_recheck_id) {
- g_source_remove (priv->force_recheck_id);
- priv->force_recheck_id = 0;
+ /* Chain up parent's initable callback before calling child's one */
+ parent_iface = g_type_interface_peek_parent (TRACKER_MINER_GET_INITABLE_IFACE (initable));
+ if (!parent_iface->init (initable, cancellable, error)) {
+ return FALSE;
}
- if (priv->stale_volumes_check_id) {
- g_source_remove (priv->stale_volumes_check_id);
- priv->stale_volumes_check_id = 0;
+ /* Set up extractor and signals */
+ mf->private->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ if (!mf->private->connection) {
+ g_prefix_error (error,
+ "Could not connect to the D-Bus session bus. ");
+ return FALSE;
}
- G_OBJECT_CLASS (tracker_miner_files_parent_class)->finalize (object);
-}
-
-static void
-miner_files_constructed (GObject *object)
-{
- TrackerMinerFiles *mf;
- TrackerMinerFS *fs;
- GSList *dirs;
- GSList *mounts = NULL, *m;
-
- G_OBJECT_CLASS (tracker_miner_files_parent_class)->constructed (object);
-
- mf = TRACKER_MINER_FILES (object);
- fs = TRACKER_MINER_FS (object);
+ /* Setup mount points */
+ init_mount_points (mf);
+ /* We must have a configuration setup here */
if (G_UNLIKELY (!mf->private->config)) {
- g_message ("No config for miner %p (%s).", object, G_OBJECT_TYPE_NAME (object));
- return;
+ g_set_error (error,
+ TRACKER_MINER_ERROR,
+ 0,
+ "No config set for miner %s",
+ G_OBJECT_TYPE_NAME (mf));
+ return FALSE;
}
/* If this happened AFTER we have initialized mount points, initialize
@@ -635,6 +566,99 @@ miner_files_constructed (GObject *object)
g_slist_free (mounts);
disk_space_check_start (mf);
+
+ return TRUE;
+}
+
+static void
+miner_files_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerMinerFilesPrivate *priv;
+
+ priv = TRACKER_MINER_FILES_GET_PRIVATE (object);
+
+ switch (prop_id) {
+ case PROP_CONFIG:
+ priv->config = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+miner_files_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerMinerFilesPrivate *priv;
+
+ priv = TRACKER_MINER_FILES_GET_PRIVATE (object);
+
+ switch (prop_id) {
+ case PROP_CONFIG:
+ g_value_set_object (value, priv->config);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+miner_files_finalize (GObject *object)
+{
+ TrackerMinerFiles *mf;
+ TrackerMinerFilesPrivate *priv;
+
+ mf = TRACKER_MINER_FILES (object);
+ priv = mf->private;
+
+ g_signal_handlers_disconnect_by_func (priv->config,
+ low_disk_space_limit_cb,
+ NULL);
+
+ g_object_unref (priv->config);
+
+ disk_space_check_stop (TRACKER_MINER_FILES (object));
+
+ if (priv->index_recursive_directories) {
+ g_slist_foreach (priv->index_recursive_directories, (GFunc) g_free, NULL);
+ g_slist_free (priv->index_recursive_directories);
+ }
+
+ if (priv->index_single_directories) {
+ g_slist_foreach (priv->index_single_directories, (GFunc) g_free, NULL);
+ g_slist_free (priv->index_single_directories);
+ }
+
+#if defined(HAVE_UPOWER) || defined(HAVE_HAL)
+ g_object_unref (priv->power);
+#endif /* defined(HAVE_UPOWER) || defined(HAVE_HAL) */
+
+ g_object_unref (priv->storage);
+
+ g_signal_handlers_disconnect_by_func (priv->volume_monitor,
+ mount_pre_unmount_cb,
+ object);
+ g_object_unref (priv->volume_monitor);
+
+ if (priv->force_recheck_id) {
+ g_source_remove (priv->force_recheck_id);
+ priv->force_recheck_id = 0;
+ }
+
+ if (priv->stale_volumes_check_id) {
+ g_source_remove (priv->stale_volumes_check_id);
+ priv->stale_volumes_check_id = 0;
+ }
+
+ G_OBJECT_CLASS (tracker_miner_files_parent_class)->finalize (object);
}
static void
@@ -2672,13 +2696,24 @@ miner_files_finished (TrackerMinerFS *fs)
TrackerMiner *
tracker_miner_files_new (TrackerConfig *config)
{
- return g_object_new (TRACKER_TYPE_MINER_FILES,
- "name", "Files",
- "config", config,
- "processing-pool-wait-limit", 10,
- "processing-pool-ready-limit", 100,
- "mtime-checking", should_check_mtime (config),
- NULL);
+ GError *error = NULL;
+ TrackerMiner *miner;
+
+ miner = g_initable_new (TRACKER_TYPE_MINER_FILES,
+ NULL,
+ &error,
+ "name", "Files",
+ "config", config,
+ "processing-pool-wait-limit", 10,
+ "processing-pool-ready-limit", 100,
+ "mtime-checking", should_check_mtime (config),
+ NULL);
+ if (!miner) {
+ g_critical ("Couldn't create new TrackerMinerFiles object: '%s'",
+ error ? error->message : "Unknown error");
+ }
+
+ return miner;
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]