Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 56 additions & 125 deletions plugins/housekeeping/csd-disk-space.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <libnotify/notify.h>

#include "csd-disk-space.h"
#include "csd-ldsm-dialog.h"
#include "csd-disk-space-helper.h"

#define GIGABYTE 1024 * 1024 * 1024
Expand Down Expand Up @@ -68,7 +67,6 @@ static unsigned int free_size_gb_no_notify = 2;
static unsigned int min_notify_period = 10;
static GSList *ignore_paths = NULL;
static GSettings *settings = NULL;
static CsdLdsmDialog *dialog = NULL;
static NotifyNotification *notification = NULL;

static guint64 *time_read;
Expand Down Expand Up @@ -168,28 +166,6 @@ ldsm_analyze_path (const gchar *path)
NULL, NULL, NULL, NULL);
}

static gboolean
server_has_actions (void)
{
gboolean has;
GList *caps;
GList *l;

caps = notify_get_server_caps ();
if (caps == NULL) {
fprintf (stderr, "Failed to receive server caps.\n");
return FALSE;
}

l = g_list_find_custom (caps, "actions", (GCompareFunc)strcmp);
has = l != NULL;

g_list_foreach (caps, (GFunc) g_free, NULL);
g_list_free (caps);

return has;
}

static void
ignore_callback (NotifyNotification *n,
const char *action)
Expand Down Expand Up @@ -304,14 +280,16 @@ ldsm_notify_for_mount (LdsmMountInfo *mount,
{
gchar *name, *program;
gint64 free_space;
gint response;
gboolean has_trash;
gboolean has_disk_analyzer;
gboolean retval = TRUE;
gchar *path;
g_autofree gchar *free_space_str = NULL;
g_autofree gchar *summary = NULL;
g_autofree gchar *body = NULL;

/* Don't show a notice if one is already displayed */
if (dialog != NULL || notification != NULL)
if (notification != NULL)
return retval;

name = g_unix_mount_guess_name (mount->mount);
Expand All @@ -323,111 +301,66 @@ ldsm_notify_for_mount (LdsmMountInfo *mount,
has_disk_analyzer = (program != NULL);
g_free (program);

if (server_has_actions ()) {
char *free_space_str;
char *summary;
char *body;

free_space_str = g_format_size (free_space);
free_space_str = g_format_size (free_space);

if (multiple_volumes) {
summary = g_strdup_printf (_("Low Disk Space on \"%s\""), name);
if (has_trash) {
body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining. You may free up some space by emptying the trash."),
name,
free_space_str);
} else {
body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."),
name,
free_space_str);
}
if (multiple_volumes) {
summary = g_strdup_printf (_("Low Disk Space on \"%s\""), name);
if (has_trash) {
body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining. You may free up some space by emptying the trash."),
name,
free_space_str);
} else {
summary = g_strdup (_("Low Disk Space"));
if (has_trash) {
body = g_strdup_printf (_("This computer has only %s disk space remaining. You may free up some space by emptying the trash."),
free_space_str);
} else {
body = g_strdup_printf (_("This computer has only %s disk space remaining."),
free_space_str);
}
}
g_free (free_space_str);

notification = notify_notification_new (summary, body, "xsi-drive-harddisk-symbolic");
g_free (summary);
g_free (body);

g_signal_connect (notification,
"closed",
G_CALLBACK (on_notification_closed),
NULL);

notify_notification_set_app_name (notification, _("Disk space"));
notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE));
notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
if (has_disk_analyzer) {
notify_notification_add_action (notification,
"examine",
_("Examine"),
(NotifyActionCallback) examine_callback,
g_strdup (path),
g_free);
body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."),
name,
free_space_str);
}
} else {
summary = g_strdup (_("Low Disk Space"));
if (has_trash) {
notify_notification_add_action (notification,
"empty-trash",
_("Empty Trash"),
(NotifyActionCallback) empty_trash_callback,
NULL,
NULL);
body = g_strdup_printf (_("This computer has only %s disk space remaining. You may free up some space by emptying the trash."),
free_space_str);
} else {
body = g_strdup_printf (_("This computer has only %s disk space remaining."),
free_space_str);
}
}

notification = notify_notification_new (summary, body, "xsi-drive-harddisk-symbolic");
g_signal_connect (notification,
"closed",
G_CALLBACK (on_notification_closed),
NULL);

notify_notification_set_app_name (notification, _("Disk space"));
notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE));
notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
if (has_disk_analyzer) {
notify_notification_add_action (notification,
"ignore",
_("Ignore"),
(NotifyActionCallback) ignore_callback,
"examine",
_("Examine"),
(NotifyActionCallback) examine_callback,
g_strdup (path),
g_free);
}
if (has_trash) {
notify_notification_add_action (notification,
"empty-trash",
_("Empty Trash"),
(NotifyActionCallback) empty_trash_callback,
NULL,
NULL);
notify_notification_set_category (notification, "device");

if (!notify_notification_show (notification, NULL)) {
g_warning ("failed to send disk space notification\n");
}

} else {
dialog = csd_ldsm_dialog_new (other_usable_volumes,
multiple_volumes,
has_disk_analyzer,
has_trash,
free_space,
name,
path);

g_object_ref (G_OBJECT (dialog));
response = gtk_dialog_run (GTK_DIALOG (dialog));

gtk_widget_destroy (GTK_WIDGET (dialog));
dialog = NULL;

switch (response) {
case GTK_RESPONSE_CANCEL:
retval = FALSE;
break;
case CSD_LDSM_DIALOG_RESPONSE_ANALYZE:
retval = FALSE;
ldsm_analyze_path (path);
break;
case CSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH:
retval = TRUE;
csd_ldsm_show_empty_trash ();
break;
case GTK_RESPONSE_NONE:
case GTK_RESPONSE_DELETE_EVENT:
retval = TRUE;
break;
default:
g_assert_not_reached ();
}
}
notify_notification_add_action (notification,
"ignore",
_("Ignore"),
(NotifyActionCallback) ignore_callback,
NULL,
NULL);
notify_notification_set_category (notification, "device");

if (!notify_notification_show (notification, NULL)) {
g_warning ("failed to send disk space notification\n");
}

g_free (name);
Expand Down Expand Up @@ -795,10 +728,8 @@ csd_ldsm_clean (void)
g_clear_pointer (&ldsm_notified_hash, g_hash_table_destroy);
g_clear_object (&ldsm_monitor);
g_clear_object (&settings);
g_clear_object (&dialog);
if (notification != NULL)
notify_notification_close (notification, NULL);
g_slist_free_full (ignore_paths, g_free);
ignore_paths = NULL;
}

Loading
Loading