source: appstream-generator/build/girepo/glib/Directory.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 4.7 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.Directory;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.ErrorG;
26private import glib.GException;
27private import glib.Str;
28
29
30/**
31 * An opaque structure representing an opened directory.
32 */
33public class Directory
34{
35        /** the main Gtk struct */
36        protected GDir* gDir;
37        protected bool ownedRef;
38
39        /** Get the main Gtk struct */
40        public GDir* getDirectoryStruct()
41        {
42                return gDir;
43        }
44
45        /** the main Gtk struct as a void* */
46        protected void* getStruct()
47        {
48                return cast(void*)gDir;
49        }
50
51        /**
52         * Sets our main struct and passes it to the parent class.
53         */
54        public this (GDir* gDir, bool ownedRef = false)
55        {
56                this.gDir = gDir;
57                this.ownedRef = ownedRef;
58        }
59
60
61        /**
62         * Closes the directory and deallocates all related resources.
63         */
64        public void close()
65        {
66                g_dir_close(gDir);
67        }
68
69        /**
70         * Retrieves the name of another entry in the directory, or %NULL.
71         * The order of entries returned from this function is not defined,
72         * and may vary by file system or other operating-system dependent
73         * factors.
74         *
75         * %NULL may also be returned in case of errors. On Unix, you can
76         * check `errno` to find out if %NULL was returned because of an error.
77         *
78         * On Unix, the '.' and '..' entries are omitted, and the returned
79         * name is in the on-disk encoding.
80         *
81         * On Windows, as is true of all GLib functions which operate on
82         * filenames, the returned name is in UTF-8.
83         *
84         * Returns: The entry's name or %NULL if there are no
85         *     more entries. The return value is owned by GLib and
86         *     must not be modified or freed.
87         */
88        public string readName()
89        {
90                return Str.toString(g_dir_read_name(gDir));
91        }
92
93        /**
94         * Resets the given directory. The next call to g_dir_read_name()
95         * will return the first entry again.
96         */
97        public void rewind()
98        {
99                g_dir_rewind(gDir);
100        }
101
102        /**
103         * Creates a subdirectory in the preferred directory for temporary
104         * files (as returned by g_get_tmp_dir()).
105         *
106         * @tmpl should be a string in the GLib file name encoding containing
107         * a sequence of six 'X' characters, as the parameter to g_mkstemp().
108         * However, unlike these functions, the template should only be a
109         * basename, no directory components are allowed. If template is
110         * %NULL, a default template is used.
111         *
112         * Note that in contrast to g_mkdtemp() (and mkdtemp()) @tmpl is not
113         * modified, and might thus be a read-only literal string.
114         *
115         * Params:
116         *     tmpl = Template for directory name,
117         *         as in g_mkdtemp(), basename only, or %NULL for a default template
118         *
119         * Returns: The actual name used. This string
120         *     should be freed with g_free() when not needed any longer and is
121         *     is in the GLib file name encoding. In case of errors, %NULL is
122         *     returned and @error will be set.
123         *
124         * Since: 2.30
125         *
126         * Throws: GException on failure.
127         */
128        public static string makeTmp(string tmpl)
129        {
130                GError* err = null;
131               
132                auto retStr = g_dir_make_tmp(Str.toStringz(tmpl), &err);
133               
134                if (err !is null)
135                {
136                        throw new GException( new ErrorG(err) );
137                }
138               
139                scope(exit) Str.freeString(retStr);
140                return Str.toString(retStr);
141        }
142
143        /**
144         * Opens a directory for reading. The names of the files in the
145         * directory can then be retrieved using g_dir_read_name().  Note
146         * that the ordering is not defined.
147         *
148         * Params:
149         *     path = the path to the directory you are interested in. On Unix
150         *         in the on-disk encoding. On Windows in UTF-8
151         *     flags = Currently must be set to 0. Reserved for future use.
152         *
153         * Returns: a newly allocated #GDir on success, %NULL on failure.
154         *     If non-%NULL, you must free the result with g_dir_close()
155         *     when you are finished with it.
156         *
157         * Throws: GException on failure.
158         */
159        public static Directory open(string path, uint flags)
160        {
161                GError* err = null;
162               
163                auto p = g_dir_open(Str.toStringz(path), flags, &err);
164               
165                if (err !is null)
166                {
167                        throw new GException( new ErrorG(err) );
168                }
169               
170                if(p is null)
171                {
172                        return null;
173                }
174               
175                return new Directory(cast(GDir*) p);
176        }
177}
Note: See TracBrowser for help on using the repository browser.