1 /* 2 * This file is part of EvinceD. 3 * EvinceD is based on GtkD. 4 * 5 * EvinceD is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License 7 * as published by the Free Software Foundation; either version 3 8 * of the License, or (at your option) any later version, with 9 * some exceptions, please read the COPYING file. 10 * 11 * EvinceD is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with EvinceD; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 19 */ 20 21 // generated automatically - do not change 22 // find conversion definition on APILookup.txt 23 24 25 module evince.document.EvinceDocument; 26 27 private import evince.document.Document; 28 private import evince.document.Rectangle; 29 private import evince.document.c.functions; 30 public import evince.document.c.types; 31 private import gio.FileIF; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import glib.ListG; 35 private import glib.Str; 36 private import gobject.ObjectG; 37 38 39 /** */ 40 public struct EvinceDocument 41 { 42 43 /** */ 44 public static ListG backendsManagerGetAllTypesInfo() 45 { 46 auto __p = ev_backends_manager_get_all_types_info(); 47 48 if(__p is null) 49 { 50 return null; 51 } 52 53 return new ListG(cast(GList*) __p); 54 } 55 56 /** 57 * 58 * Params: 59 * mimeType = a mime type hint 60 * Returns: a new #EvDocument 61 */ 62 public static Document backendsManagerGetDocument(string mimeType) 63 { 64 auto __p = ev_backends_manager_get_document(Str.toStringz(mimeType)); 65 66 if(__p is null) 67 { 68 return null; 69 } 70 71 return ObjectG.getDObject!(Document)(cast(EvDocument*) __p, true); 72 } 73 74 /** */ 75 public static string backendsManagerGetDocumentModuleName(Document document) 76 { 77 return Str.toString(ev_backends_manager_get_document_module_name((document is null) ? null : document.getDocumentStruct())); 78 } 79 80 /** */ 81 public static EvTypeInfo* backendsManagerGetDocumentTypeInfo(Document document) 82 { 83 return ev_backends_manager_get_document_type_info((document is null) ? null : document.getDocumentStruct()); 84 } 85 86 /** 87 * Compresses the file at @uri. 88 * 89 * If @type is %EV_COMPRESSION_NONE, it does nothing and returns %NULL. 90 * 91 * Otherwise, it returns the filename of a 92 * temporary file containing the compressed data from the file at @uri. 93 * 94 * On error it returns %NULL and fills in @error. 95 * 96 * It is the caller's responsibility to unlink the temp file after use. 97 * 98 * Params: 99 * uri = a file URI 100 * type = the compression type 101 * 102 * Returns: a newly allocated string URI, or %NULL on error 103 * 104 * Throws: GException on failure. 105 */ 106 public static string fileCompress(string uri, EvCompressionType type) 107 { 108 GError* err = null; 109 110 auto retStr = ev_file_compress(Str.toStringz(uri), type, &err); 111 112 if (err !is null) 113 { 114 throw new GException( new ErrorG(err) ); 115 } 116 117 scope(exit) Str.freeString(retStr); 118 return Str.toString(retStr); 119 } 120 121 /** 122 * Performs a g_file_copy_attributes() with %G_FILE_COPY_ALL_METADATA 123 * from @from to @to. 124 * 125 * Params: 126 * from = the source URI 127 * to = the target URI 128 * 129 * Returns: %TRUE if the attributes were copied successfully, %FALSE otherwise. 130 * 131 * Since: 3.4 132 * 133 * Throws: GException on failure. 134 */ 135 public static bool fileCopyMetadata(string from, string to) 136 { 137 GError* err = null; 138 139 auto __p = ev_file_copy_metadata(Str.toStringz(from), Str.toStringz(to), &err) != 0; 140 141 if (err !is null) 142 { 143 throw new GException( new ErrorG(err) ); 144 } 145 146 return __p; 147 } 148 149 /** 150 * 151 * Params: 152 * uri = the URI 153 * fast = whether to use fast MIME type detection 154 * Returns: a newly allocated string with the MIME type of the file at 155 * @uri, or %NULL on error or if the MIME type could not be determined 156 * 157 * Throws: GException on failure. 158 */ 159 public static string fileGetMimeType(string uri, bool fast) 160 { 161 GError* err = null; 162 163 auto retStr = ev_file_get_mime_type(Str.toStringz(uri), fast, &err); 164 165 if (err !is null) 166 { 167 throw new GException( new ErrorG(err) ); 168 } 169 170 scope(exit) Str.freeString(retStr); 171 return Str.toString(retStr); 172 } 173 174 /** */ 175 public static bool fileIsTemp(FileIF file) 176 { 177 return ev_file_is_temp((file is null) ? null : file.getFileStruct()) != 0; 178 } 179 180 /** 181 * Uncompresses the file at @uri. 182 * 183 * If @type is %EV_COMPRESSION_NONE, it does nothing and returns %NULL. 184 * 185 * Otherwise, it returns the filename of a 186 * temporary file containing the decompressed data from the file at @uri. 187 * On error it returns %NULL and fills in @error. 188 * 189 * It is the caller's responsibility to unlink the temp file after use. 190 * 191 * Params: 192 * uri = a file URI 193 * type = the compression type 194 * 195 * Returns: a newly allocated string URI, or %NULL on error 196 * 197 * Throws: GException on failure. 198 */ 199 public static string fileUncompress(string uri, EvCompressionType type) 200 { 201 GError* err = null; 202 203 auto retStr = ev_file_uncompress(Str.toStringz(uri), type, &err); 204 205 if (err !is null) 206 { 207 throw new GException( new ErrorG(err) ); 208 } 209 210 scope(exit) Str.freeString(retStr); 211 return Str.toString(retStr); 212 } 213 214 /** 215 * Creates a temp directory in the evince temp directory. 216 * 217 * Params: 218 * tmpl = a template string; must end in 'XXXXXX' 219 * 220 * Returns: a newly allocated string with the temp directory name, or %NULL 221 * on error with @error filled in 222 * 223 * Throws: GException on failure. 224 */ 225 public static string mkdtemp(string tmpl) 226 { 227 GError* err = null; 228 229 auto retStr = ev_mkdtemp(Str.toStringz(tmpl), &err); 230 231 if (err !is null) 232 { 233 throw new GException( new ErrorG(err) ); 234 } 235 236 scope(exit) Str.freeString(retStr); 237 return Str.toString(retStr); 238 } 239 240 /** 241 * Creates a temp file in the evince temp directory. 242 * 243 * Params: 244 * tmpl = a template string; must contain 'XXXXXX', but not necessarily as a suffix 245 * fileName = a location to store the filename of the temp file 246 * 247 * Returns: a file descriptor to the newly created temp file name, or %-1 248 * on error with @error filled in 249 * 250 * Throws: GException on failure. 251 */ 252 public static int mkstemp(string tmpl, string[] fileName) 253 { 254 GError* err = null; 255 256 auto __p = ev_mkstemp(Str.toStringz(tmpl), Str.toStringzArray(fileName), &err); 257 258 if (err !is null) 259 { 260 throw new GException( new ErrorG(err) ); 261 } 262 263 return __p; 264 } 265 266 /** 267 * Creates a temp #GFile in the evince temp directory. See ev_mkstemp() for more information. 268 * 269 * Params: 270 * tmpl = a template string; must contain 'XXXXXX', but not necessarily as a suffix 271 * 272 * Returns: a newly allocated #GFile for the newly created temp file name, or %NULL 273 * on error with @error filled in 274 * 275 * Throws: GException on failure. 276 */ 277 public static FileIF mkstempFile(string tmpl) 278 { 279 GError* err = null; 280 281 auto __p = ev_mkstemp_file(Str.toStringz(tmpl), &err); 282 283 if (err !is null) 284 { 285 throw new GException( new ErrorG(err) ); 286 } 287 288 if(__p is null) 289 { 290 return null; 291 } 292 293 return ObjectG.getDObject!(FileIF)(cast(GFile*) __p, true); 294 } 295 296 /** */ 297 public static string getLocaleDir() 298 { 299 return Str.toString(ev_get_locale_dir()); 300 } 301 302 /** 303 * Initializes the evince document library, and binds the evince 304 * gettext domain. 305 * 306 * You must call this before calling any other function in the evince 307 * document library. 308 * 309 * Returns: %TRUE if any backends were found; %FALSE otherwise 310 */ 311 public static bool init() 312 { 313 return ev_init() != 0; 314 } 315 316 /** */ 317 public static int rectCmp(Rectangle a, Rectangle b) 318 { 319 return ev_rect_cmp((a is null) ? null : a.getRectangleStruct(), (b is null) ? null : b.getRectangleStruct()); 320 } 321 322 /** 323 * Shuts the evince document library down. 324 */ 325 public static void shutdown() 326 { 327 ev_shutdown(); 328 } 329 330 /** */ 331 public static void tmpFileUnlink(FileIF file) 332 { 333 ev_tmp_file_unlink((file is null) ? null : file.getFileStruct()); 334 } 335 336 /** */ 337 public static void tmpFilenameUnlink(string filename) 338 { 339 ev_tmp_filename_unlink(Str.toStringz(filename)); 340 } 341 342 /** */ 343 public static void tmpUriUnlink(string uri) 344 { 345 ev_tmp_uri_unlink(Str.toStringz(uri)); 346 } 347 348 /** 349 * Performs a g_file_copy() from @from to @to. 350 * 351 * Params: 352 * from = the source URI 353 * to = the target URI 354 * 355 * Returns: %TRUE on success, or %FALSE on error with @error filled in 356 * 357 * Throws: GException on failure. 358 */ 359 public static bool xferUriSimple(string from, string to) 360 { 361 GError* err = null; 362 363 auto __p = ev_xfer_uri_simple(Str.toStringz(from), Str.toStringz(to), &err) != 0; 364 365 if (err !is null) 366 { 367 throw new GException( new ErrorG(err) ); 368 } 369 370 return __p; 371 } 372 }