| 255 | }; |
| 256 | |
| 257 | void tryUriConvert(std::string& filename) |
| 258 | { |
| 259 | if (filename.find(":") == std::string::npos) { |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | LibHandle gLib("libglib-2.0.so.0"); |
| 264 | LibHandle gobjectLib("libgobject-2.0.so.0"); |
| 265 | LibHandle gioLib("libgio-2.0.so.0"); |
| 266 | |
| 267 | if (gioLib && gLib && gobjectLib) { |
| 268 | FileCreateFunc createUriFunc = (FileCreateFunc)dlsym(gioLib, "g_file_new_for_uri"); |
| 269 | |
| 270 | IsNativeFunc nativeFunc = (IsNativeFunc)dlsym(gioLib, "g_file_is_native"); |
| 271 | FileGetFunc getFunc = (FileGetFunc)dlsym(gioLib, "g_file_get_path"); |
| 272 | InitFunc initFunc = (InitFunc)dlsym(gobjectLib, "g_type_init"); |
| 273 | UnrefFunc unrefFunc = (UnrefFunc)dlsym(gobjectLib, "g_object_unref"); |
| 274 | FreeFunc freeFunc = (FreeFunc)dlsym(gLib, "g_free"); |
| 275 | |
| 276 | if (!(createUriFunc && nativeFunc && getFunc && freeFunc && initFunc && unrefFunc)) { |
| 277 | std::cerr << "Failed to obtain functions from gio libraries" << std::endl; |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | initFunc(); |
| 282 | |
| 283 | void* pFile = createUriFunc(filename.c_str()); |
| 284 | if (!pFile) { |
| 285 | std::cerr << "Failed to create gio file: " << filename << std::endl; |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | if (!nativeFunc(pFile)) { |
| 290 | unrefFunc(pFile); |
| 291 | std::cerr << "Not a native file, thumbnailing will likely fail: " << filename << std::endl; |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | char* pPath = getFunc(pFile); |
| 296 | if (pPath) { |
| 297 | filename = pPath; |
| 298 | freeFunc(pPath); |
| 299 | } else { |
| 300 | std::cerr << "Failed to get path: " << filename << std::endl; |
| 301 | } |
| 302 | |
| 303 | unrefFunc(pFile); |
| 304 | } |
| 305 | } |
| 306 | #endif |
| 307 | |
| 308 | ThumbnailerImageType determineImageTypeFromFilename(const std::string& filename) |