1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/*-
* Copyright (c) 2009-2010 Jannis Pohlmann <jannis@xfce.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, Inc.,; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
//#include <thunar/thunar-file.h>
#include "eel-gio-extensions.h"
/**
* eel_g_file_list_new_from_string:
* @string : a string representation of an URI list.
*
* Splits an URI list conforming to the text/uri-list
* mime type defined in RFC 2483 into individual URIs,
* discarding any comments and whitespace. The resulting
* list will hold one #GFile for each URI.
*
* If @string contains no URIs, this function
* will return %NULL.
*
* Return value: the list of #GFile<!---->s or %NULL.
**/
GList *
eel_g_file_list_new_from_string (const gchar *string)
{
GList *list = NULL;
gchar **uris;
gsize n;
uris = g_uri_list_extract_uris (string);
for (n = 0; uris != NULL && uris[n] != NULL; ++n)
list = g_list_append (list, g_file_new_for_uri (uris[n]));
g_strfreev (uris);
return list;
}
gchar *
eel_g_file_get_location (GFile *file)
{
gchar *location;
g_return_val_if_fail (G_IS_FILE (file), NULL);
location = g_file_get_path (file);
if (location == NULL)
location = g_file_get_uri (file);
return location;
}
GFile *
eel_g_file_get_trash_original_file (const gchar *string)
{
GFile *location = NULL;
char *filename;
if (string != NULL) {
/* file name is stored in URL encoding */
filename = g_uri_unescape_string (string, "");
location = g_file_new_for_path (filename);
g_free (filename);
}
return location;
}
gboolean
eel_g_file_is_trashed (GFile *file)
{
g_return_val_if_fail (G_IS_FILE (file), FALSE);
return g_file_has_uri_scheme (file, "trash");
}
GKeyFile *
eel_g_file_query_key_file (GFile *file, GCancellable *cancellable, GError **error)
{
GKeyFile *key_file;
gchar *contents = NULL;
gsize length;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* try to load the entire file into memory */
if (!g_file_load_contents (file, cancellable, &contents, &length, NULL, error))
return NULL;
/* allocate a new key file */
key_file = g_key_file_new ();
/* try to parse the key file from the contents of the file */
if (G_LIKELY (length == 0
|| g_key_file_load_from_data (key_file, contents, length,
G_KEY_FILE_KEEP_COMMENTS
| G_KEY_FILE_KEEP_TRANSLATIONS,
error)))
{
g_free (contents);
return key_file;
}
else
{
g_free (contents);
g_key_file_free (key_file);
return NULL;
}
}
GFile *
eel_g_file_ref (GFile *file)
{
if (file == NULL) {
return NULL;
}
g_return_val_if_fail (G_FILE (file), NULL);
return g_object_ref (file);
}
void
eel_g_file_unref (GFile *file)
{
if (file == NULL) {
return;
}
g_return_if_fail (G_FILE (file));
g_object_unref (file);
}
|