/* GTK - The GIMP Toolkit
* gtkfilesystemwin32.c: Default implementation of GtkFileSystem for Windows
* Copyright (C) 2003, Red Hat, Inc.
+ * Copyright (C) 2004, Hans Breuer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Boston, MA 02111-1307, USA.
*/
+#include <config.h>
+#include "gtkalias.h"
#include "gtkfilesystem.h"
#include "gtkfilesystemwin32.h"
#include "gtkintl.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <sys/types.h>
#ifdef G_OS_WIN32
#define mkdir(p,m) _mkdir(p)
#include <gdk/win32/gdkwin32.h> /* gdk_win32_hdc_get */
#else
-#error "The implementation is win32 only yet."
+#error "The implementation is win32 only."
#endif /* G_OS_WIN32 */
+#ifndef G_IS_DIR_SEPARATOR
+#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
+#endif
+
typedef struct _GtkFileSystemWin32Class GtkFileSystemWin32Class;
#define GTK_FILE_SYSTEM_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_SYSTEM_WIN32, GtkFileSystemWin32Class))
struct _GtkFileSystemWin32
{
GObject parent_instance;
+
+ GHashTable *folder_hash;
};
#define GTK_TYPE_FILE_FOLDER_WIN32 (gtk_file_folder_win32_get_type ())
{
GObject parent_instance;
+ GtkFileSystemWin32 *system_win32;
GtkFileInfoType types;
gchar *filename;
};
gint pixel_size,
GError **error);
-static gboolean gtk_file_system_win32_add_bookmark (GtkFileSystem *file_system,
+static gboolean gtk_file_system_win32_insert_bookmark (GtkFileSystem *file_system,
const GtkFilePath *path,
+ gint position,
GError **error);
static gboolean gtk_file_system_win32_remove_bookmark (GtkFileSystem *file_system,
const GtkFilePath *path,
static gchar * filename_from_path (const GtkFilePath *path);
static GtkFilePath * filename_to_path (const gchar *filename);
-static gboolean filename_is_root (const char *filename);
+static gboolean filename_is_drive_root (const char *filename);
+static gboolean filename_is_some_root (const char *filename);
static GtkFileInfo * filename_get_info (const gchar *filename,
GtkFileInfoType types,
GError **error);
iface->uri_to_path = gtk_file_system_win32_uri_to_path;
iface->filename_to_path = gtk_file_system_win32_filename_to_path;
iface->render_icon = gtk_file_system_win32_render_icon;
- iface->add_bookmark = gtk_file_system_win32_add_bookmark;
+ iface->insert_bookmark = gtk_file_system_win32_insert_bookmark;
iface->remove_bookmark = gtk_file_system_win32_remove_bookmark;
iface->list_bookmarks = gtk_file_system_win32_list_bookmarks;
}
static void
gtk_file_system_win32_init (GtkFileSystemWin32 *system_win32)
{
+ system_win32->folder_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
static void
gtk_file_system_win32_finalize (GObject *object)
{
+ 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);
+
system_parent_class->finalize (object);
}
static GSList *
gtk_file_system_win32_list_volumes (GtkFileSystem *file_system)
{
- gchar drives[26*4];
- guint len;
- gchar *p;
+ DWORD drives;
+ gchar drive[4] = "A:\\";
GSList *list = NULL;
- len = GetLogicalDriveStrings(sizeof(drives), drives);
+ drives = GetLogicalDrives();
- if (len < 3)
- g_warning("No drive strings available!");
+ if (!drives)
+ g_warning ("GetLogicalDrives failed.");
- p = drives;
- while ((len = strlen(p)) != 0)
+ while (drives && drive[0] <= 'Z')
{
- GtkFileSystemVolume *vol = g_new0 (GtkFileSystemVolume, 1);
- if (p[0] == 'a' || p[0] == 'b')
- vol->is_mounted = FALSE; /* skip floppy */
- else
- vol->is_mounted = TRUE;
-
- /*FIXME: gtk_file_path_compare() is case sensitive, we are not*/
- p[0] = toupper (p[0]);
- vol->drive = g_strdup (p);
-
- list = g_slist_append (list, vol);
-
- p += len + 1;
+ 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]++;
}
return list;
}
const GtkFilePath *path)
{
GtkFileSystemVolume *vol = g_new0 (GtkFileSystemVolume, 1);
- gchar* p = g_strndup (path, 3);
+ gchar* p = g_strndup (gtk_file_path_get_string (path), 3);
g_return_val_if_fail (p != NULL, NULL);
/*FIXME: gtk_file_path_compare() is case sensitive, we are not*/
- p[0] = toupper (p[0]);
+ p[0] = g_ascii_toupper (p[0]);
vol->drive = p;
- vol->is_mounted = (p[0] != 'a' && p[0] != 'b');
+ vol->is_mounted = (p[0] != 'A' && p[0] != 'B');
return vol;
}
GtkFileInfoType types,
GError **error)
{
+ GtkFileSystemWin32 *system_win32;
GtkFileFolderWin32 *folder_win32;
gchar *filename;
+ system_win32 = GTK_FILE_SYSTEM_WIN32 (file_system);
+
filename = filename_from_path (path);
g_return_val_if_fail (filename != NULL, NULL);
+ folder_win32 = g_hash_table_lookup (system_win32->folder_hash, filename);
+
+ if (folder_win32)
+ return g_object_ref (folder_win32);
+
+ 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;
+ }
+
folder_win32 = g_object_new (GTK_TYPE_FILE_FOLDER_WIN32, NULL);
+ folder_win32->system_win32 = system_win32;
folder_win32->filename = filename;
folder_win32->types = types;
+ g_hash_table_insert (system_win32->folder_hash, folder_win32->filename, folder_win32);
+
return GTK_FILE_FOLDER (folder_win32);
}
const GtkFilePath *path,
GError **error)
{
+ GtkFileSystemWin32 *system_win32;
gchar *filename;
gboolean result;
+ char *parent;
+
+ system_win32 = GTK_FILE_SYSTEM_WIN32 (file_system);
filename = filename_from_path (path);
g_return_val_if_fail (filename != NULL, FALSE);
-
- result = mkdir (filename, 0777) != 0;
-
+
+ result = mkdir (filename, 0777) == 0;
+
if (!result)
{
gchar *filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
g_strerror (errno));
g_free (filename_utf8);
}
-
+ else if (!filename_is_drive_root (filename))
+ {
+ 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);
+ }
+ }
+
g_free (filename);
-
+
return result;
}
gtk_file_system_win32_volume_get_base_path (GtkFileSystem *file_system,
GtkFileSystemVolume *volume)
{
- return (GtkFilePath *) g_strndup (volume->drive, 2);
+ return (GtkFilePath *) g_strdup (volume->drive);
}
static gboolean
gtk_file_system_win32_volume_get_display_name (GtkFileSystem *file_system,
GtkFileSystemVolume *volume)
{
- gchar display_name[80];
+ gchar *real_display_name;
+ gunichar2 *wdrive = g_utf8_to_utf16 (volume->drive, -1, NULL, NULL, NULL);
+ gunichar2 wname[80];
+
+ g_return_val_if_fail (wdrive != NULL, NULL);
- if (GetVolumeInformation (volume->drive,
- display_name, sizeof(display_name),
+ if (GetVolumeInformationW (wdrive,
+ wname, G_N_ELEMENTS(wname),
NULL, /* serial number */
NULL, /* max. component length */
NULL, /* fs flags */
- NULL, 0)) /* fs type like FAT, NTFS */
+ NULL, 0) /* fs type like FAT, NTFS */
+ && wname[0])
{
- gchar* real_display_name = g_strconcat (display_name, " (", volume->drive, ")", NULL);
-
- return real_display_name;
+ gchar *name = g_utf16_to_utf8 (wname, -1, NULL, NULL, NULL);
+ real_display_name = g_strconcat (name, " (", volume->drive, ")", NULL);
+ g_free (name);
}
else
- return g_strdup (volume->drive);
+ real_display_name = g_strdup (volume->drive);
+
+ g_free (wdrive);
+
+ return real_display_name;
}
static GdkPixbuf *
GtkFilePath **parent,
GError **error)
{
- gchar *filename = filename_from_path (path);
+ const char *filename;
+
+ filename = gtk_file_path_get_string (path);
g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (g_path_is_absolute (filename), FALSE);
- if (filename_is_root (filename))
+ if (filename_is_some_root (filename))
{
*parent = NULL;
}
g_free (parent_filename);
}
- g_free (filename);
-
return TRUE;
}
const gchar *display_name,
GError **error)
{
- gchar *base_filename;
+ const char *base_filename;
gchar *filename;
gchar *full_filename;
GError *tmp_error = NULL;
GtkFilePath *result;
- base_filename = filename_from_path (base_path);
+ base_filename = gtk_file_path_get_string (base_path);
g_return_val_if_fail (base_filename != NULL, NULL);
+ g_return_val_if_fail (g_path_is_absolute (base_filename), NULL);
filename = g_filename_from_utf8 (display_name, -1, NULL, NULL, &tmp_error);
if (!filename)
tmp_error->message);
g_error_free (tmp_error);
- g_free (base_filename);
return NULL;
}
full_filename = g_build_filename (base_filename, filename, NULL);
result = filename_to_path (full_filename);
- g_free (base_filename);
g_free (filename);
g_free (full_filename);
canonicalize_filename (gchar *filename)
{
gchar *p, *q;
+ gchar *past_root;
gboolean last_was_slash = FALSE;
+#if 0
+ printf("canonicalize_filename: %s ", filename);
+#endif
+
p = filename;
q = filename;
+ if (g_ascii_isalpha (*filename) &&
+ filename[1] == ':' &&
+ G_IS_DIR_SEPARATOR (filename[2]))
+ past_root = filename + 3;
+ else
+ past_root = filename + 1;
+
+
while (*p)
{
- if (*p == G_DIR_SEPARATOR)
+ if (G_IS_DIR_SEPARATOR (*p))
{
if (!last_was_slash)
*q++ = G_DIR_SEPARATOR;
{
if (last_was_slash && *p == '.')
{
- if (*(p + 1) == G_DIR_SEPARATOR ||
+ if (G_IS_DIR_SEPARATOR (*(p + 1)) ||
*(p + 1) == '\0')
{
if (*(p + 1) == '\0')
p += 1;
}
else if (*(p + 1) == '.' &&
- (*(p + 2) == G_DIR_SEPARATOR ||
+ (G_IS_DIR_SEPARATOR (*(p + 2)) ||
*(p + 2) == '\0'))
{
- if (q > filename + 1)
+ if (q > past_root)
{
q--;
- while (q > filename + 1 &&
- *(q - 1) != G_DIR_SEPARATOR)
+ while (q > past_root &&
+ !G_IS_DIR_SEPARATOR (*(q - 1)))
q--;
}
p++;
}
- if (q > filename + 1 && *(q - 1) == G_DIR_SEPARATOR)
+ if (q > past_root && G_IS_DIR_SEPARATOR (*(q - 1)))
q--;
*q = '\0';
+#if 0
+ printf(" => %s\n", filename);
+#endif
}
static gboolean
gchar **file_part,
GError **error)
{
- char *base_filename;
- gchar *last_slash;
+ const char *base_filename;
+ gchar *last_backslash, *last_slash;
gboolean result = FALSE;
- base_filename = filename_from_path (base_path);
+#if 0
+ printf("gtk_file_system_win32_parse: base_path=%s str=%s\n",(char*)base_path,str);
+#endif
+
+ base_filename = gtk_file_path_get_string (base_path);
g_return_val_if_fail (base_filename != NULL, FALSE);
+ g_return_val_if_fail (g_path_is_absolute (base_filename), FALSE);
- last_slash = strrchr (str, G_DIR_SEPARATOR);
+ 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;
+
if (!last_slash)
{
*folder = gtk_file_path_copy (base_path);
GError *tmp_error = NULL;
if (last_slash == str)
- folder_part = g_strdup ("/");
+ {
+ 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);
else
folder_part = g_filename_from_utf8 (str, last_slash - str,
NULL, NULL, &tmp_error);
}
else
{
- if (folder_part[1] == ':')
+ if (g_path_is_absolute (folder_part))
folder_path = folder_part;
else
{
}
}
- g_free (base_filename);
-
+#if 0
+ printf("gtk_file_system_win32_parse:returning folder=%s file_part=%s\n",(*folder?(char*)*folder:"NULL"),*file_part);
+#endif
+
return result;
}
gtk_file_system_win32_uri_to_path (GtkFileSystem *file_system,
const gchar *uri)
{
+ GtkFilePath *path = NULL;
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
if (filename)
- return gtk_file_path_new_steal (filename);
- else
- return NULL;
+ {
+ path = filename_to_path (filename);
+ g_free (filename);
+ }
+
+ return path;
}
static GtkFilePath *
gtk_file_system_win32_filename_to_path (GtkFileSystem *file_system,
const gchar *filename)
{
- return gtk_file_path_new_dup (filename);
+ return filename_to_path (filename);
}
static gboolean
bookmarks_serialize (GSList **bookmarks,
gchar *uri,
gboolean add,
- GError **error)
+ gint position,
+ GError **error)
{
gchar *filename;
gboolean ok = TRUE;
for (i = 0; lines[i] != NULL; i++)
{
- if (lines[i][0] && !g_slist_find_custom (list, lines[i], strcmp))
+ if (lines[i][0] && !g_slist_find_custom (list, lines[i], (GCompareFunc) strcmp))
list = g_slist_append (list, g_strdup (lines[i]));
}
g_strfreev (lines);
}
if (ok && (f = fopen (filename, "wb")) != NULL)
{
- for (entry = list; entry != NULL; entry = entry->next)
+ entry = g_slist_find_custom (list, uri, (GCompareFunc) strcmp);
+ if (add)
{
- gchar *line = entry->data;
-
- if (strcmp (line, uri) != 0)
+ /* g_slist_insert() and our insert semantics are
+ * compatible, but maybe we should check for
+ * positon > length ?
+ *
+ */
+ if (!entry)
+ list = g_slist_insert (list, g_strdup (uri), position);
+ else
{
- fputs (line, f);
- fputs ("\n", f);
+ g_set_error (error,
+ GTK_FILE_SYSTEM_ERROR,
+ GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS,
+ "%s already exists in the bookmarks list",
+ uri);
+ ok = FALSE;
}
}
- if (add)
+ else
{
- fputs (uri, f);
- fputs ("\n", f);
+ /* 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);
+ fputs ("\n", f);
+ }
}
fclose (f);
}
GdkPixbuf *pixbuf = NULL;
WORD iicon;
HICON hicon;
+ char filename_copy[MAX_PATH];
if (!filename || !filename[0])
return NULL;
- hicon = ExtractAssociatedIcon (GetModuleHandle (NULL), filename, &iicon);
+ /* the ugly ExtractAssociatedIcon modifies filename in place - at least on win98 */
+ strcpy(filename_copy, filename);
+ hicon = ExtractAssociatedIcon (GetModuleHandle (NULL), filename_copy, &iicon);
if (hicon > (HICON)1)
{
ICONINFO ii;
if (GetIconInfo (hicon, &ii))
{
- SIZE size;
- GdkPixmap *pixmap;
- GdkGC *gc;
- HDC hdc;
-
- if (!GetBitmapDimensionEx (ii.hbmColor, &size))
- g_warning ("GetBitmapDimensionEx failed.");
-
- if (size.cx < 1) size.cx = 32;
- if (size.cy < 1) size.cy = 32;
-
- pixmap = gdk_pixmap_new (NULL, size.cx, size.cy,
- gdk_screen_get_system_visual (gdk_screen_get_default ())->depth);
- gc = gdk_gc_new (pixmap);
- hdc = gdk_win32_hdc_get (GDK_DRAWABLE (pixmap), gc, 0);
-
- if (!DrawIcon (hdc, 0, 0, hicon))
- g_warning ("DrawIcon failed");
-
- gdk_win32_hdc_release (GDK_DRAWABLE (pixmap), gc, 0);
-
- pixbuf = gdk_pixbuf_get_from_drawable (
- NULL, pixmap,
- gdk_screen_get_system_colormap (gdk_screen_get_default ()),
- 0, 0, 0, 0, size.cx, size.cy);
- g_object_unref (pixmap);
- g_object_unref (gc);
+ 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;
+ gboolean no_alpha;
+
+ bmi.bi.biBitCount = 32;
+ bmi.bi.biCompression = BI_RGB;
+ bmi.bi.biHeight = -h;
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
+ bits = g_malloc0 (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);
+ no_alpha = TRUE;
+ for (y = 0; y < h; y++)
+ {
+ for (x = 0; x < w; x++)
+ {
+ pixels[2] = bits[(x+y*w) * 4];
+ pixels[1] = bits[(x+y*w) * 4 + 1];
+ pixels[0] = bits[(x+y*w) * 4 + 2];
+ pixels[3] = bits[(x+y*w) * 4 + 3];
+ if (no_alpha && pixels[3] > 0) no_alpha = FALSE;
+ pixels += 4;
+ }
+ pixels += (w * 4 - rowstride);
+ }
+ /* mask */
+ if (no_alpha) {
+ 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) * 4];
+ 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);
}
else
- g_print ("GetIconInfo failed: %s\n", g_win32_error_message (GetLastError ()));
+ g_warning(G_STRLOC ": GetIconInfo failed: %s\n", g_win32_error_message (GetLastError ()));
if (!DestroyIcon (hicon))
- g_warning ("DestroyIcon failed");
+ g_warning(G_STRLOC ": DestroyIcon failed");
}
else
- g_print ("ExtractAssociatedIcon failed: %s\n", g_win32_error_message (GetLastError ()));
+ g_warning (G_STRLOC ":ExtractAssociatedIcon(%s) failed: %s", filename, g_win32_error_message (GetLastError ()));
return pixbuf;
}
const char* filename = gtk_file_path_get_string (path);
/* handle drives with stock icons */
- if (filename_is_root (filename))
+ if (filename_is_drive_root (filename))
{
- gchar *filename2 = g_strconcat(filename, "\\", NULL);
- DWORD dt = GetDriveType (filename2);
+ gchar filename2[] = "?:\\";
+ DWORD dt;
+
+ filename2[0] = filename[0];
+ dt = GetDriveType (filename2);
switch (dt)
{
case DRIVE_CDROM :
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_CDROM);
break;
- case DRIVE_FIXED : /* need a hard disk icon */
+ case DRIVE_FIXED :
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_HARDDISK);
break;
default :
break;
}
- g_free (filename2);
}
else if (g_file_test (filename, G_FILE_TEST_IS_DIR))
{
- if (0 == strcmp (g_get_home_dir(), filename))
+ const gchar *home = g_get_home_dir ();
+ if (home != NULL && 0 == strcmp (home, filename))
icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_HOME);
else
- icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_OPEN);
+ icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_DIRECTORY);
}
else if (g_file_test (filename, G_FILE_TEST_IS_EXECUTABLE))
{
static GSList *_bookmarks = NULL;
static gboolean
-gtk_file_system_win32_add_bookmark (GtkFileSystem *file_system,
+gtk_file_system_win32_insert_bookmark (GtkFileSystem *file_system,
const GtkFilePath *path,
+ gint position,
GError **error)
{
gchar *uri = gtk_file_system_win32_path_to_uri (file_system, path);
- gboolean ret = bookmarks_serialize (&_bookmarks, uri, TRUE, error);
+ gboolean ret = bookmarks_serialize (&_bookmarks, uri, TRUE, position, error);
+ if (ret)
+ g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
g_free (uri);
return ret;
GError **error)
{
gchar *uri = gtk_file_system_win32_path_to_uri (file_system, path);
- gboolean ret = bookmarks_serialize (&_bookmarks, uri, FALSE, error);
+ gboolean ret = bookmarks_serialize (&_bookmarks, uri, FALSE, 0, error);
+ if (ret)
+ g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
g_free (uri);
return ret;
}
GSList *entry;
- if (bookmarks_serialize (&_bookmarks, "", FALSE, NULL))
+ if (bookmarks_serialize (&_bookmarks, "", FALSE, 0, NULL))
{
for (entry = _bookmarks; entry != NULL; entry = entry->next)
{
{
GtkFileFolderWin32 *folder_win32 = GTK_FILE_FOLDER_WIN32 (object);
+ g_hash_table_remove (folder_win32->system_win32->folder_hash, folder_win32->filename);
+
g_free (folder_win32->filename);
folder_parent_class->finalize (object);
gchar *dirname;
gchar *filename;
+ if (!path)
+ {
+ g_return_val_if_fail (filename_is_some_root (folder_win32->filename), NULL);
+
+ /* ??? */
+ info = filename_get_info (folder_win32->filename, folder_win32->types, error);
+
+ return info;
+ }
+
filename = filename_from_path (path);
g_return_val_if_fail (filename != NULL, NULL);
info = gtk_file_info_new ();
- if (filename_is_root (filename))
+ if (filename_is_some_root (filename))
{
if (types & GTK_FILE_INFO_DISPLAY_NAME)
gtk_file_info_set_display_name (info, filename);
GtkFileTime time = wfad.ftLastWriteTime.dwLowDateTime
| ((guint64)wfad.ftLastWriteTime.dwHighDateTime) << 32;
/* 100-nanosecond intervals since January 1, 1601, urgh! */
- time /= 10000000I64; /* now seconds */
- time -= 134774I64 * 24 * 3600; /* good old Unix time */
+ time /= G_GINT64_CONSTANT (10000000); /* now seconds */
+ time -= G_GINT64_CONSTANT (134774) * 24 * 3600; /* good old Unix time */
gtk_file_info_set_modification_time (info, time);
}
}
static gboolean
-filename_is_root (const char *filename)
+filename_is_drive_root (const char *filename)
{
- guint len = strlen(filename);
+ guint len = strlen (filename);
/* accept both forms */
- return ( (len == 2 && filename[1] == ':')
- || (len == 3 && filename[1] == ':' && filename[2] == '\\'));
+ return (len == 3 && filename[1] == ':' && G_IS_DIR_SEPARATOR (filename[2]));
}
+static gboolean
+filename_is_some_root (const char *filename)
+{
+ return (G_IS_DIR_SEPARATOR (filename[0]) && filename[1] == '\0') ||
+ filename_is_drive_root (filename);
+}