port a few more functions to gio (part of bug #524401)
2008-05-01 Jens Granseuer <jensgr@gmx.net> * appearance-themes.c: (theme_get_mtime), (theme_drag_data_received_cb): * theme-util.c: (directory_delete_recursive), (file_delete_recursive), (theme_is_writable), (theme_delete): port a few more functions to gio (part of bug #524401) svn path=/trunk/; revision=8685
This commit is contained in:
parent
a9e90ad542
commit
9d7383da4f
3 changed files with 107 additions and 50 deletions
|
@ -1,3 +1,11 @@
|
|||
2008-05-01 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
* appearance-themes.c: (theme_get_mtime),
|
||||
(theme_drag_data_received_cb):
|
||||
* theme-util.c: (directory_delete_recursive),
|
||||
(file_delete_recursive), (theme_is_writable), (theme_delete): port a
|
||||
few more functions to gio (part of bug #524401)
|
||||
|
||||
2008-05-01 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
Based on a patch by: Lincoln de Sousa <lincoln@minaslivre.org>
|
||||
|
|
|
@ -65,19 +65,21 @@ theme_get_mtime (const char *name)
|
|||
|
||||
theme = gnome_theme_meta_info_find (name);
|
||||
if (theme != NULL) {
|
||||
GnomeVFSFileInfo *file_info;
|
||||
GnomeVFSResult result;
|
||||
GFile *file;
|
||||
GFileInfo *file_info;
|
||||
|
||||
file_info = gnome_vfs_file_info_new ();
|
||||
file = g_file_new_for_path (theme->path);
|
||||
file_info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_TIME_MODIFIED,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, NULL);
|
||||
g_object_unref (file);
|
||||
|
||||
result = gnome_vfs_get_file_info (theme->path, file_info,
|
||||
GNOME_VFS_FILE_INFO_DEFAULT |
|
||||
GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
|
||||
|
||||
if (result == GNOME_VFS_OK)
|
||||
mtime = file_info->mtime;
|
||||
|
||||
gnome_vfs_file_info_unref (file_info);
|
||||
if (file_info != NULL) {
|
||||
mtime = g_file_info_get_attribute_uint64 (file_info,
|
||||
G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
||||
g_object_unref (file_info);
|
||||
}
|
||||
}
|
||||
|
||||
return mtime;
|
||||
|
@ -1010,28 +1012,24 @@ theme_drag_data_received_cb (GtkWidget *widget,
|
|||
guint info, guint time,
|
||||
AppearanceData *data)
|
||||
{
|
||||
GList *uris;
|
||||
gchar **uris;
|
||||
|
||||
if (!(info == TARGET_URI_LIST || info == TARGET_NS_URL))
|
||||
return;
|
||||
|
||||
uris = gnome_vfs_uri_list_parse ((gchar *) selection_data->data);
|
||||
uris = g_uri_list_extract_uris ((gchar *) selection_data->data);
|
||||
|
||||
if (uris != NULL && uris->data != NULL) {
|
||||
GnomeVFSURI *uri = (GnomeVFSURI *) uris->data;
|
||||
gchar *filename;
|
||||
|
||||
if (gnome_vfs_uri_is_local (uri))
|
||||
filename = gnome_vfs_unescape_string (gnome_vfs_uri_get_path (uri), G_DIR_SEPARATOR_S);
|
||||
else
|
||||
filename = gnome_vfs_unescape_string (gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE), G_DIR_SEPARATOR_S);
|
||||
|
||||
gnome_vfs_uri_list_unref (uris);
|
||||
if (uris != NULL && uris[0] != NULL) {
|
||||
GFile *f = g_file_new_for_uri (uris[0]);
|
||||
gchar *filename = g_file_get_path (f);
|
||||
g_object_unref (f);
|
||||
|
||||
gnome_theme_install_from_uri (filename,
|
||||
GTK_WINDOW (glade_xml_get_widget (data->xml, "appearance_window")));
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
g_strfreev (uris);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -25,27 +25,88 @@
|
|||
#include <glib/gi18n.h>
|
||||
#include <string.h>
|
||||
|
||||
static gboolean
|
||||
directory_delete_recursive (GFile *directory, GError **error)
|
||||
{
|
||||
GFileEnumerator *enumerator;
|
||||
GFileInfo *info;
|
||||
gboolean success = TRUE;
|
||||
|
||||
enumerator = g_file_enumerate_children (directory,
|
||||
G_FILE_ATTRIBUTE_STANDARD_NAME ","
|
||||
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, error);
|
||||
if (enumerator == NULL)
|
||||
return FALSE;
|
||||
|
||||
while (success &&
|
||||
(info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {
|
||||
GFile *child;
|
||||
|
||||
child = g_file_get_child (directory, g_file_info_get_name (info));
|
||||
|
||||
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
|
||||
success = directory_delete_recursive (child, error);
|
||||
}
|
||||
g_object_unref (info);
|
||||
|
||||
if (success)
|
||||
success = g_file_delete (child, NULL, error);
|
||||
}
|
||||
g_file_enumerator_close (enumerator, NULL, NULL);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
file_delete_recursive (GFile *file, GError **error)
|
||||
{
|
||||
GFileInfo *info;
|
||||
GFileType type;
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, error);
|
||||
if (info == NULL)
|
||||
return FALSE;
|
||||
|
||||
type = g_file_info_get_file_type (info);
|
||||
g_object_unref (info);
|
||||
|
||||
if (type == G_FILE_TYPE_DIRECTORY)
|
||||
return directory_delete_recursive (file, error);
|
||||
else
|
||||
return g_file_delete (file, NULL, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
theme_is_writable (const gpointer theme)
|
||||
{
|
||||
GnomeThemeCommonInfo *info = theme;
|
||||
GnomeVFSResult vfs_result;
|
||||
GnomeVFSFileInfo *vfs_info;
|
||||
GFile *file;
|
||||
GFileInfo *file_info;
|
||||
gboolean writable;
|
||||
|
||||
if (info == NULL || info->path == NULL)
|
||||
return FALSE;
|
||||
|
||||
vfs_info = gnome_vfs_file_info_new ();
|
||||
vfs_result = gnome_vfs_get_file_info (info->path,
|
||||
vfs_info,
|
||||
GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
|
||||
file = g_file_new_for_uri (info->path);
|
||||
file_info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, NULL);
|
||||
g_object_unref (file);
|
||||
|
||||
writable = ((vfs_result == GNOME_VFS_OK) &&
|
||||
(vfs_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS) &&
|
||||
(vfs_info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE));
|
||||
if (file_info == NULL)
|
||||
return FALSE;
|
||||
|
||||
gnome_vfs_file_info_unref (vfs_info);
|
||||
writable = g_file_info_get_attribute_boolean (file_info,
|
||||
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
|
||||
g_object_unref (file_info);
|
||||
|
||||
return writable;
|
||||
}
|
||||
|
@ -57,10 +118,8 @@ theme_delete (const gchar *name, ThemeType type)
|
|||
GtkDialog *dialog;
|
||||
gchar *theme_dir;
|
||||
gint response;
|
||||
GList *uri_list;
|
||||
GnomeVFSResult result;
|
||||
GnomeVFSURI *uri;
|
||||
GnomeThemeCommonInfo *theme;
|
||||
GFile *dir;
|
||||
|
||||
dialog = (GtkDialog *) gtk_message_dialog_new (NULL,
|
||||
GTK_DIALOG_MODAL,
|
||||
|
@ -103,17 +162,10 @@ theme_delete (const gchar *name, ThemeType type)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
uri = gnome_vfs_uri_new (theme_dir);
|
||||
dir = g_file_new_for_uri (theme_dir);
|
||||
g_free (theme_dir);
|
||||
|
||||
uri_list = g_list_prepend (NULL, uri);
|
||||
|
||||
result = gnome_vfs_xfer_delete_list (uri_list,
|
||||
GNOME_VFS_XFER_ERROR_MODE_ABORT,
|
||||
GNOME_VFS_XFER_RECURSIVE,
|
||||
NULL, NULL);
|
||||
|
||||
if (result != GNOME_VFS_OK) {
|
||||
if (!file_delete_recursive (dir, NULL)) {
|
||||
GtkWidget *info_dialog = gtk_message_dialog_new (NULL,
|
||||
GTK_DIALOG_MODAL,
|
||||
GTK_MESSAGE_ERROR,
|
||||
|
@ -124,14 +176,13 @@ theme_delete (const gchar *name, ThemeType type)
|
|||
rc = FALSE;
|
||||
} else {
|
||||
/* also delete empty parent directories */
|
||||
GnomeVFSURI *parent = gnome_vfs_uri_get_parent (uri);
|
||||
gnome_vfs_remove_directory_from_uri (parent);
|
||||
gnome_vfs_uri_unref (parent);
|
||||
GFile *parent = g_file_get_parent (dir);
|
||||
g_file_delete (parent, NULL, NULL);
|
||||
g_object_unref (parent);
|
||||
rc = TRUE;
|
||||
}
|
||||
|
||||
gnome_vfs_uri_list_free (uri_list);
|
||||
|
||||
g_object_unref (dir);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue