| 42 | } |
| 43 | |
| 44 | void PDFBridgeEvince::OpenDocument(const PDFFile &pdfFile) { |
| 45 | auto pdfPath = pdfFile.getPath(); |
| 46 | |
| 47 | if (!filesystem::exists(pdfPath)) { // PDF file does not exist, do not attempt to load |
| 48 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "PDFBridgeEvince PDF file does not exist"); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | GError *error = nullptr; |
| 53 | |
| 54 | if (!dbusConnection) |
| 55 | dbusConnection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); |
| 56 | |
| 57 | if (!dbusConnection) { |
| 58 | if (error) { |
| 59 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "PDFBridgeEvince: could not connect to DBUS, %s", error->message); |
| 60 | g_error_free(error); |
| 61 | error = nullptr; |
| 62 | } else { |
| 63 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "PDFBridgeEvince: could not connect to DBUS"); |
| 64 | } |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | daemonProxy = g_dbus_proxy_new_sync(dbusConnection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.gnome.evince.Daemon", "/org/gnome/evince/Daemon", "org.gnome.evince.Daemon", NULL, &error); |
| 69 | if (!daemonProxy) { |
| 70 | if (error) { |
| 71 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "PDFBridgeEvince daemonProxy error: %s", error->message); |
| 72 | g_error_free(error); |
| 73 | error = nullptr; |
| 74 | } else { |
| 75 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "PDFBridgeEvince daemonProxy error"); |
| 76 | } |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | std::string canonical_path = filesystem::canonical(pdfPath).string(); |
| 81 | |
| 82 | GFile *gfile = g_file_new_for_path(canonical_path.c_str()); |
| 83 | char *uri = g_file_get_uri(gfile); |
| 84 | g_object_unref(gfile); |
| 85 | |
| 86 | SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "PDFBridgeEvince FindDocument: %s", uri); |
| 87 | |
| 88 | GVariant *owner = g_dbus_proxy_call_sync(daemonProxy, "FindDocument", g_variant_new("(sb)", uri, true), G_DBUS_CALL_FLAGS_NONE, 10000/*10 seconds timeout*/, NULL, &error); |
| 89 | if (!owner) { |
| 90 | if (error) { |
| 91 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "PDFBridgeEvince FindDocument error: %s", error->message); |
| 92 | g_error_free(error); |
| 93 | error = nullptr; |
| 94 | } else { |
| 95 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "PDFBridgeEvince FindDocument error"); |
| 96 | } |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | g_free(uri); |
| 101 | uri = nullptr; |