|
Packit |
ae235b |
/* GIO - GLib Input, Output and Streaming Library
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
Packit |
ae235b |
* Copyright (C) 2008 Hans Breuer
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This library is free software; you can redistribute it and/or
|
|
Packit |
ae235b |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
ae235b |
* License as published by the Free Software Foundation; either
|
|
Packit |
ae235b |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
ae235b |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
ae235b |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
ae235b |
* Lesser General Public License for more details.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* You should have received a copy of the GNU Lesser General
|
|
Packit |
ae235b |
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Author: Alexander Larsson <alexl@redhat.com>
|
|
Packit |
ae235b |
* David Zeuthen <davidz@redhat.com>
|
|
Packit |
ae235b |
* Hans Breuer <hans@breuer.org>
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "config.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include <string.h>
|
|
Packit |
ae235b |
#define WIN32_MEAN_AND_LEAN
|
|
Packit |
ae235b |
#include <windows.h>
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include <glib.h>
|
|
Packit |
ae235b |
#include "gwin32volumemonitor.h"
|
|
Packit |
ae235b |
#include "gwin32mount.h"
|
|
Packit |
ae235b |
#include "gmount.h"
|
|
Packit |
ae235b |
#include "gfile.h"
|
|
Packit |
ae235b |
#include "gmountprivate.h"
|
|
Packit |
ae235b |
#include "gvolumemonitor.h"
|
|
Packit |
ae235b |
#include "gthemedicon.h"
|
|
Packit |
ae235b |
#include "glibintl.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
struct _GWin32Mount {
|
|
Packit |
ae235b |
GObject parent;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
GVolumeMonitor *volume_monitor;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
GWin32Volume *volume; /* owned by volume monitor */
|
|
Packit |
ae235b |
int drive_type;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* why does all this stuff need to be duplicated? It is in volume already! */
|
|
Packit |
ae235b |
char *name;
|
|
Packit |
ae235b |
GIcon *icon;
|
|
Packit |
ae235b |
GIcon *symbolic_icon;
|
|
Packit |
ae235b |
char *mount_path;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
gboolean can_eject;
|
|
Packit |
ae235b |
};
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void g_win32_mount_mount_iface_init (GMountIface *iface);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#define g_win32_mount_get_type _g_win32_mount_get_type
|
|
Packit |
ae235b |
G_DEFINE_TYPE_WITH_CODE (GWin32Mount, g_win32_mount, G_TYPE_OBJECT,
|
|
Packit |
ae235b |
G_IMPLEMENT_INTERFACE (G_TYPE_MOUNT,
|
|
Packit |
ae235b |
g_win32_mount_mount_iface_init))
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_win32_mount_finalize (GObject *object)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *mount;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mount = G_WIN32_MOUNT (object);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (mount->volume_monitor != NULL)
|
|
Packit |
ae235b |
g_object_unref (mount->volume_monitor);
|
|
Packit |
ae235b |
#if 0
|
|
Packit |
ae235b |
if (mount->volume)
|
|
Packit |
ae235b |
_g_win32_volume_unset_mount (mount->volume, mount);
|
|
Packit |
ae235b |
#endif
|
|
Packit |
ae235b |
/* TODO: g_warn_if_fail (volume->volume == NULL); */
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (mount->icon != NULL)
|
|
Packit |
ae235b |
g_object_unref (mount->icon);
|
|
Packit |
ae235b |
if (mount->symbolic_icon != NULL)
|
|
Packit |
ae235b |
g_object_unref (mount->symbolic_icon);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_free (mount->name);
|
|
Packit |
ae235b |
g_free (mount->mount_path);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (G_OBJECT_CLASS (g_win32_mount_parent_class)->finalize)
|
|
Packit |
ae235b |
(*G_OBJECT_CLASS (g_win32_mount_parent_class)->finalize) (object);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_win32_mount_class_init (GWin32MountClass *klass)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
gobject_class->finalize = g_win32_mount_finalize;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_win32_mount_init (GWin32Mount *win32_mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static gchar *
|
|
Packit |
ae235b |
_win32_get_displayname (const char *drive)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
gunichar2 *wdrive = g_utf8_to_utf16 (drive, -1, NULL, NULL, NULL);
|
|
Packit |
ae235b |
gchar *name = NULL;
|
|
Packit |
ae235b |
SHFILEINFOW sfi;
|
|
Packit |
ae235b |
if (SHGetFileInfoW(wdrive, 0, &sfi, sizeof(sfi), SHGFI_DISPLAYNAME))
|
|
Packit |
ae235b |
name = g_utf16_to_utf8 (sfi.szDisplayName, -1, NULL, NULL, NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_free (wdrive);
|
|
Packit |
ae235b |
return name ? name : g_strdup (drive);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/*
|
|
Packit |
ae235b |
* _g_win32_mount_new:
|
|
Packit |
ae235b |
* @volume_monitor: a #GVolumeMonitor.
|
|
Packit |
ae235b |
* @path: a win32 path.
|
|
Packit |
ae235b |
* @volume: usually NULL
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns: a #GWin32Mount for the given win32 path.
|
|
Packit |
ae235b |
**/
|
|
Packit |
ae235b |
GWin32Mount *
|
|
Packit |
ae235b |
_g_win32_mount_new (GVolumeMonitor *volume_monitor,
|
|
Packit |
ae235b |
const char *path,
|
|
Packit |
ae235b |
GWin32Volume *volume)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *mount;
|
|
Packit |
ae235b |
const gchar *drive = path; //fixme
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#if 0
|
|
Packit |
ae235b |
/* No volume for mount: Ignore internal things */
|
|
Packit |
ae235b |
if (volume == NULL && !g_win32_mount_guess_should_display (mount_entry))
|
|
Packit |
ae235b |
return NULL;
|
|
Packit |
ae235b |
#endif
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
mount = g_object_new (G_TYPE_WIN32_MOUNT, NULL);
|
|
Packit |
ae235b |
mount->volume_monitor = volume_monitor != NULL ? g_object_ref (volume_monitor) : NULL;
|
|
Packit |
ae235b |
mount->mount_path = g_strdup (path);
|
|
Packit |
ae235b |
mount->drive_type = GetDriveType (drive);
|
|
Packit |
ae235b |
mount->can_eject = FALSE; /* TODO */
|
|
Packit |
ae235b |
mount->name = _win32_get_displayname (drive);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* need to do this last */
|
|
Packit |
ae235b |
mount->volume = volume;
|
|
Packit |
ae235b |
#if 0
|
|
Packit |
ae235b |
if (volume != NULL)
|
|
Packit |
ae235b |
_g_win32_volume_set_mount (volume, mount);
|
|
Packit |
ae235b |
#endif
|
|
Packit |
ae235b |
return mount;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
void
|
|
Packit |
ae235b |
_g_win32_mount_unmounted (GWin32Mount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
if (mount->volume != NULL)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
#if 0
|
|
Packit |
ae235b |
_g_win32_volume_unset_mount (mount->volume, mount);
|
|
Packit |
ae235b |
#endif
|
|
Packit |
ae235b |
mount->volume = NULL;
|
|
Packit |
ae235b |
g_signal_emit_by_name (mount, "changed");
|
|
Packit |
ae235b |
/* there's really no need to emit mount_changed on the volume monitor
|
|
Packit |
ae235b |
* as we're going to be deleted.. */
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
void
|
|
Packit |
ae235b |
_g_win32_mount_unset_volume (GWin32Mount *mount,
|
|
Packit |
ae235b |
GWin32Volume *volume)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
if (mount->volume == volume)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
mount->volume = NULL;
|
|
Packit |
ae235b |
/* TODO: Emit changed in idle to avoid locking issues */
|
|
Packit |
ae235b |
g_signal_emit_by_name (mount, "changed");
|
|
Packit |
ae235b |
if (mount->volume_monitor != NULL)
|
|
Packit |
ae235b |
g_signal_emit_by_name (mount->volume_monitor, "mount-changed", mount);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static GFile *
|
|
Packit |
ae235b |
g_win32_mount_get_root (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *win32_mount = G_WIN32_MOUNT (mount);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return g_file_new_for_path (win32_mount->mount_path);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static const char *
|
|
Packit |
ae235b |
_win32_drive_type_to_icon (int type, gboolean use_symbolic)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
switch (type)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
case DRIVE_REMOVABLE : return use_symbolic ? "drive-removable-media-symbolic" : "drive-removable-media";
|
|
Packit |
ae235b |
case DRIVE_FIXED : return use_symbolic ? "drive-harddisk-symbolic" : "drive-harddisk";
|
|
Packit |
ae235b |
case DRIVE_REMOTE : return use_symbolic ? "folder-remote-symbolic" : "folder-remote";
|
|
Packit |
ae235b |
case DRIVE_CDROM : return use_symbolic ? "drive-optical-symbolic" : "drive-optical";
|
|
Packit |
ae235b |
default : return use_symbolic ? "folder-symbolic" : "folder";
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static GIcon *
|
|
Packit |
ae235b |
g_win32_mount_get_icon (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *win32_mount = G_WIN32_MOUNT (mount);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_return_val_if_fail (win32_mount->mount_path != NULL, NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* lazy creation */
|
|
Packit |
ae235b |
if (!win32_mount->icon)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
SHFILEINFOW shfi;
|
|
Packit |
ae235b |
wchar_t *wfn = g_utf8_to_utf16 (win32_mount->mount_path, -1, NULL, NULL, NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (SHGetFileInfoW (wfn, 0, &shfi, sizeof (shfi), SHGFI_ICONLOCATION))
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
gchar *name = g_utf16_to_utf8 (shfi.szDisplayName, -1, NULL, NULL, NULL);
|
|
Packit |
ae235b |
gchar *id = g_strdup_printf ("%s,%i", name, shfi.iIcon);
|
|
Packit |
ae235b |
win32_mount->icon = g_themed_icon_new (id);
|
|
Packit |
ae235b |
g_free (name);
|
|
Packit |
ae235b |
g_free (id);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
else
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
win32_mount->icon = g_themed_icon_new_with_default_fallbacks (_win32_drive_type_to_icon (win32_mount->drive_type, FALSE));
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return g_object_ref (win32_mount->icon);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static GIcon *
|
|
Packit |
ae235b |
g_win32_mount_get_symbolic_icon (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *win32_mount = G_WIN32_MOUNT (mount);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_return_val_if_fail (win32_mount->mount_path != NULL, NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* lazy creation */
|
|
Packit |
ae235b |
if (!win32_mount->symbolic_icon)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
win32_mount->symbolic_icon = g_themed_icon_new_with_default_fallbacks (_win32_drive_type_to_icon (win32_mount->drive_type, TRUE));
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return g_object_ref (win32_mount->symbolic_icon);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static char *
|
|
Packit |
ae235b |
g_win32_mount_get_uuid (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
return NULL;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static char *
|
|
Packit |
ae235b |
g_win32_mount_get_name (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *win32_mount = G_WIN32_MOUNT (mount);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return g_strdup (win32_mount->name);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static GDrive *
|
|
Packit |
ae235b |
g_win32_mount_get_drive (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *win32_mount = G_WIN32_MOUNT (mount);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (win32_mount->volume != NULL)
|
|
Packit |
ae235b |
return g_volume_get_drive (G_VOLUME (win32_mount->volume));
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return NULL;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static GVolume *
|
|
Packit |
ae235b |
g_win32_mount_get_volume (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *win32_mount = G_WIN32_MOUNT (mount);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (win32_mount->volume)
|
|
Packit |
ae235b |
return G_VOLUME (g_object_ref (win32_mount->volume));
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return NULL;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static gboolean
|
|
Packit |
ae235b |
g_win32_mount_can_unmount (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
return FALSE;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static gboolean
|
|
Packit |
ae235b |
g_win32_mount_can_eject (GMount *mount)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GWin32Mount *win32_mount = G_WIN32_MOUNT (mount);
|
|
Packit |
ae235b |
return win32_mount->can_eject;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
typedef struct {
|
|
Packit |
ae235b |
GWin32Mount *win32_mount;
|
|
Packit |
ae235b |
GAsyncReadyCallback callback;
|
|
Packit |
ae235b |
gpointer user_data;
|
|
Packit |
ae235b |
GCancellable *cancellable;
|
|
Packit |
ae235b |
int error_fd;
|
|
Packit |
ae235b |
GIOChannel *error_channel;
|
|
Packit |
ae235b |
guint error_channel_source_id;
|
|
Packit |
ae235b |
GString *error_string;
|
|
Packit |
ae235b |
} UnmountEjectOp;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_win32_mount_unmount (GMount *mount,
|
|
Packit |
ae235b |
GMountUnmountFlags flags,
|
|
Packit |
ae235b |
GCancellable *cancellable,
|
|
Packit |
ae235b |
GAsyncReadyCallback callback,
|
|
Packit |
ae235b |
gpointer user_data)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static gboolean
|
|
Packit |
ae235b |
g_win32_mount_unmount_finish (GMount *mount,
|
|
Packit |
ae235b |
GAsyncResult *result,
|
|
Packit |
ae235b |
GError **error)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
return FALSE;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_win32_mount_eject (GMount *mount,
|
|
Packit |
ae235b |
GMountUnmountFlags flags,
|
|
Packit |
ae235b |
GCancellable *cancellable,
|
|
Packit |
ae235b |
GAsyncReadyCallback callback,
|
|
Packit |
ae235b |
gpointer user_data)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static gboolean
|
|
Packit |
ae235b |
g_win32_mount_eject_finish (GMount *mount,
|
|
Packit |
ae235b |
GAsyncResult *result,
|
|
Packit |
ae235b |
GError **error)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
return FALSE;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_win32_mount_mount_iface_init (GMountIface *iface)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
iface->get_root = g_win32_mount_get_root;
|
|
Packit |
ae235b |
iface->get_name = g_win32_mount_get_name;
|
|
Packit |
ae235b |
iface->get_icon = g_win32_mount_get_icon;
|
|
Packit |
ae235b |
iface->get_symbolic_icon = g_win32_mount_get_symbolic_icon;
|
|
Packit |
ae235b |
iface->get_uuid = g_win32_mount_get_uuid;
|
|
Packit |
ae235b |
iface->get_drive = g_win32_mount_get_drive;
|
|
Packit |
ae235b |
iface->get_volume = g_win32_mount_get_volume;
|
|
Packit |
ae235b |
iface->can_unmount = g_win32_mount_can_unmount;
|
|
Packit |
ae235b |
iface->can_eject = g_win32_mount_can_eject;
|
|
Packit |
ae235b |
iface->unmount = g_win32_mount_unmount;
|
|
Packit |
ae235b |
iface->unmount_finish = g_win32_mount_unmount_finish;
|
|
Packit |
ae235b |
iface->eject = g_win32_mount_eject;
|
|
Packit |
ae235b |
iface->eject_finish = g_win32_mount_eject_finish;
|
|
Packit |
ae235b |
}
|