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