2003-11-15 20:35:55 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2003-12-08 23:13:14 +00:00
|
|
|
* gtkfilesystemwin32.c: Default implementation of GtkFileSystem for Windows
|
2003-11-15 20:35:55 +00:00
|
|
|
* Copyright (C) 2003, Red Hat, Inc.
|
2004-05-08 16:25:15 +00:00
|
|
|
* Copyright (C) 2004, Hans Breuer
|
2003-11-15 20:35:55 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2004-03-06 03:38:59 +00:00
|
|
|
#include <config.h>
|
2004-08-09 16:59:53 +00:00
|
|
|
#include "gtkalias.h"
|
2003-11-15 20:35:55 +00:00
|
|
|
#include "gtkfilesystem.h"
|
2003-12-08 23:13:14 +00:00
|
|
|
#include "gtkfilesystemwin32.h"
|
2003-11-15 20:35:55 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtkstock.h"
|
2003-12-14 19:03:02 +00:00
|
|
|
#include "gtkiconfactory.h"
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2004-02-28 23:36:11 +00:00
|
|
|
#include <ctype.h>
|
2003-11-15 20:35:55 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
2003-12-14 19:03:02 +00:00
|
|
|
#include <shellapi.h> /* ExtractAssociatedIcon */
|
2003-11-15 20:35:55 +00:00
|
|
|
#include <direct.h>
|
|
|
|
#include <io.h>
|
|
|
|
#define mkdir(p,m) _mkdir(p)
|
2003-12-14 19:03:02 +00:00
|
|
|
#include <gdk/win32/gdkwin32.h> /* gdk_win32_hdc_get */
|
2003-11-15 20:35:55 +00:00
|
|
|
#else
|
2004-03-20 23:45:35 +00:00
|
|
|
#error "The implementation is win32 only."
|
2003-11-15 20:35:55 +00:00
|
|
|
#endif /* G_OS_WIN32 */
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
#ifndef G_IS_DIR_SEPARATOR
|
|
|
|
#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
|
|
|
|
#endif
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
typedef struct _GtkFileSystemWin32Class GtkFileSystemWin32Class;
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
#define GTK_FILE_SYSTEM_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_SYSTEM_WIN32, GtkFileSystemWin32Class))
|
|
|
|
#define GTK_IS_FILE_SYSTEM_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_SYSTEM_WIN32))
|
|
|
|
#define GTK_FILE_SYSTEM_WIN32_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_SYSTEM_WIN32, GtkFileSystemWin32Class))
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
struct _GtkFileSystemWin32Class
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
struct _GtkFileSystemWin32
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
GObject parent_instance;
|
2004-03-24 17:22:36 +00:00
|
|
|
|
|
|
|
GHashTable *folder_hash;
|
2003-11-15 20:35:55 +00:00
|
|
|
};
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
#define GTK_TYPE_FILE_FOLDER_WIN32 (gtk_file_folder_win32_get_type ())
|
|
|
|
#define GTK_FILE_FOLDER_WIN32(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER_WIN32, GtkFileFolderWin32))
|
|
|
|
#define GTK_IS_FILE_FOLDER_WIN32(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER_WIN32))
|
|
|
|
#define GTK_FILE_FOLDER_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_FOLDER_WIN32, GtkFileFolderWin32Class))
|
|
|
|
#define GTK_IS_FILE_FOLDER_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_FOLDER_WIN32))
|
|
|
|
#define GTK_FILE_FOLDER_WIN32_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_FOLDER_WIN32, GtkFileFolderWin32Class))
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
typedef struct _GtkFileFolderWin32 GtkFileFolderWin32;
|
|
|
|
typedef struct _GtkFileFolderWin32Class GtkFileFolderWin32Class;
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
struct _GtkFileFolderWin32Class
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
struct _GtkFileFolderWin32
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2004-03-24 17:22:36 +00:00
|
|
|
GtkFileSystemWin32 *system_win32;
|
2003-11-15 20:35:55 +00:00
|
|
|
GtkFileInfoType types;
|
|
|
|
gchar *filename;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GObjectClass *system_parent_class;
|
|
|
|
static GObjectClass *folder_parent_class;
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
static void gtk_file_system_win32_class_init (GtkFileSystemWin32Class *class);
|
|
|
|
static void gtk_file_system_win32_iface_init (GtkFileSystemIface *iface);
|
|
|
|
static void gtk_file_system_win32_init (GtkFileSystemWin32 *impl);
|
|
|
|
static void gtk_file_system_win32_finalize (GObject *object);
|
2004-01-04 15:45:56 +00:00
|
|
|
|
|
|
|
static GSList * gtk_file_system_win32_list_volumes (GtkFileSystem *file_system);
|
2004-01-28 21:46:02 +00:00
|
|
|
static GtkFileSystemVolume *gtk_file_system_win32_get_volume_for_path (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path);
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
static GtkFileFolder *gtk_file_system_win32_get_folder (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GtkFileInfoType types,
|
|
|
|
GError **error);
|
|
|
|
static gboolean gtk_file_system_win32_create_folder (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error);
|
2004-01-04 15:45:56 +00:00
|
|
|
|
|
|
|
static void gtk_file_system_win32_volume_free (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume);
|
|
|
|
static GtkFilePath *gtk_file_system_win32_volume_get_base_path (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume);
|
|
|
|
static gboolean gtk_file_system_win32_volume_get_is_mounted (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume);
|
|
|
|
static gboolean gtk_file_system_win32_volume_mount (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume,
|
|
|
|
GError **error);
|
|
|
|
static gchar * gtk_file_system_win32_volume_get_display_name (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume);
|
|
|
|
static GdkPixbuf * gtk_file_system_win32_volume_render_icon (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint pixel_size,
|
|
|
|
GError **error);
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
static gboolean gtk_file_system_win32_get_parent (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GtkFilePath **parent,
|
|
|
|
GError **error);
|
|
|
|
static GtkFilePath * gtk_file_system_win32_make_path (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *base_path,
|
|
|
|
const gchar *display_name,
|
|
|
|
GError **error);
|
|
|
|
static gboolean gtk_file_system_win32_parse (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *base_path,
|
|
|
|
const gchar *str,
|
|
|
|
GtkFilePath **folder,
|
|
|
|
gchar **file_part,
|
|
|
|
GError **error);
|
|
|
|
static gchar * gtk_file_system_win32_path_to_uri (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path);
|
|
|
|
static gchar * gtk_file_system_win32_path_to_filename (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path);
|
|
|
|
static GtkFilePath * gtk_file_system_win32_uri_to_path (GtkFileSystem *file_system,
|
|
|
|
const gchar *uri);
|
|
|
|
static GtkFilePath * gtk_file_system_win32_filename_to_path (GtkFileSystem *file_system,
|
|
|
|
const gchar *filename);
|
2003-12-14 19:03:02 +00:00
|
|
|
static GdkPixbuf *gtk_file_system_win32_render_icon (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint pixel_size,
|
|
|
|
GError **error);
|
|
|
|
|
2004-02-28 15:09:27 +00:00
|
|
|
static gboolean gtk_file_system_win32_insert_bookmark (GtkFileSystem *file_system,
|
2003-12-08 23:13:14 +00:00
|
|
|
const GtkFilePath *path,
|
2004-02-28 15:09:27 +00:00
|
|
|
gint position,
|
2003-12-08 23:13:14 +00:00
|
|
|
GError **error);
|
|
|
|
static gboolean gtk_file_system_win32_remove_bookmark (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error);
|
|
|
|
static GSList * gtk_file_system_win32_list_bookmarks (GtkFileSystem *file_system);
|
|
|
|
static GType gtk_file_folder_win32_get_type (void);
|
|
|
|
static void gtk_file_folder_win32_class_init (GtkFileFolderWin32Class *class);
|
|
|
|
static void gtk_file_folder_win32_iface_init (GtkFileFolderIface *iface);
|
|
|
|
static void gtk_file_folder_win32_init (GtkFileFolderWin32 *impl);
|
|
|
|
static void gtk_file_folder_win32_finalize (GObject *object);
|
|
|
|
static GtkFileInfo * gtk_file_folder_win32_get_info (GtkFileFolder *folder,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error);
|
|
|
|
static gboolean gtk_file_folder_win32_list_children (GtkFileFolder *folder,
|
|
|
|
GSList **children,
|
|
|
|
GError **error);
|
2004-01-04 15:45:56 +00:00
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
static gchar * filename_from_path (const GtkFilePath *path);
|
|
|
|
static GtkFilePath * filename_to_path (const gchar *filename);
|
2004-01-04 15:45:56 +00:00
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
static gboolean filename_is_drive_root (const char *filename);
|
|
|
|
static gboolean filename_is_some_root (const char *filename);
|
2003-12-08 23:13:14 +00:00
|
|
|
static GtkFileInfo * filename_get_info (const gchar *filename,
|
|
|
|
GtkFileInfoType types,
|
|
|
|
GError **error);
|
|
|
|
|
2004-01-04 15:45:56 +00:00
|
|
|
/* some info kept together for volumes */
|
|
|
|
struct _GtkFileSystemVolume
|
|
|
|
{
|
|
|
|
gchar *drive;
|
|
|
|
gboolean is_mounted;
|
|
|
|
};
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
/*
|
2003-12-08 23:13:14 +00:00
|
|
|
* GtkFileSystemWin32
|
2003-11-15 20:35:55 +00:00
|
|
|
*/
|
|
|
|
GType
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_get_type (void)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
static GType file_system_win32_type = 0;
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
if (!file_system_win32_type)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
static const GTypeInfo file_system_win32_info =
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
sizeof (GtkFileSystemWin32Class),
|
2003-11-15 20:35:55 +00:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2003-12-08 23:13:14 +00:00
|
|
|
(GClassInitFunc) gtk_file_system_win32_class_init,
|
2003-11-15 20:35:55 +00:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2003-12-08 23:13:14 +00:00
|
|
|
sizeof (GtkFileSystemWin32),
|
2003-11-15 20:35:55 +00:00
|
|
|
0, /* n_preallocs */
|
2003-12-08 23:13:14 +00:00
|
|
|
(GInstanceInitFunc) gtk_file_system_win32_init,
|
2003-11-15 20:35:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const GInterfaceInfo file_system_info =
|
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
(GInterfaceInitFunc) gtk_file_system_win32_iface_init, /* interface_init */
|
|
|
|
NULL, /* interface_finalize */
|
|
|
|
NULL /* interface_data */
|
2003-11-15 20:35:55 +00:00
|
|
|
};
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
file_system_win32_type = g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"GtkFileSystemWin32",
|
|
|
|
&file_system_win32_info, 0);
|
|
|
|
g_type_add_interface_static (file_system_win32_type,
|
2003-11-15 20:35:55 +00:00
|
|
|
GTK_TYPE_FILE_SYSTEM,
|
|
|
|
&file_system_info);
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
return file_system_win32_type;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-12-08 23:13:14 +00:00
|
|
|
* gtk_file_system_win32_new:
|
2003-11-15 20:35:55 +00:00
|
|
|
*
|
2003-12-08 23:13:14 +00:00
|
|
|
* Creates a new #GtkFileSystemWin32 object. #GtkFileSystemWin32
|
2003-11-15 20:35:55 +00:00
|
|
|
* implements the #GtkFileSystem interface with direct access to
|
2003-12-08 23:13:14 +00:00
|
|
|
* the filesystem using Windows API calls
|
2003-11-15 20:35:55 +00:00
|
|
|
*
|
2003-12-08 23:13:14 +00:00
|
|
|
* Return value: the new #GtkFileSystemWin32 object
|
2003-11-15 20:35:55 +00:00
|
|
|
**/
|
|
|
|
GtkFileSystem *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_new (void)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
return g_object_new (GTK_TYPE_FILE_SYSTEM_WIN32, NULL);
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_class_init (GtkFileSystemWin32Class *class)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
system_parent_class = g_type_class_peek_parent (class);
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
gobject_class->finalize = gtk_file_system_win32_finalize;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_iface_init (GtkFileSystemIface *iface)
|
|
|
|
{
|
2004-01-04 15:45:56 +00:00
|
|
|
iface->list_volumes = gtk_file_system_win32_list_volumes;
|
2004-01-28 21:46:02 +00:00
|
|
|
iface->get_volume_for_path = gtk_file_system_win32_get_volume_for_path;
|
2003-12-08 23:13:14 +00:00
|
|
|
iface->get_folder = gtk_file_system_win32_get_folder;
|
|
|
|
iface->create_folder = gtk_file_system_win32_create_folder;
|
2004-01-04 15:45:56 +00:00
|
|
|
iface->volume_free = gtk_file_system_win32_volume_free;
|
|
|
|
iface->volume_get_base_path = gtk_file_system_win32_volume_get_base_path;
|
|
|
|
iface->volume_get_is_mounted = gtk_file_system_win32_volume_get_is_mounted;
|
|
|
|
iface->volume_mount = gtk_file_system_win32_volume_mount;
|
|
|
|
iface->volume_get_display_name = gtk_file_system_win32_volume_get_display_name;
|
|
|
|
iface->volume_render_icon = gtk_file_system_win32_volume_render_icon;
|
2003-12-08 23:13:14 +00:00
|
|
|
iface->get_parent = gtk_file_system_win32_get_parent;
|
|
|
|
iface->make_path = gtk_file_system_win32_make_path;
|
|
|
|
iface->parse = gtk_file_system_win32_parse;
|
|
|
|
iface->path_to_uri = gtk_file_system_win32_path_to_uri;
|
|
|
|
iface->path_to_filename = gtk_file_system_win32_path_to_filename;
|
|
|
|
iface->uri_to_path = gtk_file_system_win32_uri_to_path;
|
|
|
|
iface->filename_to_path = gtk_file_system_win32_filename_to_path;
|
2003-12-14 19:03:02 +00:00
|
|
|
iface->render_icon = gtk_file_system_win32_render_icon;
|
2004-02-28 15:09:27 +00:00
|
|
|
iface->insert_bookmark = gtk_file_system_win32_insert_bookmark;
|
2003-12-08 23:13:14 +00:00
|
|
|
iface->remove_bookmark = gtk_file_system_win32_remove_bookmark;
|
|
|
|
iface->list_bookmarks = gtk_file_system_win32_list_bookmarks;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_init (GtkFileSystemWin32 *system_win32)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-03-24 17:22:36 +00:00
|
|
|
system_win32->folder_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_finalize (GObject *object)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-03-24 17:22:36 +00:00
|
|
|
GtkFileSystemWin32 *system_win32;
|
|
|
|
|
|
|
|
system_win32 = GTK_FILE_SYSTEM_WIN32 (object);
|
|
|
|
|
|
|
|
/* FIXME: assert that the hash is empty? */
|
|
|
|
g_hash_table_destroy (system_win32->folder_hash);
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
system_parent_class->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2004-01-04 15:45:56 +00:00
|
|
|
gtk_file_system_win32_list_volumes (GtkFileSystem *file_system)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-03-22 21:28:07 +00:00
|
|
|
DWORD drives;
|
|
|
|
gchar drive[4] = "A:\\";
|
2003-11-15 20:35:55 +00:00
|
|
|
GSList *list = NULL;
|
|
|
|
|
2004-03-22 21:28:07 +00:00
|
|
|
drives = GetLogicalDrives();
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2004-03-22 21:28:07 +00:00
|
|
|
if (!drives)
|
|
|
|
g_warning ("GetLogicalDrives failed.");
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2004-03-22 21:28:07 +00:00
|
|
|
while (drives && drive[0] <= 'Z')
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-03-22 21:28:07 +00:00
|
|
|
if (drives & 1)
|
|
|
|
{
|
|
|
|
GtkFileSystemVolume *vol = g_new0 (GtkFileSystemVolume, 1);
|
|
|
|
if (drive[0] == 'A' || drive[0] == 'B')
|
|
|
|
vol->is_mounted = FALSE; /* skip floppy */
|
|
|
|
else
|
|
|
|
vol->is_mounted = TRUE; /* handle other removable drives special, too? */
|
|
|
|
|
|
|
|
vol->drive = g_strdup (drive);
|
|
|
|
list = g_slist_append (list, vol);
|
|
|
|
}
|
|
|
|
drives >>= 1;
|
|
|
|
drive[0]++;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2004-01-28 21:46:02 +00:00
|
|
|
static GtkFileSystemVolume *
|
|
|
|
gtk_file_system_win32_get_volume_for_path (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path)
|
2004-01-04 15:45:56 +00:00
|
|
|
{
|
2004-01-28 21:46:02 +00:00
|
|
|
GtkFileSystemVolume *vol = g_new0 (GtkFileSystemVolume, 1);
|
2004-02-28 23:36:11 +00:00
|
|
|
gchar* p = g_strndup (gtk_file_path_get_string (path), 3);
|
2004-01-04 15:45:56 +00:00
|
|
|
|
2004-01-28 21:46:02 +00:00
|
|
|
g_return_val_if_fail (p != NULL, NULL);
|
2004-01-04 15:45:56 +00:00
|
|
|
|
2004-01-28 21:46:02 +00:00
|
|
|
/*FIXME: gtk_file_path_compare() is case sensitive, we are not*/
|
2004-03-20 23:45:35 +00:00
|
|
|
p[0] = g_ascii_toupper (p[0]);
|
2004-01-28 21:46:02 +00:00
|
|
|
vol->drive = p;
|
2004-03-20 23:45:35 +00:00
|
|
|
vol->is_mounted = (p[0] != 'A' && p[0] != 'B');
|
2004-01-04 15:45:56 +00:00
|
|
|
|
2004-01-28 21:46:02 +00:00
|
|
|
return vol;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFileFolder *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_get_folder (GtkFileSystem *file_system,
|
2003-11-15 20:35:55 +00:00
|
|
|
const GtkFilePath *path,
|
|
|
|
GtkFileInfoType types,
|
|
|
|
GError **error)
|
|
|
|
{
|
2004-03-24 17:22:36 +00:00
|
|
|
GtkFileSystemWin32 *system_win32;
|
2003-12-08 23:13:14 +00:00
|
|
|
GtkFileFolderWin32 *folder_win32;
|
2003-11-15 20:35:55 +00:00
|
|
|
gchar *filename;
|
|
|
|
|
2004-03-24 17:22:36 +00:00
|
|
|
system_win32 = GTK_FILE_SYSTEM_WIN32 (file_system);
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
filename = filename_from_path (path);
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
|
|
|
|
2004-03-24 17:22:36 +00:00
|
|
|
folder_win32 = g_hash_table_lookup (system_win32->folder_hash, filename);
|
|
|
|
|
|
|
|
if (folder_win32)
|
|
|
|
return g_object_ref (folder_win32);
|
|
|
|
|
2004-03-24 16:50:56 +00:00
|
|
|
if (!g_file_test (filename, G_FILE_TEST_IS_DIR))
|
|
|
|
{
|
|
|
|
int save_errno = errno;
|
|
|
|
gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
/* If g_file_test() returned FALSE but not due to an error, it means
|
|
|
|
* that the filename is not a directory.
|
|
|
|
*/
|
|
|
|
if (save_errno == 0)
|
|
|
|
/* ENOTDIR */
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
|
|
|
|
_("%s: %s"),
|
|
|
|
filename_utf8 ? filename_utf8 : "???",
|
|
|
|
g_strerror (ENOTDIR));
|
|
|
|
else
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
|
|
|
|
_("error getting information for '%s': %s"),
|
|
|
|
filename_utf8 ? filename_utf8 : "???",
|
|
|
|
g_strerror (save_errno));
|
|
|
|
|
|
|
|
g_free (filename_utf8);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
folder_win32 = g_object_new (GTK_TYPE_FILE_FOLDER_WIN32, NULL);
|
2004-03-24 17:22:36 +00:00
|
|
|
folder_win32->system_win32 = system_win32;
|
2003-12-08 23:13:14 +00:00
|
|
|
folder_win32->filename = filename;
|
|
|
|
folder_win32->types = types;
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2004-03-24 17:22:36 +00:00
|
|
|
g_hash_table_insert (system_win32->folder_hash, folder_win32->filename, folder_win32);
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
return GTK_FILE_FOLDER (folder_win32);
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_create_folder (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-03-24 17:22:36 +00:00
|
|
|
GtkFileSystemWin32 *system_win32;
|
2003-11-15 20:35:55 +00:00
|
|
|
gchar *filename;
|
|
|
|
gboolean result;
|
2004-03-24 17:22:36 +00:00
|
|
|
char *parent;
|
|
|
|
|
|
|
|
system_win32 = GTK_FILE_SYSTEM_WIN32 (file_system);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
filename = filename_from_path (path);
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
2004-03-24 17:33:09 +00:00
|
|
|
|
|
|
|
result = mkdir (filename, 0777) == 0;
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
|
|
|
|
_("error creating directory '%s': %s"),
|
|
|
|
filename_utf8 ? filename_utf8 : "???",
|
|
|
|
g_strerror (errno));
|
|
|
|
g_free (filename_utf8);
|
|
|
|
}
|
2004-04-22 05:08:19 +00:00
|
|
|
else if (!filename_is_drive_root (filename))
|
2004-03-24 17:22:36 +00:00
|
|
|
{
|
|
|
|
parent = g_path_get_dirname (filename);
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
GtkFileFolderWin32 *folder_win32;
|
|
|
|
|
|
|
|
folder_win32 = g_hash_table_lookup (system_win32->folder_hash, parent);
|
|
|
|
if (folder_win32)
|
|
|
|
{
|
|
|
|
GSList *paths;
|
|
|
|
|
|
|
|
paths = g_slist_append (NULL, (GtkFilePath *) path);
|
|
|
|
g_signal_emit_by_name (folder_win32, "files-added", paths);
|
|
|
|
g_slist_free (paths);
|
|
|
|
}
|
|
|
|
g_free(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
g_free (filename);
|
2004-03-24 17:22:36 +00:00
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-01-04 15:45:56 +00:00
|
|
|
static void
|
|
|
|
gtk_file_system_win32_volume_free (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume)
|
|
|
|
{
|
|
|
|
g_free (volume->drive);
|
|
|
|
g_free (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFilePath *
|
|
|
|
gtk_file_system_win32_volume_get_base_path (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume)
|
|
|
|
{
|
2004-03-21 22:06:37 +00:00
|
|
|
return (GtkFilePath *) g_strdup (volume->drive);
|
2004-01-04 15:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_file_system_win32_volume_get_is_mounted (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume)
|
|
|
|
{
|
|
|
|
return volume->is_mounted;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_file_system_win32_volume_mount (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_FAILED,
|
|
|
|
_("This file system does not support mounting"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gtk_file_system_win32_volume_get_display_name (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume)
|
|
|
|
{
|
2004-03-22 21:28:07 +00:00
|
|
|
gchar *real_display_name;
|
2004-03-20 23:45:35 +00:00
|
|
|
gunichar2 *wdrive = g_utf8_to_utf16 (volume->drive, -1, NULL, NULL, NULL);
|
|
|
|
gunichar2 wname[80];
|
2004-01-04 15:45:56 +00:00
|
|
|
|
2004-03-20 23:45:35 +00:00
|
|
|
g_return_val_if_fail (wdrive != NULL, NULL);
|
|
|
|
|
2004-03-22 21:28:07 +00:00
|
|
|
if (GetVolumeInformationW (wdrive,
|
|
|
|
wname, G_N_ELEMENTS(wname),
|
2004-01-04 15:45:56 +00:00
|
|
|
NULL, /* serial number */
|
|
|
|
NULL, /* max. component length */
|
|
|
|
NULL, /* fs flags */
|
2004-03-22 21:28:07 +00:00
|
|
|
NULL, 0) /* fs type like FAT, NTFS */
|
|
|
|
&& wname[0])
|
2004-01-04 15:45:56 +00:00
|
|
|
{
|
2004-03-22 21:28:07 +00:00
|
|
|
gchar *name = g_utf16_to_utf8 (wname, -1, NULL, NULL, NULL);
|
|
|
|
real_display_name = g_strconcat (name, " (", volume->drive, ")", NULL);
|
2004-03-20 23:45:35 +00:00
|
|
|
g_free (name);
|
2004-01-04 15:45:56 +00:00
|
|
|
}
|
|
|
|
else
|
2004-03-22 21:28:07 +00:00
|
|
|
real_display_name = g_strdup (volume->drive);
|
|
|
|
|
|
|
|
g_free (wdrive);
|
|
|
|
|
|
|
|
return real_display_name;
|
2004-01-04 15:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
gtk_file_system_win32_volume_render_icon (GtkFileSystem *file_system,
|
|
|
|
GtkFileSystemVolume *volume,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint pixel_size,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GtkIconSet *icon_set = NULL;
|
|
|
|
DWORD dt = GetDriveType (volume->drive);
|
|
|
|
|
|
|
|
switch (dt)
|
|
|
|
{
|
|
|
|
case DRIVE_REMOVABLE :
|
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_FLOPPY);
|
|
|
|
break;
|
|
|
|
case DRIVE_CDROM :
|
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_CDROM);
|
|
|
|
break;
|
|
|
|
case DRIVE_REMOTE :
|
2004-01-28 21:46:02 +00:00
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_NETWORK);
|
|
|
|
break;
|
2004-01-04 15:45:56 +00:00
|
|
|
case DRIVE_FIXED :
|
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_HARDDISK);
|
|
|
|
break;
|
|
|
|
case DRIVE_RAMDISK :
|
|
|
|
/*FIXME: need a ram stock icon
|
|
|
|
gtk_file_info_set_icon_type (info, GTK_STOCK_OPEN);*/
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return gtk_icon_set_render_icon (icon_set,
|
|
|
|
widget->style,
|
|
|
|
gtk_widget_get_direction (widget),
|
|
|
|
GTK_STATE_NORMAL,
|
|
|
|
GTK_ICON_SIZE_BUTTON,
|
|
|
|
widget, NULL);
|
|
|
|
}
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
static gboolean
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_get_parent (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GtkFilePath **parent,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
const char *filename;
|
|
|
|
|
|
|
|
filename = gtk_file_path_get_string (path);
|
2003-11-15 20:35:55 +00:00
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
2004-04-22 05:08:19 +00:00
|
|
|
g_return_val_if_fail (g_path_is_absolute (filename), FALSE);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
if (filename_is_some_root (filename))
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
*parent = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *parent_filename = g_path_get_dirname (filename);
|
|
|
|
*parent = filename_to_path (parent_filename);
|
|
|
|
g_free (parent_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFilePath *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_make_path (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *base_path,
|
|
|
|
const gchar *display_name,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-02-28 15:09:27 +00:00
|
|
|
const char *base_filename;
|
2003-11-15 20:35:55 +00:00
|
|
|
gchar *filename;
|
|
|
|
gchar *full_filename;
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
GtkFilePath *result;
|
|
|
|
|
2004-02-28 15:09:27 +00:00
|
|
|
base_filename = gtk_file_path_get_string (base_path);
|
2003-11-15 20:35:55 +00:00
|
|
|
g_return_val_if_fail (base_filename != NULL, NULL);
|
2004-02-28 15:09:27 +00:00
|
|
|
g_return_val_if_fail (g_path_is_absolute (base_filename), NULL);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
filename = g_filename_from_utf8 (display_name, -1, NULL, NULL, &tmp_error);
|
|
|
|
if (!filename)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
|
|
|
|
"%s",
|
|
|
|
tmp_error->message);
|
|
|
|
|
|
|
|
g_error_free (tmp_error);
|
|
|
|
|
2004-01-30 19:49:40 +00:00
|
|
|
return NULL;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
full_filename = g_build_filename (base_filename, filename, NULL);
|
|
|
|
result = filename_to_path (full_filename);
|
|
|
|
g_free (filename);
|
|
|
|
g_free (full_filename);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this was a publically exported function, it should return
|
|
|
|
* a dup'ed result, but we make it modify-in-place for efficiency
|
|
|
|
* here, and because it works for us.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
canonicalize_filename (gchar *filename)
|
|
|
|
{
|
|
|
|
gchar *p, *q;
|
2004-04-22 05:08:19 +00:00
|
|
|
gchar *past_root;
|
2003-11-15 20:35:55 +00:00
|
|
|
gboolean last_was_slash = FALSE;
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
#if 0
|
|
|
|
printf("canonicalize_filename: %s ", filename);
|
|
|
|
#endif
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
p = filename;
|
|
|
|
q = filename;
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
if (g_ascii_isalpha (*filename) &&
|
|
|
|
filename[1] == ':' &&
|
|
|
|
G_IS_DIR_SEPARATOR (filename[2]))
|
|
|
|
past_root = filename + 3;
|
|
|
|
else
|
|
|
|
past_root = filename + 1;
|
|
|
|
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
while (*p)
|
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
if (G_IS_DIR_SEPARATOR (*p))
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
if (!last_was_slash)
|
|
|
|
*q++ = G_DIR_SEPARATOR;
|
|
|
|
|
|
|
|
last_was_slash = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (last_was_slash && *p == '.')
|
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
if (G_IS_DIR_SEPARATOR (*(p + 1)) ||
|
2003-11-15 20:35:55 +00:00
|
|
|
*(p + 1) == '\0')
|
|
|
|
{
|
|
|
|
if (*(p + 1) == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
else if (*(p + 1) == '.' &&
|
2004-04-22 05:08:19 +00:00
|
|
|
(G_IS_DIR_SEPARATOR (*(p + 2)) ||
|
2003-11-15 20:35:55 +00:00
|
|
|
*(p + 2) == '\0'))
|
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
if (q > past_root)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
q--;
|
2004-04-22 05:08:19 +00:00
|
|
|
while (q > past_root &&
|
|
|
|
!G_IS_DIR_SEPARATOR (*(q - 1)))
|
2003-11-15 20:35:55 +00:00
|
|
|
q--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*(p + 2) == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*q++ = *p;
|
|
|
|
last_was_slash = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*q++ = *p;
|
|
|
|
last_was_slash = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
if (q > past_root && G_IS_DIR_SEPARATOR (*(q - 1)))
|
2003-11-15 20:35:55 +00:00
|
|
|
q--;
|
|
|
|
|
|
|
|
*q = '\0';
|
2004-04-22 05:08:19 +00:00
|
|
|
#if 0
|
|
|
|
printf(" => %s\n", filename);
|
|
|
|
#endif
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_parse (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *base_path,
|
|
|
|
const gchar *str,
|
|
|
|
GtkFilePath **folder,
|
|
|
|
gchar **file_part,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-02-28 15:09:27 +00:00
|
|
|
const char *base_filename;
|
2004-04-22 05:08:19 +00:00
|
|
|
gchar *last_backslash, *last_slash;
|
2003-11-15 20:35:55 +00:00
|
|
|
gboolean result = FALSE;
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
#if 0
|
|
|
|
printf("gtk_file_system_win32_parse: base_path=%s str=%s\n",(char*)base_path,str);
|
|
|
|
#endif
|
|
|
|
|
2004-02-28 15:09:27 +00:00
|
|
|
base_filename = gtk_file_path_get_string (base_path);
|
2003-11-15 20:35:55 +00:00
|
|
|
g_return_val_if_fail (base_filename != NULL, FALSE);
|
2004-02-28 15:09:27 +00:00
|
|
|
g_return_val_if_fail (g_path_is_absolute (base_filename), FALSE);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
last_backslash = strrchr (str, G_DIR_SEPARATOR);
|
|
|
|
last_slash = strrchr (str, '/');
|
|
|
|
if (last_slash == NULL ||
|
|
|
|
(last_backslash != NULL && last_backslash > last_slash))
|
|
|
|
last_slash = last_backslash;
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
if (!last_slash)
|
|
|
|
{
|
|
|
|
*folder = gtk_file_path_copy (base_path);
|
|
|
|
*file_part = g_strdup (str);
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *folder_part;
|
|
|
|
gchar *folder_path;
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
|
|
|
|
if (last_slash == str)
|
2004-04-22 05:08:19 +00:00
|
|
|
{
|
|
|
|
if (g_ascii_isalpha (base_filename[0]) &&
|
|
|
|
base_filename[1] == ':')
|
|
|
|
folder_part = g_strdup_printf ("%c:%c", base_filename[0],
|
|
|
|
G_DIR_SEPARATOR);
|
|
|
|
else
|
|
|
|
folder_part = g_strdup (G_DIR_SEPARATOR_S);
|
|
|
|
}
|
|
|
|
else if (g_ascii_isalpha (str[0]) &&
|
|
|
|
str[1] == ':' &&
|
|
|
|
G_IS_DIR_SEPARATOR (str[2]))
|
|
|
|
folder_part = g_filename_from_utf8 (str, last_slash - str + 1,
|
|
|
|
NULL, NULL, &tmp_error);
|
2003-11-15 20:35:55 +00:00
|
|
|
else
|
|
|
|
folder_part = g_filename_from_utf8 (str, last_slash - str,
|
|
|
|
NULL, NULL, &tmp_error);
|
|
|
|
|
|
|
|
if (!folder_part)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
|
|
|
|
"%s",
|
|
|
|
tmp_error->message);
|
|
|
|
g_error_free (tmp_error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
if (g_path_is_absolute (folder_part))
|
2003-11-15 20:35:55 +00:00
|
|
|
folder_path = folder_part;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
folder_path = g_build_filename (base_filename, folder_part, NULL);
|
|
|
|
g_free (folder_part);
|
|
|
|
}
|
|
|
|
|
|
|
|
canonicalize_filename (folder_path);
|
|
|
|
|
|
|
|
*folder = filename_to_path (folder_path);
|
|
|
|
*file_part = g_strdup (last_slash + 1);
|
|
|
|
|
|
|
|
g_free (folder_path);
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
#if 0
|
|
|
|
printf("gtk_file_system_win32_parse:returning folder=%s file_part=%s\n",(*folder?(char*)*folder:"NULL"),*file_part);
|
|
|
|
#endif
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_path_to_uri (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
return g_filename_to_uri (gtk_file_path_get_string (path), NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_path_to_filename (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
return g_strdup (gtk_file_path_get_string (path));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFilePath *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_uri_to_path (GtkFileSystem *file_system,
|
|
|
|
const gchar *uri)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-08-06 19:20:42 +00:00
|
|
|
GtkFilePath *path = NULL;
|
2003-11-15 20:35:55 +00:00
|
|
|
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
|
|
|
|
if (filename)
|
2004-08-06 19:20:42 +00:00
|
|
|
{
|
|
|
|
path = filename_to_path (filename);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFilePath *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_filename_to_path (GtkFileSystem *file_system,
|
|
|
|
const gchar *filename)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-08-06 19:20:42 +00:00
|
|
|
return filename_to_path (filename);
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
bookmarks_serialize (GSList **bookmarks,
|
|
|
|
gchar *uri,
|
|
|
|
gboolean add,
|
2004-02-28 15:09:27 +00:00
|
|
|
gint position,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
gboolean ok = TRUE;
|
|
|
|
GSList *list = *bookmarks;
|
|
|
|
|
|
|
|
filename = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
gchar *contents = NULL;
|
|
|
|
gsize len = 0;
|
2003-12-14 19:03:02 +00:00
|
|
|
GSList *entry;
|
2003-11-15 20:35:55 +00:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
if (g_file_get_contents (filename, &contents, &len, error))
|
|
|
|
{
|
|
|
|
gchar **lines = g_strsplit (contents, "\n", -1);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; lines[i] != NULL; i++)
|
|
|
|
{
|
2004-02-28 23:36:11 +00:00
|
|
|
if (lines[i][0] && !g_slist_find_custom (list, lines[i], (GCompareFunc) strcmp))
|
2003-11-15 20:35:55 +00:00
|
|
|
list = g_slist_append (list, g_strdup (lines[i]));
|
|
|
|
}
|
|
|
|
g_strfreev (lines);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok = FALSE;
|
|
|
|
}
|
|
|
|
if (ok && (f = fopen (filename, "wb")) != NULL)
|
|
|
|
{
|
2004-03-22 21:28:07 +00:00
|
|
|
entry = g_slist_find_custom (list, uri, (GCompareFunc) strcmp);
|
2004-02-28 15:09:27 +00:00
|
|
|
if (add)
|
|
|
|
{
|
|
|
|
/* g_slist_insert() and our insert semantics are
|
|
|
|
* compatible, but maybe we should check for
|
|
|
|
* positon > length ?
|
|
|
|
*
|
|
|
|
*/
|
2004-03-22 21:28:07 +00:00
|
|
|
if (!entry)
|
2004-02-28 15:09:27 +00:00
|
|
|
list = g_slist_insert (list, g_strdup (uri), position);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS,
|
|
|
|
"%s already exists in the bookmarks list",
|
|
|
|
uri);
|
|
|
|
ok = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2004-03-22 21:28:07 +00:00
|
|
|
else
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-03-22 21:28:07 +00:00
|
|
|
/* to remove the given uri */
|
|
|
|
if (entry)
|
|
|
|
list = g_slist_delete_link(list, entry);
|
|
|
|
for (entry = list; entry != NULL; entry = entry->next)
|
|
|
|
{
|
|
|
|
fputs (entry->data, f);
|
2003-11-15 20:35:55 +00:00
|
|
|
fputs ("\n", f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose (f);
|
|
|
|
}
|
|
|
|
else if (ok && error)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_FAILED,
|
|
|
|
_("Bookmark saving failed (%s)"),
|
|
|
|
g_strerror (errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*bookmarks = list;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2003-12-14 19:03:02 +00:00
|
|
|
static GdkPixbuf*
|
|
|
|
extract_icon (const char* filename)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
WORD iicon;
|
|
|
|
HICON hicon;
|
2004-05-08 16:25:15 +00:00
|
|
|
char filename_copy[MAX_PATH];
|
2003-12-14 19:03:02 +00:00
|
|
|
|
|
|
|
if (!filename || !filename[0])
|
|
|
|
return NULL;
|
|
|
|
|
2004-05-08 16:25:15 +00:00
|
|
|
/* the ugly ExtractAssociatedIcon modifies filename in place - at least on win98 */
|
|
|
|
strcpy(filename_copy, filename);
|
|
|
|
hicon = ExtractAssociatedIcon (GetModuleHandle (NULL), filename_copy, &iicon);
|
2003-12-14 19:03:02 +00:00
|
|
|
if (hicon > (HICON)1)
|
|
|
|
{
|
|
|
|
ICONINFO ii;
|
|
|
|
|
|
|
|
if (GetIconInfo (hicon, &ii))
|
|
|
|
{
|
2004-05-08 16:25:15 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
BITMAPINFOHEADER bi;
|
|
|
|
RGBQUAD colors[2];
|
|
|
|
} bmi;
|
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
memset (&bmi, 0, sizeof (bmi));
|
|
|
|
bmi.bi.biSize = sizeof (bmi.bi);
|
|
|
|
hdc = CreateCompatibleDC (NULL);
|
|
|
|
|
|
|
|
if (GetDIBits (hdc, ii.hbmColor, 0, 1, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))
|
|
|
|
{
|
|
|
|
gchar *pixels, *bits;
|
|
|
|
gint rowstride, x, y, w = bmi.bi.biWidth, h = bmi.bi.biHeight;
|
|
|
|
|
|
|
|
bmi.bi.biBitCount = 24;
|
|
|
|
bmi.bi.biCompression = BI_RGB;
|
|
|
|
bmi.bi.biHeight = -h;
|
|
|
|
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
|
|
|
|
bits = g_malloc (4 * w * h);
|
|
|
|
|
|
|
|
/* color data */
|
|
|
|
if (!GetDIBits (hdc, ii.hbmColor, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))
|
|
|
|
g_warning(G_STRLOC ": Failed to get dibits");
|
|
|
|
|
|
|
|
pixels = gdk_pixbuf_get_pixels (pixbuf);
|
|
|
|
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
|
|
|
for (y = 0; y < h; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
{
|
|
|
|
pixels[2] = bits[(x+y*w) * 3];
|
|
|
|
pixels[1] = bits[(x+y*w) * 3 + 1];
|
|
|
|
pixels[0] = bits[(x+y*w) * 3 + 2];
|
|
|
|
pixels += 4;
|
|
|
|
}
|
|
|
|
pixels += (w * 4 - rowstride);
|
|
|
|
}
|
|
|
|
/* transparency */
|
|
|
|
if (!GetDIBits (hdc, ii.hbmMask, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))
|
|
|
|
g_warning(G_STRLOC ": Failed to get dibits");
|
|
|
|
pixels = gdk_pixbuf_get_pixels (pixbuf);
|
|
|
|
for (y = 0; y < h; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
{
|
|
|
|
pixels[3] = 255 - bits[(x + y * w) * 3];
|
|
|
|
pixels += 4;
|
|
|
|
}
|
|
|
|
pixels += (w * 4 - rowstride);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release temporary resources */
|
|
|
|
g_free (bits);
|
|
|
|
if (!DeleteObject (ii.hbmColor) || !DeleteObject (ii.hbmMask))
|
|
|
|
g_warning(G_STRLOC ": Leaking Icon Bitmaps ?");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning(G_STRLOC ": GetDIBits () failed, %s", g_win32_error_message (GetLastError ()));
|
|
|
|
|
|
|
|
DeleteDC (hdc);
|
2003-12-14 19:03:02 +00:00
|
|
|
}
|
|
|
|
else
|
2004-05-08 16:25:15 +00:00
|
|
|
g_warning(G_STRLOC ": GetIconInfo failed: %s\n", g_win32_error_message (GetLastError ()));
|
2003-12-14 19:03:02 +00:00
|
|
|
|
|
|
|
if (!DestroyIcon (hicon))
|
2004-05-08 16:25:15 +00:00
|
|
|
g_warning(G_STRLOC ": DestroyIcon failed");
|
2003-12-14 19:03:02 +00:00
|
|
|
}
|
|
|
|
else
|
2004-05-08 16:25:15 +00:00
|
|
|
g_print ("ExtractAssociatedIcon(%s) failed: %s\n", filename, g_win32_error_message (GetLastError ()));
|
2003-12-14 19:03:02 +00:00
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkIconSet *
|
|
|
|
win32_pseudo_mime_lookup (const char* name)
|
|
|
|
{
|
|
|
|
static GHashTable *mime_hash = NULL;
|
|
|
|
GtkIconSet *is = NULL;
|
|
|
|
char *p = strrchr(name, '.');
|
|
|
|
char *extension = p ? g_ascii_strdown (p, -1) : g_strdup ("");
|
|
|
|
|
|
|
|
if (!mime_hash)
|
|
|
|
mime_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
|
|
/* do we already have it ? */
|
|
|
|
is = g_hash_table_lookup (mime_hash, extension);
|
|
|
|
if (is)
|
|
|
|
{
|
|
|
|
g_free (extension);
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
/* create icon and set */
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf = extract_icon (name);
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
GtkIconSource* source = gtk_icon_source_new ();
|
|
|
|
|
|
|
|
is = gtk_icon_set_new_from_pixbuf (pixbuf);
|
|
|
|
gtk_icon_source_set_pixbuf (source, pixbuf);
|
|
|
|
gtk_icon_set_add_source (is, source);
|
|
|
|
|
|
|
|
gtk_icon_source_free (source);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_insert (mime_hash, extension, is);
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
gtk_file_system_win32_render_icon (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint pixel_size,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GtkIconSet *icon_set = NULL;
|
|
|
|
const char* filename = gtk_file_path_get_string (path);
|
|
|
|
|
|
|
|
/* handle drives with stock icons */
|
2004-04-22 05:08:19 +00:00
|
|
|
if (filename_is_drive_root (filename))
|
2003-12-14 19:03:02 +00:00
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
gchar filename2[] = "?:\\";
|
|
|
|
DWORD dt;
|
|
|
|
|
|
|
|
filename2[0] = filename[0];
|
|
|
|
dt = GetDriveType (filename2);
|
2003-12-14 19:03:02 +00:00
|
|
|
|
|
|
|
switch (dt)
|
|
|
|
{
|
|
|
|
case DRIVE_REMOVABLE :
|
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_FLOPPY);
|
|
|
|
break;
|
|
|
|
case DRIVE_CDROM :
|
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_CDROM);
|
|
|
|
break;
|
2004-05-08 16:25:15 +00:00
|
|
|
case DRIVE_FIXED :
|
2004-01-04 15:45:56 +00:00
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_HARDDISK);
|
2003-12-14 19:03:02 +00:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (g_file_test (filename, G_FILE_TEST_IS_DIR))
|
|
|
|
{
|
|
|
|
if (0 == strcmp (g_get_home_dir(), filename))
|
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_HOME);
|
|
|
|
else
|
2004-08-06 19:20:42 +00:00
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_DIRECTORY);
|
2003-12-14 19:03:02 +00:00
|
|
|
}
|
|
|
|
else if (g_file_test (filename, G_FILE_TEST_IS_EXECUTABLE))
|
|
|
|
{
|
|
|
|
/* don't lookup all executable icons */
|
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_EXECUTE);
|
|
|
|
}
|
|
|
|
else if (g_file_test (filename, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
icon_set = win32_pseudo_mime_lookup (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!icon_set)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_FAILED,
|
|
|
|
_("This file system does not support icons for everything"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME : I'd like to get from pixel_size (=20) back to
|
|
|
|
// icon size, which is an index, but there appears to be no way ?
|
|
|
|
return gtk_icon_set_render_icon (icon_set,
|
|
|
|
widget->style,
|
|
|
|
gtk_widget_get_direction (widget),
|
|
|
|
GTK_STATE_NORMAL,
|
|
|
|
GTK_ICON_SIZE_BUTTON,
|
|
|
|
widget, NULL);
|
|
|
|
}
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
static GSList *_bookmarks = NULL;
|
|
|
|
|
|
|
|
static gboolean
|
2004-02-28 15:09:27 +00:00
|
|
|
gtk_file_system_win32_insert_bookmark (GtkFileSystem *file_system,
|
2003-12-08 23:13:14 +00:00
|
|
|
const GtkFilePath *path,
|
2004-02-28 15:09:27 +00:00
|
|
|
gint position,
|
2003-12-08 23:13:14 +00:00
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
gchar *uri = gtk_file_system_win32_path_to_uri (file_system, path);
|
2004-02-28 15:09:27 +00:00
|
|
|
gboolean ret = bookmarks_serialize (&_bookmarks, uri, TRUE, position, error);
|
|
|
|
if (ret)
|
|
|
|
g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
|
2003-11-15 20:35:55 +00:00
|
|
|
g_free (uri);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_remove_bookmark (GtkFileSystem *file_system,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
gchar *uri = gtk_file_system_win32_path_to_uri (file_system, path);
|
2004-02-28 15:09:27 +00:00
|
|
|
gboolean ret = bookmarks_serialize (&_bookmarks, uri, FALSE, 0, error);
|
|
|
|
if (ret)
|
|
|
|
g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
|
2003-11-15 20:35:55 +00:00
|
|
|
g_free (uri);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_system_win32_list_bookmarks (GtkFileSystem *file_system)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
GSList *list = NULL;
|
|
|
|
GSList *entry;
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
|
2004-02-28 15:09:27 +00:00
|
|
|
if (bookmarks_serialize (&_bookmarks, "", FALSE, 0, NULL))
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
for (entry = _bookmarks; entry != NULL; entry = entry->next)
|
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
GtkFilePath *path = gtk_file_system_win32_uri_to_path (
|
2003-11-15 20:35:55 +00:00
|
|
|
file_system, (gchar *)entry->data);
|
|
|
|
|
|
|
|
list = g_slist_append (list, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-12-08 23:13:14 +00:00
|
|
|
* GtkFileFolderWin32
|
2003-11-15 20:35:55 +00:00
|
|
|
*/
|
|
|
|
static GType
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_folder_win32_get_type (void)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
static GType file_folder_win32_type = 0;
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
if (!file_folder_win32_type)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
static const GTypeInfo file_folder_win32_info =
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
sizeof (GtkFileFolderWin32Class),
|
2003-11-15 20:35:55 +00:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2003-12-08 23:13:14 +00:00
|
|
|
(GClassInitFunc) gtk_file_folder_win32_class_init,
|
2003-11-15 20:35:55 +00:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2003-12-08 23:13:14 +00:00
|
|
|
sizeof (GtkFileFolderWin32),
|
2003-11-15 20:35:55 +00:00
|
|
|
0, /* n_preallocs */
|
2003-12-08 23:13:14 +00:00
|
|
|
(GInstanceInitFunc) gtk_file_folder_win32_init,
|
2003-11-15 20:35:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const GInterfaceInfo file_folder_info =
|
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
(GInterfaceInitFunc) gtk_file_folder_win32_iface_init, /* interface_init */
|
2003-11-15 20:35:55 +00:00
|
|
|
NULL, /* interface_finalize */
|
|
|
|
NULL /* interface_data */
|
|
|
|
};
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
file_folder_win32_type = g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"GtkFileFolderWin32",
|
|
|
|
&file_folder_win32_info, 0);
|
|
|
|
g_type_add_interface_static (file_folder_win32_type,
|
2003-11-15 20:35:55 +00:00
|
|
|
GTK_TYPE_FILE_FOLDER,
|
|
|
|
&file_folder_info);
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
return file_folder_win32_type;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_folder_win32_class_init (GtkFileFolderWin32Class *class)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
folder_parent_class = g_type_class_peek_parent (class);
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
gobject_class->finalize = gtk_file_folder_win32_finalize;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_folder_win32_iface_init (GtkFileFolderIface *iface)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
iface->get_info = gtk_file_folder_win32_get_info;
|
|
|
|
iface->list_children = gtk_file_folder_win32_list_children;
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_folder_win32_init (GtkFileFolderWin32 *impl)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_folder_win32_finalize (GObject *object)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
GtkFileFolderWin32 *folder_win32 = GTK_FILE_FOLDER_WIN32 (object);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2004-03-24 17:22:36 +00:00
|
|
|
g_hash_table_remove (folder_win32->system_win32->folder_hash, folder_win32->filename);
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
g_free (folder_win32->filename);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
folder_parent_class->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFileInfo *
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_folder_win32_get_info (GtkFileFolder *folder,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
GtkFileFolderWin32 *folder_win32 = GTK_FILE_FOLDER_WIN32 (folder);
|
2003-11-15 20:35:55 +00:00
|
|
|
GtkFileInfo *info;
|
|
|
|
gchar *dirname;
|
|
|
|
gchar *filename;
|
|
|
|
|
2004-03-20 23:45:35 +00:00
|
|
|
if (!path)
|
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
g_return_val_if_fail (filename_is_some_root (folder_win32->filename), NULL);
|
2004-03-20 23:45:35 +00:00
|
|
|
|
|
|
|
/* ??? */
|
|
|
|
info = filename_get_info (folder_win32->filename, folder_win32->types, error);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2003-11-15 20:35:55 +00:00
|
|
|
filename = filename_from_path (path);
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
dirname = g_path_get_dirname (filename);
|
2003-12-08 23:13:14 +00:00
|
|
|
g_return_val_if_fail (strcmp (dirname, folder_win32->filename) == 0, NULL);
|
2003-11-15 20:35:55 +00:00
|
|
|
g_free (dirname);
|
|
|
|
#endif
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
info = filename_get_info (filename, folder_win32->types, error);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-12-08 23:13:14 +00:00
|
|
|
gtk_file_folder_win32_list_children (GtkFileFolder *folder,
|
|
|
|
GSList **children,
|
|
|
|
GError **error)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
GtkFileFolderWin32 *folder_win32 = GTK_FILE_FOLDER_WIN32 (folder);
|
2003-11-15 20:35:55 +00:00
|
|
|
GError *tmp_error = NULL;
|
|
|
|
GDir *dir;
|
|
|
|
|
|
|
|
*children = NULL;
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
dir = g_dir_open (folder_win32->filename, 0, &tmp_error);
|
2003-11-15 20:35:55 +00:00
|
|
|
if (!dir)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
|
|
|
|
"%s",
|
|
|
|
tmp_error->message);
|
|
|
|
|
|
|
|
g_error_free (tmp_error);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
const gchar *filename = g_dir_read_name (dir);
|
|
|
|
gchar *fullname;
|
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
break;
|
|
|
|
|
2003-12-08 23:13:14 +00:00
|
|
|
fullname = g_build_filename (folder_win32->filename, filename, NULL);
|
2003-11-15 20:35:55 +00:00
|
|
|
*children = g_slist_prepend (*children, filename_to_path (fullname));
|
|
|
|
g_free (fullname);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_dir_close (dir);
|
|
|
|
|
|
|
|
*children = g_slist_reverse (*children);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFileInfo *
|
|
|
|
filename_get_info (const gchar *filename,
|
|
|
|
GtkFileInfoType types,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GtkFileInfo *info;
|
2003-12-14 19:03:02 +00:00
|
|
|
#if 0 /* it's dead in GtkFileSystemUnix.c, too */
|
2003-11-15 20:35:55 +00:00
|
|
|
GtkFileIconType icon_type = GTK_FILE_ICON_REGULAR;
|
2003-12-14 19:03:02 +00:00
|
|
|
#endif
|
2003-11-15 20:35:55 +00:00
|
|
|
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
|
|
|
|
|
|
|
if (!GetFileAttributesEx (filename, GetFileExInfoStandard, &wfad))
|
|
|
|
{
|
|
|
|
gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_SYSTEM_ERROR,
|
|
|
|
GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
|
|
|
|
_("error getting information for '%s': %s"),
|
|
|
|
filename_utf8 ? filename_utf8 : "???",
|
|
|
|
g_win32_error_message (GetLastError ()));
|
|
|
|
g_free (filename_utf8);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = gtk_file_info_new ();
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
if (filename_is_some_root (filename))
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
if (types & GTK_FILE_INFO_DISPLAY_NAME)
|
|
|
|
gtk_file_info_set_display_name (info, filename);
|
|
|
|
|
|
|
|
if (types & GTK_FILE_INFO_IS_HIDDEN)
|
|
|
|
gtk_file_info_set_is_hidden (info, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *basename = g_path_get_basename (filename);
|
|
|
|
|
|
|
|
if (types & GTK_FILE_INFO_DISPLAY_NAME)
|
|
|
|
{
|
|
|
|
gchar *display_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
|
|
|
|
if (!display_name)
|
|
|
|
display_name = g_strescape (basename, NULL);
|
|
|
|
|
|
|
|
gtk_file_info_set_display_name (info, display_name);
|
|
|
|
|
|
|
|
g_free (display_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types & GTK_FILE_INFO_IS_HIDDEN)
|
|
|
|
{
|
2003-12-08 23:13:14 +00:00
|
|
|
/* win32 convention ... */
|
2003-11-15 20:35:55 +00:00
|
|
|
gboolean is_hidden = basename[0] == '.';
|
|
|
|
/* ... _and_ windoze attribute */
|
|
|
|
is_hidden = is_hidden || !!(wfad.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
|
|
|
|
gtk_file_info_set_is_hidden (info, is_hidden);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (basename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types & GTK_FILE_INFO_IS_FOLDER)
|
|
|
|
{
|
|
|
|
gtk_file_info_set_is_folder (info, !!(wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
|
|
|
|
}
|
|
|
|
|
2003-12-14 19:03:02 +00:00
|
|
|
#if 0 /* it's dead in GtkFileSystemUnix.c, too */
|
2003-11-15 20:35:55 +00:00
|
|
|
if (types & GTK_FILE_INFO_ICON)
|
|
|
|
{
|
|
|
|
if (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
icon_type = GTK_FILE_ICON_DIRECTORY;
|
|
|
|
|
|
|
|
gtk_file_info_set_icon_type (info, icon_type);
|
|
|
|
}
|
2003-12-14 19:03:02 +00:00
|
|
|
#endif
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-12-14 19:03:02 +00:00
|
|
|
if ((types & GTK_FILE_INFO_MIME_TYPE)
|
|
|
|
#if 0 /* it's dead in GtkFileSystemUnix.c, too */
|
|
|
|
|| ((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR)
|
|
|
|
#endif
|
|
|
|
)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
const char *mime_type = xdg_mime_get_mime_type_for_file (filename);
|
|
|
|
gtk_file_info_set_mime_type (info, mime_type);
|
|
|
|
|
|
|
|
if ((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR &&
|
|
|
|
(statbuf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) &&
|
|
|
|
(strcmp (mime_type, XDG_MIME_TYPE_UNKNOWN) == 0 ||
|
|
|
|
strcmp (mime_type, "application/x-executable") == 0 ||
|
|
|
|
strcmp (mime_type, "application/x-shellscript") == 0))
|
|
|
|
gtk_file_info_set_icon_type (info, GTK_FILE_ICON_EXECUTABLE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types & GTK_FILE_INFO_MODIFICATION_TIME)
|
|
|
|
{
|
|
|
|
GtkFileTime time = wfad.ftLastWriteTime.dwLowDateTime
|
|
|
|
| ((guint64)wfad.ftLastWriteTime.dwHighDateTime) << 32;
|
|
|
|
/* 100-nanosecond intervals since January 1, 1601, urgh! */
|
2004-02-28 23:36:11 +00:00
|
|
|
time /= G_GINT64_CONSTANT (10000000); /* now seconds */
|
|
|
|
time -= G_GINT64_CONSTANT (134774) * 24 * 3600; /* good old Unix time */
|
2003-11-15 20:35:55 +00:00
|
|
|
gtk_file_info_set_modification_time (info, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types & GTK_FILE_INFO_SIZE)
|
|
|
|
{
|
|
|
|
gint64 size = wfad.nFileSizeLow | ((guint64)wfad.nFileSizeHigh) << 32;
|
|
|
|
gtk_file_info_set_size (info, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
filename_from_path (const GtkFilePath *path)
|
|
|
|
{
|
|
|
|
return g_strdup (gtk_file_path_get_string (path));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkFilePath *
|
|
|
|
filename_to_path (const char *filename)
|
|
|
|
{
|
|
|
|
return gtk_file_path_new_dup (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-04-22 05:08:19 +00:00
|
|
|
filename_is_drive_root (const char *filename)
|
2003-11-15 20:35:55 +00:00
|
|
|
{
|
2004-04-22 05:08:19 +00:00
|
|
|
guint len = strlen (filename);
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
/* accept both forms */
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
return (len == 3 && filename[1] == ':' && G_IS_DIR_SEPARATOR (filename[2]));
|
2003-11-15 20:35:55 +00:00
|
|
|
}
|
|
|
|
|
2004-04-22 05:08:19 +00:00
|
|
|
static gboolean
|
|
|
|
filename_is_some_root (const char *filename)
|
|
|
|
{
|
|
|
|
return (G_IS_DIR_SEPARATOR (filename[0]) && filename[1] == '\0') ||
|
|
|
|
filename_is_drive_root (filename);
|
|
|
|
}
|