Hello
I have added support to libfm for using libnotify, to
emit notifications when unmounting or ejecting a storage device.
Specifically two notifications are emitted.
One to inform the user to avoid disconnecting a storage device in the
process of unmounting or ejecting.
And a second to inform the user that it's safe to disconnect that
storage device.
Samples of both notifications:
**500 Gb Volume*
*Removing, do not disconnect*.
500 Gb Volume*
Removed, safe to disconnect.
The notifications do not include any icons.
Having no previous experience in contributing, I'm attaching the patch here.
Also having no prior experience with libfm's source tree and the
source's conventions,
I may have created a horrible mess instead of a useful contribution.
Finally I am clueless about udisks, so this patch is probably incomplete.
If there's any interest in this, let me know how to proceed.
Thanks and keep up the good work.
Sakis Bouzanis
diff -ru --new-file libfm/configure.ac libfm-notify/configure.ac
--- libfm/configure.ac 2022-03-28 11:57:07.577458539 +0300
+++ libfm-notify/configure.ac 2022-03-28 11:55:52.985340496 +0300
@@ -59,6 +59,7 @@
AM_CONDITIONAL(HAVE_OLD_ACTIONS, [test x$ACTIONS_SUBDIR = xactions])
# Checks for libraries.
+AC_CHECK_LIB(notify, notify_init, [], [echo "Error: libnotify dev files missing."; exit -1])
# Checks for header files.
AC_HEADER_STDC
diff -ru --new-file libfm/src/base/fm-notify.c libfm-notify/src/base/fm-notify.c
--- libfm/src/base/fm-notify.c 1970-01-01 02:00:00.000000000 +0200
+++ libfm-notify/src/base/fm-notify.c 2022-03-28 11:56:34.585408355 +0300
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 2022 Sakis Bouzanis <[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 the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <libnotify/notify.h>
+
+
+
+void _fm_notify_init( void )
+{
+ if( notify_init( "PCMANFM" ) != TRUE )
+ {
+ fprintf( stderr, "libfm:fm-notify.c: could not initialize libnotify." );
+ exit(EXIT_FAILURE);
+ }
+}
+
+
+void _fm_notify_finalize( void )
+{
+ notify_uninit ();
+}
+
+
+
+void fm_notify_show( GObject* device, gchar *summary )
+{
+ NotifyNotification *notification;
+
+ notification = notify_notification_new( summary, "Removing, do not disconnect.", NULL );
+ notify_notification_set_urgency( notification, NOTIFY_URGENCY_CRITICAL );
+ notify_notification_set_timeout( notification, NOTIFY_EXPIRES_NEVER );
+ notify_notification_show( notification, NULL );
+
+ g_object_set_data_full( G_OBJECT( device ), "fm-notification-summary", summary, free );
+ g_object_set_data_full( G_OBJECT( device ), "fm-notification", notification, g_object_unref );
+}
+
+
+
+void fm_notify_finish( GObject* device, gchar *message )
+{
+ NotifyNotification *notification = g_object_get_data( G_OBJECT( device ), "fm-notification" );
+ gchar *summary;
+
+ if( notification != NULL )
+ {
+ summary = g_object_get_data( G_OBJECT( device ), "fm-notification-summary" );
+ notify_notification_update( notification, summary, "Removed, safe to disconnect.", NULL );
+ notify_notification_set_urgency( notification, NOTIFY_URGENCY_NORMAL );
+ notify_notification_set_timeout( notification, 5000 );
+ notify_notification_show( notification, NULL );
+
+ notification = NULL;
+ g_object_set_data( G_OBJECT( device ), "fm-notification-summary", NULL );
+ g_object_set_data( G_OBJECT( device ), "fm-notification", NULL );
+ }
+}
+
+
+
+void fm_notify_remove( GObject* device )
+{
+ gchar *device_name = g_mount_get_name( G_OBJECT( device ) );
+ fm_notify_show( G_OBJECT( device ), device_name );
+}
+
+
+
+void fm_notify_remove_volume( GObject* device )
+{
+ GMount* mount = g_volume_get_mount( G_OBJECT (device) );
+ gchar *device_name;
+
+ if( mount != NULL )
+ {
+ device_name = g_mount_get_name( G_OBJECT( mount ) );
+ }
+ else
+ {
+ device_name = ( gchar * )malloc( 20 );
+ sprintf( device_name, "Storage Device" );
+ }
+
+ fm_notify_show( G_OBJECT( device ), device_name );
+}
diff -ru --new-file libfm/src/base/fm-notify.h libfm-notify/src/base/fm-notify.h
--- libfm/src/base/fm-notify.h 1970-01-01 02:00:00.000000000 +0200
+++ libfm-notify/src/base/fm-notify.h 2022-03-28 11:55:52.985340496 +0300
@@ -0,0 +1,26 @@
+/*-
+ * Copyright (c) 2022 Sakis Bouzanis <[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 the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+
+void _fm_notify_init( void );
+void fm_notify_remove( GObject* device );
+void fm_notify_remove_volume( GObject* device );
+void fm_notify_finish( GObject* device );
+void _fm_notify_finalize( void );
diff -ru --new-file libfm/src/fm.c libfm-notify/src/fm.c
--- libfm/src/fm.c 2022-03-28 11:57:07.609458586 +0300
+++ libfm-notify/src/fm.c 2022-03-28 11:55:52.985340496 +0300
@@ -122,6 +122,7 @@
_fm_terminal_init(); /* should be called after config initialization */
_fm_templates_init();
_fm_folder_config_init();
+ _fm_notify_init();
#ifdef HAVE_OLD_ACTIONS
/* generated by vala */
@@ -165,6 +166,7 @@
_fm_icon_finalize();
_fm_path_finalize();
_fm_file_finalize();
+ _fm_notify_finalize();
#ifdef USE_UDISKS
_fm_udisks_finalize();
diff -ru --new-file libfm/src/fm.h libfm-notify/src/fm.h
--- libfm/src/fm.h 2022-03-28 11:57:07.609458586 +0300
+++ libfm-notify/src/fm.h 2022-03-28 11:55:52.985340496 +0300
@@ -48,6 +48,7 @@
#include "fm-thumbnail-loader.h"
#include "fm-thumbnailer.h"
#include "fm-utils.h"
+#include "fm-notify.h"
#include "fm-deep-count-job.h"
#include "fm-dir-list-job.h"
diff -ru --new-file libfm/src/gtk/fm-gtk-utils.c libfm-notify/src/gtk/fm-gtk-utils.c
--- libfm/src/gtk/fm-gtk-utils.c 2022-03-28 11:57:07.617458598 +0300
+++ libfm-notify/src/gtk/fm-gtk-utils.c 2022-03-28 11:55:52.985340496 +0300
@@ -47,6 +47,8 @@
#include "fm-config.h"
+#include "fm-notify.h"
+
static GtkDialog* _fm_get_user_input_dialog (GtkWindow* parent, const char* title, const char* msg);
static gchar* _fm_user_input_dialog_run (GtkDialog* dlg, GtkEntry *entry, GtkWidget *extra);
@@ -602,12 +604,15 @@
data->ret = g_file_mount_enclosing_volume_finish(G_FILE(src), res, &data->err);
break;
case UMOUNT_MOUNT:
+ fm_notify_finish(G_OBJECT(src));
data->ret = g_mount_unmount_with_operation_finish(G_MOUNT(src), res, &data->err);
break;
case EJECT_MOUNT:
+ fm_notify_finish(G_OBJECT(src));
data->ret = g_mount_eject_with_operation_finish(G_MOUNT(src), res, &data->err);
break;
case EJECT_VOLUME:
+ fm_notify_finish(G_OBJECT(src));
data->ret = g_volume_eject_with_operation_finish(G_VOLUME(src), res, &data->err);
break;
}
@@ -653,19 +658,22 @@
g_file_mount_enclosing_volume(G_FILE(obj), 0, op, cancellable, on_mount_action_finished, data);
break;
case UMOUNT_MOUNT:
+ fm_notify_remove(G_OBJECT(obj));
prepare_unmount(G_MOUNT(obj));
g_mount_unmount_with_operation(G_MOUNT(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data);
break;
case EJECT_MOUNT:
+ fm_notify_remove(G_OBJECT(obj));
prepare_unmount(G_MOUNT(obj));
g_mount_eject_with_operation(G_MOUNT(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data);
break;
case EJECT_VOLUME:
{
+ fm_notify_remove_volume(G_OBJECT(obj));
GMount* mnt = g_volume_get_mount(G_VOLUME(obj));
if (mnt) /* it might be unmounted already */
{
- prepare_unmount(mnt);
+ prepare_unmount(mnt);
g_object_unref(mnt);
}
g_volume_eject_with_operation(G_VOLUME(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data);
diff -ru --new-file libfm/src/Makefile.am libfm-notify/src/Makefile.am
--- libfm/src/Makefile.am 2022-03-28 11:57:07.601458575 +0300
+++ libfm-notify/src/Makefile.am 2022-03-28 11:55:52.985340496 +0300
@@ -80,6 +80,7 @@
base/fm-thumbnail-loader.c \
base/fm-thumbnailer.c \
base/fm-utils.c \
+ base/fm-notify.c \
$(NULL)
job_SOURCES = \
@@ -187,6 +188,7 @@
base/fm-thumbnail-loader.h \
base/fm-thumbnailer.h \
base/fm-utils.h \
+ base/fm-notify.h \
job/fm-deep-count-job.h \
job/fm-dir-list-job.h \
job/fm-file-info-job.h \
@@ -272,6 +274,7 @@
$(DBUS_LIBS) \
$(EXIF_LIBS) \
$(INTLLIBS) \
+ -lnotify
$(NULL)
libfm_la_LDFLAGS = \
_______________________________________________
Pcmanfm-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pcmanfm-develop