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 public import gtkc.glibtypes; 33 34 35 /** 36 * An opaque structure representing an opened directory. 37 */ 38 public class Directory 39 { 40 /** the main Gtk struct */ 41 protected GDir* gDir; 42 protected bool ownedRef; 43 44 /** Get the main Gtk struct */ 45 public GDir* getDirectoryStruct(bool transferOwnership = false) 46 { 47 if (transferOwnership) 48 ownedRef = false; 49 return gDir; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)gDir; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (GDir* gDir, bool ownedRef = false) 62 { 63 this.gDir = gDir; 64 this.ownedRef = ownedRef; 65 } 66 67 68 /** 69 * Closes the directory and deallocates all related resources. 70 */ 71 public void close() 72 { 73 g_dir_close(gDir); 74 } 75 76 /** 77 * Retrieves the name of another entry in the directory, or %NULL. 78 * The order of entries returned from this function is not defined, 79 * and may vary by file system or other operating-system dependent 80 * factors. 81 * 82 * %NULL may also be returned in case of errors. On Unix, you can 83 * check `errno` to find out if %NULL was returned because of an error. 84 * 85 * On Unix, the '.' and '..' entries are omitted, and the returned 86 * name is in the on-disk encoding. 87 * 88 * On Windows, as is true of all GLib functions which operate on 89 * filenames, the returned name is in UTF-8. 90 * 91 * Returns: The entry's name or %NULL if there are no 92 * more entries. The return value is owned by GLib and 93 * must not be modified or freed. 94 */ 95 public string readName() 96 { 97 return Str.toString(g_dir_read_name(gDir)); 98 } 99 100 /** 101 * Resets the given directory. The next call to g_dir_read_name() 102 * will return the first entry again. 103 */ 104 public void rewind() 105 { 106 g_dir_rewind(gDir); 107 } 108 109 /** 110 * Creates a subdirectory in the preferred directory for temporary 111 * files (as returned by g_get_tmp_dir()). 112 * 113 * @tmpl should be a string in the GLib file name encoding containing 114 * a sequence of six 'X' characters, as the parameter to g_mkstemp(). 115 * However, unlike these functions, the template should only be a 116 * basename, no directory components are allowed. If template is 117 * %NULL, a default template is used. 118 * 119 * Note that in contrast to g_mkdtemp() (and mkdtemp()) @tmpl is not 120 * modified, and might thus be a read-only literal string. 121 * 122 * Params: 123 * tmpl = Template for directory name, 124 * as in g_mkdtemp(), basename only, or %NULL for a default template 125 * 126 * Returns: The actual name used. This string 127 * should be freed with g_free() when not needed any longer and is 128 * is in the GLib file name encoding. In case of errors, %NULL is 129 * returned and @error will be set. 130 * 131 * Since: 2.30 132 * 133 * Throws: GException on failure. 134 */ 135 public static string makeTmp(string tmpl) 136 { 137 GError* err = null; 138 139 auto retStr = g_dir_make_tmp(Str.toStringz(tmpl), &err); 140 141 if (err !is null) 142 { 143 throw new GException( new ErrorG(err) ); 144 } 145 146 scope(exit) Str.freeString(retStr); 147 return Str.toString(retStr); 148 } 149 150 /** 151 * Opens a directory for reading. The names of the files in the 152 * directory can then be retrieved using g_dir_read_name(). Note 153 * that the ordering is not defined. 154 * 155 * Params: 156 * path = the path to the directory you are interested in. On Unix 157 * in the on-disk encoding. On Windows in UTF-8 158 * flags = Currently must be set to 0. Reserved for future use. 159 * 160 * Returns: a newly allocated #GDir on success, %NULL on failure. 161 * If non-%NULL, you must free the result with g_dir_close() 162 * when you are finished with it. 163 * 164 * Throws: GException on failure. 165 */ 166 public static Directory open(string path, uint flags) 167 { 168 GError* err = null; 169 170 auto __p = g_dir_open(Str.toStringz(path), flags, &err); 171 172 if (err !is null) 173 { 174 throw new GException( new ErrorG(err) ); 175 } 176 177 if(__p is null) 178 { 179 return null; 180 } 181 182 return new Directory(cast(GDir*) __p); 183 } 184 }