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