3636#include <libnotify/notify.h>
3737
3838#include "csd-disk-space.h"
39- #include "csd-ldsm-dialog.h"
4039#include "csd-disk-space-helper.h"
4140
4241#define GIGABYTE 1024 * 1024 * 1024
@@ -68,7 +67,6 @@ static unsigned int free_size_gb_no_notify = 2;
6867static unsigned int min_notify_period = 10 ;
6968static GSList * ignore_paths = NULL ;
7069static GSettings * settings = NULL ;
71- static CsdLdsmDialog * dialog = NULL ;
7270static NotifyNotification * notification = NULL ;
7371
7472static guint64 * time_read ;
@@ -168,28 +166,6 @@ ldsm_analyze_path (const gchar *path)
168166 NULL , NULL , NULL , NULL );
169167}
170168
171- static gboolean
172- server_has_actions (void )
173- {
174- gboolean has ;
175- GList * caps ;
176- GList * l ;
177-
178- caps = notify_get_server_caps ();
179- if (caps == NULL ) {
180- fprintf (stderr , "Failed to receive server caps.\n" );
181- return FALSE;
182- }
183-
184- l = g_list_find_custom (caps , "actions" , (GCompareFunc )strcmp );
185- has = l != NULL ;
186-
187- g_list_foreach (caps , (GFunc ) g_free , NULL );
188- g_list_free (caps );
189-
190- return has ;
191- }
192-
193169static void
194170ignore_callback (NotifyNotification * n ,
195171 const char * action )
@@ -304,14 +280,16 @@ ldsm_notify_for_mount (LdsmMountInfo *mount,
304280{
305281 gchar * name , * program ;
306282 gint64 free_space ;
307- gint response ;
308283 gboolean has_trash ;
309284 gboolean has_disk_analyzer ;
310285 gboolean retval = TRUE;
311286 gchar * path ;
287+ g_autofree gchar * free_space_str = NULL ;
288+ g_autofree gchar * summary = NULL ;
289+ g_autofree gchar * body = NULL ;
312290
313291 /* Don't show a notice if one is already displayed */
314- if (dialog != NULL || notification != NULL )
292+ if (notification != NULL )
315293 return retval ;
316294
317295 name = g_unix_mount_guess_name (mount -> mount );
@@ -323,111 +301,66 @@ ldsm_notify_for_mount (LdsmMountInfo *mount,
323301 has_disk_analyzer = (program != NULL );
324302 g_free (program );
325303
326- if (server_has_actions ()) {
327- char * free_space_str ;
328- char * summary ;
329- char * body ;
330-
331- free_space_str = g_format_size (free_space );
304+ free_space_str = g_format_size (free_space );
332305
333- if (multiple_volumes ) {
334- summary = g_strdup_printf (_ ("Low Disk Space on \"%s\"" ), name );
335- if (has_trash ) {
336- body = g_strdup_printf (_ ("The volume \"%s\" has only %s disk space remaining. You may free up some space by emptying the trash." ),
337- name ,
338- free_space_str );
339- } else {
340- body = g_strdup_printf (_ ("The volume \"%s\" has only %s disk space remaining." ),
341- name ,
342- free_space_str );
343- }
306+ if (multiple_volumes ) {
307+ summary = g_strdup_printf (_ ("Low Disk Space on \"%s\"" ), name );
308+ if (has_trash ) {
309+ body = g_strdup_printf (_ ("The volume \"%s\" has only %s disk space remaining. You may free up some space by emptying the trash." ),
310+ name ,
311+ free_space_str );
344312 } else {
345- summary = g_strdup (_ ("Low Disk Space" ));
346- if (has_trash ) {
347- body = g_strdup_printf (_ ("This computer has only %s disk space remaining. You may free up some space by emptying the trash." ),
348- free_space_str );
349- } else {
350- body = g_strdup_printf (_ ("This computer has only %s disk space remaining." ),
351- free_space_str );
352- }
353- }
354- g_free (free_space_str );
355-
356- notification = notify_notification_new (summary , body , "xsi-drive-harddisk-symbolic" );
357- g_free (summary );
358- g_free (body );
359-
360- g_signal_connect (notification ,
361- "closed" ,
362- G_CALLBACK (on_notification_closed ),
363- NULL );
364-
365- notify_notification_set_app_name (notification , _ ("Disk space" ));
366- notify_notification_set_hint (notification , "transient" , g_variant_new_boolean (TRUE));
367- notify_notification_set_urgency (notification , NOTIFY_URGENCY_CRITICAL );
368- notify_notification_set_timeout (notification , NOTIFY_EXPIRES_DEFAULT );
369- if (has_disk_analyzer ) {
370- notify_notification_add_action (notification ,
371- "examine" ,
372- _ ("Examine" ),
373- (NotifyActionCallback ) examine_callback ,
374- g_strdup (path ),
375- g_free );
313+ body = g_strdup_printf (_ ("The volume \"%s\" has only %s disk space remaining." ),
314+ name ,
315+ free_space_str );
376316 }
317+ } else {
318+ summary = g_strdup (_ ("Low Disk Space" ));
377319 if (has_trash ) {
378- notify_notification_add_action (notification ,
379- "empty-trash" ,
380- _ ("Empty Trash" ),
381- (NotifyActionCallback ) empty_trash_callback ,
382- NULL ,
383- NULL );
320+ body = g_strdup_printf (_ ("This computer has only %s disk space remaining. You may free up some space by emptying the trash." ),
321+ free_space_str );
322+ } else {
323+ body = g_strdup_printf (_ ("This computer has only %s disk space remaining." ),
324+ free_space_str );
384325 }
326+ }
327+
328+ notification = notify_notification_new (summary , body , "xsi-drive-harddisk-symbolic" );
329+ g_signal_connect (notification ,
330+ "closed" ,
331+ G_CALLBACK (on_notification_closed ),
332+ NULL );
333+
334+ notify_notification_set_app_name (notification , _ ("Disk space" ));
335+ notify_notification_set_hint (notification , "transient" , g_variant_new_boolean (TRUE));
336+ notify_notification_set_urgency (notification , NOTIFY_URGENCY_CRITICAL );
337+ notify_notification_set_timeout (notification , NOTIFY_EXPIRES_DEFAULT );
338+ if (has_disk_analyzer ) {
385339 notify_notification_add_action (notification ,
386- "ignore" ,
387- _ ("Ignore" ),
388- (NotifyActionCallback ) ignore_callback ,
340+ "examine" ,
341+ _ ("Examine" ),
342+ (NotifyActionCallback ) examine_callback ,
343+ g_strdup (path ),
344+ g_free );
345+ }
346+ if (has_trash ) {
347+ notify_notification_add_action (notification ,
348+ "empty-trash" ,
349+ _ ("Empty Trash" ),
350+ (NotifyActionCallback ) empty_trash_callback ,
389351 NULL ,
390352 NULL );
391- notify_notification_set_category (notification , "device" );
392-
393- if (!notify_notification_show (notification , NULL )) {
394- g_warning ("failed to send disk space notification\n" );
395- }
396-
397- } else {
398- dialog = csd_ldsm_dialog_new (other_usable_volumes ,
399- multiple_volumes ,
400- has_disk_analyzer ,
401- has_trash ,
402- free_space ,
403- name ,
404- path );
405-
406- g_object_ref (G_OBJECT (dialog ));
407- response = gtk_dialog_run (GTK_DIALOG (dialog ));
408-
409- gtk_widget_destroy (GTK_WIDGET (dialog ));
410- dialog = NULL ;
411-
412- switch (response ) {
413- case GTK_RESPONSE_CANCEL :
414- retval = FALSE;
415- break ;
416- case CSD_LDSM_DIALOG_RESPONSE_ANALYZE :
417- retval = FALSE;
418- ldsm_analyze_path (path );
419- break ;
420- case CSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH :
421- retval = TRUE;
422- csd_ldsm_show_empty_trash ();
423- break ;
424- case GTK_RESPONSE_NONE :
425- case GTK_RESPONSE_DELETE_EVENT :
426- retval = TRUE;
427- break ;
428- default :
429- g_assert_not_reached ();
430- }
353+ }
354+ notify_notification_add_action (notification ,
355+ "ignore" ,
356+ _ ("Ignore" ),
357+ (NotifyActionCallback ) ignore_callback ,
358+ NULL ,
359+ NULL );
360+ notify_notification_set_category (notification , "device" );
361+
362+ if (!notify_notification_show (notification , NULL )) {
363+ g_warning ("failed to send disk space notification\n" );
431364 }
432365
433366 g_free (name );
@@ -795,10 +728,8 @@ csd_ldsm_clean (void)
795728 g_clear_pointer (& ldsm_notified_hash , g_hash_table_destroy );
796729 g_clear_object (& ldsm_monitor );
797730 g_clear_object (& settings );
798- g_clear_object (& dialog );
799731 if (notification != NULL )
800732 notify_notification_close (notification , NULL );
801733 g_slist_free_full (ignore_paths , g_free );
802734 ignore_paths = NULL ;
803735}
804-
0 commit comments