7373#include <gio/gio.h>
7474#include <eel/eel-gtk-extensions.h>
7575#include <eel/eel-stock-dialogs.h>
76- #include <libnotify/notify.h>
7776
7877#define GNOME_DESKTOP_USE_UNSTABLE_API
7978
9089/* Disable the self-check functionality */
9190#define NEMO_OMIT_SELF_CHECK "omit"
9291
92+ #define NEMO_NOTIFICATION_UNMOUNT_ICON_NAME "media-removable"
93+ #define NEMO_NOTIFICATION_UNMOUNT_ID_PENDING "unmount-pending"
94+ #define NEMO_NOTIFICATION_UNMOUNT_ID_DONE "unmount-done"
95+
9396static void mount_removed_callback (GVolumeMonitor * monitor ,
9497 GMount * mount ,
9598 NemoMainApplication * application );
@@ -106,61 +109,67 @@ struct _NemoMainApplicationPriv {
106109 NemoFreedesktopDBus * fdb_manager ;
107110
108111 gchar * geometry ;
109-
110- NotifyNotification * unmount_notify ;
111112};
112113
113114static void
114- nemo_main_application_notify_unmount_done (NemoApplication * application ,
115- const gchar * message )
115+ nemo_main_application_send_notification (NemoApplication * application ,
116+ const gchar * title ,
117+ const gchar * body ,
118+ const gchar * icon_name ,
119+ const gchar * notification_id ,
120+ const GNotificationPriority prio )
116121{
117- NemoMainApplication * app = NEMO_MAIN_APPLICATION (application );
122+ NemoMainApplication * app = NEMO_MAIN_APPLICATION (application );
123+ GNotification * notification ;
124+ GIcon * icon ;
118125
119- if (app -> priv -> unmount_notify ) {
120- notify_notification_close (app -> priv -> unmount_notify , NULL );
121- g_clear_object (& app -> priv -> unmount_notify );
122- }
126+ icon = g_themed_icon_new (icon_name );
127+ notification = g_notification_new (title );
128+ g_notification_set_body (notification , body );
129+ g_notification_set_icon (notification , icon );
130+ g_notification_set_priority (notification , prio );
123131
124- if (message != NULL ) {
125- NotifyNotification * unplug ;
126- gchar * * strings ;
132+ g_application_send_notification (G_APPLICATION (app ), notification_id , notification );
127133
128- strings = g_strsplit (message , "\n" , 0 );
129- unplug = notify_notification_new (strings [0 ], strings [1 ],
130- "media-removable" );
131-
132- notify_notification_show (unplug , NULL );
133- g_object_unref (unplug );
134- g_strfreev (strings );
135- }
134+ g_object_unref (notification );
135+ g_object_unref (icon );
136136}
137137
138138static void
139- nemo_main_application_notify_unmount_show (NemoApplication * application ,
139+ nemo_main_application_notify_unmount_done (NemoApplication * application ,
140140 const gchar * message )
141141{
142- NemoMainApplication * app = NEMO_MAIN_APPLICATION (application );
142+ NemoMainApplication * app = NEMO_MAIN_APPLICATION (application );
143+ gchar * * strings ;
143144
144- gchar * * strings ;
145+ // remove notification for pending unmount state
146+ g_application_withdraw_notification (G_APPLICATION (app ), NEMO_NOTIFICATION_UNMOUNT_ID_PENDING );
145147
146- strings = g_strsplit (message , "\n" , 0 );
148+ g_return_if_fail (message != NULL );
149+ strings = g_strsplit (message , "\n" , 2 );
147150
148- if (!app -> priv -> unmount_notify ) {
149- app -> priv -> unmount_notify = notify_notification_new (strings [0 ], strings [1 ],
150- "media-removable" );
151+ nemo_main_application_send_notification (application , strings [0 ], strings [1 ],
152+ NEMO_NOTIFICATION_UNMOUNT_ICON_NAME ,
153+ NEMO_NOTIFICATION_UNMOUNT_ID_DONE ,
154+ G_NOTIFICATION_PRIORITY_NORMAL );
155+
156+ g_strfreev (strings );
157+ }
151158
152- notify_notification_set_hint (app -> priv -> unmount_notify ,
153- "transient" , g_variant_new_boolean (TRUE));
154- notify_notification_set_urgency (app -> priv -> unmount_notify ,
155- NOTIFY_URGENCY_CRITICAL );
156- } else {
157- notify_notification_update (app -> priv -> unmount_notify ,
158- strings [0 ], strings [1 ],
159- "media-removable" );
160- }
159+ static void
160+ nemo_main_application_notify_unmount_show (NemoApplication * application ,
161+ const gchar * message )
162+ {
163+ gchar * * strings ;
164+
165+ g_return_if_fail (message != NULL );
166+ strings = g_strsplit (message , "\n" , 2 );
161167
162- notify_notification_show (app -> priv -> unmount_notify , NULL );
163- g_strfreev (strings );
168+ nemo_main_application_send_notification (application , strings [0 ], strings [1 ],
169+ NEMO_NOTIFICATION_UNMOUNT_ICON_NAME ,
170+ NEMO_NOTIFICATION_UNMOUNT_ID_PENDING ,
171+ G_NOTIFICATION_PRIORITY_URGENT );
172+ g_strfreev (strings );
164173}
165174
166175static void
0 commit comments