From d01d71d8f36809983b174f0b7d62d20bedf33a74 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 24 Sep 2008 12:46:09 +0000 Subject: Wrong branch svn path=/tags/GVFS_1_0_1; revision=2026 --- gnome-2-24/monitor/Makefile.am | 10 - gnome-2-24/monitor/gphoto2/Makefile.am | 60 - gnome-2-24/monitor/gphoto2/ggphoto2volume.c | 575 ------- gnome-2-24/monitor/gphoto2/ggphoto2volume.h | 66 - gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.c | 564 ------- gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.h | 54 - .../gphoto2/gphoto2-volume-monitor-daemon.c | 43 - gnome-2-24/monitor/gphoto2/gphoto2.monitor | 4 - gnome-2-24/monitor/gphoto2/hal-device.c | 297 ---- gnome-2-24/monitor/gphoto2/hal-device.h | 93 -- gnome-2-24/monitor/gphoto2/hal-marshal.c | 163 -- gnome-2-24/monitor/gphoto2/hal-marshal.h | 36 - gnome-2-24/monitor/gphoto2/hal-marshal.list | 3 - gnome-2-24/monitor/gphoto2/hal-pool.c | 458 ------ gnome-2-24/monitor/gphoto2/hal-pool.h | 74 - gnome-2-24/monitor/gphoto2/hal-utils.c | 142 -- gnome-2-24/monitor/gphoto2/hal-utils.h | 40 - ...org.gtk.Private.GPhoto2VolumeMonitor.service.in | 3 - gnome-2-24/monitor/hal/Makefile.am | 62 - gnome-2-24/monitor/hal/ghaldrive.c | 1009 ------------- gnome-2-24/monitor/hal/ghaldrive.h | 62 - gnome-2-24/monitor/hal/ghalmount.c | 1592 -------------------- gnome-2-24/monitor/hal/ghalmount.h | 76 - gnome-2-24/monitor/hal/ghalvolume.c | 1068 ------------- gnome-2-24/monitor/hal/ghalvolume.h | 84 -- gnome-2-24/monitor/hal/ghalvolumemonitor.c | 1399 ----------------- gnome-2-24/monitor/hal/ghalvolumemonitor.h | 58 - gnome-2-24/monitor/hal/hal-device.c | 297 ---- gnome-2-24/monitor/hal/hal-device.h | 93 -- gnome-2-24/monitor/hal/hal-marshal.list | 3 - gnome-2-24/monitor/hal/hal-pool.c | 458 ------ gnome-2-24/monitor/hal/hal-pool.h | 74 - gnome-2-24/monitor/hal/hal-utils.c | 171 --- gnome-2-24/monitor/hal/hal-utils.h | 42 - gnome-2-24/monitor/hal/hal-volume-monitor-daemon.c | 43 - gnome-2-24/monitor/hal/hal.monitor | 5 - .../org.gtk.Private.HalVolumeMonitor.service.in | 3 - gnome-2-24/monitor/proxy/Makefile.am | 67 - gnome-2-24/monitor/proxy/gproxydrive.c | 578 ------- gnome-2-24/monitor/proxy/gproxydrive.h | 55 - gnome-2-24/monitor/proxy/gproxymount.c | 560 ------- gnome-2-24/monitor/proxy/gproxymount.h | 56 - gnome-2-24/monitor/proxy/gproxyvolume.c | 689 --------- gnome-2-24/monitor/proxy/gproxyvolume.h | 58 - gnome-2-24/monitor/proxy/gproxyvolumemonitor.c | 1321 ---------------- gnome-2-24/monitor/proxy/gproxyvolumemonitor.h | 77 - .../monitor/proxy/gvfsproxyvolumemonitordaemon.c | 1155 -------------- .../monitor/proxy/gvfsproxyvolumemonitordaemon.h | 35 - .../monitor/proxy/remote-volume-monitor-module.c | 64 - 49 files changed, 13999 deletions(-) delete mode 100644 gnome-2-24/monitor/Makefile.am delete mode 100644 gnome-2-24/monitor/gphoto2/Makefile.am delete mode 100644 gnome-2-24/monitor/gphoto2/ggphoto2volume.c delete mode 100644 gnome-2-24/monitor/gphoto2/ggphoto2volume.h delete mode 100644 gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.c delete mode 100644 gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.h delete mode 100644 gnome-2-24/monitor/gphoto2/gphoto2-volume-monitor-daemon.c delete mode 100644 gnome-2-24/monitor/gphoto2/gphoto2.monitor delete mode 100644 gnome-2-24/monitor/gphoto2/hal-device.c delete mode 100644 gnome-2-24/monitor/gphoto2/hal-device.h delete mode 100644 gnome-2-24/monitor/gphoto2/hal-marshal.c delete mode 100644 gnome-2-24/monitor/gphoto2/hal-marshal.h delete mode 100644 gnome-2-24/monitor/gphoto2/hal-marshal.list delete mode 100644 gnome-2-24/monitor/gphoto2/hal-pool.c delete mode 100644 gnome-2-24/monitor/gphoto2/hal-pool.h delete mode 100644 gnome-2-24/monitor/gphoto2/hal-utils.c delete mode 100644 gnome-2-24/monitor/gphoto2/hal-utils.h delete mode 100644 gnome-2-24/monitor/gphoto2/org.gtk.Private.GPhoto2VolumeMonitor.service.in delete mode 100644 gnome-2-24/monitor/hal/Makefile.am delete mode 100644 gnome-2-24/monitor/hal/ghaldrive.c delete mode 100644 gnome-2-24/monitor/hal/ghaldrive.h delete mode 100644 gnome-2-24/monitor/hal/ghalmount.c delete mode 100644 gnome-2-24/monitor/hal/ghalmount.h delete mode 100644 gnome-2-24/monitor/hal/ghalvolume.c delete mode 100644 gnome-2-24/monitor/hal/ghalvolume.h delete mode 100644 gnome-2-24/monitor/hal/ghalvolumemonitor.c delete mode 100644 gnome-2-24/monitor/hal/ghalvolumemonitor.h delete mode 100644 gnome-2-24/monitor/hal/hal-device.c delete mode 100644 gnome-2-24/monitor/hal/hal-device.h delete mode 100644 gnome-2-24/monitor/hal/hal-marshal.list delete mode 100644 gnome-2-24/monitor/hal/hal-pool.c delete mode 100644 gnome-2-24/monitor/hal/hal-pool.h delete mode 100644 gnome-2-24/monitor/hal/hal-utils.c delete mode 100644 gnome-2-24/monitor/hal/hal-utils.h delete mode 100644 gnome-2-24/monitor/hal/hal-volume-monitor-daemon.c delete mode 100644 gnome-2-24/monitor/hal/hal.monitor delete mode 100644 gnome-2-24/monitor/hal/org.gtk.Private.HalVolumeMonitor.service.in delete mode 100644 gnome-2-24/monitor/proxy/Makefile.am delete mode 100644 gnome-2-24/monitor/proxy/gproxydrive.c delete mode 100644 gnome-2-24/monitor/proxy/gproxydrive.h delete mode 100644 gnome-2-24/monitor/proxy/gproxymount.c delete mode 100644 gnome-2-24/monitor/proxy/gproxymount.h delete mode 100644 gnome-2-24/monitor/proxy/gproxyvolume.c delete mode 100644 gnome-2-24/monitor/proxy/gproxyvolume.h delete mode 100644 gnome-2-24/monitor/proxy/gproxyvolumemonitor.c delete mode 100644 gnome-2-24/monitor/proxy/gproxyvolumemonitor.h delete mode 100644 gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.c delete mode 100644 gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.h delete mode 100644 gnome-2-24/monitor/proxy/remote-volume-monitor-module.c (limited to 'gnome-2-24/monitor') diff --git a/gnome-2-24/monitor/Makefile.am b/gnome-2-24/monitor/Makefile.am deleted file mode 100644 index d4197d52..00000000 --- a/gnome-2-24/monitor/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ - -SUBDIRS = proxy - -if USE_HAL -SUBDIRS += hal -endif - -if USE_GPHOTO2 -SUBDIRS += gphoto2 -endif diff --git a/gnome-2-24/monitor/gphoto2/Makefile.am b/gnome-2-24/monitor/gphoto2/Makefile.am deleted file mode 100644 index 5137a65e..00000000 --- a/gnome-2-24/monitor/gphoto2/Makefile.am +++ /dev/null @@ -1,60 +0,0 @@ - -NULL = - -libexec_PROGRAMS = gvfs-gphoto2-volume-monitor - -BUILT_SOURCES = \ - hal-marshal.h hal-marshal.c - -hal-marshal.h: hal-marshal.list - glib-genmarshal $< --prefix=hal_marshal --header > $@ - -hal-marshal.c: hal-marshal.list - echo "#include \"hal-marshal.h\"" > $@ && glib-genmarshal $< --prefix=hal_marshal --body >> $@ - - -gvfs_gphoto2_volume_monitor_SOURCES = \ - hal-utils.c hal-utils.h \ - hal-marshal.c hal-marshal.h \ - hal-device.c hal-device.h \ - hal-pool.c hal-pool.h \ - gphoto2-volume-monitor-daemon.c \ - ggphoto2volume.c ggphoto2volume.h \ - ggphoto2volumemonitor.c ggphoto2volumemonitor.h \ - $(NULL) - -gvfs_gphoto2_volume_monitor_CFLAGS = \ - -DG_LOG_DOMAIN=\"GVFS-GPhoto2\" \ - -I$(top_srcdir)/common \ - -I$(top_srcdir)/monitor/proxy \ - $(GLIB_CFLAGS) \ - $(HAL_CFLAGS) \ - -DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \ - -DGVFS_LOCALEDIR=\""$(localedir)"\" \ - -DG_DISABLE_DEPRECATED \ - $(NULL) - -gvfs_gphoto2_volume_monitor_LDFLAGS = \ - $(NULL) - -gvfs_gphoto2_volume_monitor_LDADD = \ - $(GLIB_LIBS) \ - $(HAL_LIBS) \ - $(top_builddir)/common/libgvfscommon.la \ - $(top_builddir)/monitor/proxy/libgvfsproxyvolumemonitordaemon-noin.la \ - $(NULL) - -remote_volume_monitorsdir = $(datadir)/gvfs/remote-volume-monitors -remote_volume_monitors_DATA = gphoto2.monitor - -servicedir = $(datadir)/dbus-1/services -service_in_files = org.gtk.Private.GPhoto2VolumeMonitor.service.in -service_DATA = $(service_in_files:.service.in=.service) - -$(service_DATA): $(service_in_files) Makefile - @sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ - -clean-local: - rm -f *~ *.loT $(BUILT_SOURCES) $(service_DATA) - -EXTRA_DIST = hal-marshal.list $(service_in_files) gphoto2.monitor diff --git a/gnome-2-24/monitor/gphoto2/ggphoto2volume.c b/gnome-2-24/monitor/gphoto2/ggphoto2volume.c deleted file mode 100644 index 8cdf8257..00000000 --- a/gnome-2-24/monitor/gphoto2/ggphoto2volume.c +++ /dev/null @@ -1,575 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "ggphoto2volume.h" - -#include "hal-utils.h" - -/* Protects all fields of GHalDrive that can change */ -G_LOCK_DEFINE_STATIC(gphoto2_volume); - -struct _GGPhoto2Volume { - GObject parent; - - GVolumeMonitor *volume_monitor; /* owned by volume monitor */ - - char *device_path; - HalDevice *device; - HalDevice *drive_device; - - GFile *foreign_mount_root; - GMount *foreign_mount; - - char *name; - char *icon; -}; - -static void g_gphoto2_volume_volume_iface_init (GVolumeIface *iface); - -G_DEFINE_TYPE_EXTENDED (GGPhoto2Volume, g_gphoto2_volume, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_VOLUME, - g_gphoto2_volume_volume_iface_init)) - -static void -g_gphoto2_volume_finalize (GObject *object) -{ - GGPhoto2Volume *volume; - - volume = G_GPHOTO2_VOLUME (object); - - if (volume->device != NULL) - g_object_unref (volume->device); - - if (volume->foreign_mount_root != NULL) - g_object_unref (volume->foreign_mount_root); - - if (volume->foreign_mount != NULL) - g_object_unref (volume->foreign_mount); - - if (volume->volume_monitor != NULL) - g_object_remove_weak_pointer (G_OBJECT (volume->volume_monitor), (gpointer) &(volume->volume_monitor)); - - g_free (volume->name); - g_free (volume->icon); - - if (G_OBJECT_CLASS (g_gphoto2_volume_parent_class)->finalize) - (*G_OBJECT_CLASS (g_gphoto2_volume_parent_class)->finalize) (object); -} - -static void -g_gphoto2_volume_class_init (GGPhoto2VolumeClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = g_gphoto2_volume_finalize; -} - -static void -g_gphoto2_volume_init (GGPhoto2Volume *gphoto2_volume) -{ -} - -static gboolean -changed_in_idle (gpointer data) -{ - GGPhoto2Volume *volume = data; - - g_signal_emit_by_name (volume, "changed"); - if (volume->volume_monitor != NULL) - g_signal_emit_by_name (volume->volume_monitor, "volume_changed", volume); - g_object_unref (volume); - - return FALSE; -} - -static char ** -dupv_and_uniqify (char **str_array) -{ - int n, m, o; - int len; - char **result; - - result = g_strdupv (str_array); - len = g_strv_length (result); - - for (n = 0; n < len; n++) - { - char *s = result[n]; - for (m = n + 1; m < len; m++) - { - char *p = result[m]; - if (strcmp (s, p) == 0) - { - for (o = m + 1; o < len; o++) - result[o - 1] = result[o]; - len--; - result[len] = NULL; - m--; - } - } - } - - return result; -} - -static void -do_update_from_hal_for_camera (GGPhoto2Volume *v) -{ - const char *vendor; - const char *product; - const char *icon_from_hal; - const char *name_from_hal; - gboolean is_audio_player; - - vendor = hal_device_get_property_string (v->drive_device, "usb_device.vendor"); - product = hal_device_get_property_string (v->drive_device, "usb_device.product"); - icon_from_hal = hal_device_get_property_string (v->device, "info.desktop.icon"); - name_from_hal = hal_device_get_property_string (v->device, "info.desktop.name"); - - is_audio_player = hal_device_has_capability (v->device, "portable_audio_player"); - - v->name = NULL; - if (strlen (name_from_hal) > 0) - v->name = g_strdup (name_from_hal); - else if (vendor == NULL) - { - if (product != NULL) - v->name = g_strdup (product); - } - else - { - if (product != NULL) - v->name = g_strdup_printf ("%s %s", vendor, product); - else - { - if (is_audio_player) - { - /* Translators: %s is the device vendor */ - v->name = g_strdup_printf (_("%s Audio Player"), vendor); - } - else - { - /* Translators: %s is the device vendor */ - v->name = g_strdup_printf (_("%s Camera"), vendor); - } - } - } - if (v->name == NULL) - { - if (is_audio_player) - v->name = g_strdup (_("Audio Player")); - else - v->name = g_strdup (_("Camera")); - } - - if (strlen (icon_from_hal) > 0) - v->icon = g_strdup (icon_from_hal); - else if (is_audio_player) - v->icon = g_strdup ("multimedia-player"); - else - v->icon = g_strdup ("camera-photo"); - - g_object_set_data_full (G_OBJECT (v), - "hal-storage-device-capabilities", - dupv_and_uniqify (hal_device_get_property_strlist (v->device, "info.capabilities")), - (GDestroyNotify) g_strfreev); -} - -static void -update_from_hal (GGPhoto2Volume *mv, gboolean emit_changed) -{ - char *old_name; - char *old_icon; - - G_LOCK (gphoto2_volume); - - old_name = g_strdup (mv->name); - old_icon = g_strdup (mv->icon); - - g_free (mv->name); - g_free (mv->icon); - - do_update_from_hal_for_camera (mv); - - if (emit_changed) - { - if (old_name == NULL || - old_icon == NULL || - strcmp (old_name, mv->name) != 0 || - strcmp (old_icon, mv->icon) != 0) - g_idle_add (changed_in_idle, g_object_ref (mv)); - } - g_free (old_name); - g_free (old_icon); - - G_UNLOCK (gphoto2_volume); -} - -static void -hal_changed (HalDevice *device, const char *key, gpointer user_data) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (user_data); - - /*g_warning ("hal modifying %s (property %s changed)", gphoto2_volume->device_path, key);*/ - update_from_hal (gphoto2_volume, TRUE); -} - -GGPhoto2Volume * -g_gphoto2_volume_new (GVolumeMonitor *volume_monitor, - HalDevice *device, - HalPool *pool, - GFile *foreign_mount_root) -{ - GGPhoto2Volume *volume; - HalDevice *drive_device; - const char *storage_udi; - const char *device_path; - - g_return_val_if_fail (volume_monitor != NULL, NULL); - g_return_val_if_fail (device != NULL, NULL); - g_return_val_if_fail (pool != NULL, NULL); - g_return_val_if_fail (foreign_mount_root != NULL, NULL); - - if (!hal_device_has_capability (device, "camera") || - (hal_device_has_capability (device, "portable_audio_player") && - hal_device_get_property_bool (device, "camera.libgphoto2.support"))) - return NULL; - - /* OK, so we abuse storage_udi and drive_device for the USB main - * device that holds this interface... - */ - storage_udi = hal_device_get_property_string (device, "info.parent"); - if (storage_udi == NULL) - return NULL; - - drive_device = hal_pool_get_device_by_udi (pool, storage_udi); - if (drive_device == NULL) - return NULL; - - /* TODO: other OS'es? Will address this with DK aka HAL 2.0 */ - device_path = hal_device_get_property_string (drive_device, "linux.device_file"); - if (strlen (device_path) == 0) - device_path = NULL; - - volume = g_object_new (G_TYPE_GPHOTO2_VOLUME, NULL); - volume->volume_monitor = volume_monitor; - g_object_add_weak_pointer (G_OBJECT (volume_monitor), (gpointer) &(volume->volume_monitor)); - volume->device_path = g_strdup (device_path); - volume->device = g_object_ref (device); - volume->drive_device = g_object_ref (drive_device); - volume->foreign_mount_root = foreign_mount_root != NULL ? g_object_ref (foreign_mount_root) : NULL; - - g_signal_connect_object (device, "hal_property_changed", (GCallback) hal_changed, volume, 0); - g_signal_connect_object (drive_device, "hal_property_changed", (GCallback) hal_changed, volume, 0); - - update_from_hal (volume, FALSE); - - return volume; -} - -void -g_gphoto2_volume_removed (GGPhoto2Volume *volume) -{ - ; -} - -static GIcon * -g_gphoto2_volume_get_icon (GVolume *volume) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - GIcon *icon; - - G_LOCK (gphoto2_volume); - icon = g_themed_icon_new (gphoto2_volume->icon); - G_UNLOCK (gphoto2_volume); - return icon; -} - -static char * -g_gphoto2_volume_get_name (GVolume *volume) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - char *name; - - G_LOCK (gphoto2_volume); - name = g_strdup (gphoto2_volume->name); - G_UNLOCK (gphoto2_volume); - - return name; -} - -static char * -g_gphoto2_volume_get_uuid (GVolume *volume) -{ - return NULL; -} - -static gboolean -g_gphoto2_volume_can_mount (GVolume *volume) -{ - return TRUE; -} - -static gboolean -g_gphoto2_volume_can_eject (GVolume *volume) -{ - return FALSE; -} - -static gboolean -g_gphoto2_volume_should_automount (GVolume *volume) -{ - return TRUE; -} - -static GDrive * -g_gphoto2_volume_get_drive (GVolume *volume) -{ - return NULL; -} - -static GMount * -g_gphoto2_volume_get_mount (GVolume *volume) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - GMount *mount; - - G_LOCK (gphoto2_volume); - mount = NULL; - if (gphoto2_volume->foreign_mount != NULL) - mount = g_object_ref (gphoto2_volume->foreign_mount); - G_UNLOCK (gphoto2_volume); - - return mount; -} - -gboolean -g_gphoto2_volume_has_udi (GGPhoto2Volume *volume, - const char *udi) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - gboolean res; - - G_LOCK (gphoto2_volume); - res = FALSE; - if (gphoto2_volume->device != NULL) - res = strcmp (hal_device_get_udi (gphoto2_volume->device), udi) == 0; - G_UNLOCK (gphoto2_volume); - return res; -} - -static void -foreign_mount_unmounted (GMount *mount, gpointer user_data) -{ - GGPhoto2Volume *volume = G_GPHOTO2_VOLUME (user_data); - gboolean check; - - G_LOCK (gphoto2_volume); - check = volume->foreign_mount == mount; - G_UNLOCK (gphoto2_volume); - if (check) - g_gphoto2_volume_adopt_foreign_mount (volume, NULL); -} - -void -g_gphoto2_volume_adopt_foreign_mount (GGPhoto2Volume *volume, GMount *foreign_mount) -{ - G_LOCK (gphoto2_volume); - if (volume->foreign_mount != NULL) - g_object_unref (volume->foreign_mount); - - if (foreign_mount != NULL) - { - volume->foreign_mount = g_object_ref (foreign_mount); - g_signal_connect_object (foreign_mount, "unmounted", (GCallback) foreign_mount_unmounted, volume, 0); - } - else - volume->foreign_mount = NULL; - - g_idle_add (changed_in_idle, g_object_ref (volume)); - G_UNLOCK (gphoto2_volume); -} - -gboolean -g_gphoto2_volume_has_foreign_mount_root (GGPhoto2Volume *volume, - GFile *mount_root) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - gboolean res; - - G_LOCK (gphoto2_volume); - res = FALSE; - if (gphoto2_volume->foreign_mount_root != NULL) - res = g_file_equal (gphoto2_volume->foreign_mount_root, mount_root); - G_UNLOCK (gphoto2_volume); - - return res; -} - - - -typedef struct -{ - GGPhoto2Volume *enclosing_volume; - GAsyncReadyCallback callback; - gpointer user_data; -} ForeignMountOp; - -static void -mount_foreign_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - ForeignMountOp *data = user_data; - data->callback (G_OBJECT (data->enclosing_volume), res, data->user_data); - g_free (data); -} - -static void -g_gphoto2_volume_mount (GVolume *volume, - GMountMountFlags flags, - GMountOperation *mount_operation, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - ForeignMountOp *data; - - /*g_warning ("gphoto2_volume_mount (can_mount=%d foreign=%p device_path=%s)", - g_gphoto2_volume_can_mount (volume), - gphoto2_volume->foreign_mount_root, - gphoto2_volume->device_path);*/ - - G_LOCK (gphoto2_volume); - - data = g_new0 (ForeignMountOp, 1); - data->enclosing_volume = gphoto2_volume; - data->callback = callback; - data->user_data = user_data; - - g_file_mount_enclosing_volume (gphoto2_volume->foreign_mount_root, - 0, - mount_operation, - cancellable, - mount_foreign_callback, - data); - - G_UNLOCK (gphoto2_volume); -} - -static gboolean -g_gphoto2_volume_mount_finish (GVolume *volume, - GAsyncResult *result, - GError **error) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - gboolean res; - - G_LOCK (gphoto2_volume); - res = g_file_mount_enclosing_volume_finish (gphoto2_volume->foreign_mount_root, result, error); - G_UNLOCK (gphoto2_volume); - - return res; -} - -static char * -g_gphoto2_volume_get_identifier (GVolume *volume, - const char *kind) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - char *id; - - G_LOCK (gphoto2_volume); - id = NULL; - if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_HAL_UDI) == 0) - id = g_strdup (hal_device_get_udi (gphoto2_volume->device)); - else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) == 0) - id = g_strdup (gphoto2_volume->device_path); - G_UNLOCK (gphoto2_volume); - - return id; -} - -static char ** -g_gphoto2_volume_enumerate_identifiers (GVolume *volume) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - GPtrArray *res; - - G_LOCK (gphoto2_volume); - - res = g_ptr_array_new (); - - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_HAL_UDI)); - - if (gphoto2_volume->device_path && *gphoto2_volume->device_path != 0) - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE)); - - /* Null-terminate */ - g_ptr_array_add (res, NULL); - - G_UNLOCK (gphoto2_volume); - - return (char **)g_ptr_array_free (res, FALSE); -} - -static GFile * -g_gphoto2_volume_get_activation_root (GVolume *volume) -{ - GGPhoto2Volume *gphoto2_volume = G_GPHOTO2_VOLUME (volume); - - return g_object_ref (gphoto2_volume->foreign_mount_root); -} - -static void -g_gphoto2_volume_volume_iface_init (GVolumeIface *iface) -{ - iface->get_name = g_gphoto2_volume_get_name; - iface->get_icon = g_gphoto2_volume_get_icon; - iface->get_uuid = g_gphoto2_volume_get_uuid; - iface->get_drive = g_gphoto2_volume_get_drive; - iface->get_mount = g_gphoto2_volume_get_mount; - iface->can_mount = g_gphoto2_volume_can_mount; - iface->can_eject = g_gphoto2_volume_can_eject; - iface->should_automount = g_gphoto2_volume_should_automount; - iface->mount_fn = g_gphoto2_volume_mount; - iface->mount_finish = g_gphoto2_volume_mount_finish; - iface->eject = NULL; - iface->eject_finish = NULL; - iface->get_identifier = g_gphoto2_volume_get_identifier; - iface->enumerate_identifiers = g_gphoto2_volume_enumerate_identifiers; - iface->get_activation_root = g_gphoto2_volume_get_activation_root; -} diff --git a/gnome-2-24/monitor/gphoto2/ggphoto2volume.h b/gnome-2-24/monitor/gphoto2/ggphoto2volume.h deleted file mode 100644 index 20fe486a..00000000 --- a/gnome-2-24/monitor/gphoto2/ggphoto2volume.h +++ /dev/null @@ -1,66 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_GPHOTO2_VOLUME_H__ -#define __G_GPHOTO2_VOLUME_H__ - -#include -#include - -#include "hal-pool.h" -#include "ggphoto2volumemonitor.h" - -G_BEGIN_DECLS - -#define G_TYPE_GPHOTO2_VOLUME (g_gphoto2_volume_get_type ()) -#define G_GPHOTO2_VOLUME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_GPHOTO2_VOLUME, GGPhoto2Volume)) -#define G_GPHOTO2_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_GPHOTO2_VOLUME, GGPhoto2VolumeClass)) -#define G_IS_GPHOTO2_VOLUME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_GPHOTO2_VOLUME)) -#define G_IS_GPHOTO2_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_GPHOTO2_VOLUME)) - -typedef struct _GGPhoto2VolumeClass GGPhoto2VolumeClass; - -struct _GGPhoto2VolumeClass { - GObjectClass parent_class; -}; - -GType g_gphoto2_volume_get_type (void) G_GNUC_CONST; - -GGPhoto2Volume *g_gphoto2_volume_new (GVolumeMonitor *volume_monitor, - HalDevice *device, - HalPool *pool, - GFile *foreign_mount_root); - -gboolean g_gphoto2_volume_has_udi (GGPhoto2Volume *volume, - const char *udi); - -gboolean g_gphoto2_volume_has_foreign_mount_root (GGPhoto2Volume *volume, - GFile *mount_root); - -void g_gphoto2_volume_adopt_foreign_mount (GGPhoto2Volume *volume, - GMount *foreign_mount); - -void g_gphoto2_volume_removed (GGPhoto2Volume *volume); - -G_END_DECLS - -#endif /* __G_GPHOTO2_VOLUME_H__ */ diff --git a/gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.c b/gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.c deleted file mode 100644 index 5b8e8341..00000000 --- a/gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.c +++ /dev/null @@ -1,564 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "ggphoto2volumemonitor.h" -#include "ggphoto2volume.h" - -#include "hal-pool.h" - -G_LOCK_DEFINE_STATIC(hal_vm); - -static GGPhoto2VolumeMonitor *the_volume_monitor = NULL; -static HalPool *pool = NULL; - -struct _GGPhoto2VolumeMonitor { - GNativeVolumeMonitor parent; - - GUnixMountMonitor *mount_monitor; - - HalPool *pool; - - GList *last_camera_devices; - - GList *camera_volumes; -}; - -static void hal_changed (HalPool *pool, - HalDevice *device, - gpointer user_data); - -static void update_all (GGPhoto2VolumeMonitor *monitor, - gboolean emit_changes); - -static void update_cameras (GGPhoto2VolumeMonitor *monitor, - GList **added_volumes, - GList **removed_volumes); - - -G_DEFINE_TYPE (GGPhoto2VolumeMonitor, g_gphoto2_volume_monitor, G_TYPE_VOLUME_MONITOR) - -static void -list_free (GList *objects) -{ - g_list_foreach (objects, (GFunc)g_object_unref, NULL); - g_list_free (objects); -} - -static HalPool * -get_hal_pool (void) -{ - char *cap_only[] = {"camera", "portable_audio_player", "usb_device", NULL}; - - if (pool == NULL) - pool = hal_pool_new (cap_only); - - return pool; -} - -static void -g_gphoto2_volume_monitor_dispose (GObject *object) -{ - GGPhoto2VolumeMonitor *monitor; - - monitor = G_GPHOTO2_VOLUME_MONITOR (object); - - G_LOCK (hal_vm); - the_volume_monitor = NULL; - G_UNLOCK (hal_vm); - - if (G_OBJECT_CLASS (g_gphoto2_volume_monitor_parent_class)->dispose) - (*G_OBJECT_CLASS (g_gphoto2_volume_monitor_parent_class)->dispose) (object); -} - -static void -g_gphoto2_volume_monitor_finalize (GObject *object) -{ - GGPhoto2VolumeMonitor *monitor; - - monitor = G_GPHOTO2_VOLUME_MONITOR (object); - - g_signal_handlers_disconnect_by_func (monitor->pool, hal_changed, monitor); - - g_object_unref (monitor->pool); - - list_free (monitor->last_camera_devices); - list_free (monitor->camera_volumes); - - if (G_OBJECT_CLASS (g_gphoto2_volume_monitor_parent_class)->finalize) - (*G_OBJECT_CLASS (g_gphoto2_volume_monitor_parent_class)->finalize) (object); -} - -static GList * -get_mounts (GVolumeMonitor *volume_monitor) -{ - return NULL; -} - -static GList * -get_volumes (GVolumeMonitor *volume_monitor) -{ - GGPhoto2VolumeMonitor *monitor; - GList *l; - - monitor = G_GPHOTO2_VOLUME_MONITOR (volume_monitor); - - G_LOCK (hal_vm); - - l = g_list_copy (monitor->camera_volumes); - g_list_foreach (l, (GFunc)g_object_ref, NULL); - - G_UNLOCK (hal_vm); - - return l; -} - -static GList * -get_connected_drives (GVolumeMonitor *volume_monitor) -{ - return NULL; -} - -static GVolume * -get_volume_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid) -{ - return NULL; -} - -static GMount * -get_mount_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid) -{ - return NULL; -} - -static void -hal_changed (HalPool *pool, - HalDevice *device, - gpointer user_data) -{ - GGPhoto2VolumeMonitor *monitor = G_GPHOTO2_VOLUME_MONITOR (user_data); - - /*g_warning ("hal changed");*/ - - update_all (monitor, TRUE); -} - -static GObject * -g_gphoto2_volume_monitor_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *object; - GGPhoto2VolumeMonitor *monitor; - GGPhoto2VolumeMonitorClass *klass; - GObjectClass *parent_class; - - G_LOCK (hal_vm); - if (the_volume_monitor != NULL) - { - object = g_object_ref (the_volume_monitor); - G_UNLOCK (hal_vm); - return object; - } - G_UNLOCK (hal_vm); - - /*g_warning ("creating hal vm");*/ - - object = NULL; - - /* Invoke parent constructor. */ - klass = G_GPHOTO2_VOLUME_MONITOR_CLASS (g_type_class_peek (G_TYPE_GPHOTO2_VOLUME_MONITOR)); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - object = parent_class->constructor (type, - n_construct_properties, - construct_properties); - - monitor = G_GPHOTO2_VOLUME_MONITOR (object); - monitor->pool = g_object_ref (get_hal_pool ()); - - g_signal_connect (monitor->pool, - "device_added", G_CALLBACK (hal_changed), - monitor); - - g_signal_connect (monitor->pool, - "device_removed", G_CALLBACK (hal_changed), - monitor); - - update_all (monitor, FALSE); - - G_LOCK (hal_vm); - the_volume_monitor = monitor; - G_UNLOCK (hal_vm); - - return object; -} - -static void -g_gphoto2_volume_monitor_init (GGPhoto2VolumeMonitor *monitor) -{ -} - -static gboolean -is_supported (void) -{ - return get_hal_pool() != NULL; -} - -static GVolume * -adopt_orphan_mount (GMount *mount, GVolumeMonitor *monitor) -{ - GList *l; - GFile *mount_root; - GVolume *ret; - - /* This is called by the union volume monitor which does - have a ref to this. So its guaranteed to live, unfortunately - the pointer is not passed as an argument :/ - */ - ret = NULL; - - G_LOCK (hal_vm); - if (the_volume_monitor == NULL) - { - G_UNLOCK (hal_vm); - return NULL; - } - - mount_root = g_mount_get_root (mount); - - /* gphoto2:// are foreign mounts */ - for (l = the_volume_monitor->camera_volumes; l != NULL; l = l->next) - { - GGPhoto2Volume *volume = l->data; - - if (g_gphoto2_volume_has_foreign_mount_root (volume, mount_root)) - { - g_gphoto2_volume_adopt_foreign_mount (volume, mount); - ret = g_object_ref (volume); - goto found; - } - } - - found: - g_object_unref (mount_root); - - G_UNLOCK (hal_vm); - return ret; -} - -static void -g_gphoto2_volume_monitor_class_init (GGPhoto2VolumeMonitorClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GVolumeMonitorClass *monitor_class = G_VOLUME_MONITOR_CLASS (klass); - - gobject_class->constructor = g_gphoto2_volume_monitor_constructor; - gobject_class->finalize = g_gphoto2_volume_monitor_finalize; - gobject_class->dispose = g_gphoto2_volume_monitor_dispose; - - monitor_class->get_mounts = get_mounts; - monitor_class->get_volumes = get_volumes; - monitor_class->get_connected_drives = get_connected_drives; - monitor_class->get_volume_for_uuid = get_volume_for_uuid; - monitor_class->get_mount_for_uuid = get_mount_for_uuid; - monitor_class->adopt_orphan_mount = adopt_orphan_mount; - monitor_class->is_supported = is_supported; -} - -/** - * g_gphoto2_volume_monitor_new: - * - * Returns: a new #GVolumeMonitor. - **/ -GVolumeMonitor * -g_gphoto2_volume_monitor_new (void) -{ - GGPhoto2VolumeMonitor *monitor; - - monitor = g_object_new (G_TYPE_GPHOTO2_VOLUME_MONITOR, NULL); - - return G_VOLUME_MONITOR (monitor); -} - -static void -diff_sorted_lists (GList *list1, - GList *list2, - GCompareFunc compare, - GList **added, - GList **removed) -{ - int order; - - *added = *removed = NULL; - - while (list1 != NULL && - list2 != NULL) - { - order = (*compare) (list1->data, list2->data); - if (order < 0) - { - *removed = g_list_prepend (*removed, list1->data); - list1 = list1->next; - } - else if (order > 0) - { - *added = g_list_prepend (*added, list2->data); - list2 = list2->next; - } - else - { /* same item */ - list1 = list1->next; - list2 = list2->next; - } - } - - while (list1 != NULL) - { - *removed = g_list_prepend (*removed, list1->data); - list1 = list1->next; - } - while (list2 != NULL) - { - *added = g_list_prepend (*added, list2->data); - list2 = list2->next; - } -} - -static GGPhoto2Volume * -find_camera_volume_by_udi (GGPhoto2VolumeMonitor *monitor, const char *udi) -{ - GList *l; - - for (l = monitor->camera_volumes; l != NULL; l = l->next) - { - GGPhoto2Volume *volume = l->data; - - if (g_gphoto2_volume_has_udi (volume, udi)) - return volume; - } - - return NULL; -} - -static gint -hal_device_compare (HalDevice *a, HalDevice *b) -{ - return strcmp (hal_device_get_udi (a), hal_device_get_udi (b)); -} - -static void -list_emit (GGPhoto2VolumeMonitor *monitor, - const char *monitor_signal, - const char *object_signal, - GList *objects) -{ - GList *l; - - for (l = objects; l != NULL; l = l->next) - { - g_signal_emit_by_name (monitor, monitor_signal, l->data); - if (object_signal) - g_signal_emit_by_name (l->data, object_signal); - } -} - -typedef struct { - GGPhoto2VolumeMonitor *monitor; - GList *added_volumes, *removed_volumes; -} ChangedLists; - - -static gboolean -emit_lists_in_idle (gpointer data) -{ - ChangedLists *lists = data; - - list_emit (lists->monitor, - "volume_removed", "removed", - lists->removed_volumes); - list_emit (lists->monitor, - "volume_added", NULL, - lists->added_volumes); - - list_free (lists->removed_volumes); - list_free (lists->added_volumes); - g_object_unref (lists->monitor); - g_free (lists); - - return FALSE; -} - -/* Must be called from idle if emit_changes, with no locks held */ -static void -update_all (GGPhoto2VolumeMonitor *monitor, - gboolean emit_changes) -{ - ChangedLists *lists; - GList *added_volumes, *removed_volumes; - - added_volumes = NULL; - removed_volumes = NULL; - - G_LOCK (hal_vm); - update_cameras (monitor, &added_volumes, &removed_volumes); - G_UNLOCK (hal_vm); - - if (emit_changes) - { - lists = g_new0 (ChangedLists, 1); - lists->monitor = g_object_ref (monitor); - lists->added_volumes = added_volumes; - lists->removed_volumes = removed_volumes; - - g_idle_add (emit_lists_in_idle, lists); - } - else - { - list_free (removed_volumes); - list_free (added_volumes); - } -} - -static void -update_cameras (GGPhoto2VolumeMonitor *monitor, - GList **added_volumes, - GList **removed_volumes) -{ - GList *new_camera_devices; - GList *new_mtp_devices; - GList *removed, *added; - GList *l, *ll; - GGPhoto2Volume *volume; - const char *udi; - - new_mtp_devices = hal_pool_find_by_capability (monitor->pool, "portable_audio_player"); - for (l = new_mtp_devices; l != NULL; l = ll) - { - HalDevice *d = l->data; - ll = l->next; - if (! hal_device_get_property_bool (d, "camera.libgphoto2.support")) - { - /*g_warning ("ignoring %s", hal_device_get_udi (d));*/ - /* filter out everything that isn't supported by libgphoto2 */ - new_mtp_devices = g_list_delete_link (new_mtp_devices, l); - } - } - - new_camera_devices = hal_pool_find_by_capability (monitor->pool, "camera"); - new_camera_devices = g_list_concat (new_camera_devices, new_mtp_devices); - for (l = new_camera_devices; l != NULL; l = ll) - { - HalDevice *d = l->data; - ll = l->next; - /*g_warning ("got %s", hal_device_get_udi (d));*/ - if (! hal_device_get_property_bool (d, "camera.libgphoto2.support")) - { - /*g_warning ("ignoring %s", hal_device_get_udi (d));*/ - /* filter out everything that isn't supported by libgphoto2 */ - new_camera_devices = g_list_delete_link (new_camera_devices, l); - } - } - g_list_foreach (new_camera_devices, (GFunc) g_object_ref, NULL); - - new_camera_devices = g_list_sort (new_camera_devices, (GCompareFunc) hal_device_compare); - diff_sorted_lists (monitor->last_camera_devices, - new_camera_devices, (GCompareFunc) hal_device_compare, - &added, &removed); - - for (l = removed; l != NULL; l = l->next) - { - HalDevice *d = l->data; - - udi = hal_device_get_udi (d); - /*g_warning ("camera removing %s", udi);*/ - - volume = find_camera_volume_by_udi (monitor, udi); - if (volume != NULL) - { - g_gphoto2_volume_removed (volume); - monitor->camera_volumes = g_list_remove (monitor->camera_volumes, volume); - *removed_volumes = g_list_prepend (*removed_volumes, volume); - } - } - - for (l = added; l != NULL; l = l->next) - { - HalDevice *d = l->data; - char *uri; - GFile *foreign_mount_root; - int usb_bus_num; - int usb_device_num; - gboolean found; - - /* Look for the device in the added volumes, so as - * not to add devices that are both audio players, and cameras */ - found = FALSE; - for (ll = *added_volumes; ll; ll = ll->next) - { - if (g_gphoto2_volume_has_udi (ll->data, hal_device_get_udi (d)) != FALSE) - { - found = TRUE; - break; - } - } - - if (found) - continue; - - usb_bus_num = hal_device_get_property_int (d, "usb.bus_number"); - usb_device_num = hal_device_get_property_int (d, "usb.linux.device_number"); - - uri = g_strdup_printf ("gphoto2://[usb:%03d,%03d]", usb_bus_num, usb_device_num); - /*g_warning ("uri is '%s'", uri);*/ - foreign_mount_root = g_file_new_for_uri (uri); - g_free (uri); - - udi = hal_device_get_udi (d); - /*g_warning ("camera adding %s", udi);*/ - - volume = g_gphoto2_volume_new (G_VOLUME_MONITOR (monitor), - d, - monitor->pool, - foreign_mount_root); - g_object_unref (foreign_mount_root); - if (volume != NULL) - { - monitor->camera_volumes = g_list_prepend (monitor->camera_volumes, volume); - *added_volumes = g_list_prepend (*added_volumes, g_object_ref (volume)); - } - } - - g_list_free (added); - g_list_free (removed); - list_free (monitor->last_camera_devices); - monitor->last_camera_devices = new_camera_devices; -} diff --git a/gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.h b/gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.h deleted file mode 100644 index fcb74fef..00000000 --- a/gnome-2-24/monitor/gphoto2/ggphoto2volumemonitor.h +++ /dev/null @@ -1,54 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_GPHOTO2_VOLUME_MONITOR_H__ -#define __G_GPHOTO2_VOLUME_MONITOR_H__ - -#include -#include - -G_BEGIN_DECLS - -#define G_TYPE_GPHOTO2_VOLUME_MONITOR (g_gphoto2_volume_monitor_get_type ()) -#define G_GPHOTO2_VOLUME_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_GPHOTO2_VOLUME_MONITOR, GGPhoto2VolumeMonitor)) -#define G_GPHOTO2_VOLUME_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_GPHOTO2_VOLUME_MONITOR, GGPhoto2VolumeMonitorClass)) -#define G_IS_GPHOTO2_VOLUME_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_GPHOTO2_VOLUME_MONITOR)) -#define G_IS_GPHOTO2_VOLUME_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_GPHOTO2_VOLUME_MONITOR)) - -typedef struct _GGPhoto2VolumeMonitor GGPhoto2VolumeMonitor; -typedef struct _GGPhoto2VolumeMonitorClass GGPhoto2VolumeMonitorClass; - -/* Forward definitions */ -typedef struct _GGPhoto2Volume GGPhoto2Volume; - -struct _GGPhoto2VolumeMonitorClass { - GVolumeMonitorClass parent_class; -}; - -GType g_gphoto2_volume_monitor_get_type (void) G_GNUC_CONST; - -GVolumeMonitor *g_gphoto2_volume_monitor_new (void); -void g_gphoto2_volume_monitor_force_update (GGPhoto2VolumeMonitor *monitor); - -G_END_DECLS - -#endif /* __G_GPHOTO2_VOLUME_MONITOR_H__ */ diff --git a/gnome-2-24/monitor/gphoto2/gphoto2-volume-monitor-daemon.c b/gnome-2-24/monitor/gphoto2/gphoto2-volume-monitor-daemon.c deleted file mode 100644 index f4998f35..00000000 --- a/gnome-2-24/monitor/gphoto2/gphoto2-volume-monitor-daemon.c +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include -#include - -#include - -#include "ggphoto2volumemonitor.h" - -int -main (int argc, char *argv[]) -{ - g_vfs_proxy_volume_monitor_daemon_init (); - return g_vfs_proxy_volume_monitor_daemon_main (argc, - argv, - "org.gtk.Private.GPhoto2VolumeMonitor", - G_TYPE_GPHOTO2_VOLUME_MONITOR); -} diff --git a/gnome-2-24/monitor/gphoto2/gphoto2.monitor b/gnome-2-24/monitor/gphoto2/gphoto2.monitor deleted file mode 100644 index e0a69852..00000000 --- a/gnome-2-24/monitor/gphoto2/gphoto2.monitor +++ /dev/null @@ -1,4 +0,0 @@ -[RemoteVolumeMonitor] -Name=GProxyVolumeMonitorGPhoto2 -DBusName=org.gtk.Private.GPhoto2VolumeMonitor -IsNative=false diff --git a/gnome-2-24/monitor/gphoto2/hal-device.c b/gnome-2-24/monitor/gphoto2/hal-device.c deleted file mode 100644 index 9f0b5bc3..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-device.c +++ /dev/null @@ -1,297 +0,0 @@ -/* hal-device.c - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include "hal-device.h" -#include "hal-marshal.h" - -struct _HalDevicePrivate -{ - LibHalContext *hal_ctx; - LibHalPropertySet *properties; - char *udi; - GTimeVal time_added; -}; - -enum { - HAL_PROPERTY_CHANGED, - HAL_CONDITION, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (HalDevice, hal_device, G_TYPE_OBJECT) - -static void -hal_device_finalize (HalDevice *device) -{ - if (device->priv->properties != NULL) - libhal_free_property_set (device->priv->properties); - g_free (device->priv->udi); - - if (G_OBJECT_CLASS (hal_device_parent_class)->finalize) - (* G_OBJECT_CLASS (hal_device_parent_class)->finalize) (G_OBJECT (device)); -} - -static void -hal_device_class_init (HalDeviceClass *klass) -{ - GObjectClass *obj_class = (GObjectClass *) klass; - - obj_class->finalize = (GObjectFinalizeFunc) hal_device_finalize; - - signals[HAL_PROPERTY_CHANGED] = - g_signal_new ("hal_property_changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalDeviceClass, hal_property_changed), - NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, - G_TYPE_STRING); - - signals[HAL_CONDITION] = - g_signal_new ("hal_condition", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalDeviceClass, hal_condition), - NULL, NULL, - hal_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_STRING); -} - -static void -hal_device_init (HalDevice *device) -{ - device->priv = g_new0 (HalDevicePrivate, 1); - g_get_current_time (&(device->priv->time_added)); -} - -const char * -hal_device_get_property_string (HalDevice *device, const char *key) -{ - const char *ret; - - ret = libhal_ps_get_string (device->priv->properties, key); - if (ret != NULL) - return ret; - - /* play it safe and don't make clients crash */ - return ""; -} - -int -hal_device_get_property_int (HalDevice *device, const char *key) -{ - return libhal_ps_get_int32 (device->priv->properties, key); -} - -double -hal_device_get_property_double (HalDevice *device, const char *key) -{ - return libhal_ps_get_double (device->priv->properties, key); -} - -guint64 -hal_device_get_property_uint64 (HalDevice *device, const char *key) -{ - return libhal_ps_get_uint64 (device->priv->properties, key); -} - -gboolean -hal_device_get_property_bool (HalDevice *device, const char *key) -{ - return libhal_ps_get_bool (device->priv->properties, key); -} - -char ** -hal_device_get_property_strlist (HalDevice *device, const char *key) -{ - static char * empty[1] = {NULL}; - char **ret; - - ret = (char **) libhal_ps_get_strlist (device->priv->properties, key); - if (ret != NULL) - return (char **) ret; - - /* play it safe and don't make clients crash */ - return empty; -} - -gboolean -hal_device_has_capability (HalDevice *device, const char *capability) -{ - int n; - char **caps; - gboolean ret; - - ret = FALSE; - caps = hal_device_get_property_strlist (device, "info.capabilities"); - if (caps == NULL) - goto out; - - for (n = 0; caps[n] != NULL; n++) - { - if (g_ascii_strcasecmp (caps[n], capability) == 0) - { - ret = TRUE; - break; - } - } - - out: - return ret; -} - -gboolean -hal_device_has_interface (HalDevice *device, const char *interface) -{ - int n; - char **ifs; - gboolean ret; - - ret = FALSE; - ifs = hal_device_get_property_strlist (device, "info.interfaces"); - if (ifs == NULL) - goto out; - - for (n = 0; ifs[n] != NULL; n++) - { - if (g_ascii_strcasecmp (ifs[n], interface) == 0) - { - ret = TRUE; - break; - } - } - -out: - return ret; -} - -gboolean -hal_device_has_property (HalDevice *device, const char *key) -{ - gboolean ret; - LibHalPropertySetIterator it; - - ret = FALSE; - if (device->priv->properties == NULL) - goto out; - - libhal_psi_init (&it, device->priv->properties); - - while (libhal_psi_has_more (&it)) - { - char *pkey = libhal_psi_get_key (&it); - - if (pkey != NULL && g_ascii_strcasecmp (pkey, key) == 0) - { - ret = TRUE; - break; - } - libhal_psi_next (&it); - } - - out: - return ret; -} - - -HalDevice * -hal_device_new_from_udi (LibHalContext *hal_ctx, const char *udi) -{ - HalDevice *device; - - device = HAL_DEVICE (g_object_new (HAL_TYPE_DEVICE, NULL)); - device->priv->udi = g_strdup (udi); - device->priv->hal_ctx = hal_ctx; - device->priv->properties = libhal_device_get_all_properties (hal_ctx, udi, NULL); - return device; -} - -HalDevice * -hal_device_new_from_udi_and_properties (LibHalContext *hal_ctx, - char *udi, - LibHalPropertySet *properties) -{ - HalDevice *device; - - device = HAL_DEVICE (g_object_new (HAL_TYPE_DEVICE, NULL)); - device->priv->udi = g_strdup (udi); - device->priv->hal_ctx = hal_ctx; - device->priv->properties = properties; - return device; -} - -void -_hal_device_hal_property_changed (HalDevice *device, const char *key); - -void -_hal_device_hal_condition (HalDevice *device, const char *name, const char *detail); - -void -_hal_device_hal_property_changed (HalDevice *device, const char *key) -{ - LibHalPropertySet *new_props; - - new_props = libhal_device_get_all_properties (device->priv->hal_ctx, device->priv->udi, NULL); - if (new_props != NULL) - { - libhal_free_property_set (device->priv->properties); - device->priv->properties = new_props; - g_signal_emit (device, signals[HAL_PROPERTY_CHANGED], 0, key); - } -} - -void -_hal_device_hal_condition (HalDevice *device, const char *name, const char *detail) -{ - g_signal_emit (device, signals[HAL_CONDITION], 0, name, detail); -} - -const char * -hal_device_get_udi (HalDevice *device) -{ - return device->priv->udi; -} - -LibHalPropertySet * -hal_device_get_properties (HalDevice *device) -{ - return device->priv->properties; -} - -gboolean -hal_device_is_recently_plugged_in (HalDevice *device) -{ - GTimeVal now; - glong delta_msec; - - g_get_current_time (&now); - - delta_msec = (now.tv_sec - device->priv->time_added.tv_sec) * 1000 + - (now.tv_usec - device->priv->time_added.tv_usec) / 1000; - - return delta_msec < 2000; -} diff --git a/gnome-2-24/monitor/gphoto2/hal-device.h b/gnome-2-24/monitor/gphoto2/hal-device.h deleted file mode 100644 index 8e91aa63..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-device.h +++ /dev/null @@ -1,93 +0,0 @@ -/* hal-device.h - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef HAL_DEVICE_H -#define HAL_DEVICE_H - -#include -#include -#include - -#define HAL_TYPE_DEVICE (hal_device_get_type ()) -#define HAL_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HAL_TYPE_DEVICE, HalDevice)) -#define HAL_DEVICE_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), HAL_DEVICE, HalDeviceClass)) -#define HAL_IS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HAL_TYPE_DEVICE)) -#define HAL_IS_DEVICE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), HAL_TYPE_DEVICE)) -#define HAL_DEVICE_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), HAL_TYPE_DEVICE, HalDeviceClass)) - - -typedef struct _HalDevice HalDevice; -typedef struct _HalDeviceClass HalDeviceClass; - -struct _HalDevicePrivate; -typedef struct _HalDevicePrivate HalDevicePrivate; - -struct _HalDevice -{ - GObject parent; - - /* private */ - HalDevicePrivate *priv; -}; - -struct _HalDeviceClass -{ - GObjectClass parent_class; - - /* signals */ - void (*hal_property_changed) (HalDevice *device, const char *key); - void (*hal_condition) (HalDevice *device, const char *name, const char *detail); -}; - - -GType hal_device_get_type (void); - -HalDevice * hal_device_new_from_udi (LibHalContext *hal_ctx, - const char *udi); - -HalDevice * hal_device_new_from_udi_and_properties (LibHalContext *hal_ctx, - char *udi, - LibHalPropertySet *properties); - -const char * hal_device_get_udi (HalDevice *device); -LibHalPropertySet * hal_device_get_properties (HalDevice *device); -const char * hal_device_get_property_string (HalDevice *device, - const char *key); -int hal_device_get_property_int (HalDevice *device, - const char *key); -guint64 hal_device_get_property_uint64 (HalDevice *device, - const char *key); -double hal_device_get_property_double (HalDevice *device, - const char *key); -gboolean hal_device_get_property_bool (HalDevice *device, - const char *key); -char ** hal_device_get_property_strlist (HalDevice *device, - const char *key); - -gboolean hal_device_has_property (HalDevice *device, - const char *key); -gboolean hal_device_has_capability (HalDevice *device, - const char *capability); -gboolean hal_device_has_interface (HalDevice *device, - const char *interface); - -gboolean hal_device_is_recently_plugged_in (HalDevice *device); - -#endif /* HAL_DEVICE_H */ diff --git a/gnome-2-24/monitor/gphoto2/hal-marshal.c b/gnome-2-24/monitor/gphoto2/hal-marshal.c deleted file mode 100644 index 75fec6e4..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-marshal.c +++ /dev/null @@ -1,163 +0,0 @@ -#include "hal-marshal.h" - -#include - - -#ifdef G_ENABLE_DEBUG -#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v) -#define g_marshal_value_peek_char(v) g_value_get_char (v) -#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v) -#define g_marshal_value_peek_int(v) g_value_get_int (v) -#define g_marshal_value_peek_uint(v) g_value_get_uint (v) -#define g_marshal_value_peek_long(v) g_value_get_long (v) -#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v) -#define g_marshal_value_peek_int64(v) g_value_get_int64 (v) -#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v) -#define g_marshal_value_peek_enum(v) g_value_get_enum (v) -#define g_marshal_value_peek_flags(v) g_value_get_flags (v) -#define g_marshal_value_peek_float(v) g_value_get_float (v) -#define g_marshal_value_peek_double(v) g_value_get_double (v) -#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v) -#define g_marshal_value_peek_param(v) g_value_get_param (v) -#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v) -#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v) -#define g_marshal_value_peek_object(v) g_value_get_object (v) -#else /* !G_ENABLE_DEBUG */ -/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API. - * Do not access GValues directly in your code. Instead, use the - * g_value_get_*() functions - */ -#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int -#define g_marshal_value_peek_char(v) (v)->data[0].v_int -#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint -#define g_marshal_value_peek_int(v) (v)->data[0].v_int -#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint -#define g_marshal_value_peek_long(v) (v)->data[0].v_long -#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong -#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64 -#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64 -#define g_marshal_value_peek_enum(v) (v)->data[0].v_long -#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong -#define g_marshal_value_peek_float(v) (v)->data[0].v_float -#define g_marshal_value_peek_double(v) (v)->data[0].v_double -#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer -#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer -#endif /* !G_ENABLE_DEBUG */ - - -/* VOID:OBJECT,STRING (hal-marshal.list:1) */ -void -hal_marshal_VOID__OBJECT_STRING (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__OBJECT_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer data2); - register GMarshalFunc_VOID__OBJECT_STRING callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__OBJECT_STRING) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_object (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - data2); -} - -/* VOID:OBJECT,STRING,STRING (hal-marshal.list:2) */ -void -hal_marshal_VOID__OBJECT_STRING_STRING (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__OBJECT_STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_VOID__OBJECT_STRING_STRING callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 4); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__OBJECT_STRING_STRING) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_object (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - g_marshal_value_peek_string (param_values + 3), - data2); -} - -/* VOID:STRING,STRING (hal-marshal.list:3) */ -void -hal_marshal_VOID__STRING_STRING (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer data2); - register GMarshalFunc_VOID__STRING_STRING callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__STRING_STRING) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - data2); -} - diff --git a/gnome-2-24/monitor/gphoto2/hal-marshal.h b/gnome-2-24/monitor/gphoto2/hal-marshal.h deleted file mode 100644 index 0ac3074c..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-marshal.h +++ /dev/null @@ -1,36 +0,0 @@ - -#ifndef __hal_marshal_MARSHAL_H__ -#define __hal_marshal_MARSHAL_H__ - -#include - -G_BEGIN_DECLS - -/* VOID:OBJECT,STRING (hal-marshal.list:1) */ -extern void hal_marshal_VOID__OBJECT_STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:OBJECT,STRING,STRING (hal-marshal.list:2) */ -extern void hal_marshal_VOID__OBJECT_STRING_STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:STRING,STRING (hal-marshal.list:3) */ -extern void hal_marshal_VOID__STRING_STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -G_END_DECLS - -#endif /* __hal_marshal_MARSHAL_H__ */ - diff --git a/gnome-2-24/monitor/gphoto2/hal-marshal.list b/gnome-2-24/monitor/gphoto2/hal-marshal.list deleted file mode 100644 index 52c82338..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-marshal.list +++ /dev/null @@ -1,3 +0,0 @@ -VOID:OBJECT,STRING -VOID:OBJECT,STRING,STRING -VOID:STRING,STRING diff --git a/gnome-2-24/monitor/gphoto2/hal-pool.c b/gnome-2-24/monitor/gphoto2/hal-pool.c deleted file mode 100644 index 770effd9..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-pool.c +++ /dev/null @@ -1,458 +0,0 @@ -/* hal-pool.c - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include -#include - -#include - -#include "hal-pool.h" -#include "hal-marshal.h" - -enum { - DEVICE_ADDED, - DEVICE_REMOVED, - DEVICE_PROPERTY_CHANGED, - DEVICE_CONDITION, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -struct _HalPoolPrivate -{ - char **cap_only; - - DBusConnection *dbus_connection; - LibHalContext *hal_ctx; - GHashTable *devices; -}; - -G_DEFINE_TYPE (HalPool, hal_pool, G_TYPE_OBJECT) - -static void -hal_pool_finalize (HalPool *pool) -{ - g_strfreev (pool->priv->cap_only); - - dbus_bus_remove_match (pool->priv->dbus_connection, - "type='signal'," - "interface='org.freedesktop.Hal.Device'," - "sender='org.freedesktop.Hal'", NULL); - libhal_ctx_shutdown (pool->priv->hal_ctx, NULL); - dbus_connection_close (pool->priv->dbus_connection); - dbus_connection_unref (pool->priv->dbus_connection); - - if (G_OBJECT_CLASS (hal_pool_parent_class)->finalize) - (* G_OBJECT_CLASS (hal_pool_parent_class)->finalize) (G_OBJECT (pool)); -} - -static void -hal_pool_class_init (HalPoolClass *klass) -{ - GObjectClass *obj_class = (GObjectClass *) klass; - - obj_class->finalize = (GObjectFinalizeFunc) hal_pool_finalize; - - g_type_class_ref (HAL_TYPE_DEVICE); - - signals[DEVICE_ADDED] = - g_signal_new ("device_added", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - HAL_TYPE_DEVICE); - - signals[DEVICE_REMOVED] = - g_signal_new ("device_removed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - HAL_TYPE_DEVICE); - - signals[DEVICE_PROPERTY_CHANGED] = - g_signal_new ("device_property_changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_property_changed), - NULL, NULL, - hal_marshal_VOID__OBJECT_STRING, - G_TYPE_NONE, 2, - HAL_TYPE_DEVICE, - G_TYPE_STRING); - - signals[DEVICE_CONDITION] = - g_signal_new ("device_condition", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_condition), - NULL, NULL, - hal_marshal_VOID__OBJECT_STRING_STRING, - G_TYPE_NONE, 3, - HAL_TYPE_DEVICE, - G_TYPE_STRING, - G_TYPE_STRING); -} - -static void -hal_pool_init (HalPool *pool) -{ - pool->priv = g_new0 (HalPoolPrivate, 1); - pool->priv->hal_ctx = NULL; -} - -static gboolean -has_cap_only (HalPool *pool, HalDevice *device) -{ - const char *subsys; - unsigned int n; - - for (n = 0; pool->priv->cap_only != NULL && pool->priv->cap_only[n] != NULL; n++) - { - if (hal_device_has_capability (device, pool->priv->cap_only[n])) - return TRUE; - - subsys = hal_device_get_property_string (device, "info.subsystem"); - - if (subsys != NULL && strcmp (subsys, pool->priv->cap_only[n]) == 0) - return TRUE; - } - - return FALSE; -} - -static void -hal_pool_add_device_by_udi (HalPool *pool, - const char *udi, - gboolean emit_signal) -{ - HalDevice *device; - - device = hal_device_new_from_udi (pool->priv->hal_ctx, udi); - if (device != NULL) - { - if (!has_cap_only (pool, device)) - g_object_unref (device); - else - { - g_hash_table_insert (pool->priv->devices, g_strdup (udi), device); - if (emit_signal) - g_signal_emit (pool, signals[DEVICE_ADDED], 0, device); - } - } -} - -#ifdef HAVE_HAL_FAST_INIT -static void -hal_pool_add_device_by_udi_and_properties (HalPool *pool, - char *udi, - LibHalPropertySet *properties, - gboolean emit_signal) -{ - HalDevice *device; - - device = hal_device_new_from_udi_and_properties (pool->priv->hal_ctx, udi, properties); - if (device != NULL) - { - if (!has_cap_only (pool, device)) - g_object_unref (device); - else - { - g_hash_table_insert (pool->priv->devices, g_strdup (udi), device); - if (emit_signal) - g_signal_emit (pool, signals[DEVICE_ADDED], 0, device); - } - } -} -#endif - -static void -_hal_device_added (LibHalContext *hal_ctx, const char *udi) -{ - HalPool *pool; - - pool = HAL_POOL (libhal_ctx_get_user_data (hal_ctx)); - hal_pool_add_device_by_udi (pool, udi, TRUE); -} - -static void -_hal_device_removed (LibHalContext *hal_ctx, const char *udi) -{ - HalPool *pool; - HalDevice *device; - - pool = HAL_POOL (libhal_ctx_get_user_data (hal_ctx)); - if ((device = hal_pool_get_device_by_udi (pool, udi)) != NULL) - { - g_object_ref (device); - g_hash_table_remove (pool->priv->devices, udi); - g_signal_emit (pool, signals[DEVICE_REMOVED], 0, device); - g_object_unref (device); - } -} - -void -_hal_device_hal_property_changed (HalDevice *device, const char *key); - -void -_hal_device_hal_condition (HalDevice *device, const char *name, const char *detail); - -static void -_hal_property_modified (LibHalContext *ctx, - const char *udi, - const char *key, - dbus_bool_t is_removed, - dbus_bool_t is_added) -{ - HalPool *pool; - HalDevice *device; - - pool = HAL_POOL (libhal_ctx_get_user_data (ctx)); - - device = hal_pool_get_device_by_udi (pool, udi); - if (device != NULL) - { - _hal_device_hal_property_changed (device, key); - g_signal_emit (pool, signals[DEVICE_PROPERTY_CHANGED], 0, device, key); - } -} - -static void -_hal_condition (LibHalContext *ctx, - const char *udi, - const char *condition_name, - const char *condition_detail) -{ - HalPool *pool; - HalDevice *device; - - pool = HAL_POOL (libhal_ctx_get_user_data (ctx)); - - device = hal_pool_get_device_by_udi (pool, udi); - if (device != NULL) - { - _hal_device_hal_condition (device, condition_name, condition_detail); - g_signal_emit (pool, signals[DEVICE_CONDITION], 0, device, condition_name, condition_detail); - } -} - -LibHalContext * -hal_pool_get_hal_ctx (HalPool *pool) -{ - return pool->priv->hal_ctx; -} - -DBusConnection * -hal_pool_get_dbus_connection (HalPool *pool) -{ - return pool->priv->dbus_connection; -} - -HalPool * -hal_pool_new (char **cap_only) -{ - int i; - char **devices; - int num_devices; - HalPool *pool; - LibHalContext *hal_ctx; - DBusError error; - DBusConnection *dbus_connection; -#ifdef HAVE_HAL_FAST_INIT - LibHalPropertySet **properties; -#endif - - pool = NULL; - - dbus_error_init (&error); - /* see discussion on gtk-devel-list (Subject: Re: gvfs hal volume monitoring backend) on - * why this is private - */ - dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &error); - if (dbus_error_is_set (&error)) - { - dbus_error_free (&error); - goto out; - } - - dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); - - hal_ctx = libhal_ctx_new (); - if (hal_ctx == NULL) - { - dbus_connection_close (dbus_connection); - dbus_connection_unref (dbus_connection); - goto out; - } - - _g_dbus_connection_integrate_with_main (dbus_connection); - libhal_ctx_set_dbus_connection (hal_ctx, dbus_connection); - - if (!libhal_ctx_init (hal_ctx, &error)) - { - dbus_connection_close (dbus_connection); - dbus_connection_unref (dbus_connection); - dbus_error_free (&error); - goto out; - } - - pool = HAL_POOL (g_object_new (HAL_TYPE_POOL, NULL)); - pool->priv->dbus_connection = dbus_connection; - pool->priv->hal_ctx = hal_ctx; - pool->priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - pool->priv->cap_only = g_strdupv (cap_only); - - /* Gah, unfortunately we have to watch all devices as HAL's PropertyModified signal - * doesn't include the capabilities... - */ - dbus_bus_add_match (dbus_connection, - "type='signal'," - "interface='org.freedesktop.Hal.Device'," - "sender='org.freedesktop.Hal'", NULL); - libhal_ctx_set_device_added (hal_ctx, _hal_device_added); - libhal_ctx_set_device_removed (hal_ctx, _hal_device_removed); - libhal_ctx_set_device_property_modified (hal_ctx, _hal_property_modified); - libhal_ctx_set_device_condition (hal_ctx, _hal_condition); - libhal_ctx_set_user_data (hal_ctx, pool); - -#ifdef HAVE_HAL_FAST_INIT - /* First try new O(1) algorithm to get all devices and properties in a single call.. - * - * This method is only available in post hal 0.5.10. - */ - if (libhal_get_all_devices_with_properties (pool->priv->hal_ctx, - &num_devices, - &devices, - &properties, - NULL)) - { - for (i = 0; i < num_devices; i++) - hal_pool_add_device_by_udi_and_properties (pool, devices[i], properties[i], FALSE); - libhal_free_string_array (devices); - free (properties); /* hal_pool_add_device_by_udi_and_properties steals the given properties */ - goto out; - } -#endif - - /* fallback to using O(n) algorithm; will work on any hal 0.5.x release */ - devices = libhal_get_all_devices (pool->priv->hal_ctx, &num_devices, NULL); - if (devices != NULL) - { - for (i = 0; i < num_devices; i++) - { - char *device_udi; - device_udi = devices[i]; - hal_pool_add_device_by_udi (pool, device_udi, FALSE); - } - libhal_free_string_array (devices); - goto out; - } - - /* FAIL! */ - - g_object_unref (pool); - return NULL; - - out: - return pool; -} - -HalDevice * -hal_pool_get_device_by_udi (HalPool *pool, const char *udi) -{ - return g_hash_table_lookup (pool->priv->devices, udi); -} - -HalDevice * -hal_pool_get_device_by_capability_and_string (HalPool *pool, - const char *capability, - const char *key, - const char *value) -{ - GList *i; - GList *devices; - HalDevice *result; - - result = NULL; - devices = NULL; - - if (pool->priv->devices == NULL) - goto out; - - devices = g_hash_table_get_values (pool->priv->devices); - for (i = devices; i != NULL; i = i->next) - { - HalDevice *d = i->data; - const char *s; - - if (!hal_device_has_capability (d, capability)) - continue; - - s = hal_device_get_property_string (d, key); - if (s == NULL) - continue; - - if (strcmp (s, value) == 0) - { - result = d; - goto out; - } - } - -out: - if (devices != NULL) - g_list_free (devices); - return result; -} - -GList * -hal_pool_find_by_capability (HalPool *pool, const char *capability) -{ - GList *i; - GList *j; - GList *devices; - - devices = NULL; - - if (pool->priv->devices == NULL) - goto out; - - devices = g_hash_table_get_values (pool->priv->devices); - for (i = devices; i != NULL; i = j) - { - HalDevice *d = i->data; - - j = i->next; - - if (!hal_device_has_capability (d, capability)) - devices = g_list_delete_link (devices, i); - } - - out: - return devices; -} diff --git a/gnome-2-24/monitor/gphoto2/hal-pool.h b/gnome-2-24/monitor/gphoto2/hal-pool.h deleted file mode 100644 index 04c8687d..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-pool.h +++ /dev/null @@ -1,74 +0,0 @@ -/* hal-pool.h - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#if !defined(HAL_POOL_H) -#define HAL_POOL_H - -#include -#include -#include "hal-device.h" - -#define HAL_TYPE_POOL (hal_pool_get_type ()) -#define HAL_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HAL_TYPE_POOL, HalPool)) -#define HAL_POOL_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), HAL_POOL, HalPoolClass)) -#define HAL_IS_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HAL_TYPE_POOL)) -#define HAL_IS_POOL_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), HAL_TYPE_POOL)) -#define HAL_POOL_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), HAL_TYPE_POOL, HalPoolClass)) - - -typedef struct _HalPool HalPool; -typedef struct _HalPoolClass HalPoolClass; - -struct _HalPoolPrivate; -typedef struct _HalPoolPrivate HalPoolPrivate; - -struct _HalPool -{ - GObject parent; - - /* private */ - HalPoolPrivate *priv; -}; - -struct _HalPoolClass -{ - GObjectClass parent_class; - - /* signals */ - void (*device_added) (HalPool *pool, HalDevice *device); - void (*device_removed) (HalPool *pool, HalDevice *device); - void (*device_property_changed) (HalPool *pool, HalDevice *device, const char *key); - void (*device_condition) (HalPool *pool, HalDevice *device, const char *name, const char *detail); -}; - -GType hal_pool_get_type (void); -HalPool * hal_pool_new (char **cap_only); -LibHalContext * hal_pool_get_hal_ctx (HalPool *pool); -DBusConnection * hal_pool_get_dbus_connection (HalPool *pool); -HalDevice * hal_pool_get_device_by_udi (HalPool *pool, - const char *udi); -HalDevice * hal_pool_get_device_by_capability_and_string (HalPool *pool, - const char *capability, - const char *key, - const char *value); -GList * hal_pool_find_by_capability (HalPool *pool, - const char *capability); - -#endif /* HAL_POOL_H */ diff --git a/gnome-2-24/monitor/gphoto2/hal-utils.c b/gnome-2-24/monitor/gphoto2/hal-utils.c deleted file mode 100644 index ca90bc7c..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-utils.c +++ /dev/null @@ -1,142 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - * Christian Kellner - */ - -#include - -#include -#include -#include - -#include "string.h" - -#include "hal-utils.h" - -static const struct { - const char *disc_type; - const char *icon_name; - char *ui_name; - char *ui_name_blank; -} disc_data[] = { - {"cd_rom", "media-optical-cd-rom", N_("CD-ROM Disc"), N_("Blank CD-ROM Disc")}, - {"cd_r", "media-optical-cd-r", N_("CD-R Disc"), N_("Blank CD-R Disc")}, - {"cd_rw", "media-optical-cd-rw", N_("CD-RW Disc"), N_("Blank CD-RW Disc")}, - {"dvd_rom", "media-optical-dvd-rom", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")}, - {"dvd_ram", "media-optical-dvd-ram", N_("DVD-RAM Disc"), N_("Blank DVD-RAM Disc")}, - {"dvd_r", "media-optical-dvd-r", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")}, - {"dvd_rw", "media-optical-dvd-rw", N_("DVD-RW Disc"), N_("Blank DVD-RW Disc")}, - {"dvd_plus_r", "media-optical-dvd-r-plus", N_("DVD+R Disc"), N_("Blank DVD+R Disc")}, - {"dvd_plus_rw", "media-optical-dvd-rw-plus", N_("DVD+RW Disc"), N_("Blank DVD+RW Disc")}, - {"dvd_plus_r_dl", "media-optical-dvd-dl-r-plus", N_("DVD+R DL Disc"), N_("Blank DVD+R DL Disc")}, - {"bd_rom", "media-optical-bd-rom", N_("Blu-Ray Disc"), N_("Blank Blu-Ray Disc")}, - {"bd_r", "media-optical-bd-r", N_("Blu-Ray R Disc"), N_("Blank Blu-Ray R Disc")}, - {"bd_re", "media-optical-bd-re", N_("Blu-Ray RW Disc"), N_("Blank Blu-Ray RW Disc")}, - {"hddvd_rom", "media-optical-hddvd-rom", N_("HD DVD Disc"), N_("Blank HD DVD Disc")}, - {"hddvd_r", "media-optical-hddvd-r", N_("HD DVD-R Disc"), N_("Blank HD DVD-R Disc")}, - {"hddvd_rw", "media-optical-hddvd-rw", N_("HD DVD-RW Disc"), N_("Blank HD DVD-RW Disc")}, - {"mo", "media-optical-mo", N_("MO Disc"), N_("Blank MO Disc")}, - {NULL, "media-optical", N_("Disc"), N_("Blank Disc")} -}; - -const char * -get_disc_icon (const char *disc_type) -{ - int n; - - for (n = 0; disc_data[n].disc_type != NULL; n++) - { - if (strcmp (disc_data[n].disc_type, disc_type) == 0) - break; - } - - return disc_data[n].icon_name; -} - -const char * -get_disc_name (const char *disc_type, gboolean is_blank) -{ - int n; - - for (n = 0; disc_data[n].disc_type != NULL; n++) - { - if (strcmp (disc_data[n].disc_type, disc_type) == 0) - break; - } - - if (is_blank) - return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name_blank); - else - return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name); -} - -/* - * Creates a GThemedIcon from icon_name and creates default - * fallbacks from fallbacks. Is smart in the case that icon_name - * and fallbacks are identically. - * Note: See the GThemedIcon documentation for more information - * on default fallbacks - */ -GIcon * -get_themed_icon_with_fallbacks (const char *icon_name, - const char *fallbacks) -{ - int i = 0, dashes = 0; - const char *p; - char *dashp; - char *last; - char **names; - GIcon *icon; - - if (G_UNLIKELY (icon_name == NULL)) - return NULL; - - if (fallbacks == NULL) - return g_themed_icon_new (icon_name); - - p = fallbacks; - while (*p) - { - if (*p == '-') - dashes++; - p++; - } - - if (strcmp (icon_name, fallbacks)) - { - names = g_new (char *, dashes + 3); - names[i++] = g_strdup (icon_name); - } - else - names = g_new (char *, dashes + 2); - - names[i++] = last = g_strdup (fallbacks); - - while ((dashp = strrchr (last, '-')) != NULL) - names[i++] = last = g_strndup (last, dashp - last); - - names[i++] = NULL; - icon = g_themed_icon_new_from_names (names, -1); - g_strfreev (names); - - return icon; -} - diff --git a/gnome-2-24/monitor/gphoto2/hal-utils.h b/gnome-2-24/monitor/gphoto2/hal-utils.h deleted file mode 100644 index 7244a29c..00000000 --- a/gnome-2-24/monitor/gphoto2/hal-utils.h +++ /dev/null @@ -1,40 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - * Chrsitian Kellner - */ - -#ifndef __HAL_UTILS_H__ -#define __HAL_UTILS_H__ - -#include -#include - -G_BEGIN_DECLS - -const char * get_disc_icon (const char *disc_type); -const char * get_disc_name (const char *disc_type, gboolean is_blank); - -GIcon * get_themed_icon_with_fallbacks (const char *icon_name, - const char *fallbacks); - -G_END_DECLS - -#endif /* __HAL_UTILS_H__ */ diff --git a/gnome-2-24/monitor/gphoto2/org.gtk.Private.GPhoto2VolumeMonitor.service.in b/gnome-2-24/monitor/gphoto2/org.gtk.Private.GPhoto2VolumeMonitor.service.in deleted file mode 100644 index b06e3df6..00000000 --- a/gnome-2-24/monitor/gphoto2/org.gtk.Private.GPhoto2VolumeMonitor.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.gtk.Private.GPhoto2VolumeMonitor -Exec=@libexecdir@/gvfs-gphoto2-volume-monitor diff --git a/gnome-2-24/monitor/hal/Makefile.am b/gnome-2-24/monitor/hal/Makefile.am deleted file mode 100644 index 9c3d1777..00000000 --- a/gnome-2-24/monitor/hal/Makefile.am +++ /dev/null @@ -1,62 +0,0 @@ - -NULL = - -libexec_PROGRAMS = gvfs-hal-volume-monitor - -BUILT_SOURCES = \ - hal-marshal.h hal-marshal.c - -hal-marshal.h: hal-marshal.list - glib-genmarshal $< --prefix=hal_marshal --header > $@ - -hal-marshal.c: hal-marshal.list - echo "#include \"hal-marshal.h\"" > $@ && glib-genmarshal $< --prefix=hal_marshal --body >> $@ - - -gvfs_hal_volume_monitor_SOURCES = \ - hal-utils.c hal-utils.h \ - hal-volume-monitor-daemon.c \ - hal-marshal.c hal-marshal.h \ - hal-device.c hal-device.h \ - hal-pool.c hal-pool.h \ - ghaldrive.c ghaldrive.h \ - ghalvolume.c ghalvolume.h \ - ghalmount.c ghalmount.h \ - ghalvolumemonitor.c ghalvolumemonitor.h \ - $(NULL) - -gvfs_hal_volume_monitor_CFLAGS = \ - -DG_LOG_DOMAIN=\"GVFS-Hal\" \ - -I$(top_srcdir)/common \ - -I$(top_srcdir)/monitor/proxy \ - $(GLIB_CFLAGS) \ - $(HAL_CFLAGS) \ - -DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \ - -DGVFS_LOCALEDIR=\""$(localedir)"\" \ - -DG_DISABLE_DEPRECATED \ - $(NULL) - -gvfs_hal_volume_monitor_LDFLAGS = \ - $(NULL) - -gvfs_hal_volume_monitor_LDADD = \ - $(GLIB_LIBS) \ - $(HAL_LIBS) \ - $(top_builddir)/common/libgvfscommon.la \ - $(top_builddir)/monitor/proxy/libgvfsproxyvolumemonitordaemon-noin.la \ - $(NULL) - -remote_volume_monitorsdir = $(datadir)/gvfs/remote-volume-monitors -remote_volume_monitors_DATA = hal.monitor - -servicedir = $(datadir)/dbus-1/services -service_in_files = org.gtk.Private.HalVolumeMonitor.service.in -service_DATA = $(service_in_files:.service.in=.service) - -$(service_DATA): $(service_in_files) Makefile - @sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ - -clean-local: - rm -f *~ *.loT $(BUILT_SOURCES) $(service_DATA) - -EXTRA_DIST = hal-marshal.list $(service_in_files) hal.monitor diff --git a/gnome-2-24/monitor/hal/ghaldrive.c b/gnome-2-24/monitor/hal/ghaldrive.c deleted file mode 100644 index c7aea30b..00000000 --- a/gnome-2-24/monitor/hal/ghaldrive.c +++ /dev/null @@ -1,1009 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include - -#include "ghalvolumemonitor.h" -#include "ghaldrive.h" -#include "ghalvolume.h" - -/* Protects all fields of GHalDrive that can change */ -G_LOCK_DEFINE_STATIC(hal_drive); - -struct _GHalDrive { - GObject parent; - - GVolumeMonitor *volume_monitor; /* owned by volume monitor */ - GList *volumes; /* entries in list are owned by volume_monitor */ - - char *name; - char *icon; - char *device_path; - - gboolean can_eject; - gboolean can_poll_for_media; - gboolean is_media_check_automatic; - gboolean has_media; - gboolean uses_removable_media; - - HalDevice *device; - HalPool *pool; -}; - -static void g_hal_drive_drive_iface_init (GDriveIface *iface); - -G_DEFINE_TYPE_EXTENDED (GHalDrive, g_hal_drive, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_DRIVE, - g_hal_drive_drive_iface_init)) - -static void -g_hal_drive_finalize (GObject *object) -{ - GList *l; - GHalDrive *drive; - - drive = G_HAL_DRIVE (object); - - for (l = drive->volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - g_hal_volume_unset_drive (volume, drive); - } - - g_free (drive->device_path); - if (drive->device != NULL) - g_object_unref (drive->device); - if (drive->pool != NULL) - g_object_unref (drive->pool); - - g_free (drive->name); - g_free (drive->icon); - - if (drive->volume_monitor != NULL) - g_object_remove_weak_pointer (G_OBJECT (drive->volume_monitor), (gpointer) &(drive->volume_monitor)); - - if (G_OBJECT_CLASS (g_hal_drive_parent_class)->finalize) - (*G_OBJECT_CLASS (g_hal_drive_parent_class)->finalize) (object); -} - -static void -g_hal_drive_class_init (GHalDriveClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = g_hal_drive_finalize; -} - -static void -g_hal_drive_init (GHalDrive *hal_drive) -{ -} - -static char * -_drive_get_description (HalDevice *d) -{ - char *s = NULL; - const char *drive_type; - const char *drive_bus; - const char *name_from_hal; - - drive_type = hal_device_get_property_string (d, "storage.drive_type"); - drive_bus = hal_device_get_property_string (d, "storage.bus"); - name_from_hal = hal_device_get_property_string (d, "info.desktop.name"); - - - if (strlen (name_from_hal) > 0) - { - s = g_strdup (name_from_hal); - } - else if (strcmp (drive_type, "cdrom") == 0) - { - const char *first; - const char *second; - - first = _("CD-ROM"); - if (hal_device_get_property_bool (d, "storage.cdrom.cdr")) - first = _("CD-R"); - if (hal_device_get_property_bool (d, "storage.cdrom.cdrw")) - first = _("CD-RW"); - - second = NULL; - if (hal_device_get_property_bool (d, "storage.cdrom.dvd")) - second = _("DVD-ROM"); - if (hal_device_get_property_bool (d, "storage.cdrom.dvdplusr")) - second = _("DVD+R"); - if (hal_device_get_property_bool (d, "storage.cdrom.dvdplusrw")) - second = _("DVD+RW"); - if (hal_device_get_property_bool (d, "storage.cdrom.dvdr")) - second = _("DVD-R"); - if (hal_device_get_property_bool (d, "storage.cdrom.dvdrw")) - second = _("DVD-RW"); - if (hal_device_get_property_bool (d, "storage.cdrom.dvdram")) - second = _("DVD-RAM"); - if ((hal_device_get_property_bool (d, "storage.cdrom.dvdr")) && - (hal_device_get_property_bool (d, "storage.cdrom.dvdplusr"))) - second = _("DVD\xc2\xb1R"); - if (hal_device_get_property_bool (d, "storage.cdrom.dvdrw") && - hal_device_get_property_bool (d, "storage.cdrom.dvdplusrw")) - second = _("DVD\xc2\xb1RW"); - if (hal_device_get_property_bool (d, "storage.cdrom.hddvd")) - second = _("HDDVD"); - if (hal_device_get_property_bool (d, "storage.cdrom.hddvdr")) - second = _("HDDVD-r"); - if (hal_device_get_property_bool (d, "storage.cdrom.hddvdrw")) - second = _("HDDVD-RW"); - if (hal_device_get_property_bool (d, "storage.cdrom.bd")) - second = _("Blu-ray"); - if (hal_device_get_property_bool (d, "storage.cdrom.bdr")) - second = _("Blu-ray-R"); - if (hal_device_get_property_bool (d, "storage.cdrom.bdre")) - second = _("Blu-ray-RE"); - - if (second != NULL) - { - /* translators: This wis something like "CD-ROM/DVD Drive" or - "CD-RW/Blue-ray Drive" depending on the properties of the drive */ - s = g_strdup_printf (_("%s/%s Drive"), first, second); - } - else - { - /* translators: This wis something like "CD-ROM Drive" or "CD-RW Drive - depending on the properties of the drive */ - s = g_strdup_printf (_("%s Drive"), first); - } - } - else if (strcmp (drive_type, "floppy") == 0) - s = g_strdup (_("Floppy Drive")); - else if (strcmp (drive_type, "disk") == 0) - { - if (drive_bus != NULL) - { - if (strcmp (drive_bus, "linux_raid") == 0) - s = g_strdup (_("Software RAID Drive")); - if (strcmp (drive_bus, "usb") == 0) - s = g_strdup (_("USB Drive")); - if (strcmp (drive_bus, "ide") == 0) - s = g_strdup (_("ATA Drive")); - if (strcmp (drive_bus, "scsi") == 0) - s = g_strdup (_("SCSI Drive")); - if (strcmp (drive_bus, "ieee1394") == 0) - s = g_strdup (_("FireWire Drive")); - } - } - else if (strcmp (drive_type, "tape") == 0) - s = g_strdup (_("Tape Drive")); - else if (strcmp (drive_type, "compact_flash") == 0) - s = g_strdup (_("CompactFlash Drive")); - else if (strcmp (drive_type, "memory_stick") == 0) - s = g_strdup (_("MemoryStick Drive")); - else if (strcmp (drive_type, "smart_media") == 0) - s = g_strdup (_("SmartMedia Drive")); - else if (strcmp (drive_type, "sd_mmc") == 0) - s = g_strdup (_("SD/MMC Drive")); - else if (strcmp (drive_type, "zip") == 0) - s = g_strdup (_("Zip Drive")); - else if (strcmp (drive_type, "jaz") == 0) - s = g_strdup (_("Jaz Drive")); - else if (strcmp (drive_type, "flashkey") == 0) - s = g_strdup (_("Thumb Drive")); - - if (s == NULL) - s = g_strdup (_("Mass Storage Drive")); - - return s; -} - -char * -_drive_get_icon (HalDevice *d) -{ - char *s = NULL; - const char *drive_type; - const char *drive_bus; - const char *icon_from_hal; - gboolean is_audio_player; - - drive_type = hal_device_get_property_string (d, "storage.drive_type"); - drive_bus = hal_device_get_property_string (d, "storage.bus"); - is_audio_player = hal_device_has_capability (d, "portable_audio_player"); - icon_from_hal = hal_device_get_property_string (d, "info.desktop.icon"); - - if (strlen (icon_from_hal) > 0) - s = g_strdup (icon_from_hal); - else if (is_audio_player) - s = g_strdup ("multimedia-player"); - else if (strcmp (drive_type, "disk") == 0) - { - if (strcmp (drive_bus, "ide") == 0) - s = g_strdup ("drive-removable-media-ata"); - else if (strcmp (drive_bus, "scsi") == 0) - s = g_strdup ("drive-removable-media-scsi"); - else if (strcmp (drive_bus, "ieee1394") == 0) - s = g_strdup ("drive-removable-media-ieee1394"); - else if (strcmp (drive_bus, "usb") == 0) - s = g_strdup ("drive-removable-media-usb"); - else - s = g_strdup ("drive-removable-media"); - } - else if (strcmp (drive_type, "cdrom") == 0) - { - /* TODO: maybe there's a better heuristic than this */ - if (hal_device_get_property_int (d, "storage.cdrom.write_speed") > 0) - s = g_strdup ("drive-optical-recorder"); - else - s = g_strdup ("drive-optical"); - } - else if (strcmp (drive_type, "floppy") == 0) - s = g_strdup ("drive-removable-media-floppy"); - else if (strcmp (drive_type, "tape") == 0) - s = g_strdup ("drive-removable-media-tape"); - else if (strcmp (drive_type, "compact_flash") == 0) - s = g_strdup ("drive-removable-media-flash-cf"); - else if (strcmp (drive_type, "memory_stick") == 0) - s = g_strdup ("drive-removable-media-flash-ms"); - else if (strcmp (drive_type, "smart_media") == 0) - s = g_strdup ("drive-removable-media-flash-sm"); - else if (strcmp (drive_type, "sd_mmc") == 0) - s = g_strdup ("drive-removable-media-flash-sd"); - - if (s == NULL) - s = g_strdup ("drive-removable-media"); - - return s; -} - -static void -_do_update_from_hal (GHalDrive *d) -{ - d->name = _drive_get_description (d->device); - d->icon = _drive_get_icon (d->device); - - d->uses_removable_media = hal_device_get_property_bool (d->device, "storage.removable"); - if (d->uses_removable_media) - { - d->has_media = hal_device_get_property_bool (d->device, "storage.removable.media_available"); - d->is_media_check_automatic = hal_device_get_property_bool (d->device, "storage.media_check_enabled"); - d->can_poll_for_media = hal_device_has_interface (d->device, "org.freedesktop.Hal.Device.Storage.Removable"); - d->can_eject = hal_device_get_property_bool (d->device, "storage.requires_eject"); - } - else - { - d->has_media = TRUE; - d->is_media_check_automatic = FALSE; - d->can_poll_for_media = FALSE; - d->can_eject = FALSE; - } -} - -static gboolean -changed_in_idle (gpointer data) -{ - GHalDrive *drive = data; - - g_signal_emit_by_name (drive, "changed"); - if (drive->volume_monitor != NULL) - g_signal_emit_by_name (drive->volume_monitor, "drive_changed", drive); - g_object_unref (drive); - - return FALSE; -} - -static void -_update_from_hal (GHalDrive *d, gboolean emit_changed) -{ - char *old_name; - char *old_icon; - gboolean old_uses_removable_media; - gboolean old_has_media; - gboolean old_is_media_check_automatic; - gboolean old_can_poll_for_media; - gboolean old_can_eject; - - G_LOCK (hal_drive); - - old_name = g_strdup (d->name); - old_icon = g_strdup (d->icon); - old_uses_removable_media = d->uses_removable_media; - old_has_media = d->has_media; - old_is_media_check_automatic = d->is_media_check_automatic; - old_can_poll_for_media = d->can_poll_for_media; - old_can_eject = d->can_eject; - - g_free (d->name); - g_free (d->icon); - _do_update_from_hal (d); - - if (emit_changed && - (old_uses_removable_media != d->uses_removable_media || - old_has_media != d->has_media || - old_is_media_check_automatic != d->is_media_check_automatic || - old_can_poll_for_media != d->can_poll_for_media || - old_can_eject != d->can_eject || - old_name == NULL || - old_icon == NULL || - strcmp (old_name, d->name) != 0 || - strcmp (old_icon, d->icon) != 0)) - g_idle_add (changed_in_idle, g_object_ref (d)); - - g_free (old_name); - g_free (old_icon); - - G_UNLOCK (hal_drive); -} - -static void -hal_condition (HalDevice *device, const char *name, const char *detail, gpointer user_data) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (user_data); - - if (strcmp (name, "EjectPressed") == 0) - { - g_signal_emit_by_name (hal_drive, "eject-button"); - if (hal_drive->volume_monitor != NULL) - g_signal_emit_by_name (hal_drive->volume_monitor, "drive-eject-button", hal_drive); - } - -} - -static void -hal_changed (HalDevice *device, const char *key, gpointer user_data) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (user_data); - - /*g_warning ("volhal modifying %s (property %s changed)", hal_drive->device_path, key);*/ - _update_from_hal (hal_drive, TRUE); -} - -GHalDrive * -g_hal_drive_new (GVolumeMonitor *volume_monitor, - HalDevice *device, - HalPool *pool) -{ - GHalDrive *drive; - - drive = g_object_new (G_TYPE_HAL_DRIVE, NULL); - drive->volume_monitor = volume_monitor; - g_object_add_weak_pointer (G_OBJECT (volume_monitor), (gpointer) &(drive->volume_monitor)); - drive->device_path = g_strdup (hal_device_get_property_string (device, "block.device")); - drive->device = g_object_ref (device); - drive->pool = g_object_ref (pool); - - drive->name = g_strdup_printf ("Drive for %s", drive->device_path); - drive->icon = g_strdup_printf ("drive-removable-media"); - - g_signal_connect_object (device, "hal_property_changed", (GCallback) hal_changed, drive, 0); - g_signal_connect_object (device, "hal_condition", (GCallback) hal_condition, drive, 0); - - _update_from_hal (drive, FALSE); - - return drive; -} - -void -g_hal_drive_disconnected (GHalDrive *drive) -{ - GList *l, *volumes; - - G_LOCK (hal_drive); - volumes = drive->volumes; - drive->volumes = NULL; - G_UNLOCK (hal_drive); - - for (l = volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - g_hal_volume_unset_drive (volume, drive); - } - - g_list_free (volumes); -} - -void -g_hal_drive_set_volume (GHalDrive *drive, - GHalVolume *volume) -{ - - G_LOCK (hal_drive); - - if (g_list_find (drive->volumes, volume) == NULL) - { - drive->volumes = g_list_prepend (drive->volumes, volume); - g_idle_add (changed_in_idle, g_object_ref (drive)); - } - - G_UNLOCK (hal_drive); -} - -void -g_hal_drive_unset_volume (GHalDrive *drive, - GHalVolume *volume) -{ - GList *l; - - G_LOCK (hal_drive); - - l = g_list_find (drive->volumes, volume); - if (l != NULL) - { - drive->volumes = g_list_delete_link (drive->volumes, l); - - g_idle_add (changed_in_idle, g_object_ref (drive)); - } - - G_UNLOCK (hal_drive); -} - -gboolean -g_hal_drive_has_udi (GHalDrive *drive, const char *udi) -{ - gboolean res; - - G_LOCK (hal_drive); - res = strcmp (udi, hal_device_get_udi (drive->device)) == 0; - G_UNLOCK (hal_drive); - - return res; -} - -static GIcon * -g_hal_drive_get_icon (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - GIcon *icon; - - G_LOCK (hal_drive); - icon = g_themed_icon_new_with_default_fallbacks (hal_drive->icon); - G_UNLOCK (hal_drive); - - return icon; -} - -static char * -g_hal_drive_get_name (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - char *name; - - G_LOCK (hal_drive); - name = g_strdup (hal_drive->name); - G_UNLOCK (hal_drive); - - return name; -} - -static GList * -g_hal_drive_get_volumes (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - GList *l; - - G_LOCK (hal_drive); - l = g_list_copy (hal_drive->volumes); - g_list_foreach (l, (GFunc) g_object_ref, NULL); - G_UNLOCK (hal_drive); - - return l; -} - -static gboolean -g_hal_drive_has_volumes (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - gboolean res; - - G_LOCK (hal_drive); - res = hal_drive->volumes != NULL; - G_UNLOCK (hal_drive); - - return res; -} - -static gboolean -g_hal_drive_is_media_removable (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - gboolean res; - - G_LOCK (hal_drive); - res = hal_drive->uses_removable_media; - G_UNLOCK (hal_drive); - - return res; -} - -static gboolean -g_hal_drive_has_media (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - gboolean res; - - G_LOCK (hal_drive); - res = hal_drive->has_media; - G_UNLOCK (hal_drive); - - return res; -} - -static gboolean -g_hal_drive_is_media_check_automatic (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - gboolean res; - - G_LOCK (hal_drive); - res = hal_drive->is_media_check_automatic; - G_UNLOCK (hal_drive); - - return res; -} - -static gboolean -g_hal_drive_can_eject (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - gboolean res; - - G_LOCK (hal_drive); - res = hal_drive->can_eject; - G_UNLOCK (hal_drive); - - return res; -} - -static gboolean -g_hal_drive_can_poll_for_media (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - gboolean res; - - G_LOCK (hal_drive); - res = hal_drive->can_poll_for_media; - G_UNLOCK (hal_drive); - - return res; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; -} SpawnOp; - -static void -spawn_cb (GPid pid, gint status, gpointer user_data) -{ - SpawnOp *data = user_data; - GSimpleAsyncResult *simple; - - - if (WEXITSTATUS (status) != 0) - { - GError *error; - error = g_error_new_literal (G_IO_ERROR, - G_IO_ERROR_FAILED_HANDLED, - "You are not supposed to show G_IO_ERROR_FAILED_HANDLED in the UI"); - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_error_free (error); - } - else - { - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_object_unref (data->object); - g_free (data); -} - -static void -g_hal_drive_eject_do (GDrive *drive, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - SpawnOp *data; - GPid child_pid; - GError *error; - char *argv[] = {"gnome-mount", "-e", "-b", "-d", NULL, NULL}; - - G_LOCK (hal_drive); - argv[4] = g_strdup (hal_drive->device_path); - G_UNLOCK (hal_drive); - - data = g_new0 (SpawnOp, 1); - data->object = g_object_ref (drive); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - - error = NULL; - if (!g_spawn_async (NULL, /* working dir */ - argv, - NULL, /* envp */ - G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH, - NULL, /* child_setup */ - NULL, /* user_data for child_setup */ - &child_pid, - &error)) - { - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_object_unref (drive); - g_error_free (error); - g_free (data); - } - else - g_child_watch_add (child_pid, spawn_cb, data); - - g_free (argv[4]); -} - - -typedef struct { - GDrive *drive; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; - GMountUnmountFlags flags; - - GList *pending_mounts; -} UnmountMountsOp; - -static void -free_unmount_mounts_op (UnmountMountsOp *data) -{ - GList *l; - - for (l = data->pending_mounts; l != NULL; l = l->next) - { - GMount *mount = l->data; - g_object_unref (mount); - } - g_list_free (data->pending_mounts); -} - -static void _eject_unmount_mounts (UnmountMountsOp *data); - -static void -_eject_unmount_mounts_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - UnmountMountsOp *data = user_data; - GMount *mount = G_MOUNT (source_object); - GSimpleAsyncResult *simple; - GError *error = NULL; - - if (!g_mount_unmount_finish (mount, res, &error)) - { - /* make the error dialog more targeted to the drive.. unless the user has already seen a dialog */ - if (error->code != G_IO_ERROR_FAILED_HANDLED) - { - g_error_free (error); - error = g_error_new (G_IO_ERROR, G_IO_ERROR_BUSY, - _("Failed to eject media; one or more volumes on the media are busy.")); - } - - /* unmount failed; need to fail the whole eject operation */ - simple = g_simple_async_result_new_from_error (G_OBJECT (data->drive), - data->callback, - data->user_data, - error); - g_error_free (error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - - free_unmount_mounts_op (data); - } - else - { - - /*g_warning ("successfully unmounted %p", mount);*/ - - /* move on to the next mount.. */ - _eject_unmount_mounts (data); - } - - g_object_unref (mount); -} - -static void -_eject_unmount_mounts (UnmountMountsOp *data) -{ - GMount *mount; - - if (data->pending_mounts == NULL) - { - - /*g_warning ("all pending mounts done; ejecting drive");*/ - - g_hal_drive_eject_do (data->drive, - data->cancellable, - data->callback, - data->user_data); - - g_object_unref (data->drive); - g_free (data); - } - else - { - mount = data->pending_mounts->data; - data->pending_mounts = g_list_remove (data->pending_mounts, mount); - - /*g_warning ("unmounting %p", mount);*/ - - g_mount_unmount (mount, - data->flags, - data->cancellable, - _eject_unmount_mounts_cb, - data); - } -} - -static void -g_hal_drive_eject (GDrive *drive, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - UnmountMountsOp *data; - GList *l; - - /* first we need to go through all the volumes and unmount their assoicated mounts (if any) */ - - data = g_new0 (UnmountMountsOp, 1); - data->drive = g_object_ref (drive); - data->cancellable = cancellable; - data->callback = callback; - data->user_data = user_data; - data->flags = flags; - - G_LOCK (hal_drive); - for (l = hal_drive->volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - GMount *mount; /* the mount may be foreign; cannot assume GHalMount */ - - mount = g_volume_get_mount (G_VOLUME (volume)); - if (mount != NULL && g_mount_can_unmount (mount)) - data->pending_mounts = g_list_prepend (data->pending_mounts, g_object_ref (mount)); - } - G_UNLOCK (hal_drive); - - _eject_unmount_mounts (data); -} - -static gboolean -g_hal_drive_eject_finish (GDrive *drive, - GAsyncResult *result, - GError **error) -{ - return TRUE; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; -} PollOp; - -static void -poll_for_media_cb (DBusPendingCall *pending_call, void *user_data) -{ - PollOp *data = (PollOp *) user_data; - GSimpleAsyncResult *simple; - DBusMessage *reply; - - reply = dbus_pending_call_steal_reply (pending_call); - - if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) - { - GError *error; - DBusError dbus_error; - - dbus_error_init (&dbus_error); - dbus_set_error_from_message (&dbus_error, reply); - error = g_error_new (G_IO_ERROR, - G_IO_ERROR_FAILED, - "Cannot invoke CheckForMedia on HAL: %s: %s", dbus_error.name, dbus_error.message); - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_error_free (error); - dbus_error_free (&dbus_error); - goto out; - } - - /* TODO: parse reply and extract result? - * (the result is whether the media availability state changed) - */ - - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - g_simple_async_result_complete (simple); - g_object_unref (simple); - - out: - g_object_unref (data->object); - dbus_message_unref (reply); - dbus_pending_call_unref (pending_call); -} - - -static void -g_hal_drive_poll_for_media (GDrive *drive, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - DBusConnection *con; - DBusMessage *msg; - DBusPendingCall *pending_call; - PollOp *data; - - data = g_new0 (PollOp, 1); - data->object = g_object_ref (drive); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - - /*g_warning ("Rescanning udi %s", hal_device_get_udi (hal_drive->device));*/ - - G_LOCK (hal_drive); - con = hal_pool_get_dbus_connection (hal_drive->pool); - msg = dbus_message_new_method_call ("org.freedesktop.Hal", - hal_device_get_udi (hal_drive->device), - "org.freedesktop.Hal.Device.Storage.Removable", - "CheckForMedia"); - G_UNLOCK (hal_drive); - - if (!dbus_connection_send_with_reply (con, msg, &pending_call, -1)) - { - GError *error; - GSimpleAsyncResult *simple; - error = g_error_new_literal (G_IO_ERROR, - G_IO_ERROR_FAILED, - "Cannot invoke CheckForMedia on HAL"); - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_error_free (error); - g_object_unref (data->object); - g_free (data); - } - else - dbus_pending_call_set_notify (pending_call, - poll_for_media_cb, - data, - (DBusFreeFunction) g_free); - - dbus_message_unref (msg); -} - -static gboolean -g_hal_drive_poll_for_media_finish (GDrive *drive, - GAsyncResult *result, - GError **error) -{ - /*g_warning ("poll finish");*/ - return TRUE; -} - -static char * -g_hal_drive_get_identifier (GDrive *drive, - const char *kind) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - char *res; - - res = NULL; - - G_LOCK (hal_drive); - - if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_HAL_UDI) == 0) - res = g_strdup (hal_device_get_udi (hal_drive->device)); - - if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) == 0) - res = g_strdup (hal_drive->device_path); - - G_UNLOCK (hal_drive); - - return res; -} - -static char ** -g_hal_drive_enumerate_identifiers (GDrive *drive) -{ - GHalDrive *hal_drive = G_HAL_DRIVE (drive); - GPtrArray *res; - - res = g_ptr_array_new (); - - G_LOCK (hal_drive); - - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_HAL_UDI)); - - if (hal_drive->device_path && *hal_drive->device_path != 0) - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE)); - - - G_UNLOCK (hal_drive); - - /* Null-terminate */ - g_ptr_array_add (res, NULL); - - return (char **)g_ptr_array_free (res, FALSE); -} - -static void -g_hal_drive_drive_iface_init (GDriveIface *iface) -{ - iface->get_name = g_hal_drive_get_name; - iface->get_icon = g_hal_drive_get_icon; - iface->has_volumes = g_hal_drive_has_volumes; - iface->get_volumes = g_hal_drive_get_volumes; - iface->is_media_removable = g_hal_drive_is_media_removable; - iface->has_media = g_hal_drive_has_media; - iface->is_media_check_automatic = g_hal_drive_is_media_check_automatic; - iface->can_eject = g_hal_drive_can_eject; - iface->can_poll_for_media = g_hal_drive_can_poll_for_media; - iface->eject = g_hal_drive_eject; - iface->eject_finish = g_hal_drive_eject_finish; - iface->poll_for_media = g_hal_drive_poll_for_media; - iface->poll_for_media_finish = g_hal_drive_poll_for_media_finish; - iface->get_identifier = g_hal_drive_get_identifier; - iface->enumerate_identifiers = g_hal_drive_enumerate_identifiers; -} diff --git a/gnome-2-24/monitor/hal/ghaldrive.h b/gnome-2-24/monitor/hal/ghaldrive.h deleted file mode 100644 index 7832db59..00000000 --- a/gnome-2-24/monitor/hal/ghaldrive.h +++ /dev/null @@ -1,62 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_HAL_DRIVE_H__ -#define __G_HAL_DRIVE_H__ - -#include -#include - -#include "hal-pool.h" -#include "ghalvolumemonitor.h" - -G_BEGIN_DECLS - -#define G_TYPE_HAL_DRIVE (g_hal_drive_get_type ()) -#define G_HAL_DRIVE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_HAL_DRIVE, GHalDrive)) -#define G_HAL_DRIVE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_HAL_DRIVE, GHalDriveClass)) -#define G_IS_HAL_DRIVE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_HAL_DRIVE)) -#define G_IS_HAL_DRIVE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_HAL_DRIVE)) - -typedef struct _GHalDriveClass GHalDriveClass; - -struct _GHalDriveClass { - GObjectClass parent_class; -}; - -GType g_hal_drive_get_type (void) G_GNUC_CONST; - -GHalDrive *g_hal_drive_new (GVolumeMonitor *volume_monitor, - HalDevice *device, - HalPool *pool); -gboolean g_hal_drive_has_udi (GHalDrive *drive, - const char *udi); -void g_hal_drive_set_volume (GHalDrive *drive, - GHalVolume *volume); -void g_hal_drive_unset_volume (GHalDrive *drive, - GHalVolume *volume); -void g_hal_drive_disconnected (GHalDrive *drive); -char * _drive_get_icon (HalDevice *d); - -G_END_DECLS - -#endif /* __G_HAL_DRIVE_H__ */ diff --git a/gnome-2-24/monitor/hal/ghalmount.c b/gnome-2-24/monitor/hal/ghalmount.c deleted file mode 100644 index 138c9a10..00000000 --- a/gnome-2-24/monitor/hal/ghalmount.c +++ /dev/null @@ -1,1592 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "ghalvolumemonitor.h" -#include "ghalmount.h" -#include "ghalvolume.h" - -#include "hal-utils.h" - -/* Protects all fields of GHalDrive that can change */ -G_LOCK_DEFINE_STATIC(hal_mount); - -struct _GHalMount { - GObject parent; - - GVolumeMonitor *volume_monitor; /* owned by volume monitor */ - GHalVolume *volume; /* owned by volume monitor */ - - char *name; - GIcon *icon; - char *device_path; - char *mount_path; - - char *uuid; - - char *override_name; - GIcon *override_icon; - GFile *override_root; - gboolean cannot_unmount; - gboolean searched_for_icon; - - HalDevice *device; - HalDevice *drive_device; -}; - -static GFile * -_g_find_file_insensitive_finish (GFile *parent, - GAsyncResult *result, - GError **error); - -static void -_g_find_file_insensitive_async (GFile *parent, - const gchar *name, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - - -static GFile *get_root (GHalMount *hal_mount); - -static void g_hal_mount_mount_iface_init (GMountIface *iface); - -G_DEFINE_TYPE_EXTENDED (GHalMount, g_hal_mount, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_MOUNT, - g_hal_mount_mount_iface_init)) - -static void -g_hal_mount_finalize (GObject *object) -{ - GHalMount *mount; - - mount = G_HAL_MOUNT (object); - - if (mount->volume != NULL) - g_hal_volume_unset_mount (mount->volume, mount); - - g_free (mount->device_path); - g_free (mount->mount_path); - g_free (mount->uuid); - - if (mount->device != NULL) - g_object_unref (mount->device); - if (mount->drive_device != NULL) - g_object_unref (mount->drive_device); - - g_free (mount->name); - if (mount->icon != NULL) - g_object_unref (mount->icon); - - g_free (mount->override_name); - if (mount->override_icon != NULL) - g_object_unref (mount->override_icon); - - if (mount->override_root != NULL) - g_object_unref (mount->override_root); - - if (mount->volume_monitor != NULL) - g_object_remove_weak_pointer (G_OBJECT (mount->volume_monitor), (gpointer) &(mount->volume_monitor)); - - if (G_OBJECT_CLASS (g_hal_mount_parent_class)->finalize) - (*G_OBJECT_CLASS (g_hal_mount_parent_class)->finalize) (object); -} - -static void -g_hal_mount_class_init (GHalMountClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = g_hal_mount_finalize; -} - -static void -g_hal_mount_init (GHalMount *hal_mount) -{ -} - -static gboolean -changed_in_idle (gpointer data) -{ - GHalMount *mount = data; - - g_signal_emit_by_name (mount, "changed"); - if (mount->volume_monitor != NULL) - g_signal_emit_by_name (mount->volume_monitor, "mount_changed", mount); - g_object_unref (mount); - - return FALSE; -} - -typedef struct _MountIconSearchData -{ - GHalMount *mount; - GFile *root; -} MountIconSearchData; - -static void -clear_icon_search_data (MountIconSearchData *data) -{ - if (data->mount) - g_object_unref (data->mount); - if (data->root) - g_object_unref (data->root); - g_free (data); -} - -static void -on_icon_file_located (GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - GFile *icon_file; - GIcon *icon; - MountIconSearchData *data = (MountIconSearchData *) (user_data); - - icon_file = _g_find_file_insensitive_finish (G_FILE (source_object), - res, NULL); - - /* TODO: check if the file actually exists? */ - - icon = g_file_icon_new (icon_file); - g_object_unref (icon_file); - - g_hal_mount_override_icon (data->mount, icon); - g_object_unref (icon); - - clear_icon_search_data (data); -} - -static void -on_autorun_loaded (GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - gchar *content, *relative_icon_path = NULL; - gsize content_length; - MountIconSearchData *data = (MountIconSearchData *) (user_data); - - if (g_file_load_contents_finish (G_FILE (source_object), res, &content, - &content_length, NULL, NULL)) - { - /* Scan through for an "icon=" line. Can't use GKeyFile, - * because .inf files aren't always valid key files - **/ - GRegex *icon_regex; - GMatchInfo *match_info; - - /* [^,] is because sometimes the icon= line - * has a comma at the end - **/ - icon_regex = g_regex_new ("icon=([^,\\r\\n]+)", - G_REGEX_CASELESS, 0, NULL); - g_regex_match (icon_regex, content, 0, - &match_info); - - /* Even if there are multiple matches, pick only the - * first. - **/ - if (g_match_info_matches (match_info)) - { - gchar *chr; - gchar *word = g_match_info_fetch (match_info, 1); - - /* Replace '\' with '/' */ - while ((chr = strchr (word, '\\')) != NULL) - *chr = '/'; - - /* If the file name's not valid UTF-8, - * don't even try to load it - **/ - if (g_utf8_validate (word, -1, NULL)) - relative_icon_path = word; - else - g_free (word); - } - - g_match_info_free (match_info); - - g_regex_unref (icon_regex); - g_free (content); - } - - /* some autorun.in points to the .exe file for the icon; make sure we avoid using that */ - if (relative_icon_path && !g_str_has_suffix (relative_icon_path, ".exe")) - { - _g_find_file_insensitive_async (data->root, - relative_icon_path, - NULL, on_icon_file_located, - data); - - g_free (relative_icon_path); - } - else - clear_icon_search_data (data); -} - -static void -on_autorun_located (GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - GFile *autorun_path; - MountIconSearchData *data = (MountIconSearchData *) (user_data); - - autorun_path = _g_find_file_insensitive_finish (G_FILE (source_object), - res, NULL); - if (autorun_path) - g_file_load_contents_async (autorun_path, NULL, on_autorun_loaded, data); - else - clear_icon_search_data (data); - - g_object_unref (autorun_path); -} - -static void -_g_find_mount_icon (GHalMount *m) -{ - MountIconSearchData *search_data; - - m->searched_for_icon = TRUE; - - search_data = g_new0 (MountIconSearchData, 1); - search_data->mount = g_object_ref (m); - search_data->root = get_root (m); - - _g_find_file_insensitive_async (search_data->root, - "autorun.inf", - NULL, on_autorun_located, - search_data); -} - -#define KILOBYTE_FACTOR 1000.0 -#define MEGABYTE_FACTOR (1000.0 * 1000.0) -#define GIGABYTE_FACTOR (1000.0 * 1000.0 * 1000.0) - -static char * -format_size_for_display (guint64 size) -{ - char *str; - gdouble displayed_size; - - if (size < MEGABYTE_FACTOR) - { - displayed_size = (double) size / KILOBYTE_FACTOR; - str = g_strdup_printf (_("%.1f kB"), displayed_size); - } - else if (size < GIGABYTE_FACTOR) - { - displayed_size = (double) size / MEGABYTE_FACTOR; - str = g_strdup_printf (_("%.1f MB"), displayed_size); - } - else - { - displayed_size = (double) size / GIGABYTE_FACTOR; - str = g_strdup_printf (_("%.1f GB"), displayed_size); - } - - return str; -} - -static void -do_update_from_hal (GHalMount *m) -{ - HalDevice *volume; - HalDevice *drive; - char *name; - const char *icon_name; - const char *icon_name_fallback; - const char *drive_type; - const char *drive_bus; - gboolean drive_uses_removable_media; - const char *volume_fs_label; - guint64 volume_size; - gboolean volume_is_disc; - gboolean volume_disc_has_audio; - gboolean volume_disc_has_data; - const char *volume_disc_type; - gboolean volume_disc_is_blank; - gboolean is_audio_player; - const char *icon_from_hal; - const char *volume_icon_from_hal; - const char *name_from_hal; - const char *volume_name_from_hal; - gboolean is_crypto; - gboolean is_crypto_cleartext; - - volume = m->device; - drive = m->drive_device; - - drive_type = hal_device_get_property_string (drive, "storage.drive_type"); - drive_bus = hal_device_get_property_string (drive, "storage.bus"); - drive_uses_removable_media = hal_device_get_property_bool (drive, "storage.removable"); - volume_fs_label = hal_device_get_property_string (volume, "volume.label"); - volume_size = hal_device_get_property_uint64 (volume, "volume.size"); - volume_is_disc = hal_device_get_property_bool (volume, "volume.is_disc"); - volume_disc_has_audio = hal_device_get_property_bool (volume, "volume.disc.has_audio"); - volume_disc_has_data = hal_device_get_property_bool (volume, "volume.disc.has_data"); - volume_disc_is_blank = hal_device_get_property_bool (volume, "volume.disc.is_blank"); - volume_disc_type = hal_device_get_property_string (volume, "volume.disc.type"); - is_audio_player = hal_device_has_capability (drive, "portable_audio_player"); - icon_from_hal = hal_device_get_property_string (drive, "info.desktop.icon"); - volume_icon_from_hal = hal_device_get_property_string (volume, "info.desktop.icon"); - name_from_hal = hal_device_get_property_string (drive, "info.desktop.name"); - volume_name_from_hal = hal_device_get_property_string (volume, "info.desktop.name"); - - is_crypto = FALSE; - is_crypto_cleartext = FALSE; - if (strcmp (hal_device_get_property_string (volume, "volume.fsusage"), "crypto") == 0) - is_crypto = TRUE; - - if (strlen (hal_device_get_property_string (volume, "volume.crypto_luks.clear.backing_volume")) > 0) - is_crypto_cleartext = TRUE; - - /*g_warning ("drive_type='%s'", drive_type); */ - /*g_warning ("drive_bus='%s'", drive_bus); */ - /*g_warning ("drive_uses_removable_media=%d", drive_uses_removable_media); */ - - icon_name_fallback = NULL; - - if (strlen (volume_icon_from_hal) > 0) - icon_name = volume_icon_from_hal; - else if (strlen (icon_from_hal) > 0) - icon_name = icon_from_hal; - else if (is_audio_player) - icon_name = "multimedia-player"; - else if (strcmp (drive_type, "disk") == 0) - { - if (strcmp (drive_bus, "ide") == 0) - icon_name = "drive-harddisk-ata"; - else if (strcmp (drive_bus, "scsi") == 0) - icon_name = "drive-harddisk-scsi"; - else if (strcmp (drive_bus, "ieee1394") == 0) - icon_name = "drive-harddisk-ieee1394"; - else if (strcmp (drive_bus, "usb") == 0) - icon_name = "drive-harddisk-usb"; - else - icon_name = "drive-harddisk"; - } - else if (strcmp (drive_type, "cdrom") == 0) - icon_name = get_disc_icon (volume_disc_type); - else if (strcmp (drive_type, "floppy") == 0) - icon_name = "media-floppy"; - else if (strcmp (drive_type, "tape") == 0) - icon_name = "media-tape"; - else if (strcmp (drive_type, "compact_flash") == 0) - icon_name = "media-flash-cf"; - else if (strcmp (drive_type, "memory_stick") == 0) - icon_name = "media-flash-ms"; - else if (strcmp (drive_type, "smart_media") == 0) - icon_name = "media-flash-sm"; - else if (strcmp (drive_type, "sd_mmc") == 0) - icon_name = "media-flash-sd"; - else - icon_name = "drive-harddisk"; - - /* Create default fallbacks for the icon_name by default - * with get_themed_icon_with_fallbacks () */ - icon_name_fallback = icon_name; - - /* Note: we are not chaning the default fallbacks - * so we get all the fallbacks if the media-encrytped - * icon is not there */ - if (is_crypto || is_crypto_cleartext) - icon_name = "media-encrypted"; - - if (strlen (volume_name_from_hal) > 0) - name = g_strdup (volume_name_from_hal); - else if (strlen (name_from_hal) > 0) - name = g_strdup (name_from_hal); - else if (volume_fs_label != NULL && strlen (volume_fs_label) > 0) - name = g_strdup (volume_fs_label); - else if (volume_is_disc) - { - if (volume_disc_has_audio) - { - if (volume_disc_has_data) - name = g_strdup (_("Mixed Audio/Data Disc")); - else - name = g_strdup (_("Audio Disc")); - } - else - name = g_strdup (get_disc_name (volume_disc_type, volume_disc_is_blank)); - } - else - { - char *size; - - size = format_size_for_display (volume_size); - /* Translators: %s is the size of the mount (e.g. 512 MB) */ - name = g_strdup_printf (_("%s Media"), size); - g_free (size); - } - - if (m->override_name != NULL) - { - m->name = g_strdup (m->override_name); - g_free (name); - } - else - m->name = name; - - if (m->override_icon != NULL) - m->icon = g_object_ref (m->override_icon); - else - m->icon = get_themed_icon_with_fallbacks (icon_name, - icon_name_fallback); - - /* If this is a CD-ROM, begin searching for an icon specified in - * autorun.inf. - **/ - if (strcmp (drive_type, "cdrom") == 0 && !m->searched_for_icon) - _g_find_mount_icon (m); -} - - -static void -update_from_hal (GHalMount *m, gboolean emit_changed) -{ - char *old_name; - GIcon *old_icon; - - G_LOCK (hal_mount); - - old_name = g_strdup (m->name); - old_icon = m->icon != NULL ? g_object_ref (m->icon) : NULL; - - g_free (m->name); - if (m->icon != NULL) - g_object_unref (m->icon); - do_update_from_hal (m); - - if (emit_changed) - { - if (old_name == NULL || - old_icon == NULL || - strcmp (old_name, m->name) != 0 || - (! g_icon_equal (old_icon, m->icon))) - g_idle_add (changed_in_idle, g_object_ref (m)); - } - g_free (old_name); - if (old_icon != NULL) - g_object_unref (old_icon); - - G_UNLOCK (hal_mount); -} - -static void -hal_changed (HalDevice *device, const char *key, gpointer user_data) -{ - GHalMount *hal_mount = G_HAL_MOUNT (user_data); - - /*g_warning ("mounthal modifying %s (property %s changed)", hal_mount->device_path, key); */ - update_from_hal (hal_mount, TRUE); -} - -static void -compute_uuid (GHalMount *mount) -{ - const char *fs_uuid; - const char *fs_label; - - /* use the FS uuid before falling back to the FS label */ - - fs_uuid = hal_device_get_property_string (mount->device, "volume.uuid"); - fs_label = hal_device_get_property_string (mount->device, "volume.label"); - - if (strlen (fs_uuid) == 0) - { - if (strlen (fs_label) == 0) - mount->uuid = NULL; - else - mount->uuid = g_strdup (fs_label); - } - else - mount->uuid = g_strdup (fs_uuid); -} - - -GHalMount * -g_hal_mount_new_for_hal_device (GVolumeMonitor *volume_monitor, - HalDevice *device, - GFile *override_root, - const char *override_name, - GIcon *override_icon, - gboolean cannot_unmount, - HalPool *pool, - GHalVolume *volume) -{ - HalDevice *drive_device; - const char *storage_udi; - GHalMount *mount; - - storage_udi = hal_device_get_property_string (device, "block.storage_device"); - if (storage_udi == NULL) - goto fail; - - /* g_warning ("storage_udi = %s", storage_udi); */ - - drive_device = hal_pool_get_device_by_udi (pool, storage_udi); - if (drive_device == NULL) - goto fail; - - /* g_warning ("drive_device = %p", drive_device); */ - - mount = g_object_new (G_TYPE_HAL_MOUNT, NULL); - mount->volume_monitor = volume_monitor; - g_object_add_weak_pointer (G_OBJECT (mount->volume_monitor), (gpointer) &(mount->volume_monitor)); - mount->device_path = g_strdup (hal_device_get_property_string (device, "block.device")); - mount->mount_path = g_strdup ("/"); - mount->device = g_object_ref (device); - mount->drive_device = g_object_ref (drive_device); - mount->override_root = override_root != NULL ? g_object_ref (override_root) : NULL; - mount->override_icon = override_icon != NULL ? g_object_ref (override_icon) : NULL; - mount->override_name = g_strdup (override_name); - mount->cannot_unmount = cannot_unmount; - - g_signal_connect_object (device, "hal_property_changed", (GCallback) hal_changed, mount, 0); - g_signal_connect_object (drive_device, "hal_property_changed", (GCallback) hal_changed, mount, 0); - - compute_uuid (mount); - update_from_hal (mount, FALSE); - - /* need to do this last */ - mount->volume = volume; - if (volume != NULL) - g_hal_volume_set_mount (volume, mount); - - return mount; - - fail: - return NULL; -} - -void -g_hal_mount_override_name (GHalMount *mount, const char *name) -{ - G_LOCK (hal_mount); - - g_free (mount->override_name); - - if (name != NULL) - mount->override_name = g_strdup (name); - else - mount->override_name = NULL; - - G_UNLOCK (hal_mount); - - update_from_hal (mount, TRUE); -} - -void -g_hal_mount_override_icon (GHalMount *mount, GIcon *icon) -{ - G_LOCK (hal_mount); - if (mount->override_icon != NULL) - g_object_unref (mount->override_icon); - - if (icon != NULL) - mount->override_icon = g_object_ref (icon); - else - mount->override_icon = NULL; - - G_UNLOCK (hal_mount); - - update_from_hal (mount, TRUE); -} - -GHalMount * -g_hal_mount_new (GVolumeMonitor *volume_monitor, - GUnixMountEntry *mount_entry, - HalPool *pool, - GHalVolume *volume) -{ - HalDevice *device; - HalDevice *drive_device; - const char *storage_udi; - GHalMount *mount; - - /* If no volume for mount - Ignore internal things */ - if (volume == NULL && !g_unix_mount_guess_should_display (mount_entry)) - return NULL; - - mount = g_object_new (G_TYPE_HAL_MOUNT, NULL); - mount->volume_monitor = volume_monitor; - g_object_add_weak_pointer (G_OBJECT (volume_monitor), (gpointer) &(mount->volume_monitor)); - mount->device_path = g_strdup (g_unix_mount_get_device_path (mount_entry)); - mount->mount_path = g_strdup (g_unix_mount_get_mount_path (mount_entry)); - mount->device = NULL; - mount->drive_device = NULL; - mount->uuid = NULL; - - if (pool != NULL) - { - device = hal_pool_get_device_by_capability_and_string (pool, - "volume", - "block.device", - mount->device_path); - /* g_warning ("device = %p for %s", device, mount->device_path); */ - if (device != NULL) - { - /* g_warning ("udi = %s", hal_device_get_udi (device)); */ - - storage_udi = hal_device_get_property_string (device, "block.storage_device"); - if (storage_udi == NULL) - goto not_hal; - - /* g_warning ("storage_udi = %s", storage_udi); */ - - drive_device = hal_pool_get_device_by_udi (pool, storage_udi); - if (drive_device == NULL) - goto not_hal; - - /* g_warning ("drive_device = %p", drive_device); */ - - mount->device = g_object_ref (device); - mount->drive_device = g_object_ref (drive_device); - - g_signal_connect_object (device, "hal_property_changed", (GCallback) hal_changed, mount, 0); - g_signal_connect_object (drive_device, "hal_property_changed", (GCallback) hal_changed, mount, 0); - - compute_uuid (mount); - update_from_hal (mount, FALSE); - - goto was_hal; - } - } - - not_hal: - - if (volume != NULL) - { - g_object_unref (mount); - return NULL; - } - - mount->name = g_unix_mount_guess_name (mount_entry); - mount->icon = g_unix_mount_guess_icon (mount_entry); - - was_hal: - - /* need to do this last */ - mount->volume = volume; - if (volume != NULL) - g_hal_volume_set_mount (volume, mount); - - return mount; -} - -void -g_hal_mount_unmounted (GHalMount *mount) -{ - G_LOCK (hal_mount); - if (mount->volume != NULL) - { - g_hal_volume_unset_mount (mount->volume, mount); - mount->volume = NULL; - g_idle_add (changed_in_idle, g_object_ref (mount)); - } - G_UNLOCK (hal_mount); -} - -void -g_hal_mount_unset_volume (GHalMount *mount, - GHalVolume *volume) -{ - G_LOCK (hal_mount); - if (mount->volume == volume) - { - mount->volume = NULL; - g_idle_add (changed_in_idle, g_object_ref (mount)); - } - G_UNLOCK (hal_mount); -} - -static GFile * -get_root (GHalMount *hal_mount) -{ - if (hal_mount->override_root != NULL) - return g_object_ref (hal_mount->override_root); - else - return g_file_new_for_path (hal_mount->mount_path); -} - -static GFile * -g_hal_mount_get_root (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - GFile *root; - - G_LOCK (hal_mount); - root = get_root (hal_mount); - G_UNLOCK (hal_mount); - - return root; -} - -static GIcon * -g_hal_mount_get_icon (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - GIcon *icon; - - G_LOCK (hal_mount); - icon = g_object_ref (hal_mount->icon); - G_UNLOCK (hal_mount); - - return icon; -} - -static char * -g_hal_mount_get_uuid (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - char *uuid; - - G_LOCK (hal_mount); - uuid = g_strdup (hal_mount->uuid); - G_UNLOCK (hal_mount); - - return uuid; -} - -static char * -g_hal_mount_get_name (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - char *name; - - G_LOCK (hal_mount); - name = g_strdup (hal_mount->name); - G_UNLOCK (hal_mount); - - return name; -} - -gboolean -g_hal_mount_has_uuid (GHalMount *mount, - const char *uuid) -{ - gboolean res; - - G_LOCK (hal_mount); - res = FALSE; - if (mount->uuid != NULL) - res = strcmp (mount->uuid, uuid) == 0; - G_UNLOCK (hal_mount); - - return res; -} - -gboolean -g_hal_mount_has_mount_path (GHalMount *mount, - const char *mount_path) -{ - gboolean res; - - G_LOCK (hal_mount); - res = strcmp (mount->mount_path, mount_path) == 0; - G_UNLOCK (hal_mount); - return res; -} - -gboolean -g_hal_mount_has_udi (GHalMount *mount, - const char *udi) -{ - gboolean res; - - G_LOCK (hal_mount); - res = FALSE; - if (mount->device != NULL) - res = strcmp (hal_device_get_udi (mount->device), udi) == 0; - G_UNLOCK (hal_mount); - - return res; -} - -static GDrive * -g_hal_mount_get_drive (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - GDrive *drive; - - G_LOCK (hal_mount); - drive = NULL; - if (hal_mount->volume != NULL) - drive = g_volume_get_drive (G_VOLUME (hal_mount->volume)); - G_UNLOCK (hal_mount); - - return drive; -} - -static GVolume * -g_hal_mount_get_volume (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - GVolume *volume; - - G_LOCK (hal_mount); - volume = NULL; - if (hal_mount->volume) - volume = G_VOLUME (g_object_ref (hal_mount->volume)); - G_UNLOCK (hal_mount); - - return volume; -} - -static gboolean -g_hal_mount_can_unmount (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - gboolean res; - - G_LOCK (hal_mount); - res = TRUE; - if (hal_mount->cannot_unmount) - res = FALSE; - G_UNLOCK (hal_mount); - - return res; -} - -static gboolean -g_hal_mount_can_eject (GMount *mount) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - GDrive *drive; - gboolean can_eject; - - G_LOCK (hal_mount); - can_eject = FALSE; - if (hal_mount->volume != NULL) - { - drive = g_volume_get_drive (G_VOLUME (hal_mount->volume)); - if (drive != NULL) - can_eject = g_drive_can_eject (drive); - } - G_UNLOCK (hal_mount); - - return can_eject; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; - int error_fd; - GIOChannel *error_channel; - guint error_channel_source_id; - GString *error_string; - gboolean using_legacy; -} UnmountOp; - -static void -unmount_cb (GPid pid, gint status, gpointer user_data) -{ - UnmountOp *data = user_data; - GSimpleAsyncResult *simple; - - if (WEXITSTATUS (status) != 0) - { - if (data->using_legacy) - { - GError *error; - error = g_error_new_literal (G_IO_ERROR, - G_IO_ERROR_FAILED, - data->error_string->str); - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_error_free (error); - } - else - { - GError *error; - error = g_error_new_literal (G_IO_ERROR, - G_IO_ERROR_FAILED_HANDLED, - "You are not supposed to show G_IO_ERROR_FAILED_HANDLED in the UI"); - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_error_free (error); - } - } - else - { - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); - - g_source_remove (data->error_channel_source_id); - g_io_channel_unref (data->error_channel); - g_string_free (data->error_string, TRUE); - close (data->error_fd); - g_spawn_close_pid (pid); - - g_object_unref (data->object); - g_free (data); -} - -static gboolean -unmount_read_error (GIOChannel *channel, - GIOCondition condition, - gpointer user_data) -{ - char *str; - gsize str_len; - UnmountOp *data = user_data; - - g_io_channel_read_to_end (channel, &str, &str_len, NULL); - g_string_append (data->error_string, str); - g_free (str); - return TRUE; -} - -static void -unmount_do (GMount *mount, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data, - char **argv, - gboolean using_legacy) -{ - UnmountOp *data; - GPid child_pid; - GError *error; - - data = g_new0 (UnmountOp, 1); - data->object = g_object_ref (mount); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - data->using_legacy = using_legacy; - - error = NULL; - if (!g_spawn_async_with_pipes (NULL, /* working dir */ - argv, - NULL, /* envp */ - G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH, - NULL, /* child_setup */ - NULL, /* user_data for child_setup */ - &child_pid, - NULL, /* standard_input */ - NULL, /* standard_output */ - &(data->error_fd), - &error)) - { - GSimpleAsyncResult *simple; - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_error_free (error); - g_free (data); - return; - } - data->error_string = g_string_new (""); - data->error_channel = g_io_channel_unix_new (data->error_fd); - data->error_channel_source_id = g_io_add_watch (data->error_channel, G_IO_IN, unmount_read_error, data); - g_child_watch_add (child_pid, unmount_cb, data); -} - - -static void -g_hal_mount_unmount (GMount *mount, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - char *argv[] = {"gnome-mount", "-u", "-b", "-d", NULL, NULL}; - gboolean using_legacy = FALSE; - char *d, *m; - - G_LOCK (hal_mount); - d = g_strdup (hal_mount->device_path); - m = g_strdup (hal_mount->mount_path); - G_UNLOCK (hal_mount); - - - if (hal_mount->device != NULL) - argv[4] = d; - else - { - using_legacy = TRUE; - argv[0] = "umount"; - argv[1] = m; - argv[2] = NULL; - } - - unmount_do (mount, cancellable, callback, user_data, argv, using_legacy); - g_free (d); - g_free (m); -} - -static gboolean -g_hal_mount_unmount_finish (GMount *mount, - GAsyncResult *result, - GError **error) -{ - return TRUE; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; -} EjectWrapperOp; - -static void -eject_wrapper_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - EjectWrapperOp *data = user_data; - data->callback (data->object, res, data->user_data); - g_object_unref (data->object); - g_free (data); -} - -static void -g_hal_mount_eject (GMount *mount, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - GDrive *drive; - - G_LOCK (hal_mount); - drive = NULL; - if (hal_mount->volume != NULL) - drive = g_volume_get_drive (G_VOLUME (hal_mount->volume)); - G_UNLOCK (hal_mount); - - if (drive != NULL) - { - EjectWrapperOp *data; - data = g_new0 (EjectWrapperOp, 1); - data->object = g_object_ref (mount); - data->callback = callback; - data->user_data = user_data; - g_drive_eject (drive, flags, cancellable, eject_wrapper_callback, data); - g_object_unref (drive); - } -} - -static gboolean -g_hal_mount_eject_finish (GMount *mount, - GAsyncResult *result, - GError **error) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - GDrive *drive; - gboolean res; - - res = TRUE; - - G_LOCK (hal_mount); - drive = NULL; - if (hal_mount->volume != NULL) - drive = g_volume_get_drive (G_VOLUME (hal_mount->volume)); - G_UNLOCK (hal_mount); - - if (drive != NULL) - { - res = g_drive_eject_finish (drive, result, error); - g_object_unref (drive); - } - return res; -} - -/* TODO: handle force_rescan */ -static char ** -g_hal_mount_guess_content_type_sync (GMount *mount, - gboolean force_rescan, - GCancellable *cancellable, - GError **error) -{ - GHalMount *hal_mount = G_HAL_MOUNT (mount); - const char *disc_type; - char **x_content_types; - GFile *root; - GPtrArray *p; - char **result; - int n; - char **caps; - char *uri; - - p = g_ptr_array_new (); - - G_LOCK (hal_mount); - - root = get_root (hal_mount); - uri = g_file_get_uri (root); - if (g_str_has_prefix (uri, "burn://")) - { - /* doesn't make sense to probe burn:/// - look at the disc type instead */ - if (hal_mount->device != NULL) - { - disc_type = hal_device_get_property_string (hal_mount->device, "volume.disc.type"); - if (disc_type != NULL) - { - if (g_str_has_prefix (disc_type, "dvd")) - g_ptr_array_add (p, g_strdup ("x-content/blank-dvd")); - else if (g_str_has_prefix (disc_type, "hddvd")) - g_ptr_array_add (p, g_strdup ("x-content/blank-hddvd")); - else if (g_str_has_prefix (disc_type, "bd")) - g_ptr_array_add (p, g_strdup ("x-content/blank-bd")); - else - g_ptr_array_add (p, g_strdup ("x-content/blank-cd")); /* assume CD */ - } - } - } - else - { - /* sniff content type */ - x_content_types = g_content_type_guess_for_tree (root); - if (x_content_types != NULL) - { - for (n = 0; x_content_types[n] != NULL; n++) - g_ptr_array_add (p, g_strdup (x_content_types[n])); - g_strfreev (x_content_types); - } - } - g_object_unref (root); - g_free (uri); - - /* also add content types from hal capabilities */ - if (hal_mount->drive_device != NULL) - { - caps = dupv_and_uniqify (hal_device_get_property_strlist (hal_mount->drive_device, "info.capabilities")); - if (caps != NULL) - { - for (n = 0; caps[n] != NULL; n++) - { - if (strcmp (caps[n], "portable_audio_player") == 0) - g_ptr_array_add (p, g_strdup ("x-content/audio-player")); - } - g_strfreev (caps); - } - } - - if (p->len == 0) - { - result = NULL; - g_ptr_array_free (p, TRUE); - } - else - { - g_ptr_array_add (p, NULL); - result = (char **) g_ptr_array_free (p, FALSE); - } - - G_UNLOCK (hal_mount); - - return result; -} - -/* since we're an out-of-process volume monitor we'll just do this sync */ -static void -g_hal_mount_guess_content_type (GMount *mount, - gboolean force_rescan, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - /* TODO: handle force_rescan */ - simple = g_simple_async_result_new (G_OBJECT (mount), - callback, - user_data, - NULL); - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -static char ** -g_hal_mount_guess_content_type_finish (GMount *mount, - GAsyncResult *result, - GError **error) -{ - /* TODO: handle force_rescan */ - return g_hal_mount_guess_content_type_sync (mount, FALSE, NULL, error); -} - -static void -g_hal_mount_mount_iface_init (GMountIface *iface) -{ - iface->get_root = g_hal_mount_get_root; - iface->get_name = g_hal_mount_get_name; - iface->get_icon = g_hal_mount_get_icon; - iface->get_uuid = g_hal_mount_get_uuid; - iface->get_drive = g_hal_mount_get_drive; - iface->get_volume = g_hal_mount_get_volume; - iface->can_unmount = g_hal_mount_can_unmount; - iface->can_eject = g_hal_mount_can_eject; - iface->unmount = g_hal_mount_unmount; - iface->unmount_finish = g_hal_mount_unmount_finish; - iface->eject = g_hal_mount_eject; - iface->eject_finish = g_hal_mount_eject_finish; - iface->guess_content_type = g_hal_mount_guess_content_type; - iface->guess_content_type_finish = g_hal_mount_guess_content_type_finish; - iface->guess_content_type_sync = g_hal_mount_guess_content_type_sync; -} - -#define INSENSITIVE_SEARCH_ITEMS_PER_CALLBACK 100 - -static void -enumerated_children_callback (GObject *source_object, GAsyncResult *res, - gpointer user_data); - -static void -more_files_callback (GObject *source_object, GAsyncResult *res, - gpointer user_data); - -static void -find_file_insensitive_exists_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data); - -typedef struct _InsensitiveFileSearchData -{ - GFile *root; - gchar *original_path; - gchar **split_path; - gint index; - GFileEnumerator *enumerator; - GFile *current_file; - - GCancellable *cancellable; - GAsyncReadyCallback callback; - gpointer user_data; -} InsensitiveFileSearchData; - -static void -_g_find_file_insensitive_async (GFile *parent, - const gchar *name, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - InsensitiveFileSearchData *data; - GFile *direct_file = g_file_get_child (parent, name); - - data = g_new0 (InsensitiveFileSearchData, 1); - data->cancellable = cancellable; - data->callback = callback; - data->user_data = user_data; - data->root = g_object_ref (parent); - data->original_path = g_strdup (name); - - g_file_query_info_async (direct_file, G_FILE_ATTRIBUTE_STANDARD_TYPE, - G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, - cancellable, - find_file_insensitive_exists_callback, data); - - -} - -static void -clear_find_file_insensitive_state (InsensitiveFileSearchData *data) -{ - if (data->root) - g_object_unref (data->root); - g_free (data->original_path); - if (data->split_path) - g_strfreev (data->split_path); - if (data->enumerator) - g_object_unref (data->enumerator); - if (data->current_file) - g_object_unref (data->current_file); - g_free (data); -} - -static void -find_file_insensitive_exists_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GFileInfo *info; - InsensitiveFileSearchData *data = (InsensitiveFileSearchData *) (user_data); - - /* The file exists and can be found with the given path, no need to search. */ - if ((info = g_file_query_info_finish (G_FILE (source_object), res, NULL))) - { - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new (G_OBJECT (data->root), - data->callback, - data->user_data, - _g_find_file_insensitive_async); - - g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (source_object), g_object_unref); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - clear_find_file_insensitive_state (data); - } - - else - { - data->split_path = g_strsplit (data->original_path, G_DIR_SEPARATOR_S, -1); - data->index = 0; - data->enumerator = NULL; - data->current_file = g_object_ref (data->root); - - /* Skip any empty components due to multiple slashes */ - while (data->split_path[data->index] != NULL && - *data->split_path[data->index] == 0) - data->index++; - - g_file_enumerate_children_async (data->current_file, - G_FILE_ATTRIBUTE_STANDARD_NAME, - 0, G_PRIORITY_DEFAULT, - data->cancellable, - enumerated_children_callback, data); - } - - g_object_unref (source_object); -} - -static void -enumerated_children_callback (GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - GFileEnumerator *enumerator; - InsensitiveFileSearchData *data = (InsensitiveFileSearchData *) (user_data); - - enumerator = g_file_enumerate_children_finish (G_FILE (source_object), - res, NULL); - - if (enumerator == NULL) - { - GSimpleAsyncResult *simple; - GFile *file; - - simple = g_simple_async_result_new (G_OBJECT (data->root), - data->callback, - data->user_data, - _g_find_file_insensitive_async); - - file = g_file_get_child (data->root, data->original_path); - - g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (file), g_object_unref); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - clear_find_file_insensitive_state (data); - return; - } - - data->enumerator = enumerator; - g_file_enumerator_next_files_async (enumerator, - INSENSITIVE_SEARCH_ITEMS_PER_CALLBACK, - G_PRIORITY_DEFAULT, - data->cancellable, - more_files_callback, - data); -} - -static void -more_files_callback (GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - InsensitiveFileSearchData *data = (InsensitiveFileSearchData *) (user_data); - GList *files, *l; - gchar *filename = NULL, *component, *case_folded_name, - *name_collation_key; - gboolean end_of_files, is_utf8; - - files = g_file_enumerator_next_files_finish (data->enumerator, - res, NULL); - - end_of_files = files == NULL; - - component = data->split_path[data->index]; - g_return_if_fail (component != NULL); - - is_utf8 = (g_utf8_validate (component, -1, NULL)); - if (is_utf8) - { - case_folded_name = g_utf8_casefold (component, -1); - name_collation_key = g_utf8_collate_key (case_folded_name, -1); - g_free (case_folded_name); - } - - else - { - name_collation_key = g_ascii_strdown (component, -1); - } - - for (l = files; l != NULL; l = l->next) - { - GFileInfo *info; - const gchar *this_name; - gchar *key; - - info = l->data; - this_name = g_file_info_get_name (info); - - if (is_utf8 && g_utf8_validate (this_name, -1, NULL)) - { - gchar *case_folded; - case_folded = g_utf8_casefold (this_name, -1); - key = g_utf8_collate_key (case_folded, -1); - g_free (case_folded); - } - else - { - key = g_ascii_strdown (this_name, -1); - } - - if (strcmp (key, name_collation_key) == 0) - filename = g_strdup (this_name); - g_free (key); - - if (filename) - break; - } - - g_list_foreach (files, (GFunc)g_object_unref, NULL); - g_list_free (files); - g_free (name_collation_key); - - if (filename) - { - GFile *next_file; - - g_file_enumerator_close_async (data->enumerator, - G_PRIORITY_DEFAULT, - data->cancellable, - NULL, NULL); - g_object_unref (data->enumerator); - data->enumerator = NULL; - - /* Set the current file and continue searching */ - next_file = g_file_get_child (data->current_file, filename); - g_free (filename); - g_object_unref (data->current_file); - data->current_file = next_file; - - data->index++; - /* Skip any empty components due to multiple slashes */ - while (data->split_path[data->index] != NULL && - *data->split_path[data->index] == 0) - data->index++; - - if (data->split_path[data->index] == NULL) - { - /* Search is complete, file was found */ - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new (G_OBJECT (data->root), - data->callback, - data->user_data, - _g_find_file_insensitive_async); - - g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (data->current_file), g_object_unref); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - clear_find_file_insensitive_state (data); - return; - } - - /* Continue searching down the tree */ - g_file_enumerate_children_async (data->current_file, - G_FILE_ATTRIBUTE_STANDARD_NAME, - 0, G_PRIORITY_DEFAULT, - data->cancellable, - enumerated_children_callback, - data); - return; - } - - if (end_of_files) - { - /* Could not find the given file, abort the search */ - GSimpleAsyncResult *simple; - GFile *file; - - g_object_unref (data->enumerator); - data->enumerator = NULL; - - simple = g_simple_async_result_new (G_OBJECT (data->root), - data->callback, - data->user_data, - _g_find_file_insensitive_async); - - file = g_file_get_child (data->root, data->original_path); - g_simple_async_result_set_op_res_gpointer (simple, file, g_object_unref); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - clear_find_file_insensitive_state (data); - return; - } - - /* Continue enumerating */ - g_file_enumerator_next_files_async (data->enumerator, - INSENSITIVE_SEARCH_ITEMS_PER_CALLBACK, - G_PRIORITY_DEFAULT, - data->cancellable, - more_files_callback, - data); -} - -static GFile * -_g_find_file_insensitive_finish (GFile *parent, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - GFile *file; - - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - - file = G_FILE (g_simple_async_result_get_op_res_gpointer (simple)); - return g_object_ref (file); -} - diff --git a/gnome-2-24/monitor/hal/ghalmount.h b/gnome-2-24/monitor/hal/ghalmount.h deleted file mode 100644 index 31981aed..00000000 --- a/gnome-2-24/monitor/hal/ghalmount.h +++ /dev/null @@ -1,76 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_HAL_MOUNT_H__ -#define __G_HAL_MOUNT_H__ - -#include -#include - -#include "hal-pool.h" -#include "ghalvolumemonitor.h" - -G_BEGIN_DECLS - -#define G_TYPE_HAL_MOUNT (g_hal_mount_get_type ()) -#define G_HAL_MOUNT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_HAL_MOUNT, GHalMount)) -#define G_HAL_MOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_HAL_MOUNT, GHalMountClass)) -#define G_IS_HAL_MOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_HAL_MOUNT)) -#define G_IS_HAL_MOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_HAL_MOUNT)) - -typedef struct _GHalMountClass GHalMountClass; - -struct _GHalMountClass { - GObjectClass parent_class; -}; - -GType g_hal_mount_get_type (void) G_GNUC_CONST; - -GHalMount * g_hal_mount_new_for_hal_device (GVolumeMonitor *volume_monitor, - HalDevice *device, - GFile *override_root, - const char *override_name, - GIcon *override_icon, - gboolean cannot_unmount, - HalPool *pool, - GHalVolume *volume); -GHalMount * g_hal_mount_new (GVolumeMonitor *volume_monitor, - GUnixMountEntry *mount_entry, - HalPool *pool, - GHalVolume *volume); -gboolean g_hal_mount_has_mount_path (GHalMount *mount, - const char *mount_path); -gboolean g_hal_mount_has_udi (GHalMount *mount, - const char *udi); -gboolean g_hal_mount_has_uuid (GHalMount *mount, - const char *uuid); -void g_hal_mount_unset_volume (GHalMount *mount, - GHalVolume *volume); -void g_hal_mount_unmounted (GHalMount *mount); -void g_hal_mount_override_name (GHalMount *mount, - const char *name); -void g_hal_mount_override_icon (GHalMount *mount, - GIcon *icon); - -G_END_DECLS - -#endif /* __G_HAL_MOUNT_H__ */ diff --git a/gnome-2-24/monitor/hal/ghalvolume.c b/gnome-2-24/monitor/hal/ghalvolume.c deleted file mode 100644 index 12579887..00000000 --- a/gnome-2-24/monitor/hal/ghalvolume.c +++ /dev/null @@ -1,1068 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "ghaldrive.h" -#include "ghalvolume.h" -#include "ghalmount.h" - -#include "hal-utils.h" - -/* Protects all fields of GHalDrive that can change */ -G_LOCK_DEFINE_STATIC(hal_volume); - -struct _GHalVolume { - GObject parent; - - GVolumeMonitor *volume_monitor; /* owned by volume monitor */ - GHalMount *mount; /* owned by volume monitor */ - GHalDrive *drive; /* owned by volume monitor */ - - char *device_path; - char *mount_path; - char *uuid; - HalDevice *device; - HalDevice *drive_device; - - /* set on creation if we won't create a GHalMount object ourselves - * and instead except to adopt one, with the given mount root, - * via adopt_orphan_mount() - */ - GFile *foreign_mount_root; - GMount *foreign_mount; - gboolean is_mountable; - gboolean ignore_automount; - - char *name; - char *icon; - char *icon_fallback; -}; - -static void g_hal_volume_volume_iface_init (GVolumeIface *iface); - -G_DEFINE_TYPE_EXTENDED (GHalVolume, g_hal_volume, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_VOLUME, - g_hal_volume_volume_iface_init)) - -static void -g_hal_volume_finalize (GObject *object) -{ - GHalVolume *volume; - - volume = G_HAL_VOLUME (object); - - if (volume->mount != NULL) - g_hal_mount_unset_volume (volume->mount, volume); - - if (volume->drive != NULL) - g_hal_drive_unset_volume (volume->drive, volume); - - g_free (volume->mount_path); - g_free (volume->device_path); - g_free (volume->uuid); - if (volume->device != NULL) - g_object_unref (volume->device); - if (volume->drive_device != NULL) - g_object_unref (volume->drive_device); - - if (volume->foreign_mount_root != NULL) - g_object_unref (volume->foreign_mount_root); - - if (volume->foreign_mount != NULL) - g_object_unref (volume->foreign_mount); - - if (volume->volume_monitor != NULL) - g_object_remove_weak_pointer (G_OBJECT (volume->volume_monitor), (gpointer) &(volume->volume_monitor)); - - g_free (volume->name); - g_free (volume->icon); - g_free (volume->icon_fallback); - - if (G_OBJECT_CLASS (g_hal_volume_parent_class)->finalize) - (*G_OBJECT_CLASS (g_hal_volume_parent_class)->finalize) (object); -} - -static void -g_hal_volume_class_init (GHalVolumeClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = g_hal_volume_finalize; -} - -static void -g_hal_volume_init (GHalVolume *hal_volume) -{ -} - -static gboolean -changed_in_idle (gpointer data) -{ - GHalVolume *volume = data; - - g_signal_emit_by_name (volume, "changed"); - if (volume->volume_monitor != NULL) - g_signal_emit_by_name (volume->volume_monitor, "volume_changed", volume); - g_object_unref (volume); - - return FALSE; -} - -#define KILOBYTE_FACTOR 1000.0 -#define MEGABYTE_FACTOR (1000.0 * 1000.0) -#define GIGABYTE_FACTOR (1000.0 * 1000.0 * 1000.0) - -/** - * format_size_for_display: - * @size: a number of octects - * - * Format a human readable string that can conveys how much storage a - * user-visible drive or piece of media can hold. - * - * As a matter of policy, we want this string to resemble what's on - * the packaging of the drive/media. Since all manufacturers use - * powers of 10, g_format_size_for_display() is not suitable here. - * - * TODO: we probably want to round to nearest power of two if @size is - * "close" (e.g. within 5%) - this is to avoid e.g. 63.4G when the - * packaging says "64G drive". We could also use per-drive or - * per-media quirks to make a better guess. - * - * Returns: A human readable string, caller must free it using - * g_free(). - **/ -static char * -format_size_for_display (guint64 size) -{ - char *str; - gdouble displayed_size; - - if (size < MEGABYTE_FACTOR) - { - displayed_size = (double) size / KILOBYTE_FACTOR; - str = g_strdup_printf (_("%.1f kB"), displayed_size); - } - else if (size < GIGABYTE_FACTOR) - { - displayed_size = (double) size / MEGABYTE_FACTOR; - str = g_strdup_printf (_("%.1f MB"), displayed_size); - } - else - { - displayed_size = (double) size / GIGABYTE_FACTOR; - str = g_strdup_printf (_("%.1f GB"), displayed_size); - } - - return str; -} - -static void -do_update_from_hal (GHalVolume *mv) -{ - const char *drive_type; - const char *drive_bus; - gboolean drive_uses_removable_media; - const char *volume_fs_label; - guint64 volume_size; - gboolean volume_is_disc; - gboolean volume_disc_has_audio; - gboolean volume_disc_has_data; - const char *volume_disc_type; - gboolean volume_disc_is_blank; - const char *volume_fsusage; - const char *volume_fstype; - HalDevice *volume; - HalDevice *drive; - char *name; - char *size; - gboolean is_crypto; - gboolean is_crypto_cleartext; - - volume = mv->device; - drive = mv->drive_device; - - drive_type = hal_device_get_property_string (drive, "storage.drive_type"); - drive_bus = hal_device_get_property_string (drive, "storage.bus"); - drive_uses_removable_media = hal_device_get_property_bool (drive, "storage.removable"); - volume_fs_label = hal_device_get_property_string (volume, "volume.label"); - volume_size = hal_device_get_property_uint64 (volume, "volume.size"); - volume_is_disc = hal_device_get_property_bool (volume, "volume.is_disc"); - volume_disc_has_audio = hal_device_get_property_bool (volume, "volume.disc.has_audio"); - volume_disc_has_data = hal_device_get_property_bool (volume, "volume.disc.has_data"); - volume_disc_is_blank = hal_device_get_property_bool (volume, "volume.disc.is_blank"); - volume_disc_type = hal_device_get_property_string (volume, "volume.disc.type"); - volume_fsusage = hal_device_get_property_string (volume, "volume.fsusage"); - volume_fstype = hal_device_get_property_string (volume, "volume.fstype"); - - is_crypto = FALSE; - is_crypto_cleartext = FALSE; - if (strcmp (hal_device_get_property_string (volume, "volume.fsusage"), "crypto") == 0) - is_crypto = TRUE; - if (strlen (hal_device_get_property_string (volume, "volume.crypto_luks.clear.backing_volume")) > 0) - is_crypto_cleartext = TRUE; - - if (volume_is_disc && volume_disc_has_audio && mv->foreign_mount_root != NULL) - name = g_strdup (_("Audio Disc")); - else - { - if (strcmp (volume_fsusage, "crypto") == 0 && strcmp (volume_fstype, "crypto_LUKS") == 0) - { - size = format_size_for_display (volume_size); - /* Translators: %s is the size of the volume (e.g. 512 MB) */ - name = g_strdup_printf (_("%s Encrypted Data"), size); - g_free (size); - } - else - { - if (volume_fs_label != NULL && strlen (volume_fs_label) > 0) - name = g_strdup (volume_fs_label); - else if (volume_is_disc) - { - if (volume_disc_has_audio) - { - if (volume_disc_has_data) - name = g_strdup (_("Mixed Audio/Data Disc")); - else - name = g_strdup (_("Audio Disc")); - } - else - name = g_strdup (get_disc_name (volume_disc_type, volume_disc_is_blank)); - } - else - { - size = format_size_for_display (volume_size); - /* Translators: %s is the size of the volume (e.g. 512 MB) */ - name = g_strdup_printf (_("%s Media"), size); - g_free (size); - } - } - } - - mv->name = name; - mv->icon = _drive_get_icon (drive); /* use the drive icon since we're unmounted */ - - if (is_crypto || is_crypto_cleartext) - { - mv->icon_fallback = mv->icon; - mv->icon = g_strdup ("drive-encrypted"); - } - - if (hal_device_get_property_bool (volume, "volume.is_mounted")) - mv->mount_path = g_strdup (hal_device_get_property_string (volume, "volume.mount_point")); - else - mv->mount_path = NULL; - - g_object_set_data_full (G_OBJECT (mv), - "hal-storage-device-capabilities", - dupv_and_uniqify (hal_device_get_property_strlist (mv->drive_device, "info.capabilities")), - (GDestroyNotify) g_strfreev); - - if (volume_disc_type != NULL && strlen (volume_disc_type) == 0) - volume_disc_type = NULL; - g_object_set_data_full (G_OBJECT (mv), - "hal-volume.disc.type", - g_strdup (volume_disc_type), - (GDestroyNotify) g_free); -} - -static void -update_from_hal (GHalVolume *mv, gboolean emit_changed) -{ - char *old_name; - char *old_icon; - char *old_mount_path; - - G_LOCK (hal_volume); - - old_name = g_strdup (mv->name); - old_icon = g_strdup (mv->icon); - old_mount_path = g_strdup (mv->mount_path); - - g_free (mv->name); - g_free (mv->icon); - g_free (mv->mount_path); - do_update_from_hal (mv); - - if (emit_changed) - { - gboolean mount_path_changed; - - if ((old_mount_path == NULL && mv->mount_path != NULL) || - (old_mount_path != NULL && mv->mount_path == NULL) || - (old_mount_path != NULL && mv->mount_path != NULL && strcmp (old_mount_path, mv->mount_path) != 0)) - mount_path_changed = TRUE; - else - mount_path_changed = FALSE; - - if (mount_path_changed || - (old_name == NULL || - old_icon == NULL || - strcmp (old_name, mv->name) != 0 || - strcmp (old_icon, mv->icon) != 0)) - g_idle_add (changed_in_idle, g_object_ref (mv)); - } - g_free (old_name); - g_free (old_icon); - g_free (old_mount_path); - - G_UNLOCK (hal_volume); -} - -static void -hal_changed (HalDevice *device, const char *key, gpointer user_data) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (user_data); - - /*g_warning ("hal modifying %s (property %s changed)", hal_volume->device_path, key);*/ - update_from_hal (hal_volume, TRUE); -} - -static void -compute_uuid (GHalVolume *volume) -{ - const char *fs_uuid; - const char *fs_label; - - /* use the FS uuid before falling back to the FS label */ - - fs_uuid = hal_device_get_property_string (volume->device, "volume.uuid"); - fs_label = hal_device_get_property_string (volume->device, "volume.label"); - - if (strlen (fs_uuid) == 0) - { - if (strlen (fs_label) == 0) - volume->uuid = NULL; - else - volume->uuid = g_strdup (fs_label); - } - else - volume->uuid = g_strdup (fs_uuid); -} - -GHalVolume * -g_hal_volume_new (GVolumeMonitor *volume_monitor, - HalDevice *device, - HalPool *pool, - GFile *foreign_mount_root, - gboolean is_mountable, - GHalDrive *drive) -{ - GHalVolume *volume; - HalDevice *drive_device; - const char *storage_udi; - const char *device_path; - gboolean ignore_automount; - - ignore_automount = FALSE; - - if (hal_device_has_capability (device, "block")) - { - storage_udi = hal_device_get_property_string (device, "block.storage_device"); - if (storage_udi == NULL) - return NULL; - - drive_device = hal_pool_get_device_by_udi (pool, storage_udi); - if (drive_device == NULL) - return NULL; - - device_path = hal_device_get_property_string (device, "block.device"); - } - else - { - return NULL; - } - - if (drive_device && - hal_device_has_property (drive_device, "storage.automount_enabled_hint") && - !hal_device_get_property_bool (drive_device, "storage.automount_enabled_hint")) - ignore_automount = TRUE; - - volume = g_object_new (G_TYPE_HAL_VOLUME, NULL); - volume->volume_monitor = volume_monitor; - g_object_add_weak_pointer (G_OBJECT (volume_monitor), (gpointer) &(volume->volume_monitor)); - volume->mount_path = NULL; - volume->device_path = g_strdup (device_path); - volume->device = g_object_ref (device); - volume->drive_device = g_object_ref (drive_device); - volume->foreign_mount_root = foreign_mount_root != NULL ? g_object_ref (foreign_mount_root) : NULL; - volume->is_mountable = is_mountable; - volume->ignore_automount = ignore_automount || ! hal_device_is_recently_plugged_in (device); - - g_signal_connect_object (device, "hal_property_changed", (GCallback) hal_changed, volume, 0); - g_signal_connect_object (drive_device, "hal_property_changed", (GCallback) hal_changed, volume, 0); - - compute_uuid (volume); - update_from_hal (volume, FALSE); - - /* need to do this last */ - volume->drive = drive; - if (drive != NULL) - g_hal_drive_set_volume (drive, volume); - - return volume; -} - -/** - * g_hal_volume_removed: - * @volume: - * - **/ -void -g_hal_volume_removed (GHalVolume *volume) -{ - - G_LOCK (hal_volume); - - if (volume->mount != NULL) - { - g_hal_mount_unset_volume (volume->mount, volume); - volume->mount = NULL; - } - - if (volume->drive != NULL) - { - g_hal_drive_unset_volume (volume->drive, volume); - volume->drive = NULL; - } - - G_UNLOCK (hal_volume); -} - -void -g_hal_volume_set_mount (GHalVolume *volume, - GHalMount *mount) -{ - G_LOCK (hal_volume); - if (volume->mount != mount) - { - - if (volume->mount != NULL) - g_hal_mount_unset_volume (volume->mount, volume); - - volume->mount = mount; - - g_idle_add (changed_in_idle, g_object_ref (volume)); - } - G_UNLOCK (hal_volume); -} - -void -g_hal_volume_unset_mount (GHalVolume *volume, - GHalMount *mount) -{ - G_LOCK (hal_volume); - if (volume->mount == mount) - { - volume->mount = NULL; - g_idle_add (changed_in_idle, g_object_ref (volume)); - } - G_UNLOCK (hal_volume); -} - -void -g_hal_volume_set_drive (GHalVolume *volume, - GHalDrive *drive) -{ - G_LOCK (hal_volume); - if (volume->drive != drive) - { - if (volume->drive != NULL) - g_hal_drive_unset_volume (volume->drive, volume); - - volume->drive = drive; - - g_idle_add (changed_in_idle, g_object_ref (volume)); - } - G_UNLOCK (hal_volume); -} - -void -g_hal_volume_unset_drive (GHalVolume *volume, - GHalDrive *drive) -{ - G_LOCK (hal_volume); - if (volume->drive == drive) - { - volume->drive = NULL; - g_idle_add (changed_in_idle, g_object_ref (volume)); - } - G_UNLOCK (hal_volume); -} - -static GIcon * -g_hal_volume_get_icon (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - GIcon *icon; - const char *name; - const char *fallback; - - G_LOCK (hal_volume); - name = hal_volume->icon; - - if (hal_volume->icon_fallback) - fallback = hal_volume->icon_fallback; - else /* if no custom fallbacks are set, use the icon to create them */ - fallback = name; - - icon = get_themed_icon_with_fallbacks (name, fallback); - G_UNLOCK (hal_volume); - return icon; -} - -static char * -g_hal_volume_get_name (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - char *name; - - G_LOCK (hal_volume); - name = g_strdup (hal_volume->name); - G_UNLOCK (hal_volume); - - return name; -} - -static char * -g_hal_volume_get_uuid (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - char *uuid; - - G_LOCK (hal_volume); - uuid = g_strdup (hal_volume->uuid); - G_UNLOCK (hal_volume); - - return uuid; -} - -static gboolean -g_hal_volume_can_mount (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = hal_volume->is_mountable; - G_UNLOCK (hal_volume); - - return res; -} - -static gboolean -g_hal_volume_can_eject (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = FALSE; - if (hal_volume->drive != NULL) - res = g_drive_can_eject (G_DRIVE (hal_volume->drive)); - G_UNLOCK (hal_volume); - - return res; -} - -static gboolean -g_hal_volume_should_automount (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = ! (hal_volume->ignore_automount); - G_UNLOCK (hal_volume); - - return res; -} - -static GDrive * -g_hal_volume_get_drive (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - GDrive *drive; - - G_LOCK (hal_volume); - drive = NULL; - if (hal_volume->drive != NULL) - drive = g_object_ref (hal_volume->drive); - G_UNLOCK (hal_volume); - - return drive; -} - -static GMount * -g_hal_volume_get_mount (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - GMount *mount; - - G_LOCK (hal_volume); - mount = NULL; - if (hal_volume->foreign_mount != NULL) - mount = g_object_ref (hal_volume->foreign_mount); - else if (hal_volume->mount != NULL) - mount = g_object_ref (hal_volume->mount); - G_UNLOCK (hal_volume); - - return mount; -} - -gboolean -g_hal_volume_has_mount_path (GHalVolume *volume, - const char *mount_path) -{ - gboolean res; - - G_LOCK (hal_volume); - res = FALSE; - if (volume->mount_path != NULL) - res = strcmp (volume->mount_path, mount_path) == 0; - G_UNLOCK (hal_volume); - - return res; -} - -gboolean -g_hal_volume_has_device_path (GHalVolume *volume, - const char *device_path) -{ - gboolean res; - - res = FALSE; - G_LOCK (hal_volume); - if (volume->device_path != NULL) - res = strcmp (volume->device_path, device_path) == 0; - G_UNLOCK (hal_volume); - return res; -} - -gboolean -g_hal_volume_has_udi (GHalVolume *volume, - const char *udi) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = FALSE; - if (hal_volume->device != NULL) - res = strcmp (hal_device_get_udi (hal_volume->device), udi) == 0; - G_UNLOCK (hal_volume); - return res; -} - -gboolean -g_hal_volume_has_uuid (GHalVolume *volume, - const char *uuid) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = FALSE; - if (hal_volume->uuid != NULL) - res = strcmp (hal_volume->uuid, uuid) == 0; - G_UNLOCK (hal_volume); - - return res; -} - -static void -foreign_mount_unmounted (GMount *mount, gpointer user_data) -{ - GHalVolume *volume = G_HAL_VOLUME (user_data); - gboolean check; - - G_LOCK (hal_volume); - check = volume->foreign_mount == mount; - G_UNLOCK (hal_volume); - if (check) - g_hal_volume_adopt_foreign_mount (volume, NULL); -} - -void -g_hal_volume_adopt_foreign_mount (GHalVolume *volume, GMount *foreign_mount) -{ - G_LOCK (hal_volume); - if (volume->foreign_mount != NULL) - g_object_unref (volume->foreign_mount); - - if (foreign_mount != NULL) - { - volume->foreign_mount = g_object_ref (foreign_mount); - g_signal_connect_object (foreign_mount, "unmounted", (GCallback) foreign_mount_unmounted, volume, 0); - } - else - volume->foreign_mount = NULL; - - g_idle_add (changed_in_idle, g_object_ref (volume)); - G_UNLOCK (hal_volume); -} - -gboolean -g_hal_volume_has_foreign_mount_root (GHalVolume *volume, - GFile *mount_root) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = FALSE; - if (hal_volume->foreign_mount_root != NULL) - res = g_file_equal (hal_volume->foreign_mount_root, mount_root); - G_UNLOCK (hal_volume); - - return res; -} - - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; -} SpawnOp; - -static void -spawn_cb (GPid pid, gint status, gpointer user_data) -{ - SpawnOp *data = user_data; - GSimpleAsyncResult *simple; - - /* ensure that the #GHalMount corrosponding to the #GHalVolume we've - * mounted is made available before returning to the user - */ - g_hal_volume_monitor_force_update (G_HAL_VOLUME_MONITOR (G_HAL_VOLUME (data->object)->volume_monitor)); - - if (WEXITSTATUS (status) != 0) - { - GError *error; - error = g_error_new_literal (G_IO_ERROR, - G_IO_ERROR_FAILED_HANDLED, - "You are not supposed to show G_IO_ERROR_FAILED_HANDLED in the UI"); - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - g_error_free (error); - } - else - { - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_object_unref (data->object); - g_free (data); -} - -static void -spawn_do (GVolume *volume, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data, - char **argv) -{ - SpawnOp *data; - GPid child_pid; - GError *error; - - data = g_new0 (SpawnOp, 1); - data->object = g_object_ref (volume); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - - error = NULL; - if (!g_spawn_async (NULL, /* working dir */ - argv, - NULL, /* envp */ - G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH, - NULL, /* child_setup */ - NULL, /* user_data for child_setup */ - &child_pid, - &error)) - { - g_simple_async_report_gerror_in_idle (data->object, - data->callback, - data->user_data, - error); - g_object_unref (data->object); - g_error_free (error); - g_free (data); - return; - } - - g_child_watch_add (child_pid, spawn_cb, data); -} - -typedef struct -{ - GHalVolume *enclosing_volume; - GAsyncReadyCallback callback; - gpointer user_data; -} ForeignMountOp; - -static void -mount_foreign_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - ForeignMountOp *data = user_data; - data->callback (G_OBJECT (data->enclosing_volume), res, data->user_data); - g_object_unref (data->enclosing_volume); - g_free (data); -} - -static void -g_hal_volume_mount (GVolume *volume, - GMountMountFlags flags, - GMountOperation *mount_operation, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - - /*g_warning ("hal_volume_mount (can_mount=%d foreign=%p device_path=%s)", - g_hal_volume_can_mount (volume), - hal_volume->foreign_mount_root, - hal_volume->device_path);*/ - - G_LOCK (hal_volume); - if (hal_volume->foreign_mount_root != NULL) - { - ForeignMountOp *data; - - data = g_new0 (ForeignMountOp, 1); - data->enclosing_volume = g_object_ref (hal_volume); - data->callback = callback; - data->user_data = user_data; - - g_file_mount_enclosing_volume (hal_volume->foreign_mount_root, - 0, - mount_operation, - cancellable, - mount_foreign_callback, - data); - } - else - { - char *argv[] = {"gnome-mount", "-b", "-d", NULL, NULL, NULL}; - argv[3] = hal_volume->device_path; - /* ask for no dialogs if mount_operation is NULL */ - if (mount_operation == NULL) - argv[4] = "-n"; - spawn_do (volume, cancellable, callback, user_data, argv); - } - G_UNLOCK (hal_volume); -} - -static gboolean -g_hal_volume_mount_finish (GVolume *volume, - GAsyncResult *result, - GError **error) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = TRUE; - - if (hal_volume->foreign_mount_root != NULL) - res = g_file_mount_enclosing_volume_finish (hal_volume->foreign_mount_root, result, error); - - G_UNLOCK (hal_volume); - - return res; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; -} EjectWrapperOp; - -static void -eject_wrapper_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - EjectWrapperOp *data = user_data; - data->callback (data->object, res, data->user_data); - g_object_unref (data->object); - g_free (data); -} - -static void -g_hal_volume_eject (GVolume *volume, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - GHalDrive *drive; - - /*g_warning ("hal_volume_eject");*/ - - drive = NULL; - G_LOCK (hal_volume); - if (hal_volume->drive != NULL) - drive = g_object_ref (hal_volume->drive); - G_UNLOCK (hal_volume); - - if (drive != NULL) - { - EjectWrapperOp *data; - data = g_new0 (EjectWrapperOp, 1); - data->object = g_object_ref (volume); - data->callback = callback; - data->user_data = user_data; - g_drive_eject (G_DRIVE (drive), flags, cancellable, eject_wrapper_callback, data); - g_object_unref (drive); - } -} - -static gboolean -g_hal_volume_eject_finish (GVolume *volume, - GAsyncResult *result, - GError **error) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - gboolean res; - - G_LOCK (hal_volume); - res = TRUE; - if (hal_volume->drive != NULL) - res = g_drive_eject_finish (G_DRIVE (hal_volume->drive), result, error); - G_UNLOCK (hal_volume); - return res; -} - -static char * -g_hal_volume_get_identifier (GVolume *volume, - const char *kind) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - char *id; - - G_LOCK (hal_volume); - id = NULL; - if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_HAL_UDI) == 0) - id = g_strdup (hal_device_get_udi (hal_volume->device)); - else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) == 0) - id = g_strdup (hal_volume->device_path); - else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_LABEL) == 0) - id = g_strdup (hal_device_get_property_string (hal_volume->device, "volume.label")); - else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UUID) == 0) - id = g_strdup (hal_device_get_property_string (hal_volume->device, "volume.uuid")); - G_UNLOCK (hal_volume); - - return id; -} - -static char ** -g_hal_volume_enumerate_identifiers (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - GPtrArray *res; - const char *label, *uuid; - - G_LOCK (hal_volume); - - res = g_ptr_array_new (); - - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_HAL_UDI)); - - if (hal_volume->device_path && *hal_volume->device_path != 0) - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE)); - - label = hal_device_get_property_string (hal_volume->device, "volume.label"); - uuid = hal_device_get_property_string (hal_volume->device, "volume.uuid"); - - if (label && *label != 0) - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_LABEL)); - - if (uuid && *uuid != 0) - g_ptr_array_add (res, - g_strdup (G_VOLUME_IDENTIFIER_KIND_UUID)); - - /* Null-terminate */ - g_ptr_array_add (res, NULL); - - G_UNLOCK (hal_volume); - - return (char **)g_ptr_array_free (res, FALSE); -} - -static GFile * -g_hal_volume_get_activation_root (GVolume *volume) -{ - GHalVolume *hal_volume = G_HAL_VOLUME (volume); - GFile *root = NULL; - - G_LOCK (hal_volume); - if (hal_volume->foreign_mount_root != NULL) - root = g_object_ref (hal_volume->foreign_mount_root); - G_UNLOCK (hal_volume); - - return root; -} - -static void -g_hal_volume_volume_iface_init (GVolumeIface *iface) -{ - iface->get_name = g_hal_volume_get_name; - iface->get_icon = g_hal_volume_get_icon; - iface->get_uuid = g_hal_volume_get_uuid; - iface->get_drive = g_hal_volume_get_drive; - iface->get_mount = g_hal_volume_get_mount; - iface->can_mount = g_hal_volume_can_mount; - iface->can_eject = g_hal_volume_can_eject; - iface->should_automount = g_hal_volume_should_automount; - iface->mount_fn = g_hal_volume_mount; - iface->mount_finish = g_hal_volume_mount_finish; - iface->eject = g_hal_volume_eject; - iface->eject_finish = g_hal_volume_eject_finish; - iface->get_identifier = g_hal_volume_get_identifier; - iface->enumerate_identifiers = g_hal_volume_enumerate_identifiers; - iface->get_activation_root = g_hal_volume_get_activation_root; -} diff --git a/gnome-2-24/monitor/hal/ghalvolume.h b/gnome-2-24/monitor/hal/ghalvolume.h deleted file mode 100644 index edbdfb31..00000000 --- a/gnome-2-24/monitor/hal/ghalvolume.h +++ /dev/null @@ -1,84 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_HAL_VOLUME_H__ -#define __G_HAL_VOLUME_H__ - -#include -#include - -#include "hal-pool.h" -#include "ghalvolumemonitor.h" - -G_BEGIN_DECLS - -#define G_TYPE_HAL_VOLUME (g_hal_volume_get_type ()) -#define G_HAL_VOLUME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_HAL_VOLUME, GHalVolume)) -#define G_HAL_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_HAL_VOLUME, GHalVolumeClass)) -#define G_IS_HAL_VOLUME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_HAL_VOLUME)) -#define G_IS_HAL_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_HAL_VOLUME)) - -typedef struct _GHalVolumeClass GHalVolumeClass; - -struct _GHalVolumeClass { - GObjectClass parent_class; -}; - -GType g_hal_volume_get_type (void) G_GNUC_CONST; - -GHalVolume *g_hal_volume_new (GVolumeMonitor *volume_monitor, - HalDevice *device, - HalPool *pool, - GFile *foreign_mount_root, - gboolean is_mountable, - GHalDrive *drive); - -gboolean g_hal_volume_has_mount_path (GHalVolume *volume, - const char *mount_path); -gboolean g_hal_volume_has_device_path (GHalVolume *volume, - const char *device_path); -gboolean g_hal_volume_has_udi (GHalVolume *volume, - const char *udi); -gboolean g_hal_volume_has_uuid (GHalVolume *volume, - const char *uuid); - -gboolean g_hal_volume_has_foreign_mount_root (GHalVolume *volume, - GFile *mount_root); - -void g_hal_volume_adopt_foreign_mount (GHalVolume *volume, - GMount *foreign_mount); - -void g_hal_volume_set_mount (GHalVolume *volume, - GHalMount *mount); -void g_hal_volume_unset_mount (GHalVolume *volume, - GHalMount *mount); - -void g_hal_volume_set_drive (GHalVolume *volume, - GHalDrive *drive); -void g_hal_volume_unset_drive (GHalVolume *volume, - GHalDrive *drive); - -void g_hal_volume_removed (GHalVolume *volume); - -G_END_DECLS - -#endif /* __G_HAL_VOLUME_H__ */ diff --git a/gnome-2-24/monitor/hal/ghalvolumemonitor.c b/gnome-2-24/monitor/hal/ghalvolumemonitor.c deleted file mode 100644 index 0a2a0877..00000000 --- a/gnome-2-24/monitor/hal/ghalvolumemonitor.c +++ /dev/null @@ -1,1399 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "ghalvolumemonitor.h" -#include "ghalmount.h" -#include "ghalvolume.h" -#include "ghaldrive.h" -#include "hal-pool.h" - -/* We use this static variable for enforcing a singleton pattern since - * the get_mount_for_mount_path() method on GNativeVolumeMonitor calls - * us without an instance.. and ideally we want to piggyback on an - * already existing instance. - * - * We avoid locking since GUnionVolumeMonitor, the only user of us, - * does locking. - */ - -G_LOCK_DEFINE_STATIC(hal_vm); - -static GHalVolumeMonitor *the_volume_monitor = NULL; -static HalPool *pool = NULL; - -struct _GHalVolumeMonitor { - GNativeVolumeMonitor parent; - - GUnixMountMonitor *mount_monitor; - - HalPool *pool; - - GList *last_optical_disc_devices; - GList *last_drive_devices; - GList *last_volume_devices; - GList *last_mountpoints; - GList *last_mounts; - - GList *drives; - GList *volumes; - GList *mounts; - - /* we keep volumes/mounts for blank and audio discs separate to handle e.g. mixed discs properly */ - GList *disc_volumes; - GList *disc_mounts; - -}; - -static void mountpoints_changed (GUnixMountMonitor *mount_monitor, - gpointer user_data); -static void mounts_changed (GUnixMountMonitor *mount_monitor, - gpointer user_data); -static void hal_changed (HalPool *pool, - HalDevice *device, - gpointer user_data); -static void update_all (GHalVolumeMonitor *monitor, - gboolean emit_changes); -static void update_drives (GHalVolumeMonitor *monitor, - GList **added_drives, - GList **removed_drives); -static void update_volumes (GHalVolumeMonitor *monitor, - GList **added_volumes, - GList **removed_volumes); -static void update_mounts (GHalVolumeMonitor *monitor, - GList **added_mounts, - GList **removed_mounts); -static void update_discs (GHalVolumeMonitor *monitor, - GList **added_volumes, - GList **removed_volumes, - GList **added_mounts, - GList **removed_mounts); - - -G_DEFINE_TYPE (GHalVolumeMonitor, g_hal_volume_monitor, G_TYPE_NATIVE_VOLUME_MONITOR) - -static void -list_free (GList *objects) -{ - g_list_foreach (objects, (GFunc)g_object_unref, NULL); - g_list_free (objects); -} - -static HalPool * -get_hal_pool (void) -{ - char *cap_only[] = {"block", NULL}; - - if (pool == NULL) - pool = hal_pool_new (cap_only); - - return pool; -} - -static void -g_hal_volume_monitor_dispose (GObject *object) -{ - GHalVolumeMonitor *monitor; - - monitor = G_HAL_VOLUME_MONITOR (object); - - G_LOCK (hal_vm); - the_volume_monitor = NULL; - G_UNLOCK (hal_vm); - - if (G_OBJECT_CLASS (g_hal_volume_monitor_parent_class)->dispose) - (*G_OBJECT_CLASS (g_hal_volume_monitor_parent_class)->dispose) (object); -} - -static void -g_hal_volume_monitor_finalize (GObject *object) -{ - GHalVolumeMonitor *monitor; - - monitor = G_HAL_VOLUME_MONITOR (object); - - g_signal_handlers_disconnect_by_func (monitor->mount_monitor, mountpoints_changed, monitor); - g_signal_handlers_disconnect_by_func (monitor->mount_monitor, mounts_changed, monitor); - g_signal_handlers_disconnect_by_func (monitor->pool, hal_changed, monitor); - - g_object_unref (monitor->mount_monitor); - g_object_unref (monitor->pool); - - list_free (monitor->last_optical_disc_devices); - list_free (monitor->last_drive_devices); - list_free (monitor->last_volume_devices); - list_free (monitor->last_mountpoints); - g_list_foreach (monitor->last_mounts, - (GFunc)g_unix_mount_free, NULL); - g_list_free (monitor->last_mounts); - - list_free (monitor->drives); - list_free (monitor->volumes); - list_free (monitor->mounts); - - list_free (monitor->disc_volumes); - list_free (monitor->disc_mounts); - - if (G_OBJECT_CLASS (g_hal_volume_monitor_parent_class)->finalize) - (*G_OBJECT_CLASS (g_hal_volume_monitor_parent_class)->finalize) (object); -} - -static GList * -get_mounts (GVolumeMonitor *volume_monitor) -{ - GHalVolumeMonitor *monitor; - GList *l, *ll; - - monitor = G_HAL_VOLUME_MONITOR (volume_monitor); - - G_LOCK (hal_vm); - - l = g_list_copy (monitor->mounts); - ll = g_list_copy (monitor->disc_mounts); - l = g_list_concat (l, ll); - - g_list_foreach (l, (GFunc)g_object_ref, NULL); - - G_UNLOCK (hal_vm); - - return l; -} - -static GList * -get_volumes (GVolumeMonitor *volume_monitor) -{ - GHalVolumeMonitor *monitor; - GList *l, *ll; - - monitor = G_HAL_VOLUME_MONITOR (volume_monitor); - - G_LOCK (hal_vm); - - l = g_list_copy (monitor->volumes); - ll = g_list_copy (monitor->disc_volumes); - l = g_list_concat (l, ll); - - g_list_foreach (l, (GFunc)g_object_ref, NULL); - - G_UNLOCK (hal_vm); - - return l; -} - -static GList * -get_connected_drives (GVolumeMonitor *volume_monitor) -{ - GHalVolumeMonitor *monitor; - GList *l; - - monitor = G_HAL_VOLUME_MONITOR (volume_monitor); - - G_LOCK (hal_vm); - - l = g_list_copy (monitor->drives); - g_list_foreach (l, (GFunc)g_object_ref, NULL); - - G_UNLOCK (hal_vm); - - return l; -} - -static GVolume * -get_volume_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid) -{ - GHalVolumeMonitor *monitor; - GHalVolume *volume; - GList *l; - - monitor = G_HAL_VOLUME_MONITOR (volume_monitor); - - G_LOCK (hal_vm); - - volume = NULL; - - for (l = monitor->volumes; l != NULL; l = l->next) - { - volume = l->data; - if (g_hal_volume_has_uuid (volume, uuid)) - goto found; - } - - for (l = monitor->disc_volumes; l != NULL; l = l->next) - { - volume = l->data; - if (g_hal_volume_has_uuid (volume, uuid)) - goto found; - } - - G_UNLOCK (hal_vm); - - return NULL; - - found: - - g_object_ref (volume); - - G_UNLOCK (hal_vm); - - return (GVolume *)volume; -} - -static GMount * -get_mount_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid) -{ - GHalVolumeMonitor *monitor; - GHalMount *mount; - GList *l; - - monitor = G_HAL_VOLUME_MONITOR (volume_monitor); - - G_LOCK (hal_vm); - - mount = NULL; - - for (l = monitor->mounts; l != NULL; l = l->next) - { - mount = l->data; - if (g_hal_mount_has_uuid (mount, uuid)) - goto found; - } - - for (l = monitor->disc_mounts; l != NULL; l = l->next) - { - mount = l->data; - if (g_hal_mount_has_uuid (mount, uuid)) - goto found; - } - - G_UNLOCK (hal_vm); - - return NULL; - - found: - - g_object_ref (mount); - - G_UNLOCK (hal_vm); - - return (GMount *)mount; -} - -static GMount * -get_mount_for_mount_path (const char *mount_path, - GCancellable *cancellable) -{ - GMount *mount; - GHalMount *hal_mount; - GHalVolumeMonitor *volume_monitor; - - G_LOCK (hal_vm); - volume_monitor = NULL; - if (the_volume_monitor != NULL) - volume_monitor = g_object_ref (the_volume_monitor); - G_UNLOCK (hal_vm); - - if (volume_monitor == NULL) - { - /* Dammit, no monitor is set up.. so we have to create one, find - * what the user asks for and throw it away again. - * - * What a waste - especially considering that there's IO - * involved in doing this: connect to the system message bus; - * IPC to hald... - */ - volume_monitor = G_HAL_VOLUME_MONITOR (g_hal_volume_monitor_new ()); - } - - mount = NULL; - - /* creation of the volume monitor might actually fail */ - if (volume_monitor != NULL) - { - GList *l; - - G_LOCK (hal_vm); - - for (l = volume_monitor->mounts; l != NULL; l = l->next) - { - hal_mount = l->data; - - if (g_hal_mount_has_mount_path (hal_mount, mount_path)) - { - mount = g_object_ref (hal_mount); - break; - } - } - - G_UNLOCK (hal_vm); - - g_object_unref (volume_monitor); - } - - return (GMount *)mount; -} - -static void -mountpoints_changed (GUnixMountMonitor *mount_monitor, - gpointer user_data) -{ - GHalVolumeMonitor *monitor = G_HAL_VOLUME_MONITOR (user_data); - - update_all (monitor, TRUE); -} - -static void -mounts_changed (GUnixMountMonitor *mount_monitor, - gpointer user_data) -{ - GHalVolumeMonitor *monitor = G_HAL_VOLUME_MONITOR (user_data); - - update_all (monitor, TRUE); -} - -void -g_hal_volume_monitor_force_update (GHalVolumeMonitor *monitor) -{ - update_all (monitor, TRUE); -} - -static void -hal_changed (HalPool *pool, - HalDevice *device, - gpointer user_data) -{ - GHalVolumeMonitor *monitor = G_HAL_VOLUME_MONITOR (user_data); - - /*g_warning ("hal changed");*/ - - update_all (monitor, TRUE); -} - -static GObject * -g_hal_volume_monitor_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *object; - GHalVolumeMonitor *monitor; - GHalVolumeMonitorClass *klass; - GObjectClass *parent_class; - - G_LOCK (hal_vm); - if (the_volume_monitor != NULL) - { - object = g_object_ref (the_volume_monitor); - G_UNLOCK (hal_vm); - return object; - } - G_UNLOCK (hal_vm); - - /*g_warning ("creating hal vm");*/ - - object = NULL; - - /* Invoke parent constructor. */ - klass = G_HAL_VOLUME_MONITOR_CLASS (g_type_class_peek (G_TYPE_HAL_VOLUME_MONITOR)); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - object = parent_class->constructor (type, - n_construct_properties, - construct_properties); - - monitor = G_HAL_VOLUME_MONITOR (object); - monitor->pool = g_object_ref (get_hal_pool ()); - - monitor->mount_monitor = g_unix_mount_monitor_new (); - - g_signal_connect (monitor->mount_monitor, - "mounts_changed", G_CALLBACK (mounts_changed), - monitor); - - g_signal_connect (monitor->mount_monitor, - "mountpoints_changed", G_CALLBACK (mountpoints_changed), - monitor); - - g_signal_connect (monitor->pool, - "device_added", G_CALLBACK (hal_changed), - monitor); - - g_signal_connect (monitor->pool, - "device_removed", G_CALLBACK (hal_changed), - monitor); - - update_all (monitor, FALSE); - - G_LOCK (hal_vm); - the_volume_monitor = monitor; - G_UNLOCK (hal_vm); - - return object; -} - -static void -g_hal_volume_monitor_init (GHalVolumeMonitor *monitor) -{ -} - -static gboolean -is_supported (void) -{ - return get_hal_pool() != NULL; -} - -static GVolume * -adopt_orphan_mount (GMount *mount, GVolumeMonitor *monitor) -{ - GList *l; - GFile *mount_root; - GVolume *ret; - - /* This is called by the union volume monitor which does - have a ref to this. So its guaranteed to live, unfortunately - the pointer is not passed as an argument :/ - */ - ret = NULL; - - G_LOCK (hal_vm); - if (the_volume_monitor == NULL) - { - G_UNLOCK (hal_vm); - return NULL; - } - - mount_root = g_mount_get_root (mount); - - /* cdda:// as foreign mounts */ - for (l = the_volume_monitor->disc_volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - - if (g_hal_volume_has_foreign_mount_root (volume, mount_root)) - { - g_hal_volume_adopt_foreign_mount (volume, mount); - ret = g_object_ref (volume); - goto found; - } - } - - found: - g_object_unref (mount_root); - - G_UNLOCK (hal_vm); - return ret; -} - -static void -g_hal_volume_monitor_class_init (GHalVolumeMonitorClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GVolumeMonitorClass *monitor_class = G_VOLUME_MONITOR_CLASS (klass); - GNativeVolumeMonitorClass *native_class = G_NATIVE_VOLUME_MONITOR_CLASS (klass); - - gobject_class->constructor = g_hal_volume_monitor_constructor; - gobject_class->finalize = g_hal_volume_monitor_finalize; - gobject_class->dispose = g_hal_volume_monitor_dispose; - - monitor_class->get_mounts = get_mounts; - monitor_class->get_volumes = get_volumes; - monitor_class->get_connected_drives = get_connected_drives; - monitor_class->get_volume_for_uuid = get_volume_for_uuid; - monitor_class->get_mount_for_uuid = get_mount_for_uuid; - monitor_class->adopt_orphan_mount = adopt_orphan_mount; - monitor_class->is_supported = is_supported; - - native_class->get_mount_for_mount_path = get_mount_for_mount_path; -} - -/** - * g_hal_volume_monitor_new: - * - * Returns: a new #GVolumeMonitor. - **/ -GVolumeMonitor * -g_hal_volume_monitor_new (void) -{ - GHalVolumeMonitor *monitor; - - monitor = g_object_new (G_TYPE_HAL_VOLUME_MONITOR, NULL); - - return G_VOLUME_MONITOR (monitor); -} - -static void -diff_sorted_lists (GList *list1, - GList *list2, - GCompareFunc compare, - GList **added, - GList **removed) -{ - int order; - - *added = *removed = NULL; - - while (list1 != NULL && - list2 != NULL) - { - order = (*compare) (list1->data, list2->data); - if (order < 0) - { - *removed = g_list_prepend (*removed, list1->data); - list1 = list1->next; - } - else if (order > 0) - { - *added = g_list_prepend (*added, list2->data); - list2 = list2->next; - } - else - { /* same item */ - list1 = list1->next; - list2 = list2->next; - } - } - - while (list1 != NULL) - { - *removed = g_list_prepend (*removed, list1->data); - list1 = list1->next; - } - while (list2 != NULL) - { - *added = g_list_prepend (*added, list2->data); - list2 = list2->next; - } -} - -static GHalVolume * -lookup_volume_for_mount_path (GHalVolumeMonitor *monitor, - const char *mount_path) -{ - GList *l; - GHalVolume *found; - - found = NULL; - - for (l = monitor->volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - - if (g_hal_volume_has_mount_path (volume, mount_path)) - { - found = volume; - break; - } - } - - return found; -} - -static GHalVolume * -lookup_volume_for_device_path (GHalVolumeMonitor *monitor, - const char *device_path) -{ - GList *l; - - for (l = monitor->volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - - if (g_hal_volume_has_device_path (volume, device_path)) - return volume; - } - - return NULL; -} - - - -static GHalMount * -find_mount_by_mount_path (GHalVolumeMonitor *monitor, - const char *mount_path) -{ - GList *l; - - for (l = monitor->mounts; l != NULL; l = l->next) - { - GHalMount *mount = l->data; - - if (g_hal_mount_has_mount_path (mount, mount_path)) - return mount; - } - - return NULL; -} - -static GHalVolume * -find_volume_by_udi (GHalVolumeMonitor *monitor, const char *udi) -{ - GList *l; - - for (l = monitor->volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - - if (g_hal_volume_has_udi (volume, udi)) - return volume; - } - - return NULL; -} - -static GHalDrive * -find_drive_by_udi (GHalVolumeMonitor *monitor, const char *udi) -{ - GList *l; - - for (l = monitor->drives; l != NULL; l = l->next) - { - GHalDrive *drive = l->data; - - if (g_hal_drive_has_udi (drive, udi)) - return drive; - } - - return NULL; -} - -static GHalMount * -find_disc_mount_by_udi (GHalVolumeMonitor *monitor, const char *udi) -{ - GList *l; - - for (l = monitor->disc_mounts; l != NULL; l = l->next) - { - GHalMount *mount = l->data; - - if (g_hal_mount_has_udi (mount, udi)) - return mount; - } - - return NULL; -} - -static GHalVolume * -find_disc_volume_by_udi (GHalVolumeMonitor *monitor, const char *udi) -{ - GList *l; - - for (l = monitor->disc_volumes; l != NULL; l = l->next) - { - GHalVolume *volume = l->data; - - if (g_hal_volume_has_udi (volume, udi)) - return volume; - } - - return NULL; -} - -static gint -hal_device_compare (HalDevice *a, HalDevice *b) -{ - return strcmp (hal_device_get_udi (a), hal_device_get_udi (b)); -} - -/* TODO: move to gio */ -static gboolean -_g_unix_mount_point_guess_should_display (GUnixMountPoint *mount_point) -{ - const char *mount_path; - - mount_path = g_unix_mount_point_get_mount_path (mount_point); - - /* Never display internal mountpoints */ - if (g_unix_is_mount_path_system_internal (mount_path)) - return FALSE; - - /* Only display things in /media (which are generally user mountable) - and home dir (fuse stuff) */ - if (g_str_has_prefix (mount_path, "/media/")) - return TRUE; - - if (g_str_has_prefix (mount_path, g_get_home_dir ())) - return TRUE; - - return FALSE; -} - - -static GUnixMountPoint * -get_mount_point_for_device (HalDevice *d, GList *fstab_mount_points) -{ - GList *l; - const char *device_file; - const char *device_mount_point; - - device_mount_point = hal_device_get_property_string (d, "volume.mount_point"); - - device_file = hal_device_get_property_string (d, "block.device"); - - for (l = fstab_mount_points; l != NULL; l = l->next) - { - GUnixMountPoint *mount_point = l->data; - const char *device_path; - const char *mount_path; - - mount_path = g_unix_mount_point_get_mount_path (mount_point); - if (device_mount_point != NULL && - mount_path != NULL && - strcmp (device_mount_point, mount_path) == 0) - return mount_point; - - device_path = g_unix_mount_point_get_device_path (mount_point); - if (g_str_has_prefix (device_path, "LABEL=")) - { - if (strcmp (device_path + 6, hal_device_get_property_string (d, "volume.label")) == 0) - return mount_point; - } - else if (g_str_has_prefix (device_path, "UUID=")) - { - if (g_ascii_strcasecmp (device_path + 5, hal_device_get_property_string (d, "volume.uuid")) == 0) - return mount_point; - } - else - { - char resolved_device_path[PATH_MAX]; - /* handle symlinks such as /dev/disk/by-uuid/47C2-1994 */ - if (realpath (device_path, resolved_device_path) != NULL && - strcmp (resolved_device_path, device_file) == 0) - return mount_point; - } - } - - return NULL; -} - -static gboolean -should_mount_be_ignored (HalPool *pool, HalDevice *d) -{ - const char *device_mount_point; - - device_mount_point = hal_device_get_property_string (d, "volume.mount_point"); - if (device_mount_point != NULL && strlen (device_mount_point) > 0) - { - GUnixMountEntry *mount_entry; - - /*g_warning ("device_mount_point = '%s'", device_mount_point);*/ - - mount_entry = g_unix_mount_at (device_mount_point, NULL); - if (mount_entry != NULL) { - if (!g_unix_mount_guess_should_display (mount_entry)) - { - g_unix_mount_free (mount_entry); - return TRUE; - } - g_unix_mount_free (mount_entry); - } - } - - return FALSE; -} - -static gboolean -should_volume_be_ignored (HalPool *pool, HalDevice *d, GList *fstab_mount_points) -{ - gboolean volume_ignore; - const char *volume_fsusage; - GUnixMountPoint *mount_point; - - volume_fsusage = hal_device_get_property_string (d, "volume.fsusage"); - volume_ignore = hal_device_get_property_bool (d, "volume.ignore"); - - if (volume_fsusage == NULL) - { - /*g_warning ("no volume.fsusage property. Refusing to ignore");*/ - return FALSE; - } - - if (volume_ignore) - return TRUE; - - if (strcmp (volume_fsusage, "filesystem") != 0) - { - /* no file system on the volume... blank and audio discs are handled in update_discs() */ - - /* check if it's a LUKS crypto volume */ - if (strcmp (volume_fsusage, "crypto") == 0) - { - if (strcmp (hal_device_get_property_string (d, "volume.fstype"), "crypto_LUKS") == 0) - { - HalDevice *cleartext_device; - - /* avoid showing cryptotext volume if it's corresponding cleartext volume is available */ - cleartext_device = hal_pool_get_device_by_capability_and_string (pool, - "block", - "volume.crypto_luks.clear.backing_volume", - hal_device_get_udi (d)); - - if (cleartext_device == NULL) - { - return FALSE; - } - } - } - return TRUE; - } - - mount_point = get_mount_point_for_device (d, fstab_mount_points); - if (mount_point != NULL && !_g_unix_mount_point_guess_should_display (mount_point)) - return TRUE; - - if (hal_device_get_property_bool (d, "volume.is_mounted")) - return should_mount_be_ignored (pool, d); - - return FALSE; -} - -static gboolean -should_drive_be_ignored (HalPool *pool, HalDevice *d, GList *fstab_mount_points) -{ - GList *volumes, *l; - const char *drive_udi; - gboolean all_volumes_ignored, got_volumes; - - /* never ignore drives with removable media */ - if (hal_device_get_property_bool (d, "storage.removable")) - return FALSE; - - drive_udi = hal_device_get_udi (d); - - volumes = hal_pool_find_by_capability (pool, "volume"); - - all_volumes_ignored = TRUE; - got_volumes = FALSE; - for (l = volumes; l != NULL; l = l->next) - { - HalDevice *volume_dev = l->data; - if (strcmp (drive_udi, hal_device_get_property_string (volume_dev, "block.storage_device")) == 0) - { - got_volumes = TRUE; - if (!should_volume_be_ignored (pool, volume_dev, fstab_mount_points) || - hal_device_get_property_bool (volume_dev, "volume.disc.has_audio") || - hal_device_get_property_bool (volume_dev, "volume.disc.is_blank")) - { - all_volumes_ignored = FALSE; - break; - } - } - } - - return got_volumes && all_volumes_ignored; -} - -static void -list_emit (GHalVolumeMonitor *monitor, - const char *monitor_signal, - const char *object_signal, - GList *objects) -{ - GList *l; - - for (l = objects; l != NULL; l = l->next) - { - g_signal_emit_by_name (monitor, monitor_signal, l->data); - if (object_signal) - g_signal_emit_by_name (l->data, object_signal); - } -} - -typedef struct { - GHalVolumeMonitor *monitor; - GList *added_drives, *removed_drives; - GList *added_volumes, *removed_volumes; - GList *added_mounts, *removed_mounts; -} ChangedLists; - - -static gboolean -emit_lists_in_idle (gpointer data) -{ - ChangedLists *lists = data; - - list_emit (lists->monitor, - "drive_disconnected", NULL, - lists->removed_drives); - list_emit (lists->monitor, - "drive_connected", NULL, - lists->added_drives); - - list_emit (lists->monitor, - "volume_removed", "removed", - lists->removed_volumes); - list_emit (lists->monitor, - "volume_added", NULL, - lists->added_volumes); - - list_emit (lists->monitor, - "mount_removed", "unmounted", - lists->removed_mounts); - list_emit (lists->monitor, - "mount_added", NULL, - lists->added_mounts); - - list_free (lists->removed_drives); - list_free (lists->added_drives); - list_free (lists->removed_volumes); - list_free (lists->added_volumes); - list_free (lists->removed_mounts); - list_free (lists->added_mounts); - g_object_unref (lists->monitor); - g_free (lists); - - return FALSE; -} - -/* Must be called from idle if emit_changes, with no locks held */ -static void -update_all (GHalVolumeMonitor *monitor, - gboolean emit_changes) -{ - ChangedLists *lists; - GList *added_drives, *removed_drives; - GList *added_volumes, *removed_volumes; - GList *added_mounts, *removed_mounts; - - added_drives = NULL; - removed_drives = NULL; - added_volumes = NULL; - removed_volumes = NULL; - added_mounts = NULL; - removed_mounts = NULL; - - G_LOCK (hal_vm); - update_drives (monitor, &added_drives, &removed_drives); - update_volumes (monitor, &added_volumes, &removed_volumes); - update_mounts (monitor, &added_mounts, &removed_mounts); - update_discs (monitor, - &added_volumes, &removed_volumes, - &added_mounts, &removed_mounts); - G_UNLOCK (hal_vm); - - if (emit_changes) - { - lists = g_new0 (ChangedLists, 1); - lists->monitor = g_object_ref (monitor); - lists->added_drives = added_drives; - lists->removed_drives = removed_drives; - lists->added_volumes = added_volumes; - lists->removed_volumes = removed_volumes; - lists->added_mounts = added_mounts; - lists->removed_mounts = removed_mounts; - - g_idle_add (emit_lists_in_idle, lists); - } - else - { - list_free (removed_drives); - list_free (added_drives); - list_free (removed_volumes); - list_free (added_volumes); - list_free (removed_mounts); - list_free (added_mounts); - } -} - -static void -update_drives (GHalVolumeMonitor *monitor, - GList **added_drives, - GList **removed_drives) -{ - GList *new_drive_devices; - GList *removed, *added; - GList *l, *ll; - GHalDrive *drive; - GList *fstab_mount_points; - - fstab_mount_points = g_unix_mount_points_get (NULL); - - new_drive_devices = hal_pool_find_by_capability (monitor->pool, "storage"); - - /* remove devices we want to ignore - we do it here so we get to reevaluate - * on the next update whether they should still be ignored - */ - for (l = new_drive_devices; l != NULL; l = ll) - { - HalDevice *d = l->data; - ll = l->next; - if (should_drive_be_ignored (monitor->pool, d, fstab_mount_points)) - new_drive_devices = g_list_delete_link (new_drive_devices, l); - } - - g_list_foreach (new_drive_devices, (GFunc) g_object_ref, NULL); - - new_drive_devices = g_list_sort (new_drive_devices, (GCompareFunc) hal_device_compare); - diff_sorted_lists (monitor->last_drive_devices, - new_drive_devices, (GCompareFunc) hal_device_compare, - &added, &removed); - - for (l = removed; l != NULL; l = l->next) - { - HalDevice *d = l->data; - - drive = find_drive_by_udi (monitor, hal_device_get_udi (d)); - if (drive != NULL) - { - /*g_warning ("hal removing drive %s", hal_device_get_property_string (d, "block.device"));*/ - g_hal_drive_disconnected (drive); - monitor->drives = g_list_remove (monitor->drives, drive); - *removed_drives = g_list_prepend (*removed_drives, drive); - } - } - - for (l = added; l != NULL; l = l->next) - { - HalDevice *d = l->data; - - drive = find_drive_by_udi (monitor, hal_device_get_udi (d)); - if (drive == NULL) - { - /*g_warning ("hal adding drive %s", hal_device_get_property_string (d, "block.device"));*/ - drive = g_hal_drive_new (G_VOLUME_MONITOR (monitor), d, monitor->pool); - if (drive != NULL) - { - monitor->drives = g_list_prepend (monitor->drives, drive); - *added_drives = g_list_prepend (*added_drives, g_object_ref (drive)); - } - } - } - - g_list_free (added); - g_list_free (removed); - list_free (monitor->last_drive_devices); - monitor->last_drive_devices = new_drive_devices; - - g_list_foreach (fstab_mount_points, (GFunc) g_unix_mount_point_free, NULL); - g_list_free (fstab_mount_points); -} - -static void -update_volumes (GHalVolumeMonitor *monitor, - GList **added_volumes, - GList **removed_volumes) -{ - GList *new_volume_devices; - GList *removed, *added; - GList *l, *ll; - GHalVolume *volume; - GHalDrive *drive; - GList *fstab_mount_points; - - fstab_mount_points = g_unix_mount_points_get (NULL); - - new_volume_devices = hal_pool_find_by_capability (monitor->pool, "volume"); - - /* remove devices we want to ignore - we do it here so we get to reevaluate - * on the next update whether they should still be ignored - */ - for (l = new_volume_devices; l != NULL; l = ll) - { - HalDevice *d = l->data; - ll = l->next; - if (should_volume_be_ignored (monitor->pool, d, fstab_mount_points)) - new_volume_devices = g_list_delete_link (new_volume_devices, l); - } - - g_list_foreach (new_volume_devices, (GFunc) g_object_ref, NULL); - - new_volume_devices = g_list_sort (new_volume_devices, (GCompareFunc) hal_device_compare); - diff_sorted_lists (monitor->last_volume_devices, - new_volume_devices, (GCompareFunc) hal_device_compare, - &added, &removed); - - for (l = removed; l != NULL; l = l->next) - { - HalDevice *d = l->data; - - volume = find_volume_by_udi (monitor, hal_device_get_udi (d)); - if (volume != NULL) - { - /*g_warning ("hal removing vol %s", hal_device_get_property_string (d, "block.device"));*/ - g_hal_volume_removed (volume); - monitor->volumes = g_list_remove (monitor->volumes, volume); - - *removed_volumes = g_list_prepend (*removed_volumes, volume); - } - } - - for (l = added; l != NULL; l = l->next) - { - HalDevice *d = l->data; - - volume = find_volume_by_udi (monitor, hal_device_get_udi (d)); - if (volume == NULL) - { - drive = find_drive_by_udi (monitor, hal_device_get_property_string (d, "block.storage_device")); - - /*g_warning ("hal adding vol %s (drive %p)", hal_device_get_property_string (d, "block.device"), drive);*/ - volume = g_hal_volume_new (G_VOLUME_MONITOR (monitor), - d, - monitor->pool, - NULL, - TRUE, - drive); - if (volume != NULL) - { - monitor->volumes = g_list_prepend (monitor->volumes, volume); - *added_volumes = g_list_prepend (*added_volumes, g_object_ref (volume)); - } - } - } - - g_list_free (added); - g_list_free (removed); - list_free (monitor->last_volume_devices); - monitor->last_volume_devices = new_volume_devices; - - g_list_foreach (fstab_mount_points, (GFunc) g_unix_mount_point_free, NULL); - g_list_free (fstab_mount_points); -} - -static void -update_mounts (GHalVolumeMonitor *monitor, - GList **added_mounts, - GList **removed_mounts) -{ - GList *new_mounts; - GList *removed, *added; - GList *l, *ll; - GHalMount *mount; - GHalVolume *volume; - const char *device_path; - const char *mount_path; - - new_mounts = g_unix_mounts_get (NULL); - - /* remove mounts we want to ignore - we do it here so we get to reevaluate - * on the next update whether they should still be ignored - */ - for (l = new_mounts; l != NULL; l = ll) - { - GUnixMountEntry *mount_entry = l->data; - ll = l->next; - - /* keep in sync with should_mount_be_ignored() */ - if (!g_unix_mount_guess_should_display (mount_entry)) - { - g_unix_mount_free (mount_entry); - new_mounts = g_list_delete_link (new_mounts, l); - } - } - - new_mounts = g_list_sort (new_mounts, (GCompareFunc) g_unix_mount_compare); - - diff_sorted_lists (monitor->last_mounts, - new_mounts, (GCompareFunc) g_unix_mount_compare, - &added, &removed); - - for (l = removed; l != NULL; l = l->next) - { - GUnixMountEntry *mount_entry = l->data; - - mount = find_mount_by_mount_path (monitor, g_unix_mount_get_mount_path (mount_entry)); - /*g_warning ("hal removing mount %s (%p)", g_unix_mount_get_device_path (mount_entry), mount);*/ - if (mount) - { - g_hal_mount_unmounted (mount); - monitor->mounts = g_list_remove (monitor->mounts, mount); - - *removed_mounts = g_list_prepend (*removed_mounts, mount); - } - } - - for (l = added; l != NULL; l = l->next) - { - GUnixMountEntry *mount_entry = l->data; - - device_path = g_unix_mount_get_device_path (mount_entry); - mount_path = g_unix_mount_get_mount_path (mount_entry); - volume = lookup_volume_for_device_path (monitor, device_path); - if (volume == NULL) - volume = lookup_volume_for_mount_path (monitor, mount_path); - - /*g_warning ("hal adding mount %s (vol %p)", g_unix_mount_get_device_path (mount_entry), volume);*/ - mount = g_hal_mount_new (G_VOLUME_MONITOR (monitor), mount_entry, monitor->pool, volume); - if (mount) - { - monitor->mounts = g_list_prepend (monitor->mounts, mount); - *added_mounts = g_list_prepend (*added_mounts, g_object_ref (mount)); - } - } - - g_list_free (added); - g_list_free (removed); - g_list_foreach (monitor->last_mounts, - (GFunc)g_unix_mount_free, NULL); - g_list_free (monitor->last_mounts); - monitor->last_mounts = new_mounts; -} - -static void -update_discs (GHalVolumeMonitor *monitor, - GList **added_volumes, - GList **removed_volumes, - GList **added_mounts, - GList **removed_mounts) -{ - GList *new_optical_disc_devices; - GList *removed, *added; - GList *l, *ll; - GHalDrive *drive; - GHalVolume *volume; - GHalMount *mount; - const char *udi; - const char *drive_udi; - - /* we also need to generate GVolume + GMount objects for - * - * - optical discs that have audio - * - optical discs that are blank - * - */ - - new_optical_disc_devices = hal_pool_find_by_capability (monitor->pool, "volume.disc"); - for (l = new_optical_disc_devices; l != NULL; l = ll) - { - HalDevice *d = l->data; - ll = l->next; - if (! (hal_device_get_property_bool (d, "volume.disc.is_blank") || - hal_device_get_property_bool (d, "volume.disc.has_audio"))) - { - /* filter out everything but discs that are blank or has audio */ - new_optical_disc_devices = g_list_delete_link (new_optical_disc_devices, l); - } - } - - g_list_foreach (new_optical_disc_devices, (GFunc) g_object_ref, NULL); - - new_optical_disc_devices = g_list_sort (new_optical_disc_devices, (GCompareFunc) hal_device_compare); - diff_sorted_lists (monitor->last_optical_disc_devices, - new_optical_disc_devices, (GCompareFunc) hal_device_compare, - &added, &removed); - - for (l = removed; l != NULL; l = l->next) - { - HalDevice *d = l->data; - - udi = hal_device_get_udi (d); - /*g_warning ("audio/blank disc removing %s", udi);*/ - - mount = find_disc_mount_by_udi (monitor, udi); - if (mount != NULL) - { - g_hal_mount_unmounted (mount); - monitor->disc_mounts = g_list_remove (monitor->disc_mounts, mount); - *removed_mounts = g_list_prepend (*removed_mounts, mount); - } - - volume = find_disc_volume_by_udi (monitor, udi); - if (volume != NULL) - { - g_hal_volume_removed (volume); - monitor->disc_volumes = g_list_remove (monitor->disc_volumes, volume); - *removed_volumes = g_list_prepend (*removed_volumes, volume); - } - } - - for (l = added; l != NULL; l = l->next) - { - HalDevice *d = l->data; - - udi = hal_device_get_udi (d); - /*g_warning ("audio/blank disc adding %s", udi);*/ - - drive_udi = hal_device_get_property_string (d, "block.storage_device"); - drive = find_drive_by_udi (monitor, drive_udi); - if (drive != NULL) - { - mount = NULL; - if (hal_device_get_property_bool (d, "volume.disc.is_blank")) - { - volume = g_hal_volume_new (G_VOLUME_MONITOR (monitor), - d, monitor->pool, - NULL, - FALSE, - drive); - if (volume != NULL) - { - GFile *root; - root = g_file_new_for_uri ("burn:///"); - mount = g_hal_mount_new_for_hal_device (G_VOLUME_MONITOR (monitor), - d, - root, - NULL, - NULL, - TRUE, - monitor->pool, - volume); - g_object_unref (root); - } - } - else - { - char *uri; - char *device_basename; - GFile *foreign_mount_root; - - /* the gvfsd-cdda backend uses URI's like these */ - device_basename = g_path_get_basename (hal_device_get_property_string (d, "block.device")); - uri = g_strdup_printf ("cdda://%s", device_basename); - foreign_mount_root = g_file_new_for_uri (uri); - g_free (device_basename); - g_free (uri); - - volume = g_hal_volume_new (G_VOLUME_MONITOR (monitor), - d, - monitor->pool, - foreign_mount_root, - TRUE, - drive); - g_object_unref (foreign_mount_root); - mount = NULL; - } - - if (volume != NULL) - { - monitor->disc_volumes = g_list_prepend (monitor->disc_volumes, volume); - *added_volumes = g_list_prepend (*added_volumes, g_object_ref (volume)); - - if (mount != NULL) - { - monitor->disc_mounts = g_list_prepend (monitor->disc_mounts, mount); - *added_mounts = g_list_prepend (*added_mounts, g_object_ref (mount)); - } - } - } - } - - g_list_free (added); - g_list_free (removed); - list_free (monitor->last_optical_disc_devices); - monitor->last_optical_disc_devices = new_optical_disc_devices; -} diff --git a/gnome-2-24/monitor/hal/ghalvolumemonitor.h b/gnome-2-24/monitor/hal/ghalvolumemonitor.h deleted file mode 100644 index a8397030..00000000 --- a/gnome-2-24/monitor/hal/ghalvolumemonitor.h +++ /dev/null @@ -1,58 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_HAL_VOLUME_MONITOR_H__ -#define __G_HAL_VOLUME_MONITOR_H__ - -#include -#include -#include - -G_BEGIN_DECLS - -#define G_TYPE_HAL_VOLUME_MONITOR (g_hal_volume_monitor_get_type ()) -#define G_HAL_VOLUME_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_HAL_VOLUME_MONITOR, GHalVolumeMonitor)) -#define G_HAL_VOLUME_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_HAL_VOLUME_MONITOR, GHalVolumeMonitorClass)) -#define G_IS_HAL_VOLUME_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_HAL_VOLUME_MONITOR)) -#define G_IS_HAL_VOLUME_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_HAL_VOLUME_MONITOR)) - -typedef struct _GHalVolumeMonitor GHalVolumeMonitor; -typedef struct _GHalVolumeMonitorClass GHalVolumeMonitorClass; - -/* Forward definitions */ -typedef struct _GHalDrive GHalDrive; -typedef struct _GHalVolume GHalVolume; -typedef struct _GHalMount GHalMount; - -struct _GHalVolumeMonitorClass { - GNativeVolumeMonitorClass parent_class; - -}; - -GType g_hal_volume_monitor_get_type (void) G_GNUC_CONST; - -GVolumeMonitor *g_hal_volume_monitor_new (void); -void g_hal_volume_monitor_force_update (GHalVolumeMonitor *monitor); - -G_END_DECLS - -#endif /* __G_HAL_VOLUME_MONITOR_H__ */ diff --git a/gnome-2-24/monitor/hal/hal-device.c b/gnome-2-24/monitor/hal/hal-device.c deleted file mode 100644 index 9f0b5bc3..00000000 --- a/gnome-2-24/monitor/hal/hal-device.c +++ /dev/null @@ -1,297 +0,0 @@ -/* hal-device.c - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include "hal-device.h" -#include "hal-marshal.h" - -struct _HalDevicePrivate -{ - LibHalContext *hal_ctx; - LibHalPropertySet *properties; - char *udi; - GTimeVal time_added; -}; - -enum { - HAL_PROPERTY_CHANGED, - HAL_CONDITION, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (HalDevice, hal_device, G_TYPE_OBJECT) - -static void -hal_device_finalize (HalDevice *device) -{ - if (device->priv->properties != NULL) - libhal_free_property_set (device->priv->properties); - g_free (device->priv->udi); - - if (G_OBJECT_CLASS (hal_device_parent_class)->finalize) - (* G_OBJECT_CLASS (hal_device_parent_class)->finalize) (G_OBJECT (device)); -} - -static void -hal_device_class_init (HalDeviceClass *klass) -{ - GObjectClass *obj_class = (GObjectClass *) klass; - - obj_class->finalize = (GObjectFinalizeFunc) hal_device_finalize; - - signals[HAL_PROPERTY_CHANGED] = - g_signal_new ("hal_property_changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalDeviceClass, hal_property_changed), - NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, - G_TYPE_STRING); - - signals[HAL_CONDITION] = - g_signal_new ("hal_condition", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalDeviceClass, hal_condition), - NULL, NULL, - hal_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_STRING); -} - -static void -hal_device_init (HalDevice *device) -{ - device->priv = g_new0 (HalDevicePrivate, 1); - g_get_current_time (&(device->priv->time_added)); -} - -const char * -hal_device_get_property_string (HalDevice *device, const char *key) -{ - const char *ret; - - ret = libhal_ps_get_string (device->priv->properties, key); - if (ret != NULL) - return ret; - - /* play it safe and don't make clients crash */ - return ""; -} - -int -hal_device_get_property_int (HalDevice *device, const char *key) -{ - return libhal_ps_get_int32 (device->priv->properties, key); -} - -double -hal_device_get_property_double (HalDevice *device, const char *key) -{ - return libhal_ps_get_double (device->priv->properties, key); -} - -guint64 -hal_device_get_property_uint64 (HalDevice *device, const char *key) -{ - return libhal_ps_get_uint64 (device->priv->properties, key); -} - -gboolean -hal_device_get_property_bool (HalDevice *device, const char *key) -{ - return libhal_ps_get_bool (device->priv->properties, key); -} - -char ** -hal_device_get_property_strlist (HalDevice *device, const char *key) -{ - static char * empty[1] = {NULL}; - char **ret; - - ret = (char **) libhal_ps_get_strlist (device->priv->properties, key); - if (ret != NULL) - return (char **) ret; - - /* play it safe and don't make clients crash */ - return empty; -} - -gboolean -hal_device_has_capability (HalDevice *device, const char *capability) -{ - int n; - char **caps; - gboolean ret; - - ret = FALSE; - caps = hal_device_get_property_strlist (device, "info.capabilities"); - if (caps == NULL) - goto out; - - for (n = 0; caps[n] != NULL; n++) - { - if (g_ascii_strcasecmp (caps[n], capability) == 0) - { - ret = TRUE; - break; - } - } - - out: - return ret; -} - -gboolean -hal_device_has_interface (HalDevice *device, const char *interface) -{ - int n; - char **ifs; - gboolean ret; - - ret = FALSE; - ifs = hal_device_get_property_strlist (device, "info.interfaces"); - if (ifs == NULL) - goto out; - - for (n = 0; ifs[n] != NULL; n++) - { - if (g_ascii_strcasecmp (ifs[n], interface) == 0) - { - ret = TRUE; - break; - } - } - -out: - return ret; -} - -gboolean -hal_device_has_property (HalDevice *device, const char *key) -{ - gboolean ret; - LibHalPropertySetIterator it; - - ret = FALSE; - if (device->priv->properties == NULL) - goto out; - - libhal_psi_init (&it, device->priv->properties); - - while (libhal_psi_has_more (&it)) - { - char *pkey = libhal_psi_get_key (&it); - - if (pkey != NULL && g_ascii_strcasecmp (pkey, key) == 0) - { - ret = TRUE; - break; - } - libhal_psi_next (&it); - } - - out: - return ret; -} - - -HalDevice * -hal_device_new_from_udi (LibHalContext *hal_ctx, const char *udi) -{ - HalDevice *device; - - device = HAL_DEVICE (g_object_new (HAL_TYPE_DEVICE, NULL)); - device->priv->udi = g_strdup (udi); - device->priv->hal_ctx = hal_ctx; - device->priv->properties = libhal_device_get_all_properties (hal_ctx, udi, NULL); - return device; -} - -HalDevice * -hal_device_new_from_udi_and_properties (LibHalContext *hal_ctx, - char *udi, - LibHalPropertySet *properties) -{ - HalDevice *device; - - device = HAL_DEVICE (g_object_new (HAL_TYPE_DEVICE, NULL)); - device->priv->udi = g_strdup (udi); - device->priv->hal_ctx = hal_ctx; - device->priv->properties = properties; - return device; -} - -void -_hal_device_hal_property_changed (HalDevice *device, const char *key); - -void -_hal_device_hal_condition (HalDevice *device, const char *name, const char *detail); - -void -_hal_device_hal_property_changed (HalDevice *device, const char *key) -{ - LibHalPropertySet *new_props; - - new_props = libhal_device_get_all_properties (device->priv->hal_ctx, device->priv->udi, NULL); - if (new_props != NULL) - { - libhal_free_property_set (device->priv->properties); - device->priv->properties = new_props; - g_signal_emit (device, signals[HAL_PROPERTY_CHANGED], 0, key); - } -} - -void -_hal_device_hal_condition (HalDevice *device, const char *name, const char *detail) -{ - g_signal_emit (device, signals[HAL_CONDITION], 0, name, detail); -} - -const char * -hal_device_get_udi (HalDevice *device) -{ - return device->priv->udi; -} - -LibHalPropertySet * -hal_device_get_properties (HalDevice *device) -{ - return device->priv->properties; -} - -gboolean -hal_device_is_recently_plugged_in (HalDevice *device) -{ - GTimeVal now; - glong delta_msec; - - g_get_current_time (&now); - - delta_msec = (now.tv_sec - device->priv->time_added.tv_sec) * 1000 + - (now.tv_usec - device->priv->time_added.tv_usec) / 1000; - - return delta_msec < 2000; -} diff --git a/gnome-2-24/monitor/hal/hal-device.h b/gnome-2-24/monitor/hal/hal-device.h deleted file mode 100644 index 8e91aa63..00000000 --- a/gnome-2-24/monitor/hal/hal-device.h +++ /dev/null @@ -1,93 +0,0 @@ -/* hal-device.h - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef HAL_DEVICE_H -#define HAL_DEVICE_H - -#include -#include -#include - -#define HAL_TYPE_DEVICE (hal_device_get_type ()) -#define HAL_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HAL_TYPE_DEVICE, HalDevice)) -#define HAL_DEVICE_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), HAL_DEVICE, HalDeviceClass)) -#define HAL_IS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HAL_TYPE_DEVICE)) -#define HAL_IS_DEVICE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), HAL_TYPE_DEVICE)) -#define HAL_DEVICE_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), HAL_TYPE_DEVICE, HalDeviceClass)) - - -typedef struct _HalDevice HalDevice; -typedef struct _HalDeviceClass HalDeviceClass; - -struct _HalDevicePrivate; -typedef struct _HalDevicePrivate HalDevicePrivate; - -struct _HalDevice -{ - GObject parent; - - /* private */ - HalDevicePrivate *priv; -}; - -struct _HalDeviceClass -{ - GObjectClass parent_class; - - /* signals */ - void (*hal_property_changed) (HalDevice *device, const char *key); - void (*hal_condition) (HalDevice *device, const char *name, const char *detail); -}; - - -GType hal_device_get_type (void); - -HalDevice * hal_device_new_from_udi (LibHalContext *hal_ctx, - const char *udi); - -HalDevice * hal_device_new_from_udi_and_properties (LibHalContext *hal_ctx, - char *udi, - LibHalPropertySet *properties); - -const char * hal_device_get_udi (HalDevice *device); -LibHalPropertySet * hal_device_get_properties (HalDevice *device); -const char * hal_device_get_property_string (HalDevice *device, - const char *key); -int hal_device_get_property_int (HalDevice *device, - const char *key); -guint64 hal_device_get_property_uint64 (HalDevice *device, - const char *key); -double hal_device_get_property_double (HalDevice *device, - const char *key); -gboolean hal_device_get_property_bool (HalDevice *device, - const char *key); -char ** hal_device_get_property_strlist (HalDevice *device, - const char *key); - -gboolean hal_device_has_property (HalDevice *device, - const char *key); -gboolean hal_device_has_capability (HalDevice *device, - const char *capability); -gboolean hal_device_has_interface (HalDevice *device, - const char *interface); - -gboolean hal_device_is_recently_plugged_in (HalDevice *device); - -#endif /* HAL_DEVICE_H */ diff --git a/gnome-2-24/monitor/hal/hal-marshal.list b/gnome-2-24/monitor/hal/hal-marshal.list deleted file mode 100644 index 52c82338..00000000 --- a/gnome-2-24/monitor/hal/hal-marshal.list +++ /dev/null @@ -1,3 +0,0 @@ -VOID:OBJECT,STRING -VOID:OBJECT,STRING,STRING -VOID:STRING,STRING diff --git a/gnome-2-24/monitor/hal/hal-pool.c b/gnome-2-24/monitor/hal/hal-pool.c deleted file mode 100644 index 770effd9..00000000 --- a/gnome-2-24/monitor/hal/hal-pool.c +++ /dev/null @@ -1,458 +0,0 @@ -/* hal-pool.c - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include -#include - -#include - -#include "hal-pool.h" -#include "hal-marshal.h" - -enum { - DEVICE_ADDED, - DEVICE_REMOVED, - DEVICE_PROPERTY_CHANGED, - DEVICE_CONDITION, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -struct _HalPoolPrivate -{ - char **cap_only; - - DBusConnection *dbus_connection; - LibHalContext *hal_ctx; - GHashTable *devices; -}; - -G_DEFINE_TYPE (HalPool, hal_pool, G_TYPE_OBJECT) - -static void -hal_pool_finalize (HalPool *pool) -{ - g_strfreev (pool->priv->cap_only); - - dbus_bus_remove_match (pool->priv->dbus_connection, - "type='signal'," - "interface='org.freedesktop.Hal.Device'," - "sender='org.freedesktop.Hal'", NULL); - libhal_ctx_shutdown (pool->priv->hal_ctx, NULL); - dbus_connection_close (pool->priv->dbus_connection); - dbus_connection_unref (pool->priv->dbus_connection); - - if (G_OBJECT_CLASS (hal_pool_parent_class)->finalize) - (* G_OBJECT_CLASS (hal_pool_parent_class)->finalize) (G_OBJECT (pool)); -} - -static void -hal_pool_class_init (HalPoolClass *klass) -{ - GObjectClass *obj_class = (GObjectClass *) klass; - - obj_class->finalize = (GObjectFinalizeFunc) hal_pool_finalize; - - g_type_class_ref (HAL_TYPE_DEVICE); - - signals[DEVICE_ADDED] = - g_signal_new ("device_added", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - HAL_TYPE_DEVICE); - - signals[DEVICE_REMOVED] = - g_signal_new ("device_removed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - HAL_TYPE_DEVICE); - - signals[DEVICE_PROPERTY_CHANGED] = - g_signal_new ("device_property_changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_property_changed), - NULL, NULL, - hal_marshal_VOID__OBJECT_STRING, - G_TYPE_NONE, 2, - HAL_TYPE_DEVICE, - G_TYPE_STRING); - - signals[DEVICE_CONDITION] = - g_signal_new ("device_condition", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HalPoolClass, device_condition), - NULL, NULL, - hal_marshal_VOID__OBJECT_STRING_STRING, - G_TYPE_NONE, 3, - HAL_TYPE_DEVICE, - G_TYPE_STRING, - G_TYPE_STRING); -} - -static void -hal_pool_init (HalPool *pool) -{ - pool->priv = g_new0 (HalPoolPrivate, 1); - pool->priv->hal_ctx = NULL; -} - -static gboolean -has_cap_only (HalPool *pool, HalDevice *device) -{ - const char *subsys; - unsigned int n; - - for (n = 0; pool->priv->cap_only != NULL && pool->priv->cap_only[n] != NULL; n++) - { - if (hal_device_has_capability (device, pool->priv->cap_only[n])) - return TRUE; - - subsys = hal_device_get_property_string (device, "info.subsystem"); - - if (subsys != NULL && strcmp (subsys, pool->priv->cap_only[n]) == 0) - return TRUE; - } - - return FALSE; -} - -static void -hal_pool_add_device_by_udi (HalPool *pool, - const char *udi, - gboolean emit_signal) -{ - HalDevice *device; - - device = hal_device_new_from_udi (pool->priv->hal_ctx, udi); - if (device != NULL) - { - if (!has_cap_only (pool, device)) - g_object_unref (device); - else - { - g_hash_table_insert (pool->priv->devices, g_strdup (udi), device); - if (emit_signal) - g_signal_emit (pool, signals[DEVICE_ADDED], 0, device); - } - } -} - -#ifdef HAVE_HAL_FAST_INIT -static void -hal_pool_add_device_by_udi_and_properties (HalPool *pool, - char *udi, - LibHalPropertySet *properties, - gboolean emit_signal) -{ - HalDevice *device; - - device = hal_device_new_from_udi_and_properties (pool->priv->hal_ctx, udi, properties); - if (device != NULL) - { - if (!has_cap_only (pool, device)) - g_object_unref (device); - else - { - g_hash_table_insert (pool->priv->devices, g_strdup (udi), device); - if (emit_signal) - g_signal_emit (pool, signals[DEVICE_ADDED], 0, device); - } - } -} -#endif - -static void -_hal_device_added (LibHalContext *hal_ctx, const char *udi) -{ - HalPool *pool; - - pool = HAL_POOL (libhal_ctx_get_user_data (hal_ctx)); - hal_pool_add_device_by_udi (pool, udi, TRUE); -} - -static void -_hal_device_removed (LibHalContext *hal_ctx, const char *udi) -{ - HalPool *pool; - HalDevice *device; - - pool = HAL_POOL (libhal_ctx_get_user_data (hal_ctx)); - if ((device = hal_pool_get_device_by_udi (pool, udi)) != NULL) - { - g_object_ref (device); - g_hash_table_remove (pool->priv->devices, udi); - g_signal_emit (pool, signals[DEVICE_REMOVED], 0, device); - g_object_unref (device); - } -} - -void -_hal_device_hal_property_changed (HalDevice *device, const char *key); - -void -_hal_device_hal_condition (HalDevice *device, const char *name, const char *detail); - -static void -_hal_property_modified (LibHalContext *ctx, - const char *udi, - const char *key, - dbus_bool_t is_removed, - dbus_bool_t is_added) -{ - HalPool *pool; - HalDevice *device; - - pool = HAL_POOL (libhal_ctx_get_user_data (ctx)); - - device = hal_pool_get_device_by_udi (pool, udi); - if (device != NULL) - { - _hal_device_hal_property_changed (device, key); - g_signal_emit (pool, signals[DEVICE_PROPERTY_CHANGED], 0, device, key); - } -} - -static void -_hal_condition (LibHalContext *ctx, - const char *udi, - const char *condition_name, - const char *condition_detail) -{ - HalPool *pool; - HalDevice *device; - - pool = HAL_POOL (libhal_ctx_get_user_data (ctx)); - - device = hal_pool_get_device_by_udi (pool, udi); - if (device != NULL) - { - _hal_device_hal_condition (device, condition_name, condition_detail); - g_signal_emit (pool, signals[DEVICE_CONDITION], 0, device, condition_name, condition_detail); - } -} - -LibHalContext * -hal_pool_get_hal_ctx (HalPool *pool) -{ - return pool->priv->hal_ctx; -} - -DBusConnection * -hal_pool_get_dbus_connection (HalPool *pool) -{ - return pool->priv->dbus_connection; -} - -HalPool * -hal_pool_new (char **cap_only) -{ - int i; - char **devices; - int num_devices; - HalPool *pool; - LibHalContext *hal_ctx; - DBusError error; - DBusConnection *dbus_connection; -#ifdef HAVE_HAL_FAST_INIT - LibHalPropertySet **properties; -#endif - - pool = NULL; - - dbus_error_init (&error); - /* see discussion on gtk-devel-list (Subject: Re: gvfs hal volume monitoring backend) on - * why this is private - */ - dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &error); - if (dbus_error_is_set (&error)) - { - dbus_error_free (&error); - goto out; - } - - dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); - - hal_ctx = libhal_ctx_new (); - if (hal_ctx == NULL) - { - dbus_connection_close (dbus_connection); - dbus_connection_unref (dbus_connection); - goto out; - } - - _g_dbus_connection_integrate_with_main (dbus_connection); - libhal_ctx_set_dbus_connection (hal_ctx, dbus_connection); - - if (!libhal_ctx_init (hal_ctx, &error)) - { - dbus_connection_close (dbus_connection); - dbus_connection_unref (dbus_connection); - dbus_error_free (&error); - goto out; - } - - pool = HAL_POOL (g_object_new (HAL_TYPE_POOL, NULL)); - pool->priv->dbus_connection = dbus_connection; - pool->priv->hal_ctx = hal_ctx; - pool->priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - pool->priv->cap_only = g_strdupv (cap_only); - - /* Gah, unfortunately we have to watch all devices as HAL's PropertyModified signal - * doesn't include the capabilities... - */ - dbus_bus_add_match (dbus_connection, - "type='signal'," - "interface='org.freedesktop.Hal.Device'," - "sender='org.freedesktop.Hal'", NULL); - libhal_ctx_set_device_added (hal_ctx, _hal_device_added); - libhal_ctx_set_device_removed (hal_ctx, _hal_device_removed); - libhal_ctx_set_device_property_modified (hal_ctx, _hal_property_modified); - libhal_ctx_set_device_condition (hal_ctx, _hal_condition); - libhal_ctx_set_user_data (hal_ctx, pool); - -#ifdef HAVE_HAL_FAST_INIT - /* First try new O(1) algorithm to get all devices and properties in a single call.. - * - * This method is only available in post hal 0.5.10. - */ - if (libhal_get_all_devices_with_properties (pool->priv->hal_ctx, - &num_devices, - &devices, - &properties, - NULL)) - { - for (i = 0; i < num_devices; i++) - hal_pool_add_device_by_udi_and_properties (pool, devices[i], properties[i], FALSE); - libhal_free_string_array (devices); - free (properties); /* hal_pool_add_device_by_udi_and_properties steals the given properties */ - goto out; - } -#endif - - /* fallback to using O(n) algorithm; will work on any hal 0.5.x release */ - devices = libhal_get_all_devices (pool->priv->hal_ctx, &num_devices, NULL); - if (devices != NULL) - { - for (i = 0; i < num_devices; i++) - { - char *device_udi; - device_udi = devices[i]; - hal_pool_add_device_by_udi (pool, device_udi, FALSE); - } - libhal_free_string_array (devices); - goto out; - } - - /* FAIL! */ - - g_object_unref (pool); - return NULL; - - out: - return pool; -} - -HalDevice * -hal_pool_get_device_by_udi (HalPool *pool, const char *udi) -{ - return g_hash_table_lookup (pool->priv->devices, udi); -} - -HalDevice * -hal_pool_get_device_by_capability_and_string (HalPool *pool, - const char *capability, - const char *key, - const char *value) -{ - GList *i; - GList *devices; - HalDevice *result; - - result = NULL; - devices = NULL; - - if (pool->priv->devices == NULL) - goto out; - - devices = g_hash_table_get_values (pool->priv->devices); - for (i = devices; i != NULL; i = i->next) - { - HalDevice *d = i->data; - const char *s; - - if (!hal_device_has_capability (d, capability)) - continue; - - s = hal_device_get_property_string (d, key); - if (s == NULL) - continue; - - if (strcmp (s, value) == 0) - { - result = d; - goto out; - } - } - -out: - if (devices != NULL) - g_list_free (devices); - return result; -} - -GList * -hal_pool_find_by_capability (HalPool *pool, const char *capability) -{ - GList *i; - GList *j; - GList *devices; - - devices = NULL; - - if (pool->priv->devices == NULL) - goto out; - - devices = g_hash_table_get_values (pool->priv->devices); - for (i = devices; i != NULL; i = j) - { - HalDevice *d = i->data; - - j = i->next; - - if (!hal_device_has_capability (d, capability)) - devices = g_list_delete_link (devices, i); - } - - out: - return devices; -} diff --git a/gnome-2-24/monitor/hal/hal-pool.h b/gnome-2-24/monitor/hal/hal-pool.h deleted file mode 100644 index 04c8687d..00000000 --- a/gnome-2-24/monitor/hal/hal-pool.h +++ /dev/null @@ -1,74 +0,0 @@ -/* hal-pool.h - * - * Copyright (C) 2007 David Zeuthen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#if !defined(HAL_POOL_H) -#define HAL_POOL_H - -#include -#include -#include "hal-device.h" - -#define HAL_TYPE_POOL (hal_pool_get_type ()) -#define HAL_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HAL_TYPE_POOL, HalPool)) -#define HAL_POOL_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), HAL_POOL, HalPoolClass)) -#define HAL_IS_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HAL_TYPE_POOL)) -#define HAL_IS_POOL_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), HAL_TYPE_POOL)) -#define HAL_POOL_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), HAL_TYPE_POOL, HalPoolClass)) - - -typedef struct _HalPool HalPool; -typedef struct _HalPoolClass HalPoolClass; - -struct _HalPoolPrivate; -typedef struct _HalPoolPrivate HalPoolPrivate; - -struct _HalPool -{ - GObject parent; - - /* private */ - HalPoolPrivate *priv; -}; - -struct _HalPoolClass -{ - GObjectClass parent_class; - - /* signals */ - void (*device_added) (HalPool *pool, HalDevice *device); - void (*device_removed) (HalPool *pool, HalDevice *device); - void (*device_property_changed) (HalPool *pool, HalDevice *device, const char *key); - void (*device_condition) (HalPool *pool, HalDevice *device, const char *name, const char *detail); -}; - -GType hal_pool_get_type (void); -HalPool * hal_pool_new (char **cap_only); -LibHalContext * hal_pool_get_hal_ctx (HalPool *pool); -DBusConnection * hal_pool_get_dbus_connection (HalPool *pool); -HalDevice * hal_pool_get_device_by_udi (HalPool *pool, - const char *udi); -HalDevice * hal_pool_get_device_by_capability_and_string (HalPool *pool, - const char *capability, - const char *key, - const char *value); -GList * hal_pool_find_by_capability (HalPool *pool, - const char *capability); - -#endif /* HAL_POOL_H */ diff --git a/gnome-2-24/monitor/hal/hal-utils.c b/gnome-2-24/monitor/hal/hal-utils.c deleted file mode 100644 index 6bf0cd8c..00000000 --- a/gnome-2-24/monitor/hal/hal-utils.c +++ /dev/null @@ -1,171 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - * Christian Kellner - */ - -#include - -#include -#include -#include - -#include "string.h" - -#include "hal-utils.h" - -static const struct { - const char *disc_type; - const char *icon_name; - char *ui_name; - char *ui_name_blank; -} disc_data[] = { - {"cd_rom", "media-optical-cd-rom", N_("CD-ROM Disc"), N_("Blank CD-ROM Disc")}, - {"cd_r", "media-optical-cd-r", N_("CD-R Disc"), N_("Blank CD-R Disc")}, - {"cd_rw", "media-optical-cd-rw", N_("CD-RW Disc"), N_("Blank CD-RW Disc")}, - {"dvd_rom", "media-optical-dvd-rom", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")}, - {"dvd_ram", "media-optical-dvd-ram", N_("DVD-RAM Disc"), N_("Blank DVD-RAM Disc")}, - {"dvd_r", "media-optical-dvd-r", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")}, - {"dvd_rw", "media-optical-dvd-rw", N_("DVD-RW Disc"), N_("Blank DVD-RW Disc")}, - {"dvd_plus_r", "media-optical-dvd-r-plus", N_("DVD+R Disc"), N_("Blank DVD+R Disc")}, - {"dvd_plus_rw", "media-optical-dvd-rw-plus", N_("DVD+RW Disc"), N_("Blank DVD+RW Disc")}, - {"dvd_plus_r_dl", "media-optical-dvd-dl-r-plus", N_("DVD+R DL Disc"), N_("Blank DVD+R DL Disc")}, - {"bd_rom", "media-optical-bd-rom", N_("Blu-Ray Disc"), N_("Blank Blu-Ray Disc")}, - {"bd_r", "media-optical-bd-r", N_("Blu-Ray R Disc"), N_("Blank Blu-Ray R Disc")}, - {"bd_re", "media-optical-bd-re", N_("Blu-Ray RW Disc"), N_("Blank Blu-Ray RW Disc")}, - {"hddvd_rom", "media-optical-hddvd-rom", N_("HD DVD Disc"), N_("Blank HD DVD Disc")}, - {"hddvd_r", "media-optical-hddvd-r", N_("HD DVD-R Disc"), N_("Blank HD DVD-R Disc")}, - {"hddvd_rw", "media-optical-hddvd-rw", N_("HD DVD-RW Disc"), N_("Blank HD DVD-RW Disc")}, - {"mo", "media-optical-mo", N_("MO Disc"), N_("Blank MO Disc")}, - {NULL, "media-optical", N_("Disc"), N_("Blank Disc")} -}; - -const char * -get_disc_icon (const char *disc_type) -{ - int n; - - for (n = 0; disc_data[n].disc_type != NULL; n++) - { - if (strcmp (disc_data[n].disc_type, disc_type) == 0) - break; - } - - return disc_data[n].icon_name; -} - -const char * -get_disc_name (const char *disc_type, gboolean is_blank) -{ - int n; - - for (n = 0; disc_data[n].disc_type != NULL; n++) - { - if (strcmp (disc_data[n].disc_type, disc_type) == 0) - break; - } - - if (is_blank) - return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name_blank); - else - return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name); -} - -/* - * Creates a GThemedIcon from icon_name and creates default - * fallbacks from fallbacks. Is smart in the case that icon_name - * and fallbacks are identically. - * Note: See the GThemedIcon documentation for more information - * on default fallbacks - */ -GIcon * -get_themed_icon_with_fallbacks (const char *icon_name, - const char *fallbacks) -{ - int i = 0, dashes = 0; - const char *p; - char *dashp; - char *last; - char **names; - GIcon *icon; - - if (G_UNLIKELY (icon_name == NULL)) - return NULL; - - if (fallbacks == NULL) - return g_themed_icon_new (icon_name); - - p = fallbacks; - while (*p) - { - if (*p == '-') - dashes++; - p++; - } - - if (strcmp (icon_name, fallbacks)) - { - names = g_new (char *, dashes + 3); - names[i++] = g_strdup (icon_name); - } - else - names = g_new (char *, dashes + 2); - - names[i++] = last = g_strdup (fallbacks); - - while ((dashp = strrchr (last, '-')) != NULL) - names[i++] = last = g_strndup (last, dashp - last); - - names[i++] = NULL; - icon = g_themed_icon_new_from_names (names, -1); - g_strfreev (names); - - return icon; -} - -char ** -dupv_and_uniqify (char **str_array) -{ - int n, m, o; - int len; - char **result; - - result = g_strdupv (str_array); - len = g_strv_length (result); - - for (n = 0; n < len; n++) - { - char *s = result[n]; - for (m = n + 1; m < len; m++) - { - char *p = result[m]; - if (strcmp (s, p) == 0) - { - for (o = m + 1; o < len; o++) - result[o - 1] = result[o]; - len--; - result[len] = NULL; - m--; - } - } - } - - return result; -} diff --git a/gnome-2-24/monitor/hal/hal-utils.h b/gnome-2-24/monitor/hal/hal-utils.h deleted file mode 100644 index fd737ca2..00000000 --- a/gnome-2-24/monitor/hal/hal-utils.h +++ /dev/null @@ -1,42 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - * Chrsitian Kellner - */ - -#ifndef __HAL_UTILS_H__ -#define __HAL_UTILS_H__ - -#include -#include - -G_BEGIN_DECLS - -const char * get_disc_icon (const char *disc_type); -const char * get_disc_name (const char *disc_type, gboolean is_blank); - -GIcon * get_themed_icon_with_fallbacks (const char *icon_name, - const char *fallbacks); - -char **dupv_and_uniqify (char **str_array); - -G_END_DECLS - -#endif /* __HAL_UTILS_H__ */ diff --git a/gnome-2-24/monitor/hal/hal-volume-monitor-daemon.c b/gnome-2-24/monitor/hal/hal-volume-monitor-daemon.c deleted file mode 100644 index 6f83175d..00000000 --- a/gnome-2-24/monitor/hal/hal-volume-monitor-daemon.c +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include -#include - -#include - -#include "ghalvolumemonitor.h" - -int -main (int argc, char *argv[]) -{ - g_vfs_proxy_volume_monitor_daemon_init (); - return g_vfs_proxy_volume_monitor_daemon_main (argc, - argv, - "org.gtk.Private.HalVolumeMonitor", - G_TYPE_HAL_VOLUME_MONITOR); -} diff --git a/gnome-2-24/monitor/hal/hal.monitor b/gnome-2-24/monitor/hal/hal.monitor deleted file mode 100644 index c287f853..00000000 --- a/gnome-2-24/monitor/hal/hal.monitor +++ /dev/null @@ -1,5 +0,0 @@ -[RemoteVolumeMonitor] -Name=GProxyVolumeMonitorHal -DBusName=org.gtk.Private.HalVolumeMonitor -IsNative=true -NativePriority=2 diff --git a/gnome-2-24/monitor/hal/org.gtk.Private.HalVolumeMonitor.service.in b/gnome-2-24/monitor/hal/org.gtk.Private.HalVolumeMonitor.service.in deleted file mode 100644 index c785241d..00000000 --- a/gnome-2-24/monitor/hal/org.gtk.Private.HalVolumeMonitor.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.gtk.Private.HalVolumeMonitor -Exec=@libexecdir@/gvfs-hal-volume-monitor diff --git a/gnome-2-24/monitor/proxy/Makefile.am b/gnome-2-24/monitor/proxy/Makefile.am deleted file mode 100644 index 9f1c9743..00000000 --- a/gnome-2-24/monitor/proxy/Makefile.am +++ /dev/null @@ -1,67 +0,0 @@ - -NULL = - -remote_volume_monitorsdir = $(datadir)/gvfs/remote-volume-monitors - -module_flags = -export_dynamic -avoid-version -module -no-undefined -export-symbols-regex '^g_io_module_(load|unload)' - -giomodules_LTLIBRARIES = libgioremote-volume-monitor.la - -libgioremote_volume_monitor_la_SOURCES = \ - remote-volume-monitor-module.c \ - gproxydrive.c gproxydrive.h \ - gproxyvolume.c gproxyvolume.h \ - gproxymount.c gproxymount.h \ - gproxyvolumemonitor.c gproxyvolumemonitor.h \ - $(NULL) - -libgioremote_volume_monitor_la_CFLAGS = \ - -DG_LOG_DOMAIN=\"GVFS-RemoteVolumeMonitor\" \ - -I$(top_srcdir)/common \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - -DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \ - -DREMOTE_VOLUME_MONITORS_DIR=\"$(remote_volume_monitorsdir)\" \ - -DGVFS_LOCALEDIR=\""$(localedir)"\" \ - -DG_DISABLE_DEPRECATED \ - $(NULL) - -libgioremote_volume_monitor_la_LDFLAGS = \ - $(module_flags) \ - $(NULL) - -libgioremote_volume_monitor_la_LIBADD = \ - $(GLIB_LIBS) \ - $(DBUS_LIBS) \ - $(top_builddir)/common/libgvfscommon.la \ - $(NULL) - -############################################################################ - -noinst_LTLIBRARIES = libgvfsproxyvolumemonitordaemon-noin.la - -libgvfsproxyvolumemonitordaemon_noin_la_SOURCES = \ - gvfsproxyvolumemonitordaemon.c \ - gvfsproxyvolumemonitordaemon.h - -libgvfsproxyvolumemonitordaemon_noin_la_CFLAGS = \ - -I$(top_srcdir)/common \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(GDU_CFLAGS) \ - -DG_LOG_DOMAIN=\"GVFS-RemoteVolumeMonitorDaemon\" \ - -DGVFS_LOCALEDIR=\""$(localedir)"\" \ - -DG_DISABLE_DEPRECATED \ - $(NULL) - -libgvfsproxyvolumemonitordaemon_noin_la_LIBADD = \ - $(GLIB_LIBS) \ - $(DBUS_LIBS) \ - $(top_builddir)/common/libgvfscommon.la \ - $(NULL) - -clean-local: - rm -f *~ *.loT - -install-data-local: - mkdir -p $(DESTDIR)$(remote_volume_monitorsdir) diff --git a/gnome-2-24/monitor/proxy/gproxydrive.c b/gnome-2-24/monitor/proxy/gproxydrive.c deleted file mode 100644 index b1e9533b..00000000 --- a/gnome-2-24/monitor/proxy/gproxydrive.c +++ /dev/null @@ -1,578 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include - -#include - -#include "gproxyvolumemonitor.h" -#include "gproxydrive.h" -#include "gproxyvolume.h" - -/* Protects all fields of GProxyDrive that can change */ -G_LOCK_DEFINE_STATIC(proxy_drive); - -struct _GProxyDrive { - GObject parent; - - GProxyVolumeMonitor *volume_monitor; - - char *id; - char *name; - GIcon *icon; - char **volume_ids; - gboolean can_eject; - gboolean can_poll_for_media; - gboolean is_media_check_automatic; - gboolean has_media; - gboolean is_media_removable; - - GHashTable *identifiers; -}; - -static void g_proxy_drive_drive_iface_init (GDriveIface *iface); - -#define _G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) { \ - const GInterfaceInfo g_implement_interface_info = { \ - (GInterfaceInitFunc) iface_init, NULL, NULL \ - }; \ - g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ -} - -G_DEFINE_DYNAMIC_TYPE_EXTENDED (GProxyDrive, g_proxy_drive, G_TYPE_OBJECT, 0, - _G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_DRIVE, - g_proxy_drive_drive_iface_init)) - -static void -g_proxy_drive_finalize (GObject *object) -{ - GProxyDrive *drive; - - drive = G_PROXY_DRIVE (object); - - if (drive->volume_monitor != NULL) - g_object_unref (drive->volume_monitor); - g_free (drive->id); - g_free (drive->name); - if (drive->icon != NULL) - g_object_unref (drive->icon); - g_strfreev (drive->volume_ids); - if (drive->identifiers != NULL) - g_hash_table_unref (drive->identifiers); - - if (G_OBJECT_CLASS (g_proxy_drive_parent_class)->finalize) - (*G_OBJECT_CLASS (g_proxy_drive_parent_class)->finalize) (object); -} - -static void -g_proxy_drive_class_init (GProxyDriveClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = g_proxy_drive_finalize; -} - -static void -g_proxy_drive_class_finalize (GProxyDriveClass *klass) -{ -} - -static void -g_proxy_drive_init (GProxyDrive *proxy_drive) -{ -} - -GProxyDrive * -g_proxy_drive_new (GProxyVolumeMonitor *volume_monitor) -{ - GProxyDrive *drive; - drive = g_object_new (G_TYPE_PROXY_DRIVE, NULL); - drive->volume_monitor = g_object_ref (volume_monitor); - return drive; -} - -/* string id - * string name - * string gicon_data - * boolean can-eject - * boolean can-poll-for-media - * boolean has-media - * boolean is-media-removable - * array:string volume-ids - * dict:string->string identifiers - */ -#define DRIVE_STRUCT_TYPE "(sssbbbasa{ss})" - -void -g_proxy_drive_update (GProxyDrive *drive, - DBusMessageIter *iter) -{ - DBusMessageIter iter_struct; - DBusMessageIter iter_volume_ids_iter; - const char *id; - const char *name; - const char *gicon_data; - dbus_bool_t can_eject; - dbus_bool_t can_poll_for_media; - dbus_bool_t has_media; - dbus_bool_t is_media_removable; - GPtrArray *volume_ids; - GHashTable *identifiers; - - dbus_message_iter_recurse (iter, &iter_struct); - dbus_message_iter_get_basic (&iter_struct, &id); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &name); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &gicon_data); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &can_eject); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &can_poll_for_media); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &has_media); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &is_media_removable); - dbus_message_iter_next (&iter_struct); - - volume_ids = g_ptr_array_new (); - dbus_message_iter_recurse (&iter_struct, &iter_volume_ids_iter); - while (dbus_message_iter_get_arg_type (&iter_volume_ids_iter) != DBUS_TYPE_INVALID) - { - const char *volume_id; - dbus_message_iter_get_basic (&iter_volume_ids_iter, &volume_id); - dbus_message_iter_next (&iter_volume_ids_iter); - g_ptr_array_add (volume_ids, (gpointer) volume_id); - } - g_ptr_array_add (volume_ids, NULL); - dbus_message_iter_next (&iter_struct); - - identifiers = _get_identifiers (&iter_struct); - dbus_message_iter_next (&iter_struct); - - if (drive->id != NULL && strcmp (drive->id, id) != 0) - { - g_warning ("id mismatch during update of drive"); - goto out; - } - - if (strlen (name) == 0) - name = NULL; - - /* out with the old */ - g_free (drive->id); - g_free (drive->name); - if (drive->icon != NULL) - g_object_unref (drive->icon); - g_strfreev (drive->volume_ids); - if (drive->identifiers != NULL) - g_hash_table_unref (drive->identifiers); - - /* in with the new */ - drive->id = g_strdup (id); - drive->name = g_strdup (name); - drive->icon = _g_icon_new_from_serialized_data (gicon_data); - drive->can_eject = can_eject; - drive->can_poll_for_media = can_poll_for_media; - drive->has_media = has_media; - drive->is_media_removable = is_media_removable; - drive->identifiers = identifiers != NULL ? g_hash_table_ref (identifiers) : NULL; - drive->volume_ids = g_strdupv ((char **) volume_ids->pdata); - - out: - g_ptr_array_free (volume_ids, TRUE); - g_hash_table_unref (identifiers); -} - -static GIcon * -g_proxy_drive_get_icon (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - GIcon *icon; - - G_LOCK (proxy_drive); - icon = proxy_drive->icon != NULL ? g_object_ref (proxy_drive->icon) : NULL; - G_UNLOCK (proxy_drive); - - return icon; -} - -static char * -g_proxy_drive_get_name (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - char *name; - - G_LOCK (proxy_drive); - name = g_strdup (proxy_drive->name); - G_UNLOCK (proxy_drive); - - return name; -} - -static GList * -g_proxy_drive_get_volumes (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - GList *l; - - l = NULL; - - G_LOCK (proxy_drive); - if (proxy_drive->volume_monitor != NULL && proxy_drive->volume_ids != NULL) - { - int n; - - for (n = 0; proxy_drive->volume_ids[n] != NULL; n++) - { - GProxyVolume *volume; - volume = g_proxy_volume_monitor_get_volume_for_id (proxy_drive->volume_monitor, proxy_drive->volume_ids[n]); - if (volume != NULL) - l = g_list_append (l, volume); - } - } - G_UNLOCK (proxy_drive); - - return l; -} - -static gboolean -g_proxy_drive_has_volumes (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - gboolean res; - - G_LOCK (proxy_drive); - res = (proxy_drive->volume_ids != NULL && g_strv_length (proxy_drive->volume_ids) > 0); - G_UNLOCK (proxy_drive); - - return res; -} - -static gboolean -g_proxy_drive_is_media_removable (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - gboolean res; - - G_LOCK (proxy_drive); - res = proxy_drive->is_media_removable; - G_UNLOCK (proxy_drive); - - return res; -} - -static gboolean -g_proxy_drive_has_media (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - gboolean res; - - G_LOCK (proxy_drive); - res = proxy_drive->has_media; - G_UNLOCK (proxy_drive); - - return res; -} - -static gboolean -g_proxy_drive_is_media_check_automatic (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - gboolean res; - - G_LOCK (proxy_drive); - res = proxy_drive->is_media_check_automatic; - G_UNLOCK (proxy_drive); - - return res; -} - -static gboolean -g_proxy_drive_can_eject (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - gboolean res; - - G_LOCK (proxy_drive); - res = proxy_drive->can_eject; - G_UNLOCK (proxy_drive); - - return res; -} - -static gboolean -g_proxy_drive_can_poll_for_media (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - gboolean res; - - G_LOCK (proxy_drive); - res = proxy_drive->can_poll_for_media; - G_UNLOCK (proxy_drive); - - return res; -} - -static char * -g_proxy_drive_get_identifier (GDrive *drive, - const char *kind) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - char *res; - - G_LOCK (proxy_drive); - if (proxy_drive->identifiers != NULL) - res = g_strdup (g_hash_table_lookup (proxy_drive->identifiers, kind)); - else - res = NULL; - G_UNLOCK (proxy_drive); - - return res; -} - -static void -add_identifier_key (const char *key, const char *value, GPtrArray *res) -{ - g_ptr_array_add (res, g_strdup (key)); -} - -static char ** -g_proxy_drive_enumerate_identifiers (GDrive *drive) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - GPtrArray *res; - - res = g_ptr_array_new (); - - G_LOCK (proxy_drive); - if (proxy_drive->identifiers != NULL) - g_hash_table_foreach (proxy_drive->identifiers, (GHFunc) add_identifier_key, res); - G_UNLOCK (proxy_drive); - - /* Null-terminate */ - g_ptr_array_add (res, NULL); - - return (char **) g_ptr_array_free (res, FALSE); -} - -const char * -g_proxy_drive_get_id (GProxyDrive *drive) -{ - return drive->id; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; -} DBusOp; - -static void -eject_cb (DBusMessage *reply, - GError *error, - DBusOp *data) -{ - GSimpleAsyncResult *simple; - if (error != NULL) - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - else - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - g_simple_async_result_complete (simple); - g_object_unref (simple); - - g_object_unref (data->object); - g_free (data); -} - -static void -g_proxy_drive_eject (GDrive *drive, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - DBusConnection *connection; - const char *name; - DBusMessage *message; - DBusOp *data; - dbus_uint32_t _flags = flags; - - G_LOCK (proxy_drive); - - data = g_new0 (DBusOp, 1); - data->object = g_object_ref (drive); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - - connection = g_proxy_volume_monitor_get_dbus_connection (proxy_drive->volume_monitor); - name = g_proxy_volume_monitor_get_dbus_name (proxy_drive->volume_monitor); - - message = dbus_message_new_method_call (name, - "/", - "org.gtk.Private.RemoteVolumeMonitor", - "DriveEject"); - dbus_message_append_args (message, - DBUS_TYPE_STRING, - &(proxy_drive->id), - DBUS_TYPE_UINT32, - &_flags, - DBUS_TYPE_INVALID); - G_UNLOCK (proxy_drive); - - _g_dbus_connection_call_async (connection, - message, - -1, - (GAsyncDBusCallback) eject_cb, - data); - dbus_connection_unref (connection); - dbus_message_unref (message); -} - -static gboolean -g_proxy_drive_eject_finish (GDrive *drive, - GAsyncResult *result, - GError **error) -{ - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) - return FALSE; - return TRUE; -} - -static void -poll_for_media_cb (DBusMessage *reply, - GError *error, - DBusOp *data) -{ - GSimpleAsyncResult *simple; - if (error != NULL) - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - else - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - g_simple_async_result_complete (simple); - g_object_unref (simple); - - g_object_unref (data->object); - g_free (data); -} - -static void -g_proxy_drive_poll_for_media (GDrive *drive, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive); - DBusConnection *connection; - const char *name; - DBusMessage *message; - DBusOp *data; - - G_LOCK (proxy_drive); - - data = g_new0 (DBusOp, 1); - data->object = g_object_ref (drive); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - - connection = g_proxy_volume_monitor_get_dbus_connection (proxy_drive->volume_monitor); - name = g_proxy_volume_monitor_get_dbus_name (proxy_drive->volume_monitor); - - message = dbus_message_new_method_call (name, - "/", - "org.gtk.Private.RemoteVolumeMonitor", - "DrivePollForMedia"); - dbus_message_append_args (message, - DBUS_TYPE_STRING, - &(proxy_drive->id), - DBUS_TYPE_INVALID); - G_UNLOCK (proxy_drive); - - _g_dbus_connection_call_async (connection, - message, - -1, - (GAsyncDBusCallback) poll_for_media_cb, - data); - dbus_connection_unref (connection); - dbus_message_unref (message); -} - -static gboolean -g_proxy_drive_poll_for_media_finish (GDrive *drive, - GAsyncResult *result, - GError **error) -{ - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) - return FALSE; - return TRUE; -} - - -static void -g_proxy_drive_drive_iface_init (GDriveIface *iface) -{ - iface->get_name = g_proxy_drive_get_name; - iface->get_icon = g_proxy_drive_get_icon; - iface->has_volumes = g_proxy_drive_has_volumes; - iface->get_volumes = g_proxy_drive_get_volumes; - iface->is_media_removable = g_proxy_drive_is_media_removable; - iface->has_media = g_proxy_drive_has_media; - iface->is_media_check_automatic = g_proxy_drive_is_media_check_automatic; - iface->can_eject = g_proxy_drive_can_eject; - iface->can_poll_for_media = g_proxy_drive_can_poll_for_media; - iface->eject = g_proxy_drive_eject; - iface->eject_finish = g_proxy_drive_eject_finish; - iface->poll_for_media = g_proxy_drive_poll_for_media; - iface->poll_for_media_finish = g_proxy_drive_poll_for_media_finish; - iface->get_identifier = g_proxy_drive_get_identifier; - iface->enumerate_identifiers = g_proxy_drive_enumerate_identifiers; -} - -void -g_proxy_drive_register (GIOModule *module) -{ - g_proxy_drive_register_type (G_TYPE_MODULE (module)); -} diff --git a/gnome-2-24/monitor/proxy/gproxydrive.h b/gnome-2-24/monitor/proxy/gproxydrive.h deleted file mode 100644 index 7494286c..00000000 --- a/gnome-2-24/monitor/proxy/gproxydrive.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_PROXY_DRIVE_H__ -#define __G_PROXY_DRIVE_H__ - -#include -#include - -#include "gproxyvolumemonitor.h" - -G_BEGIN_DECLS - -#define G_TYPE_PROXY_DRIVE (g_proxy_drive_get_type ()) -#define G_PROXY_DRIVE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PROXY_DRIVE, GProxyDrive)) -#define G_PROXY_DRIVE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_PROXY_DRIVE, GProxyDriveClass)) -#define G_IS_PROXY_DRIVE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_PROXY_DRIVE)) -#define G_IS_PROXY_DRIVE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_PROXY_DRIVE)) - -typedef struct _GProxyDriveClass GProxyDriveClass; - -struct _GProxyDriveClass { - GObjectClass parent_class; -}; - -GType g_proxy_drive_get_type (void) G_GNUC_CONST; -void g_proxy_drive_register (GIOModule *module); -GProxyDrive *g_proxy_drive_new (GProxyVolumeMonitor *volume_monitor); -void g_proxy_drive_update (GProxyDrive *drive, - DBusMessageIter *iter); -const char *g_proxy_drive_get_id (GProxyDrive *drive); - -G_END_DECLS - -#endif /* __G_PROXY_DRIVE_H__ */ diff --git a/gnome-2-24/monitor/proxy/gproxymount.c b/gnome-2-24/monitor/proxy/gproxymount.c deleted file mode 100644 index 123f5c43..00000000 --- a/gnome-2-24/monitor/proxy/gproxymount.c +++ /dev/null @@ -1,560 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#include "gproxyvolumemonitor.h" -#include "gproxymount.h" -#include "gproxyvolume.h" - -/* Protects all fields of GProxyMount that can change */ -G_LOCK_DEFINE_STATIC(proxy_mount); - -struct _GProxyMount { - GObject parent; - - GProxyVolumeMonitor *volume_monitor; - - char *id; - char *name; - char *uuid; - char *volume_id; - gboolean can_unmount; - char **x_content_types; - GFile *root; - GIcon *icon; -}; - -static void g_proxy_mount_mount_iface_init (GMountIface *iface); - -#define _G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) { \ - const GInterfaceInfo g_implement_interface_info = { \ - (GInterfaceInitFunc) iface_init, NULL, NULL \ - }; \ - g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ -} -G_DEFINE_DYNAMIC_TYPE_EXTENDED (GProxyMount, g_proxy_mount, G_TYPE_OBJECT, 0, - _G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_MOUNT, - g_proxy_mount_mount_iface_init)) - -static void -g_proxy_mount_finalize (GObject *object) -{ - GProxyMount *mount; - - mount = G_PROXY_MOUNT (object); - - g_free (mount->id); - g_free (mount->name); - g_free (mount->uuid); - g_free (mount->volume_id); - g_strfreev (mount->x_content_types); - if (mount->icon != NULL) - g_object_unref (mount->icon); - if (mount->root != NULL) - g_object_unref (mount->root); - - if (mount->volume_monitor != NULL) - g_object_unref (mount->volume_monitor); - - if (G_OBJECT_CLASS (g_proxy_mount_parent_class)->finalize) - (*G_OBJECT_CLASS (g_proxy_mount_parent_class)->finalize) (object); -} - -static void -g_proxy_mount_class_init (GProxyMountClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = g_proxy_mount_finalize; -} - -static void -g_proxy_mount_class_finalize (GProxyMountClass *klass) -{ -} - -static void -g_proxy_mount_init (GProxyMount *proxy_mount) -{ -} - -GProxyMount * -g_proxy_mount_new (GProxyVolumeMonitor *volume_monitor) -{ - GProxyMount *mount; - mount = g_object_new (G_TYPE_PROXY_MOUNT, NULL); - mount->volume_monitor = g_object_ref (volume_monitor); - return mount; -} - -gboolean -g_proxy_mount_has_mount_path (GProxyMount *mount, const char *mount_path) -{ - char *path; - gboolean result; - result = FALSE; - path = g_file_get_path (mount->root); - if (path != NULL) - { - if (strcmp (path, mount_path) == 0) - result = TRUE; - g_free (path); - } - return result; -} - -/* string id - * string name - * string gicon_data - * string uuid - * string root_uri - * boolean can-unmount - * string volume-id - * array:string x-content-types - */ - -void -g_proxy_mount_update (GProxyMount *mount, - DBusMessageIter *iter) -{ - DBusMessageIter iter_struct; - DBusMessageIter iter_x_content_types; - const char *id; - const char *name; - const char *gicon_data; - const char *uuid; - const char *root_uri; - dbus_bool_t can_unmount; - const char *volume_id; - GPtrArray *x_content_types; - - dbus_message_iter_recurse (iter, &iter_struct); - dbus_message_iter_get_basic (&iter_struct, &id); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &name); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &gicon_data); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &uuid); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &root_uri); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &can_unmount); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &volume_id); - dbus_message_iter_next (&iter_struct); - - x_content_types = g_ptr_array_new (); - dbus_message_iter_recurse (&iter_struct, &iter_x_content_types); - while (dbus_message_iter_get_arg_type (&iter_x_content_types) != DBUS_TYPE_INVALID) - { - const char *x_content_type; - dbus_message_iter_get_basic (&iter_x_content_types, &x_content_type); - dbus_message_iter_next (&iter_x_content_types); - g_ptr_array_add (x_content_types, (gpointer) x_content_type); - } - g_ptr_array_add (x_content_types, NULL); - dbus_message_iter_next (&iter_struct); - - if (mount->id != NULL && strcmp (mount->id, id) != 0) - { - g_warning ("id mismatch during update of mount"); - goto out; - } - - if (strlen (name) == 0) - name = NULL; - if (strlen (uuid) == 0) - uuid = NULL; - - /* out with the old */ - g_free (mount->id); - g_free (mount->name); - g_free (mount->uuid); - g_free (mount->volume_id); - if (mount->icon != NULL) - g_object_unref (mount->icon); - g_strfreev (mount->x_content_types); - if (mount->root != NULL) - g_object_unref (mount->root); - - /* in with the new */ - mount->id = g_strdup (id); - mount->name = g_strdup (name); - mount->icon = _g_icon_new_from_serialized_data (gicon_data); - mount->uuid = g_strdup (uuid); - mount->root = g_file_new_for_uri (root_uri); - mount->can_unmount = can_unmount; - mount->volume_id = g_strdup (volume_id); - mount->x_content_types = g_strdupv ((char **) x_content_types->pdata); - - out: - g_ptr_array_free (x_content_types, TRUE); -} - -const char * -g_proxy_mount_get_id (GProxyMount *mount) -{ - return mount->id; -} - -static GFile * -g_proxy_mount_get_root (GMount *mount) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - GFile *root; - - G_LOCK (proxy_mount); - root = proxy_mount->root != NULL ? g_object_ref (proxy_mount->root) : NULL; - G_UNLOCK (proxy_mount); - return root; -} - -static GIcon * -g_proxy_mount_get_icon (GMount *mount) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - GIcon *icon; - - G_LOCK (proxy_mount); - icon = proxy_mount->icon != NULL ? g_object_ref (proxy_mount->icon) : NULL; - G_UNLOCK (proxy_mount); - return icon; -} - -static char * -g_proxy_mount_get_uuid (GMount *mount) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - char *uuid; - - G_LOCK (proxy_mount); - uuid = g_strdup (proxy_mount->uuid); - G_UNLOCK (proxy_mount); - return uuid; -} - -static char * -g_proxy_mount_get_name (GMount *mount) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - char *name; - - G_LOCK (proxy_mount); - name = g_strdup (proxy_mount->name); - G_UNLOCK (proxy_mount); - - return name; -} - -static GDrive * -g_proxy_mount_get_drive (GMount *mount) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - GProxyVolume *volume; - GDrive *drive; - - G_LOCK (proxy_mount); - volume = NULL; - if (proxy_mount->volume_id != NULL && strlen (proxy_mount->volume_id) > 0) - volume = g_proxy_volume_monitor_get_volume_for_id (proxy_mount->volume_monitor, - proxy_mount->volume_id); - G_UNLOCK (proxy_mount); - - drive = NULL; - if (volume != NULL) - { - drive = g_volume_get_drive (G_VOLUME (volume)); - g_object_unref (volume); - } - - return drive; -} - -static GVolume * -g_proxy_mount_get_volume (GMount *mount) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - GProxyVolume *volume; - - G_LOCK (proxy_mount); - volume = NULL; - if (proxy_mount->volume_id != NULL && strlen (proxy_mount->volume_id) > 0) - volume = g_proxy_volume_monitor_get_volume_for_id (proxy_mount->volume_monitor, - proxy_mount->volume_id); - G_UNLOCK (proxy_mount); - - return volume != NULL ? G_VOLUME (volume) : NULL; -} - -static gboolean -g_proxy_mount_can_unmount (GMount *mount) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - gboolean res; - - G_LOCK (proxy_mount); - res = proxy_mount->can_unmount; - G_UNLOCK (proxy_mount); - - return res; -} - -static gboolean -g_proxy_mount_can_eject (GMount *mount) -{ - GDrive *drive; - gboolean can_eject; - - can_eject = FALSE; - drive = g_proxy_mount_get_drive (mount); - if (drive != NULL) - { - can_eject = g_drive_can_eject (drive); - g_object_unref (drive); - } - - return can_eject; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; -} EjectWrapperOp; - -static void -eject_wrapper_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - EjectWrapperOp *data = user_data; - data->callback (data->object, res, data->user_data); - g_object_unref (data->object); - g_free (data); -} - -static void -g_proxy_mount_eject (GMount *mount, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GDrive *drive; - - drive = g_proxy_mount_get_drive (mount); - - if (drive != NULL) - { - EjectWrapperOp *data; - data = g_new0 (EjectWrapperOp, 1); - data->object = g_object_ref (mount); - data->callback = callback; - data->user_data = user_data; - g_drive_eject (drive, flags, cancellable, eject_wrapper_callback, data); - g_object_unref (drive); - } -} - -static gboolean -g_proxy_mount_eject_finish (GMount *mount, - GAsyncResult *result, - GError **error) -{ - GDrive *drive; - gboolean res; - - res = TRUE; - - drive = g_proxy_mount_get_drive (mount); - - if (drive != NULL) - { - res = g_drive_eject_finish (drive, result, error); - g_object_unref (drive); - } - return res; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; -} DBusOp; - -static void -unmount_cb (DBusMessage *reply, - GError *error, - DBusOp *data) -{ - GSimpleAsyncResult *simple; - if (error != NULL) - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - else - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - g_simple_async_result_complete (simple); - g_object_unref (simple); - - g_object_unref (data->object); - g_free (data); -} - -static void -g_proxy_mount_unmount (GMount *mount, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - DBusConnection *connection; - const char *name; - DBusMessage *message; - DBusOp *data; - dbus_uint32_t _flags = flags; - - G_LOCK (proxy_mount); - - data = g_new0 (DBusOp, 1); - data->object = g_object_ref (mount); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - - connection = g_proxy_volume_monitor_get_dbus_connection (proxy_mount->volume_monitor); - name = g_proxy_volume_monitor_get_dbus_name (proxy_mount->volume_monitor); - - message = dbus_message_new_method_call (name, - "/", - "org.gtk.Private.RemoteVolumeMonitor", - "MountUnmount"); - dbus_message_append_args (message, - DBUS_TYPE_STRING, - &(proxy_mount->id), - DBUS_TYPE_UINT32, - &_flags, - DBUS_TYPE_INVALID); - G_UNLOCK (proxy_mount); - - _g_dbus_connection_call_async (connection, - message, - -1, - (GAsyncDBusCallback) unmount_cb, - data); - - dbus_message_unref (message); - dbus_connection_unref (connection); -} - -static gboolean -g_proxy_mount_unmount_finish (GMount *mount, - GAsyncResult *result, - GError **error) -{ - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) - return FALSE; - return TRUE; -} - -static void -g_proxy_mount_guess_content_type (GMount *mount, - gboolean force_rescan, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - /* TODO: handle force_rescan */ - simple = g_simple_async_result_new (G_OBJECT (mount), - callback, - user_data, - NULL); - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -static char ** -g_proxy_mount_guess_content_type_finish (GMount *mount, - GAsyncResult *result, - GError **error) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - return g_strdupv (proxy_mount->x_content_types); -} - -static char ** -g_proxy_mount_guess_content_type_sync (GMount *mount, - gboolean force_rescan, - GCancellable *cancellable, - GError **error) -{ - GProxyMount *proxy_mount = G_PROXY_MOUNT (mount); - /* TODO: handle force_rescan */ - return g_strdupv (proxy_mount->x_content_types); -} - -static void -g_proxy_mount_mount_iface_init (GMountIface *iface) -{ - iface->get_root = g_proxy_mount_get_root; - iface->get_name = g_proxy_mount_get_name; - iface->get_icon = g_proxy_mount_get_icon; - iface->get_uuid = g_proxy_mount_get_uuid; - iface->get_drive = g_proxy_mount_get_drive; - iface->get_volume = g_proxy_mount_get_volume; - iface->can_unmount = g_proxy_mount_can_unmount; - iface->can_eject = g_proxy_mount_can_eject; - iface->unmount = g_proxy_mount_unmount; - iface->unmount_finish = g_proxy_mount_unmount_finish; - iface->eject = g_proxy_mount_eject; - iface->eject_finish = g_proxy_mount_eject_finish; - iface->guess_content_type = g_proxy_mount_guess_content_type; - iface->guess_content_type_finish = g_proxy_mount_guess_content_type_finish; - iface->guess_content_type_sync = g_proxy_mount_guess_content_type_sync; -} - -void -g_proxy_mount_register (GIOModule *module) -{ - g_proxy_mount_register_type (G_TYPE_MODULE (module)); -} diff --git a/gnome-2-24/monitor/proxy/gproxymount.h b/gnome-2-24/monitor/proxy/gproxymount.h deleted file mode 100644 index c6356518..00000000 --- a/gnome-2-24/monitor/proxy/gproxymount.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_PROXY_MOUNT_H__ -#define __G_PROXY_MOUNT_H__ - -#include -#include - -#include "gproxyvolumemonitor.h" - -G_BEGIN_DECLS - -#define G_TYPE_PROXY_MOUNT (g_proxy_mount_get_type ()) -#define G_PROXY_MOUNT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PROXY_MOUNT, GProxyMount)) -#define G_PROXY_MOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_PROXY_MOUNT, GProxyMountClass)) -#define G_IS_PROXY_MOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_PROXY_MOUNT)) -#define G_IS_PROXY_MOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_PROXY_MOUNT)) - -typedef struct _GProxyMountClass GProxyMountClass; - -struct _GProxyMountClass { - GObjectClass parent_class; -}; - -GType g_proxy_mount_get_type (void) G_GNUC_CONST; -void g_proxy_mount_register (GIOModule *module); -GProxyMount *g_proxy_mount_new (GProxyVolumeMonitor *volume_monitor); -void g_proxy_mount_update (GProxyMount *mount, - DBusMessageIter *iter); -const char *g_proxy_mount_get_id (GProxyMount *mount); -gboolean g_proxy_mount_has_mount_path (GProxyMount *mount, const char *mount_path); - -G_END_DECLS - -#endif /* __G_PROXY_MOUNT_H__ */ diff --git a/gnome-2-24/monitor/proxy/gproxyvolume.c b/gnome-2-24/monitor/proxy/gproxyvolume.c deleted file mode 100644 index 23730b2f..00000000 --- a/gnome-2-24/monitor/proxy/gproxyvolume.c +++ /dev/null @@ -1,689 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#include "gproxydrive.h" -#include "gproxyvolume.h" -#include "gproxymount.h" - -/* Protects all fields of GProxyVolume that can change */ -G_LOCK_DEFINE_STATIC(proxy_volume); - -struct _GProxyVolume { - GObject parent; - - GProxyVolumeMonitor *volume_monitor; - - char *id; - char *name; - char *uuid; - char *activation_uri; - GIcon *icon; - char *drive_id; - char *mount_id; - GHashTable *identifiers; - - GMount *foreign_mount; - - gboolean can_mount; - gboolean should_automount; -}; - -static void g_proxy_volume_volume_iface_init (GVolumeIface *iface); - -#define _G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) { \ - const GInterfaceInfo g_implement_interface_info = { \ - (GInterfaceInitFunc) iface_init, NULL, NULL \ - }; \ - g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ -} - -G_DEFINE_DYNAMIC_TYPE_EXTENDED (GProxyVolume, g_proxy_volume, G_TYPE_OBJECT, 0, - _G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_VOLUME, - g_proxy_volume_volume_iface_init)) - -static void -g_proxy_volume_finalize (GObject *object) -{ - GProxyVolume *volume; - - volume = G_PROXY_VOLUME (object); - - g_free (volume->id); - g_free (volume->name); - g_free (volume->uuid); - g_free (volume->activation_uri); - if (volume->icon != NULL) - g_object_unref (volume->icon); - g_free (volume->drive_id); - g_free (volume->mount_id); - if (volume->identifiers != NULL) - g_hash_table_unref (volume->identifiers); - - if (volume->foreign_mount != NULL) - g_object_unref (volume->foreign_mount); - - if (volume->volume_monitor != NULL) - g_object_unref (volume->volume_monitor); - - if (G_OBJECT_CLASS (g_proxy_volume_parent_class)->finalize) - (*G_OBJECT_CLASS (g_proxy_volume_parent_class)->finalize) (object); -} - -static void -g_proxy_volume_class_init (GProxyVolumeClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = g_proxy_volume_finalize; -} - -static void -g_proxy_volume_class_finalize (GProxyVolumeClass *klass) -{ -} - -static void -g_proxy_volume_init (GProxyVolume *proxy_volume) -{ -} - -GProxyVolume * -g_proxy_volume_new (GProxyVolumeMonitor *volume_monitor) -{ - GProxyVolume *volume; - volume = g_object_new (G_TYPE_PROXY_VOLUME, NULL); - volume->volume_monitor = g_object_ref (volume_monitor); - return volume; -} - -static gboolean -changed_in_idle (gpointer data) -{ - GProxyVolume *volume = data; - - g_signal_emit_by_name (volume, "changed"); - if (volume->volume_monitor != NULL) - g_signal_emit_by_name (volume->volume_monitor, "volume-changed", volume); - g_object_unref (volume); - - return FALSE; -} - -static void -foreign_mount_unmounted (GMount *mount, gpointer user_data) -{ - GProxyVolume *volume = G_PROXY_VOLUME (user_data); - gboolean check; - - G_LOCK (proxy_volume); - check = (volume->foreign_mount == mount); - G_UNLOCK (proxy_volume); - if (check) - g_proxy_volume_adopt_foreign_mount (volume, NULL); -} - -void -g_proxy_volume_adopt_foreign_mount (GProxyVolume *volume, - GMount *foreign_mount) -{ - G_LOCK (proxy_volume); - if (volume->foreign_mount != NULL) - g_object_unref (volume->foreign_mount); - - if (foreign_mount != NULL) - { - volume->foreign_mount = g_object_ref (foreign_mount); - g_signal_connect_object (foreign_mount, "unmounted", (GCallback) foreign_mount_unmounted, volume, 0); - } - else - volume->foreign_mount = NULL; - - g_idle_add (changed_in_idle, g_object_ref (volume)); - G_UNLOCK (proxy_volume); -} - -/* string id - * string name - * string gicon_data - * string uuid - * string activation_uri - * boolean can-mount - * boolean should-automount - * string drive-id - * string mount-id - * dict:string->string identifiers - */ - -void g_proxy_volume_update (GProxyVolume *volume, - DBusMessageIter *iter) -{ - DBusMessageIter iter_struct; - const char *id; - const char *name; - const char *gicon_data; - const char *uuid; - const char *activation_uri; - const char *drive_id; - const char *mount_id; - dbus_bool_t can_mount; - dbus_bool_t should_automount; - GHashTable *identifiers; - - dbus_message_iter_recurse (iter, &iter_struct); - dbus_message_iter_get_basic (&iter_struct, &id); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &name); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &gicon_data); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &uuid); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &activation_uri); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &can_mount); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &should_automount); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &drive_id); - dbus_message_iter_next (&iter_struct); - dbus_message_iter_get_basic (&iter_struct, &mount_id); - dbus_message_iter_next (&iter_struct); - - identifiers = _get_identifiers (&iter_struct); - dbus_message_iter_next (&iter_struct); - - if (volume->id != NULL && strcmp (volume->id, id) != 0) - { - g_warning ("id mismatch during update of volume"); - goto out; - } - - if (strlen (name) == 0) - name = NULL; - if (strlen (uuid) == 0) - uuid = NULL; - if (strlen (activation_uri) == 0) - activation_uri = NULL; - - /* out with the old */ - g_free (volume->id); - g_free (volume->name); - g_free (volume->uuid); - g_free (volume->activation_uri); - if (volume->icon != NULL) - g_object_unref (volume->icon); - g_free (volume->drive_id); - g_free (volume->mount_id); - if (volume->identifiers != NULL) - g_hash_table_unref (volume->identifiers); - - /* in with the new */ - volume->id = g_strdup (id); - volume->name = g_strdup (name); - volume->uuid = g_strdup (uuid); - volume->activation_uri = g_strdup (activation_uri); - volume->icon = _g_icon_new_from_serialized_data (gicon_data); - volume->drive_id = g_strdup (drive_id); - volume->mount_id = g_strdup (mount_id); - volume->can_mount = can_mount; - volume->should_automount = should_automount; - volume->identifiers = identifiers != NULL ? g_hash_table_ref (identifiers) : NULL; - - out: - g_hash_table_unref (identifiers); -} - -const char * -g_proxy_volume_get_id (GProxyVolume *volume) -{ - return volume->id; -} - -static GIcon * -g_proxy_volume_get_icon (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - GIcon *icon; - - G_LOCK (proxy_volume); - icon = proxy_volume->icon != NULL ? g_object_ref (proxy_volume->icon) : NULL; - G_UNLOCK (proxy_volume); - return icon; -} - -static char * -g_proxy_volume_get_name (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - char *name; - - G_LOCK (proxy_volume); - name = g_strdup (proxy_volume->name); - G_UNLOCK (proxy_volume); - return name; -} - -static char * -g_proxy_volume_get_uuid (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - char *uuid; - - G_LOCK (proxy_volume); - uuid = g_strdup (proxy_volume->uuid); - G_UNLOCK (proxy_volume); - return uuid; -} - -static gboolean -g_proxy_volume_can_mount (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - gboolean res; - - G_LOCK (proxy_volume); - res = proxy_volume->can_mount; - G_UNLOCK (proxy_volume); - return res; -} - -static gboolean -g_proxy_volume_can_eject (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - GProxyDrive *drive; - gboolean res; - - G_LOCK (proxy_volume); - res = FALSE; - if (proxy_volume->drive_id != NULL && strlen (proxy_volume->drive_id) > 0) - { - drive = g_proxy_volume_monitor_get_drive_for_id (proxy_volume->volume_monitor, - proxy_volume->drive_id); - if (drive != NULL) - { - res = g_drive_can_eject (G_DRIVE (drive)); - g_object_unref (drive); - } - } - G_UNLOCK (proxy_volume); - - return res; -} - -static gboolean -g_proxy_volume_should_automount (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - gboolean res; - - G_LOCK (proxy_volume); - res = proxy_volume->should_automount; - G_UNLOCK (proxy_volume); - - return res; -} - -static GDrive * -g_proxy_volume_get_drive (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - GProxyDrive *drive; - - G_LOCK (proxy_volume); - drive = NULL; - if (proxy_volume->drive_id != NULL && strlen (proxy_volume->drive_id) > 0) - drive = g_proxy_volume_monitor_get_drive_for_id (proxy_volume->volume_monitor, - proxy_volume->drive_id); - G_UNLOCK (proxy_volume); - - return drive != NULL ? G_DRIVE (drive) : NULL; -} - -static GMount * -g_proxy_volume_get_mount (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - GMount *mount; - - G_LOCK (proxy_volume); - if (proxy_volume->foreign_mount != NULL) - { - mount = g_object_ref (proxy_volume->foreign_mount); - } - else - { - mount = NULL; - if (proxy_volume->mount_id != NULL && strlen (proxy_volume->mount_id) > 0) - { - GProxyMount *proxy_mount; - proxy_mount = g_proxy_volume_monitor_get_mount_for_id (proxy_volume->volume_monitor, - proxy_volume->mount_id); - if (proxy_mount != NULL) - mount = G_MOUNT (proxy_mount); - } - } - G_UNLOCK (proxy_volume); - - return mount; -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; -} EjectWrapperOp; - -static void -eject_wrapper_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - EjectWrapperOp *data = user_data; - data->callback (data->object, res, data->user_data); - g_object_unref (data->object); - g_free (data); -} - -static void -g_proxy_volume_eject (GVolume *volume, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - GProxyDrive *drive; - - drive = NULL; - G_LOCK (proxy_volume); - if (proxy_volume->drive_id != NULL && strlen (proxy_volume->drive_id) > 0) - { - drive = g_proxy_volume_monitor_get_drive_for_id (proxy_volume->volume_monitor, - proxy_volume->drive_id); - } - G_UNLOCK (proxy_volume); - - if (drive != NULL) - { - EjectWrapperOp *data; - data = g_new0 (EjectWrapperOp, 1); - data->object = g_object_ref (volume); - data->callback = callback; - data->user_data = user_data; - g_drive_eject (G_DRIVE (drive), flags, cancellable, eject_wrapper_callback, data); - g_object_unref (drive); - } -} - -static gboolean -g_proxy_volume_eject_finish (GVolume *volume, - GAsyncResult *result, - GError **error) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - GProxyDrive *drive; - gboolean res; - - G_LOCK (proxy_volume); - res = TRUE; - drive = NULL; - if (proxy_volume->drive_id != NULL && strlen (proxy_volume->drive_id) > 0) - drive = g_proxy_volume_monitor_get_drive_for_id (proxy_volume->volume_monitor, - proxy_volume->drive_id); - G_UNLOCK (proxy_volume); - - if (drive != NULL) - { - res = g_drive_eject_finish (G_DRIVE (drive), result, error); - g_object_unref (drive); - } - - return res; -} - -static char * -g_proxy_volume_get_identifier (GVolume *volume, - const char *kind) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - char *res; - - G_LOCK (proxy_volume); - if (proxy_volume->identifiers != NULL) - res = g_strdup (g_hash_table_lookup (proxy_volume->identifiers, kind)); - else - res = NULL; - G_UNLOCK (proxy_volume); - - return res; -} - -static void -add_identifier_key (const char *key, const char *value, GPtrArray *res) -{ - g_ptr_array_add (res, g_strdup (key)); -} - -static char ** -g_proxy_volume_enumerate_identifiers (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - GPtrArray *res; - - res = g_ptr_array_new (); - - G_LOCK (proxy_volume); - if (proxy_volume->identifiers != NULL) - g_hash_table_foreach (proxy_volume->identifiers, (GHFunc) add_identifier_key, res); - G_UNLOCK (proxy_volume); - - /* Null-terminate */ - g_ptr_array_add (res, NULL); - - return (char **) g_ptr_array_free (res, FALSE); -} - -typedef struct { - GObject *object; - GAsyncReadyCallback callback; - gpointer user_data; - GCancellable *cancellable; -} DBusOp; - -static void -mount_cb (DBusMessage *reply, - GError *error, - DBusOp *data) -{ - GSimpleAsyncResult *simple; - if (error != NULL) - simple = g_simple_async_result_new_from_error (data->object, - data->callback, - data->user_data, - error); - else - simple = g_simple_async_result_new (data->object, - data->callback, - data->user_data, - NULL); - g_simple_async_result_complete (simple); - g_object_unref (simple); - - g_object_unref (data->object); - g_free (data); -} - -typedef struct -{ - GProxyVolume *enclosing_volume; - GAsyncReadyCallback callback; - gpointer user_data; -} ForeignMountOp; - -static void -mount_foreign_callback (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - ForeignMountOp *data = user_data; - data->callback (G_OBJECT (data->enclosing_volume), res, data->user_data); - g_object_unref (data->enclosing_volume); - g_free (data); -} - -static void -g_proxy_volume_mount (GVolume *volume, - GMountMountFlags flags, - GMountOperation *mount_operation, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - - G_LOCK (proxy_volume); - if (proxy_volume->activation_uri != NULL) - { - ForeignMountOp *data; - GFile *root; - - data = g_new0 (ForeignMountOp, 1); - data->enclosing_volume = g_object_ref (volume); - data->callback = callback; - data->user_data = user_data; - - root = g_file_new_for_uri (proxy_volume->activation_uri); - - G_UNLOCK (proxy_volume); - - g_file_mount_enclosing_volume (root, - flags, - mount_operation, - cancellable, - mount_foreign_callback, - data); - - g_object_unref (root); - } - else - { - DBusOp *data; - DBusConnection *connection; - const char *name; - DBusMessage *message; - dbus_uint32_t _flags = flags; - dbus_bool_t use_mount_operation = mount_operation != NULL; - - /* TODO: support mount_operation */ - - data = g_new0 (DBusOp, 1); - data->object = g_object_ref (volume); - data->callback = callback; - data->user_data = user_data; - data->cancellable = cancellable; - - connection = g_proxy_volume_monitor_get_dbus_connection (proxy_volume->volume_monitor); - name = g_proxy_volume_monitor_get_dbus_name (proxy_volume->volume_monitor); - - message = dbus_message_new_method_call (name, - "/", - "org.gtk.Private.RemoteVolumeMonitor", - "VolumeMount"); - dbus_message_append_args (message, - DBUS_TYPE_STRING, - &(proxy_volume->id), - DBUS_TYPE_UINT32, - &_flags, - DBUS_TYPE_BOOLEAN, - &use_mount_operation, - DBUS_TYPE_INVALID); - G_UNLOCK (proxy_volume); - - _g_dbus_connection_call_async (connection, - message, - -1, - (GAsyncDBusCallback) mount_cb, - data); - dbus_message_unref (message); - dbus_connection_unref (connection); - } -} - -static gboolean -g_proxy_volume_mount_finish (GVolume *volume, - GAsyncResult *result, - GError **error) -{ - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) - return FALSE; - return TRUE; -} - -static GFile * -g_proxy_volume_get_activation_root (GVolume *volume) -{ - GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume); - if (proxy_volume->activation_uri == NULL) - return NULL; - else - return g_file_new_for_uri (proxy_volume->activation_uri); -} - -static void -g_proxy_volume_volume_iface_init (GVolumeIface *iface) -{ - iface->get_name = g_proxy_volume_get_name; - iface->get_icon = g_proxy_volume_get_icon; - iface->get_uuid = g_proxy_volume_get_uuid; - iface->get_drive = g_proxy_volume_get_drive; - iface->get_mount = g_proxy_volume_get_mount; - iface->can_mount = g_proxy_volume_can_mount; - iface->can_eject = g_proxy_volume_can_eject; - iface->should_automount = g_proxy_volume_should_automount; - iface->mount_fn = g_proxy_volume_mount; - iface->mount_finish = g_proxy_volume_mount_finish; - iface->eject = g_proxy_volume_eject; - iface->eject_finish = g_proxy_volume_eject_finish; - iface->get_identifier = g_proxy_volume_get_identifier; - iface->enumerate_identifiers = g_proxy_volume_enumerate_identifiers; - iface->get_activation_root = g_proxy_volume_get_activation_root; -} - -void -g_proxy_volume_register (GIOModule *module) -{ - g_proxy_volume_register_type (G_TYPE_MODULE (module)); -} diff --git a/gnome-2-24/monitor/proxy/gproxyvolume.h b/gnome-2-24/monitor/proxy/gproxyvolume.h deleted file mode 100644 index 5626092f..00000000 --- a/gnome-2-24/monitor/proxy/gproxyvolume.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_PROXY_VOLUME_H__ -#define __G_PROXY_VOLUME_H__ - -#include -#include - -#include "gproxyvolumemonitor.h" - -G_BEGIN_DECLS - -#define G_TYPE_PROXY_VOLUME (g_proxy_volume_get_type ()) -#define G_PROXY_VOLUME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PROXY_VOLUME, GProxyVolume)) -#define G_PROXY_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_PROXY_VOLUME, GProxyVolumeClass)) -#define G_IS_PROXY_VOLUME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_PROXY_VOLUME)) -#define G_IS_PROXY_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_PROXY_VOLUME)) - -typedef struct _GProxyVolumeClass GProxyVolumeClass; - -struct _GProxyVolumeClass { - GObjectClass parent_class; -}; - -GType g_proxy_volume_get_type (void) G_GNUC_CONST; -GProxyVolume *g_proxy_volume_new (GProxyVolumeMonitor *volume_monitor); -void g_proxy_volume_update (GProxyVolume *volume, - DBusMessageIter *iter); -const char *g_proxy_volume_get_id (GProxyVolume *volume); -void g_proxy_volume_adopt_foreign_mount (GProxyVolume *volume, - GMount *foreign_mount); -void g_proxy_volume_register (GIOModule *module); - - -G_END_DECLS - -#endif /* __G_PROXY_VOLUME_H__ */ diff --git a/gnome-2-24/monitor/proxy/gproxyvolumemonitor.c b/gnome-2-24/monitor/proxy/gproxyvolumemonitor.c deleted file mode 100644 index e71fcde0..00000000 --- a/gnome-2-24/monitor/proxy/gproxyvolumemonitor.c +++ /dev/null @@ -1,1321 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -/* - * TODO: since we already call IsSupported() at module load time (in - * order to register the appropriate types) we really just should - * construct all the volume monitors. This is a good idea because - * - * - instead of calling IsSupported() we just call List() - * - e.g. exactly the same IPC overhead - * - neglible memory + cpu overhead - * - will need to construct them at some point - * - we can actually implement get_mount_for_mount_path() - * correctly even when no volume monitor is constructed - * - * - implement support for GMountOperation - * - not implemented in the HAL volume monitor and that's all - * that is using it right now. Will implement at some point - * when it's needed or someone has spare cycles. - */ - -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include "gproxyvolumemonitor.h" -#include "gproxymount.h" -#include "gproxyvolume.h" -#include "gproxydrive.h" - -G_LOCK_DEFINE_STATIC(proxy_vm); - -static DBusConnection *the_session_bus = NULL; -static gboolean the_session_bus_is_integrated = FALSE; -static GHashTable *the_volume_monitors = NULL; - -struct _GProxyVolumeMonitor { - GNativeVolumeMonitor parent; - DBusConnection *session_bus; - - GHashTable *drives; - GHashTable *volumes; - GHashTable *mounts; -}; - -G_DEFINE_DYNAMIC_TYPE_EXTENDED (GProxyVolumeMonitor, - g_proxy_volume_monitor, - G_TYPE_NATIVE_VOLUME_MONITOR, - G_TYPE_FLAG_ABSTRACT, - {}) - -static void seed_monitor (GProxyVolumeMonitor *monitor); - -static DBusHandlerResult filter_function (DBusConnection *connection, DBusMessage *message, void *user_data); - -static void signal_emit_in_idle (gpointer object, const char *signal_name, gpointer other_object); - -static gboolean is_supported (GProxyVolumeMonitorClass *klass); - -/* The is_supported API is kinda lame and doesn't pass in the class, - so we work around this with this hack */ -typedef gboolean (*is_supported_func) (void); - -static GProxyVolumeMonitorClass *is_supported_classes[10] = { NULL }; -static gboolean is_supported_0 (void) { return is_supported (is_supported_classes[0]); }; -static gboolean is_supported_1 (void) { return is_supported (is_supported_classes[1]); }; -static gboolean is_supported_2 (void) { return is_supported (is_supported_classes[2]); }; -static gboolean is_supported_3 (void) { return is_supported (is_supported_classes[3]); }; -static gboolean is_supported_4 (void) { return is_supported (is_supported_classes[4]); }; -static gboolean is_supported_5 (void) { return is_supported (is_supported_classes[5]); }; -static gboolean is_supported_6 (void) { return is_supported (is_supported_classes[6]); }; -static gboolean is_supported_7 (void) { return is_supported (is_supported_classes[7]); }; -static gboolean is_supported_8 (void) { return is_supported (is_supported_classes[8]); }; -static gboolean is_supported_9 (void) { return is_supported (is_supported_classes[9]); }; -static is_supported_func is_supported_funcs[] = { - is_supported_0, is_supported_1, is_supported_2, is_supported_3, - is_supported_4, is_supported_5, is_supported_6, is_supported_7, - is_supported_8, is_supported_9, - NULL -}; - -static char * -get_match_rule (GProxyVolumeMonitor *monitor) -{ - return g_strdup_printf ("type='signal'," - "interface='org.gtk.Private.RemoteVolumeMonitor'," - "sender='%s'", - g_proxy_volume_monitor_get_dbus_name (monitor)); -} - -static void -g_proxy_volume_monitor_finalize (GObject *object) -{ - GProxyVolumeMonitor *monitor; - DBusError dbus_error; - char *match_rule; - GObjectClass *parent_class; - - /* since GProxyVolumeMonitor is a non-instantiatable type we're dealing with a - * sub-type here. So we need to look at the grandparent sub-type to get the - * parent class for GProxyVolumeMonitor */ - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent ( - g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)))); - - monitor = G_PROXY_VOLUME_MONITOR (object); - - g_hash_table_unref (monitor->drives); - g_hash_table_unref (monitor->volumes); - g_hash_table_unref (monitor->mounts); - - dbus_connection_remove_filter (monitor->session_bus, filter_function, monitor); - match_rule = get_match_rule (monitor); - dbus_error_init (&dbus_error); - dbus_bus_remove_match (monitor->session_bus, - match_rule, - &dbus_error); - if (dbus_error_is_set (&dbus_error)) { - /* not really a whole lot to do on failure than whine since - * GObject finalization can't fail... - */ - g_warning ("cannot remove match rule '%s': %s: %s", match_rule, dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - } - g_free (match_rule); - dbus_connection_unref (monitor->session_bus); - - if (parent_class->finalize) - parent_class->finalize (object); -} - -static GList * -get_mounts (GVolumeMonitor *volume_monitor) -{ - GProxyVolumeMonitor *monitor; - GList *l; - GHashTableIter hash_iter; - GProxyMount *mount; - - monitor = G_PROXY_VOLUME_MONITOR (volume_monitor); - l = NULL; - - G_LOCK (proxy_vm); - - g_hash_table_iter_init (&hash_iter, monitor->mounts); - while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &mount)) - l = g_list_append (l, g_object_ref (mount)); - - G_UNLOCK (proxy_vm); - - return l; -} - -static GList * -get_volumes (GVolumeMonitor *volume_monitor) -{ - GProxyVolumeMonitor *monitor; - GList *l; - GHashTableIter hash_iter; - GProxyVolume *volume; - - monitor = G_PROXY_VOLUME_MONITOR (volume_monitor); - l = NULL; - - G_LOCK (proxy_vm); - - g_hash_table_iter_init (&hash_iter, monitor->volumes); - while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &volume)) - l = g_list_append (l, g_object_ref (volume)); - - G_UNLOCK (proxy_vm); - - return l; -} - -static GList * -get_connected_drives (GVolumeMonitor *volume_monitor) -{ - GProxyVolumeMonitor *monitor; - GList *l; - GHashTableIter hash_iter; - GProxyDrive *drive; - - monitor = G_PROXY_VOLUME_MONITOR (volume_monitor); - l = NULL; - - G_LOCK (proxy_vm); - - g_hash_table_iter_init (&hash_iter, monitor->drives); - while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &drive)) - l = g_list_append (l, g_object_ref (drive)); - - G_UNLOCK (proxy_vm); - - return l; -} - -static GVolume * -get_volume_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid) -{ - GProxyVolumeMonitor *monitor; - GHashTableIter hash_iter; - GVolume *found_volume; - GVolume *volume; - - monitor = G_PROXY_VOLUME_MONITOR (volume_monitor); - - G_LOCK (proxy_vm); - - found_volume = NULL; - g_hash_table_iter_init (&hash_iter, monitor->volumes); - while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &volume) && - found_volume != NULL) - { - char *_uuid; - _uuid = g_volume_get_uuid (volume); - if (_uuid != NULL) - { - if (strcmp (uuid, _uuid) == 0) - found_volume = g_object_ref (volume); - g_free (_uuid); - } - } - - G_UNLOCK (proxy_vm); - - return found_volume; -} - -static GMount * -get_mount_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid) -{ - GProxyVolumeMonitor *monitor; - GHashTableIter hash_iter; - GMount *found_mount; - GMount *mount; - - monitor = G_PROXY_VOLUME_MONITOR (volume_monitor); - - G_LOCK (proxy_vm); - - found_mount = NULL; - g_hash_table_iter_init (&hash_iter, monitor->mounts); - while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &mount) && - found_mount != NULL) - { - char *_uuid; - _uuid = g_mount_get_uuid (mount); - if (_uuid != NULL) - { - if (strcmp (uuid, _uuid) == 0) - found_mount = g_object_ref (mount); - g_free (_uuid); - } - } - - G_UNLOCK (proxy_vm); - - return found_mount; -} - -static GMount * -get_mount_for_mount_path (const char *mount_path, - GCancellable *cancellable) -{ - GMount *mount; - GProxyVolumeMonitor *volume_monitor; - GProxyVolumeMonitorClass *klass; - GHashTableIter vm_hash_iter; - GHashTableIter vol_hash_iter; - GProxyMount *candidate_mount; - - /* This static method on GNativeVolumeMonitor is a *complete* pain - * in the ass to deal with; we need to rework gio so it's deprecated - * and thus never will get called. - * - * TODO: we don't handle the case when there's no volume monitor ever - * constructed. See TODO at the top of this file on how to handle that. - */ - - mount = NULL; - G_LOCK (proxy_vm); - - /* First find the native volume monitor if one exists */ - g_hash_table_iter_init (&vm_hash_iter, the_volume_monitors); - while (g_hash_table_iter_next (&vm_hash_iter, NULL, (gpointer) &volume_monitor)) { - klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (volume_monitor)); - - if (klass->is_native) { - /* The see if we've got a mount */ - g_hash_table_iter_init (&vol_hash_iter, volume_monitor->mounts); - while (g_hash_table_iter_next (&vol_hash_iter, NULL, (gpointer) &candidate_mount)) { - if (g_proxy_mount_has_mount_path (candidate_mount, mount_path)) - { - mount = g_object_ref (candidate_mount); - goto out; - } - } - goto out; - } - } - - out: - G_UNLOCK (proxy_vm); - return mount; -} - -static void -volume_monitor_went_away (gpointer data, - GObject *where_the_object_was) -{ - GType type = (GType) data; - G_LOCK (proxy_vm); - g_hash_table_remove (the_volume_monitors, (gpointer) type); - G_UNLOCK (proxy_vm); -} - -static GObject * -g_proxy_volume_monitor_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *object; - GProxyVolumeMonitor *monitor; - GProxyVolumeMonitorClass *klass; - GObjectClass *parent_class; - DBusError dbus_error; - char *match_rule; - - G_LOCK (proxy_vm); - - klass = G_PROXY_VOLUME_MONITOR_CLASS (g_type_class_peek (type)); - object = g_hash_table_lookup (the_volume_monitors, (gpointer) type); - if (object != NULL) - { - g_object_ref (object); - goto out; - } - - /* Invoke parent constructor. */ - klass = G_PROXY_VOLUME_MONITOR_CLASS (g_type_class_peek (G_TYPE_PROXY_VOLUME_MONITOR)); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - object = parent_class->constructor (type, - n_construct_properties, - construct_properties); - - monitor = G_PROXY_VOLUME_MONITOR (object); - - dbus_error_init (&dbus_error); - monitor->session_bus = dbus_connection_ref (the_session_bus); - monitor->drives = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - monitor->volumes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - monitor->mounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - - dbus_connection_add_filter (monitor->session_bus, filter_function, monitor, NULL); - match_rule = get_match_rule (monitor); - dbus_bus_add_match (monitor->session_bus, - match_rule, - &dbus_error); - if (dbus_error_is_set (&dbus_error)) { - /* not really a whole lot to do on failure than whine since - * GObject construction can't fail... - */ - g_warning ("cannot add match rule '%s': %s: %s", match_rule, dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - } - g_free (match_rule); - - seed_monitor (monitor); - - g_hash_table_insert (the_volume_monitors, (gpointer) type, object); - g_object_weak_ref (G_OBJECT (object), volume_monitor_went_away, (gpointer) type); - - out: - G_UNLOCK (proxy_vm); - return object; -} - -typedef struct { - const char *signal_name; - GObject *object; - GObject *other_object; -} SignalEmitIdleData; - -static gboolean -signal_emit_in_idle_do (SignalEmitIdleData *data) -{ - if (data->other_object != NULL) - { - g_signal_emit_by_name (data->object, data->signal_name, data->other_object); - g_object_unref (data->other_object); - } - else - { - g_signal_emit_by_name (data->object, data->signal_name); - } - g_object_unref (data->object); - g_free (data); - - return FALSE; -} - -static void -signal_emit_in_idle (gpointer object, const char *signal_name, gpointer other_object) -{ - SignalEmitIdleData *data; - - data = g_new0 (SignalEmitIdleData, 1); - data->signal_name = signal_name; - data->object = g_object_ref (G_OBJECT (object)); - data->other_object = other_object != NULL ? g_object_ref (G_OBJECT (other_object)) : NULL; - g_idle_add ((GSourceFunc) signal_emit_in_idle_do, data); -} - - - -static DBusHandlerResult -filter_function (DBusConnection *connection, DBusMessage *message, void *user_data) -{ - GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data); - DBusMessageIter iter; - const char *id; - const char *the_dbus_name; - const char *member; - GProxyDrive *drive; - GProxyVolume *volume; - GProxyMount *mount; - GProxyVolumeMonitorClass *klass; - - G_LOCK (proxy_vm); - - klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor)); - - member = dbus_message_get_member (message); - - if (dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveChanged") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveConnected") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveDisconnected") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveEjectButton")) { - - dbus_message_iter_init (message, &iter); - dbus_message_iter_get_basic (&iter, &the_dbus_name); - dbus_message_iter_next (&iter); - dbus_message_iter_get_basic (&iter, &id); - dbus_message_iter_next (&iter); - - if (strcmp (the_dbus_name, klass->dbus_name) != 0) - goto not_for_us; - - if (strcmp (member, "DriveChanged") == 0) - { - drive = g_hash_table_lookup (monitor->drives, id); - if (drive != NULL) - { - g_proxy_drive_update (drive, &iter); - signal_emit_in_idle (drive, "changed", NULL); - signal_emit_in_idle (monitor, "drive-changed", drive); - } - } - else if (strcmp (member, "DriveConnected") == 0) - { - drive = g_hash_table_lookup (monitor->drives, id); - if (drive == NULL) - { - drive = g_proxy_drive_new (monitor); - g_proxy_drive_update (drive, &iter); - g_hash_table_insert (monitor->drives, g_strdup (g_proxy_drive_get_id (drive)), drive); - signal_emit_in_idle (monitor, "drive-connected", drive); - } - } - else if (strcmp (member, "DriveDisconnected") == 0) - { - drive = g_hash_table_lookup (monitor->drives, id); - if (drive != NULL) - { - g_object_ref (drive); - g_hash_table_remove (monitor->drives, id); - signal_emit_in_idle (drive, "disconnected", NULL); - signal_emit_in_idle (monitor, "drive-disconnected", drive); - g_object_unref (drive); - } - } - else if (strcmp (member, "DriveEjectButton") == 0) - { - drive = g_hash_table_lookup (monitor->drives, id); - if (drive != NULL) - { - signal_emit_in_idle (drive, "eject-button", NULL); - signal_emit_in_idle (monitor, "drive-eject-button", drive); - } - } - - } else if (dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeChanged") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeAdded") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeRemoved")) { - - dbus_message_iter_init (message, &iter); - dbus_message_iter_get_basic (&iter, &the_dbus_name); - dbus_message_iter_next (&iter); - dbus_message_iter_get_basic (&iter, &id); - dbus_message_iter_next (&iter); - - if (strcmp (the_dbus_name, klass->dbus_name) != 0) - goto not_for_us; - - if (strcmp (member, "VolumeChanged") == 0) - { - volume = g_hash_table_lookup (monitor->volumes, id); - if (volume != NULL) - { - g_proxy_volume_update (volume, &iter); - signal_emit_in_idle (volume, "changed", NULL); - signal_emit_in_idle (monitor, "volume-changed", volume); - } - } - else if (strcmp (member, "VolumeAdded") == 0) - { - volume = g_hash_table_lookup (monitor->volumes, id); - if (volume == NULL) - { - volume = g_proxy_volume_new (monitor); - g_proxy_volume_update (volume, &iter); - g_hash_table_insert (monitor->volumes, g_strdup (g_proxy_volume_get_id (volume)), volume); - signal_emit_in_idle (monitor, "volume-added", volume); - } - } - else if (strcmp (member, "VolumeRemoved") == 0) - { - volume = g_hash_table_lookup (monitor->volumes, id); - if (volume != NULL) - { - g_object_ref (volume); - g_hash_table_remove (monitor->volumes, id); - signal_emit_in_idle (volume, "removed", NULL); - signal_emit_in_idle (monitor, "volume-removed", volume); - g_object_unref (volume); - } - } - - } else if (dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountChanged") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountAdded") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountPreUnmount") || - dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountRemoved")) { - - dbus_message_iter_init (message, &iter); - dbus_message_iter_get_basic (&iter, &the_dbus_name); - dbus_message_iter_next (&iter); - dbus_message_iter_get_basic (&iter, &id); - dbus_message_iter_next (&iter); - - if (strcmp (the_dbus_name, klass->dbus_name) != 0) - goto not_for_us; - - if (strcmp (member, "MountChanged") == 0) - { - mount = g_hash_table_lookup (monitor->mounts, id); - if (mount != NULL) - { - g_proxy_mount_update (mount, &iter); - signal_emit_in_idle (mount, "changed", NULL); - signal_emit_in_idle (monitor, "mount-changed", mount); - } - } - else if (strcmp (member, "MountAdded") == 0) - { - mount = g_hash_table_lookup (monitor->mounts, id); - if (mount == NULL) - { - mount = g_proxy_mount_new (monitor); - g_proxy_mount_update (mount, &iter); - g_hash_table_insert (monitor->mounts, g_strdup (g_proxy_mount_get_id (mount)), mount); - signal_emit_in_idle (monitor, "mount-added", mount); - } - } - else if (strcmp (member, "MountPreUnmount") == 0) - { - mount = g_hash_table_lookup (monitor->mounts, id); - if (mount != NULL) - { - signal_emit_in_idle (mount, "pre-unmount", NULL); - signal_emit_in_idle (monitor, "mount-pre-unmount", mount); - } - } - else if (strcmp (member, "MountRemoved") == 0) - { - mount = g_hash_table_lookup (monitor->mounts, id); - if (mount != NULL) - { - g_object_ref (mount); - g_hash_table_remove (monitor->mounts, id); - signal_emit_in_idle (mount, "unmounted", NULL); - signal_emit_in_idle (monitor, "mount-removed", mount); - g_object_unref (mount); - } - } - - } - - not_for_us: - G_UNLOCK (proxy_vm); - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static void -g_proxy_volume_monitor_init (GProxyVolumeMonitor *monitor) -{ - g_proxy_volume_monitor_setup_session_bus_connection (TRUE); -} - -static void -g_proxy_volume_monitor_class_finalize (GProxyVolumeMonitorClass *klass) -{ - g_free (klass->dbus_name); -} - -typedef struct { - char *dbus_name; - gboolean is_native; - int is_supported_nr; -} ProxyClassData; - -static ProxyClassData * -proxy_class_data_new (const char *dbus_name, gboolean is_native) -{ - ProxyClassData *data; - static int is_supported_nr = 0; - - data = g_new0 (ProxyClassData, 1); - data->dbus_name = g_strdup (dbus_name); - data->is_native = is_native; - data->is_supported_nr = is_supported_nr++; - - g_assert (is_supported_funcs[data->is_supported_nr] != NULL); - - return data; -} - -static void -g_proxy_volume_monitor_class_intern_init_pre (GProxyVolumeMonitorClass *klass, gconstpointer class_data) -{ - ProxyClassData *data = (ProxyClassData *) class_data; - klass->dbus_name = g_strdup (data->dbus_name); - klass->is_native = data->is_native; - klass->is_supported_nr = data->is_supported_nr; - g_proxy_volume_monitor_class_intern_init (klass); -} - -static gboolean -is_remote_monitor_supported (const char *dbus_name) -{ - DBusMessage *message; - DBusMessage *reply; - DBusError dbus_error; - dbus_bool_t is_supported; - - message = NULL; - reply = NULL; - is_supported = FALSE; - - message = dbus_message_new_method_call (dbus_name, - "/", - "org.gtk.Private.RemoteVolumeMonitor", - "IsSupported"); - if (message == NULL) - { - g_warning ("Cannot allocate memory for DBusMessage"); - goto fail; - } - dbus_error_init (&dbus_error); - reply = dbus_connection_send_with_reply_and_block (the_session_bus, - message, - -1, - &dbus_error); - if (dbus_error_is_set (&dbus_error)) - { - g_warning ("invoking IsSupported() failed for remote volume monitor with dbus name %s: %s: %s", - dbus_name, - dbus_error.name, - dbus_error.message); - dbus_error_free (&dbus_error); - goto fail; - } - - if (!dbus_message_get_args (reply, &dbus_error, - DBUS_TYPE_BOOLEAN, &is_supported, - DBUS_TYPE_INVALID)) - { - g_warning ("Error parsing args in reply for IsSupported(): %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto fail; - } - - if (!is_supported) - g_warning ("remote volume monitor with dbus name %s is not supported", dbus_name); - - fail: - if (message != NULL) - dbus_message_unref (message); - if (reply != NULL) - dbus_message_unref (reply); - return is_supported; -} - -static gboolean -is_supported (GProxyVolumeMonitorClass *klass) -{ - gboolean res; - - G_LOCK (proxy_vm); - res = g_proxy_volume_monitor_setup_session_bus_connection (FALSE); - G_UNLOCK (proxy_vm); - - if (res) - res = is_remote_monitor_supported (klass->dbus_name); - - return res; -} - -static GVolume * -adopt_orphan_mount (GMount *mount, GVolumeMonitor *monitor) -{ - GProxyVolumeMonitor *proxy_monitor = G_PROXY_VOLUME_MONITOR (monitor); - GFile *mount_root; - GProxyVolume *proxy_volume; - GVolume *ret; - GHashTableIter hash_iter; - - ret = NULL; - - G_LOCK (proxy_vm); - - mount_root = g_mount_get_root (mount); - - /* TODO: consider what happens if two volumes wants to adopt the same mount? - * - * e.g. imagine two GVolume objects with activation_roots - * - * ssh://server/dir1 - * ssh://server/dir2 - */ - - g_hash_table_iter_init (&hash_iter, proxy_monitor->volumes); - while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &proxy_volume)) - { - GFile *activation_root; - - activation_root = g_volume_get_activation_root (G_VOLUME (proxy_volume)); - if (activation_root != NULL) - { - if (g_file_has_prefix (activation_root, mount_root) || - g_file_equal (activation_root, mount_root)) - { - g_proxy_volume_adopt_foreign_mount (proxy_volume, mount); - ret = g_object_ref (proxy_volume); - g_object_unref (activation_root); - goto found; - } - g_object_unref (activation_root); - } - } - - found: - g_object_unref (mount_root); - - G_UNLOCK (proxy_vm); - return ret; -} - -static void -g_proxy_volume_monitor_class_init (GProxyVolumeMonitorClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GVolumeMonitorClass *monitor_class = G_VOLUME_MONITOR_CLASS (klass); - GNativeVolumeMonitorClass *native_class = G_NATIVE_VOLUME_MONITOR_CLASS (klass); - int i; - - gobject_class->constructor = g_proxy_volume_monitor_constructor; - gobject_class->finalize = g_proxy_volume_monitor_finalize; - - monitor_class->get_mounts = get_mounts; - monitor_class->get_volumes = get_volumes; - monitor_class->get_connected_drives = get_connected_drives; - monitor_class->get_volume_for_uuid = get_volume_for_uuid; - monitor_class->get_mount_for_uuid = get_mount_for_uuid; - monitor_class->adopt_orphan_mount = adopt_orphan_mount; - - i = klass->is_supported_nr; - is_supported_classes[i] = klass; - monitor_class->is_supported = is_supported_funcs[i]; - - native_class->get_mount_for_mount_path = get_mount_for_mount_path; -} - -/* Must be called with no locks held */ -static void -seed_monitor (GProxyVolumeMonitor *monitor) -{ - DBusMessage *message; - DBusMessage *reply; - DBusError dbus_error; - DBusMessageIter iter_reply; - DBusMessageIter iter_array; - - message = dbus_message_new_method_call (g_proxy_volume_monitor_get_dbus_name (monitor), - "/", - "org.gtk.Private.RemoteVolumeMonitor", - "List"); - if (message == NULL) - { - g_warning ("Cannot allocate memory for DBusMessage"); - goto fail; - } - dbus_error_init (&dbus_error); - reply = dbus_connection_send_with_reply_and_block (monitor->session_bus, - message, - -1, - &dbus_error); - dbus_message_unref (message); - if (dbus_error_is_set (&dbus_error)) - { - g_warning ("invoking List() failed for type %s: %s: %s", - G_OBJECT_TYPE_NAME (monitor), - dbus_error.name, - dbus_error.message); - dbus_error_free (&dbus_error); - goto fail; - } - - dbus_message_iter_init (reply, &iter_reply); - - /* TODO: verify signature */ - - /* drives */ - dbus_message_iter_recurse (&iter_reply, &iter_array); - while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID) - { - GProxyDrive *drive; - const char *id; - drive = g_proxy_drive_new (monitor); - g_proxy_drive_update (drive, &iter_array); - id = g_proxy_drive_get_id (drive); - g_hash_table_insert (monitor->drives, g_strdup (id), drive); - dbus_message_iter_next (&iter_array); - } - dbus_message_iter_next (&iter_reply); - - /* volumes */ - dbus_message_iter_recurse (&iter_reply, &iter_array); - while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID) - { - GProxyVolume *volume; - const char *id; - volume = g_proxy_volume_new (monitor); - g_proxy_volume_update (volume, &iter_array); - id = g_proxy_volume_get_id (volume); - g_hash_table_insert (monitor->volumes, g_strdup (id), volume); - dbus_message_iter_next (&iter_array); - } - dbus_message_iter_next (&iter_reply); - - /* mounts */ - dbus_message_iter_recurse (&iter_reply, &iter_array); - while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID) - { - GProxyMount *mount; - const char *id; - mount = g_proxy_mount_new (monitor); - g_proxy_mount_update (mount, &iter_array); - id = g_proxy_mount_get_id (mount); - g_hash_table_insert (monitor->mounts, g_strdup (id), mount); - dbus_message_iter_next (&iter_array); - } - dbus_message_iter_next (&iter_reply); - - dbus_message_unref (reply); - - fail: - ; -} - -GProxyDrive * -g_proxy_volume_monitor_get_drive_for_id (GProxyVolumeMonitor *volume_monitor, - const char *id) -{ - GProxyDrive *drive; - - G_LOCK (proxy_vm); - drive = g_hash_table_lookup (volume_monitor->drives, id); - if (drive != NULL) - g_object_ref (drive); - G_UNLOCK (proxy_vm); - - return drive; -} - -GProxyVolume * -g_proxy_volume_monitor_get_volume_for_id (GProxyVolumeMonitor *volume_monitor, - const char *id) -{ - GProxyVolume *volume; - - G_LOCK (proxy_vm); - volume = g_hash_table_lookup (volume_monitor->volumes, id); - if (volume != NULL) - g_object_ref (volume); - G_UNLOCK (proxy_vm); - - return volume; -} - -GProxyMount * -g_proxy_volume_monitor_get_mount_for_id (GProxyVolumeMonitor *volume_monitor, - const char *id) -{ - GProxyMount *mount; - - G_LOCK (proxy_vm); - mount = g_hash_table_lookup (volume_monitor->mounts, id); - if (mount != NULL) - g_object_ref (mount); - G_UNLOCK (proxy_vm); - - return mount; -} - - -GHashTable * -_get_identifiers (DBusMessageIter *iter) -{ - GHashTable *hash_table; - DBusMessageIter iter_array; - - hash_table = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_free); - - dbus_message_iter_recurse (iter, &iter_array); - while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID) - { - DBusMessageIter iter_dict_entry; - const char *key; - const char *value; - - dbus_message_iter_recurse (&iter_array, &iter_dict_entry); - dbus_message_iter_get_basic (&iter_dict_entry, &key); - dbus_message_iter_next (&iter_dict_entry); - dbus_message_iter_get_basic (&iter_dict_entry, &value); - - g_hash_table_insert (hash_table, g_strdup (key), g_strdup (value)); - - dbus_message_iter_next (&iter_array); - } - - return hash_table; -} - -static GIcon * -_g_icon_new_from_tokens (char **tokens, int num_tokens) -{ - GIcon *icon; - - icon = NULL; - if (strcmp (tokens[0], "GFileIcon") == 0) - { - GFile *file; - char *unescaped_uri; - - if (num_tokens != 2) - goto out; - - unescaped_uri = g_uri_unescape_string (tokens[1], NULL); - file = g_file_new_for_uri (unescaped_uri); - icon = g_file_icon_new (file); - g_object_unref (file); - g_free (unescaped_uri); - } - else if (strcmp (tokens[0], "GThemedIcon") == 0) - { - int n; - - for (n = 1; n < num_tokens; n++) - { - char *unescaped_name; - - unescaped_name = g_uri_unescape_string (tokens[n], NULL); - if (icon == NULL) - icon = g_themed_icon_new (unescaped_name); - else - g_themed_icon_append_name (G_THEMED_ICON (icon), unescaped_name); - g_free (unescaped_name); - } - } - else if (strcmp (tokens[0], "GEmblemedIcon") == 0) - { - int n, m, i; - GIcon *base, *e_icon; - GEmblem *emblem; - GList *emblems, *e; - GEmblemOrigin origin; - char **t = tokens; - - t++; - n = atoi (*t); - t++; - if (t - tokens >= num_tokens) - goto out; - base = _g_icon_new_from_tokens (t, n); - if (base == NULL) - goto out; - - t = t + n; - m = atoi (*t); - t++; - emblems = NULL; - for (i = 0; i < m; i++) - { - origin = atoi (*t); - t++; - n = atoi (*t); - t++; - if (t - tokens >= num_tokens) - goto cleanup; - e_icon = _g_icon_new_from_tokens (t, n); - t += n; - if (e_icon == NULL) - goto cleanup; - emblem = g_emblem_new_with_origin (e_icon, origin); - emblems = g_list_append (emblems, emblem); - } - icon = g_emblemed_icon_new (base, (GEmblem*)emblems->data); - for (e = emblems->next; e; e = e->next) - g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon), (GEmblem*)e->data); - - cleanup: - g_object_unref (base); - g_list_foreach (emblems, (GFunc)g_object_unref, NULL); - g_list_free (emblems); - } - - out: - return icon; -} - -GIcon * -_g_icon_new_from_serialized_data (const char *gicon_data) -{ - char **tokens; - GIcon *icon; - gint num_tokens; - - g_return_val_if_fail (gicon_data != NULL, NULL); - - icon = NULL; - - tokens = g_strsplit (gicon_data, " ", 0); - - if (g_strv_length (tokens) >= 3) - { - num_tokens = atoi (tokens[0]); - icon = _g_icon_new_from_tokens (tokens + 1, num_tokens); - } - - if (icon == NULL) - g_warning ("malformed GIcon data \"%s\"", gicon_data); - - g_strfreev (tokens); - return icon; -} - -DBusConnection * -g_proxy_volume_monitor_get_dbus_connection (GProxyVolumeMonitor *volume_monitor) -{ - return dbus_connection_ref (volume_monitor->session_bus); -} - -const char * -g_proxy_volume_monitor_get_dbus_name (GProxyVolumeMonitor *volume_monitor) -{ - GProxyVolumeMonitorClass *klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (volume_monitor)); - return klass->dbus_name; -} - -static void -register_volume_monitor (GTypeModule *type_module, - const char *type_name, - const char *dbus_name, - gboolean is_native, - int priority) -{ - GType type; - const GTypeInfo type_info = { - sizeof (GProxyVolumeMonitorClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) g_proxy_volume_monitor_class_intern_init_pre, - (GClassFinalizeFunc) g_proxy_volume_monitor_class_finalize, - (gconstpointer) proxy_class_data_new (dbus_name, is_native), /* class_data (leaked!) */ - sizeof (GProxyVolumeMonitor), - 0, /* n_preallocs */ - (GInstanceInitFunc) g_proxy_volume_monitor_init, - NULL /* value_table */ - }; - - type = g_type_module_register_type (type_module, - G_TYPE_PROXY_VOLUME_MONITOR, - type_name, - &type_info, - 0 /* type_flags */); - - g_io_extension_point_implement (is_native ? G_NATIVE_VOLUME_MONITOR_EXTENSION_POINT_NAME : - G_VOLUME_MONITOR_EXTENSION_POINT_NAME, - type, - type_name, - priority); -} - -/* Call with proxy_vm lock held */ -gboolean -g_proxy_volume_monitor_setup_session_bus_connection (gboolean need_integration) -{ - gboolean ret; - DBusError dbus_error; - - ret = FALSE; - - if (the_session_bus != NULL) - goto has_bus_already; - - /* This is so that system daemons can use gio - * without spawning private dbus instances. - * See bug 526454. - */ - if (g_getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) - goto out; - - dbus_error_init (&dbus_error); - the_session_bus = dbus_bus_get_private (DBUS_BUS_SESSION, &dbus_error); - if (dbus_error_is_set (&dbus_error)) - { - g_warning ("cannot connect to the session bus: %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto out; - } - - the_volume_monitors = g_hash_table_new (g_direct_hash, g_direct_equal); - - has_bus_already: - - if (need_integration && !the_session_bus_is_integrated) - { - _g_dbus_connection_integrate_with_main (the_session_bus); - the_session_bus_is_integrated = TRUE; - } - - ret = TRUE; - - out: - return ret; -} - -void -g_proxy_volume_monitor_teardown_session_bus_connection (void) -{ - G_LOCK (proxy_vm); - if (the_session_bus != NULL) - { - if (the_session_bus_is_integrated) - _g_dbus_connection_remove_from_main (the_session_bus); - the_session_bus_is_integrated = FALSE; - dbus_connection_close (the_session_bus); - the_session_bus = NULL; - - g_hash_table_unref (the_volume_monitors); - the_volume_monitors = NULL; - } - G_UNLOCK (proxy_vm); -} - -void -g_proxy_volume_monitor_register (GIOModule *module) -{ - GDir *dir; - GError *error; - - /* first register the abstract base type... */ - g_proxy_volume_monitor_register_type (G_TYPE_MODULE (module)); - - /* ... then register instantiable types for each remote volume - * monitor - each remote volume monitor is defined in a key-value - * file in $(datadir)/gvfs/remote-volume-monitors that must have - * the suffix .monitor. Each file specifies - * - * - the name of the volume monitor - * - the name of the D-Bus service - * - whether the volume monitor is native - * - and if so the priority - */ - - error = NULL; - dir = g_dir_open (REMOTE_VOLUME_MONITORS_DIR, 0, &error); - if (dir == NULL) - { - g_warning ("cannot open directory " REMOTE_VOLUME_MONITORS_DIR ": %s", error->message); - g_error_free (error); - } - else - { - const char *name; - - while ((name = g_dir_read_name (dir)) != NULL) - { - GKeyFile *key_file; - char *type_name; - char *path; - char *dbus_name; - gboolean is_native; - int native_priority; - - type_name = NULL; - key_file = NULL; - dbus_name = NULL; - path = NULL; - - if (!g_str_has_suffix (name, ".monitor")) - goto cont; - - path = g_build_filename (REMOTE_VOLUME_MONITORS_DIR, name, NULL); - - key_file = g_key_file_new (); - error = NULL; - if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error)) - { - g_warning ("error loading key-value file %s: %s", path, error->message); - g_error_free (error); - goto cont; - } - - type_name = g_key_file_get_string (key_file, "RemoteVolumeMonitor", "Name", &error); - if (error != NULL) - { - g_warning ("error extracting Name key from %s: %s", path, error->message); - g_error_free (error); - goto cont; - } - - dbus_name = g_key_file_get_string (key_file, "RemoteVolumeMonitor", "DBusName", &error); - if (error != NULL) - { - g_warning ("error extracting DBusName key from %s: %s", path, error->message); - g_error_free (error); - goto cont; - } - - is_native = g_key_file_get_boolean (key_file, "RemoteVolumeMonitor", "IsNative", &error); - if (error != NULL) - { - g_warning ("error extracting IsNative key from %s: %s", path, error->message); - g_error_free (error); - goto cont; - } - - if (is_native) - { - native_priority = g_key_file_get_integer (key_file, "RemoteVolumeMonitor", "NativePriority", &error); - if (error != NULL) - { - g_warning ("error extracting NativePriority key from %s: %s", path, error->message); - g_error_free (error); - goto cont; - } - } - else - { - native_priority = 0; - } - - register_volume_monitor (G_TYPE_MODULE (module), - type_name, - dbus_name, - is_native, - native_priority); - - cont: - - g_free (type_name); - g_free (dbus_name); - g_free (path); - if (key_file != NULL) - g_key_file_free (key_file); - } - g_dir_close (dir); - } -} diff --git a/gnome-2-24/monitor/proxy/gproxyvolumemonitor.h b/gnome-2-24/monitor/proxy/gproxyvolumemonitor.h deleted file mode 100644 index 4768ba8f..00000000 --- a/gnome-2-24/monitor/proxy/gproxyvolumemonitor.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_PROXY_VOLUME_MONITOR_H__ -#define __G_PROXY_VOLUME_MONITOR_H__ - -#include -#include -#include -#include - -G_BEGIN_DECLS - -#define G_TYPE_PROXY_VOLUME_MONITOR (g_proxy_volume_monitor_get_type ()) -#define G_PROXY_VOLUME_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_PROXY_VOLUME_MONITOR, GProxyVolumeMonitor)) -#define G_PROXY_VOLUME_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_PROXY_VOLUME_MONITOR, GProxyVolumeMonitorClass)) -#define G_IS_PROXY_VOLUME_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_PROXY_VOLUME_MONITOR)) -#define G_IS_PROXY_VOLUME_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_PROXY_VOLUME_MONITOR)) - -typedef struct _GProxyVolumeMonitor GProxyVolumeMonitor; -typedef struct _GProxyVolumeMonitorClass GProxyVolumeMonitorClass; - -/* Forward definitions */ -typedef struct _GProxyDrive GProxyDrive; -typedef struct _GProxyVolume GProxyVolume; -typedef struct _GProxyMount GProxyMount; - -struct _GProxyVolumeMonitorClass { - GNativeVolumeMonitorClass parent_class; - char *dbus_name; - gboolean is_native; - int is_supported_nr; -}; - -GType g_proxy_volume_monitor_get_type (void) G_GNUC_CONST; - -void g_proxy_volume_monitor_register (GIOModule *module); -GProxyDrive *g_proxy_volume_monitor_get_drive_for_id (GProxyVolumeMonitor *volume_monitor, - const char *id); -GProxyVolume *g_proxy_volume_monitor_get_volume_for_id (GProxyVolumeMonitor *volume_monitor, - const char *id); -GProxyMount *g_proxy_volume_monitor_get_mount_for_id (GProxyVolumeMonitor *volume_monitor, - const char *id); -DBusConnection *g_proxy_volume_monitor_get_dbus_connection (GProxyVolumeMonitor *volume_monitor); -const char *g_proxy_volume_monitor_get_dbus_name (GProxyVolumeMonitor *volume_monitor); - -gboolean g_proxy_volume_monitor_setup_session_bus_connection (gboolean need_integration); -void g_proxy_volume_monitor_teardown_session_bus_connection (void); - - -GHashTable *_get_identifiers (DBusMessageIter *iter); - -GIcon *_g_icon_new_from_serialized_data (const char *gicon_data); - -G_END_DECLS - -#endif /* __G_PROXY_VOLUME_MONITOR_H__ */ diff --git a/gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.c b/gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.c deleted file mode 100644 index 3ee5bbf8..00000000 --- a/gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.c +++ /dev/null @@ -1,1155 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "gdbusutils.h" -#include "gvfsproxyvolumemonitordaemon.h" - -static GVolumeMonitor *monitor = NULL; -static DBusConnection *connection = NULL; -static GType the_volume_monitor_type; -static const char *the_dbus_name = NULL; - -static void monitor_try_create (void); - -static char * -_g_icon_serialize (GIcon *icon) -{ - char *ret; - - g_return_val_if_fail (icon != NULL, NULL); - g_return_val_if_fail (G_IS_ICON (icon), NULL); - - /* We encode icons as a series of whitespace-separated tokens. - * The first token is the type of the icon. To help decoding, - * the number of tokens is prepended as the first token (not - * included in the count). - */ - if (G_IS_FILE_ICON (icon)) - { - GFileIcon *file_icon = G_FILE_ICON (icon); - GFile *file; - char *uri; - char *escaped_uri; - - file = g_file_icon_get_file (file_icon); - uri = g_file_get_uri (file); - escaped_uri = g_uri_escape_string (uri, NULL, TRUE); - - ret = g_strdup_printf ("2 GFileIcon %s", escaped_uri); - - g_free (uri); - g_free (escaped_uri); - } - else if (G_IS_THEMED_ICON (icon)) - { - GThemedIcon *themed_icon = G_THEMED_ICON (icon); - char *escaped_name; - char **names; - GString *s; - - g_object_get (themed_icon, - "names", &names, - NULL); - - s = g_string_new (0); - g_string_append_printf (s, "%d GThemedIcon", g_strv_length (names) + 1); - - if (names != NULL) - { - int n; - for (n = 0; names[n] != NULL; n++) - { - escaped_name = g_uri_escape_string (names[n], NULL, TRUE); - g_string_append_c (s, ' '); - g_string_append (s, escaped_name); - g_free (escaped_name); - } - } - - ret = g_string_free (s, FALSE); - - g_strfreev (names); - } - else if (G_IS_EMBLEMED_ICON (icon)) - { - char *base, *s; - GList *emblems, *e; - int n; - GString *str; - - /* GEmblemedIcons are encoded as - * - * GEmblemedIcon [ ]* - */ - str = g_string_new (""); - base = _g_icon_serialize (g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon))); - emblems = g_emblemed_icon_get_emblems (G_EMBLEMED_ICON (icon)); - g_string_append_printf (str, "GEmblemedIcon %s %d", base, g_list_length (emblems)); - n = atoi (base) + 2; - g_free (base); - for (e = emblems; e; e = e->next) - { - s = _g_icon_serialize (g_emblem_get_icon (G_EMBLEM (e->data))); - g_string_append_printf (str, " %d %s", g_emblem_get_origin (G_EMBLEM (e->data)), s); - n += atoi (s) + 2; - g_free (s); - } - - s = g_string_free (str, FALSE); - ret = g_strdup_printf ("%d %s", n + 1, s); - g_free (s); - } - else - { - ret = NULL; - g_warning ("unknown icon type; please add support"); - } - - return ret; -} - -/* string id - * string name - * string gicon_data - * boolean can-eject - * boolean can-poll-for-media - * boolean has-media - * boolean is-media-removable - * array:string volume-ids - * dict:string->string identifiers - */ -#define DRIVE_STRUCT_TYPE "(sssbbbbasa{ss})" - -static void -append_drive (GDrive *drive, DBusMessageIter *iter_array) -{ - DBusMessageIter iter_struct; - DBusMessageIter iter_volume_array; - DBusMessageIter iter_identifiers; - char *id; - char *name; - GIcon *icon; - char *icon_data; - gboolean can_eject; - gboolean can_poll_for_media; - gboolean has_media; - gboolean is_media_removable; - GList *volumes, *l; - char **identifiers; - int n; - - dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct); - - id = g_strdup_printf ("%p", drive); - name = g_drive_get_name (drive); - icon = g_drive_get_icon (drive); - icon_data = _g_icon_serialize (icon); - can_eject = g_drive_can_eject (drive); - can_poll_for_media = g_drive_can_poll_for_media (drive); - has_media = g_drive_has_media (drive); - is_media_removable = g_drive_is_media_removable (drive); - volumes = g_drive_get_volumes (drive); - identifiers = g_drive_enumerate_identifiers (drive); - - if (name == NULL) - name = g_strdup (""); - - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &id); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &icon_data); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_eject); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_poll_for_media); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &has_media); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &is_media_removable); - - dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_volume_array); - for (l = volumes; l != NULL; l = l->next) - { - GVolume *volume = G_VOLUME (l->data); - char *volume_id; - volume_id = g_strdup_printf ("%p", volume); - dbus_message_iter_append_basic (&iter_volume_array, DBUS_TYPE_STRING, &volume_id); - g_free (volume_id); - } - dbus_message_iter_close_container (&iter_struct, &iter_volume_array); - - dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "{ss}", &iter_identifiers); - for (n = 0; identifiers[n] != NULL; n++) - { - DBusMessageIter iter_dict_entry; - char *id_value; - id_value = g_drive_get_identifier (drive, identifiers[n]); - dbus_message_iter_open_container (&iter_identifiers, - DBUS_TYPE_DICT_ENTRY, - NULL, - &iter_dict_entry); - dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &(identifiers[n])); - dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &id_value); - dbus_message_iter_close_container (&iter_identifiers, &iter_dict_entry); - g_free (id_value); - } - dbus_message_iter_close_container (&iter_struct, &iter_identifiers); - - g_strfreev (identifiers); - g_list_foreach (volumes, (GFunc) g_object_unref, NULL); - g_list_free (volumes); - g_free (icon_data); - g_object_unref (icon); - g_free (name); - g_free (id); - - dbus_message_iter_close_container (iter_array, &iter_struct); -} - -/* string id - * string name - * string gicon_data - * string uuid - * string activation_uri - * boolean can-mount - * boolean should-automount - * string drive-id - * string mount-id - * dict:string->string identifiers - */ -#define VOLUME_STRUCT_TYPE "(sssssbbssa{ss})" - -static void -append_volume (GVolume *volume, DBusMessageIter *iter_array) -{ - DBusMessageIter iter_struct; - DBusMessageIter iter_identifiers; - char *id; - char *name; - GIcon *icon; - char *icon_data; - char *uuid; - GFile *activation_root; - char *activation_uri; - gboolean can_mount; - gboolean should_automount; - GDrive *drive; - char *drive_id; - GMount *mount; - char *mount_id; - char **identifiers; - int n; - - dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct); - - id = g_strdup_printf ("%p", volume); - name = g_volume_get_name (volume); - icon = g_volume_get_icon (volume); - icon_data = _g_icon_serialize (icon); - uuid = g_volume_get_uuid (volume); - activation_root = g_volume_get_activation_root (volume); - if (activation_root == NULL) - activation_uri = g_strdup (""); - else - activation_uri = g_file_get_uri (activation_root); - can_mount = g_volume_can_mount (volume); - should_automount = g_volume_should_automount (volume); - drive = g_volume_get_drive (volume); - if (drive == NULL) - drive_id = g_strdup (""); - else - drive_id = g_strdup_printf ("%p", drive); - mount = g_volume_get_mount (volume); - if (mount == NULL) - mount_id = g_strdup (""); - else - mount_id = g_strdup_printf ("%p", mount); - identifiers = g_volume_enumerate_identifiers (volume); - - if (name == NULL) - name = g_strdup (""); - if (uuid == NULL) - uuid = g_strdup (""); - - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &id); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &icon_data); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &uuid); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &activation_uri); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_mount); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &should_automount); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &drive_id); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &mount_id); - - dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "{ss}", &iter_identifiers); - for (n = 0; identifiers[n] != NULL; n++) - { - DBusMessageIter iter_dict_entry; - char *id_value; - id_value = g_volume_get_identifier (volume, identifiers[n]); - dbus_message_iter_open_container (&iter_identifiers, - DBUS_TYPE_DICT_ENTRY, - NULL, - &iter_dict_entry); - dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &(identifiers[n])); - dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &id_value); - dbus_message_iter_close_container (&iter_identifiers, &iter_dict_entry); - g_free (id_value); - } - dbus_message_iter_close_container (&iter_struct, &iter_identifiers); - - g_strfreev (identifiers); - g_free (mount_id); - if (mount != NULL) - g_object_unref (mount); - g_free (drive_id); - if (drive != NULL) - g_object_unref (drive); - g_free (uuid); - if (activation_root != NULL) - g_object_unref (activation_root); - g_free (activation_uri); - g_free (icon_data); - g_object_unref (icon); - g_free (name); - g_free (id); - - dbus_message_iter_close_container (iter_array, &iter_struct); -} - -/* string id - * string name - * string gicon_data - * string uuid - * string root_uri - * boolean can-unmount - * string volume-id - * array:string x-content-types - */ -#define MOUNT_STRUCT_TYPE "(sssssbsas)" - -static void -append_mount (GMount *mount, DBusMessageIter *iter_array) -{ - DBusMessageIter iter_struct; - DBusMessageIter iter_x_content_types_array; - char *id; - char *name; - GIcon *icon; - char *icon_data; - char *uuid; - GFile *root; - char *root_uri; - gboolean can_unmount; - GVolume *volume; - char *volume_id; - char **x_content_types; - int n; - - dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct); - - id = g_strdup_printf ("%p", mount); - name = g_mount_get_name (mount); - icon = g_mount_get_icon (mount); - icon_data = _g_icon_serialize (icon); - uuid = g_mount_get_uuid (mount); - root = g_mount_get_root (mount); - root_uri = g_file_get_uri (root); - can_unmount = g_mount_can_unmount (mount); - volume = g_mount_get_volume (mount); - if (volume == NULL) - volume_id = g_strdup (""); - else - volume_id = g_strdup_printf ("%p", volume); - - if (name == NULL) - name = g_strdup (""); - if (uuid == NULL) - uuid = g_strdup (""); - - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &id); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &icon_data); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &uuid); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &root_uri); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_unmount); - dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &volume_id); - - dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_x_content_types_array); - x_content_types = (char **) g_object_get_data (G_OBJECT (mount), "x-content-types"); - if (x_content_types != NULL) - { - for (n = 0; x_content_types[n] != NULL; n++) - dbus_message_iter_append_basic (&iter_x_content_types_array, DBUS_TYPE_STRING, &(x_content_types[n])); - } - dbus_message_iter_close_container (&iter_struct, &iter_x_content_types_array); - - g_free (volume_id); - if (volume != NULL) - g_object_unref (volume); - g_free (root_uri); - g_object_unref (root); - g_free (uuid); - g_free (icon_data); - g_object_unref (icon); - g_free (name); - g_free (id); - - dbus_message_iter_close_container (iter_array, &iter_struct); -} - -static DBusHandlerResult -handle_list (DBusConnection *connection, DBusMessage *message) -{ - GList *drives; - GList *volumes; - GList *mounts; - DBusMessageIter iter; - DBusMessageIter iter_array; - DBusMessage *reply; - - drives = g_volume_monitor_get_connected_drives (monitor); - volumes = g_volume_monitor_get_volumes (monitor); - mounts = g_volume_monitor_get_mounts (monitor); - - reply = dbus_message_new_method_return (message); - dbus_message_iter_init_append (reply, &iter); - - dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DRIVE_STRUCT_TYPE, &iter_array); - g_list_foreach (drives, (GFunc) append_drive, &iter_array); - dbus_message_iter_close_container (&iter, &iter_array); - - dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, VOLUME_STRUCT_TYPE, &iter_array); - g_list_foreach (volumes, (GFunc) append_volume, &iter_array); - dbus_message_iter_close_container (&iter, &iter_array); - - dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, MOUNT_STRUCT_TYPE, &iter_array); - g_list_foreach (mounts, (GFunc) append_mount, &iter_array); - dbus_message_iter_close_container (&iter, &iter_array); - - g_list_foreach (drives, (GFunc) g_object_unref, NULL); - g_list_free (drives); - g_list_foreach (volumes, (GFunc) g_object_unref, NULL); - g_list_free (volumes); - g_list_foreach (mounts, (GFunc) g_object_unref, NULL); - g_list_free (mounts); - - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -mount_unmount_cb (GMount *mount, GAsyncResult *result, DBusMessage *message) -{ - GError *error; - DBusMessage *reply; - - error = NULL; - if (!g_mount_unmount_finish (mount, result, &error)) - { - reply = _dbus_message_new_from_gerror (message, error); - g_error_free (error); - } - else - { - reply = dbus_message_new_method_return (message); - } - - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (message); - dbus_message_unref (reply); -} - -static DBusHandlerResult -handle_mount_unmount (DBusConnection *connection, DBusMessage *message) -{ - const char *id; - dbus_uint32_t unmount_flags; - DBusError dbus_error; - GList *mounts, *l; - GMount *mount; - DBusHandlerResult ret; - - mounts = NULL; - unmount_flags = 0; - ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_error_init (&dbus_error); - if (!dbus_message_get_args (message, &dbus_error, - DBUS_TYPE_STRING, &id, - DBUS_TYPE_UINT32 &unmount_flags, - DBUS_TYPE_INVALID)) - { - g_warning ("Error parsing args for MountUnmount(): %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto out; - } - - ret = DBUS_HANDLER_RESULT_HANDLED; - - mount = NULL; - mounts = g_volume_monitor_get_mounts (monitor); - for (l = mounts; l != NULL; l = l->next) - { - char *mount_id; - - mount = G_MOUNT (l->data); - mount_id = g_strdup_printf ("%p", mount); - if (strcmp (mount_id, id) == 0) - break; - - g_free (mount_id); - } - if (l == NULL) - mount = NULL; - - if (mount == NULL) - { - DBusMessage *reply; - reply = dbus_message_new_error (message, - "org.gtk.Private.RemoteVolumeMonitor.NotFound", - "The given mount was not found"); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - goto out; - } - - g_mount_unmount (mount, - unmount_flags, - NULL, - (GAsyncReadyCallback) mount_unmount_cb, - dbus_message_ref (message)); - - out: - if (mounts != NULL) - { - g_list_foreach (mounts, (GFunc) g_object_unref, NULL); - g_list_free (mounts); - } - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -volume_mount_cb (GVolume *volume, GAsyncResult *result, DBusMessage *message) -{ - GError *error; - DBusMessage *reply; - - error = NULL; - if (!g_volume_mount_finish (volume, result, &error)) - { - reply = _dbus_message_new_from_gerror (message, error); - g_error_free (error); - } - else - { - reply = dbus_message_new_method_return (message); - } - - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (message); - dbus_message_unref (reply); -} - -static DBusHandlerResult -handle_volume_mount (DBusConnection *connection, DBusMessage *message) -{ - const char *id; - dbus_uint32_t mount_flags; - dbus_bool_t use_mount_operation; - DBusError dbus_error; - GList *volumes, *l; - GVolume *volume; - DBusHandlerResult ret; - GMountOperation *mount_operation; - - volume = NULL; - ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_error_init (&dbus_error); - if (!dbus_message_get_args (message, &dbus_error, - DBUS_TYPE_STRING, &id, - DBUS_TYPE_UINT32, &mount_flags, - DBUS_TYPE_BOOLEAN, &use_mount_operation, - DBUS_TYPE_INVALID)) - { - g_warning ("Error parsing args for VolumeMount(): %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto out; - } - - ret = DBUS_HANDLER_RESULT_HANDLED; - - volume = NULL; - volumes = g_volume_monitor_get_volumes (monitor); - for (l = volumes; l != NULL; l = l->next) - { - char *volume_id; - - volume = G_VOLUME (l->data); - volume_id = g_strdup_printf ("%p", volume); - if (strcmp (volume_id, id) == 0) - break; - - g_free (volume_id); - } - if (l == NULL) - volume = NULL; - - if (volume == NULL) - { - DBusMessage *reply; - reply = dbus_message_new_error (message, - "org.gtk.Private.RemoteVolumeMonitor.NotFound", - "The given volume was not found"); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - goto out; - } - - mount_operation = NULL; - if (use_mount_operation) - mount_operation = g_mount_operation_new (); - - g_volume_mount (volume, - mount_flags, - mount_operation, - NULL, - (GAsyncReadyCallback) volume_mount_cb, - dbus_message_ref (message)); - - if (mount_operation != NULL) - g_object_unref (mount_operation); - - out: - if (volumes != NULL) - { - g_list_foreach (volumes, (GFunc) g_object_unref, NULL); - g_list_free (volumes); - } - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -drive_eject_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message) -{ - GError *error; - DBusMessage *reply; - - error = NULL; - if (!g_drive_eject_finish (drive, result, &error)) - { - reply = _dbus_message_new_from_gerror (message, error); - g_error_free (error); - } - else - { - reply = dbus_message_new_method_return (message); - } - - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (message); - dbus_message_unref (reply); -} - -static DBusHandlerResult -handle_drive_eject (DBusConnection *connection, DBusMessage *message) -{ - const char *id; - dbus_uint32_t unmount_flags; - DBusError dbus_error; - GList *drives, *l; - GDrive *drive; - DBusHandlerResult ret; - - drive = NULL; - unmount_flags = 0; - ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_error_init (&dbus_error); - if (!dbus_message_get_args (message, &dbus_error, - DBUS_TYPE_STRING, &id, - DBUS_TYPE_UINT32 &unmount_flags, - DBUS_TYPE_INVALID)) - { - g_warning ("Error parsing args for DriveEject(): %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto out; - } - - ret = DBUS_HANDLER_RESULT_HANDLED; - - drive = NULL; - drives = g_volume_monitor_get_connected_drives (monitor); - for (l = drives; l != NULL; l = l->next) - { - char *drive_id; - - drive = G_DRIVE (l->data); - drive_id = g_strdup_printf ("%p", drive); - if (strcmp (drive_id, id) == 0) - break; - - g_free (drive_id); - } - if (l == NULL) - drive = NULL; - - if (drive == NULL) - { - DBusMessage *reply; - reply = dbus_message_new_error (message, - "org.gtk.Private.RemoteVolumeMonitor.NotFound", - "The given drive was not found"); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - goto out; - } - - g_drive_eject (drive, - unmount_flags, - NULL, - (GAsyncReadyCallback) drive_eject_cb, - dbus_message_ref (message)); - - out: - if (drives != NULL) - { - g_list_foreach (drives, (GFunc) g_object_unref, NULL); - g_list_free (drives); - } - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -drive_poll_for_media_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message) -{ - GError *error; - DBusMessage *reply; - - error = NULL; - if (!g_drive_poll_for_media_finish (drive, result, &error)) - { - reply = _dbus_message_new_from_gerror (message, error); - g_error_free (error); - } - else - { - reply = dbus_message_new_method_return (message); - } - - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (message); - dbus_message_unref (reply); -} - -static DBusHandlerResult -handle_drive_poll_for_media (DBusConnection *connection, DBusMessage *message) -{ - const char *id; - DBusError dbus_error; - GList *drives, *l; - GDrive *drive; - DBusHandlerResult ret; - - drive = NULL; - ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_error_init (&dbus_error); - if (!dbus_message_get_args (message, &dbus_error, - DBUS_TYPE_STRING, &id, - DBUS_TYPE_INVALID)) - { - g_warning ("Error parsing args for DrivePollForMedia(): %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto out; - } - - ret = DBUS_HANDLER_RESULT_HANDLED; - - drive = NULL; - drives = g_volume_monitor_get_connected_drives (monitor); - for (l = drives; l != NULL; l = l->next) - { - char *drive_id; - - drive = G_DRIVE (l->data); - drive_id = g_strdup_printf ("%p", drive); - if (strcmp (drive_id, id) == 0) - break; - - g_free (drive_id); - } - if (l == NULL) - drive = NULL; - - if (drive == NULL) - { - DBusMessage *reply; - reply = dbus_message_new_error (message, - "org.gtk.Private.RemoteVolumeMonitor.NotFound", - "The given drive was not found"); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - goto out; - } - - g_drive_poll_for_media (drive, - NULL, - (GAsyncReadyCallback) drive_poll_for_media_cb, - dbus_message_ref (message)); - - out: - if (drives != NULL) - { - g_list_foreach (drives, (GFunc) g_object_unref, NULL); - g_list_free (drives); - } - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static DBusHandlerResult -handle_is_supported (DBusConnection *connection, DBusMessage *message) -{ - dbus_bool_t is_supported; - DBusMessage *reply; - DBusMessageIter iter; - - /* if monitor wasn't created on startup; try again */ - if (monitor == NULL) - monitor_try_create (); - - is_supported = (monitor != NULL); - - reply = dbus_message_new_method_return (message); - dbus_message_iter_init_append (reply, &iter); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_supported); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static DBusHandlerResult -filter_function (DBusConnection *connection, DBusMessage *message, void *user_data) -{ - DBusHandlerResult ret; - - ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "IsSupported") && - strcmp (dbus_message_get_path (message), "/") == 0) - { - ret = handle_is_supported (connection, message); - } - else - { - if (monitor != NULL) - { - if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "List") && - strcmp (dbus_message_get_path (message), "/") == 0) - ret = handle_list (connection, message); - - else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "MountUnmount") && - strcmp (dbus_message_get_path (message), "/") == 0) - ret = handle_mount_unmount (connection, message); - - else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeMount") && - strcmp (dbus_message_get_path (message), "/") == 0) - ret = handle_volume_mount (connection, message); - - else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveEject") && - strcmp (dbus_message_get_path (message), "/") == 0) - ret = handle_drive_eject (connection, message); - - else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "DrivePollForMedia") && - strcmp (dbus_message_get_path (message), "/") == 0) - ret = handle_drive_poll_for_media (connection, message); - } - } - - return ret; -} - -typedef void (*AppendFunc) (void *object, DBusMessageIter *iter); - -static void -emit_signal (DBusConnection *connection, const char *signal_name, void *object, AppendFunc func) -{ - char *id; - DBusMessage *message; - DBusMessageIter iter; - - id = g_strdup_printf ("%p", object); - - message = dbus_message_new_signal ("/", "org.gtk.Private.RemoteVolumeMonitor", signal_name); - dbus_message_iter_init_append (message, &iter); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &the_dbus_name); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &id); - - func (object, &iter); - - dbus_connection_send (connection, message, NULL); - dbus_message_unref (message); - - - g_free (id); -} - -static void -drive_changed (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection) -{ - emit_signal (connection, "DriveChanged", drive, (AppendFunc) append_drive); -} - -static void -drive_connected (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection) -{ - emit_signal (connection, "DriveConnected", drive, (AppendFunc) append_drive); -} - -static void -drive_disconnected (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection) -{ - emit_signal (connection, "DriveDisconnected", drive, (AppendFunc) append_drive); -} - -static void -drive_eject_button (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection) -{ - g_warning ("drive eject button!"); - emit_signal (connection, "DriveEjectButton", drive, (AppendFunc) append_drive); -} - -static void -volume_changed (GVolumeMonitor *monitor, GVolume *volume, DBusConnection *connection) -{ - emit_signal (connection, "VolumeChanged", volume, (AppendFunc) append_volume); -} - -static void -volume_added (GVolumeMonitor *monitor, GVolume *volume, DBusConnection *connection) -{ - emit_signal (connection, "VolumeAdded", volume, (AppendFunc) append_volume); -} - -static void -volume_removed (GVolumeMonitor *monitor, GVolume *volume, DBusConnection *connection) -{ - emit_signal (connection, "VolumeRemoved", volume, (AppendFunc) append_volume); -} - -static void -mount_changed (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection) -{ - emit_signal (connection, "MountChanged", mount, (AppendFunc) append_mount); -} - -static void -mount_sniff_x_content_type (GMount *mount) -{ - char **x_content_types; - x_content_types = g_mount_guess_content_type_sync (mount, TRUE, NULL, NULL); - g_object_set_data_full (G_OBJECT (mount), "x-content-types", x_content_types, (GDestroyNotify) g_strfreev); -} - -static void -mount_added (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection) -{ - mount_sniff_x_content_type (mount); - emit_signal (connection, "MountAdded", mount, (AppendFunc) append_mount); -} - -static void -mount_pre_unmount (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection) -{ - emit_signal (connection, "MountPreUnmount", mount, (AppendFunc) append_mount); -} - -static void -mount_removed (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection) -{ - emit_signal (connection, "MountRemoved", mount, (AppendFunc) append_mount); -} - -void -g_vfs_proxy_volume_monitor_daemon_init (void) -{ - /* avoid loading the gio proxy module which will spawn ourselves - * - * see remote-volume-monitor-module.c - */ - g_setenv ("GVFS_REMOTE_VOLUME_MONITOR_IGNORE", "1", TRUE); - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - dbus_threads_init_default (); - g_thread_init (NULL); - g_type_init (); -} - - -static void -monitor_try_create (void) -{ - GVolumeMonitorClass *klass; - GList *mounts; - GList *l; - - monitor = NULL; - klass = G_VOLUME_MONITOR_CLASS (g_type_class_ref (the_volume_monitor_type)); - if (klass == NULL) - { - g_warning ("Can't get class for type"); - goto fail; - } - - if (klass->is_supported != NULL) - { - if (! (klass->is_supported ())) - { - g_warning ("monitor says it's not supported"); - goto fail; - } - } - - monitor = G_VOLUME_MONITOR (g_object_new (the_volume_monitor_type, NULL)); - if (monitor == NULL) - { - g_warning ("Cannot instantiate volume monitor"); - goto fail; - } - - mounts = g_volume_monitor_get_mounts (monitor); - for (l = mounts; l != NULL; l = l->next) - mount_sniff_x_content_type (G_MOUNT (l->data)); - g_list_foreach (mounts, (GFunc) g_object_unref, NULL); - g_list_free (mounts); - - fail: - if (klass != NULL) - g_type_class_unref (klass); -} - -int -g_vfs_proxy_volume_monitor_daemon_main (int argc, - char *argv[], - const char *dbus_name, - GType volume_monitor_type) -{ - int rc; - int ret; - GMainLoop *loop; - DBusError dbus_error; - - ret = 1; - - loop = g_main_loop_new (NULL, FALSE); - - /* need to start up regardless of whether we can instantiate a - * volume monitor; this is because the proxy will need to be able to - * call IsSupported() on our D-Bus interface. - */ - - the_volume_monitor_type = volume_monitor_type; - the_dbus_name = dbus_name; - - /* try and create the monitor */ - monitor_try_create (); - - dbus_error_init (&dbus_error); - connection = dbus_bus_get (DBUS_BUS_SESSION, &dbus_error); - if (dbus_error_is_set (&dbus_error)) - { - g_warning ("Cannot connect to session bus: %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto out; - } - - _g_dbus_connection_integrate_with_main (connection); - - rc = dbus_bus_request_name (connection, dbus_name, 0, &dbus_error); - if (dbus_error_is_set (&dbus_error)) - { - g_warning ("dbus_bus_request_name failed: %s: %s", dbus_error.name, dbus_error.message); - dbus_error_free (&dbus_error); - goto out; - } - if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) - { - g_warning ("Cannot become primary owner"); - goto out; - } - - if (!dbus_connection_add_filter (connection, filter_function, NULL, NULL)) - { - g_warning ("Cannot add filter function"); - goto out; - } - - if (monitor != NULL) - { - g_signal_connect (monitor, "drive-changed", (GCallback) drive_changed, connection); - g_signal_connect (monitor, "drive-connected", (GCallback) drive_connected, connection); - g_signal_connect (monitor, "drive-disconnected", (GCallback) drive_disconnected, connection); - g_signal_connect (monitor, "drive-eject-button", (GCallback) drive_eject_button, connection); - - g_signal_connect (monitor, "volume-changed", (GCallback) volume_changed, connection); - g_signal_connect (monitor, "volume-added", (GCallback) volume_added, connection); - g_signal_connect (monitor, "volume-removed", (GCallback) volume_removed, connection); - - g_signal_connect (monitor, "mount-changed", (GCallback) mount_changed, connection); - g_signal_connect (monitor, "mount-added", (GCallback) mount_added, connection); - g_signal_connect (monitor, "mount-pre-unmount", (GCallback) mount_pre_unmount, connection); - g_signal_connect (monitor, "mount-removed", (GCallback) mount_removed, connection); - } - - g_main_loop_run (loop); - g_main_loop_unref (loop); - - ret = 0; - -out: - return ret; -} diff --git a/gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.h b/gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.h deleted file mode 100644 index d6c767db..00000000 --- a/gnome-2-24/monitor/proxy/gvfsproxyvolumemonitordaemon.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#ifndef __G_VFS_PROXY_VOLUME_MONITOR_DAEMON_H__ -#define __G_VFS_PROXY_VOLUME_MONITOR_DAEMON_H__ - -#include - -void g_vfs_proxy_volume_monitor_daemon_init (void); -int g_vfs_proxy_volume_monitor_daemon_main (int argc, - char *argv[], - const char *dbus_name, - GType volume_monitor_type); - -#endif diff --git a/gnome-2-24/monitor/proxy/remote-volume-monitor-module.c b/gnome-2-24/monitor/proxy/remote-volume-monitor-module.c deleted file mode 100644 index 90945141..00000000 --- a/gnome-2-24/monitor/proxy/remote-volume-monitor-module.c +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* gvfs - extensions for gio - * - * Copyright (C) 2006-2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include - -#include -#include -#include -#include - -#include "gproxyvolumemonitor.h" -#include "gproxyvolume.h" -#include "gproxymount.h" -#include "gproxydrive.h" - -void -g_io_module_load (GIOModule *module) -{ - /* see gvfsproxyvolumemonitor.c:g_vfs_proxy_volume_monitor_daemon_init() */ - if (g_getenv ("GVFS_REMOTE_VOLUME_MONITOR_IGNORE") != NULL) - goto out; - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - - g_proxy_drive_register (module); - g_proxy_mount_register (module); - g_proxy_volume_register (module); - g_proxy_volume_monitor_register (module); -out: - ; - } - -void -g_io_module_unload (GIOModule *module) -{ - if (g_getenv ("GVFS_REMOTE_VOLUME_MONITOR_IGNORE") != NULL) - goto out; - - g_proxy_volume_monitor_teardown_session_bus_connection (); - -out: - ; -} -- cgit v1.2.1