summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/notification/Makefile.am1
-rw-r--r--src/notification/notification-main.c133
2 files changed, 134 insertions, 0 deletions
diff --git a/src/notification/Makefile.am b/src/notification/Makefile.am
index 5ad1e30..7afa6b9 100644
--- a/src/notification/Makefile.am
+++ b/src/notification/Makefile.am
@@ -13,6 +13,7 @@ gdu_notification_daemon_CPPFLAGS = \
-I$(top_builddir)/src/ \
-DG_LOG_DOMAIN=\"GduNotification\" \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+ -DLIBEXECDIR=\"$(libexecdir)\" \
$(DISABLE_DEPRECATED) \
-DGDU_API_IS_SUBJECT_TO_CHANGE \
-DGDU_GTK_API_IS_SUBJECT_TO_CHANGE \
diff --git a/src/notification/notification-main.c b/src/notification/notification-main.c
index a63a090..191c2b8 100644
--- a/src/notification/notification-main.c
+++ b/src/notification/notification-main.c
@@ -45,6 +45,9 @@ typedef struct
/* List of GduDevice objects with ATA SMART failures */
GList *ata_smart_failures;
+ /* List of uninitialized GduDevice objects */
+ GList *uninitialized_devices;
+
gboolean show_icon_for_ata_smart_failures;
NotifyNotification *ata_smart_notification;
@@ -65,6 +68,8 @@ static void update_unmount_dialogs (NotificationData *data);
static void update_ata_smart_failures (NotificationData *data);
+static void update_uninitialized (NotificationData *data);
+
static void update_status_icon (NotificationData *data);
static void show_menu_for_status_icon (NotificationData *data);
@@ -76,6 +81,7 @@ update_all (NotificationData *data)
{
update_unmount_dialogs (data);
update_ata_smart_failures (data);
+ update_uninitialized (data);
}
static void
@@ -172,6 +178,8 @@ notification_data_free (NotificationData *data)
g_list_free (data->devices_being_unmounted);
g_list_foreach (data->ata_smart_failures, (GFunc) g_object_unref, NULL);
g_list_free (data->ata_smart_failures);
+ g_list_foreach (data->uninitialized_devices, (GFunc) g_object_unref, NULL);
+ g_list_free (data->uninitialized_devices);
g_free (data);
}
@@ -385,6 +393,131 @@ update_ata_smart_failures (NotificationData *data)
/* ---------------------------------------------------------------------------------------------------- */
+/* Look whether the device needs to be partitioned */
+/* - generally we don't want to have partitions on optical drives and floppy disks */
+static gboolean
+device_needs_partition_table (GduDevice *device)
+{
+ char **media_compat;
+ gboolean needs = TRUE; /* default to TRUE */
+
+ media_compat = gdu_device_drive_get_media_compatibility (device);
+ for (; *media_compat; media_compat++) {
+ /* http://hal.freedesktop.org/docs/DeviceKit-disks/Device.html#Device:drive-media-compatibility */
+ if (strstr (*media_compat, "optical") == *media_compat ||
+ strstr (*media_compat, "floppy") == *media_compat) {
+ needs = FALSE;
+ break;
+ }
+ }
+/* g_strfreev (media_compat); */ /* TODO: so, is this const then? */
+ return needs;
+}
+
+static gboolean
+is_uninitialized (GduDevice *device)
+{
+ GduPool *pool;
+ GduPresentable *drive;
+ GList *enclosed_presentables = NULL;
+ GList *l;
+ gboolean usable;
+
+
+ pool = gdu_device_get_pool (device);
+ drive = gdu_pool_get_drive_by_device (pool, device);
+ /* this will filter out devices which are not drives */
+ if (drive == NULL || ! device_needs_partition_table (device)) {
+ g_object_unref (pool);
+ return FALSE;
+ }
+
+ /* test if we have any usable enclosed presentables */
+ enclosed_presentables = gdu_pool_get_enclosed_presentables (pool, drive);
+
+ usable = FALSE;
+ for (l = enclosed_presentables; l != NULL; l = l->next) {
+ GduPresentable *presentable_e = l->data;
+ usable = usable || (gdu_presentable_is_allocated (presentable_e) && gdu_presentable_is_recognized (presentable_e));
+ }
+
+ g_list_foreach (enclosed_presentables, (GFunc) g_object_unref, NULL);
+ g_list_free (enclosed_presentables);
+
+ if (drive)
+ g_object_unref (drive);
+ g_object_unref (pool);
+
+ return (! usable);
+}
+
+static void
+update_uninitialized (NotificationData *data)
+{
+ GList *devices;
+ GList *current;
+ GList *l;
+ GList *added;
+ GList *removed;
+
+ devices = gdu_pool_get_devices (data->pool);
+
+ current = NULL;
+
+ for (l = devices; l != NULL; l = l->next) {
+ GduDevice *device = GDU_DEVICE (l->data);
+
+ if (!gdu_device_is_removable (device) ||
+ !gdu_device_is_media_available (device) ||
+ gdu_device_is_read_only (device))
+ continue;
+
+ g_print ("checking %s\n", gdu_device_get_device_file (device));
+
+ if (! is_uninitialized (device))
+ continue;
+
+ g_print (" it is uninitialized, adding to the list\n");
+
+ /* TODO: write some code for the UI... */
+
+ current = g_list_prepend (current, device);
+ }
+
+ current = g_list_sort (current, ptr_compare);
+ data->ata_smart_failures = g_list_sort (data->ata_smart_failures, ptr_compare);
+
+ added = removed = NULL;
+ diff_sorted_lists (data->ata_smart_failures,
+ current,
+ ptr_compare,
+ &added,
+ &removed);
+
+ for (l = removed; l != NULL; l = l->next) {
+ GduDevice *device = GDU_DEVICE (l->data);
+
+ //g_debug ("%s is no longer failing", gdu_device_get_device_file (device));
+
+ data->ata_smart_failures = g_list_remove (data->ata_smart_failures, device);
+ g_object_unref (device);
+ }
+
+ for (l = added; l != NULL; l = l->next) {
+ GduDevice *device = GDU_DEVICE (l->data);
+ data->ata_smart_failures = g_list_prepend (data->ata_smart_failures, g_object_ref (device));
+
+ //g_debug ("%s is now failing", gdu_device_get_device_file (device));
+ }
+
+ g_list_foreach (devices, (GFunc) g_object_unref, NULL);
+ g_list_free (devices);
+
+ update_status_icon (data);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
update_status_icon (NotificationData *data)
{