Index: trunk/src/tracker-preferences/tracker-preferences.c =================================================================== --- trunk/src/tracker-preferences/tracker-preferences.c (revision 1097) +++ trunk/src/tracker-preferences/tracker-preferences.c (working copy) @@ -24,6 +24,7 @@ #include #include #include +#include #include "../trackerd/tracker-dbus.h" #include "../libtracker/tracker.h" @@ -34,9 +35,24 @@ #define TRACKER_PREFERENCES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), TRACKER_TYPE_PREFERENCES, TrackerPreferencesPrivate)) +typedef enum { + KEY_BOOL, + KEY_INT, + KEY_STR, + KEY_NONE +} KeyType; + +typedef struct _KeyChange { + KeyType type; + gchar *key; + gchar *key_in_conf; + gchar *value; +} KeyChange; + typedef struct _TrackerPreferencesPrivate { GladeXML *gxml; TrackerConfiguration *prefs; + GSList *key_changes; DBusGConnection *connection; DBusGProxy *dbus_proxy; DBusGProxy *tracker_proxy; @@ -72,6 +88,12 @@ static void initialize_listview (GtkWidget *treeview); static void populate_list (GtkWidget *treeview, GSList *list); +static gchar* int_to_str (gint i); +static gint key_change_compare (gconstpointer a, gconstpointer b); +static void add_key_change (TrackerPreferencesPrivate *priv, KeyChange *change); +static void send_key_change (gpointer data, gpointer user_data); +static void free_key_change (gpointer data, gpointer user_data); + static GObjectClass *parent_class = NULL; static gboolean flag_restart = FALSE; static gboolean flag_reindex = FALSE; @@ -98,6 +120,12 @@ priv->prefs = tracker_configuration_new (); + /* + priv->int_key_change_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + priv->bool_key_change_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + priv->str_key_change_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); +*/ + GtkWidget *widget = NULL; @@ -221,6 +249,12 @@ TrackerPreferencesPrivate *priv = TRACKER_PREFERENCES_GET_PRIVATE (self); +/* + g_hash_table_destroy (priv->int_key_change_table); + g_hash_table_destroy (priv->bool_key_change_table); + g_hash_table_destroy (priv->str_key_change_table); +*/ + g_object_unref (priv->prefs); g_object_unref (priv->gxml); @@ -276,12 +310,15 @@ int value = gtk_range_get_value (range); - tracker_configuration_set_int (configuration, - "/Indexing/Throttle", - value); + KeyChange *change = g_new (KeyChange, 1); - set_int_option (priv, "Throttle", value); + change->type = KEY_INT; + change->key = g_strdup ("Throttle"); + change->key_in_conf = g_strdup ("/Indexing/Throttle"); + change->value = int_to_str (value); + add_key_change (priv, change); + } void @@ -299,22 +336,24 @@ g_print ("unknown widget was clicked with value %d\n", value); } + KeyChange *change = g_new (KeyChange, 1); + + change->type = KEY_INT; if (g_str_equal (name, "spnMaxText")) { - set_int_option (priv, "MaxText", value*1024); + change->key = g_strdup ("MaxText"); + change->key_in_conf = g_strdup ("/Performance/MaxTextToIndex"); + change->value = int_to_str (value*1024); - tracker_configuration_set_int (configuration, - "/Performance/MaxTextToIndex", - value); + add_key_change (priv, change); - } else if (g_str_equal (name, "spnMaxWords")) { - set_int_option (priv, "MaxWords", value); + change->key = g_strdup ("MaxWords"); + change->key_in_conf = g_strdup ("/Performance/MaxWordsToIndex"); + change->value = int_to_str (value); - tracker_configuration_set_int (configuration, - "/Performance/MaxWordsToIndex", - value); + add_key_change (priv, change); } @@ -336,94 +375,91 @@ g_print ("unknown widget was clicked with value %d\n", value); } + KeyChange *change = g_new (KeyChange, 1); + + change->type = KEY_BOOL; if (g_str_equal (name, "chkEnableIndexing")) { - set_bool_option (priv, "EnableIndexing", value); + change->key = g_strdup ("EnableIndexing"); + change->key_in_conf = g_strdup ("/Indexing/EnableIndexing"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Indexing/EnableIndexing", - value); + add_key_change (priv, change); flag_restart = TRUE; } else if (g_str_equal (name, "chkEnableWatching")) { - set_bool_option (priv, "EnableWatching", value); + change->key = g_strdup ("EnableWatching"); + change->key_in_conf = g_strdup ("/Watches/EnableWatching"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Watches/EnableWatching", - value); - + add_key_change (priv, change); flag_restart = TRUE; } else if (g_str_equal (name, "chkEnableEvolutionIndexing")) { - set_bool_option (priv, "EnableEvolution", value); + change->key = g_strdup ("EnableEvolution"); + change->key_in_conf = g_strdup ("/Emails/IndexEvolutionEmails"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Emails/IndexEvolutionEmails", - value); + add_key_change (priv, change); - flag_restart = TRUE; - } else if (g_str_equal (name, "chkIndexContents")) { - set_bool_option (priv, "IndexFileContents", value); + change->key = g_strdup ("IndexFileContents"); + change->key_in_conf = g_strdup ("/Indexing/EnableFileContentIndexing"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Indexing/EnableFileContentIndexing", - value); - + add_key_change (priv, change); flag_restart = TRUE; } else if (g_str_equal (name, "chkGenerateThumbs")) { - set_bool_option (priv, "GenerateThumbs", value); + change->key = g_strdup ("GenerateThumbs"); + change->key_in_conf = g_strdup ("/Indexing/EnableThumbnails"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Indexing/EnableThumbnails", - value); + add_key_change (priv, change); - } else if (g_str_equal (name, "chkSkipMountPoints")) { - set_bool_option (priv, "SkipMountPoints", !value); + change->key = g_strdup ("SkipMountPoints"); + change->key_in_conf = g_strdup ("/Indexing/SkipMountPoints"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Indexing/SkipMountPoints", - !value); + add_key_change (priv, change); - } else if (g_str_equal (name, "chkFastMerges")) { - set_bool_option (priv, "FastMerges", value); + change->key = g_strdup ("FastMerges"); + change->key_in_conf = g_strdup ("/Indexing/FastMerges"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Indexing/FastMerges", - value); + add_key_change (priv, change); } else if (g_str_equal (name, "optReducedMemory")) { - set_bool_option (priv, "LowMemoryMode", value); + change->key = g_strdup ("LowMemoryMode"); + change->key_in_conf = g_strdup ("/General/LowMemoryMode"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/General/LowMemoryMode", - value); + add_key_change (priv, change); } else if (g_str_equal (name, "chkDisableBatteryIndex")) { - set_bool_option (priv, "BatteryIndex", !value); + change->key = g_strdup ("BatteryIndex"); + change->key_in_conf = g_strdup ("/Indexing/BatteryIndex"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Indexing/BatteryIndex", - !value); + add_key_change (priv, change); } else if (g_str_equal (name, "chkDisableBatteryInitialIndex")) { - set_bool_option (priv, "BatteryIndexInitial", !value); + change->key = g_strdup ("BatteryIndexInitial"); + change->key_in_conf = g_strdup ("/Indexing/BatteryIndexInitial"); + change->value = int_to_str (value); - tracker_configuration_set_bool (configuration, - "/Indexing/BatteryIndexInitial", - !value); + add_key_change (priv, change); } } @@ -818,7 +854,7 @@ TRACKER_CONFIGURATION (priv->prefs); GSList *list = NULL; - gboolean value = FALSE; + int value = FALSE; char *str_value; @@ -887,6 +923,9 @@ list = NULL; + g_slist_foreach (priv->key_changes, send_key_change, self); + g_slist_foreach (priv->key_changes, free_key_change, NULL); + tracker_configuration_write (configuration); if (flag_restart && if_trackerd_start (priv)) { @@ -1166,6 +1205,104 @@ } } +gchar * +int_to_str (gint i) +{ + return g_strdup_printf ("%d", i); +} + +static gint +key_change_compare (gconstpointer a, gconstpointer b) +{ + KeyChange *changea, *changeb; + + changea = (KeyChange *)a; + changeb = (KeyChange *)b; + return strcmp (changea->key, changeb->key); +} + +static void +add_key_change (TrackerPreferencesPrivate *priv, KeyChange *change) +{ + GSList *find = g_slist_find_custom (priv->key_changes, change, key_change_compare); + + if (!find) { + priv->key_changes = g_slist_prepend (priv->key_changes, change); + } else { + KeyChange *old_data = (KeyChange *)(find->data); + g_free (old_data->value); + old_data->value = g_strdup (change->value); + free_key_change (change, NULL); + } +} + + +static void +send_key_change (gpointer data, gpointer user_data) +{ + KeyChange *change = (KeyChange *)data; + TrackerPreferences *self = TRACKER_PREFERENCES (user_data); + TrackerPreferencesPrivate *priv = + TRACKER_PREFERENCES_GET_PRIVATE (self); + TrackerConfiguration *configuration = + TRACKER_CONFIGURATION (priv->prefs); + + gint i_value, i_value_orig; + gboolean b_value, b_value_orig; + gchar *s_value, *s_value_orig; + + switch (change->type) { + case KEY_INT: + i_value = atoi (change->value); + i_value_orig = + tracker_configuration_get_int (configuration, + change->key_in_conf, + NULL); + if (i_value != i_value_orig) { + set_int_option (priv, change->key, i_value); + tracker_configuration_set_int (configuration, + change->key_in_conf, + i_value); + } + break; + case KEY_BOOL: + b_value = atoi (change->value); + b_value_orig = + tracker_configuration_get_bool (configuration, + change->key_in_conf, + NULL); + if (b_value != b_value_orig) { + set_bool_option (priv, change->key, b_value); + tracker_configuration_set_bool (configuration, + change->key_in_conf, + b_value); + } + break; + case KEY_STR: + /* TODO: send str key change*/ + break; + default: + break; + } +} + +static void +free_key_change (gpointer data, gpointer user_data) +{ + KeyChange *change = (KeyChange *)data; + + change->type = KEY_NONE; + g_free (change->key); + change->key = NULL; + g_free (change->key_in_conf); + change->key_in_conf = NULL; + g_free (change->value); + change->value = NULL; + + g_free (change); + change = NULL; +} + GType tracker_preferences_get_type (void) {