summaryrefslogtreecommitdiff
path: root/plugins/housekeeping
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/housekeeping')
-rw-r--r--plugins/housekeeping/msd-disk-space.c2
-rw-r--r--plugins/housekeeping/msd-housekeeping-manager.c106
-rw-r--r--plugins/housekeeping/msd-ldsm-dialog.c37
-rw-r--r--plugins/housekeeping/msd-ldsm-trash-empty.c2
4 files changed, 84 insertions, 63 deletions
diff --git a/plugins/housekeeping/msd-disk-space.c b/plugins/housekeeping/msd-disk-space.c
index 3065b39..59c7527 100644
--- a/plugins/housekeeping/msd-disk-space.c
+++ b/plugins/housekeeping/msd-disk-space.c
@@ -207,7 +207,7 @@ ldsm_notify_for_mount (LdsmMountInfo *mount,
g_object_ref (G_OBJECT (dialog));
response = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_object_destroy (GTK_OBJECT (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
dialog = NULL;
switch (response) {
diff --git a/plugins/housekeeping/msd-housekeeping-manager.c b/plugins/housekeeping/msd-housekeeping-manager.c
index e9e27c9..cbb1143 100644
--- a/plugins/housekeeping/msd-housekeeping-manager.c
+++ b/plugins/housekeeping/msd-housekeeping-manager.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008 Michael J. Chudobiak <[email protected]>
+ * Copyright (C) 2012 Jasmine Hassan <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,14 +33,12 @@
#define INTERVAL_ONCE_A_DAY 24*60*60
#define INTERVAL_TWO_MINUTES 2*60
-
/* Thumbnail cleaner */
-#define GSETTINGS_THUMB_SCHEMA "org.mate.thumbnail-cache"
-#define GSETTINGS_THUMB_AGE "maximum-age"
-#define DEFAULT_MAX_AGE_IN_DAYS 180
-#define GSETTINGS_THUMB_SIZE "maximum-size"
-#define DEFAULT_MAX_SIZE_IN_MB 512
-
+#define THUMB_CACHE_SCHEMA "org.mate.thumbnail-cache"
+#define THUMB_CACHE_KEY_AGE "maximum-age"
+#define THUMB_CACHE_KEY_SIZE "maximum-size"
+#define DEFAULT_MAX_AGE 180 /* in Days */
+#define DEFAULT_MAX_SIZE 512 /* in MB */
struct MsdHousekeepingManagerPrivate {
guint long_term_cb;
@@ -47,7 +46,6 @@ struct MsdHousekeepingManagerPrivate {
GSettings *settings;
};
-
#define MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerPrivate))
static void msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass);
@@ -84,7 +82,6 @@ thumb_data_free (gpointer data)
}
}
-
static GList *
read_dir_for_purge (const char *path, GList *files)
{
@@ -134,7 +131,6 @@ read_dir_for_purge (const char *path, GList *files)
return files;
}
-
static void
purge_old_thumbnails (ThumbData *info, PurgeData *purge_data)
{
@@ -146,29 +142,55 @@ purge_old_thumbnails (ThumbData *info, PurgeData *purge_data)
}
}
-
static int
sort_file_mtime (ThumbData *file1, ThumbData *file2)
{
return file1->mtime - file2->mtime;
}
+static gboolean
+int_gsettings_mapping (GVariant *value,
+ gpointer *result,
+ gpointer int_ptr)
+{
+ gint32 key_value = g_variant_get_int32 (value);
+
+ /* NULL value means the "last chance" for us to return a valid value */
+ if (value == NULL) {
+ *result = int_ptr; /* use the supplied default value */
+ return TRUE;
+ }
+
+ /* For either AGE/SIZE keys, -1 disables cleaning.
+ * A zero value corresponds to an extra-paranoid level of cleaning
+ */
+ if (key_value >= -1) {
+ *result = &key_value;
+ return TRUE;
+ }
+
+ return FALSE;
+}
static int
-get_gsettings_int_with_default (GSettings *settings, char *key, int default_value)
+get_max_age (MsdHousekeepingManager *manager)
{
- /* If the key is unset, we use a non-zero default value.
- A zero value corresponds to an extra-paranoid level
- of cleaning - it deletes all files. We don't want that
- as a default condition. */
- int value = g_settings_get_int (settings, key);
-
- if (value == NULL || value == 0)
- value = default_value;
-
- return value;
+ int *age = g_settings_get_mapped (manager->priv->settings,
+ THUMB_CACHE_KEY_AGE,
+ int_gsettings_mapping,
+ GINT_TO_POINTER(DEFAULT_MAX_AGE));
+ return *age * 24 * 60 * 60;
}
+static int
+get_max_size (MsdHousekeepingManager *manager)
+{
+ int *size = g_settings_get_mapped (manager->priv->settings,
+ THUMB_CACHE_KEY_SIZE,
+ int_gsettings_mapping,
+ GINT_TO_POINTER(DEFAULT_MAX_SIZE));
+ return *size * 1024 * 1024;
+}
static void
purge_thumbnail_cache (MsdHousekeepingManager *manager)
@@ -206,8 +228,8 @@ purge_thumbnail_cache (MsdHousekeepingManager *manager)
g_get_current_time (&current_time);
purge_data.now = current_time.tv_sec;
- purge_data.max_age = get_gsettings_int_with_default (manager->priv->settings, GSETTINGS_THUMB_AGE, DEFAULT_MAX_AGE_IN_DAYS) * 24 * 60 * 60;
- purge_data.max_size = get_gsettings_int_with_default (manager->priv->settings, GSETTINGS_THUMB_SIZE, DEFAULT_MAX_SIZE_IN_MB) * 1024 * 1024;
+ purge_data.max_age = get_max_age (manager);
+ purge_data.max_size = get_max_size (manager);
purge_data.total_size = 0;
if (purge_data.max_age >= 0)
@@ -227,7 +249,6 @@ purge_thumbnail_cache (MsdHousekeepingManager *manager)
g_list_free (files);
}
-
static gboolean
do_cleanup (MsdHousekeepingManager *manager)
{
@@ -235,7 +256,6 @@ do_cleanup (MsdHousekeepingManager *manager)
return TRUE;
}
-
static gboolean
do_cleanup_once (MsdHousekeepingManager *manager)
{
@@ -244,7 +264,6 @@ do_cleanup_once (MsdHousekeepingManager *manager)
return FALSE;
}
-
static void
do_cleanup_soon (MsdHousekeepingManager *manager)
{
@@ -256,14 +275,14 @@ do_cleanup_soon (MsdHousekeepingManager *manager)
}
}
-
static void
-bindings_callback (GSettings *settings, gchar *key, MsdHousekeepingManager *manager)
+settings_changed_callback (GSettings *settings,
+ const char *key,
+ MsdHousekeepingManager *manager)
{
do_cleanup_soon (manager);
}
-
gboolean
msd_housekeeping_manager_start (MsdHousekeepingManager *manager,
GError **error)
@@ -273,9 +292,10 @@ msd_housekeeping_manager_start (MsdHousekeepingManager *manager,
msd_ldsm_setup (FALSE);
- manager->priv->settings = g_settings_new (GSETTINGS_THUMB_SCHEMA);
+ manager->priv->settings = g_settings_new (THUMB_CACHE_SCHEMA);
- g_signal_connect (manager->priv->settings, "changed", G_CALLBACK (bindings_callback), manager);
+ g_signal_connect (manager->priv->settings, "changed",
+ G_CALLBACK (settings_changed_callback), manager);
/* Clean once, a few minutes after start-up */
do_cleanup_soon (manager);
@@ -289,7 +309,6 @@ msd_housekeeping_manager_start (MsdHousekeepingManager *manager,
return TRUE;
}
-
void
msd_housekeeping_manager_stop (MsdHousekeepingManager *manager)
{
@@ -297,8 +316,6 @@ msd_housekeeping_manager_stop (MsdHousekeepingManager *manager)
g_debug ("Stopping housekeeping manager");
- g_object_unref (p->settings);
-
if (p->short_term_cb) {
g_source_remove (p->short_term_cb);
p->short_term_cb = 0;
@@ -308,32 +325,33 @@ msd_housekeeping_manager_stop (MsdHousekeepingManager *manager)
g_source_remove (p->long_term_cb);
p->long_term_cb = 0;
- /* Do a clean-up on shutdown if and only if the size or age
- limits have been set to paranoid levels (zero) */
- if ((get_gsettings_int_with_default (p->settings, GSETTINGS_THUMB_AGE, DEFAULT_MAX_AGE_IN_DAYS) == 0) ||
- (get_gsettings_int_with_default (p->settings, GSETTINGS_THUMB_SIZE, DEFAULT_MAX_SIZE_IN_MB) == 0)) {
- do_cleanup (manager);
- }
+ /* Do a clean-up on shutdown if and only if the size or age
+ * limits have been set to a paranoid level of cleaning (zero)
+ */
+ if (get_max_age (manager) == 0 || get_max_size (manager) == 0)
+ {
+ do_cleanup (manager);
+ }
}
+ g_object_unref (p->settings);
+ p->settings = NULL;
+
msd_ldsm_clean ();
}
-
static void
msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass)
{
g_type_class_add_private (klass, sizeof (MsdHousekeepingManagerPrivate));
}
-
static void
msd_housekeeping_manager_init (MsdHousekeepingManager *manager)
{
manager->priv = MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE (manager);
}
-
MsdHousekeepingManager *
msd_housekeeping_manager_new (void)
{
diff --git a/plugins/housekeeping/msd-ldsm-dialog.c b/plugins/housekeeping/msd-ldsm-dialog.c
index 7615206..0624448 100644
--- a/plugins/housekeeping/msd-ldsm-dialog.c
+++ b/plugins/housekeeping/msd-ldsm-dialog.c
@@ -17,11 +17,16 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <glib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include "msd-ldsm-dialog.h"
+#if GLIB_CHECK_VERSION (2, 30, 0)
+#define g_format_size_for_display g_format_size
+#endif
+
#define SETTINGS_SCHEMA "org.mate.SettingsDaemon.plugins.housekeeping"
#define SETTINGS_IGNORE_PATHS "ignore-paths"
@@ -151,25 +156,25 @@ ignore_check_button_toggled_cb (GtkToggleButton *button,
{
MsdLdsmDialog *dialog = (MsdLdsmDialog *)user_data;
GSettings *settings;
- GSList *ignore_paths;
+ gchar **settings_list;
+ GSList *ignore_paths = NULL;
GError *error = NULL;
gboolean ignore, ret, updated;
- gchar **settings_list;
-
+ gint i;
+
settings = g_settings_new (SETTINGS_SCHEMA);
-
+
settings_list = g_settings_get_strv (settings, SETTINGS_IGNORE_PATHS);
- if (settings_list != NULL) {
- gint i;
- for (i = 0; i < G_N_ELEMENTS (settings_list); i++) {
- if (settings_list[i] != NULL)
- ignore_paths = g_slist_append (ignore_paths, g_strdup (settings_list[i]));
- }
- g_strfreev (settings_list);
+ for (i = 0; i < G_N_ELEMENTS (settings_list); i++) {
+ if (settings_list[i] != NULL)
+ ignore_paths = g_slist_prepend (ignore_paths, g_strdup (settings_list[i]));
}
-
-
+ g_strfreev (settings_list);
+
+ if (i > 0)
+ ignore_paths = g_slist_reverse (ignore_paths);
+
ignore = gtk_toggle_button_get_active (button);
updated = update_ignore_paths (&ignore_paths, dialog->priv->mount_path, ignore);
@@ -179,9 +184,10 @@ ignore_check_button_toggled_cb (GtkToggleButton *button,
for (l = ignore_paths; l != NULL; l = l->next)
g_ptr_array_add (array, l->data);
+
g_ptr_array_add (array, NULL);
- if (!g_settings_set_strv (settings, "ignore-paths", (const gchar **) array->pdata)) {
+ if (!g_settings_set_strv (settings, SETTINGS_IGNORE_PATHS, (const gchar **) array->pdata)) {
g_warning ("Cannot change ignore preference - failed to commit changes");
}
@@ -213,9 +219,6 @@ msd_ldsm_dialog_init (MsdLdsmDialog *dialog)
gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- /* We don't want a separator - they're really ugly */
- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-
/* Create the image */
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
diff --git a/plugins/housekeeping/msd-ldsm-trash-empty.c b/plugins/housekeeping/msd-ldsm-trash-empty.c
index af01aa1..a12f8ce 100644
--- a/plugins/housekeeping/msd-ldsm-trash-empty.c
+++ b/plugins/housekeeping/msd-ldsm-trash-empty.c
@@ -318,7 +318,7 @@ trash_empty_confirmation_response (GtkDialog *dialog,
if (response_id == GTK_RESPONSE_YES)
trash_empty_start ();
- gtk_object_destroy (GTK_OBJECT (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
trash_empty_confirm_dialog = NULL;
}