Index: src/trackerd/tracker-utils.h =================================================================== --- src/trackerd/tracker-utils.h (revision 1096) +++ src/trackerd/tracker-utils.h (working copy) @@ -211,6 +211,7 @@ /* config options */ GSList *watch_directory_roots_list; + GSList *watch_mounts_list; GSList *crawl_directory_list; GSList *no_watch_directory_list; GSList *no_index_file_types_list; @@ -255,7 +256,6 @@ gboolean fast_merges; /* HAL battery */ - char *battery_udi; gboolean index_on_battery; gboolean initial_index_on_battery; @@ -428,6 +428,7 @@ TRACKER_ACTION_DIRECTORY_CHECK, TRACKER_ACTION_DIRECTORY_CREATED, TRACKER_ACTION_DIRECTORY_DELETED, + TRACKER_ACTION_DIRECTORY_UNMOUNTED, TRACKER_ACTION_DIRECTORY_MOVED_FROM, TRACKER_ACTION_DIRECTORY_MOVED_TO, TRACKER_ACTION_DIRECTORY_REFRESH, /* re checks all files in folder */ @@ -586,6 +587,7 @@ gboolean tracker_file_is_indexable (const char *uri); +gboolean tracker_is_mounted (const char *dir); gboolean tracker_is_directory (const char *dir); gboolean tracker_file_is_no_watched (const char *uri); @@ -648,6 +650,7 @@ gboolean tracker_do_cleanup (const gchar *sig_msg); +gboolean tracker_is_laptop (void); gboolean tracker_pause_on_battery (void); gboolean tracker_low_diskspace (void); gboolean tracker_pause (void); Index: src/trackerd/tracker-inotify.c =================================================================== --- src/trackerd/tracker-inotify.c (revision 1096) +++ src/trackerd/tracker-inotify.c (working copy) @@ -90,7 +90,8 @@ return (event_type == TRACKER_ACTION_DELETE || event_type == TRACKER_ACTION_DELETE_SELF || event_type == TRACKER_ACTION_FILE_DELETED || - event_type == TRACKER_ACTION_DIRECTORY_DELETED); + event_type == TRACKER_ACTION_DIRECTORY_DELETED || + event_type == TRACKER_ACTION_DIRECTORY_UNMOUNTED); } @@ -265,6 +266,10 @@ static TrackerChangeAction get_event (guint32 event_type) { + if (event_type & IN_UNMOUNT) { + return TRACKER_ACTION_DIRECTORY_UNMOUNTED; + } + if (event_type & IN_DELETE) { if (event_type & IN_ISDIR) { return TRACKER_ACTION_DIRECTORY_DELETED; @@ -383,8 +388,12 @@ if (tracker_is_empty_string (filename)) { //tracker_log ("WARNING: inotify event has no filename"); - g_free (event); - continue; + if (action_type == TRACKER_ACTION_DIRECTORY_UNMOUNTED && monitor_name) { + filename = monitor_name; + } else { + g_free (event); + continue; + } } file_utf8_uri = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL); Index: src/trackerd/tracker-hal.c =================================================================== --- src/trackerd/tracker-hal.c (revision 0) +++ src/trackerd/tracker-hal.c (revision 0) @@ -0,0 +1,362 @@ +/* Tracker - indexer and metadata database engine + * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org) + * Copyright (C) 2007, Instituto Nokia de Tecnologia (thiago santos indt org br) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_HAL + +#include +#include +#include +#include +#include + +#include "tracker-db.h" +#include "tracker-hal.h" +#include "tracker-utils.h" + +#define COMPUTER_UDI "/org/freedesktop/Hal/devices/computer" + +#define AC_ADAPTER_ON "ac_adapter.present" +#define AC_ADAPTER "ac_adapter" +#define VOLUME "volume" +#define IS_VOLUME "block.is_volume" +#define COMPUTER_TYPE "system.formfactor" + + +extern Tracker *tracker; +extern DBConnection *main_thread_db_con; + + +/* Holds userdata in HAL context */ +struct HalData { + char *battery_udi; + gboolean laptop; +}; + + +static void +print_error (const char *message, const DBusError *error) +{ + if (error && dbus_error_is_set (error)) + tracker_error ("%s (%s)", message, error->message); + else + tracker_error (message); +} + + +static int +compare (const void *a, const void *b) +{ + return strcmp ((const char *) a, (const char *) b); +} + + +static gboolean +is_battery (LibHalContext *ctx, const char *udi) +{ + struct HalData *user_data = libhal_ctx_get_user_data (ctx); + + if (user_data->battery_udi && strcmp (udi, user_data->battery_udi) == 0) + return TRUE; + else + return FALSE; +} + + +static gboolean +is_mounted_volume (LibHalContext *ctx, const char *udi, const char *key) +{ + if (tracker->watch_mounts_list && strcmp (key, IS_VOLUME)) + if (libhal_device_get_property_bool (ctx, udi, IS_VOLUME, NULL)) + return TRUE; + + return FALSE; +} + + +static gboolean +is_laptop (LibHalContext *ctx) +{ + gboolean ret = FALSE; + char *type; + + if (!libhal_device_property_exists (ctx, COMPUTER_UDI, COMPUTER_TYPE, NULL)) + goto out; + + type = libhal_device_get_property_string (ctx, COMPUTER_UDI, COMPUTER_TYPE, NULL); + if (!type) + goto out; + + tracker_log ("HAL: Computer type is %s", type); + + if (strcmp (type, "laptop") == 0) + ret = TRUE; + +out: + return ret; +} + + +static void +volume_added_callback (LibHalContext *ctx, const char *udi) +{ + DBusError error; + + dbus_error_init (&error); + + if (libhal_device_property_exists (ctx, udi, IS_VOLUME, NULL)) { + if (libhal_device_get_property_bool (ctx, udi, IS_VOLUME, NULL)) { + if (!libhal_device_add_property_watch (ctx, udi, &error)) { + print_error ("HAL: Could not set watch on device", &error); + dbus_error_free (&error); + } else + tracker_log ("HAL: Watch added to device udi %s", udi); + } + } +} + + +static void +property_callback (LibHalContext *ctx, const char *udi, const char *key, + dbus_bool_t is_removed, dbus_bool_t is_added) +{ + tracker_log ("HAL: property changed for udi %s and key %s", udi, key); + + /* Avoid compilation warnings */ + (void) is_removed; + (void) is_added; + + /* Handle battery property changes */ + if (is_battery (ctx, udi)) { + gboolean current_state = tracker->pause_battery; + + if (libhal_device_get_property_bool (ctx, udi, AC_ADAPTER_ON, NULL)) + tracker->pause_battery = FALSE; + else + tracker->pause_battery = TRUE; + + tracker_log ("HAL: Battery power is now %s", + tracker->pause_battery ? "off" : "on"); + + /* If we have come off battery power wakeup index thread */ + if (current_state && !tracker->pause_battery) + tracker_notify_file_data_available (); + + return; + } + + /* Handle volume property changes */ + if (is_mounted_volume (ctx, udi, key)) { + char *mount_point = libhal_device_get_property_string (ctx, udi, + key, NULL); + + if (!mount_point) + return; + + if (g_slist_find_custom (tracker->watch_mounts_list, mount_point, compare)) { + /* Handled as directory creation event */ + FileInfo *info = tracker_create_file_info (mount_point, + TRACKER_ACTION_DIRECTORY_CREATED, 1, WATCH_OTHER); + + if (!tracker_file_info_is_valid (info)) + return; + + info->is_directory = TRUE; + + tracker_db_insert_pending_file (main_thread_db_con, + info->file_id, info->uri, NULL, + info->mime, 0, info->action, + info->is_directory, TRUE, -1); + + tracker_free_file_info (info); + } + + libhal_free_string (mount_point); + } +} + + +static gboolean +battery_detection (LibHalContext *ctx) +{ + int num; + char *battery_udi, **devices; + DBusError error; + gboolean pause_battery, ret = FALSE; + struct HalData *user_data = libhal_ctx_get_user_data (ctx); + + dbus_error_init (&error); + + /* Default sanity values */ + tracker->pause_battery = FALSE; + + devices = libhal_find_device_by_capability (ctx, AC_ADAPTER, + &num, &error); + + if (dbus_error_is_set (&error)) { + print_error ("HAL: Could not find device", &error); + goto out; + } + + if (!devices || !devices[0]) { + tracker_log ("HAL: No battery found"); + ret = TRUE; + goto out; + } + + /* There should only be one ac-adaptor so use first one */ + battery_udi = strdup (devices[0]); + dbus_free_string_array (devices); + + if (!libhal_device_add_property_watch (ctx, battery_udi, &error)) { + print_error ("HAL: Could not set watch on device", &error); + free (battery_udi); + goto out; + } + + pause_battery = !libhal_device_get_property_bool (ctx, + battery_udi, AC_ADAPTER_ON, NULL); + + if (pause_battery) { + tracker->pause_battery = TRUE; + tracker_log ("HAL: System is on battery"); + } else + tracker_log ("HAL: System is on AC power"); + + user_data->battery_udi = battery_udi; + ret = TRUE; + +out: + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + + return ret; +} + + +static gboolean +mount_detection (LibHalContext *ctx) +{ + int i, num; + char **devices; + DBusError error; + gboolean ret = TRUE; + + if (!tracker->watch_mounts_list) + goto out; + + dbus_error_init (&error); + + libhal_ctx_set_device_added (ctx, volume_added_callback); + + devices = libhal_find_device_by_capability (ctx, VOLUME, &num, &error); + if (dbus_error_is_set (&error)) { + print_error ("HAL: Could not find device", &error); + dbus_error_free (&error); + ret = FALSE; + goto out; + } + + if (devices && devices[0]) { + for (i = 0; i < num; i++) + volume_added_callback (ctx, devices[i]); + dbus_free_string_array (devices); + } + +out: + return ret; +} + + +gboolean +tracker_hal_is_laptop (LibHalContext *ctx) +{ + struct HalData *user_data; + + if (ctx) { + user_data = libhal_ctx_get_user_data (ctx); + + if (user_data) + return user_data->laptop; + } + + return FALSE; +} + + +LibHalContext * +tracker_hal_init (void) +{ + LibHalContext *ctx = NULL; + DBusError error; + DBusConnection *connection; + struct HalData *user_data = NULL; + + dbus_error_init (&error); + connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); + + tracker_log ("HAL: Starting... "); + + if (!connection) { + print_error ("HAL: Could not connect to system bus", &error); + goto out; + } + + dbus_connection_setup_with_g_main (connection, NULL); + + ctx = libhal_ctx_new (); + if (!ctx) { + tracker_error ("HAL: Could not create context"); + goto out; + } + + libhal_ctx_set_dbus_connection (ctx, connection); + if (!libhal_ctx_init (ctx, &error)) { + print_error ("HAL: Could not initialize connection", &error); + libhal_ctx_free (ctx); + ctx = NULL; + goto out; + } + + libhal_ctx_set_device_property_modified (ctx, property_callback); + + user_data = malloc (sizeof (*user_data)); + user_data->laptop = is_laptop (ctx); + + libhal_ctx_set_user_data (ctx, user_data); + + if (!mount_detection (ctx) || !battery_detection (ctx)) { + libhal_ctx_free (ctx); + free (user_data); + ctx = NULL; + } + +out: + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + + return ctx; +} + +#endif /* HAVE_HAL */ + Index: src/trackerd/trackerd.c =================================================================== --- src/trackerd/trackerd.c (revision 1096) +++ src/trackerd/trackerd.c (working copy) @@ -11,10 +11,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * - * You should have received a copy of the GNU General Public + * You should have received a copy of the GNU General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Boston, MA 02110-1301, USA. */ #ifndef DBUS_API_SUBJECT_TO_CHANGE @@ -45,15 +45,6 @@ #include "tracker-ioprio.h" #endif - -#ifdef HAVE_HAL -#include -#include -#endif - -#define BATTERY_OFF "ac_adapter.present" -#define AC_ADAPTER "ac_adapter" - #include "tracker-dbus-methods.h" #include "tracker-dbus-metadata.h" #include "tracker-dbus-keywords.h" @@ -64,6 +55,7 @@ #include "tracker-cache.h" #include "tracker-indexer.h" #include "tracker-watch.h" +#include "tracker-hal.h" #include "tracker-os-dependant.h" @@ -126,12 +118,14 @@ static void delete_file (DBConnection *db_con, FileInfo *info); -static void scan_directory (const gchar *uri, DBConnection *db_con); +void scan_directory (const gchar *uri, DBConnection *db_con); +gboolean watch_dir (const gchar* dir, DBConnection *db_con); static gchar **ignore_pattern = NULL; static gchar **no_watch_dirs = NULL; static gchar **watch_dirs = NULL; +static gchar **mount_points = NULL; static gchar **crawl_dirs = NULL; static gchar *language = NULL; static gboolean disable_indexing = FALSE; @@ -145,6 +139,7 @@ static GOptionEntry entries[] = { {"exclude-dir", 'e', 0, G_OPTION_ARG_STRING_ARRAY, &no_watch_dirs, N_("Directory to exclude from indexing"), N_("/PATH/DIR")}, {"include-dir", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &watch_dirs, N_("Directory to include in indexing"), N_("/PATH/DIR")}, + {"mount-point", 'u', 0, G_OPTION_ARG_STRING_ARRAY, &mount_points, N_("Mount point to include in indexing"), N_("/PATH/DIR")}, {"crawl-dir", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &crawl_dirs, N_("Directory to crawl for indexing at start up only"), N_("/PATH/DIR")}, {"no-indexing", 'n', 0, G_OPTION_ARG_NONE, &disable_indexing, N_("Disable any indexing or watching taking place"), NULL }, {"verbosity", 'v', 0, G_OPTION_ARG_INT, &verbosity, N_("Value that controls the level of logging. Valid values are 0 (displays/logs only errors), 1 (minimal), 2 (detailed), and 3 (debug)"), N_("VALUE") }, @@ -196,135 +191,6 @@ } -#ifdef HAVE_HAL - -static void -property_callback (LibHalContext *ctx, const char *udi, const char *key, - dbus_bool_t is_removed, dbus_bool_t is_added) -{ - - tracker_log ("HAL property change detected for udi %s and key %s", udi, key); - - gboolean current_state = tracker->pause_battery; - - if (strcmp (udi, tracker->battery_udi) == 0) { - - tracker->pause_battery = !libhal_device_get_property_bool (ctx, tracker->battery_udi, BATTERY_OFF, NULL); - - char *bat_state[2] = {"off","on"}; - tracker_log ("Battery power is now %s", bat_state[tracker->pause_battery]); - - } else { - return; - } - - /* if we have come off battery power wakeup index thread */ - if (current_state && !tracker->pause_battery) { - tracker_notify_file_data_available (); - } - -} - - -LibHalContext * -tracker_hal_init () -{ - LibHalContext *ctx; - char **devices; - int num; - DBusError error; - DBusConnection *connection; - - dbus_error_init (&error); - - connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - - g_print ("starting HAL detection for ac adaptors..."); - - if (!connection) { - if (dbus_error_is_set (&error)) { - tracker_error ("Could not connect to system bus due to %s", error.message); - dbus_error_free (&error); - } else { - tracker_error ("Could not connect to system bus"); - } - - return NULL; - } - - dbus_connection_setup_with_g_main (connection, NULL); - - ctx = libhal_ctx_new (); - - if (!ctx) { - tracker_error ("Could not create HAL context"); - return NULL; - } - - - - libhal_ctx_set_dbus_connection (ctx, connection); - - if (!libhal_ctx_init (ctx, &error)) { - - if (dbus_error_is_set (&error)) { - tracker_error ("Could not initialise HAL connection due to %s", error.message); - dbus_error_free (&error); - } else { - tracker_error ("Could not initialise HAL connection -is hald running?"); - } - - libhal_ctx_free (ctx); - - return NULL; - } - - devices = libhal_find_device_by_capability (ctx, AC_ADAPTER, &num, &error); - - if (dbus_error_is_set (&error)) { - tracker_error ("Could not get HAL devices due to %s", error.message); - dbus_error_free (&error); - return NULL; - } - - if (!devices || !devices[0]) { - tracker->pause_battery = FALSE; - tracker->battery_udi = NULL; - g_print ("none found\n"); - return ctx; - } - - /* there should only be one ac-adaptor so use first one */ - tracker->battery_udi = g_strdup (devices[0]); - g_print ("found %s\n", devices[0]); - - libhal_ctx_set_device_property_modified (ctx, property_callback); - - libhal_device_add_property_watch (ctx, devices[0], &error); - if (dbus_error_is_set (&error)) { - tracker_error ("Could not set watch on HAL device %s due to %s", devices[0], error.message); - dbus_error_free (&error); - return NULL; - } - - - tracker->pause_battery = !libhal_device_get_property_bool (ctx, tracker->battery_udi, BATTERY_OFF, NULL); - - if (tracker->pause_battery) { - tracker_log ("system is on battery"); - } else { - tracker_log ("system is on AC power"); - } - - dbus_free_string_array (devices); - - return ctx; - -} - -#endif /* HAVE_HAL */ - - gboolean tracker_die () { @@ -488,6 +354,14 @@ static void +add_to_roots_list (const gchar *uri) +{ + if (tracker_is_mounted(uri)) + tracker->watch_directory_roots_list = g_slist_prepend(tracker->watch_directory_roots_list, g_strdup(uri)); +} + + +static void add_dirs_to_list (GSList *my_list, DBConnection *db_con) { if (!tracker->is_running) { @@ -564,7 +438,7 @@ } -static gboolean +gboolean watch_dir (const gchar* dir, DBConnection *db_con) { gchar *dir_utf8; @@ -761,7 +635,7 @@ -static void +void scan_directory (const gchar *uri, DBConnection *db_con) { GSList *file_list; @@ -1126,6 +1000,10 @@ } } + if (tracker->watch_mounts_list) { + g_slist_foreach (tracker->watch_mounts_list, (GFunc) add_to_roots_list, NULL); + } + if (!tracker->watch_directory_roots_list) { break; } @@ -1457,7 +1335,7 @@ tracker_debug ("processing %s with action %s and counter %d ", info->uri, tracker_actions[info->action], info->counter); - if (info->action != TRACKER_ACTION_DELETE && + if (info->action != TRACKER_ACTION_DELETE && info->action != TRACKER_ACTION_DIRECTORY_UNMOUNTED && info->action != TRACKER_ACTION_DIRECTORY_DELETED && info->action != TRACKER_ACTION_FILE_DELETED) { @@ -1490,7 +1368,8 @@ continue; } else { - if (info->action == TRACKER_ACTION_DIRECTORY_DELETED) { + if (info->action == TRACKER_ACTION_DIRECTORY_DELETED || + info->action == TRACKER_ACTION_DIRECTORY_UNMOUNTED) { delete_file (db_con, info); @@ -2088,6 +1967,7 @@ tracker->pause_io = FALSE; tracker->watch_directory_roots_list = NULL; + tracker->watch_mounts_list = NULL; tracker->no_watch_directory_list = NULL; tracker->crawl_directory_list = NULL; tracker->use_nfs_safe_locking = FALSE; @@ -2319,6 +2199,15 @@ } } + if (tracker->watch_mounts_list) { + tracker_log ("Setting watch mount points to:"); + for (lst = tracker->watch_mounts_list; lst; lst = lst->next) { + if (lst->data) { + tracker_log (lst->data); + } + } + } + if (tracker->no_watch_directory_list) { tracker_log ("Setting no watch directory roots to:"); @@ -2647,12 +2536,6 @@ /* deal with config options with defaults, config file and option params */ set_defaults (); - tracker->battery_udi = NULL; - -#ifdef HAVE_HAL - tracker->hal_con = tracker_hal_init (); -#endif - tracker_load_config_file (); if (error) { @@ -2668,6 +2551,10 @@ tracker->watch_directory_roots_list = tracker_filename_array_to_list (watch_dirs); } + if (!tracker->skip_mount_points && mount_points) { + tracker->watch_mounts_list = tracker_filename_array_to_list (mount_points); + } + if (crawl_dirs) { tracker->crawl_directory_list = tracker_filename_array_to_list (crawl_dirs); } @@ -2708,6 +2595,10 @@ sanity_check_option_values (); +#ifdef HAVE_HAL + tracker->hal_con = tracker_hal_init (); +#endif + /* set thread safe DB connection */ tracker_db_thread_init (); Index: src/trackerd/tracker-hal.h =================================================================== --- src/trackerd/tracker-hal.h (revision 0) +++ src/trackerd/tracker-hal.h (revision 0) @@ -0,0 +1,67 @@ +/* Tracker - HAL subsystem support + * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org) + * Copyright (C) 2007, Instituto Nokia de Tecnologia (thiago santos indt org br) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_HAL + +#ifndef _TRACKER_HAL_H_ +#define _TRACKER_HAL_H_ + +#include +#include + + +/** Init HAL subsystem + * + * The HAL subsystem in Tracker is responsible to detect if the system + * is on AC power or battery, when a watched mount point is mounted and + * determine if the computer is a laptop for configuration tunning. + * + * Note: the unmounting detection can be implemented using HAL, but + * currently is implemented using inotify. + * + * @return HAL context on success, NULL otherwise + * + */ +LibHalContext *tracker_hal_init (void); + + +/** Determine if the current computer is a laptop + * + * This function must be called after the the HAL intialization or + * will always return FALSE. + * + * No DBUS messages are sent while calling this function. The return + * value is recovery previously in tracker_hal_init(). + * + * @param ctx the current HAL context + * + * @return TRUE if the current computer is a laptop, FALSE otherwise + * + */ +gboolean tracker_hal_is_laptop (LibHalContext *ctx); + + +#endif /* _TRACKER_HAL_H_ */ + +#endif /* HAVE_HAL */ Index: src/trackerd/tracker-indexer.c =================================================================== --- src/trackerd/tracker-indexer.c (revision 1096) +++ src/trackerd/tracker-indexer.c (working copy) @@ -432,7 +432,7 @@ } /* halve the interval value as notebook hard drives are smaller */ - if (tracker->battery_udi) interval = interval / 2; + if (tracker_is_laptop ()) interval = interval / 2; dpiterinit (src->word_index); @@ -710,7 +710,7 @@ } /* halve the interval value as notebook hard drives are smaller */ - if (tracker->battery_udi) interval = interval / 2; + if (tracker_is_laptop ()) interval = interval / 2; } } Index: src/trackerd/Makefile.am =================================================================== --- src/trackerd/Makefile.am (revision 1096) +++ src/trackerd/Makefile.am (working copy) @@ -35,6 +35,11 @@ unix_sources = tracker-os-dependant-unix.c endif +if HAVE_HAL +hal_sources = tracker-hal.c \ + tracker-hal.h +endif + db_sources = \ tracker-indexer.c \ tracker-indexer.h \ @@ -55,6 +60,7 @@ $(watch_sources) \ $(win_sources) \ $(unix_sources) \ + $(hal_sources) \ $(db_sources) \ tracker-apps.c \ tracker-apps.h \ Index: src/trackerd/tracker-utils.c =================================================================== --- src/trackerd/tracker-utils.c (revision 1096) +++ src/trackerd/tracker-utils.c (working copy) @@ -44,6 +44,7 @@ #include "tracker-utils.h" #include "tracker-indexer.h" #include "tracker-stemmer.h" +#include "tracker-hal.h" #include "../xdgmime/xdgmime.h" #include "tracker-os-dependant.h" @@ -61,8 +62,8 @@ "TRACKER_ACTION_IGNORE", "TRACKER_ACTION_CHECK", "TRACKER_ACTION_DELETE", "TRACKER_ACTION_DELETE_SELF", "TRACKER_ACTION_CREATE","TRACKER_ACTION_MOVED_FROM", "TRACKER_ACTION_MOVED_TO","TRACKER_ACTION_FILE_CHECK", "TRACKER_ACTION_FILE_CHANGED","TRACKER_ACTION_FILE_DELETED", "TRACKER_ACTION_FILE_CREATED", "TRACKER_ACTION_FILE_MOVED_FROM", "TRACKER_ACTION_FILE_MOVED_TO", "TRACKER_ACTION_WRITABLE_FILE_CLOSED","TRACKER_ACTION_DIRECTORY_CHECK", - "TRACKER_ACTION_DIRECTORY_CREATED","TRACKER_ACTION_DIRECTORY_DELETED","TRACKER_ACTION_DIRECTORY_MOVED_FROM","TRACKER_ACTION_DIRECTORY_MOVED_TO", - "TRACKER_ACTION_DIRECTORY_REFRESH", "TRACKER_ACTION_EXTRACT_METADATA", + "TRACKER_ACTION_DIRECTORY_CREATED","TRACKER_ACTION_DIRECTORY_DELETED","TRACKER_ACTION_DIRECTORY_UNMOUNTED", "TRACKER_ACTION_DIRECTORY_MOVED_FROM", + "TRACKER_ACTION_DIRECTORY_MOVED_TO", "TRACKER_ACTION_DIRECTORY_REFRESH", "TRACKER_ACTION_EXTRACT_METADATA", NULL}; char *ignore_suffix[] = {"~", ".o", ".la", ".lo", ".loT", ".in", ".csproj", ".m4", ".rej", ".gmo", ".orig", ".pc", ".omf", ".aux", ".tmp", ".po", NULL}; @@ -1893,6 +1894,49 @@ } +#if defined(__linux__) +#define MOUNT_TABLE "/proc/mounts" +#else +#define MOUNT_TABLE NULL +#endif + +gboolean +tracker_is_mounted(const char *dir) +{ + int i; + char *tok, *cursor, *line = NULL; + FILE *file; + size_t len = 0; + gboolean result = FALSE; + + if (!MOUNT_TABLE) + goto out; + + file = fopen(MOUNT_TABLE, "r"); + if (!file) { + perror("fopen()"); + goto out; + } + + while (result == 0 && getline(&line, &len, file) > 0) { + cursor = line; + for (i = 0; i < 2; i++) + tok = strsep(&cursor, " "); + + if (tok && strcmp(dir, tok) == 0) + result = TRUE; + + free(line); + line = NULL; + } + + fclose(file); + +out: + return result; +} + + gboolean tracker_is_directory (const char *dir) { @@ -2502,7 +2546,7 @@ char *default_throttle; - if (tracker->battery_udi) { + if (tracker_is_laptop ()) { default_throttle = "5"; } else { default_throttle = "0"; @@ -3838,6 +3882,17 @@ gboolean +tracker_is_laptop (void) +{ +#ifdef HAVE_HAL + return tracker_hal_is_laptop (tracker->hal_con); +#else + return FALSE; +#endif +} + + +gboolean tracker_pause_on_battery (void) { if (!tracker->pause_battery) { Index: configure.ac =================================================================== --- configure.ac (revision 1096) +++ configure.ac (working copy) @@ -274,6 +274,8 @@ AC_DEFINE(HAVE_HAL, [], [Define if we have HAL]) fi +AM_CONDITIONAL(HAVE_HAL, test "x$have_hal" = "xyes") + #################################################################### # check for GStreamer or Xine. Otherwise, call an external video # player (Totem or MPlayer). @@ -839,7 +841,7 @@ inotify header location: $inotify_header ioprio support: $ioprio_support Win32: $native_win32 - HAL (battery detection) support: $have_hal + HAL support: $have_hal unac accent stripper support: $enable_unac deskbar-applet support: $enable_deskbar_applet build search tool (GNOME): $have_gnome