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