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 gio.ContentType; 26 27 private import gio.FileIF; 28 private import gio.Icon; 29 private import gio.IconIF; 30 private import glib.ListG; 31 private import glib.Str; 32 private import gobject.ObjectG; 33 private import gtkc.gio; 34 public import gtkc.giotypes; 35 36 37 /** */ 38 public struct ContentType 39 { 40 41 /** 42 * Checks if a content type can be executable. Note that for instance 43 * things like text files can be executables (i.e. scripts and batch files). 44 * 45 * Params: 46 * type = a content type string 47 * 48 * Return: %TRUE if the file type corresponds to a type that 49 * can be executable, %FALSE otherwise. 50 */ 51 public static bool canBeExecutable(string type) 52 { 53 return g_content_type_can_be_executable(Str.toStringz(type)) != 0; 54 } 55 56 /** 57 * Compares two content types for equality. 58 * 59 * Params: 60 * type1 = a content type string 61 * type2 = a content type string 62 * 63 * Return: %TRUE if the two strings are identical or equivalent, 64 * %FALSE otherwise. 65 */ 66 public static bool equals(string type1, string type2) 67 { 68 return g_content_type_equals(Str.toStringz(type1), Str.toStringz(type2)) != 0; 69 } 70 71 /** 72 * Tries to find a content type based on the mime type name. 73 * 74 * Params: 75 * mimeType = a mime type string 76 * 77 * Return: Newly allocated string with content type or 78 * %NULL. Free with g_free() 79 * 80 * Since: 2.18 81 */ 82 public static string fromMimeType(string mimeType) 83 { 84 auto retStr = g_content_type_from_mime_type(Str.toStringz(mimeType)); 85 86 scope(exit) Str.freeString(retStr); 87 return Str.toString(retStr); 88 } 89 90 /** 91 * Gets the human readable description of the content type. 92 * 93 * Params: 94 * type = a content type string 95 * 96 * Return: a short description of the content type @type. Free the 97 * returned string with g_free() 98 */ 99 public static string getDescription(string type) 100 { 101 auto retStr = g_content_type_get_description(Str.toStringz(type)); 102 103 scope(exit) Str.freeString(retStr); 104 return Str.toString(retStr); 105 } 106 107 /** 108 * Gets the generic icon name for a content type. 109 * 110 * See the 111 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec) 112 * specification for more on the generic icon name. 113 * 114 * Params: 115 * type = a content type string 116 * 117 * Return: the registered generic icon name for the given @type, 118 * or %NULL if unknown. Free with g_free() 119 * 120 * Since: 2.34 121 */ 122 public static string getGenericIconName(string type) 123 { 124 auto retStr = g_content_type_get_generic_icon_name(Str.toStringz(type)); 125 126 scope(exit) Str.freeString(retStr); 127 return Str.toString(retStr); 128 } 129 130 /** 131 * Gets the icon for a content type. 132 * 133 * Params: 134 * type = a content type string 135 * 136 * Return: #GIcon corresponding to the content type. Free the returned 137 * object with g_object_unref() 138 */ 139 public static IconIF getIcon(string type) 140 { 141 auto p = g_content_type_get_icon(Str.toStringz(type)); 142 143 if(p is null) 144 { 145 return null; 146 } 147 148 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true); 149 } 150 151 /** 152 * Gets the mime type for the content type, if one is registered. 153 * 154 * Params: 155 * type = a content type string 156 * 157 * Return: the registered mime type for the given @type, 158 * or %NULL if unknown. 159 */ 160 public static string getMimeType(string type) 161 { 162 auto retStr = g_content_type_get_mime_type(Str.toStringz(type)); 163 164 scope(exit) Str.freeString(retStr); 165 return Str.toString(retStr); 166 } 167 168 /** 169 * Gets the symbolic icon for a content type. 170 * 171 * Params: 172 * type = a content type string 173 * 174 * Return: symbolic #GIcon corresponding to the content type. 175 * Free the returned object with g_object_unref() 176 * 177 * Since: 2.34 178 */ 179 public static IconIF getSymbolicIcon(string type) 180 { 181 auto p = g_content_type_get_symbolic_icon(Str.toStringz(type)); 182 183 if(p is null) 184 { 185 return null; 186 } 187 188 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p, true); 189 } 190 191 /** 192 * Guesses the content type based on example data. If the function is 193 * uncertain, @result_uncertain will be set to %TRUE. Either @filename 194 * or @data may be %NULL, in which case the guess will be based solely 195 * on the other argument. 196 * 197 * Params: 198 * filename = a string, or %NULL 199 * data = a stream of data, or %NULL 200 * dataSize = the size of @data 201 * resultUncertain = return location for the certainty 202 * of the result, or %NULL 203 * 204 * Return: a string indicating a guessed content type for the 205 * given data. Free with g_free() 206 */ 207 public static string typeGuess(string filename, char[] data, out bool resultUncertain) 208 { 209 int outresultUncertain; 210 211 auto retStr = g_content_type_guess(Str.toStringz(filename), data.ptr, cast(size_t)data.length, &outresultUncertain); 212 213 resultUncertain = (outresultUncertain == 1); 214 215 scope(exit) Str.freeString(retStr); 216 return Str.toString(retStr); 217 } 218 219 /** 220 * Tries to guess the type of the tree with root @root, by 221 * looking at the files it contains. The result is an array 222 * of content types, with the best guess coming first. 223 * 224 * The types returned all have the form x-content/foo, e.g. 225 * x-content/audio-cdda (for audio CDs) or x-content/image-dcf 226 * (for a camera memory card). See the 227 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec) 228 * specification for more on x-content types. 229 * 230 * This function is useful in the implementation of 231 * g_mount_guess_content_type(). 232 * 233 * Params: 234 * root = the root of the tree to guess a type for 235 * 236 * Return: an %NULL-terminated 237 * array of zero or more content types. Free with g_strfreev() 238 * 239 * Since: 2.18 240 */ 241 public static string[] guessForTree(FileIF root) 242 { 243 auto retStr = g_content_type_guess_for_tree((root is null) ? null : root.getFileStruct()); 244 245 scope(exit) Str.freeStringArray(retStr); 246 return Str.toStringArray(retStr); 247 } 248 249 /** 250 * Determines if @type is a subset of @supertype. 251 * 252 * Params: 253 * type = a content type string 254 * supertype = a content type string 255 * 256 * Return: %TRUE if @type is a kind of @supertype, 257 * %FALSE otherwise. 258 */ 259 public static bool isA(string type, string supertype) 260 { 261 return g_content_type_is_a(Str.toStringz(type), Str.toStringz(supertype)) != 0; 262 } 263 264 /** 265 * Checks if the content type is the generic "unknown" type. 266 * On UNIX this is the "application/octet-stream" mimetype, 267 * while on win32 it is "*". 268 * 269 * Params: 270 * type = a content type string 271 * 272 * Return: %TRUE if the type is the unknown type. 273 */ 274 public static bool isUnknown(string type) 275 { 276 return g_content_type_is_unknown(Str.toStringz(type)) != 0; 277 } 278 279 /** 280 * Gets a list of strings containing all the registered content types 281 * known to the system. The list and its data should be freed using 282 * g_list_free_full (list, g_free). 283 * 284 * Return: list of the registered 285 * content types 286 */ 287 public static ListG contentTypesGetRegistered() 288 { 289 auto p = g_content_types_get_registered(); 290 291 if(p is null) 292 { 293 return null; 294 } 295 296 return new ListG(cast(GList*) p, true); 297 } 298 }