From 5470878e59c78f1072cc77ff740a0192cf4e62da Mon Sep 17 00:00:00 2001 From: Ondra Voves Date: Wed, 20 Nov 2024 10:21:00 +0100 Subject: [PATCH] WIP: Vendor external --- .ci/init_zig.sh | 1 - .github/workflows/test.yaml | 25 +- .gitmodules | 27 +- Writerside/snippets/getting-started/clone.sh | 4 +- Writerside/topics/getting-started.md | 4 +- build.zig | 115 +- build.zig.zon | 14 +- externals/shared | 1 + externals/shared/.gitignore | 4 - externals/shared/README.md | 1 - externals/shared/lib/SDL_GameControllerDB | 1 - externals/shared/lib/zbgfx | 1 - externals/shared/lib/zf | 1 - externals/shared/lib/zig-gamedev | 1 - externals/shared/lib/zig-uuid | 1 - externals/shared/lib/ziglang-set | 1 - externals/shared/lib/znfde/README.md | 11 - externals/shared/lib/znfde/build.zig | 63 - externals/shared/lib/znfde/build.zig.zon | 13 - .../lib/znfde/includes/dbus/dbus-address.h | 85 - .../lib/znfde/includes/dbus/dbus-arch-deps.h | 61 - .../shared/lib/znfde/includes/dbus/dbus-bus.h | 95 - .../lib/znfde/includes/dbus/dbus-connection.h | 526 ----- .../lib/znfde/includes/dbus/dbus-errors.h | 90 - .../lib/znfde/includes/dbus/dbus-macros.h | 251 --- .../lib/znfde/includes/dbus/dbus-memory.h | 72 - .../lib/znfde/includes/dbus/dbus-message.h | 383 ---- .../lib/znfde/includes/dbus/dbus-misc.h | 58 - .../znfde/includes/dbus/dbus-pending-call.h | 98 - .../lib/znfde/includes/dbus/dbus-protocol.h | 486 ----- .../lib/znfde/includes/dbus/dbus-server.h | 125 -- .../lib/znfde/includes/dbus/dbus-shared.h | 136 -- .../lib/znfde/includes/dbus/dbus-signature.h | 95 - .../lib/znfde/includes/dbus/dbus-syntax.h | 58 - .../lib/znfde/includes/dbus/dbus-threads.h | 189 -- .../lib/znfde/includes/dbus/dbus-types.h | 156 -- .../shared/lib/znfde/includes/dbus/dbus.h | 104 - .../shared/lib/znfde/nativefiledialog/LICENSE | 16 - .../lib/znfde/nativefiledialog/README.md | 310 --- .../znfde/nativefiledialog/src/CMakeLists.txt | 135 -- .../znfde/nativefiledialog/src/include/nfd.h | 564 ------ .../nativefiledialog/src/include/nfd.hpp | 375 ---- .../znfde/nativefiledialog/src/nfd_cocoa.m | 615 ------ .../znfde/nativefiledialog/src/nfd_gtk.cpp | 918 --------- .../znfde/nativefiledialog/src/nfd_portal.cpp | 1793 ----------------- .../znfde/nativefiledialog/src/nfd_win.cpp | 1185 ----------- externals/shared/lib/znfde/src/c.zig | 3 - externals/shared/lib/znfde/src/znfde.zig | 103 - externals/shared/tools/zls | 1 - public/build.zig.zon | 2 +- tools/generate_vscode.zig | 2 +- zig | 2 +- 52 files changed, 110 insertions(+), 9271 deletions(-) create mode 160000 externals/shared delete mode 100644 externals/shared/.gitignore delete mode 100644 externals/shared/README.md delete mode 160000 externals/shared/lib/SDL_GameControllerDB delete mode 160000 externals/shared/lib/zbgfx delete mode 160000 externals/shared/lib/zf delete mode 160000 externals/shared/lib/zig-gamedev delete mode 160000 externals/shared/lib/zig-uuid delete mode 160000 externals/shared/lib/ziglang-set delete mode 100644 externals/shared/lib/znfde/README.md delete mode 100644 externals/shared/lib/znfde/build.zig delete mode 100644 externals/shared/lib/znfde/build.zig.zon delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-address.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-arch-deps.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-bus.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-connection.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-errors.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-macros.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-memory.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-message.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-misc.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-pending-call.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-protocol.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-server.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-shared.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-signature.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-syntax.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-threads.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus-types.h delete mode 100644 externals/shared/lib/znfde/includes/dbus/dbus.h delete mode 100644 externals/shared/lib/znfde/nativefiledialog/LICENSE delete mode 100644 externals/shared/lib/znfde/nativefiledialog/README.md delete mode 100644 externals/shared/lib/znfde/nativefiledialog/src/CMakeLists.txt delete mode 100644 externals/shared/lib/znfde/nativefiledialog/src/include/nfd.h delete mode 100644 externals/shared/lib/znfde/nativefiledialog/src/include/nfd.hpp delete mode 100644 externals/shared/lib/znfde/nativefiledialog/src/nfd_cocoa.m delete mode 100644 externals/shared/lib/znfde/nativefiledialog/src/nfd_gtk.cpp delete mode 100644 externals/shared/lib/znfde/nativefiledialog/src/nfd_portal.cpp delete mode 100644 externals/shared/lib/znfde/nativefiledialog/src/nfd_win.cpp delete mode 100644 externals/shared/lib/znfde/src/c.zig delete mode 100644 externals/shared/lib/znfde/src/znfde.zig delete mode 160000 externals/shared/tools/zls mode change 160000 => 120000 zig diff --git a/.ci/init_zig.sh b/.ci/init_zig.sh index 7149bda20..4decee742 100755 --- a/.ci/init_zig.sh +++ b/.ci/init_zig.sh @@ -7,4 +7,3 @@ ZIG_ARCH=$1 OPTIMIZE=$2 ./zig/get_zig.sh ${ZIG_ARCH} - diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9874b7330..a22c32367 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,8 +29,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - submodules: true + + - name: Fetch zig submodule + run: git submodule update --init externals/shared - name: Read .zig-version id: zigversion @@ -58,10 +59,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - submodules: true - + - name: Fetch zig submodule + run: git submodule update --init externals/shared + - name: Prepare uses: awalsh128/cache-apt-pkgs-action@latest with: @@ -165,10 +166,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - submodules: true - # - name: Prepare + - name: Fetch zig submodule + run: git submodule update --init externals/shared + + # - name: Prepare` # run: | # brew update # brew install kcov @@ -256,9 +258,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - submodules: true - + + - name: Fetch zig submodule + run: git submodule update --init externals/shared + - name: Read .zig-version id: zigversion uses: juliangruber/read-file-action@v1 diff --git a/.gitmodules b/.gitmodules index 3ca1ad199..93ad0ab82 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,24 +1,3 @@ -[submodule "externals/shared/lib/zig-gamedev"] - path = externals/shared/lib/zig-gamedev - url = https://github.com/OndraVoves/zig-gamedev.git -[submodule "externals/shared/tools/zls"] - path = externals/shared/tools/zls - url = https://github.com/zigtools/zls.git -[submodule "externals/shared/lib/SDL_GameControllerDB"] - path = externals/shared/lib/SDL_GameControllerDB - url = https://github.com/mdqinc/SDL_GameControllerDB.git -[submodule "zig"] - path = zig - url = https://github.com/cyberegoorg/cetech1-zig.git -[submodule "externals/shared/lib/zbgfx"] - path = externals/shared/lib/zbgfx - url = https://github.com/cyberegoorg/zbgfx.git -[submodule "externals/shared/lib/ziglang-set"] - path = externals/shared/lib/ziglang-set - url = https://github.com/deckarep/ziglang-set -[submodule "externals/shared/lib/zig-uuid"] - path = externals/shared/lib/zig-uuid - url = https://github.com/tensorush/zig-uuid.git -[submodule "externals/shared/lib/zf"] - path = externals/shared/lib/zf - url = https://github.com/OndraVoves/zf.git +[submodule "externals/shared"] + path = externals/shared + url = https://github.com/cyberegoorg/cetech1-externals-shared.git diff --git a/Writerside/snippets/getting-started/clone.sh b/Writerside/snippets/getting-started/clone.sh index c68be5946..c77aa31bc 100644 --- a/Writerside/snippets/getting-started/clone.sh +++ b/Writerside/snippets/getting-started/clone.sh @@ -1,8 +1,8 @@ # GIT_LFS_SKIP_SMUDGE=1 disable loading all LFS objects GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/cyberegoorg/cetech1.git -# This fetch submodules from `externals` and zig directory -git submodule update --init +# This fetch basic externals deps +git submodule update --init externals/shared # This download zig binary from our website. Only need for your arch where you develop ./zig/get_zig.sh diff --git a/Writerside/topics/getting-started.md b/Writerside/topics/getting-started.md index ca7cc3475..07f58c78f 100644 --- a/Writerside/topics/getting-started.md +++ b/Writerside/topics/getting-started.md @@ -129,12 +129,12 @@ CETech provide ZLS as submodule, but you must build it. - zig/bin/ARCH/zig build zls + zig/bin/ARCH/zig build -Dwith_zls zls - zig/bin/ARCH/zig.exe build zls + zig/bin/ARCH/zig.exe build -Dwith_zls zls diff --git a/build.zig b/build.zig index 3c93e51ca..fb54c20f5 100644 --- a/build.zig +++ b/build.zig @@ -34,6 +34,8 @@ pub fn build(b: *std.Build) !void { .externals_optimize = b.option(std.builtin.OptimizeMode, "externals_optimize", "Optimize for externals libs") orelse .ReleaseFast, .enable_shaderc = b.option(bool, "with_shaderc", "build with shaderc support") orelse true, + + .enable_zls = b.option(bool, "with_zls", "zls") orelse false, }; const options_step = b.addOptions(); @@ -120,15 +122,6 @@ pub fn build(b: *std.Build) !void { }, ); - // ZPOOL - const zpool = b.dependency( - "zpool", - .{ - .target = target, - .optimize = options.externals_optimize, - }, - ); - // ZFLECS const zflecs = b.dependency( "zflecs", @@ -148,12 +141,6 @@ pub fn build(b: *std.Build) !void { }, ); - // ZLS - const zls = b.dependency("zls", .{ - .target = target, - .optimize = .ReleaseFast, - }); - // System sdk // const system_sdk = b.dependency("system_sdk", .{}); @@ -235,18 +222,41 @@ pub fn build(b: *std.Build) !void { "--include", "src/embed/fonts/*", }); + + const init_system_sdk = b.addSystemCommand(&.{ + "git", + "-C", + "externals/shared", + "submodule", + "update", + "--init", + "repo/system_sdk", + }); const init_lfs_system_sdk = b.addSystemCommand(&.{ "git", "-C", - "externals/shared/lib/zig-gamedev", + "externals/shared/repo/system_sdk", "lfs", "pull", "--include", "libs/system-sdk/**/*", }); + init_lfs_system_sdk.step.dependOn(&init_system_sdk.step); + + const init_zls = b.addSystemCommand(&.{ + "git", + "-C", + "externals/shared", + "submodule", + "update", + "--init", + "tools/zls", + }); + init_step.dependOn(&init_lfs_writerside.step); init_step.dependOn(&init_lfs_fonts.step); - init_step.dependOn(&init_lfs_system_sdk.step); + init_step.dependOn(&init_system_sdk.step); + init_step.dependOn(&init_zls.step); // // Gen vscode @@ -259,9 +269,17 @@ pub fn build(b: *std.Build) !void { // // ZLS // - const zls_step = b.step("zls", "Build bundled ZLS"); - var zls_install = b.addInstallArtifact(zls.artifact("zls"), .{}); - zls_step.dependOn(&zls_install.step); + if (options.enable_zls) { + const zls = b.dependency("zls", .{ + .target = target, + .optimize = .ReleaseFast, + }); + + const zls_step = b.step("zls", "Build bundled ZLS"); + var zls_install = b.addInstallArtifact(zls.artifact("zls"), .{}); + zls_install.step.dependOn(&init_zls.step); + zls_step.dependOn(&zls_install.step); + } // // CETech1 core build @@ -337,7 +355,35 @@ pub fn build(b: *std.Build) !void { // Libs, moduels etc.. inline for (.{ exe, tests }) |e| { - @import("system_sdk").addLibraryPathsTo(e); + switch (target.result.os.tag) { + .windows => { + if (target.result.cpu.arch.isX86()) { + if (target.result.abi.isGnu() or target.result.abi.isMusl()) { + if (b.lazyDependency("system_sdk", .{})) |system_sdk| { + e.addLibraryPath(system_sdk.path("windows/lib/x86_64-windows-gnu")); + } + } + } + }, + .macos => { + if (b.lazyDependency("system_sdk", .{})) |system_sdk| { + e.addLibraryPath(system_sdk.path("macos12/usr/lib")); + e.addFrameworkPath(system_sdk.path("macos12/System/Library/Frameworks")); + } + }, + .linux => { + if (target.result.cpu.arch.isX86()) { + if (b.lazyDependency("system_sdk", .{})) |system_sdk| { + e.addLibraryPath(system_sdk.path("linux/lib/x86_64-linux-gnu")); + } + } else if (target.result.cpu.arch == .aarch64) { + if (b.lazyDependency("system_sdk", .{})) |system_sdk| { + e.addLibraryPath(system_sdk.path("linux/lib/aarch64-linux-gnu")); + } + } + }, + else => {}, + } // Make exe depends on generated files. e.step.dependOn(&generated_files.step); @@ -367,7 +413,6 @@ pub fn build(b: *std.Build) !void { e.root_module.addImport("ztracy", ztracy.module("root")); e.root_module.addImport("zjobs", zjobs.module("root")); - e.root_module.addImport("zpool", zpool.module("root")); e.root_module.addImport("zglfw", zglfw.module("root")); e.root_module.addImport("zgui", zgui.module("root")); e.root_module.addImport("zflecs", zflecs.module("root")); @@ -426,26 +471,24 @@ const externals = .{ .{ .name = "zig", .file = "zig/LICENSE" }, // zig-gamedev - .{ .name = "zig-gamedev", .file = "externals/shared/lib/zig-gamedev/LICENSE" }, - .{ .name = "zglfw", .file = "externals/shared/lib/zig-gamedev/libs/zglfw/LICENSE" }, - .{ .name = "zpool", .file = "externals/shared/lib/zig-gamedev/libs/zpool/LICENSE" }, - .{ .name = "zjobs", .file = "externals/shared/lib/zig-gamedev/libs/zjobs/LICENSE" }, - .{ .name = "ztracy", .file = "externals/shared/lib/zig-gamedev/libs/ztracy/LICENSE" }, - .{ .name = "zgui", .file = "externals/shared/lib/zig-gamedev/libs/zgui/LICENSE" }, - .{ .name = "zflecs", .file = "externals/shared/lib/zig-gamedev/libs/zflecs/LICENSE" }, + .{ .name = "zglfw", .file = "externals/shared/lib/zglfw/LICENSE" }, + .{ .name = "zjobs", .file = "externals/shared/lib/zjobs/LICENSE" }, + .{ .name = "ztracy", .file = "externals/shared/lib/ztracy/LICENSE" }, + .{ .name = "zgui", .file = "externals/shared/lib/zgui/LICENSE" }, + .{ .name = "zflecs", .file = "externals/shared/lib/zflecs/LICENSE" }, // ImGui - .{ .name = "imgui", .file = "externals/shared/lib/zig-gamedev/libs/zgui/libs/imgui/LICENSE.txt" }, - .{ .name = "imgui_test_engine", .file = "externals/shared/lib/zig-gamedev/libs/zgui/libs/imgui_test_engine/LICENSE.txt" }, - .{ .name = "implot", .file = "externals/shared/lib/zig-gamedev/libs/zgui/libs/implot/LICENSE" }, - .{ .name = "imguizmo", .file = "externals/shared/lib/zig-gamedev/libs/zgui/libs/imguizmo/LICENSE" }, - .{ .name = "imgui_node_editor", .file = "externals/shared/lib/zig-gamedev/libs/zgui/libs/node_editor/LICENSE" }, + .{ .name = "imgui", .file = "externals/shared/lib/zgui/libs/imgui/LICENSE.txt" }, + .{ .name = "imgui_test_engine", .file = "externals/shared/lib/zgui/libs/imgui_test_engine/LICENSE.txt" }, + .{ .name = "implot", .file = "externals/shared/lib/zgui/libs/implot/LICENSE" }, + .{ .name = "imguizmo", .file = "externals/shared/lib/zgui/libs/imguizmo/LICENSE" }, + .{ .name = "imgui_node_editor", .file = "externals/shared/lib/zgui/libs/node_editor/LICENSE" }, // FLECS - .{ .name = "FLECS", .file = "externals/shared/lib/zig-gamedev/libs/zflecs/libs/flecs/LICENSE" }, + .{ .name = "FLECS", .file = "externals/shared/lib/zflecs/libs/flecs/LICENSE" }, // GLFW - .{ .name = "glfw", .file = "externals/shared/lib/zig-gamedev/libs/zglfw/libs/glfw/LICENSE.md" }, + .{ .name = "glfw", .file = "externals/shared/lib/zglfw/libs/glfw/LICENSE.md" }, // SDL_GameControllerDB .{ .name = "SDL_GameControllerDB", .file = "externals/shared/lib/SDL_GameControllerDB/LICENSE" }, diff --git a/build.zig.zon b/build.zig.zon index 804b23842..7d09d1d56 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -67,13 +67,11 @@ .zbgfx = .{ .path = "externals/shared/lib/zbgfx" }, // zig-gamedev - .system_sdk = .{ .path = "externals/shared/lib/zig-gamedev/libs/system-sdk" }, - .zglfw = .{ .path = "externals/shared/lib/zig-gamedev/libs/zglfw" }, - .zpool = .{ .path = "externals/shared/lib/zig-gamedev/libs/zpool" }, - .zjobs = .{ .path = "externals/shared/lib/zig-gamedev/libs/zjobs" }, - .ztracy = .{ .path = "externals/shared/lib/zig-gamedev/libs/ztracy" }, - .zgui = .{ .path = "externals/shared/lib/zig-gamedev/libs/zgui" }, - .zflecs = .{ .path = "externals/shared/lib/zig-gamedev/libs/zflecs" }, - //.znfde = .{ .path = "externals/shared/lib/zig-gamedev/libs/znfde" }, + .system_sdk = .{ .path = "externals/shared/repo/system_sdk" }, + .zjobs = .{ .path = "externals/shared/lib/zjobs" }, + .zglfw = .{ .path = "externals/shared/lib/zglfw" }, + .zflecs = .{ .path = "externals/shared/lib/zflecs" }, + .ztracy = .{ .path = "externals/shared/lib/ztracy" }, + .zgui = .{ .path = "externals/shared/lib/zgui" }, }, } diff --git a/externals/shared b/externals/shared new file mode 160000 index 000000000..380bdcd8f --- /dev/null +++ b/externals/shared @@ -0,0 +1 @@ +Subproject commit 380bdcd8fd75a9f765e5d4e67d6d3028d0203008 diff --git a/externals/shared/.gitignore b/externals/shared/.gitignore deleted file mode 100644 index 808003e33..000000000 --- a/externals/shared/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.DS_Store -.DS_Store - -tmp \ No newline at end of file diff --git a/externals/shared/README.md b/externals/shared/README.md deleted file mode 100644 index 40c4e9248..000000000 --- a/externals/shared/README.md +++ /dev/null @@ -1 +0,0 @@ -# cetech1-externals-shared diff --git a/externals/shared/lib/SDL_GameControllerDB b/externals/shared/lib/SDL_GameControllerDB deleted file mode 160000 index 08715f75b..000000000 --- a/externals/shared/lib/SDL_GameControllerDB +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 08715f75b459129d08b918e411c1a91c71a3cd0a diff --git a/externals/shared/lib/zbgfx b/externals/shared/lib/zbgfx deleted file mode 160000 index 53c38f5d6..000000000 --- a/externals/shared/lib/zbgfx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 53c38f5d6662d95a942b27df88f9831590cfd1e1 diff --git a/externals/shared/lib/zf b/externals/shared/lib/zf deleted file mode 160000 index 256fe06b6..000000000 --- a/externals/shared/lib/zf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 256fe06b610529cb242b72291320dfbfca657d6c diff --git a/externals/shared/lib/zig-gamedev b/externals/shared/lib/zig-gamedev deleted file mode 160000 index 14e625890..000000000 --- a/externals/shared/lib/zig-gamedev +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 14e6258901c6fb47ae598705682837ef6c298e60 diff --git a/externals/shared/lib/zig-uuid b/externals/shared/lib/zig-uuid deleted file mode 160000 index 4e51b6a69..000000000 --- a/externals/shared/lib/zig-uuid +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4e51b6a69bbc06ba825731912b8041bfb13bec72 diff --git a/externals/shared/lib/ziglang-set b/externals/shared/lib/ziglang-set deleted file mode 160000 index fc2aa4360..000000000 --- a/externals/shared/lib/ziglang-set +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fc2aa4360fb4441c562a5095b7d8a347f0a106b5 diff --git a/externals/shared/lib/znfde/README.md b/externals/shared/lib/znfde/README.md deleted file mode 100644 index 229472e11..000000000 --- a/externals/shared/lib/znfde/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# znfde v0.1.0 - NativeFileDialog extended bindings - -Easy to use NFDe zig wraper. - -## Getting started - -Copy `znfde` to a subdirectory in your project and add the following to your `build.zig.zon` .dependencies: - -```zig - .znfde = .{ .path = "libs/znfde" }, -``` diff --git a/externals/shared/lib/znfde/build.zig b/externals/shared/lib/znfde/build.zig deleted file mode 100644 index 0f49d9e57..000000000 --- a/externals/shared/lib/znfde/build.zig +++ /dev/null @@ -1,63 +0,0 @@ -const std = @import("std"); - -pub fn build(b: *std.Build) void { - const optimize = b.standardOptimizeOption(.{}); - const target = b.standardTargetOptions(.{}); - - const options = .{ - .with_portal = b.option( - bool, - "with_portal", - "Use xdg-desktop-portal instead of GTK", - ) orelse true, - }; - - const znfde = b.addModule("root", .{ - .root_source_file = b.path("src/znfde.zig"), - }); - - var lib: *std.Build.Step.Compile = undefined; - lib = b.addStaticLibrary(.{ - .name = "nfde", - .target = target, - .optimize = optimize, - }); - - const cflags = [_][]const u8{}; - - lib.addIncludePath(b.path("nativefiledialog/src/include")); - znfde.addIncludePath(b.path("nativefiledialog/src/include")); - - switch (lib.rootModuleTarget().os.tag) { - .windows => { - lib.addCSourceFile(.{ .file = b.path("nativefiledialog/src/nfd_win.cpp"), .flags = &cflags }); - lib.linkSystemLibrary("shell32"); - lib.linkSystemLibrary("ole32"); - lib.linkSystemLibrary("uuid"); - }, - .macos => { - lib.defineCMacro("NFD_MACOS_ALLOWEDCONTENTTYPES", "1"); - lib.addCSourceFile(.{ .file = b.path("nativefiledialog/src/nfd_cocoa.m"), .flags = &cflags }); - lib.linkFramework("AppKit"); - lib.linkFramework("UniformTypeIdentifiers"); - }, - else => { - if (options.with_portal) { - lib.addSystemIncludePath(b.path("includes")); - znfde.addSystemIncludePath(b.path("includes")); - lib.addCSourceFile(.{ .file = b.path("nativefiledialog/src/nfd_portal.cpp"), .flags = &cflags }); - lib.linkSystemLibrary("dbus-1"); - } else { - lib.addCSourceFile(.{ .file = b.path("nativefiledialog/src/nfd_gtk.cpp"), .flags = &cflags }); - lib.linkSystemLibrary("atk-1.0"); - lib.linkSystemLibrary("gdk-3"); - lib.linkSystemLibrary("gtk-3"); - lib.linkSystemLibrary("glib-2.0"); - lib.linkSystemLibrary("gobject-2.0"); - } - lib.linkLibCpp(); - }, - } - - b.installArtifact(lib); -} diff --git a/externals/shared/lib/znfde/build.zig.zon b/externals/shared/lib/znfde/build.zig.zon deleted file mode 100644 index e6e2303ae..000000000 --- a/externals/shared/lib/znfde/build.zig.zon +++ /dev/null @@ -1,13 +0,0 @@ -.{ - .name = "znfde", - .version = "0.1.0", - .dependencies = .{}, - .paths = .{ - "includes", - "nativefiledialog", - "src", - "README.md", - "build.zig", - "build.zig.zon", - }, -} diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-address.h b/externals/shared/lib/znfde/includes/dbus/dbus-address.h deleted file mode 100644 index 30df44636..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-address.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-address.h Server address parser. - * - * Copyright (C) 2003 CodeFactory AB - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_ADDRESS_H -#define DBUS_ADDRESS_H - -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusAddress - * @{ - */ - -/** Opaque type representing one of the semicolon-separated items in an address */ -typedef struct DBusAddressEntry DBusAddressEntry; - -DBUS_EXPORT -dbus_bool_t dbus_parse_address (const char *address, - DBusAddressEntry ***entry_result, - int *array_len, - DBusError *error); -DBUS_EXPORT -const char *dbus_address_entry_get_value (DBusAddressEntry *entry, - const char *key); -DBUS_EXPORT -const char *dbus_address_entry_get_method (DBusAddressEntry *entry); -DBUS_EXPORT -void dbus_address_entries_free (DBusAddressEntry **entries); - -DBUS_EXPORT -char* dbus_address_escape_value (const char *value); -DBUS_EXPORT -char* dbus_address_unescape_value (const char *value, - DBusError *error); - -/** - * Clear a variable or struct member that contains an array of #DBusAddressEntry. - * If it does not contain #NULL, the entries that were previously - * there are freed with dbus_address_entries_free(). - * - * This is similar to dbus_clear_connection(): see that function - * for more details. - * - * @param pointer_to_entries A pointer to a variable or struct member. - * pointer_to_entries must not be #NULL, but *pointer_to_entries - * may be #NULL. - */ -static inline void -dbus_clear_address_entries (DBusAddressEntry ***pointer_to_entries) -{ - _dbus_clear_pointer_impl (DBusAddressEntry *, pointer_to_entries, - dbus_address_entries_free); -} - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_ADDRESS_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-arch-deps.h b/externals/shared/lib/znfde/includes/dbus/dbus-arch-deps.h deleted file mode 100644 index 15cfe7efb..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-arch-deps.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* dbus-arch-deps.h Header with architecture/compiler specific information, installed to libdir - * - * Copyright (C) 2003 Red Hat, Inc. - * - * Licensed under the Academic Free License version 2.0 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_ARCH_DEPS_H -#define DBUS_ARCH_DEPS_H - -#include - -DBUS_BEGIN_DECLS - -/* D-Bus no longer supports platforms with no 64-bit integer type. */ -#define DBUS_HAVE_INT64 1 -_DBUS_GNUC_EXTENSION typedef long dbus_int64_t; -_DBUS_GNUC_EXTENSION typedef unsigned long dbus_uint64_t; - -#define DBUS_INT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##L)) -#define DBUS_UINT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##UL)) - -typedef int dbus_int32_t; -typedef unsigned int dbus_uint32_t; - -typedef short dbus_int16_t; -typedef unsigned short dbus_uint16_t; - -/* This is not really arch-dependent, but it's not worth - * creating an additional generated header just for this - */ -#define DBUS_MAJOR_VERSION 1 -#define DBUS_MINOR_VERSION 14 -#define DBUS_MICRO_VERSION 10 - -#define DBUS_VERSION_STRING "1.14.10" - -#define DBUS_VERSION ((1 << 16) | (14 << 8) | (10)) - -DBUS_END_DECLS - -#endif /* DBUS_ARCH_DEPS_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-bus.h b/externals/shared/lib/znfde/includes/dbus/dbus-bus.h deleted file mode 100644 index c4c602ab2..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-bus.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-bus.h Convenience functions for communicating with the bus. - * - * Copyright (C) 2003 CodeFactory AB - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_BUS_H -#define DBUS_BUS_H - -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusBus - * @{ - */ - -DBUS_EXPORT -DBusConnection *dbus_bus_get (DBusBusType type, - DBusError *error); -DBUS_EXPORT -DBusConnection *dbus_bus_get_private (DBusBusType type, - DBusError *error); - -DBUS_EXPORT -dbus_bool_t dbus_bus_register (DBusConnection *connection, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_bus_set_unique_name (DBusConnection *connection, - const char *unique_name); -DBUS_EXPORT -const char* dbus_bus_get_unique_name (DBusConnection *connection); -DBUS_EXPORT -unsigned long dbus_bus_get_unix_user (DBusConnection *connection, - const char *name, - DBusError *error); -DBUS_EXPORT -char* dbus_bus_get_id (DBusConnection *connection, - DBusError *error); -DBUS_EXPORT -int dbus_bus_request_name (DBusConnection *connection, - const char *name, - unsigned int flags, - DBusError *error); -DBUS_EXPORT -int dbus_bus_release_name (DBusConnection *connection, - const char *name, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_bus_name_has_owner (DBusConnection *connection, - const char *name, - DBusError *error); - -DBUS_EXPORT -dbus_bool_t dbus_bus_start_service_by_name (DBusConnection *connection, - const char *name, - dbus_uint32_t flags, - dbus_uint32_t *reply, - DBusError *error); - -DBUS_EXPORT -void dbus_bus_add_match (DBusConnection *connection, - const char *rule, - DBusError *error); -DBUS_EXPORT -void dbus_bus_remove_match (DBusConnection *connection, - const char *rule, - DBusError *error); - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_BUS_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-connection.h b/externals/shared/lib/znfde/includes/dbus/dbus-connection.h deleted file mode 100644 index 32d79979b..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-connection.h +++ /dev/null @@ -1,526 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-connection.h DBusConnection object - * - * Copyright (C) 2002, 2003 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_CONNECTION_H -#define DBUS_CONNECTION_H - -#include -#include -#include -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusConnection - * @{ - */ - -/* documented in dbus-watch.c */ -typedef struct DBusWatch DBusWatch; -/* documented in dbus-timeout.c */ -typedef struct DBusTimeout DBusTimeout; -/** Opaque type representing preallocated resources so a message can be sent without further memory allocation. */ -typedef struct DBusPreallocatedSend DBusPreallocatedSend; -/** Opaque type representing a method call that has not yet received a reply. */ -typedef struct DBusPendingCall DBusPendingCall; -/** Opaque type representing a connection to a remote application and associated incoming/outgoing message queues. */ -typedef struct DBusConnection DBusConnection; -/** Set of functions that must be implemented to handle messages sent to a particular object path. */ -typedef struct DBusObjectPathVTable DBusObjectPathVTable; - -/** - * Indicates the status of a #DBusWatch. - */ -typedef enum -{ - DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */ - DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */ - DBUS_WATCH_ERROR = 1 << 2, /**< As in POLLERR (can't watch for - * this, but can be present in - * current state passed to - * dbus_watch_handle()). - */ - DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for - * it, but can be present in current - * state passed to - * dbus_watch_handle()). - */ - /* Internal to libdbus, there is also _DBUS_WATCH_NVAL in dbus-watch.h */ -} DBusWatchFlags; - -/** - * Indicates the status of incoming data on a #DBusConnection. This determines whether - * dbus_connection_dispatch() needs to be called. - */ -typedef enum -{ - DBUS_DISPATCH_DATA_REMAINS, /**< There is more data to potentially convert to messages. */ - DBUS_DISPATCH_COMPLETE, /**< All currently available data has been processed. */ - DBUS_DISPATCH_NEED_MEMORY /**< More memory is needed to continue. */ -} DBusDispatchStatus; - -/** Called when libdbus needs a new watch to be monitored by the main - * loop. Returns #FALSE if it lacks enough memory to add the - * watch. Set by dbus_connection_set_watch_functions() or - * dbus_server_set_watch_functions(). - */ -typedef dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch, - void *data); -/** Called when dbus_watch_get_enabled() may return a different value - * than it did before. Set by dbus_connection_set_watch_functions() - * or dbus_server_set_watch_functions(). - */ -typedef void (* DBusWatchToggledFunction) (DBusWatch *watch, - void *data); -/** Called when libdbus no longer needs a watch to be monitored by the - * main loop. Set by dbus_connection_set_watch_functions() or - * dbus_server_set_watch_functions(). - */ -typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch, - void *data); -/** Called when libdbus needs a new timeout to be monitored by the main - * loop. Returns #FALSE if it lacks enough memory to add the - * watch. Set by dbus_connection_set_timeout_functions() or - * dbus_server_set_timeout_functions(). - */ -typedef dbus_bool_t (* DBusAddTimeoutFunction) (DBusTimeout *timeout, - void *data); -/** Called when dbus_timeout_get_enabled() may return a different - * value than it did before. - * Set by dbus_connection_set_timeout_functions() or - * dbus_server_set_timeout_functions(). - */ -typedef void (* DBusTimeoutToggledFunction) (DBusTimeout *timeout, - void *data); -/** Called when libdbus no longer needs a timeout to be monitored by the - * main loop. Set by dbus_connection_set_timeout_functions() or - * dbus_server_set_timeout_functions(). - */ -typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout, - void *data); -/** Called when the return value of dbus_connection_get_dispatch_status() - * may have changed. Set with dbus_connection_set_dispatch_status_function(). - */ -typedef void (* DBusDispatchStatusFunction) (DBusConnection *connection, - DBusDispatchStatus new_status, - void *data); -/** - * Called when the main loop's thread should be notified that there's now work - * to do. Set with dbus_connection_set_wakeup_main_function(). - */ -typedef void (* DBusWakeupMainFunction) (void *data); - -/** - * Called during authentication to check whether the given UNIX user - * ID is allowed to connect, if the client tried to auth as a UNIX - * user ID. Normally on Windows this would never happen. Set with - * dbus_connection_set_unix_user_function(). - */ -typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection, - unsigned long uid, - void *data); - -/** - * Called during authentication to check whether the given Windows user - * ID is allowed to connect, if the client tried to auth as a Windows - * user ID. Normally on UNIX this would never happen. Set with - * dbus_connection_set_windows_user_function(). - */ -typedef dbus_bool_t (* DBusAllowWindowsUserFunction) (DBusConnection *connection, - const char *user_sid, - void *data); - - -/** - * Called when a pending call now has a reply available. Set with - * dbus_pending_call_set_notify(). - */ -typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending, - void *user_data); - -/** - * Called when a message needs to be handled. The result indicates whether or - * not more handlers should be run. Set with dbus_connection_add_filter(). - */ -typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *connection, - DBusMessage *message, - void *user_data); -DBUS_EXPORT -DBusConnection* dbus_connection_open (const char *address, - DBusError *error); -DBUS_EXPORT -DBusConnection* dbus_connection_open_private (const char *address, - DBusError *error); -DBUS_EXPORT -DBusConnection* dbus_connection_ref (DBusConnection *connection); -DBUS_EXPORT -void dbus_connection_unref (DBusConnection *connection); -DBUS_EXPORT -void dbus_connection_close (DBusConnection *connection); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_is_authenticated (DBusConnection *connection); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_is_anonymous (DBusConnection *connection); -DBUS_EXPORT -char* dbus_connection_get_server_id (DBusConnection *connection); -DBUS_EXPORT -dbus_bool_t dbus_connection_can_send_type (DBusConnection *connection, - int type); - -DBUS_EXPORT -void dbus_connection_set_exit_on_disconnect (DBusConnection *connection, - dbus_bool_t exit_on_disconnect); -DBUS_EXPORT -void dbus_connection_flush (DBusConnection *connection); -DBUS_EXPORT -dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection, - int timeout_milliseconds); -DBUS_EXPORT -dbus_bool_t dbus_connection_read_write (DBusConnection *connection, - int timeout_milliseconds); -DBUS_EXPORT -DBusMessage* dbus_connection_borrow_message (DBusConnection *connection); -DBUS_EXPORT -void dbus_connection_return_message (DBusConnection *connection, - DBusMessage *message); -DBUS_EXPORT -void dbus_connection_steal_borrowed_message (DBusConnection *connection, - DBusMessage *message); -DBUS_EXPORT -DBusMessage* dbus_connection_pop_message (DBusConnection *connection); -DBUS_EXPORT -DBusDispatchStatus dbus_connection_get_dispatch_status (DBusConnection *connection); -DBUS_EXPORT -DBusDispatchStatus dbus_connection_dispatch (DBusConnection *connection); -DBUS_EXPORT -dbus_bool_t dbus_connection_has_messages_to_send (DBusConnection *connection); -DBUS_EXPORT -dbus_bool_t dbus_connection_send (DBusConnection *connection, - DBusMessage *message, - dbus_uint32_t *client_serial); -DBUS_EXPORT -dbus_bool_t dbus_connection_send_with_reply (DBusConnection *connection, - DBusMessage *message, - DBusPendingCall **pending_return, - int timeout_milliseconds); -DBUS_EXPORT -DBusMessage * dbus_connection_send_with_reply_and_block (DBusConnection *connection, - DBusMessage *message, - int timeout_milliseconds, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_connection_set_watch_functions (DBusConnection *connection, - DBusAddWatchFunction add_function, - DBusRemoveWatchFunction remove_function, - DBusWatchToggledFunction toggled_function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_connection_set_timeout_functions (DBusConnection *connection, - DBusAddTimeoutFunction add_function, - DBusRemoveTimeoutFunction remove_function, - DBusTimeoutToggledFunction toggled_function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -void dbus_connection_set_wakeup_main_function (DBusConnection *connection, - DBusWakeupMainFunction wakeup_main_function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -void dbus_connection_set_dispatch_status_function (DBusConnection *connection, - DBusDispatchStatusFunction function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection, - unsigned long *uid); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_unix_process_id (DBusConnection *connection, - unsigned long *pid); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_adt_audit_session_data (DBusConnection *connection, - void **data, - dbus_int32_t *data_size); -DBUS_EXPORT -void dbus_connection_set_unix_user_function (DBusConnection *connection, - DBusAllowUnixUserFunction function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_windows_user (DBusConnection *connection, - char **windows_sid_p); -DBUS_EXPORT -void dbus_connection_set_windows_user_function (DBusConnection *connection, - DBusAllowWindowsUserFunction function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -void dbus_connection_set_allow_anonymous (DBusConnection *connection, - dbus_bool_t value); -DBUS_EXPORT -void dbus_connection_set_route_peer_messages (DBusConnection *connection, - dbus_bool_t value); - - -/* Filters */ - -DBUS_EXPORT -dbus_bool_t dbus_connection_add_filter (DBusConnection *connection, - DBusHandleMessageFunction function, - void *user_data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -void dbus_connection_remove_filter (DBusConnection *connection, - DBusHandleMessageFunction function, - void *user_data); - - -/* Other */ -DBUS_EXPORT -dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -void dbus_connection_free_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -dbus_bool_t dbus_connection_set_data (DBusConnection *connection, - dbus_int32_t slot, - void *data, - DBusFreeFunction free_data_func); -DBUS_EXPORT -void* dbus_connection_get_data (DBusConnection *connection, - dbus_int32_t slot); - -DBUS_EXPORT -void dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe); - -DBUS_EXPORT -void dbus_connection_set_max_message_size (DBusConnection *connection, - long size); -DBUS_EXPORT -long dbus_connection_get_max_message_size (DBusConnection *connection); -DBUS_EXPORT -void dbus_connection_set_max_received_size (DBusConnection *connection, - long size); -DBUS_EXPORT -long dbus_connection_get_max_received_size (DBusConnection *connection); - -DBUS_EXPORT -void dbus_connection_set_max_message_unix_fds (DBusConnection *connection, - long n); -DBUS_EXPORT -long dbus_connection_get_max_message_unix_fds (DBusConnection *connection); -DBUS_EXPORT -void dbus_connection_set_max_received_unix_fds(DBusConnection *connection, - long n); -DBUS_EXPORT -long dbus_connection_get_max_received_unix_fds(DBusConnection *connection); - -DBUS_EXPORT -long dbus_connection_get_outgoing_size (DBusConnection *connection); -DBUS_EXPORT -long dbus_connection_get_outgoing_unix_fds (DBusConnection *connection); - -DBUS_EXPORT -DBusPreallocatedSend* dbus_connection_preallocate_send (DBusConnection *connection); -DBUS_EXPORT -void dbus_connection_free_preallocated_send (DBusConnection *connection, - DBusPreallocatedSend *preallocated); -DBUS_EXPORT -void dbus_connection_send_preallocated (DBusConnection *connection, - DBusPreallocatedSend *preallocated, - DBusMessage *message, - dbus_uint32_t *client_serial); - - -/* Object tree functionality */ - -/** - * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed). - * Found in #DBusObjectPathVTable. - */ -typedef void (* DBusObjectPathUnregisterFunction) (DBusConnection *connection, - void *user_data); -/** - * Called when a message is sent to a registered object path. Found in - * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path() - * or dbus_connection_register_fallback(). - */ -typedef DBusHandlerResult (* DBusObjectPathMessageFunction) (DBusConnection *connection, - DBusMessage *message, - void *user_data); - -/** - * Virtual table that must be implemented to handle a portion of the - * object path hierarchy. Attach the vtable to a particular path using - * dbus_connection_register_object_path() or - * dbus_connection_register_fallback(). - */ -struct DBusObjectPathVTable -{ - DBusObjectPathUnregisterFunction unregister_function; /**< Function to unregister this handler */ - DBusObjectPathMessageFunction message_function; /**< Function to handle messages */ - - void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */ - void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */ - void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */ - void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */ -}; - -DBUS_EXPORT -dbus_bool_t dbus_connection_try_register_object_path (DBusConnection *connection, - const char *path, - const DBusObjectPathVTable *vtable, - void *user_data, - DBusError *error); - -DBUS_EXPORT -dbus_bool_t dbus_connection_register_object_path (DBusConnection *connection, - const char *path, - const DBusObjectPathVTable *vtable, - void *user_data); - -DBUS_EXPORT -dbus_bool_t dbus_connection_try_register_fallback (DBusConnection *connection, - const char *path, - const DBusObjectPathVTable *vtable, - void *user_data, - DBusError *error); - -DBUS_EXPORT -dbus_bool_t dbus_connection_register_fallback (DBusConnection *connection, - const char *path, - const DBusObjectPathVTable *vtable, - void *user_data); -DBUS_EXPORT -dbus_bool_t dbus_connection_unregister_object_path (DBusConnection *connection, - const char *path); - -DBUS_EXPORT -dbus_bool_t dbus_connection_get_object_path_data (DBusConnection *connection, - const char *path, - void **data_p); - -DBUS_EXPORT -dbus_bool_t dbus_connection_list_registered (DBusConnection *connection, - const char *parent_path, - char ***child_entries); - -DBUS_EXPORT -dbus_bool_t dbus_connection_get_unix_fd (DBusConnection *connection, - int *fd); -DBUS_EXPORT -dbus_bool_t dbus_connection_get_socket (DBusConnection *connection, - int *fd); - -/** - * Clear a variable or struct member that contains a #DBusConnection. - * If it does not contain #NULL, the connection that was previously - * there is unreferenced with dbus_connection_unref(). - * - * For example, this function and the similar functions for - * other reference-counted types can be used in code like this: - * - * @code - * DBusConnection *conn = NULL; - * struct { ...; DBusMessage *m; ... } *larger_structure = ...; - * - * ... code that might set conn or m to be non-NULL ... - * - * dbus_clear_connection (&conn); - * dbus_clear_message (&larger_structure->m); - * @endcode - * - * @param pointer_to_connection A pointer to a variable or struct member. - * pointer_to_connection must not be #NULL, but *pointer_to_connection - * may be #NULL. - */ -static inline void -dbus_clear_connection (DBusConnection **pointer_to_connection) -{ - _dbus_clear_pointer_impl (DBusConnection, pointer_to_connection, - dbus_connection_unref); -} - -/** @} */ - - -/** - * @addtogroup DBusWatch - * @{ - */ - -#ifndef DBUS_DISABLE_DEPRECATED -DBUS_EXPORT -DBUS_DEPRECATED int dbus_watch_get_fd (DBusWatch *watch); -#endif - -DBUS_EXPORT -int dbus_watch_get_unix_fd (DBusWatch *watch); -DBUS_EXPORT -int dbus_watch_get_socket (DBusWatch *watch); -DBUS_EXPORT -unsigned int dbus_watch_get_flags (DBusWatch *watch); -DBUS_EXPORT -void* dbus_watch_get_data (DBusWatch *watch); -DBUS_EXPORT -void dbus_watch_set_data (DBusWatch *watch, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_watch_handle (DBusWatch *watch, - unsigned int flags); -DBUS_EXPORT -dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch); - -/** @} */ - -/** - * @addtogroup DBusTimeout - * @{ - */ - -DBUS_EXPORT -int dbus_timeout_get_interval (DBusTimeout *timeout); -DBUS_EXPORT -void* dbus_timeout_get_data (DBusTimeout *timeout); -DBUS_EXPORT -void dbus_timeout_set_data (DBusTimeout *timeout, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_timeout_handle (DBusTimeout *timeout); -DBUS_EXPORT -dbus_bool_t dbus_timeout_get_enabled (DBusTimeout *timeout); - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_CONNECTION_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-errors.h b/externals/shared/lib/znfde/includes/dbus/dbus-errors.h deleted file mode 100644 index 945ddb4c4..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-errors.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-errors.h Error reporting - * - * Copyright (C) 2002 Red Hat Inc. - * Copyright (C) 2003 CodeFactory AB - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_ERROR_H -#define DBUS_ERROR_H - -#include -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusErrors - * @{ - */ - -/** Mostly-opaque type representing an error that occurred */ -typedef struct DBusError DBusError; - -/** - * Object representing an exception. - */ -struct DBusError -{ - const char *name; /**< public error name field */ - const char *message; /**< public error message field */ - - unsigned int dummy1 : 1; /**< placeholder */ - unsigned int dummy2 : 1; /**< placeholder */ - unsigned int dummy3 : 1; /**< placeholder */ - unsigned int dummy4 : 1; /**< placeholder */ - unsigned int dummy5 : 1; /**< placeholder */ - - void *padding1; /**< placeholder */ -}; - -#define DBUS_ERROR_INIT { NULL, NULL, TRUE, 0, 0, 0, 0, NULL } - -DBUS_EXPORT -void dbus_error_init (DBusError *error); -DBUS_EXPORT -void dbus_error_free (DBusError *error); -DBUS_EXPORT -void dbus_set_error (DBusError *error, - const char *name, - const char *message, - ...) _DBUS_GNUC_PRINTF (3, 4); -DBUS_EXPORT -void dbus_set_error_const (DBusError *error, - const char *name, - const char *message); -DBUS_EXPORT -void dbus_move_error (DBusError *src, - DBusError *dest); -DBUS_EXPORT -dbus_bool_t dbus_error_has_name (const DBusError *error, - const char *name); -DBUS_EXPORT -dbus_bool_t dbus_error_is_set (const DBusError *error); - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_ERROR_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-macros.h b/externals/shared/lib/znfde/includes/dbus/dbus-macros.h deleted file mode 100644 index 80faed294..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-macros.h +++ /dev/null @@ -1,251 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-macros.h generic macros - * - * Copyright (C) 2002 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_MACROS_H -#define DBUS_MACROS_H - -#ifdef __cplusplus -# define DBUS_BEGIN_DECLS extern "C" { -# define DBUS_END_DECLS } -#else -# define DBUS_BEGIN_DECLS -# define DBUS_END_DECLS -#endif - -#ifndef TRUE -# define TRUE 1 -#endif -#ifndef FALSE -# define FALSE 0 -#endif - -#ifndef NULL -# ifdef __cplusplus -# define NULL (0L) -# else /* !__cplusplus */ -# define NULL ((void*) 0) -# endif /* !__cplusplus */ -#endif - -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) -# define DBUS_DEPRECATED __attribute__ ((__deprecated__)) -#elif defined(_MSC_VER) && (_MSC_VER >= 1300) -# define DBUS_DEPRECATED __declspec(deprecated) -#else -# define DBUS_DEPRECATED -#endif - -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) -# define _DBUS_GNUC_EXTENSION __extension__ -#else -# define _DBUS_GNUC_EXTENSION -#endif - -#if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)) || \ - defined(__clang__) -#define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \ - __attribute__((__format__ (__printf__, format_idx, arg_idx))) -#define _DBUS_GNUC_NORETURN \ - __attribute__((__noreturn__)) -#define _DBUS_GNUC_UNUSED \ - __attribute__((__unused__)) -#else /* !__GNUC__ */ -#define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) -#define _DBUS_GNUC_NORETURN -#define _DBUS_GNUC_UNUSED -#endif /* !__GNUC__ */ - -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) -#define DBUS_MALLOC __attribute__((__malloc__)) -#else -#define DBUS_MALLOC -#endif - -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) -#define DBUS_ALLOC_SIZE(x) __attribute__((__alloc_size__(x))) -#define DBUS_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y))) -#else -#define DBUS_ALLOC_SIZE(x) -#define DBUS_ALLOC_SIZE2(x,y) -#endif - -/** @def _DBUS_WARN_UNUSED_RESULT - * - * An attribute for functions whose result must be checked by the caller. - * - * This macro is used in function declarations. Unlike gcc-specific - * attributes, to avoid compilation failure with MSVC it must appear - * somewhere before the function name in the declaration. Our preferred - * coding style is to place it before the return type, for example: - * - * DBUS_PRIVATE_EXPORT _DBUS_WARN_UNUSED_RESULT - * dbus_bool_t _dbus_user_database_lock_system (void); - */ -#if defined(_MSC_VER) && (_MSC_VER >= 1700) -#define _DBUS_WARN_UNUSED_RESULT _Must_inspect_result_ -#elif (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -#define _DBUS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -#define _DBUS_WARN_UNUSED_RESULT -#endif - -/** @def _DBUS_GNUC_PRINTF - * used to tell gcc about printf format strings - */ -/** @def _DBUS_GNUC_NORETURN - * used to tell gcc about functions that never return, such as _dbus_abort() - */ - -/* Normally docs are in .c files, but there isn't a .c file for this. */ -/** - * @defgroup DBusMacros Utility macros - * @ingroup DBus - * @brief #TRUE, #FALSE, #NULL, and so on - * - * Utility macros. - * - * @{ - */ - -/** - * @def DBUS_BEGIN_DECLS - * - * Macro used prior to declaring functions in the D-Bus header - * files. Expands to "extern "C"" when using a C++ compiler, - * and expands to nothing when using a C compiler. - * - * Please don't use this in your own code, consider it - * D-Bus internal. - */ -/** - * @def DBUS_END_DECLS - * - * Macro used after declaring functions in the D-Bus header - * files. Expands to "}" when using a C++ compiler, - * and expands to nothing when using a C compiler. - * - * Please don't use this in your own code, consider it - * D-Bus internal. - */ -/** - * @def TRUE - * - * Expands to "1" - */ -/** - * @def FALSE - * - * Expands to "0" - */ -/** - * @def NULL - * - * A null pointer, defined appropriately for C or C++. - */ -/** - * @def DBUS_DEPRECATED - * - * Tells the compiler to warn about a function or type if it's used. - * Code marked in this way should also be enclosed in - * @code - * #ifndef DBUS_DISABLE_DEPRECATED - * deprecated stuff here - * #endif - * @endcode - * - * Please don't use this in your own code, consider it - * D-Bus internal. - */ -/** - * @def _DBUS_GNUC_EXTENSION - * - * Tells gcc not to warn about extensions to the C standard in the - * following expression, even if compiling with -pedantic. Do not use - * this macro in your own code; please consider it to be internal to libdbus. - */ - -/* - * @def DBUS_EXPORT - * - * Declare the following symbol as public. This is currently a noop on - * platforms other than Windows. - */ - -#if defined(DBUS_EXPORT) - /* value forced by compiler command line, don't redefine */ -#elif defined(_WIN32) -# if defined(DBUS_STATIC_BUILD) -# define DBUS_EXPORT -# elif defined(dbus_1_EXPORTS) -# define DBUS_EXPORT __declspec(dllexport) -# else -# define DBUS_EXPORT __declspec(dllimport) -# endif -#elif defined(__GNUC__) && __GNUC__ >= 4 -# define DBUS_EXPORT __attribute__ ((__visibility__ ("default"))) -#else -#define DBUS_EXPORT -#endif - -#if defined(DBUS_PRIVATE_EXPORT) - /* value forced by compiler command line, don't redefine */ -#elif defined(_WIN32) -# if defined(DBUS_STATIC_BUILD) -# define DBUS_PRIVATE_EXPORT /* no decoration */ -# elif defined(dbus_1_EXPORTS) -# define DBUS_PRIVATE_EXPORT __declspec(dllexport) -# else -# define DBUS_PRIVATE_EXPORT __declspec(dllimport) -# endif -#elif defined(__GNUC__) && __GNUC__ >= 4 -# define DBUS_PRIVATE_EXPORT __attribute__ ((__visibility__ ("default"))) -#else -# define DBUS_PRIVATE_EXPORT /* no decoration */ -#endif - -/* Implementation for dbus_clear_message() etc. This is not API, - * do not use it directly. - * - * We're using a specific type (T ** and T *) instead of void ** and - * void * partly for type-safety, partly to be strict-aliasing-compliant, - * and partly to keep C++ compilers happy. This code is inlined into - * users of libdbus, so we can't rely on it having dbus' own compiler - * settings. */ -#define _dbus_clear_pointer_impl(T, pointer_to_pointer, destroy) \ - do { \ - T **_pp = (pointer_to_pointer); \ - T *_value = *_pp; \ - \ - *_pp = NULL; \ - \ - if (_value != NULL) \ - destroy (_value); \ - } while (0) -/* Not (destroy) (_value) in case destroy() is a function-like macro */ - -/** @} */ - -#endif /* DBUS_MACROS_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-memory.h b/externals/shared/lib/znfde/includes/dbus/dbus-memory.h deleted file mode 100644 index 4dcf2f92f..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-memory.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-memory.h D-Bus memory handling - * - * Copyright (C) 2002 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_MEMORY_H -#define DBUS_MEMORY_H - -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusMemory - * @{ - */ - -DBUS_EXPORT -DBUS_MALLOC -DBUS_ALLOC_SIZE(1) -void* dbus_malloc (size_t bytes); - -DBUS_EXPORT -DBUS_MALLOC -DBUS_ALLOC_SIZE(1) -void* dbus_malloc0 (size_t bytes); - -DBUS_EXPORT -DBUS_ALLOC_SIZE(2) -void* dbus_realloc (void *memory, - size_t bytes); -DBUS_EXPORT -void dbus_free (void *memory); - -#define dbus_new(type, count) ((type*)dbus_malloc (sizeof (type) * (count))) -#define dbus_new0(type, count) ((type*)dbus_malloc0 (sizeof (type) * (count))) - -DBUS_EXPORT -void dbus_free_string_array (char **str_array); - -typedef void (* DBusFreeFunction) (void *memory); - -DBUS_EXPORT -void dbus_shutdown (void); - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_MEMORY_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-message.h b/externals/shared/lib/znfde/includes/dbus/dbus-message.h deleted file mode 100644 index da2f2d9de..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-message.h +++ /dev/null @@ -1,383 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-message.h DBusMessage object - * - * Copyright (C) 2002, 2003, 2005 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_MESSAGE_H -#define DBUS_MESSAGE_H - -#include -#include -#include -#include -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusMessage - * @{ - */ - -typedef struct DBusMessage DBusMessage; -/** - * Opaque type representing a message iterator. Can be copied by value and - * allocated on the stack. - * - * A DBusMessageIter usually contains no allocated memory. However, there - * is one special case: after a successful call to - * dbus_message_iter_open_container(), the caller is responsible for calling - * either dbus_message_iter_close_container() or - * dbus_message_iter_abandon_container() exactly once, with the same pair - * of iterators. - */ -typedef struct DBusMessageIter DBusMessageIter; - -/** - * DBusMessageIter struct; contains no public fields. - */ -struct DBusMessageIter -{ - void *dummy1; /**< Don't use this */ - void *dummy2; /**< Don't use this */ - dbus_uint32_t dummy3; /**< Don't use this */ - int dummy4; /**< Don't use this */ - int dummy5; /**< Don't use this */ - int dummy6; /**< Don't use this */ - int dummy7; /**< Don't use this */ - int dummy8; /**< Don't use this */ - int dummy9; /**< Don't use this */ - int dummy10; /**< Don't use this */ - int dummy11; /**< Don't use this */ - int pad1; /**< Don't use this */ - void *pad2; /**< Don't use this */ - void *pad3; /**< Don't use this */ -}; - -/** - * A message iterator for which dbus_message_iter_abandon_container_if_open() - * is the only valid operation. - */ -#define DBUS_MESSAGE_ITER_INIT_CLOSED \ -{ \ - NULL, /* dummy1 */ \ - NULL, /* dummy2 */ \ - 0, /* dummy3 */ \ - 0, /* dummy4 */ \ - 0, /* dummy5 */ \ - 0, /* dummy6 */ \ - 0, /* dummy7 */ \ - 0, /* dummy8 */ \ - 0, /* dummy9 */ \ - 0, /* dummy10 */ \ - 0, /* dummy11 */ \ - 0, /* pad1 */ \ - NULL, /* pad2 */ \ - NULL /* pad3 */ \ -} - -DBUS_EXPORT -DBusMessage* dbus_message_new (int message_type); -DBUS_EXPORT -DBusMessage* dbus_message_new_method_call (const char *bus_name, - const char *path, - const char *iface, - const char *method); -DBUS_EXPORT -DBusMessage* dbus_message_new_method_return (DBusMessage *method_call); -DBUS_EXPORT -DBusMessage* dbus_message_new_signal (const char *path, - const char *iface, - const char *name); -DBUS_EXPORT -DBusMessage* dbus_message_new_error (DBusMessage *reply_to, - const char *error_name, - const char *error_message); -DBUS_EXPORT -DBusMessage* dbus_message_new_error_printf (DBusMessage *reply_to, - const char *error_name, - const char *error_format, - ...) _DBUS_GNUC_PRINTF (3, 4); - -DBUS_EXPORT -DBusMessage* dbus_message_copy (const DBusMessage *message); - -DBUS_EXPORT -DBusMessage* dbus_message_ref (DBusMessage *message); -DBUS_EXPORT -void dbus_message_unref (DBusMessage *message); -DBUS_EXPORT -int dbus_message_get_type (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_set_path (DBusMessage *message, - const char *object_path); -DBUS_EXPORT -const char* dbus_message_get_path (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_has_path (DBusMessage *message, - const char *object_path); -DBUS_EXPORT -dbus_bool_t dbus_message_set_interface (DBusMessage *message, - const char *iface); -DBUS_EXPORT -const char* dbus_message_get_interface (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_has_interface (DBusMessage *message, - const char *iface); -DBUS_EXPORT -dbus_bool_t dbus_message_set_member (DBusMessage *message, - const char *member); -DBUS_EXPORT -const char* dbus_message_get_member (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_has_member (DBusMessage *message, - const char *member); -DBUS_EXPORT -dbus_bool_t dbus_message_set_error_name (DBusMessage *message, - const char *name); -DBUS_EXPORT -const char* dbus_message_get_error_name (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_set_destination (DBusMessage *message, - const char *destination); -DBUS_EXPORT -const char* dbus_message_get_destination (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_set_sender (DBusMessage *message, - const char *sender); -DBUS_EXPORT -const char* dbus_message_get_sender (DBusMessage *message); -DBUS_EXPORT -const char* dbus_message_get_signature (DBusMessage *message); -DBUS_EXPORT -void dbus_message_set_no_reply (DBusMessage *message, - dbus_bool_t no_reply); -DBUS_EXPORT -dbus_bool_t dbus_message_get_no_reply (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_is_method_call (DBusMessage *message, - const char *iface, - const char *method); -DBUS_EXPORT -dbus_bool_t dbus_message_is_signal (DBusMessage *message, - const char *iface, - const char *signal_name); -DBUS_EXPORT -dbus_bool_t dbus_message_is_error (DBusMessage *message, - const char *error_name); -DBUS_EXPORT -dbus_bool_t dbus_message_has_destination (DBusMessage *message, - const char *bus_name); -DBUS_EXPORT -dbus_bool_t dbus_message_has_sender (DBusMessage *message, - const char *unique_bus_name); -DBUS_EXPORT -dbus_bool_t dbus_message_has_signature (DBusMessage *message, - const char *signature); -DBUS_EXPORT -dbus_uint32_t dbus_message_get_serial (DBusMessage *message); -DBUS_EXPORT -void dbus_message_set_serial (DBusMessage *message, - dbus_uint32_t serial); -DBUS_EXPORT -dbus_bool_t dbus_message_set_reply_serial (DBusMessage *message, - dbus_uint32_t reply_serial); -DBUS_EXPORT -dbus_uint32_t dbus_message_get_reply_serial (DBusMessage *message); - -DBUS_EXPORT -void dbus_message_set_auto_start (DBusMessage *message, - dbus_bool_t auto_start); -DBUS_EXPORT -dbus_bool_t dbus_message_get_auto_start (DBusMessage *message); - -DBUS_EXPORT -dbus_bool_t dbus_message_get_path_decomposed (DBusMessage *message, - char ***path); - -DBUS_EXPORT -const char *dbus_message_get_container_instance (DBusMessage *message); -DBUS_EXPORT -dbus_bool_t dbus_message_set_container_instance (DBusMessage *message, - const char *object_path); - -DBUS_EXPORT -dbus_bool_t dbus_message_append_args (DBusMessage *message, - int first_arg_type, - ...); -DBUS_EXPORT -dbus_bool_t dbus_message_append_args_valist (DBusMessage *message, - int first_arg_type, - va_list var_args); -DBUS_EXPORT -dbus_bool_t dbus_message_get_args (DBusMessage *message, - DBusError *error, - int first_arg_type, - ...); -DBUS_EXPORT -dbus_bool_t dbus_message_get_args_valist (DBusMessage *message, - DBusError *error, - int first_arg_type, - va_list var_args); - -DBUS_EXPORT -dbus_bool_t dbus_message_contains_unix_fds (DBusMessage *message); - -DBUS_EXPORT -void dbus_message_iter_init_closed (DBusMessageIter *iter); -DBUS_EXPORT -dbus_bool_t dbus_message_iter_init (DBusMessage *message, - DBusMessageIter *iter); -DBUS_EXPORT -dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter); -DBUS_EXPORT -dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter); -DBUS_EXPORT -char* dbus_message_iter_get_signature (DBusMessageIter *iter); -DBUS_EXPORT -int dbus_message_iter_get_arg_type (DBusMessageIter *iter); -DBUS_EXPORT -int dbus_message_iter_get_element_type (DBusMessageIter *iter); -DBUS_EXPORT -void dbus_message_iter_recurse (DBusMessageIter *iter, - DBusMessageIter *sub); -DBUS_EXPORT -void dbus_message_iter_get_basic (DBusMessageIter *iter, - void *value); -DBUS_EXPORT -int dbus_message_iter_get_element_count(DBusMessageIter *iter); - -#ifndef DBUS_DISABLE_DEPRECATED -/* This function returns the wire protocol size of the array in bytes, - * you do not want to know that probably - */ -DBUS_EXPORT -DBUS_DEPRECATED int dbus_message_iter_get_array_len (DBusMessageIter *iter); -#endif -DBUS_EXPORT -void dbus_message_iter_get_fixed_array (DBusMessageIter *iter, - void *value, - int *n_elements); - - -DBUS_EXPORT -void dbus_message_iter_init_append (DBusMessage *message, - DBusMessageIter *iter); -DBUS_EXPORT -dbus_bool_t dbus_message_iter_append_basic (DBusMessageIter *iter, - int type, - const void *value); -DBUS_EXPORT -dbus_bool_t dbus_message_iter_append_fixed_array (DBusMessageIter *iter, - int element_type, - const void *value, - int n_elements); -DBUS_EXPORT -dbus_bool_t dbus_message_iter_open_container (DBusMessageIter *iter, - int type, - const char *contained_signature, - DBusMessageIter *sub); -DBUS_EXPORT -dbus_bool_t dbus_message_iter_close_container (DBusMessageIter *iter, - DBusMessageIter *sub); -DBUS_EXPORT -void dbus_message_iter_abandon_container (DBusMessageIter *iter, - DBusMessageIter *sub); - -DBUS_EXPORT -void dbus_message_iter_abandon_container_if_open (DBusMessageIter *iter, - DBusMessageIter *sub); - -DBUS_EXPORT -void dbus_message_lock (DBusMessage *message); - -DBUS_EXPORT -dbus_bool_t dbus_set_error_from_message (DBusError *error, - DBusMessage *message); - - -DBUS_EXPORT -dbus_bool_t dbus_message_allocate_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -void dbus_message_free_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -dbus_bool_t dbus_message_set_data (DBusMessage *message, - dbus_int32_t slot, - void *data, - DBusFreeFunction free_data_func); -DBUS_EXPORT -void* dbus_message_get_data (DBusMessage *message, - dbus_int32_t slot); - -DBUS_EXPORT -int dbus_message_type_from_string (const char *type_str); -DBUS_EXPORT -const char* dbus_message_type_to_string (int type); - -DBUS_EXPORT -dbus_bool_t dbus_message_marshal (DBusMessage *msg, - char **marshalled_data_p, - int *len_p); -DBUS_EXPORT -DBusMessage* dbus_message_demarshal (const char *str, - int len, - DBusError *error); - -DBUS_EXPORT -int dbus_message_demarshal_bytes_needed (const char *str, - int len); - -DBUS_EXPORT -void dbus_message_set_allow_interactive_authorization (DBusMessage *message, - dbus_bool_t allow); - -DBUS_EXPORT -dbus_bool_t dbus_message_get_allow_interactive_authorization ( - DBusMessage *message); - -/** - * Clear a variable or struct member that contains a #DBusMessage. - * If it does not contain #NULL, the message that was previously - * there is unreferenced with dbus_message_unref(). - * - * This is very similar to dbus_clear_connection(): see that function - * for more details. - * - * @param pointer_to_message A pointer to a variable or struct member. - * pointer_to_message must not be #NULL, but *pointer_to_message - * may be #NULL. - */ -static inline void -dbus_clear_message (DBusMessage **pointer_to_message) -{ - _dbus_clear_pointer_impl (DBusMessage, pointer_to_message, - dbus_message_unref); -} - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_MESSAGE_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-misc.h b/externals/shared/lib/znfde/includes/dbus/dbus-misc.h deleted file mode 100644 index ff2a7e4b2..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-misc.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-misc.h A few assorted public functions that don't fit elsewhere - * - * Copyright (C) 2006 Red Hat, Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_MISC_H -#define DBUS_MISC_H - -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusMisc - * @{ - */ -DBUS_EXPORT -char* dbus_get_local_machine_id (void); - -DBUS_EXPORT -void dbus_get_version (int *major_version_p, - int *minor_version_p, - int *micro_version_p); - -DBUS_EXPORT -dbus_bool_t dbus_setenv (const char *variable, - const char *value); - -DBUS_EXPORT -char *dbus_try_get_local_machine_id (DBusError *error); - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_MISC_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-pending-call.h b/externals/shared/lib/znfde/includes/dbus/dbus-pending-call.h deleted file mode 100644 index f5122f197..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-pending-call.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-pending-call.h Object representing a call in progress. - * - * Copyright (C) 2002, 2003 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_PENDING_CALL_H -#define DBUS_PENDING_CALL_H - -#include -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusPendingCall - * @{ - */ - -#define DBUS_TIMEOUT_INFINITE ((int) 0x7fffffff) -#define DBUS_TIMEOUT_USE_DEFAULT (-1) - -DBUS_EXPORT -DBusPendingCall* dbus_pending_call_ref (DBusPendingCall *pending); -DBUS_EXPORT -void dbus_pending_call_unref (DBusPendingCall *pending); -DBUS_EXPORT -dbus_bool_t dbus_pending_call_set_notify (DBusPendingCall *pending, - DBusPendingCallNotifyFunction function, - void *user_data, - DBusFreeFunction free_user_data); -DBUS_EXPORT -void dbus_pending_call_cancel (DBusPendingCall *pending); -DBUS_EXPORT -dbus_bool_t dbus_pending_call_get_completed (DBusPendingCall *pending); -DBUS_EXPORT -DBusMessage* dbus_pending_call_steal_reply (DBusPendingCall *pending); -DBUS_EXPORT -void dbus_pending_call_block (DBusPendingCall *pending); - -DBUS_EXPORT -dbus_bool_t dbus_pending_call_allocate_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -void dbus_pending_call_free_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -dbus_bool_t dbus_pending_call_set_data (DBusPendingCall *pending, - dbus_int32_t slot, - void *data, - DBusFreeFunction free_data_func); -DBUS_EXPORT -void* dbus_pending_call_get_data (DBusPendingCall *pending, - dbus_int32_t slot); - -/** - * Clear a variable or struct member that contains a #DBusPendingCall. - * If it does not contain #NULL, the pending call that was previously - * there is unreferenced with dbus_pending_call_unref(). - * - * This is very similar to dbus_clear_connection(): see that function - * for more details. - * - * @param pointer_to_pending_call A pointer to a variable or struct member. - * pointer_to_pending_call must not be #NULL, but *pointer_to_pending_call - * may be #NULL. - */ -static inline void -dbus_clear_pending_call (DBusPendingCall **pointer_to_pending_call) -{ - _dbus_clear_pointer_impl (DBusPendingCall, pointer_to_pending_call, - dbus_pending_call_unref); -} - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_PENDING_CALL_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-protocol.h b/externals/shared/lib/znfde/includes/dbus/dbus-protocol.h deleted file mode 100644 index b3db8c611..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-protocol.h +++ /dev/null @@ -1,486 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-protocol.h D-Bus protocol constants - * - * Copyright (C) 2002, 2003 CodeFactory AB - * Copyright (C) 2004, 2005 Red Hat, Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef DBUS_PROTOCOL_H -#define DBUS_PROTOCOL_H - -/* Don't include anything in here from anywhere else. It's - * intended for use by any random library. - */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* avoids confusing emacs indentation */ -#endif -#endif - -/* Normally docs are in .c files, but there isn't a .c file for this. */ -/** - * @defgroup DBusProtocol Protocol constants - * @ingroup DBus - * - * @brief Defines constants which are part of the D-Bus protocol - * - * This header is intended for use by any library, not only libdbus. - * - * @{ - */ - - -/* Message byte order */ -#define DBUS_LITTLE_ENDIAN ('l') /**< Code marking LSB-first byte order in the wire protocol. */ -#define DBUS_BIG_ENDIAN ('B') /**< Code marking MSB-first byte order in the wire protocol. */ - -/** Protocol version. */ -#define DBUS_MAJOR_PROTOCOL_VERSION 1 - -/** Type code that is never equal to a legitimate type code */ -#define DBUS_TYPE_INVALID ((int) '\0') -/** #DBUS_TYPE_INVALID as a string literal instead of a int literal */ -#define DBUS_TYPE_INVALID_AS_STRING "\0" - -/* Primitive types */ -/** Type code marking an 8-bit unsigned integer */ -#define DBUS_TYPE_BYTE ((int) 'y') -/** #DBUS_TYPE_BYTE as a string literal instead of a int literal */ -#define DBUS_TYPE_BYTE_AS_STRING "y" -/** Type code marking a boolean */ -#define DBUS_TYPE_BOOLEAN ((int) 'b') -/** #DBUS_TYPE_BOOLEAN as a string literal instead of a int literal */ -#define DBUS_TYPE_BOOLEAN_AS_STRING "b" -/** Type code marking a 16-bit signed integer */ -#define DBUS_TYPE_INT16 ((int) 'n') -/** #DBUS_TYPE_INT16 as a string literal instead of a int literal */ -#define DBUS_TYPE_INT16_AS_STRING "n" -/** Type code marking a 16-bit unsigned integer */ -#define DBUS_TYPE_UINT16 ((int) 'q') -/** #DBUS_TYPE_UINT16 as a string literal instead of a int literal */ -#define DBUS_TYPE_UINT16_AS_STRING "q" -/** Type code marking a 32-bit signed integer */ -#define DBUS_TYPE_INT32 ((int) 'i') -/** #DBUS_TYPE_INT32 as a string literal instead of a int literal */ -#define DBUS_TYPE_INT32_AS_STRING "i" -/** Type code marking a 32-bit unsigned integer */ -#define DBUS_TYPE_UINT32 ((int) 'u') -/** #DBUS_TYPE_UINT32 as a string literal instead of a int literal */ -#define DBUS_TYPE_UINT32_AS_STRING "u" -/** Type code marking a 64-bit signed integer */ -#define DBUS_TYPE_INT64 ((int) 'x') -/** #DBUS_TYPE_INT64 as a string literal instead of a int literal */ -#define DBUS_TYPE_INT64_AS_STRING "x" -/** Type code marking a 64-bit unsigned integer */ -#define DBUS_TYPE_UINT64 ((int) 't') -/** #DBUS_TYPE_UINT64 as a string literal instead of a int literal */ -#define DBUS_TYPE_UINT64_AS_STRING "t" -/** Type code marking an 8-byte double in IEEE 754 format */ -#define DBUS_TYPE_DOUBLE ((int) 'd') -/** #DBUS_TYPE_DOUBLE as a string literal instead of a int literal */ -#define DBUS_TYPE_DOUBLE_AS_STRING "d" -/** Type code marking a UTF-8 encoded, nul-terminated Unicode string */ -#define DBUS_TYPE_STRING ((int) 's') -/** #DBUS_TYPE_STRING as a string literal instead of a int literal */ -#define DBUS_TYPE_STRING_AS_STRING "s" -/** Type code marking a D-Bus object path */ -#define DBUS_TYPE_OBJECT_PATH ((int) 'o') -/** #DBUS_TYPE_OBJECT_PATH as a string literal instead of a int literal */ -#define DBUS_TYPE_OBJECT_PATH_AS_STRING "o" -/** Type code marking a D-Bus type signature */ -#define DBUS_TYPE_SIGNATURE ((int) 'g') -/** #DBUS_TYPE_SIGNATURE as a string literal instead of a int literal */ -#define DBUS_TYPE_SIGNATURE_AS_STRING "g" -/** Type code marking a unix file descriptor */ -#define DBUS_TYPE_UNIX_FD ((int) 'h') -/** #DBUS_TYPE_UNIX_FD as a string literal instead of a int literal */ -#define DBUS_TYPE_UNIX_FD_AS_STRING "h" - -/* Compound types */ -/** Type code marking a D-Bus array type */ -#define DBUS_TYPE_ARRAY ((int) 'a') -/** #DBUS_TYPE_ARRAY as a string literal instead of a int literal */ -#define DBUS_TYPE_ARRAY_AS_STRING "a" -/** Type code marking a D-Bus variant type */ -#define DBUS_TYPE_VARIANT ((int) 'v') -/** #DBUS_TYPE_VARIANT as a string literal instead of a int literal */ -#define DBUS_TYPE_VARIANT_AS_STRING "v" - -/** STRUCT and DICT_ENTRY are sort of special since their codes can't - * appear in a type string, instead - * DBUS_STRUCT_BEGIN_CHAR/DBUS_DICT_ENTRY_BEGIN_CHAR have to appear - */ -/** Type code used to represent a struct; however, this type code does not appear - * in type signatures, instead #DBUS_STRUCT_BEGIN_CHAR and #DBUS_STRUCT_END_CHAR will - * appear in a signature. - */ -#define DBUS_TYPE_STRUCT ((int) 'r') -/** #DBUS_TYPE_STRUCT as a string literal instead of a int literal */ -#define DBUS_TYPE_STRUCT_AS_STRING "r" -/** Type code used to represent a dict entry; however, this type code does not appear - * in type signatures, instead #DBUS_DICT_ENTRY_BEGIN_CHAR and #DBUS_DICT_ENTRY_END_CHAR will - * appear in a signature. - */ -#define DBUS_TYPE_DICT_ENTRY ((int) 'e') -/** #DBUS_TYPE_DICT_ENTRY as a string literal instead of a int literal */ -#define DBUS_TYPE_DICT_ENTRY_AS_STRING "e" - -/** Does not include #DBUS_TYPE_INVALID, #DBUS_STRUCT_BEGIN_CHAR, #DBUS_STRUCT_END_CHAR, - * #DBUS_DICT_ENTRY_BEGIN_CHAR, or #DBUS_DICT_ENTRY_END_CHAR - i.e. it is the number of - * valid types, not the number of distinct characters that may appear in a type signature. - */ -#define DBUS_NUMBER_OF_TYPES (16) - -/* characters other than typecodes that appear in type signatures */ - -/** Code marking the start of a struct type in a type signature */ -#define DBUS_STRUCT_BEGIN_CHAR ((int) '(') -/** #DBUS_STRUCT_BEGIN_CHAR as a string literal instead of a int literal */ -#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "(" -/** Code marking the end of a struct type in a type signature */ -#define DBUS_STRUCT_END_CHAR ((int) ')') -/** #DBUS_STRUCT_END_CHAR a string literal instead of a int literal */ -#define DBUS_STRUCT_END_CHAR_AS_STRING ")" -/** Code marking the start of a dict entry type in a type signature */ -#define DBUS_DICT_ENTRY_BEGIN_CHAR ((int) '{') -/** #DBUS_DICT_ENTRY_BEGIN_CHAR as a string literal instead of a int literal */ -#define DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING "{" -/** Code marking the end of a dict entry type in a type signature */ -#define DBUS_DICT_ENTRY_END_CHAR ((int) '}') -/** #DBUS_DICT_ENTRY_END_CHAR as a string literal instead of a int literal */ -#define DBUS_DICT_ENTRY_END_CHAR_AS_STRING "}" - -/** Max length in bytes of a bus name, interface, or member (not object - * path, paths are unlimited). This is limited because lots of stuff - * is O(n) in this number, plus it would be obnoxious to type in a - * paragraph-long method name so most likely something like that would - * be an exploit. - */ -#define DBUS_MAXIMUM_NAME_LENGTH 255 - -/** This one is 255 so it fits in a byte */ -#define DBUS_MAXIMUM_SIGNATURE_LENGTH 255 - -/** Max length of a match rule string; to keep people from hosing the - * daemon with some huge rule - */ -#define DBUS_MAXIMUM_MATCH_RULE_LENGTH 1024 - -/** Max arg number you can match on in a match rule, e.g. - * arg0='hello' is OK, arg3489720987='hello' is not - */ -#define DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER 63 - -/** Max length of a marshaled array in bytes (64M, 2^26) We use signed - * int for lengths so must be INT_MAX or less. We need something a - * bit smaller than INT_MAX because the array is inside a message with - * header info, etc. so an INT_MAX array wouldn't allow the message - * overhead. The 64M number is an attempt at a larger number than - * we'd reasonably ever use, but small enough that your bus would chew - * through it fairly quickly without locking up forever. If you have - * data that's likely to be larger than this, you should probably be - * sending it in multiple incremental messages anyhow. - */ -#define DBUS_MAXIMUM_ARRAY_LENGTH (67108864) -/** Number of bits you need in an unsigned to store the max array size */ -#define DBUS_MAXIMUM_ARRAY_LENGTH_BITS 26 - -/** The maximum total message size including header and body; similar - * rationale to max array size. - */ -#define DBUS_MAXIMUM_MESSAGE_LENGTH (DBUS_MAXIMUM_ARRAY_LENGTH * 2) -/** Number of bits you need in an unsigned to store the max message size */ -#define DBUS_MAXIMUM_MESSAGE_LENGTH_BITS 27 - -/** The maximum total number of unix fds in a message. Similar - * rationale as DBUS_MAXIMUM_MESSAGE_LENGTH. However we divide by four - * given that one fd is an int and hence at least 32 bits. - */ -#define DBUS_MAXIMUM_MESSAGE_UNIX_FDS (DBUS_MAXIMUM_MESSAGE_LENGTH/4) -/** Number of bits you need in an unsigned to store the max message unix fds */ -#define DBUS_MAXIMUM_MESSAGE_UNIX_FDS_BITS (DBUS_MAXIMUM_MESSAGE_LENGTH_BITS-2) - -/** Depth of recursion in the type tree. This is automatically limited - * to DBUS_MAXIMUM_SIGNATURE_LENGTH since you could only have an array - * of array of array of ... that fit in the max signature. But that's - * probably a bit too large. - */ -#define DBUS_MAXIMUM_TYPE_RECURSION_DEPTH 32 - -/* Types of message */ - -/** This value is never a valid message type, see dbus_message_get_type() */ -#define DBUS_MESSAGE_TYPE_INVALID 0 -/** Message type of a method call message, see dbus_message_get_type() */ -#define DBUS_MESSAGE_TYPE_METHOD_CALL 1 -/** Message type of a method return message, see dbus_message_get_type() */ -#define DBUS_MESSAGE_TYPE_METHOD_RETURN 2 -/** Message type of an error reply message, see dbus_message_get_type() */ -#define DBUS_MESSAGE_TYPE_ERROR 3 -/** Message type of a signal message, see dbus_message_get_type() */ -#define DBUS_MESSAGE_TYPE_SIGNAL 4 - -#define DBUS_NUM_MESSAGE_TYPES 5 - -/* Header flags */ - -/** If set, this flag means that the sender of a message does not care about getting - * a reply, so the recipient need not send one. See dbus_message_set_no_reply(). - */ -#define DBUS_HEADER_FLAG_NO_REPLY_EXPECTED 0x1 -/** - * If set, this flag means that even if the message bus knows how to start an owner for - * the destination bus name (see dbus_message_set_destination()), it should not - * do so. If this flag is not set, the bus may launch a program to process the - * message. - */ -#define DBUS_HEADER_FLAG_NO_AUTO_START 0x2 -/** - * If set on a method call, this flag means that the caller is prepared to - * wait for interactive authorization. - */ -#define DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION 0x4 - -/* Header fields */ - -/** Not equal to any valid header field code */ -#define DBUS_HEADER_FIELD_INVALID 0 -/** Header field code for the path - the path is the object emitting a signal or the object receiving a method call. - * See dbus_message_set_path(). - */ -#define DBUS_HEADER_FIELD_PATH 1 -/** Header field code for the interface containing a member (method or signal). - * See dbus_message_set_interface(). - */ -#define DBUS_HEADER_FIELD_INTERFACE 2 -/** Header field code for a member (method or signal). See dbus_message_set_member(). */ -#define DBUS_HEADER_FIELD_MEMBER 3 -/** Header field code for an error name (found in #DBUS_MESSAGE_TYPE_ERROR messages). - * See dbus_message_set_error_name(). - */ -#define DBUS_HEADER_FIELD_ERROR_NAME 4 -/** Header field code for a reply serial, used to match a #DBUS_MESSAGE_TYPE_METHOD_RETURN message with the - * message that it's a reply to. See dbus_message_set_reply_serial(). - */ -#define DBUS_HEADER_FIELD_REPLY_SERIAL 5 -/** - * Header field code for the destination bus name of a message. See dbus_message_set_destination(). - */ -#define DBUS_HEADER_FIELD_DESTINATION 6 -/** - * Header field code for the sender of a message; usually initialized by the message bus. - * See dbus_message_set_sender(). - */ -#define DBUS_HEADER_FIELD_SENDER 7 -/** - * Header field code for the type signature of a message. - */ -#define DBUS_HEADER_FIELD_SIGNATURE 8 -/** - * Header field code for the number of unix file descriptors associated - * with this message. - */ -#define DBUS_HEADER_FIELD_UNIX_FDS 9 -/** - * Header field code for the container instance that sent this message. - */ -#define DBUS_HEADER_FIELD_CONTAINER_INSTANCE 10 - - -/** - * Value of the highest-numbered header field code, can be used to determine - * the size of an array indexed by header field code. Remember though - * that unknown codes must be ignored, so check for that before - * indexing the array. - */ -#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_CONTAINER_INSTANCE - -/** Header format is defined as a signature: - * byte byte order - * byte message type ID - * byte flags - * byte protocol version - * uint32 body length - * uint32 serial - * array of struct (byte,variant) (field name, value) - * - * The length of the header can be computed as the - * fixed size of the initial data, plus the length of - * the array at the end, plus padding to an 8-boundary. - */ -#define DBUS_HEADER_SIGNATURE \ - DBUS_TYPE_BYTE_AS_STRING \ - DBUS_TYPE_BYTE_AS_STRING \ - DBUS_TYPE_BYTE_AS_STRING \ - DBUS_TYPE_BYTE_AS_STRING \ - DBUS_TYPE_UINT32_AS_STRING \ - DBUS_TYPE_UINT32_AS_STRING \ - DBUS_TYPE_ARRAY_AS_STRING \ - DBUS_STRUCT_BEGIN_CHAR_AS_STRING \ - DBUS_TYPE_BYTE_AS_STRING \ - DBUS_TYPE_VARIANT_AS_STRING \ - DBUS_STRUCT_END_CHAR_AS_STRING - - -/** - * The smallest header size that can occur. (It won't be valid due to - * missing required header fields.) This is 4 bytes, two uint32, an - * array length. This isn't any kind of resource limit, just the - * necessary/logical outcome of the header signature. - */ -#define DBUS_MINIMUM_HEADER_SIZE 16 - -/* Errors */ -/* WARNING these get autoconverted to an enum in dbus-glib.h. Thus, - * if you change the order it breaks the ABI. Keep them in order. - * Also, don't change the formatting since that will break the sed - * script. - */ -/** A generic error; "something went wrong" - see the error message for more. */ -#define DBUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed" -/** There was not enough memory to complete an operation. */ -#define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory" -/** The bus doesn't know how to launch a service to supply the bus name you wanted. */ -#define DBUS_ERROR_SERVICE_UNKNOWN "org.freedesktop.DBus.Error.ServiceUnknown" -/** The bus name you referenced doesn't exist (i.e. no application owns it). */ -#define DBUS_ERROR_NAME_HAS_NO_OWNER "org.freedesktop.DBus.Error.NameHasNoOwner" -/** No reply to a message expecting one, usually means a timeout occurred. */ -#define DBUS_ERROR_NO_REPLY "org.freedesktop.DBus.Error.NoReply" -/** Something went wrong reading or writing to a socket, for example. */ -#define DBUS_ERROR_IO_ERROR "org.freedesktop.DBus.Error.IOError" -/** A D-Bus bus address was malformed. */ -#define DBUS_ERROR_BAD_ADDRESS "org.freedesktop.DBus.Error.BadAddress" -/** Requested operation isn't supported (like ENOSYS on UNIX). */ -#define DBUS_ERROR_NOT_SUPPORTED "org.freedesktop.DBus.Error.NotSupported" -/** Some limited resource is exhausted. */ -#define DBUS_ERROR_LIMITS_EXCEEDED "org.freedesktop.DBus.Error.LimitsExceeded" -/** Security restrictions don't allow doing what you're trying to do. */ -#define DBUS_ERROR_ACCESS_DENIED "org.freedesktop.DBus.Error.AccessDenied" -/** Authentication didn't work. */ -#define DBUS_ERROR_AUTH_FAILED "org.freedesktop.DBus.Error.AuthFailed" -/** Unable to connect to server (probably caused by ECONNREFUSED on a socket). */ -#define DBUS_ERROR_NO_SERVER "org.freedesktop.DBus.Error.NoServer" -/** Certain timeout errors, possibly ETIMEDOUT on a socket. - * Note that #DBUS_ERROR_NO_REPLY is used for message reply timeouts. - * @warning this is confusingly-named given that #DBUS_ERROR_TIMED_OUT also exists. We can't fix - * it for compatibility reasons so just be careful. - */ -#define DBUS_ERROR_TIMEOUT "org.freedesktop.DBus.Error.Timeout" -/** No network access (probably ENETUNREACH on a socket). */ -#define DBUS_ERROR_NO_NETWORK "org.freedesktop.DBus.Error.NoNetwork" -/** Can't bind a socket since its address is in use (i.e. EADDRINUSE). */ -#define DBUS_ERROR_ADDRESS_IN_USE "org.freedesktop.DBus.Error.AddressInUse" -/** The connection is disconnected and you're trying to use it. */ -#define DBUS_ERROR_DISCONNECTED "org.freedesktop.DBus.Error.Disconnected" -/** Invalid arguments passed to a method call. */ -#define DBUS_ERROR_INVALID_ARGS "org.freedesktop.DBus.Error.InvalidArgs" -/** Missing file. */ -#define DBUS_ERROR_FILE_NOT_FOUND "org.freedesktop.DBus.Error.FileNotFound" -/** Existing file and the operation you're using does not silently overwrite. */ -#define DBUS_ERROR_FILE_EXISTS "org.freedesktop.DBus.Error.FileExists" -/** Method name you invoked isn't known by the object you invoked it on. */ -#define DBUS_ERROR_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod" -/** Object you invoked a method on isn't known. */ -#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject" -/** Interface you invoked a method on isn't known by the object. */ -#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface" -/** Property you tried to access isn't known by the object. */ -#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty" -/** Property you tried to set is read-only. */ -#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly" -/** Certain timeout errors, e.g. while starting a service. - * @warning this is confusingly-named given that #DBUS_ERROR_TIMEOUT also exists. We can't fix - * it for compatibility reasons so just be careful. - */ -#define DBUS_ERROR_TIMED_OUT "org.freedesktop.DBus.Error.TimedOut" -/** Tried to remove or modify a match rule that didn't exist. */ -#define DBUS_ERROR_MATCH_RULE_NOT_FOUND "org.freedesktop.DBus.Error.MatchRuleNotFound" -/** The match rule isn't syntactically valid. */ -#define DBUS_ERROR_MATCH_RULE_INVALID "org.freedesktop.DBus.Error.MatchRuleInvalid" -/** While starting a new process, the exec() call failed. */ -#define DBUS_ERROR_SPAWN_EXEC_FAILED "org.freedesktop.DBus.Error.Spawn.ExecFailed" -/** While starting a new process, the fork() call failed. */ -#define DBUS_ERROR_SPAWN_FORK_FAILED "org.freedesktop.DBus.Error.Spawn.ForkFailed" -/** While starting a new process, the child exited with a status code. */ -#define DBUS_ERROR_SPAWN_CHILD_EXITED "org.freedesktop.DBus.Error.Spawn.ChildExited" -/** While starting a new process, the child exited on a signal. */ -#define DBUS_ERROR_SPAWN_CHILD_SIGNALED "org.freedesktop.DBus.Error.Spawn.ChildSignaled" -/** While starting a new process, something went wrong. */ -#define DBUS_ERROR_SPAWN_FAILED "org.freedesktop.DBus.Error.Spawn.Failed" -/** We failed to setup the environment correctly. */ -#define DBUS_ERROR_SPAWN_SETUP_FAILED "org.freedesktop.DBus.Error.Spawn.FailedToSetup" -/** We failed to setup the config parser correctly. */ -#define DBUS_ERROR_SPAWN_CONFIG_INVALID "org.freedesktop.DBus.Error.Spawn.ConfigInvalid" -/** Bus name was not valid. */ -#define DBUS_ERROR_SPAWN_SERVICE_INVALID "org.freedesktop.DBus.Error.Spawn.ServiceNotValid" -/** Service file not found in system-services directory. */ -#define DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND "org.freedesktop.DBus.Error.Spawn.ServiceNotFound" -/** Permissions are incorrect on the setuid helper. */ -#define DBUS_ERROR_SPAWN_PERMISSIONS_INVALID "org.freedesktop.DBus.Error.Spawn.PermissionsInvalid" -/** Service file invalid (Name, User or Exec missing). */ -#define DBUS_ERROR_SPAWN_FILE_INVALID "org.freedesktop.DBus.Error.Spawn.FileInvalid" -/** There was not enough memory to complete the operation. */ -#define DBUS_ERROR_SPAWN_NO_MEMORY "org.freedesktop.DBus.Error.Spawn.NoMemory" -/** Tried to get a UNIX process ID and it wasn't available. */ -#define DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN "org.freedesktop.DBus.Error.UnixProcessIdUnknown" -/** A type signature is not valid. */ -#define DBUS_ERROR_INVALID_SIGNATURE "org.freedesktop.DBus.Error.InvalidSignature" -/** A file contains invalid syntax or is otherwise broken. */ -#define DBUS_ERROR_INVALID_FILE_CONTENT "org.freedesktop.DBus.Error.InvalidFileContent" -/** Asked for SELinux security context and it wasn't available. */ -#define DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN "org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown" -/** Asked for ADT audit data and it wasn't available. */ -#define DBUS_ERROR_ADT_AUDIT_DATA_UNKNOWN "org.freedesktop.DBus.Error.AdtAuditDataUnknown" -/** There's already an object with the requested object path. */ -#define DBUS_ERROR_OBJECT_PATH_IN_USE "org.freedesktop.DBus.Error.ObjectPathInUse" -/** The message meta data does not match the payload. e.g. expected - number of file descriptors were not sent over the socket this message was received on. */ -#define DBUS_ERROR_INCONSISTENT_MESSAGE "org.freedesktop.DBus.Error.InconsistentMessage" -/** The message is not allowed without performing interactive authorization, - * but could have succeeded if an interactive authorization step was - * allowed. */ -#define DBUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED "org.freedesktop.DBus.Error.InteractiveAuthorizationRequired" -/** The connection is not from a container, or the specified container instance - * does not exist. */ -#define DBUS_ERROR_NOT_CONTAINER "org.freedesktop.DBus.Error.NotContainer" - -/* XML introspection format */ - -/** XML namespace of the introspection format version 1.0 */ -#define DBUS_INTROSPECT_1_0_XML_NAMESPACE "http://www.freedesktop.org/standards/dbus" -/** XML public identifier of the introspection format version 1.0 */ -#define DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" -/** XML system identifier of the introspection format version 1.0 */ -#define DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" -/** XML document type declaration of the introspection format version 1.0 */ -#define DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE "\n" - -/** @} */ - -#ifdef __cplusplus -#if 0 -{ /* avoids confusing emacs indentation */ -#endif -} -#endif - -#endif /* DBUS_PROTOCOL_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-server.h b/externals/shared/lib/znfde/includes/dbus/dbus-server.h deleted file mode 100644 index 0d84f796a..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-server.h +++ /dev/null @@ -1,125 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-server.h DBusServer object - * - * Copyright (C) 2002, 2003 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_SERVER_H -#define DBUS_SERVER_H - -#include -#include -#include -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusServer - * @{ - */ - -typedef struct DBusServer DBusServer; - -/** Called when a new connection to the server is available. Must reference and save the new - * connection, or close the new connection. Set with dbus_server_set_new_connection_function(). - */ -typedef void (* DBusNewConnectionFunction) (DBusServer *server, - DBusConnection *new_connection, - void *data); - -DBUS_EXPORT -DBusServer* dbus_server_listen (const char *address, - DBusError *error); -DBUS_EXPORT -DBusServer* dbus_server_ref (DBusServer *server); -DBUS_EXPORT -void dbus_server_unref (DBusServer *server); -DBUS_EXPORT -void dbus_server_disconnect (DBusServer *server); -DBUS_EXPORT -dbus_bool_t dbus_server_get_is_connected (DBusServer *server); -DBUS_EXPORT -char* dbus_server_get_address (DBusServer *server); -DBUS_EXPORT -char* dbus_server_get_id (DBusServer *server); -DBUS_EXPORT -void dbus_server_set_new_connection_function (DBusServer *server, - DBusNewConnectionFunction function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_server_set_watch_functions (DBusServer *server, - DBusAddWatchFunction add_function, - DBusRemoveWatchFunction remove_function, - DBusWatchToggledFunction toggled_function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_server_set_timeout_functions (DBusServer *server, - DBusAddTimeoutFunction add_function, - DBusRemoveTimeoutFunction remove_function, - DBusTimeoutToggledFunction toggled_function, - void *data, - DBusFreeFunction free_data_function); -DBUS_EXPORT -dbus_bool_t dbus_server_set_auth_mechanisms (DBusServer *server, - const char **mechanisms); - -DBUS_EXPORT -dbus_bool_t dbus_server_allocate_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -void dbus_server_free_data_slot (dbus_int32_t *slot_p); -DBUS_EXPORT -dbus_bool_t dbus_server_set_data (DBusServer *server, - int slot, - void *data, - DBusFreeFunction free_data_func); -DBUS_EXPORT -void* dbus_server_get_data (DBusServer *server, - int slot); - -/** - * Clear a variable or struct member that contains a #DBusServer. - * If it does not contain #NULL, the server that was previously - * there is unreferenced with dbus_server_unref(). - * - * This is very similar to dbus_clear_connection(): see that function - * for more details. - * - * @param pointer_to_server A pointer to a variable or struct member. - * pointer_to_server must not be #NULL, but *pointer_to_server - * may be #NULL. - */ -static inline void -dbus_clear_server (DBusServer **pointer_to_server) -{ - _dbus_clear_pointer_impl (DBusServer, pointer_to_server, dbus_server_unref); -} - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_SERVER_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-shared.h b/externals/shared/lib/znfde/includes/dbus/dbus-shared.h deleted file mode 100644 index d6a3c9893..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-shared.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-shared.h Stuff used by both dbus/dbus.h low-level and C/C++ binding APIs - * - * Copyright (C) 2004 Red Hat, Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef DBUS_SHARED_H -#define DBUS_SHARED_H - -/* Don't include anything in here from anywhere else. It's - * intended for use by any random library. - */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* avoids confusing emacs indentation */ -#endif -#endif - -/* Normally docs are in .c files, but there isn't a .c file for this. */ -/** - * @defgroup DBusShared Shared constants - * @ingroup DBus - * - * @brief Shared header included by both libdbus and C/C++ bindings such as the GLib bindings. - * - * Usually a C/C++ binding such as the GLib or Qt binding won't want to include dbus.h in its - * public headers. However, a few constants and macros may be useful to include; those are - * found here and in dbus-protocol.h - * - * @{ - */ - - -/** - * Well-known bus types. See dbus_bus_get(). - */ -typedef enum -{ - DBUS_BUS_SESSION, /**< The login session bus */ - DBUS_BUS_SYSTEM, /**< The systemwide bus */ - DBUS_BUS_STARTER /**< The bus that started us, if any */ -} DBusBusType; - -/** - * Results that a message handler can return. - */ -typedef enum -{ - DBUS_HANDLER_RESULT_HANDLED, /**< Message has had its effect - no need to run more handlers. */ - DBUS_HANDLER_RESULT_NOT_YET_HANDLED, /**< Message has not had any effect - see if other handlers want it. */ - DBUS_HANDLER_RESULT_NEED_MEMORY /**< Need more memory in order to return #DBUS_HANDLER_RESULT_HANDLED or #DBUS_HANDLER_RESULT_NOT_YET_HANDLED. Please try again later with more memory. */ -} DBusHandlerResult; - -/* Bus names */ - -/** The bus name used to talk to the bus itself. */ -#define DBUS_SERVICE_DBUS "org.freedesktop.DBus" - -/* Paths */ -/** The object path used to talk to the bus itself. */ -#define DBUS_PATH_DBUS "/org/freedesktop/DBus" -/** The object path used in local/in-process-generated messages. */ -#define DBUS_PATH_LOCAL "/org/freedesktop/DBus/Local" - -/* Interfaces, these #define don't do much other than - * catch typos at compile time - */ -/** The interface exported by the object with #DBUS_SERVICE_DBUS and #DBUS_PATH_DBUS */ -#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus" -/** The monitoring interface exported by the dbus-daemon */ -#define DBUS_INTERFACE_MONITORING "org.freedesktop.DBus.Monitoring" - -/** The verbose interface exported by the dbus-daemon */ -#define DBUS_INTERFACE_VERBOSE "org.freedesktop.DBus.Verbose" -/** The interface supported by introspectable objects */ -#define DBUS_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable" -/** The interface supported by objects with properties */ -#define DBUS_INTERFACE_PROPERTIES "org.freedesktop.DBus.Properties" -/** The interface supported by most dbus peers */ -#define DBUS_INTERFACE_PEER "org.freedesktop.DBus.Peer" - -/** This is a special interface whose methods can only be invoked - * by the local implementation (messages from remote apps aren't - * allowed to specify this interface). - */ -#define DBUS_INTERFACE_LOCAL "org.freedesktop.DBus.Local" - -/* Owner flags */ -#define DBUS_NAME_FLAG_ALLOW_REPLACEMENT 0x1 /**< Allow another service to become the primary owner if requested */ -#define DBUS_NAME_FLAG_REPLACE_EXISTING 0x2 /**< Request to replace the current primary owner */ -#define DBUS_NAME_FLAG_DO_NOT_QUEUE 0x4 /**< If we can not become the primary owner do not place us in the queue */ - -/* Replies to request for a name */ -#define DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1 /**< Service has become the primary owner of the requested name */ -#define DBUS_REQUEST_NAME_REPLY_IN_QUEUE 2 /**< Service could not become the primary owner and has been placed in the queue */ -#define DBUS_REQUEST_NAME_REPLY_EXISTS 3 /**< Service is already in the queue */ -#define DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER 4 /**< Service is already the primary owner */ - -/* Replies to releasing a name */ -#define DBUS_RELEASE_NAME_REPLY_RELEASED 1 /**< Service was released from the given name */ -#define DBUS_RELEASE_NAME_REPLY_NON_EXISTENT 2 /**< The given name does not exist on the bus */ -#define DBUS_RELEASE_NAME_REPLY_NOT_OWNER 3 /**< Service is not an owner of the given name */ - -/* Replies to service starts */ -#define DBUS_START_REPLY_SUCCESS 1 /**< Service was auto started */ -#define DBUS_START_REPLY_ALREADY_RUNNING 2 /**< Service was already running */ - -/** @} */ - -#ifdef __cplusplus -#if 0 -{ /* avoids confusing emacs indentation */ -#endif -} -#endif - -#endif /* DBUS_SHARED_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-signature.h b/externals/shared/lib/znfde/includes/dbus/dbus-signature.h deleted file mode 100644 index c9571cd0f..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-signature.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-signatures.h utility functions for D-Bus types - * - * Copyright (C) 2005 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_SIGNATURES_H -#define DBUS_SIGNATURES_H - -#include -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusSignature - * @{ - */ - -/** - * DBusSignatureIter struct; contains no public fields - */ -typedef struct -{ - void *dummy1; /**< Don't use this */ - void *dummy2; /**< Don't use this */ - dbus_uint32_t dummy8; /**< Don't use this */ - int dummy12; /**< Don't use this */ - int dummy17; /**< Don't use this */ -} DBusSignatureIter; - -DBUS_EXPORT -void dbus_signature_iter_init (DBusSignatureIter *iter, - const char *signature); - -DBUS_EXPORT -int dbus_signature_iter_get_current_type (const DBusSignatureIter *iter); - -DBUS_EXPORT -char * dbus_signature_iter_get_signature (const DBusSignatureIter *iter); - -DBUS_EXPORT -int dbus_signature_iter_get_element_type (const DBusSignatureIter *iter); - -DBUS_EXPORT -dbus_bool_t dbus_signature_iter_next (DBusSignatureIter *iter); - -DBUS_EXPORT -void dbus_signature_iter_recurse (const DBusSignatureIter *iter, - DBusSignatureIter *subiter); - -DBUS_EXPORT -dbus_bool_t dbus_signature_validate (const char *signature, - DBusError *error); - -DBUS_EXPORT -dbus_bool_t dbus_signature_validate_single (const char *signature, - DBusError *error); - -DBUS_EXPORT -dbus_bool_t dbus_type_is_valid (int typecode); - -DBUS_EXPORT -dbus_bool_t dbus_type_is_basic (int typecode); -DBUS_EXPORT -dbus_bool_t dbus_type_is_container (int typecode); -DBUS_EXPORT -dbus_bool_t dbus_type_is_fixed (int typecode); - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_SIGNATURE_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-syntax.h b/externals/shared/lib/znfde/includes/dbus/dbus-syntax.h deleted file mode 100644 index daf20f06e..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-syntax.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-syntax.h - utility functions for strings with special syntax - * - * Author: Simon McVittie - * Copyright © 2011 Nokia Corporation - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_SYNTAX_H -#define DBUS_SYNTAX_H - -#include -#include -#include - -DBUS_BEGIN_DECLS - -DBUS_EXPORT -dbus_bool_t dbus_validate_path (const char *path, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_validate_interface (const char *name, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_validate_member (const char *name, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_validate_error_name (const char *name, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_validate_bus_name (const char *name, - DBusError *error); -DBUS_EXPORT -dbus_bool_t dbus_validate_utf8 (const char *alleged_utf8, - DBusError *error); - -DBUS_END_DECLS - -#endif /* multiple-inclusion guard */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-threads.h b/externals/shared/lib/znfde/includes/dbus/dbus-threads.h deleted file mode 100644 index d30200d81..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-threads.h +++ /dev/null @@ -1,189 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-threads.h D-Bus threads handling - * - * Copyright (C) 2002 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_THREADS_H -#define DBUS_THREADS_H - -#include -#include - -DBUS_BEGIN_DECLS - -/** - * @addtogroup DBusThreads - * @{ - */ - -/** An opaque mutex type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ -typedef struct DBusMutex DBusMutex; -/** An opaque condition variable type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ -typedef struct DBusCondVar DBusCondVar; - -/** Deprecated, provide DBusRecursiveMutexNewFunction instead. */ -typedef DBusMutex* (* DBusMutexNewFunction) (void); -/** Deprecated, provide DBusRecursiveMutexFreeFunction instead. */ -typedef void (* DBusMutexFreeFunction) (DBusMutex *mutex); -/** Deprecated, provide DBusRecursiveMutexLockFunction instead. Return value is lock success, but gets ignored in practice. */ -typedef dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex); -/** Deprecated, provide DBusRecursiveMutexUnlockFunction instead. Return value is unlock success, but gets ignored in practice. */ -typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex); - -/** Creates a new recursively-lockable mutex, or returns #NULL if not - * enough memory. Can only fail due to lack of memory. Found in - * #DBusThreadFunctions. Do not just use PTHREAD_MUTEX_RECURSIVE for - * this, because it does not save/restore the recursion count when - * waiting on a condition. libdbus requires the Java-style behavior - * where the mutex is fully unlocked to wait on a condition. - */ -typedef DBusMutex* (* DBusRecursiveMutexNewFunction) (void); -/** Frees a recursively-lockable mutex. Found in #DBusThreadFunctions. - */ -typedef void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex); -/** Locks a recursively-lockable mutex. Found in #DBusThreadFunctions. - * Can only fail due to lack of memory. - */ -typedef void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex); -/** Unlocks a recursively-lockable mutex. Found in #DBusThreadFunctions. - * Can only fail due to lack of memory. - */ -typedef void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex); - -/** Creates a new condition variable. Found in #DBusThreadFunctions. - * Can only fail (returning #NULL) due to lack of memory. - */ -typedef DBusCondVar* (* DBusCondVarNewFunction) (void); -/** Frees a condition variable. Found in #DBusThreadFunctions. - */ -typedef void (* DBusCondVarFreeFunction) (DBusCondVar *cond); - -/** Waits on a condition variable. Found in - * #DBusThreadFunctions. Must work with either a recursive or - * nonrecursive mutex, whichever the thread implementation - * provides. Note that PTHREAD_MUTEX_RECURSIVE does not work with - * condition variables (does not save/restore the recursion count) so - * don't try using simply pthread_cond_wait() and a - * PTHREAD_MUTEX_RECURSIVE to implement this, it won't work right. - * - * Has no error conditions. Must succeed if it returns. - */ -typedef void (* DBusCondVarWaitFunction) (DBusCondVar *cond, - DBusMutex *mutex); - -/** Waits on a condition variable with a timeout. Found in - * #DBusThreadFunctions. Returns #TRUE if the wait did not - * time out, and #FALSE if it did. - * - * Has no error conditions. Must succeed if it returns. - */ -typedef dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond, - DBusMutex *mutex, - int timeout_milliseconds); -/** Wakes one waiting thread on a condition variable. Found in #DBusThreadFunctions. - * - * Has no error conditions. Must succeed if it returns. - */ -typedef void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond); - -/** Wakes all waiting threads on a condition variable. Found in #DBusThreadFunctions. - * - * Has no error conditions. Must succeed if it returns. - */ -typedef void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond); - -/** - * Flags indicating which functions are present in #DBusThreadFunctions. Used to allow - * the library to detect older callers of dbus_threads_init() if new possible functions - * are added to #DBusThreadFunctions. - */ -typedef enum -{ - DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0, - DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1, - DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2, - DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3, - DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4, - DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5, - DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6, - DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7, - DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8, - DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9, - DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10, - DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11, - DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12, - DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13, - DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1 -} DBusThreadFunctionsMask; - -/** - * Functions that must be implemented to make the D-Bus library - * thread-aware. - * - * If you supply both recursive and non-recursive mutexes, - * libdbus will use the non-recursive version for condition variables, - * and the recursive version in other contexts. - * - * The condition variable functions have to work with nonrecursive - * mutexes if you provide those, or with recursive mutexes if you - * don't. - */ -typedef struct -{ - unsigned int mask; /**< Mask indicating which functions are present. */ - - DBusMutexNewFunction mutex_new; /**< Function to create a mutex; optional and deprecated. */ - DBusMutexFreeFunction mutex_free; /**< Function to free a mutex; optional and deprecated. */ - DBusMutexLockFunction mutex_lock; /**< Function to lock a mutex; optional and deprecated. */ - DBusMutexUnlockFunction mutex_unlock; /**< Function to unlock a mutex; optional and deprecated. */ - - DBusCondVarNewFunction condvar_new; /**< Function to create a condition variable */ - DBusCondVarFreeFunction condvar_free; /**< Function to free a condition variable */ - DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */ - DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */ - DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */ - DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */ - - DBusRecursiveMutexNewFunction recursive_mutex_new; /**< Function to create a recursive mutex */ - DBusRecursiveMutexFreeFunction recursive_mutex_free; /**< Function to free a recursive mutex */ - DBusRecursiveMutexLockFunction recursive_mutex_lock; /**< Function to lock a recursive mutex */ - DBusRecursiveMutexUnlockFunction recursive_mutex_unlock; /**< Function to unlock a recursive mutex */ - - void (* padding1) (void); /**< Reserved for future expansion */ - void (* padding2) (void); /**< Reserved for future expansion */ - void (* padding3) (void); /**< Reserved for future expansion */ - void (* padding4) (void); /**< Reserved for future expansion */ - -} DBusThreadFunctions; - -DBUS_EXPORT -dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions); -DBUS_EXPORT -dbus_bool_t dbus_threads_init_default (void); - -/** @} */ - -DBUS_END_DECLS - -#endif /* DBUS_THREADS_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus-types.h b/externals/shared/lib/znfde/includes/dbus/dbus-types.h deleted file mode 100644 index 85f603ae1..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus-types.h +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus-types.h types such as dbus_bool_t - * - * Copyright (C) 2002 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef DBUS_TYPES_H -#define DBUS_TYPES_H - -#include -#include - -typedef dbus_uint32_t dbus_unichar_t; -/* boolean size must be fixed at 4 bytes due to wire protocol! */ -typedef dbus_uint32_t dbus_bool_t; - -/* Normally docs are in .c files, but there isn't a .c file for this. */ -/** - * @defgroup DBusTypes Basic types - * @ingroup DBus - * @brief dbus_bool_t, dbus_int32_t, etc. - * - * Typedefs for common primitive types. - * - * @{ - */ - -/** - * @typedef dbus_bool_t - * - * A boolean, valid values are #TRUE and #FALSE. - */ - -/** - * @typedef dbus_uint32_t - * - * A 32-bit unsigned integer on all platforms. - */ - -/** - * @typedef dbus_int32_t - * - * A 32-bit signed integer on all platforms. - */ - -/** - * @typedef dbus_uint16_t - * - * A 16-bit unsigned integer on all platforms. - */ - -/** - * @typedef dbus_int16_t - * - * A 16-bit signed integer on all platforms. - */ - - -/** - * @typedef dbus_uint64_t - * - * A 64-bit unsigned integer. - */ - -/** - * @typedef dbus_int64_t - * - * A 64-bit signed integer. - */ - -/** - * @def DBUS_HAVE_INT64 - * - * Always defined. - * - * In older libdbus versions, this would be undefined if there was no - * 64-bit integer type on that platform. libdbus no longer supports - * such platforms. - */ - -/** - * @def DBUS_INT64_CONSTANT - * - * Declare a 64-bit signed integer constant. The macro - * adds the necessary "LL" or whatever after the integer, - * giving a literal such as "325145246765LL" - */ - -/** - * @def DBUS_UINT64_CONSTANT - * - * Declare a 64-bit unsigned integer constant. The macro - * adds the necessary "ULL" or whatever after the integer, - * giving a literal such as "325145246765ULL" - */ - -/** - * An 8-byte struct you could use to access int64 without having - * int64 support. Use #dbus_int64_t or #dbus_uint64_t instead. - */ -typedef struct -{ - dbus_uint32_t first32; /**< first 32 bits in the 8 bytes (beware endian issues) */ - dbus_uint32_t second32; /**< second 32 bits in the 8 bytes (beware endian issues) */ -} DBus8ByteStruct; - -/** - * A simple value union that lets you access bytes as if they - * were various types; useful when dealing with basic types via - * void pointers and varargs. - * - * This union also contains a pointer member (which can be used - * to retrieve a string from dbus_message_iter_get_basic(), for - * instance), so on future platforms it could conceivably be larger - * than 8 bytes. - */ -typedef union -{ - unsigned char bytes[8]; /**< as 8 individual bytes */ - dbus_int16_t i16; /**< as int16 */ - dbus_uint16_t u16; /**< as int16 */ - dbus_int32_t i32; /**< as int32 */ - dbus_uint32_t u32; /**< as int32 */ - dbus_bool_t bool_val; /**< as boolean */ - dbus_int64_t i64; /**< as int64 */ - dbus_uint64_t u64; /**< as int64 */ - DBus8ByteStruct eight; /**< as 8-byte struct */ - double dbl; /**< as double */ - unsigned char byt; /**< as byte */ - char *str; /**< as char* (string, object path or signature) */ - int fd; /**< as Unix file descriptor */ -} DBusBasicValue; - -/** @} */ - -#endif /* DBUS_TYPES_H */ diff --git a/externals/shared/lib/znfde/includes/dbus/dbus.h b/externals/shared/lib/znfde/includes/dbus/dbus.h deleted file mode 100644 index dbfe6761f..000000000 --- a/externals/shared/lib/znfde/includes/dbus/dbus.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* dbus.h Convenience header including all other headers - * - * Copyright (C) 2002, 2003 Red Hat Inc. - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef DBUS_H -#define DBUS_H - -#define DBUS_INSIDE_DBUS_H 1 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#undef DBUS_INSIDE_DBUS_H - -/** - * @defgroup DBus D-Bus low-level public API - * @brief The low-level public API of the D-Bus library - * - * libdbus provides a low-level C API intended primarily for use by - * bindings to specific object systems and languages. D-Bus is most - * convenient when used with the GLib bindings, Python bindings, Qt - * bindings, Mono bindings, and so forth. This low-level API has a - * lot of complexity useful only for bindings. - * - * @{ - */ - -/** @} */ - -/** - * @mainpage - * - * This manual documents the low-level D-Bus C API. If you use - * this low-level API directly, you're signing up for some pain. - * - * Caveats aside, you might get started learning the low-level API by reading - * about @ref DBusConnection and @ref DBusMessage. - * - * There are several other places to look for D-Bus information, such - * as the tutorial and the specification; those can be found at the D-Bus - * website. If you're interested in a sysadmin or package - * maintainer's perspective on the dbus-daemon itself and its - * configuration, be sure to check out the man pages as well. - * - * The low-level API documented in this manual deliberately lacks - * most convenience functions - those are left up to higher-level libraries - * based on frameworks such as GLib, Qt, Python, Mono, Java, - * etc. These higher-level libraries (often called "D-Bus bindings") - * have features such as object systems and main loops that allow a - * much more convenient API. - * - * The low-level API also contains plenty of clutter to support - * integration with arbitrary object systems, languages, main loops, - * and so forth. These features add a lot of noise to the API that you - * probably don't care about unless you're coding a binding. - * - * This manual also contains docs for @ref DBusInternals "D-Bus internals", - * so you can use it to get oriented to the D-Bus source code if you're - * interested in patching the code. You should also read the - * file CONTRIBUTING.md which comes with the source code if you plan to - * contribute to D-Bus. - * - * As you read the code, you can identify internal D-Bus functions - * because they start with an underscore ('_') character. Also, any - * identifier or macro that lacks a DBus, dbus_, or DBUS_ namepace - * prefix is internal, with a couple of exceptions such as #NULL, - * #TRUE, and #FALSE. - */ - -#endif /* DBUS_H */ diff --git a/externals/shared/lib/znfde/nativefiledialog/LICENSE b/externals/shared/lib/znfde/nativefiledialog/LICENSE deleted file mode 100644 index 3ab103c55..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/LICENSE +++ /dev/null @@ -1,16 +0,0 @@ -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. - diff --git a/externals/shared/lib/znfde/nativefiledialog/README.md b/externals/shared/lib/znfde/nativefiledialog/README.md deleted file mode 100644 index ac87ed5e6..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/README.md +++ /dev/null @@ -1,310 +0,0 @@ - -# Native File Dialog Extended - -![GitHub Actions](https://github.com/btzy/nativefiledialog-extended/workflows/build/badge.svg) - -A small C library with that portably invokes native file open, folder select and file save dialogs. Write dialog code once and have it pop up native dialogs on all supported platforms. Avoid linking large dependencies like wxWidgets and Qt. - -This library is based on Michael Labbe's Native File Dialog ([mlabbe/nativefiledialog](https://github.com/mlabbe/nativefiledialog)). - -Features: - -- Lean C API, static library — no C++/ObjC runtime needed -- Supports Windows (MSVC, MinGW, Clang), MacOS (Clang), and Linux (GTK, portal) (GCC, Clang) -- Zlib licensed -- Friendly names for filters (e.g. `C/C++ Source files (*.c;*.cpp)` instead of `(*.c;*.cpp)`) on platforms that support it -- Automatically append file extension on platforms where users expect it -- Support for setting a default folder path -- Support for setting a default file name (e.g. `Untitled.c`) -- Consistent UTF-8 support on all platforms -- Native character set (UTF-16 `wchar_t`) support on Windows -- Initialization and de-initialization of platform library (e.g. COM (Windows) / GTK (Linux GTK) / D-Bus (Linux portal)) decoupled from dialog functions, so applications can choose when to initialize/de-initialize -- Multiple file selection support (for file open dialog) -- Support for Vista's modern `IFileDialog` on Windows -- No third party dependencies -- Modern CMake build system -- Works alongside [SDL2](http://www.libsdl.org) on all platforms -- Optional C++ wrapper with `unique_ptr` auto-freeing semantics and optional parameters, for those using this library from C++ - -**Comparison with original Native File Dialog:** - -The friendly names feature is the primary reason for breaking API compatibility with Michael Labbe's library (and hence this library probably will never be merged with it). There are also a number of tweaks that cause observable differences in this library. - -Features added in Native File Dialog Extended: - -- Friendly names for filters -- Automatically appending file extensions -- Support for setting a default file name -- Native character set (UTF-16 `wchar_t`) support on Windows -- xdg-desktop-portal support on Linux that opens the "native" file chooser (see "Usage" section below) -- Initialization and de-initialization of platform library decoupled from file dialog functions -- Modern CMake build system -- Optional C++ wrapper with `unique_ptr` auto-freeing semantics and optional parameters - -There is also significant code refractoring, especially for the Windows implementation. - -The [wiki](https://github.com/btzy/nativefiledialog-extended/wiki) keeps track of known language bindings and known popular projects that depend on this library. - -# Basic Usage - -```C -#include -#include -#include - -int main(void) -{ - - NFD_Init(); - - nfdchar_t *outPath; - nfdfilteritem_t filterItem[2] = { { "Source code", "c,cpp,cc" }, { "Headers", "h,hpp" } }; - nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL); - if (result == NFD_OKAY) - { - puts("Success!"); - puts(outPath); - NFD_FreePath(outPath); - } - else if (result == NFD_CANCEL) - { - puts("User pressed cancel."); - } - else - { - printf("Error: %s\n", NFD_GetError()); - } - - NFD_Quit(); - return 0; -} -``` - -See [NFD.h](src/include/nfd.h) for more options. - -If you are using a platform abstraction framework such as SDL or GLFW, also see the "Usage" section below. - -# Screenshots # - -![Windows 10](screens/open_win10.png?raw=true#gh-light-mode-only) -![Windows 10](screens/open_win10_dark.png?raw=true#gh-dark-mode-only) -![MacOS 10.13](screens/open_macos_11.0.png?raw=true#gh-light-mode-only) -![MacOS 10.13](screens/open_macos_11.0_dark.png?raw=true#gh-dark-mode-only) -![GTK3 on Ubuntu 20.04](screens/open_gtk3.png?raw=true#gh-light-mode-only) -![GTK3 on Ubuntu 20.04](screens/open_gtk3_dark.png?raw=true#gh-dark-mode-only) - -# Building - -## CMake Projects -If your project uses CMake, -simply add the following lines to your CMakeLists.txt: -``` -add_subdirectory(path/to/nativefiledialog-extended) -target_link_libraries(MyProgram PRIVATE nfd) -``` -Make sure that you also have the needed [dependencies](#dependencies). - -When included as a subproject, sample programs are not built and the install target is disabled by default. -Add `-DNFD_BUILD_TESTS=ON` to build sample programs and `-DNFD_INSTALL=ON` to enable the install target. - -## Standalone Library -If you want to build the standalone static library, -execute the following commands (starting from the project root directory): - -For GCC and Clang: -``` -mkdir build -cd build -cmake -DCMAKE_BUILD_TYPE=Release .. -cmake --build . -``` - -For MSVC: -``` -mkdir build -cd build -cmake .. -cmake --build . --config Release -``` - -The above commands will make a `build` directory, -and build the project (in release mode) there. -If you are developing NFDe, you may want to do `-DCMAKE_BUILD_TYPE=Debug`/`--config Debug` -to build a debug version of the library instead. - -When building as a standalone library, sample programs are built and the install target is enabled by default. -Add `-DNFD_BUILD_TESTS=OFF` to disable building sample programs and `-DNFD_INSTALL=OFF` to disable the install target. - -On Linux, if you want to use the Flatpak desktop portal instead of GTK, add `-DNFD_PORTAL=ON`. (Otherwise, GTK will be used.) See the "Usage" section below for more information. - -See the [CI build file](.github/workflows/cmake.yml) for some example build commands. - -### Visual Studio on Windows -Recent versions of Visual Studio have CMake support built into the IDE. -You should be able to "Open Folder" in the project root directory, -and Visual Studio will recognize and configure the project appropriately. -From there, you will be able to set configurations for Debug vs Release, -and for x86 vs x64. -For more information, see [the Microsoft Docs page]([https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019)). -This has been tested to work on Visual Studio 2019, -and it probably works on Visual Studio 2017 too. - -### Compiling Your Programs - - 1. Add `src/include` to your include search path. - 2. Add `nfd.lib` or `nfd_d.lib` to the list of static libraries to link against (for release or debug, respectively). - 3. Add `build//` to the library search path. - -## Dependencies - -### Linux - -#### GTK (default) -Make sure `libgtk-3-dev` is installed on your system. - -#### Portal -Make sure `libdbus-1-dev` is installed on your system. - -### MacOS -On MacOS, add `AppKit` and `UniformTypeIdentifiers` to the list of frameworks. - -### Windows -On Windows (both MSVC and MinGW), ensure you are building against `ole32.lib`, `uuid.lib`, and `shell32.lib`. - -# Usage - -See `NFD.h` for API calls. See the `test` directory for example code (both C and C++). - -If you turned on the option to build the `test` directory (`-DNFD_BUILD_TESTS=ON`), then `build/bin` will contain the compiled test programs. - -## File Filter Syntax - -Files can be filtered by file extension groups: - -```C -nfdfilteritem_t filterItem[2] = { { "Source code", "c,cpp,cc" }, { "Headers", "h,hpp" } }; -``` - -A file filter is a pair of strings comprising the friendly name and the specification (multiple file extensions are comma-separated). - -A list of file filters can be passed as an argument when invoking the library. - -A wildcard filter is always added to every dialog. - -*Note: On MacOS, the file dialogs do not have friendly names and there is no way to switch between filters, so the filter specifications are combined (e.g. "c,cpp,cc,h,hpp"). The filter specification is also never explicitly shown to the user. This is usual MacOS behaviour and users expect it.* - -*Note 2: You must ensure that the specification string is non-empty and that every file extension has at least one character. Otherwise, bad things might ensue (i.e. undefined behaviour).* - -*Note 3: On Linux, the file extension is appended (if missing) when the user presses down the "Save" button. The appended file extension will remain visible to the user, even if an overwrite prompt is shown and the user then presses "Cancel".* - -*Note 4: On Windows, the default folder parameter is only used if there is no recently used folder available. Otherwise, the default folder will be the folder that was last used. Internally, the Windows implementation calls [IFileDialog::SetDefaultFolder(IShellItem)](https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifiledialog-setdefaultfolder). This is usual Windows behaviour and users expect it.* - -## Iterating Over PathSets - -A file open dialog that supports multiple selection produces a PathSet, which is a thin abstraction over the platform-specific collection. There are two ways to iterate over a PathSet: - -### Accessing by index - -This method does array-like access on the PathSet, and is the easiest to use. -However, on certain platforms (Linux, and possibly Windows), -it takes O(N2) time in total to iterate the entire PathSet, -because the underlying platform-specific implementation uses a linked list. - -See [test_opendialogmultiple.c](test/test_opendialogmultiple.c). - -### Using an enumerator (experimental) - -This method uses an enumerator object to iterate the paths in the PathSet. -It is guaranteed to take O(N) time in total to iterate the entire PathSet. - -See [test_opendialogmultiple_enum.c](test/test_opendialogmultiple_enum.c). - -This API is experimental, and subject to change. - -## Customization Macros - -You can define the following macros *before* including `nfd.h`/`nfd.hpp`: - -- `NFD_NATIVE`: Define this before including `nfd.h` to make non-suffixed function names and typedefs (e.g. `NFD_OpenDialog`) aliases for the native functions (e.g. `NFD_OpenDialogN`) instead of aliases for the UTF-8 functions (e.g. `NFD_OpenDialogU8`). This macro does not affect the C++ wrapper `nfd.hpp`. -- `NFD_THROWS_EXCEPTIONS`: (C++ only) Define this before including `nfd.hpp` to make `NFD::Guard` construction throw `std::runtime_error` if `NFD_Init` fails. Otherwise, there is no way to detect failure in `NFD::Guard` construction. - -Macros that might be defined by `nfd.h`: - -- `NFD_DIFFERENT_NATIVE_FUNCTIONS`: Defined if the native and UTF-8 versions of functions are different (i.e. compiling for Windows); not defined otherwise. If `NFD_DIFFERENT_NATIVE_FUNCTIONS` is not defined, then the UTF-8 versions of functions are aliases for the native versions. This might be useful if you are writing a function that wants to provide overloads depending on whether the native functions and UTF-8 functions are the same. (Native is UTF-16 (`wchar_t`) for Windows and UTF-8 (`char`) for Mac/Linux.) - -## Usage with a Platform Abstraction Framework - -NFDe is known to work with SDL2 and GLFW, and should also work with other platform abstraction framworks. However, you should initialize NFDe _after_ initializing the framework, and probably should deinitialize NFDe _before_ deinitializing the framework. This is because some frameworks expect to be initialized on a "clean slate", and they may configure the system in a different way from NFDe. `NFD_Init` is generally very careful not to disrupt the existing configuration unless necessary, and `NFD_Quit` restores the configuration back exactly to what it was before initialization. - -An example with SDL2: - -``` -// Initialize SDL2 first -if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) { - // display some error here -} - -// Then initialize NFDe -if (NFD_Init() != NFD_OKAY) { - // display some error here -} - -/* -Your main program goes here -*/ - -NFD_Quit(); // deinitialize NFDe first - -SDL_Quit(); // Then deinitialize SDL2 -``` - -## Using xdg-desktop-portal on Linux - -On Linux, you can use the portal implementation instead of GTK, which will open the "native" file chooser selected by the OS or customized by the user. The user must have `xdg-desktop-portal` and a suitable backend installed (this comes pre-installed with most common desktop distros), otherwise `NFD_ERROR` will be returned. - -To use the portal implementation, add `-DNFD_PORTAL=ON` to the build command. - -*Note: Setting a default path is not supported by the portal implementation, and any default path passed to NFDe will be ignored. This is a limitation of the portal API, so there is no way NFDe can work around it. If this feature is something you desire, please show your interest on https://github.com/flatpak/xdg-desktop-portal/pull/874.* - -*Note 2: The folder picker is only supported on org.freedesktop.portal.FileChooser interface version >= 3, which corresponds to xdg-desktop-portal version >= 1.7.1. `NFD_PickFolder()` will query the interface version at runtime, and return `NFD_ERROR` if the version is too low. - -### What is a portal? - -Unlike Windows and MacOS, Linux does not have a file chooser baked into the operating system. Linux applications that want a file chooser usually link with a library that provides one (such as GTK, as in the Linux screenshot above). This is a mostly acceptable solution that many applications use, but may make the file chooser look foreign on non-GTK distros. - -Flatpak was introduced in 2015, and with it came a standardized interface to open a file chooser. Applications using this interface did not need to come with a file chooser, and could use the one provided by Flatpak. This interface became known as the desktop portal, and its use expanded to non-Flatpak applications. Now, most major desktop Linux distros come with the desktop portal installed, with file choosers that fit the theme of the distro. Users can also install a different portal backend if desired. There are currently two known backends: GTK and KDE. (XFCE does not currently seem to have a portal backend.) - -## Platform-specific Quirks - -### MacOS - -- If the MacOS deployment target is ≥ 11.0, the [allowedContentTypes](https://developer.apple.com/documentation/appkit/nssavepanel/3566857-allowedcontenttypes?language=objc) property of NSSavePanel is used instead of the deprecated [allowedFileTypes](https://developer.apple.com/documentation/appkit/nssavepanel/1534419-allowedfiletypes?language=objc) property for file filters. Thus, if you are filtering by a custom file extension specific to your application, you will need to define the data type in your `Info.plist` file as per the [Apple documentation](https://developer.apple.com/documentation/uniformtypeidentifiers/defining_file_and_data_types_for_your_app). (It is possible to force NFDe to use allowedFileTypes by adding `-DNFD_USE_ALLOWEDCONTENTTYPES_IF_AVAILABLE=OFF` to your CMake build command, but this is not recommended. If you need to support older MacOS versions, you should be setting the correct deployment target instead.) - -# Known Limitations # - - - No support for Windows XP's legacy dialogs such as `GetOpenFileName`. (There are no plans to support this; you shouldn't be still using Windows XP anyway.) - - No Emscripten (WebAssembly) bindings. (This might get implemented if I decide to port Circuit Sandbox for the web, but I don't think there is any way to implement a web-based folder picker.) - - GTK dialogs don't set the existing window as parent, so if users click the existing window while the dialog is open then the dialog will go behind it. GTK writes a warning to stdout or stderr about this. - - Portal dialogs (the alternative to GTK on Linux) don't support a default path. Any default path you supply will be ignored. - - This library is not compatible with the original Native File Dialog library. Things might break if you use both in the same project. (There are no plans to support this; you have to use one or the other.) - - This library does not explicitly dispatch calls to the UI thread. This may lead to crashes if you call functions from other threads when the platform does not support it (e.g. MacOS). Users are generally expected to call NFDe from an appropriate UI thread (i.e. the thread performing the UI event loop). - -# Reporting Bugs # - -Please use the GitHub issue tracker to report bugs or to contribute to this repository. Feel free to submit bug reports of any kind. - -# Credit # - -Bernard Teo (me) and other contributors for everything that wasn't from Michael Labbe's [Native File Dialog](https://github.com/mlabbe/nativefiledialog). - -[Michael Labbe](https://github.com/mlabbe) for his awesome Native File Dialog library, and the other contributors to that library. - -Much of this README has also been copied from the README of original Native File Dialog repository. - -## License ## - -Everything in this repository is distributed under the ZLib license, as is the original Native File Dialog library. - -## Support ## - -I don't provide any paid support. [Michael Labbe](https://github.com/mlabbe) appears to provide paid support for his [library](https://github.com/mlabbe/nativefiledialog) at the time of writing. diff --git a/externals/shared/lib/znfde/nativefiledialog/src/CMakeLists.txt b/externals/shared/lib/znfde/nativefiledialog/src/CMakeLists.txt deleted file mode 100644 index f83c583f3..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/src/CMakeLists.txt +++ /dev/null @@ -1,135 +0,0 @@ -set(TARGET_NAME nfd) - -set(PUBLIC_HEADER_FILES - include/nfd.h - include/nfd.hpp) - -set(SOURCE_FILES ${PUBLIC_HEADER_FILES}) - -if(nfd_PLATFORM STREQUAL PLATFORM_WIN32) - list(APPEND SOURCE_FILES nfd_win.cpp) -endif() - -if(nfd_PLATFORM STREQUAL PLATFORM_LINUX) - find_package(PkgConfig REQUIRED) - # for Linux, we support GTK3 and xdg-desktop-portal - option(NFD_PORTAL "Use xdg-desktop-portal instead of GTK" OFF) - if(NOT NFD_PORTAL) - pkg_check_modules(GTK3 REQUIRED gtk+-3.0) - message("Using GTK version: ${GTK3_VERSION}") - list(APPEND SOURCE_FILES nfd_gtk.cpp) - else() - pkg_check_modules(DBUS REQUIRED dbus-1) - message("Using DBUS version: ${DBUS_VERSION}") - list(APPEND SOURCE_FILES nfd_portal.cpp) - endif() -endif() - -if(nfd_PLATFORM STREQUAL PLATFORM_MACOS) - # For setting the filter list, macOS introduced allowedContentTypes in version 11.0 and deprecated allowedFileTypes in 12.0. - # By default (set to ON), NFDe will use allowedContentTypes when targeting macOS >= 11.0. - # Set this option to OFF to always use allowedFileTypes regardless of the target macOS version. - # This is mainly needed for applications that are built on macOS >= 11.0 but should be able to run on lower versions - # and should not be used otherwise. - option(NFD_USE_ALLOWEDCONTENTTYPES_IF_AVAILABLE "Use allowedContentTypes for filter lists on macOS >= 11.0" ON) - - find_library(APPKIT_LIBRARY AppKit) - if(NFD_USE_ALLOWEDCONTENTTYPES_IF_AVAILABLE) - include(CheckCXXSourceCompiles) - check_cxx_source_compiles( - " - #include - #if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || !defined(__MAC_11_0) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_11_0 - static_assert(false); - #endif - int main() { return 0; } - " - NFD_USE_ALLOWEDCONTENTTYPES - ) - if(NFD_USE_ALLOWEDCONTENTTYPES) - find_library(UNIFORMTYPEIDENTIFIERS_LIBRARY UniformTypeIdentifiers) - if(NOT UNIFORMTYPEIDENTIFIERS_LIBRARY) - message(FATAL_ERROR "UniformTypeIdentifiers framework is not available even though we are targeting macOS >= 11.0") - endif() - endif() - endif() - list(APPEND SOURCE_FILES nfd_cocoa.m) -endif() - -# Define the library -add_library(${TARGET_NAME} ${SOURCE_FILES}) - -if (BUILD_SHARED_LIBS) - target_compile_definitions(${TARGET_NAME} PRIVATE NFD_EXPORT INTERFACE NFD_SHARED) -endif () - -# Allow includes from include/ -target_include_directories(${TARGET_NAME} - PUBLIC - $ - $ -) - -if(nfd_PLATFORM STREQUAL PLATFORM_LINUX) - if(NOT NFD_PORTAL) - target_include_directories(${TARGET_NAME} - PRIVATE ${GTK3_INCLUDE_DIRS}) - target_link_libraries(${TARGET_NAME} - PRIVATE ${GTK3_LINK_LIBRARIES}) - else() - target_include_directories(${TARGET_NAME} - PRIVATE ${DBUS_INCLUDE_DIRS}) - target_link_libraries(${TARGET_NAME} - PRIVATE ${DBUS_LINK_LIBRARIES}) - target_compile_definitions(${TARGET_NAME} - PUBLIC NFD_PORTAL) - endif() - - option(NFD_APPEND_EXTENSION "Automatically append file extension to an extensionless selection in SaveDialog()" OFF) - if(NFD_APPEND_EXTENSION) - target_compile_definitions(${TARGET_NAME} PRIVATE NFD_APPEND_EXTENSION) - endif() -endif() - -if(nfd_PLATFORM STREQUAL PLATFORM_MACOS) - if(NFD_USE_ALLOWEDCONTENTTYPES) - target_link_libraries(${TARGET_NAME} PRIVATE ${APPKIT_LIBRARY} ${UNIFORMTYPEIDENTIFIERS_LIBRARY}) - target_compile_definitions(${TARGET_NAME} PRIVATE NFD_MACOS_ALLOWEDCONTENTTYPES=1) - else() - target_link_libraries(${TARGET_NAME} PRIVATE ${APPKIT_LIBRARY}) - target_compile_definitions(${TARGET_NAME} PRIVATE NFD_MACOS_ALLOWEDCONTENTTYPES=0) - endif() -endif() - -if(nfd_COMPILER STREQUAL COMPILER_MSVC) - string(REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/GR" "/GR-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - set_property(TARGET ${TARGET_NAME} APPEND_STRING PROPERTY STATIC_LIBRARY_OPTIONS /NODEFAULTLIB) -endif() - -if(nfd_COMPILER STREQUAL COMPILER_CLANGCL) - string(REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/GR" "/GR-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -endif() - -if(nfd_COMPILER STREQUAL COMPILER_GNU) - target_compile_options(${TARGET_NAME} PRIVATE -nostdlib -fno-exceptions -fno-rtti) -endif() - -set_target_properties(${TARGET_NAME} PROPERTIES - PUBLIC_HEADER "${PUBLIC_HEADER_FILES}" - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR}) - -if (NFD_INSTALL) - include(GNUInstallDirs) - - install(TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME}-export - LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - install(EXPORT ${TARGET_NAME}-export - DESTINATION lib/cmake/${TARGET_NAME} - NAMESPACE ${TARGET_NAME}:: - FILE ${TARGET_NAME}-config.cmake - ) -endif() diff --git a/externals/shared/lib/znfde/nativefiledialog/src/include/nfd.h b/externals/shared/lib/znfde/nativefiledialog/src/include/nfd.h deleted file mode 100644 index adb1c8143..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/src/include/nfd.h +++ /dev/null @@ -1,564 +0,0 @@ -/* - Native File Dialog Extended - Repository: https://github.com/btzy/nativefiledialog-extended - License: Zlib - Authors: Bernard Teo, Michael Labbe - - This header contains the functions that can be called by user code. - */ - -#ifndef _NFD_H -#define _NFD_H - -#if defined(_WIN32) -#if defined(NFD_EXPORT) -#define NFD_API __declspec(dllexport) -#elif defined(NFD_SHARED) -#define NFD_API __declspec(dllimport) -#endif -#else -#if defined(NFD_EXPORT) || defined(NFD_SHARED) -#if defined(__GNUC__) || defined(__clang__) -#define NFD_API __attribute__((visibility("default"))) -#endif -#endif -#endif -#ifndef NFD_API -#define NFD_API -#endif - -#ifdef __cplusplus -extern "C" { -#define NFD_INLINE inline -#else -#define NFD_INLINE static inline -#endif // __cplusplus - -#include - -typedef char nfdu8char_t; - -#ifdef _WIN32 -/** @typedef UTF-16 character */ -typedef wchar_t nfdnchar_t; -#else -/** @typedef UTF-8 character */ -typedef nfdu8char_t nfdnchar_t; -#endif // _WIN32 - -/** @typedef Opaque data structure -- see NFD_PathSet_* */ -typedef void nfdpathset_t; -#ifndef NFD_PORTAL -typedef struct { - void* ptr; -} nfdpathsetenum_t; -#else -typedef struct { - void* d1; - void* d2; - unsigned int d3; - int d4; - int d5; - int d6; - int d7; - int d8; - int d9; - int d10; - int d11; - int p1; - void* p2; - void* p3; -} nfdpathsetenum_t; -#endif - -typedef unsigned int nfdfiltersize_t; - -typedef enum { - NFD_ERROR, /**< Programmatic error */ - NFD_OKAY, /**< User pressed okay, or successful return */ - NFD_CANCEL /**< User pressed cancel */ -} nfdresult_t; - -/** @typedef UTF-8 Filter Item */ -typedef struct { - const nfdu8char_t* name; - const nfdu8char_t* spec; -} nfdu8filteritem_t; - -#ifdef _WIN32 -/** @typedef UTF-16 Filter Item */ -typedef struct { - const nfdnchar_t* name; - const nfdnchar_t* spec; -} nfdnfilteritem_t; -#else -/** @typedef UTF-8 Filter Item */ -typedef nfdu8filteritem_t nfdnfilteritem_t; -#endif // _WIN32 - -// The native window handle type. -enum { - NFD_WINDOW_HANDLE_TYPE_UNSET = 0, - // Windows: handle is HWND (the Windows API typedefs this to void*) - NFD_WINDOW_HANDLE_TYPE_WINDOWS = 1, - // Cocoa: handle is NSWindow* - NFD_WINDOW_HANDLE_TYPE_COCOA = 2, - // X11: handle is Window - NFD_WINDOW_HANDLE_TYPE_X11 = 3, - // Wayland support will be implemented separately in the future -}; -// The native window handle. If using a platform abstraction framework (e.g. SDL2), this should be -// obtained using the corresponding NFD glue header (e.g. nfd_sdl2.h). -typedef struct { - size_t type; // this is one of the values of the enum above - void* handle; -} nfdwindowhandle_t; - -typedef size_t nfdversion_t; - -typedef struct { - const nfdu8filteritem_t* filterList; - nfdfiltersize_t filterCount; - const nfdu8char_t* defaultPath; - nfdwindowhandle_t parentWindow; -} nfdopendialogu8args_t; - -#ifdef _WIN32 -typedef struct { - const nfdnfilteritem_t* filterList; - nfdfiltersize_t filterCount; - const nfdnchar_t* defaultPath; - nfdwindowhandle_t parentWindow; -} nfdopendialognargs_t; -#else -typedef nfdopendialogu8args_t nfdopendialognargs_t; -#endif // _WIN32 - -typedef struct { - const nfdu8filteritem_t* filterList; - nfdfiltersize_t filterCount; - const nfdu8char_t* defaultPath; - const nfdu8char_t* defaultName; - nfdwindowhandle_t parentWindow; -} nfdsavedialogu8args_t; - -#ifdef _WIN32 -typedef struct { - const nfdnfilteritem_t* filterList; - nfdfiltersize_t filterCount; - const nfdnchar_t* defaultPath; - const nfdnchar_t* defaultName; - nfdwindowhandle_t parentWindow; -} nfdsavedialognargs_t; -#else -typedef nfdsavedialogu8args_t nfdsavedialognargs_t; -#endif // _WIN32 - -typedef struct { - const nfdu8char_t* defaultPath; - nfdwindowhandle_t parentWindow; -} nfdpickfolderu8args_t; - -#ifdef _WIN32 -typedef struct { - const nfdnchar_t* defaultPath; - nfdwindowhandle_t parentWindow; -} nfdpickfoldernargs_t; -#else -typedef nfdpickfolderu8args_t nfdpickfoldernargs_t; -#endif // _WIN32 - -// This is a unique identifier tagged to all the NFD_*With() function calls, for backward -// compatibility purposes. There is usually no need to use this directly, unless you want to use -// NFD differently depending on the version you're building with. -#define NFD_INTERFACE_VERSION 1 - -/** Free a file path that was returned by the dialogs. - * - * Note: use NFD_PathSet_FreePathN() to free path from pathset instead of this function. */ -NFD_API void NFD_FreePathN(nfdnchar_t* filePath); - -/** Free a file path that was returned by the dialogs. - * - * Note: use NFD_PathSet_FreePathU8() to free path from pathset instead of this function. */ -NFD_API void NFD_FreePathU8(nfdu8char_t* filePath); - -/** Initialize NFD. Call this for every thread that might use NFD, before calling any other NFD - * functions on that thread. */ -NFD_API nfdresult_t NFD_Init(void); - -/** Call this to de-initialize NFD, if NFD_Init returned NFD_OKAY. */ -NFD_API void NFD_Quit(void); - -/** Single file open dialog - * - * It's the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns - * NFD_OKAY. - * @param[out] outPath - * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath); - -/** Single file open dialog - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function - * returns NFD_OKAY. - * @param[out] outPath - * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath); - -/** This function is a library implementation detail. Please use NFD_OpenDialogN_With() instead. */ -NFD_API nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdopendialognargs_t* args); - -/** Single file open dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function - * returns NFD_OKAY. See documentation of nfdopendialognargs_t for details. */ -NFD_INLINE nfdresult_t NFD_OpenDialogN_With(nfdnchar_t** outPath, - const nfdopendialognargs_t* args) { - return NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, args); -} - -/** This function is a library implementation detail. Please use NFD_OpenDialogU8_With() instead. - */ -NFD_API nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdopendialogu8args_t* args); - -/** Single file open dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function - * returns NFD_OKAY. See documentation of nfdopendialogu8args_t for details. */ -NFD_INLINE nfdresult_t NFD_OpenDialogU8_With(nfdu8char_t** outPath, - const nfdopendialogu8args_t* args) { - return NFD_OpenDialogU8_With_Impl(NFD_INTERFACE_VERSION, outPath, args); -} - -/** Multiple file open dialog - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeN() if this function - * returns NFD_OKAY. - * @param[out] outPaths - * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath); - -/** Multiple file open dialog - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeU8() if this function - * returns NFD_OKAY. - * @param[out] outPaths - * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath); - -/** This function is a library implementation detail. Please use NFD_OpenDialogMultipleN_With() - * instead. */ -NFD_API nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialognargs_t* args); - -/** Multiple file open dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeN() if this function - * returns NFD_OKAY. See documentation of nfdopendialognargs_t for details. */ -NFD_INLINE nfdresult_t NFD_OpenDialogMultipleN_With(const nfdpathset_t** outPaths, - const nfdopendialognargs_t* args) { - return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, args); -} - -/** This function is a library implementation detail. Please use NFD_OpenDialogU8_With() instead. - */ -NFD_API nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialogu8args_t* args); - -/** Multiple file open dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeU8() if this function - * returns NFD_OKAY. See documentation of nfdopendialogu8args_t for details. */ -NFD_INLINE nfdresult_t NFD_OpenDialogMultipleU8_With(const nfdpathset_t** outPaths, - const nfdopendialogu8args_t* args) { - return NFD_OpenDialogMultipleU8_With_Impl(NFD_INTERFACE_VERSION, outPaths, args); -} - -/** Save dialog - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns - * NFD_OKAY. - * @param[out] outPath - * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName); - -/** Save dialog - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function - * returns NFD_OKAY. - * @param[out] outPath - * @param filterCount If zero, filterList is ignored (you can use null). - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName); - -/** This function is a library implementation detail. Please use NFD_SaveDialogN_With() instead. */ -NFD_API nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdsavedialognargs_t* args); - -/** Single file save dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function - * returns NFD_OKAY. See documentation of nfdsavedialognargs_t for details. */ -NFD_INLINE nfdresult_t NFD_SaveDialogN_With(nfdnchar_t** outPath, - const nfdsavedialognargs_t* args) { - return NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, args); -} - -/** This function is a library implementation detail. Please use NFD_SaveDialogU8_With() instead. - */ -NFD_API nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdsavedialogu8args_t* args); - -/** Single file save dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function - * returns NFD_OKAY. See documentation of nfdsavedialogu8args_t for details. */ -NFD_INLINE nfdresult_t NFD_SaveDialogU8_With(nfdu8char_t** outPath, - const nfdsavedialogu8args_t* args) { - return NFD_SaveDialogU8_With_Impl(NFD_INTERFACE_VERSION, outPath, args); -} - -/** Select single folder dialog - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns - * NFD_OKAY. - * @param[out] outPath - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath); - -/** Select single folder dialog - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function - * returns NFD_OKAY. - * @param[out] outPath - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath); - -/** This function is a library implementation detail. Please use NFD_PickFolderN_With() instead. */ -NFD_API nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdpickfoldernargs_t* args); - -/** Select single folder dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function - * returns NFD_OKAY. See documentation of nfdpickfoldernargs_t for details. */ -NFD_INLINE nfdresult_t NFD_PickFolderN_With(nfdnchar_t** outPath, - const nfdpickfoldernargs_t* args) { - return NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, outPath, args); -} - -/** This function is a library implementation detail. Please use NFD_PickFolderU8_With() instead. - */ -NFD_API nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdpickfolderu8args_t* args); - -/** Select single folder dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function - * returns NFD_OKAY. See documentation of nfdpickfolderu8args_t for details. */ -NFD_INLINE nfdresult_t NFD_PickFolderU8_With(nfdu8char_t** outPath, - const nfdpickfolderu8args_t* args) { - return NFD_PickFolderU8_With_Impl(NFD_INTERFACE_VERSION, outPath, args); -} - -/** Select multiple folder dialog - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeN() if this function - * returns NFD_OKAY. - * @param[out] outPaths - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, - const nfdnchar_t* defaultPath); - -/** Select multiple folder dialog - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeU8() if this function - * returns NFD_OKAY. - * @param[out] outPaths - * @param defaultPath If null, the operating system will decide. */ -NFD_API nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, - const nfdu8char_t* defaultPath); - -/** This function is a library implementation detail. Please use NFD_PickFolderMultipleN_With() - * instead. */ -NFD_API nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfoldernargs_t* args); - -/** Select multiple folder dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeN() if this function - * returns NFD_OKAY. See documentation of nfdopendialogargs_t for details. */ -NFD_INLINE nfdresult_t NFD_PickFolderMultipleN_With(const nfdpathset_t** outPaths, - const nfdpickfoldernargs_t* args) { - return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, args); -} - -/** This function is a library implementation detail. Please use NFD_PickFolderMultipleU8_With() - * instead. - */ -NFD_API nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfolderu8args_t* args); - -/** Select multiple folder dialog, with additional parameters. - * - * It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeU8() if this function - * returns NFD_OKAY. See documentation of nfdpickfolderargs_t for details. */ -NFD_INLINE nfdresult_t NFD_PickFolderMultipleU8_With(const nfdpathset_t** outPaths, - const nfdpickfolderu8args_t* args) { - return NFD_PickFolderMultipleU8_With_Impl(NFD_INTERFACE_VERSION, outPaths, args); -} - -/** Get the last error - * - * This is set when a function returns NFD_ERROR. - * The memory is owned by NFD and should not be freed by user code. - * This is *always* ASCII printable characters, so it can be interpreted as UTF-8 without any - * conversion. - * @return The last error that was set, or null if there is no error. */ -NFD_API const char* NFD_GetError(void); - -/** Clear the error. */ -NFD_API void NFD_ClearError(void); - -/* path set operations */ -#ifdef _WIN32 -typedef unsigned long nfdpathsetsize_t; -#elif __APPLE__ -typedef unsigned long nfdpathsetsize_t; -#else -typedef unsigned int nfdpathsetsize_t; -#endif // _WIN32, __APPLE__ - -/** Get the number of entries stored in pathSet. - * - * Note: some paths might be invalid (NFD_ERROR will be returned by NFD_PathSet_GetPath), - * so we might not actually have this number of usable paths. */ -NFD_API nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count); - -/** Get the UTF-8 path at offset index. - * - * It is the caller's responsibility to free `outPath` via NFD_PathSet_FreePathN() if this function - * returns NFD_OKAY. */ -NFD_API nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdnchar_t** outPath); - -/** Get the native path at offset index. - * - * It is the caller's responsibility to free `outPath` via NFD_PathSet_FreePathU8() if this - * function returns NFD_OKAY. */ -NFD_API nfdresult_t NFD_PathSet_GetPathU8(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdu8char_t** outPath); - -/** Free the path gotten by NFD_PathSet_GetPathN(). */ -NFD_API void NFD_PathSet_FreePathN(const nfdnchar_t* filePath); - -/** Free the path gotten by NFD_PathSet_GetPathU8(). */ -NFD_API void NFD_PathSet_FreePathU8(const nfdu8char_t* filePath); - -/** Gets an enumerator of the path set. - * - * It is the caller's responsibility to free `enumerator` via NFD_PathSet_FreeEnum() - * if this function returns NFD_OKAY, and it should be freed before freeing the pathset. */ -NFD_API nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, - nfdpathsetenum_t* outEnumerator); - -/** Frees an enumerator of the path set. */ -NFD_API void NFD_PathSet_FreeEnum(nfdpathsetenum_t* enumerator); - -/** Gets the next item from the path set enumerator. - * - * If there are no more items, then *outPaths will be set to null. - * It is the caller's responsibility to free `*outPath` via NFD_PathSet_FreePathN() - * if this function returns NFD_OKAY and `*outPath` is not null. */ -NFD_API nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath); - -/** Gets the next item from the path set enumerator. - * - * If there are no more items, then *outPaths will be set to null. - * It is the caller's responsibility to free `*outPath` via NFD_PathSet_FreePathU8() - * if this function returns NFD_OKAY and `*outPath` is not null. */ -NFD_API nfdresult_t NFD_PathSet_EnumNextU8(nfdpathsetenum_t* enumerator, nfdu8char_t** outPath); - -/** Free the pathSet */ -NFD_API void NFD_PathSet_Free(const nfdpathset_t* pathSet); - -#ifdef _WIN32 - -/* say that the U8 versions of functions are not just __attribute__((alias(""))) to the native - * versions */ -#define NFD_DIFFERENT_NATIVE_FUNCTIONS - -#endif // _WIN32 - -#ifdef NFD_NATIVE -typedef nfdnchar_t nfdchar_t; -typedef nfdnfilteritem_t nfdfilteritem_t; -#define NFD_FreePath NFD_FreePathN -#define NFD_OpenDialog NFD_OpenDialogN -#define NFD_OpenDialogMultiple NFD_OpenDialogMultipleN -#define NFD_SaveDialog NFD_SaveDialogN -#define NFD_PickFolder NFD_PickFolderN -#define NFD_PickFolderMultiple NFD_PickFolderMultipleN -#define NFD_PathSet_GetPath NFD_PathSet_GetPathN -#define NFD_PathSet_FreePath NFD_PathSet_FreePathN -#define NFD_PathSet_EnumNext NFD_PathSet_EnumNextN -#else -typedef nfdu8char_t nfdchar_t; -typedef nfdu8filteritem_t nfdfilteritem_t; -#define NFD_FreePath NFD_FreePathU8 -#define NFD_OpenDialog NFD_OpenDialogU8 -#define NFD_OpenDialogMultiple NFD_OpenDialogMultipleU8 -#define NFD_SaveDialog NFD_SaveDialogU8 -#define NFD_PickFolder NFD_PickFolderU8 -#define NFD_PickFolderMultiple NFD_PickFolderMultipleU8 -#define NFD_PathSet_GetPath NFD_PathSet_GetPathU8 -#define NFD_PathSet_FreePath NFD_PathSet_FreePathU8 -#define NFD_PathSet_EnumNext NFD_PathSet_EnumNextU8 -#endif // NFD_NATIVE - -#undef NFD_INLINE -#ifdef __cplusplus -} -#endif // __cplusplus - -#endif // _NFD_H diff --git a/externals/shared/lib/znfde/nativefiledialog/src/include/nfd.hpp b/externals/shared/lib/znfde/nativefiledialog/src/include/nfd.hpp deleted file mode 100644 index da232ae83..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/src/include/nfd.hpp +++ /dev/null @@ -1,375 +0,0 @@ -/* - Native File Dialog Extended - Repository: https://github.com/btzy/nativefiledialog-extended - License: Zlib - Author: Bernard Teo - - This header is a thin C++ wrapper for nfd.h. - C++ projects can choose to use this header instead of nfd.h directly. - - Refer to documentation on nfd.h for instructions on how to use these functions. -*/ - -#ifndef _NFD_HPP -#define _NFD_HPP - -#include -#include // for std::size_t -#include // for std::unique_ptr -#ifdef NFD_THROWS_EXCEPTIONS -#include -#endif - -namespace NFD { - -inline nfdresult_t Init() noexcept { - return ::NFD_Init(); -} - -inline void Quit() noexcept { - ::NFD_Quit(); -} - -inline void FreePath(nfdnchar_t* outPath) noexcept { - ::NFD_FreePathN(outPath); -} - -inline nfdresult_t OpenDialog(nfdnchar_t*& outPath, - const nfdnfilteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow}; - return ::NFD_OpenDialogN_With(&outPath, &args); -} - -inline nfdresult_t OpenDialogMultiple(const nfdpathset_t*& outPaths, - const nfdnfilteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdopendialognargs_t args{filterList, filterCount, defaultPath, parentWindow}; - return ::NFD_OpenDialogMultipleN_With(&outPaths, &args); -} - -inline nfdresult_t SaveDialog(nfdnchar_t*& outPath, - const nfdnfilteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdnchar_t* defaultPath = nullptr, - const nfdnchar_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdsavedialognargs_t args{ - filterList, filterCount, defaultPath, defaultName, parentWindow}; - return ::NFD_SaveDialogN_With(&outPath, &args); -} - -inline nfdresult_t PickFolder(nfdnchar_t*& outPath, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfoldernargs_t args{defaultPath, parentWindow}; - return ::NFD_PickFolderN_With(&outPath, &args); -} - -inline nfdresult_t PickFolderMultiple(const nfdpathset_t*& outPaths, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfoldernargs_t args{defaultPath, parentWindow}; - return ::NFD_PickFolderMultipleN_With(&outPaths, &args); -} - -inline const char* GetError() noexcept { - return ::NFD_GetError(); -} - -inline void ClearError() noexcept { - ::NFD_ClearError(); -} - -namespace PathSet { -inline nfdresult_t Count(const nfdpathset_t* pathSet, nfdpathsetsize_t& count) noexcept { - return ::NFD_PathSet_GetCount(pathSet, &count); -} - -inline nfdresult_t GetPath(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdnchar_t*& outPath) noexcept { - return ::NFD_PathSet_GetPathN(pathSet, index, &outPath); -} - -inline void FreePath(nfdnchar_t* filePath) noexcept { - ::NFD_PathSet_FreePathN(filePath); -} - -inline void Free(const nfdpathset_t* pathSet) noexcept { - ::NFD_PathSet_Free(pathSet); -} -} // namespace PathSet - -#ifdef NFD_DIFFERENT_NATIVE_FUNCTIONS -/* we need the C++ bindings for the UTF-8 functions as well, because there are different functions - * for them */ - -inline void FreePath(nfdu8char_t* outPath) noexcept { - ::NFD_FreePathU8(outPath); -} - -inline nfdresult_t OpenDialog(nfdu8char_t*& outPath, - const nfdu8filteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdopendialogu8args_t args{filterList, filterCount, defaultPath, parentWindow}; - return ::NFD_OpenDialogU8_With(&outPath, &args); -} - -inline nfdresult_t OpenDialogMultiple(const nfdpathset_t*& outPaths, - const nfdu8filteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdopendialogu8args_t args{filterList, filterCount, defaultPath, parentWindow}; - return ::NFD_OpenDialogMultipleU8_With(&outPaths, &args); -} - -inline nfdresult_t SaveDialog(nfdu8char_t*& outPath, - const nfdu8filteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdu8char_t* defaultPath = nullptr, - const nfdu8char_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdsavedialogu8args_t args{ - filterList, filterCount, defaultPath, defaultName, parentWindow}; - return ::NFD_SaveDialogU8_With(&outPath, &args); -} - -inline nfdresult_t PickFolder(nfdu8char_t*& outPath, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfolderu8args_t args{defaultPath, parentWindow}; - return ::NFD_PickFolderU8_With(&outPath, &args); -} - -inline nfdresult_t PickFolderMultiple(const nfdpathset_t*& outPaths, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpickfolderu8args_t args{defaultPath, parentWindow}; - return ::NFD_PickFolderMultipleU8_With(&outPaths, &args); -} - -namespace PathSet { -inline nfdresult_t GetPath(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdu8char_t*& outPath) noexcept { - return ::NFD_PathSet_GetPathU8(pathSet, index, &outPath); -} -inline void FreePath(nfdu8char_t* filePath) noexcept { - ::NFD_PathSet_FreePathU8(filePath); -} -} // namespace PathSet -#endif - -// smart objects - -class Guard { - public: -#ifndef NFD_THROWS_EXCEPTIONS - inline Guard() noexcept { - Init(); // always assume that initialization succeeds - } -#else - inline Guard() { - if (!Init()) { - throw std::runtime_error(GetError()); - } - } -#endif - inline ~Guard() noexcept { Quit(); } - - // Not allowed to copy or move this class - Guard(const Guard&) = delete; - Guard& operator=(const Guard&) = delete; -}; - -template -struct PathDeleter { - inline void operator()(T* ptr) const noexcept { FreePath(ptr); } -}; - -typedef std::unique_ptr> UniquePath; -typedef std::unique_ptr> UniquePathN; -typedef std::unique_ptr> UniquePathU8; - -struct PathSetDeleter { - inline void operator()(const nfdpathset_t* ptr) const noexcept { PathSet::Free(ptr); } -}; - -typedef std::unique_ptr UniquePathSet; - -template -struct PathSetPathDeleter { - inline void operator()(T* ptr) const noexcept { PathSet::FreePath(ptr); } -}; - -typedef std::unique_ptr> UniquePathSetPath; -typedef std::unique_ptr> UniquePathSetPathN; -typedef std::unique_ptr> UniquePathSetPathU8; - -inline nfdresult_t OpenDialog(UniquePathN& outPath, - const nfdnfilteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - nfdnchar_t* out; - nfdresult_t res = OpenDialog(out, filterList, filterCount, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} - -inline nfdresult_t OpenDialogMultiple(UniquePathSet& outPaths, - const nfdnfilteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpathset_t* out; - nfdresult_t res = OpenDialogMultiple(out, filterList, filterCount, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPaths.reset(out); - } - return res; -} - -inline nfdresult_t SaveDialog(UniquePathN& outPath, - const nfdnfilteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdnchar_t* defaultPath = nullptr, - const nfdnchar_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - nfdnchar_t* out; - nfdresult_t res = - SaveDialog(out, filterList, filterCount, defaultPath, defaultName, parentWindow); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} - -inline nfdresult_t PickFolder(UniquePathN& outPath, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - nfdnchar_t* out; - nfdresult_t res = PickFolder(out, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} - -inline nfdresult_t PickFolderMultiple(UniquePathSet& outPaths, - const nfdnchar_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpathset_t* out; - nfdresult_t res = PickFolderMultiple(out, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPaths.reset(out); - } - return res; -} - -#ifdef NFD_DIFFERENT_NATIVE_FUNCTIONS -inline nfdresult_t OpenDialog(UniquePathU8& outPath, - const nfdu8filteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - nfdu8char_t* out; - nfdresult_t res = OpenDialog(out, filterList, filterCount, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} - -inline nfdresult_t OpenDialogMultiple(UniquePathSet& outPaths, - const nfdu8filteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpathset_t* out; - nfdresult_t res = OpenDialogMultiple(out, filterList, filterCount, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPaths.reset(out); - } - return res; -} - -inline nfdresult_t SaveDialog(UniquePathU8& outPath, - const nfdu8filteritem_t* filterList = nullptr, - nfdfiltersize_t filterCount = 0, - const nfdu8char_t* defaultPath = nullptr, - const nfdu8char_t* defaultName = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - nfdu8char_t* out; - nfdresult_t res = - SaveDialog(out, filterList, filterCount, defaultPath, defaultName, parentWindow); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} - -inline nfdresult_t PickFolder(UniquePathU8& outPath, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - nfdu8char_t* out; - nfdresult_t res = PickFolder(out, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} - -inline nfdresult_t PickFolderMultiple(UniquePathSet& outPaths, - const nfdu8char_t* defaultPath = nullptr, - nfdwindowhandle_t parentWindow = {}) noexcept { - const nfdpathset_t* out; - nfdresult_t res = PickFolderMultiple(out, defaultPath, parentWindow); - if (res == NFD_OKAY) { - outPaths.reset(out); - } - return res; -} -#endif - -namespace PathSet { -inline nfdresult_t Count(const UniquePathSet& uniquePathSet, nfdpathsetsize_t& count) noexcept { - return Count(uniquePathSet.get(), count); -} -inline nfdresult_t GetPath(const UniquePathSet& uniquePathSet, - nfdpathsetsize_t index, - UniquePathSetPathN& outPath) noexcept { - nfdnchar_t* out; - nfdresult_t res = GetPath(uniquePathSet.get(), index, out); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} -#ifdef NFD_DIFFERENT_NATIVE_FUNCTIONS -inline nfdresult_t GetPath(const UniquePathSet& uniquePathSet, - nfdpathsetsize_t index, - UniquePathSetPathU8& outPath) noexcept { - nfdu8char_t* out; - nfdresult_t res = GetPath(uniquePathSet.get(), index, out); - if (res == NFD_OKAY) { - outPath.reset(out); - } - return res; -} -#endif -} // namespace PathSet - -} // namespace NFD - -#endif diff --git a/externals/shared/lib/znfde/nativefiledialog/src/nfd_cocoa.m b/externals/shared/lib/znfde/nativefiledialog/src/nfd_cocoa.m deleted file mode 100644 index 4bcea2201..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/src/nfd_cocoa.m +++ /dev/null @@ -1,615 +0,0 @@ -/* - Native File Dialog Extended - Repository: https://github.com/btzy/nativefiledialog-extended - License: Zlib - Authors: Bernard Teo, Michael Labbe - */ - -#include -#include -#include "nfd.h" - -// MacOS is deprecating the allowedFileTypes property in favour of allowedContentTypes, so we have -// to introduce this breaking change. Define NFD_MACOS_ALLOWEDCONTENTTYPES to 1 to have it set the -// allowedContentTypes property of the SavePanel or OpenPanel. Define -// NFD_MACOS_ALLOWEDCONTENTTYPES to 0 to have it set the allowedFileTypes property of the SavePanel -// or OpenPanel. If NFD_MACOS_ALLOWEDCONTENTTYPES is undefined, then it will set it to 1 if -// __MAC_OS_X_VERSION_MIN_REQUIRED >= 11.0, and 0 otherwise. -#if !defined(NFD_MACOS_ALLOWEDCONTENTTYPES) -#if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || !defined(__MAC_11_0) || \ - __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_11_0 -#define NFD_MACOS_ALLOWEDCONTENTTYPES 0 -#else -#define NFD_MACOS_ALLOWEDCONTENTTYPES 1 -#endif -#endif - -#if NFD_MACOS_ALLOWEDCONTENTTYPES == 1 -#include -#endif - -static const char* g_errorstr = NULL; - -static void NFDi_SetError(const char* msg) { - g_errorstr = msg; -} - -static void* NFDi_Malloc(size_t bytes) { - void* ptr = malloc(bytes); - if (!ptr) NFDi_SetError("NFDi_Malloc failed."); - - return ptr; -} - -static void NFDi_Free(void* ptr) { - assert(ptr); - free(ptr); -} - -#if NFD_MACOS_ALLOWEDCONTENTTYPES == 1 -// Returns an NSArray of UTType representing the content types. -static NSArray* BuildAllowedContentTypes(const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - NSMutableArray* buildFilterList = [[NSMutableArray alloc] init]; - - for (nfdfiltersize_t filterIndex = 0; filterIndex != filterCount; ++filterIndex) { - // this is the spec to parse (we don't use the friendly name on OS X) - const nfdnchar_t* filterSpec = filterList[filterIndex].spec; - - const nfdnchar_t* p_currentFilterBegin = filterSpec; - for (const nfdnchar_t* p_filterSpec = filterSpec; *p_filterSpec; ++p_filterSpec) { - if (*p_filterSpec == ',') { - // add the extension to the array - NSString* filterStr = [[NSString alloc] - initWithBytes:(const void*)p_currentFilterBegin - length:(sizeof(nfdnchar_t) * (p_filterSpec - p_currentFilterBegin)) - encoding:NSUTF8StringEncoding]; - UTType* filterType = [UTType typeWithFilenameExtension:filterStr - conformingToType:UTTypeData]; - [filterStr release]; - if (filterType) [buildFilterList addObject:filterType]; - p_currentFilterBegin = p_filterSpec + 1; - } - } - // add the extension to the array - NSString* filterStr = [[NSString alloc] initWithUTF8String:p_currentFilterBegin]; - UTType* filterType = [UTType typeWithFilenameExtension:filterStr - conformingToType:UTTypeData]; - [filterStr release]; - if (filterType) [buildFilterList addObject:filterType]; - } - - NSArray* returnArray = [NSArray arrayWithArray:buildFilterList]; - - [buildFilterList release]; - - assert([returnArray count] != 0); - - return returnArray; -} -#else -// Returns an NSArray of NSString representing the file types. -static NSArray* BuildAllowedFileTypes(const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - NSMutableArray* buildFilterList = [[NSMutableArray alloc] init]; - - for (nfdfiltersize_t filterIndex = 0; filterIndex != filterCount; ++filterIndex) { - // this is the spec to parse (we don't use the friendly name on OS X) - const nfdnchar_t* filterSpec = filterList[filterIndex].spec; - - const nfdnchar_t* p_currentFilterBegin = filterSpec; - for (const nfdnchar_t* p_filterSpec = filterSpec; *p_filterSpec; ++p_filterSpec) { - if (*p_filterSpec == ',') { - // add the extension to the array - NSString* filterStr = [[[NSString alloc] - initWithBytes:(const void*)p_currentFilterBegin - length:(sizeof(nfdnchar_t) * (p_filterSpec - p_currentFilterBegin)) - encoding:NSUTF8StringEncoding] autorelease]; - [buildFilterList addObject:filterStr]; - p_currentFilterBegin = p_filterSpec + 1; - } - } - // add the extension to the array - NSString* filterStr = [NSString stringWithUTF8String:p_currentFilterBegin]; - [buildFilterList addObject:filterStr]; - } - - NSArray* returnArray = [NSArray arrayWithArray:buildFilterList]; - - [buildFilterList release]; - - assert([returnArray count] != 0); - - return returnArray; -} -#endif - -static void AddFilterListToDialog(NSSavePanel* dialog, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - // note: NSOpenPanel inherits from NSSavePanel. - - if (!filterCount) return; - - assert(filterList); - -// Make NSArray of file types and set it on the dialog -// We use setAllowedFileTypes or setAllowedContentTypes depending on the deployment target -#if NFD_MACOS_ALLOWEDCONTENTTYPES == 1 - NSArray* allowedContentTypes = BuildAllowedContentTypes(filterList, filterCount); - [dialog setAllowedContentTypes:allowedContentTypes]; -#else - NSArray* allowedFileTypes = BuildAllowedFileTypes(filterList, filterCount); - [dialog setAllowedFileTypes:allowedFileTypes]; -#endif -} - -static void SetDefaultPath(NSSavePanel* dialog, const nfdnchar_t* defaultPath) { - if (!defaultPath || !*defaultPath) return; - - NSString* defaultPathString = [NSString stringWithUTF8String:defaultPath]; - NSURL* url = [NSURL fileURLWithPath:defaultPathString isDirectory:YES]; - [dialog setDirectoryURL:url]; -} - -static void SetDefaultName(NSSavePanel* dialog, const nfdnchar_t* defaultName) { - if (!defaultName || !*defaultName) return; - - NSString* defaultNameString = [NSString stringWithUTF8String:defaultName]; - [dialog setNameFieldStringValue:defaultNameString]; -} - -static nfdresult_t CopyUtf8String(const char* utf8Str, nfdnchar_t** out) { - // byte count, not char count - size_t len = strlen(utf8Str); - - // Too bad we have to use additional memory for all the result paths, - // because we cannot reconstitute an NSString from a char* to release it properly. - *out = (nfdnchar_t*)NFDi_Malloc(len + 1); - if (*out) { - strcpy(*out, utf8Str); - return NFD_OKAY; - } - - return NFD_ERROR; -} - -static NSWindow* GetNativeWindowHandle(const nfdwindowhandle_t* parentWindow) { - if (parentWindow->type != NFD_WINDOW_HANDLE_TYPE_COCOA) { - return NULL; - } - return (NSWindow*)parentWindow->handle; -} - -/* public */ - -const char* NFD_GetError(void) { - return g_errorstr; -} - -void NFD_ClearError(void) { - NFDi_SetError(NULL); -} - -void NFD_FreePathN(nfdnchar_t* filePath) { - NFDi_Free((void*)filePath); -} - -void NFD_FreePathU8(nfdu8char_t* filePath) { - NFD_FreePathN(filePath); -} - -static NSApplicationActivationPolicy old_app_policy; - -nfdresult_t NFD_Init(void) { - NSApplication* app = [NSApplication sharedApplication]; - old_app_policy = [app activationPolicy]; - if (old_app_policy == NSApplicationActivationPolicyProhibited) { - if (![app setActivationPolicy:NSApplicationActivationPolicyAccessory]) { - NFDi_SetError("Failed to set activation policy."); - return NFD_ERROR; - } - } - return NFD_OKAY; -} - -/* call this to de-initialize NFD, if NFD_Init returned NFD_OKAY */ -void NFD_Quit(void) { - [[NSApplication sharedApplication] setActivationPolicy:old_app_policy]; -} - -nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args = {0}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - nfdresult_t result = NFD_CANCEL; - @autoreleasepool { - NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow); - if (keyWindow) { - [keyWindow makeKeyAndOrderFront:nil]; - } else { - keyWindow = [[NSApplication sharedApplication] keyWindow]; - } - - NSOpenPanel* dialog = [NSOpenPanel openPanel]; - [dialog setAllowsMultipleSelection:NO]; - - // Build the filter list - AddFilterListToDialog(dialog, args->filterList, args->filterCount); - - // Set the starting directory - SetDefaultPath(dialog, args->defaultPath); - - if ([dialog runModal] == NSModalResponseOK) { - const NSURL* url = [dialog URL]; - const char* utf8Path = [[url path] UTF8String]; - result = CopyUtf8String(utf8Path, outPath); - } - - // return focus to the key window (i.e. main window) - [keyWindow makeKeyAndOrderFront:nil]; - } - return result; -} - -nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { - return NFD_OpenDialogN(outPath, filterList, filterCount, defaultPath); -} - -nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdopendialogu8args_t* args) { - return NFD_OpenDialogN_With_Impl(version, outPath, args); -} - -nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args = {0}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - nfdresult_t result = NFD_CANCEL; - @autoreleasepool { - NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow); - if (keyWindow) { - [keyWindow makeKeyAndOrderFront:nil]; - } else { - keyWindow = [[NSApplication sharedApplication] keyWindow]; - } - - NSOpenPanel* dialog = [NSOpenPanel openPanel]; - [dialog setAllowsMultipleSelection:YES]; - - // Build the filter list - AddFilterListToDialog(dialog, args->filterList, args->filterCount); - - // Set the starting directory - SetDefaultPath(dialog, args->defaultPath); - - if ([dialog runModal] == NSModalResponseOK) { - const NSArray* urls = [dialog URLs]; - - if ([urls count] > 0) { - // have at least one URL, we return this NSArray - [urls retain]; - *outPaths = (const nfdpathset_t*)urls; - result = NFD_OKAY; - } - } - - // return focus to the key window (i.e. main window) - [keyWindow makeKeyAndOrderFront:nil]; - } - return result; -} - -nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { - return NFD_OpenDialogMultipleN(outPaths, filterList, filterCount, defaultPath); -} - -nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialogu8args_t* args) { - return NFD_OpenDialogMultipleN_With_Impl(version, outPaths, args); -} - -nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName) { - nfdsavedialognargs_t args = {0}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - args.defaultName = defaultName; - return NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdsavedialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - nfdresult_t result = NFD_CANCEL; - @autoreleasepool { - NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow); - if (keyWindow) { - [keyWindow makeKeyAndOrderFront:nil]; - } else { - keyWindow = [[NSApplication sharedApplication] keyWindow]; - } - - NSSavePanel* dialog = [NSSavePanel savePanel]; - [dialog setExtensionHidden:NO]; - // allow other file types, to give the user an escape hatch since you can't select "*.*" on - // Mac - [dialog setAllowsOtherFileTypes:TRUE]; - - // Build the filter list - AddFilterListToDialog(dialog, args->filterList, args->filterCount); - - // Set the starting directory - SetDefaultPath(dialog, args->defaultPath); - - // Set the default file name - SetDefaultName(dialog, args->defaultName); - - if ([dialog runModal] == NSModalResponseOK) { - const NSURL* url = [dialog URL]; - const char* utf8Path = [[url path] UTF8String]; - result = CopyUtf8String(utf8Path, outPath); - } - - // return focus to the key window (i.e. main window) - [keyWindow makeKeyAndOrderFront:nil]; - } - return result; -} - -nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) { - return NFD_SaveDialogN(outPath, filterList, filterCount, defaultPath, defaultName); -} - -nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdsavedialogu8args_t* args) { - return NFD_SaveDialogN_With_Impl(version, outPath, args); -} - -nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args = {0}; - args.defaultPath = defaultPath; - return NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - nfdresult_t result = NFD_CANCEL; - @autoreleasepool { - NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow); - if (keyWindow) { - [keyWindow makeKeyAndOrderFront:nil]; - } else { - keyWindow = [[NSApplication sharedApplication] keyWindow]; - } - - NSOpenPanel* dialog = [NSOpenPanel openPanel]; - [dialog setAllowsMultipleSelection:NO]; - [dialog setCanChooseDirectories:YES]; - [dialog setCanCreateDirectories:YES]; - [dialog setCanChooseFiles:NO]; - - // Set the starting directory - SetDefaultPath(dialog, args->defaultPath); - - if ([dialog runModal] == NSModalResponseOK) { - const NSURL* url = [dialog URL]; - const char* utf8Path = [[url path] UTF8String]; - result = CopyUtf8String(utf8Path, outPath); - } - - // return focus to the key window (i.e. main window) - [keyWindow makeKeyAndOrderFront:nil]; - } - return result; -} - -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) { - return NFD_PickFolderN(outPath, defaultPath); -} - -nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdpickfolderu8args_t* args) { - return NFD_PickFolderN_With_Impl(version, outPath, args); -} - -nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args = {0}; - args.defaultPath = defaultPath; - return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - nfdresult_t result = NFD_CANCEL; - @autoreleasepool { - NSWindow* keyWindow = GetNativeWindowHandle(&args->parentWindow); - if (keyWindow) { - [keyWindow makeKeyAndOrderFront:nil]; - } else { - keyWindow = [[NSApplication sharedApplication] keyWindow]; - } - - NSOpenPanel* dialog = [NSOpenPanel openPanel]; - [dialog setAllowsMultipleSelection:YES]; - [dialog setCanChooseDirectories:YES]; - [dialog setCanCreateDirectories:YES]; - [dialog setCanChooseFiles:NO]; - - // Set the starting directory - SetDefaultPath(dialog, args->defaultPath); - - if ([dialog runModal] == NSModalResponseOK) { - const NSArray* urls = [dialog URLs]; - - if ([urls count] > 0) { - // have at least one URL, we return this NSArray - [urls retain]; - *outPaths = (const nfdpathset_t*)urls; - result = NFD_OKAY; - } - } - - // return focus to the key window (i.e. main window) - [keyWindow makeKeyAndOrderFront:nil]; - } - return result; -} - -nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, - const nfdu8char_t* defaultPath) { - return NFD_PickFolderMultipleN(outPaths, defaultPath); -} - -nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfolderu8args_t* args) { - return NFD_PickFolderMultipleN_With_Impl(version, outPaths, args); -} - -nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count) { - const NSArray* urls = (const NSArray*)pathSet; - *count = [urls count]; - return NFD_OKAY; -} - -nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdnchar_t** outPath) { - const NSArray* urls = (const NSArray*)pathSet; - - @autoreleasepool { - // autoreleasepool needed because UTF8String method might use the pool - const NSURL* url = [urls objectAtIndex:index]; - const char* utf8Path = [[url path] UTF8String]; - return CopyUtf8String(utf8Path, outPath); - } -} - -nfdresult_t NFD_PathSet_GetPathU8(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdu8char_t** outPath) { - return NFD_PathSet_GetPathN(pathSet, index, outPath); -} - -void NFD_PathSet_FreePathN(const nfdnchar_t* filePath) { - // const_cast not supported on Mac - union { - const nfdnchar_t* constPath; - nfdnchar_t* nonConstPath; - } pathUnion; - - pathUnion.constPath = filePath; - - NFD_FreePathN(pathUnion.nonConstPath); -} - -void NFD_PathSet_FreePathU8(const nfdu8char_t* filePath) { - // const_cast not supported on Mac - union { - const nfdu8char_t* constPath; - nfdu8char_t* nonConstPath; - } pathUnion; - - pathUnion.constPath = filePath; - - NFD_FreePathU8(pathUnion.nonConstPath); -} - -void NFD_PathSet_Free(const nfdpathset_t* pathSet) { - const NSArray* urls = (const NSArray*)pathSet; - [urls release]; -} - -nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, nfdpathsetenum_t* outEnumerator) { - const NSArray* urls = (const NSArray*)pathSet; - - @autoreleasepool { - // autoreleasepool needed because NSEnumerator uses it - NSEnumerator* enumerator = [urls objectEnumerator]; - [enumerator retain]; - outEnumerator->ptr = (void*)enumerator; - } - - return NFD_OKAY; -} - -void NFD_PathSet_FreeEnum(nfdpathsetenum_t* enumerator) { - NSEnumerator* real_enum = (NSEnumerator*)enumerator->ptr; - [real_enum release]; -} - -nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath) { - NSEnumerator* real_enum = (NSEnumerator*)enumerator->ptr; - - @autoreleasepool { - // autoreleasepool needed because NSURL uses it - const NSURL* url = [real_enum nextObject]; - if (url) { - const char* utf8Path = [[url path] UTF8String]; - return CopyUtf8String(utf8Path, outPath); - } else { - *outPath = NULL; - return NFD_OKAY; - } - } -} - -nfdresult_t NFD_PathSet_EnumNextU8(nfdpathsetenum_t* enumerator, nfdu8char_t** outPath) { - return NFD_PathSet_EnumNextN(enumerator, outPath); -} diff --git a/externals/shared/lib/znfde/nativefiledialog/src/nfd_gtk.cpp b/externals/shared/lib/znfde/nativefiledialog/src/nfd_gtk.cpp deleted file mode 100644 index bdb62924a..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/src/nfd_gtk.cpp +++ /dev/null @@ -1,918 +0,0 @@ -/* - Native File Dialog Extended - Repository: https://github.com/btzy/nativefiledialog-extended - License: Zlib - Authors: Bernard Teo, Michael Labbe - - Note: We do not check for malloc failure on Linux - Linux overcommits memory! -*/ - -#include -#include -#if defined(GDK_WINDOWING_X11) -#include -#endif -#include -#include -#include -#include - -#include "nfd.h" - -namespace { - -template -struct Free_Guard { - T* data; - Free_Guard(T* freeable) noexcept : data(freeable) {} - ~Free_Guard() { NFDi_Free(data); } -}; - -template -struct FreeCheck_Guard { - T* data; - FreeCheck_Guard(T* freeable = nullptr) noexcept : data(freeable) {} - ~FreeCheck_Guard() { - if (data) NFDi_Free(data); - } -}; - -/* current error */ -const char* g_errorstr = nullptr; - -void NFDi_SetError(const char* msg) { - g_errorstr = msg; -} - -template -T* NFDi_Malloc(size_t bytes) { - void* ptr = malloc(bytes); - if (!ptr) NFDi_SetError("NFDi_Malloc failed."); - - return static_cast(ptr); -} - -template -void NFDi_Free(T* ptr) { - assert(ptr); - free(static_cast(ptr)); -} - -template -T* copy(const T* begin, const T* end, T* out) { - for (; begin != end; ++begin) { - *out++ = *begin; - } - return out; -} - -// Does not own the filter and extension. -struct Pair_GtkFileFilter_FileExtension { - GtkFileFilter* filter; - const nfdnchar_t* extensionBegin; - const nfdnchar_t* extensionEnd; -}; - -struct ButtonClickedArgs { - Pair_GtkFileFilter_FileExtension* map; - GtkFileChooser* chooser; -}; - -void AddFiltersToDialog(GtkFileChooser* chooser, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - if (filterCount) { - assert(filterList); - - // we have filters to add ... format and add them - - for (nfdfiltersize_t index = 0; index != filterCount; ++index) { - GtkFileFilter* filter = gtk_file_filter_new(); - - // count number of file extensions - size_t sep = 1; - for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) { - if (*p_spec == L',') { - ++sep; - } - } - - // friendly name conversions: "png,jpg" -> "Image files - // (png, jpg)" - - // calculate space needed (including the trailing '\0') - size_t nameSize = - sep + strlen(filterList[index].spec) + 3 + strlen(filterList[index].name); - - // malloc the required memory - nfdnchar_t* nameBuf = NFDi_Malloc(sizeof(nfdnchar_t) * nameSize); - - nfdnchar_t* p_nameBuf = nameBuf; - for (const nfdnchar_t* p_filterName = filterList[index].name; *p_filterName; - ++p_filterName) { - *p_nameBuf++ = *p_filterName; - } - *p_nameBuf++ = ' '; - *p_nameBuf++ = '('; - const nfdnchar_t* p_extensionStart = filterList[index].spec; - for (const nfdnchar_t* p_spec = filterList[index].spec; true; ++p_spec) { - if (*p_spec == ',' || !*p_spec) { - if (*p_spec == ',') { - *p_nameBuf++ = ','; - *p_nameBuf++ = ' '; - } - - // +1 for the trailing '\0' - nfdnchar_t* extnBuf = NFDi_Malloc(sizeof(nfdnchar_t) * - (p_spec - p_extensionStart + 3)); - nfdnchar_t* p_extnBufEnd = extnBuf; - *p_extnBufEnd++ = '*'; - *p_extnBufEnd++ = '.'; - p_extnBufEnd = copy(p_extensionStart, p_spec, p_extnBufEnd); - *p_extnBufEnd++ = '\0'; - assert((size_t)(p_extnBufEnd - extnBuf) == - sizeof(nfdnchar_t) * (p_spec - p_extensionStart + 3)); - gtk_file_filter_add_pattern(filter, extnBuf); - NFDi_Free(extnBuf); - - if (*p_spec) { - // update the extension start point - p_extensionStart = p_spec + 1; - } else { - // reached the '\0' character - break; - } - } else { - *p_nameBuf++ = *p_spec; - } - } - *p_nameBuf++ = ')'; - *p_nameBuf++ = '\0'; - assert((size_t)(p_nameBuf - nameBuf) == sizeof(nfdnchar_t) * nameSize); - - // add to the filter - gtk_file_filter_set_name(filter, nameBuf); - - // free the memory - NFDi_Free(nameBuf); - - // add filter to chooser - gtk_file_chooser_add_filter(chooser, filter); - } - } - - /* always append a wildcard option to the end*/ - - GtkFileFilter* filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, "All files"); - gtk_file_filter_add_pattern(filter, "*"); - gtk_file_chooser_add_filter(chooser, filter); -} - -// returns null-terminated map (trailing .filter is null) -Pair_GtkFileFilter_FileExtension* AddFiltersToDialogWithMap(GtkFileChooser* chooser, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - Pair_GtkFileFilter_FileExtension* map = NFDi_Malloc( - sizeof(Pair_GtkFileFilter_FileExtension) * (filterCount + 1)); - - if (filterCount) { - assert(filterList); - - // we have filters to add ... format and add them - - for (nfdfiltersize_t index = 0; index != filterCount; ++index) { - GtkFileFilter* filter = gtk_file_filter_new(); - - // store filter in map - map[index].filter = filter; - map[index].extensionBegin = filterList[index].spec; - map[index].extensionEnd = nullptr; - - // count number of file extensions - size_t sep = 1; - for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) { - if (*p_spec == L',') { - ++sep; - } - } - - // friendly name conversions: "png,jpg" -> "Image files - // (png, jpg)" - - // calculate space needed (including the trailing '\0') - size_t nameSize = - sep + strlen(filterList[index].spec) + 3 + strlen(filterList[index].name); - - // malloc the required memory - nfdnchar_t* nameBuf = NFDi_Malloc(sizeof(nfdnchar_t) * nameSize); - - nfdnchar_t* p_nameBuf = nameBuf; - for (const nfdnchar_t* p_filterName = filterList[index].name; *p_filterName; - ++p_filterName) { - *p_nameBuf++ = *p_filterName; - } - *p_nameBuf++ = ' '; - *p_nameBuf++ = '('; - const nfdnchar_t* p_extensionStart = filterList[index].spec; - for (const nfdnchar_t* p_spec = filterList[index].spec; true; ++p_spec) { - if (*p_spec == ',' || !*p_spec) { - if (*p_spec == ',') { - *p_nameBuf++ = ','; - *p_nameBuf++ = ' '; - } - - // +1 for the trailing '\0' - nfdnchar_t* extnBuf = NFDi_Malloc(sizeof(nfdnchar_t) * - (p_spec - p_extensionStart + 3)); - nfdnchar_t* p_extnBufEnd = extnBuf; - *p_extnBufEnd++ = '*'; - *p_extnBufEnd++ = '.'; - p_extnBufEnd = copy(p_extensionStart, p_spec, p_extnBufEnd); - *p_extnBufEnd++ = '\0'; - assert((size_t)(p_extnBufEnd - extnBuf) == - sizeof(nfdnchar_t) * (p_spec - p_extensionStart + 3)); - gtk_file_filter_add_pattern(filter, extnBuf); - NFDi_Free(extnBuf); - - // store current pointer in map (if it's - // the first one) - if (map[index].extensionEnd == nullptr) { - map[index].extensionEnd = p_spec; - } - - if (*p_spec) { - // update the extension start point - p_extensionStart = p_spec + 1; - } else { - // reached the '\0' character - break; - } - } else { - *p_nameBuf++ = *p_spec; - } - } - *p_nameBuf++ = ')'; - *p_nameBuf++ = '\0'; - assert((size_t)(p_nameBuf - nameBuf) == sizeof(nfdnchar_t) * nameSize); - - // add to the filter - gtk_file_filter_set_name(filter, nameBuf); - - // free the memory - NFDi_Free(nameBuf); - - // add filter to chooser - gtk_file_chooser_add_filter(chooser, filter); - } - } - // set trailing map index to null - map[filterCount].filter = nullptr; - - /* always append a wildcard option to the end*/ - GtkFileFilter* filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, "All files"); - gtk_file_filter_add_pattern(filter, "*"); - gtk_file_chooser_add_filter(chooser, filter); - - return map; -} - -void SetDefaultPath(GtkFileChooser* chooser, const char* defaultPath) { - if (!defaultPath || !*defaultPath) return; - - /* GTK+ manual recommends not specifically setting the default path. - We do it anyway in order to be consistent across platforms. - - If consistency with the native OS is preferred, this is the line - to comment out. -ml */ - gtk_file_chooser_set_current_folder(chooser, defaultPath); -} - -void SetDefaultName(GtkFileChooser* chooser, const char* defaultName) { - if (!defaultName || !*defaultName) return; - - gtk_file_chooser_set_current_name(chooser, defaultName); -} - -void WaitForCleanup() { - while (gtk_events_pending()) gtk_main_iteration(); -} - -struct Widget_Guard { - GtkWidget* data; - Widget_Guard(GtkWidget* widget) : data(widget) {} - ~Widget_Guard() { - WaitForCleanup(); - gtk_widget_destroy(data); - WaitForCleanup(); - } -}; - -void FileActivatedSignalHandler(GtkButton* saveButton, void* userdata) { - (void)saveButton; // silence the unused arg warning - - ButtonClickedArgs* args = static_cast(userdata); - GtkFileChooser* chooser = args->chooser; - char* currentFileName = gtk_file_chooser_get_current_name(chooser); - if (*currentFileName) { // string is not empty - - // find a '.' in the file name - const char* p_period = currentFileName; - for (; *p_period; ++p_period) { - if (*p_period == '.') { - break; - } - } - - if (!*p_period) { // there is no '.', so append the default extension - Pair_GtkFileFilter_FileExtension* filterMap = - static_cast(args->map); - GtkFileFilter* currentFilter = gtk_file_chooser_get_filter(chooser); - if (currentFilter) { - for (; filterMap->filter; ++filterMap) { - if (filterMap->filter == currentFilter) break; - } - } - if (filterMap->filter) { - // memory for appended string (including '.' and - // trailing '\0') - char* appendedFileName = NFDi_Malloc( - sizeof(char) * ((p_period - currentFileName) + - (filterMap->extensionEnd - filterMap->extensionBegin) + 2)); - char* p_fileName = copy(currentFileName, p_period, appendedFileName); - *p_fileName++ = '.'; - p_fileName = copy(filterMap->extensionBegin, filterMap->extensionEnd, p_fileName); - *p_fileName++ = '\0'; - - assert(p_fileName - appendedFileName == - (p_period - currentFileName) + - (filterMap->extensionEnd - filterMap->extensionBegin) + 2); - - // set the appended file name - gtk_file_chooser_set_current_name(chooser, appendedFileName); - - // free the memory - NFDi_Free(appendedFileName); - } - } - } - - // free the memory - g_free(currentFileName); -} - -// wrapper for gtk_dialog_run() that brings the dialog to the front -// see issues at: -// https://github.com/btzy/nativefiledialog-extended/issues/31 -// https://github.com/mlabbe/nativefiledialog/pull/92 -// https://github.com/guillaumechereau/noc/pull/11 -gint RunDialogWithFocus(GtkDialog* dialog) { -#if defined(GDK_WINDOWING_X11) - gtk_widget_show_all(GTK_WIDGET(dialog)); // show the dialog so that it gets a display - if (GDK_IS_X11_DISPLAY(gtk_widget_get_display(GTK_WIDGET(dialog)))) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(dialog)); - gdk_window_set_events( - window, - static_cast(gdk_window_get_events(window) | GDK_PROPERTY_CHANGE_MASK)); - gtk_window_present_with_time(GTK_WINDOW(dialog), gdk_x11_get_server_time(window)); - } -#endif - return gtk_dialog_run(dialog); -} - -// Gets the GdkWindow from the given window handle. This function might fail even if parentWindow -// is set correctly, since it calls some failable GDK functions. If it fails, it will return -// nullptr. The caller is responsible for freeing ths returned GdkWindow, if not nullptr. -GdkWindow* GetAllocNativeWindowHandle(const nfdwindowhandle_t& parentWindow) { - switch (parentWindow.type) { -#if defined(GDK_WINDOWING_X11) - case NFD_WINDOW_HANDLE_TYPE_X11: { - const Window x11_handle = reinterpret_cast(parentWindow.handle); - // AFAIK, _any_ X11 display will do, because Windows are not associated to a specific - // Display. Supposedly, a Display is just a connection to the X server. - - // This will contain the X11 display we want to use. - GdkDisplay* x11_display = nullptr; - GdkDisplayManager* display_manager = gdk_display_manager_get(); - - // If we can find an existing X11 display, use it. - GSList* gdk_display_list = gdk_display_manager_list_displays(display_manager); - while (gdk_display_list) { - GSList* node = gdk_display_list; - GdkDisplay* display = GDK_DISPLAY(node->data); - if (GDK_IS_X11_DISPLAY(display)) { - g_slist_free(node); - x11_display = display; - break; - } else { - gdk_display_list = node->next; - g_slist_free_1(node); - } - } - - // Otherwise, we have to create our own X11 display. - if (!x11_display) { - // This is not very nice, because we are always resetting the allowed backends - // setting to NULL (which means all backends are allowed), even though we can't be - // sure that the user didn't call gdk_set_allowed_backends() earlier to force a - // specific backend. But well if the user doesn't have an X11 display already open - // and yet is telling us with have an X11 window as parent, they probably don't use - // GTK in their application at all so they probably won't notice this. - // - // There is no way, AFAIK, to get the allowed backends first so we can restore it - // later, and gdk_x11_display_open() is GTK4-only (the GTK3 version is a private - // implementation detail). - // - // Also, we don't close the display we specially opened, since GTK will need it to - // show the dialog. Though it probably doesn't matter very much if we want to free - // up resources and clean it up. - gdk_set_allowed_backends("x11"); - x11_display = gdk_display_manager_open_display(display_manager, NULL); - gdk_set_allowed_backends(NULL); - } - if (!x11_display) return nullptr; - GdkWindow* gdk_window = gdk_x11_window_foreign_new_for_display(x11_display, x11_handle); - return gdk_window; - } -#endif - default: - return nullptr; - } -} - -void RealizedSignalHandler(GtkWidget* window, void* userdata) { - GdkWindow* const parentWindow = static_cast(userdata); - gdk_window_set_transient_for(gtk_widget_get_window(window), parentWindow); -} - -struct NativeWindowParenter { - NativeWindowParenter(GtkWidget* w, const nfdwindowhandle_t& parentWindow) noexcept : widget(w) { - parent = GetAllocNativeWindowHandle(parentWindow); - - if (parent) { - // set the handler to the realize signal to set the transient GDK parent - handlerID = g_signal_connect(G_OBJECT(widget), - "realize", - G_CALLBACK(RealizedSignalHandler), - static_cast(parent)); - - // make the dialog window use the same GtkScreen as the parent (so that parenting works) - gtk_window_set_screen(GTK_WINDOW(widget), gdk_window_get_screen(parent)); - } - } - ~NativeWindowParenter() { - if (parent) { - // unset the handler and delete the parent GdkWindow - g_signal_handler_disconnect(G_OBJECT(widget), handlerID); - g_object_unref(parent); - } - } - GtkWidget* const widget; - GdkWindow* parent; - gulong handlerID; -}; - -} // namespace - -const char* NFD_GetError(void) { - return g_errorstr; -} - -void NFD_ClearError(void) { - NFDi_SetError(nullptr); -} - -/* public */ - -nfdresult_t NFD_Init(void) { - // Init GTK - if (!gtk_init_check(NULL, NULL)) { - NFDi_SetError("Failed to initialize GTK+ with gtk_init_check."); - return NFD_ERROR; - } - return NFD_OKAY; -} -void NFD_Quit(void) { - // do nothing, GTK cannot be de-initialized -} - -void NFD_FreePathN(nfdnchar_t* filePath) { - assert(filePath); - g_free(filePath); -} - -void NFD_FreePathU8(nfdu8char_t* filePath) __attribute__((alias("NFD_FreePathN"))); - -nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - GtkWidget* widget = gtk_file_chooser_dialog_new("Open File", - nullptr, - GTK_FILE_CHOOSER_ACTION_OPEN, - "_Cancel", - GTK_RESPONSE_CANCEL, - "_Open", - GTK_RESPONSE_ACCEPT, - nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - /* Build the filter list */ - AddFiltersToDialog(GTK_FILE_CHOOSER(widget), args->filterList, args->filterCount); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), args->defaultPath); - - gint result; - { - /* Parent the window properly */ - NativeWindowParenter nativeWindowParenter(widget, args->parentWindow); - - /* invoke the dialog (blocks until dialog is closed) */ - result = RunDialogWithFocus(GTK_DIALOG(widget)); - } - - if (result == GTK_RESPONSE_ACCEPT) { - // write out the file name - *outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - - return NFD_OKAY; - } else { - return NFD_CANCEL; - } -} - -nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_OpenDialogN"))); - -nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdopendialogu8args_t* args) - __attribute__((alias("NFD_OpenDialogN_With_Impl"))); - -nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - GtkWidget* widget = gtk_file_chooser_dialog_new("Open Files", - nullptr, - GTK_FILE_CHOOSER_ACTION_OPEN, - "_Cancel", - GTK_RESPONSE_CANCEL, - "_Open", - GTK_RESPONSE_ACCEPT, - nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - // set select multiple - gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(widget), TRUE); - - /* Build the filter list */ - AddFiltersToDialog(GTK_FILE_CHOOSER(widget), args->filterList, args->filterCount); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), args->defaultPath); - - gint result; - { - /* Parent the window properly */ - NativeWindowParenter nativeWindowParenter(widget, args->parentWindow); - - /* invoke the dialog (blocks until dialog is closed) */ - result = RunDialogWithFocus(GTK_DIALOG(widget)); - } - - if (result == GTK_RESPONSE_ACCEPT) { - // write out the file name - GSList* fileList = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(widget)); - - *outPaths = static_cast(fileList); - return NFD_OKAY; - } else { - return NFD_CANCEL; - } -} - -nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_OpenDialogMultipleN"))); - -nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialogu8args_t* args) - __attribute__((alias("NFD_OpenDialogMultipleN_With_Impl"))); - -nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName) { - nfdsavedialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - args.defaultName = defaultName; - return NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdsavedialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - GtkWidget* widget = gtk_file_chooser_dialog_new("Save File", - nullptr, - GTK_FILE_CHOOSER_ACTION_SAVE, - "_Cancel", - GTK_RESPONSE_CANCEL, - nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - GtkWidget* saveButton = gtk_dialog_add_button(GTK_DIALOG(widget), "_Save", GTK_RESPONSE_ACCEPT); - - // Prompt on overwrite - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widget), TRUE); - - /* Build the filter list */ - ButtonClickedArgs buttonClickedArgs; - buttonClickedArgs.chooser = GTK_FILE_CHOOSER(widget); - buttonClickedArgs.map = - AddFiltersToDialogWithMap(GTK_FILE_CHOOSER(widget), args->filterList, args->filterCount); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), args->defaultPath); - - /* Set the default file name */ - SetDefaultName(GTK_FILE_CHOOSER(widget), args->defaultName); - - /* set the handler to add file extension */ - gulong handlerID = g_signal_connect(G_OBJECT(saveButton), - "pressed", - G_CALLBACK(FileActivatedSignalHandler), - static_cast(&buttonClickedArgs)); - - gint result; - { - /* Parent the window properly */ - NativeWindowParenter nativeWindowParenter(widget, args->parentWindow); - - /* invoke the dialog (blocks until dialog is closed) */ - result = RunDialogWithFocus(GTK_DIALOG(widget)); - } - - /* unset the handler */ - g_signal_handler_disconnect(G_OBJECT(saveButton), handlerID); - - /* free the filter map */ - NFDi_Free(buttonClickedArgs.map); - - if (result == GTK_RESPONSE_ACCEPT) { - // write out the file name - *outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - - return NFD_OKAY; - } else { - return NFD_CANCEL; - } -} - -nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) - __attribute__((alias("NFD_SaveDialogN"))); - -nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdsavedialogu8args_t* args) - __attribute__((alias("NFD_SaveDialogN_With_Impl"))); - -nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - GtkWidget* widget = gtk_file_chooser_dialog_new("Select Folder", - nullptr, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - "_Cancel", - GTK_RESPONSE_CANCEL, - "_Select", - GTK_RESPONSE_ACCEPT, - nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), args->defaultPath); - - gint result; - { - /* Parent the window properly */ - NativeWindowParenter nativeWindowParenter(widget, args->parentWindow); - - /* invoke the dialog (blocks until dialog is closed) */ - result = RunDialogWithFocus(GTK_DIALOG(widget)); - } - - if (result == GTK_RESPONSE_ACCEPT) { - // write out the file name - *outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - - return NFD_OKAY; - } else { - return NFD_CANCEL; - } -} - -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_PickFolderN"))); - -nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdpickfolderu8args_t* args) - __attribute__((alias("NFD_PickFolderN_With_Impl"))); - -nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - GtkWidget* widget = gtk_file_chooser_dialog_new("Select Folders", - nullptr, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - "_Cancel", - GTK_RESPONSE_CANCEL, - "_Select", - GTK_RESPONSE_ACCEPT, - nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), args->defaultPath); - - gint result; - { - /* Parent the window properly */ - NativeWindowParenter nativeWindowParenter(widget, args->parentWindow); - - /* invoke the dialog (blocks until dialog is closed) */ - result = RunDialogWithFocus(GTK_DIALOG(widget)); - } - - if (result == GTK_RESPONSE_ACCEPT) { - // write out the file name - GSList* fileList = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(widget)); - - *outPaths = static_cast(fileList); - return NFD_OKAY; - } else { - return NFD_CANCEL; - } -} - -nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_PickFolderMultipleN"))); - -nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfolderu8args_t* args) - __attribute__((alias("NFD_PickFolderMultipleN_With_Impl"))); - -nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count) { - assert(pathSet); - // const_cast because methods on GSList aren't const, but it should act - // like const to the caller - GSList* fileList = const_cast(static_cast(pathSet)); - - *count = g_slist_length(fileList); - return NFD_OKAY; -} - -nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdnchar_t** outPath) { - assert(pathSet); - // const_cast because methods on GSList aren't const, but it should act - // like const to the caller - GSList* fileList = const_cast(static_cast(pathSet)); - - // Note: this takes linear time... but should be good enough - *outPath = static_cast(g_slist_nth_data(fileList, index)); - - return NFD_OKAY; -} - -nfdresult_t NFD_PathSet_GetPathU8(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdu8char_t** outPath) - __attribute__((alias("NFD_PathSet_GetPathN"))); - -void NFD_PathSet_FreePathN(const nfdnchar_t* filePath) { - assert(filePath); - (void)filePath; // prevent warning in release build - // no-op, because NFD_PathSet_Free does the freeing for us -} - -void NFD_PathSet_FreePathU8(const nfdu8char_t* filePath) - __attribute__((alias("NFD_PathSet_FreePathN"))); - -void NFD_PathSet_Free(const nfdpathset_t* pathSet) { - assert(pathSet); - // const_cast because methods on GSList aren't const, but it should act - // like const to the caller - GSList* fileList = const_cast(static_cast(pathSet)); - - // free all the nodes - for (GSList* node = fileList; node; node = node->next) { - assert(node->data); - g_free(node->data); - } - - // free the path set memory - g_slist_free(fileList); -} - -nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, nfdpathsetenum_t* outEnumerator) { - // The pathset (GSList) is already a linked list, so the enumeration is itself - outEnumerator->ptr = const_cast(pathSet); - - return NFD_OKAY; -} - -void NFD_PathSet_FreeEnum(nfdpathsetenum_t*) { - // Do nothing, because the enumeration is the pathset itself -} - -nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath) { - const GSList* fileList = static_cast(enumerator->ptr); - - if (fileList) { - *outPath = static_cast(fileList->data); - enumerator->ptr = static_cast(fileList->next); - } else { - *outPath = nullptr; - } - - return NFD_OKAY; -} - -nfdresult_t NFD_PathSet_EnumNextU8(nfdpathsetenum_t* enumerator, nfdu8char_t** outPath) - __attribute__((alias("NFD_PathSet_EnumNextN"))); diff --git a/externals/shared/lib/znfde/nativefiledialog/src/nfd_portal.cpp b/externals/shared/lib/znfde/nativefiledialog/src/nfd_portal.cpp deleted file mode 100644 index 684c50286..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/src/nfd_portal.cpp +++ /dev/null @@ -1,1793 +0,0 @@ -/* - Native File Dialog Extended - Repository: https://github.com/btzy/nativefiledialog-extended - License: Zlib - Authors: Bernard Teo - - Note: We do not check for malloc failure on Linux - Linux overcommits memory! -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include // for access() - -#if !defined(__has_include) || !defined(__linux__) -#include // for getrandom() - the random token string -#elif __has_include() -#include -#else // for GLIBC < 2.25 -#include -#define getrandom(buf, sz, flags) syscall(SYS_getrandom, buf, sz, flags) -#endif - -#include "nfd.h" - -/* -Define NFD_APPEND_EXTENSION if you want the file extension to be appended when missing. Linux -programs usually don't append the file extension, but for consistency with other OSes you might want -to append it. However, when using portals, the file overwrite prompt and the Flatpak sandbox won't -know that we appended an extension, so they will not check or whitelist the correct file. Enabling -NFD_APPEND_EXTENSION is not recommended for portals. -*/ - -namespace { - -template -T* NFDi_Malloc(size_t bytes) { - void* ptr = malloc(bytes); - assert(ptr); // Linux malloc never fails - - return static_cast(ptr); -} - -template -void NFDi_Free(T* ptr) { - assert(ptr); - free(static_cast(ptr)); -} - -template -struct Free_Guard { - T* data; - Free_Guard(T* freeable) noexcept : data(freeable) {} - ~Free_Guard() { NFDi_Free(data); } -}; - -template -struct FreeCheck_Guard { - T* data; - FreeCheck_Guard(T* freeable = nullptr) noexcept : data(freeable) {} - ~FreeCheck_Guard() { - if (data) NFDi_Free(data); - } -}; - -struct DBusMessage_Guard { - DBusMessage* data; - DBusMessage_Guard(DBusMessage* freeable) noexcept : data(freeable) {} - ~DBusMessage_Guard() { dbus_message_unref(data); } -}; - -/* D-Bus connection handle */ -DBusConnection* dbus_conn; -/* current D-Bus error */ -DBusError dbus_err; -/* current non D-Bus error */ -constexpr size_t OWNED_ERR_LEN = 1024; -char owned_err[OWNED_ERR_LEN]{}; -/* current error (may be a pointer to dbus_err.message, owned_err, or a pointer to some string - * literal) */ -const char* err_ptr = nullptr; -/* the unique name of our connection, used for the Request handle; owned by D-Bus so we don't free - * it */ -const char* dbus_unique_name; - -void NFDi_SetError(const char* msg) { - err_ptr = msg; -} - -void NFDi_SetFormattedError(const char* format, ...) { - va_list args; - va_start(args, format); - vsnprintf(owned_err, OWNED_ERR_LEN, format, args); - va_end(args); - err_ptr = owned_err; -} - -template -T* copy(const T* begin, const T* end, T* out) { - for (; begin != end; ++begin) { - *out++ = *begin; - } - return out; -} - -template -T* transform(const T* begin, const T* end, T* out, Callback callback) { - for (; begin != end; ++begin) { - *out++ = callback(*begin); - } - return out; -} - -template -T* reverse_copy(const T* begin, const T* end, T* out) { - while (begin != end) { - *out++ = *--end; - } - return out; -} - -// Returns true if ch is in [0-9A-Za-z], false otherwise. -bool IsHex(char ch) { - return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || ('a' <= ch && ch <= 'f'); -} - -// Returns the hexadecimal value contained in the char. Precondition: IsHex(ch) -char ParseHexUnchecked(char ch) { - if ('0' <= ch && ch <= '9') return ch - '0'; - if ('A' <= ch && ch <= 'F') return ch - ('A' - 10); - if ('a' <= ch && ch <= 'f') return ch - ('a' - 10); -#if defined(__GNUC__) - __builtin_unreachable(); -#endif -} - -// Writes val as a hex string to out -char* FormatUIntToHexString(char* out, uintptr_t val) { - char tmp[sizeof(uintptr_t) * 2]; - char* tmp_end = tmp; - do { - const uintptr_t digit = val & 15u; - *tmp_end++ = digit < 10 ? '0' + digit : 'A' - 10 + digit; - val >>= 4; - } while (val != 0); - return reverse_copy(tmp, tmp_end, out); -} - -constexpr const char* STR_EMPTY = ""; -constexpr const char* STR_OPEN_FILE = "Open File"; -constexpr const char* STR_OPEN_FILES = "Open Files"; -constexpr const char* STR_SAVE_FILE = "Save File"; -constexpr const char* STR_SELECT_FOLDER = "Select Folder"; -constexpr const char* STR_SELECT_FOLDERS = "Select Folders"; -constexpr const char* STR_HANDLE_TOKEN = "handle_token"; -constexpr const char* STR_MULTIPLE = "multiple"; -constexpr const char* STR_DIRECTORY = "directory"; -constexpr const char* STR_FILTERS = "filters"; -constexpr const char* STR_CURRENT_FILTER = "current_filter"; -constexpr const char* STR_CURRENT_NAME = "current_name"; -constexpr const char* STR_CURRENT_FOLDER = "current_folder"; -constexpr const char* STR_CURRENT_FILE = "current_file"; -constexpr const char* STR_ALL_FILES = "All files"; -constexpr const char* STR_ASTERISK = "*"; -constexpr const char* DBUS_DESTINATION = "org.freedesktop.portal.Desktop"; -constexpr const char* DBUS_PATH = "/org/freedesktop/portal/desktop"; -constexpr const char* DBUS_FILECHOOSER_IFACE = "org.freedesktop.portal.FileChooser"; -constexpr const char* DBUS_REQUEST_IFACE = "org.freedesktop.portal.Request"; - -void AppendOpenFileQueryParentWindow(DBusMessageIter& iter, const nfdwindowhandle_t& parentWindow) { - switch (parentWindow.type) { - case NFD_WINDOW_HANDLE_TYPE_X11: { - constexpr size_t maxX11WindowStrLen = - 4 + sizeof(uintptr_t) * 2 + 1; // "x11:" + "" + "\0" - char serializedWindowBuf[maxX11WindowStrLen]; - char* serializedWindow = serializedWindowBuf; - const uintptr_t handle = reinterpret_cast(parentWindow.handle); - char* out = serializedWindowBuf; - *out++ = 'x'; - *out++ = '1'; - *out++ = '1'; - *out++ = ':'; - out = FormatUIntToHexString(out, handle); - *out = '\0'; - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &serializedWindow); - return; - } - default: { - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_EMPTY); - return; - } - } -} - -template -void AppendOpenFileQueryTitle(DBusMessageIter&); -template <> -void AppendOpenFileQueryTitle(DBusMessageIter& iter) { - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_OPEN_FILE); -} -template <> -void AppendOpenFileQueryTitle(DBusMessageIter& iter) { - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_OPEN_FILES); -} -template <> -void AppendOpenFileQueryTitle(DBusMessageIter& iter) { - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_SELECT_FOLDER); -} -template <> -void AppendOpenFileQueryTitle(DBusMessageIter& iter) { - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_SELECT_FOLDERS); -} - -void AppendSaveFileQueryTitle(DBusMessageIter& iter) { - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_SAVE_FILE); -} - -void AppendOpenFileQueryDictEntryHandleToken(DBusMessageIter& sub_iter, const char* handle_token) { - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_HANDLE_TOKEN); - dbus_message_iter_open_container(&sub_sub_iter, DBUS_TYPE_VARIANT, "s", &variant_iter); - dbus_message_iter_append_basic(&variant_iter, DBUS_TYPE_STRING, &handle_token); - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); -} - -template -void AppendOpenFileQueryDictEntryMultiple(DBusMessageIter&); -template <> -void AppendOpenFileQueryDictEntryMultiple(DBusMessageIter& sub_iter) { - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_MULTIPLE); - dbus_message_iter_open_container(&sub_sub_iter, DBUS_TYPE_VARIANT, "b", &variant_iter); - { - int b = true; - dbus_message_iter_append_basic(&variant_iter, DBUS_TYPE_BOOLEAN, &b); - } - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); -} -template <> -void AppendOpenFileQueryDictEntryMultiple(DBusMessageIter&) {} - -template -void AppendOpenFileQueryDictEntryDirectory(DBusMessageIter&); -template <> -void AppendOpenFileQueryDictEntryDirectory(DBusMessageIter& sub_iter) { - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_DIRECTORY); - dbus_message_iter_open_container(&sub_sub_iter, DBUS_TYPE_VARIANT, "b", &variant_iter); - { - int b = true; - dbus_message_iter_append_basic(&variant_iter, DBUS_TYPE_BOOLEAN, &b); - } - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); -} -template <> -void AppendOpenFileQueryDictEntryDirectory(DBusMessageIter&) {} - -void AppendSingleFilter(DBusMessageIter& base_iter, const nfdnfilteritem_t& filter) { - DBusMessageIter filter_list_struct_iter; - DBusMessageIter filter_sublist_iter; - DBusMessageIter filter_sublist_struct_iter; - dbus_message_iter_open_container( - &base_iter, DBUS_TYPE_STRUCT, nullptr, &filter_list_struct_iter); - // count number of file extensions - size_t sep = 1; - for (const char* p = filter.spec; *p; ++p) { - if (*p == L',') { - ++sep; - } - } - { - const size_t name_len = strlen(filter.name); - const size_t spec_len = strlen(filter.spec); - char* buf = static_cast(alloca(sep + name_len + 2 + spec_len + 1)); - char* buf_end = buf; - buf_end = copy(filter.name, filter.name + name_len, buf_end); - *buf_end++ = ' '; - *buf_end++ = '('; - const char* spec_ptr = filter.spec; - do { - *buf_end++ = *spec_ptr; - if (*spec_ptr == ',') *buf_end++ = ' '; - ++spec_ptr; - } while (*spec_ptr != '\0'); - *buf_end++ = ')'; - *buf_end = '\0'; - dbus_message_iter_append_basic(&filter_list_struct_iter, DBUS_TYPE_STRING, &buf); - } - { - dbus_message_iter_open_container( - &filter_list_struct_iter, DBUS_TYPE_ARRAY, "(us)", &filter_sublist_iter); - const char* extn_begin = filter.spec; - const char* extn_end = extn_begin; - while (true) { - dbus_message_iter_open_container( - &filter_sublist_iter, DBUS_TYPE_STRUCT, nullptr, &filter_sublist_struct_iter); - { - const unsigned zero = 0; - dbus_message_iter_append_basic( - &filter_sublist_struct_iter, DBUS_TYPE_UINT32, &zero); - } - do { - ++extn_end; - } while (*extn_end != ',' && *extn_end != '\0'); - char* buf = static_cast(alloca(2 + (extn_end - extn_begin) + 1)); - char* buf_end = buf; - *buf_end++ = '*'; - *buf_end++ = '.'; - buf_end = copy(extn_begin, extn_end, buf_end); - *buf_end = '\0'; - dbus_message_iter_append_basic(&filter_sublist_struct_iter, DBUS_TYPE_STRING, &buf); - dbus_message_iter_close_container(&filter_sublist_iter, &filter_sublist_struct_iter); - if (*extn_end == '\0') { - break; - } - extn_begin = extn_end + 1; - extn_end = extn_begin; - } - } - dbus_message_iter_close_container(&filter_list_struct_iter, &filter_sublist_iter); - dbus_message_iter_close_container(&base_iter, &filter_list_struct_iter); -} - -bool AppendSingleFilterCheckExtn(DBusMessageIter& base_iter, - const nfdnfilteritem_t& filter, - const nfdnchar_t* match_extn) { - DBusMessageIter filter_list_struct_iter; - DBusMessageIter filter_sublist_iter; - DBusMessageIter filter_sublist_struct_iter; - dbus_message_iter_open_container( - &base_iter, DBUS_TYPE_STRUCT, nullptr, &filter_list_struct_iter); - // count number of file extensions - size_t sep = 1; - for (const char* p = filter.spec; *p; ++p) { - if (*p == L',') { - ++sep; - } - } - { - const size_t name_len = strlen(filter.name); - const size_t spec_len = strlen(filter.spec); - char* buf = static_cast(alloca(sep + name_len + 2 + spec_len + 1)); - char* buf_end = buf; - buf_end = copy(filter.name, filter.name + name_len, buf_end); - *buf_end++ = ' '; - *buf_end++ = '('; - const char* spec_ptr = filter.spec; - do { - *buf_end++ = *spec_ptr; - if (*spec_ptr == ',') *buf_end++ = ' '; - ++spec_ptr; - } while (*spec_ptr != '\0'); - *buf_end++ = ')'; - *buf_end = '\0'; - dbus_message_iter_append_basic(&filter_list_struct_iter, DBUS_TYPE_STRING, &buf); - } - bool extn_matched = false; - { - dbus_message_iter_open_container( - &filter_list_struct_iter, DBUS_TYPE_ARRAY, "(us)", &filter_sublist_iter); - const char* extn_begin = filter.spec; - const char* extn_end = extn_begin; - while (true) { - dbus_message_iter_open_container( - &filter_sublist_iter, DBUS_TYPE_STRUCT, nullptr, &filter_sublist_struct_iter); - { - const unsigned zero = 0; - dbus_message_iter_append_basic( - &filter_sublist_struct_iter, DBUS_TYPE_UINT32, &zero); - } - do { - ++extn_end; - } while (*extn_end != ',' && *extn_end != '\0'); - char* buf = static_cast(alloca(2 + (extn_end - extn_begin) + 1)); - char* buf_end = buf; - *buf_end++ = '*'; - *buf_end++ = '.'; - buf_end = copy(extn_begin, extn_end, buf_end); - *buf_end = '\0'; - dbus_message_iter_append_basic(&filter_sublist_struct_iter, DBUS_TYPE_STRING, &buf); - dbus_message_iter_close_container(&filter_sublist_iter, &filter_sublist_struct_iter); - if (!extn_matched) { - const char* match_extn_p; - const char* p; - for (p = extn_begin, match_extn_p = match_extn; p != extn_end && *match_extn_p; - ++p, ++match_extn_p) { - if (*p != *match_extn_p) break; - } - if (p == extn_end && !*match_extn_p) { - extn_matched = true; - } - } - if (*extn_end == '\0') { - break; - } - extn_begin = extn_end + 1; - extn_end = extn_begin; - } - } - dbus_message_iter_close_container(&filter_list_struct_iter, &filter_sublist_iter); - dbus_message_iter_close_container(&base_iter, &filter_list_struct_iter); - return extn_matched; -} - -void AppendWildcardFilter(DBusMessageIter& base_iter) { - DBusMessageIter filter_list_struct_iter; - DBusMessageIter filter_sublist_iter; - DBusMessageIter filter_sublist_struct_iter; - dbus_message_iter_open_container( - &base_iter, DBUS_TYPE_STRUCT, nullptr, &filter_list_struct_iter); - dbus_message_iter_append_basic(&filter_list_struct_iter, DBUS_TYPE_STRING, &STR_ALL_FILES); - dbus_message_iter_open_container( - &filter_list_struct_iter, DBUS_TYPE_ARRAY, "(us)", &filter_sublist_iter); - dbus_message_iter_open_container( - &filter_sublist_iter, DBUS_TYPE_STRUCT, nullptr, &filter_sublist_struct_iter); - { - const unsigned zero = 0; - dbus_message_iter_append_basic(&filter_sublist_struct_iter, DBUS_TYPE_UINT32, &zero); - } - dbus_message_iter_append_basic(&filter_sublist_struct_iter, DBUS_TYPE_STRING, &STR_ASTERISK); - dbus_message_iter_close_container(&filter_sublist_iter, &filter_sublist_struct_iter); - dbus_message_iter_close_container(&filter_list_struct_iter, &filter_sublist_iter); - dbus_message_iter_close_container(&base_iter, &filter_list_struct_iter); -} - -template -void AppendOpenFileQueryDictEntryFilters(DBusMessageIter&, - const nfdnfilteritem_t*, - nfdfiltersize_t); -template <> -void AppendOpenFileQueryDictEntryFilters(DBusMessageIter& sub_iter, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - if (filterCount != 0) { - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - DBusMessageIter filter_list_iter; - - // filters - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_FILTERS); - dbus_message_iter_open_container( - &sub_sub_iter, DBUS_TYPE_VARIANT, "a(sa(us))", &variant_iter); - dbus_message_iter_open_container( - &variant_iter, DBUS_TYPE_ARRAY, "(sa(us))", &filter_list_iter); - for (nfdfiltersize_t i = 0; i != filterCount; ++i) { - AppendSingleFilter(filter_list_iter, filterList[i]); - } - AppendWildcardFilter(filter_list_iter); - dbus_message_iter_close_container(&variant_iter, &filter_list_iter); - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); - - // current_filter - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_CURRENT_FILTER); - dbus_message_iter_open_container( - &sub_sub_iter, DBUS_TYPE_VARIANT, "(sa(us))", &variant_iter); - AppendSingleFilter(variant_iter, filterList[0]); - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); - } -} -template <> -void AppendOpenFileQueryDictEntryFilters(DBusMessageIter&, - const nfdnfilteritem_t*, - nfdfiltersize_t) {} - -void AppendSaveFileQueryDictEntryFilters(DBusMessageIter& sub_iter, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultName) { - if (filterCount != 0) { - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - DBusMessageIter filter_list_iter; - - // The extension of the defaultName (without the '.'). If NULL, it means that there is no - // extension. - const nfdnchar_t* extn = NULL; - if (defaultName) { - const nfdnchar_t* p = defaultName; - while (*p) ++p; - while (*--p != '.') - ; - ++p; - if (*p) extn = p; - } - bool extn_matched = false; - size_t selected_filter_index; - - // filters - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_FILTERS); - dbus_message_iter_open_container( - &sub_sub_iter, DBUS_TYPE_VARIANT, "a(sa(us))", &variant_iter); - dbus_message_iter_open_container( - &variant_iter, DBUS_TYPE_ARRAY, "(sa(us))", &filter_list_iter); - for (nfdfiltersize_t i = 0; i != filterCount; ++i) { - if (!extn_matched && extn) { - extn_matched = AppendSingleFilterCheckExtn(filter_list_iter, filterList[i], extn); - if (extn_matched) selected_filter_index = i; - } else { - AppendSingleFilter(filter_list_iter, filterList[i]); - } - } - AppendWildcardFilter(filter_list_iter); - dbus_message_iter_close_container(&variant_iter, &filter_list_iter); - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); - - // current_filter - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_CURRENT_FILTER); - dbus_message_iter_open_container( - &sub_sub_iter, DBUS_TYPE_VARIANT, "(sa(us))", &variant_iter); - if (extn_matched) { - AppendSingleFilter(variant_iter, filterList[selected_filter_index]); - } else { - AppendWildcardFilter(variant_iter); - } - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); - } -} - -void AppendSaveFileQueryDictEntryCurrentName(DBusMessageIter& sub_iter, const char* name) { - if (!name) return; - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_CURRENT_NAME); - dbus_message_iter_open_container(&sub_sub_iter, DBUS_TYPE_VARIANT, "s", &variant_iter); - dbus_message_iter_append_basic(&variant_iter, DBUS_TYPE_STRING, &name); - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); -} - -void AppendOpenFileQueryDictEntryCurrentFolder(DBusMessageIter& sub_iter, const char* path) { - if (!path) return; - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - DBusMessageIter array_iter; - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_CURRENT_FOLDER); - dbus_message_iter_open_container(&sub_sub_iter, DBUS_TYPE_VARIANT, "ay", &variant_iter); - dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY, "y", &array_iter); - // Append string as byte array, including the terminating null byte as required by the portal. - const char* p = path; - do { - dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_BYTE, p); - } while (*p++); - dbus_message_iter_close_container(&variant_iter, &array_iter); - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); -} - -void AppendSaveFileQueryDictEntryCurrentFile(DBusMessageIter& sub_iter, - const char* path, - const char* name) { - if (!path || !name) return; - const size_t path_len = strlen(path); - const size_t name_len = strlen(name); - char* pathname; - char* pathname_end; - size_t pathname_len; - if (path_len && path[path_len - 1] == '/') { - pathname_len = path_len + name_len; - pathname = NFDi_Malloc(pathname_len + 1); - pathname_end = pathname; - pathname_end = copy(path, path + path_len, pathname_end); - pathname_end = copy(name, name + name_len, pathname_end); - *pathname_end++ = '\0'; - } else { - pathname_len = path_len + 1 + name_len; - pathname = NFDi_Malloc(pathname_len + 1); - pathname_end = pathname; - pathname_end = copy(path, path + path_len, pathname_end); - *pathname_end++ = '/'; - pathname_end = copy(name, name + name_len, pathname_end); - *pathname_end++ = '\0'; - } - Free_Guard guard(pathname); - if (access(pathname, F_OK) != 0) return; - DBusMessageIter sub_sub_iter; - DBusMessageIter variant_iter; - DBusMessageIter array_iter; - dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, nullptr, &sub_sub_iter); - dbus_message_iter_append_basic(&sub_sub_iter, DBUS_TYPE_STRING, &STR_CURRENT_FILE); - dbus_message_iter_open_container(&sub_sub_iter, DBUS_TYPE_VARIANT, "ay", &variant_iter); - dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY, "y", &array_iter); - // This includes the terminating null character, which is required by the portal. - for (const char* p = pathname; p != pathname_end; ++p) { - dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_BYTE, p); - } - dbus_message_iter_close_container(&variant_iter, &array_iter); - dbus_message_iter_close_container(&sub_sub_iter, &variant_iter); - dbus_message_iter_close_container(&sub_iter, &sub_sub_iter); -} - -// Append OpenFile() portal params to the given query. -template -void AppendOpenFileQueryParams(DBusMessage* query, - const char* handle_token, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdwindowhandle_t& parentWindow) { - DBusMessageIter iter; - dbus_message_iter_init_append(query, &iter); - - AppendOpenFileQueryParentWindow(iter, parentWindow); - AppendOpenFileQueryTitle(iter); - - DBusMessageIter sub_iter; - dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub_iter); - AppendOpenFileQueryDictEntryHandleToken(sub_iter, handle_token); - AppendOpenFileQueryDictEntryMultiple(sub_iter); - AppendOpenFileQueryDictEntryDirectory(sub_iter); - AppendOpenFileQueryDictEntryFilters(sub_iter, filterList, filterCount); - AppendOpenFileQueryDictEntryCurrentFolder(sub_iter, defaultPath); - dbus_message_iter_close_container(&iter, &sub_iter); -} - -// Append SaveFile() portal params to the given query. -void AppendSaveFileQueryParams(DBusMessage* query, - const char* handle_token, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName, - const nfdwindowhandle_t& parentWindow) { - DBusMessageIter iter; - dbus_message_iter_init_append(query, &iter); - - AppendOpenFileQueryParentWindow(iter, parentWindow); - AppendSaveFileQueryTitle(iter); - - DBusMessageIter sub_iter; - dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub_iter); - AppendOpenFileQueryDictEntryHandleToken(sub_iter, handle_token); - AppendSaveFileQueryDictEntryFilters(sub_iter, filterList, filterCount, defaultName); - AppendSaveFileQueryDictEntryCurrentName(sub_iter, defaultName); - AppendOpenFileQueryDictEntryCurrentFolder(sub_iter, defaultPath); - AppendSaveFileQueryDictEntryCurrentFile(sub_iter, defaultPath, defaultName); - dbus_message_iter_close_container(&iter, &sub_iter); -} - -nfdresult_t ReadDictImpl(const char*, DBusMessageIter&) { - return NFD_OKAY; -} - -template -nfdresult_t ReadDictImpl(const char* key, - DBusMessageIter& iter, - const char*& candidate_key, - Callback& candidate_callback, - Args&... args) { - if (strcmp(key, candidate_key) == 0) { - // this is the correct callback - return candidate_callback(iter); - } else { - return ReadDictImpl(key, iter, args...); - } -} - -// Read a dictionary from the given iterator. The type of the element under this iterator will be -// checked. The args are alternately key and callback. Key is a const char*, and callback is a -// function that returns nfdresult_t. Return NFD_ERROR to stop processing and return immediately. -template -nfdresult_t ReadDict(DBusMessageIter iter, Args... args) { - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) { - NFDi_SetError("D-Bus response signal argument is not an array."); - return NFD_ERROR; - } - DBusMessageIter sub_iter; - dbus_message_iter_recurse(&iter, &sub_iter); - while (dbus_message_iter_get_arg_type(&sub_iter) == DBUS_TYPE_DICT_ENTRY) { - DBusMessageIter de_iter; - dbus_message_iter_recurse(&sub_iter, &de_iter); - if (dbus_message_iter_get_arg_type(&de_iter) != DBUS_TYPE_STRING) { - NFDi_SetError("D-Bus response signal dict entry does not start with a string."); - return NFD_ERROR; - } - const char* key; - dbus_message_iter_get_basic(&de_iter, &key); - if (!dbus_message_iter_next(&de_iter)) { - NFDi_SetError("D-Bus response signal dict entry is missing one or more arguments."); - return NFD_ERROR; - } - // unwrap the variant - if (dbus_message_iter_get_arg_type(&de_iter) != DBUS_TYPE_VARIANT) { - NFDi_SetError("D-Bus response signal dict entry value is not a variant."); - return NFD_ERROR; - } - DBusMessageIter de_variant_iter; - dbus_message_iter_recurse(&de_iter, &de_variant_iter); - if (ReadDictImpl(key, de_variant_iter, args...) == NFD_ERROR) return NFD_ERROR; - if (!dbus_message_iter_next(&sub_iter)) break; - } - return NFD_OKAY; -} - -// Read the message, returning an iterator to the `results` dictionary of the response. If response -// was okay, then returns NFD_OKAY and set `resultsIter` to the results dictionary iterator (this is -// the iterator to the entire dictionary (which has type DBUS_TYPE_ARRAY), not an iterator to the -// first item in the dictionary). It does not check that this iterator is DBUS_TYPE_ARRAY; you -// should use ReadDict() which will check it. Otherwise, returns NFD_CANCEL or NFD_ERROR as -// appropriate, and does not modify `resultsIter`. `resultsIter` can be copied by value. -nfdresult_t ReadResponseResults(DBusMessage* msg, DBusMessageIter& resultsIter) { - DBusMessageIter iter; - if (!dbus_message_iter_init(msg, &iter)) { - NFDi_SetError("D-Bus response signal is missing one or more arguments."); - return NFD_ERROR; - } - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) { - NFDi_SetError("D-Bus response signal argument is not a uint32."); - return NFD_ERROR; - } - dbus_uint32_t resp_code; - dbus_message_iter_get_basic(&iter, &resp_code); - if (resp_code != 0) { - if (resp_code == 1) { - // User pressed cancel - return NFD_CANCEL; - } else { - // Some error occurred - NFDi_SetFormattedError( - "D-Bus file dialog interaction was ended abruptly with response code %u.", - resp_code); - return NFD_ERROR; - } - } - // User successfully responded - if (!dbus_message_iter_next(&iter)) { - NFDi_SetError("D-Bus response signal is missing one or more arguments."); - return NFD_ERROR; - } - resultsIter = iter; - return NFD_OKAY; -} - -// Read the message. If response was okay, then returns NFD_OKAY and set `uriIter` to the URI array -// iterator. Otherwise, returns NFD_CANCEL or NFD_ERROR as appropriate, and does not modify -// `uriIter`. `uriIter` can be copied by value. -nfdresult_t ReadResponseUris(DBusMessage* msg, DBusMessageIter& uriIter) { - DBusMessageIter iter; - const nfdresult_t res = ReadResponseResults(msg, iter); - if (res != NFD_OKAY) return res; - bool has_uris = false; - if (ReadDict(iter, "uris", [&uriIter, &has_uris](DBusMessageIter& uris_iter) { - if (dbus_message_iter_get_arg_type(&uris_iter) != DBUS_TYPE_ARRAY) { - NFDi_SetError("D-Bus response signal URI iter is not an array."); - return NFD_ERROR; - } - dbus_message_iter_recurse(&uris_iter, &uriIter); - has_uris = true; - return NFD_OKAY; - }) == NFD_ERROR) - return NFD_ERROR; - - if (!has_uris) { - NFDi_SetError("D-Bus response signal has no URI field."); - return NFD_ERROR; - } - return NFD_OKAY; -} - -// Same as ReadResponseUris, but does not perform any message type checks. -// You should only use this if you previously used ReadResponseUris and it returned NFD_OKAY! -void ReadResponseUrisUnchecked(DBusMessage* msg, DBusMessageIter& uriIter) { - DBusMessageIter iter; - dbus_message_iter_init(msg, &iter); - dbus_message_iter_next(&iter); - ReadDict(iter, "uris", [&uriIter](DBusMessageIter& uris_iter) { - dbus_message_iter_recurse(&uris_iter, &uriIter); - return NFD_OKAY; - }); -} -nfdpathsetsize_t ReadResponseUrisUncheckedGetArraySize(DBusMessage* msg) { - DBusMessageIter iter; - dbus_message_iter_init(msg, &iter); - dbus_message_iter_next(&iter); - nfdpathsetsize_t sz = 0; // Initialization will never be used, but we initialize it to prevent - // the uninitialized warning otherwise. - ReadDict(iter, "uris", [&sz](DBusMessageIter& uris_iter) { - sz = dbus_message_iter_get_element_count(&uris_iter); - return NFD_OKAY; - }); - return sz; -} - -// Read the response URI. If response was okay, then returns NFD_OKAY and set file to it (the -// pointer is set to some string owned by msg, so you should not manually free it). Otherwise, -// returns NFD_CANCEL or NFD_ERROR as appropriate, and does not modify `file`. -nfdresult_t ReadResponseUrisSingle(DBusMessage* msg, const char*& file) { - DBusMessageIter uri_iter; - const nfdresult_t res = ReadResponseUris(msg, uri_iter); - if (res != NFD_OKAY) return res; // can be NFD_CANCEL or NFD_ERROR - if (dbus_message_iter_get_arg_type(&uri_iter) != DBUS_TYPE_STRING) { - NFDi_SetError("D-Bus response signal URI sub iter is not a string."); - return NFD_ERROR; - } - dbus_message_iter_get_basic(&uri_iter, &file); - return NFD_OKAY; -} - -#ifdef NFD_APPEND_EXTENSION -// Read the response URI and selected extension (in the form "*.abc" or "*") (if any). If response -// was okay, then returns NFD_OKAY and set file and extn to them (the pointer is set to some string -// owned by msg, so you should not manually free it). `file` is the user-entered file name, and -// `extn` is the selected file extension (the first one if there are multiple extensions in the -// selected option) (this is NULL if "All files" is selected). Otherwise, returns NFD_CANCEL or -// NFD_ERROR as appropriate, and does not modify `file` and `extn`. -nfdresult_t ReadResponseUrisSingleAndCurrentExtension(DBusMessage* msg, - const char*& file, - const char*& extn) { - DBusMessageIter iter; - const nfdresult_t res = ReadResponseResults(msg, iter); - if (res != NFD_OKAY) return res; - const char* tmp_file = nullptr; - const char* tmp_extn = nullptr; - if (ReadDict( - iter, - "uris", - [&tmp_file](DBusMessageIter& uris_iter) { - if (dbus_message_iter_get_arg_type(&uris_iter) != DBUS_TYPE_ARRAY) { - NFDi_SetError("D-Bus response signal URI iter is not an array."); - return NFD_ERROR; - } - DBusMessageIter uri_iter; - dbus_message_iter_recurse(&uris_iter, &uri_iter); - if (dbus_message_iter_get_arg_type(&uri_iter) != DBUS_TYPE_STRING) { - NFDi_SetError("D-Bus response signal URI sub iter is not a string."); - return NFD_ERROR; - } - dbus_message_iter_get_basic(&uri_iter, &tmp_file); - return NFD_OKAY; - }, - "current_filter", - [&tmp_extn](DBusMessageIter& current_filter_iter) { - // current_filter is best_effort, so if we fail, we still return NFD_OKAY. - if (dbus_message_iter_get_arg_type(¤t_filter_iter) != DBUS_TYPE_STRUCT) { - return NFD_OKAY; - } - DBusMessageIter current_filter_struct_iter; - dbus_message_iter_recurse(¤t_filter_iter, ¤t_filter_struct_iter); - if (!dbus_message_iter_next(¤t_filter_struct_iter)) { - return NFD_OKAY; - } - if (dbus_message_iter_get_arg_type(¤t_filter_struct_iter) != - DBUS_TYPE_ARRAY) { - return NFD_OKAY; - } - DBusMessageIter current_filter_array_iter; - dbus_message_iter_recurse(¤t_filter_struct_iter, ¤t_filter_array_iter); - if (dbus_message_iter_get_arg_type(¤t_filter_array_iter) != - DBUS_TYPE_STRUCT) { - return NFD_OKAY; - } - DBusMessageIter current_filter_extn_iter; - dbus_message_iter_recurse(¤t_filter_array_iter, ¤t_filter_extn_iter); - if (dbus_message_iter_get_arg_type(¤t_filter_extn_iter) != DBUS_TYPE_UINT32) { - return NFD_OKAY; - } - dbus_uint32_t type; - dbus_message_iter_get_basic(¤t_filter_extn_iter, &type); - if (type != 0) { - return NFD_OKAY; - } - if (!dbus_message_iter_next(¤t_filter_extn_iter)) { - return NFD_OKAY; - } - if (dbus_message_iter_get_arg_type(¤t_filter_extn_iter) != DBUS_TYPE_STRING) { - return NFD_OKAY; - } - dbus_message_iter_get_basic(¤t_filter_extn_iter, &tmp_extn); - return NFD_OKAY; - }) == NFD_ERROR) - return NFD_ERROR; - - if (!tmp_file) { - NFDi_SetError("D-Bus response signal has no URI field."); - return NFD_ERROR; - } - file = tmp_file; - extn = tmp_extn; - return NFD_OKAY; -} -#endif - -// Appends up to 64 random chars to the given pointer. Returns the end of the appended chars. -char* Generate64RandomChars(char* out) { - size_t amount = 32; - while (amount > 0) { - unsigned char buf[32]; - ssize_t res = getrandom(buf, amount, 0); - if (res == -1) { - if (errno == EINTR) - continue; - else - break; // too bad, urandom isn't working well - } - amount -= res; - // we encode each random char using two chars, since they must be [A-Z][a-z][0-9]_ - for (size_t i = 0; i != static_cast(res); ++i) { - *out++ = 'A' + static_cast(buf[i] & 15); - *out++ = 'A' + static_cast(buf[i] >> 4); - } - } - return out; -} - -constexpr const char STR_RESPONSE_HANDLE_PREFIX[] = "/org/freedesktop/portal/desktop/request/"; -constexpr size_t STR_RESPONSE_HANDLE_PREFIX_LEN = - sizeof(STR_RESPONSE_HANDLE_PREFIX) - 1; // -1 to remove the \0. - -// Allocates and returns a path like "/org/freedesktop/portal/desktop/request/SENDER/TOKEN" with -// randomly generated TOKEN as recommended by flatpak. `handle_token_ptr` is a pointer to the -// TOKEN part. -char* MakeUniqueObjectPath(const char** handle_token_ptr) { - const char* sender = dbus_unique_name; - if (*sender == ':') ++sender; - const size_t sender_len = strlen(sender); - const size_t sz = STR_RESPONSE_HANDLE_PREFIX_LEN + sender_len + 1 + - 64; // 1 for '/', followed by 64 random chars - char* path = NFDi_Malloc(sz + 1); - char* path_ptr = path; - path_ptr = copy(STR_RESPONSE_HANDLE_PREFIX, - STR_RESPONSE_HANDLE_PREFIX + STR_RESPONSE_HANDLE_PREFIX_LEN, - path_ptr); - path_ptr = transform( - sender, sender + sender_len, path_ptr, [](char ch) { return ch != '.' ? ch : '_'; }); - *path_ptr++ = '/'; - *handle_token_ptr = path_ptr; - path_ptr = Generate64RandomChars(path_ptr); - *path_ptr = '\0'; - return path; -} - -constexpr const char STR_RESPONSE_SUBSCRIPTION_PATH_1[] = - "type='signal',sender='org.freedesktop.portal.Desktop',path='"; -constexpr const char STR_RESPONSE_SUBSCRIPTION_PATH_1_LEN = - sizeof(STR_RESPONSE_SUBSCRIPTION_PATH_1) - 1; -constexpr const char STR_RESPONSE_SUBSCRIPTION_PATH_2[] = - "',interface='org.freedesktop.portal.Request',member='Response',destination='"; -constexpr const char STR_RESPONSE_SUBSCRIPTION_PATH_2_LEN = - sizeof(STR_RESPONSE_SUBSCRIPTION_PATH_2) - 1; -constexpr const char STR_RESPONSE_SUBSCRIPTION_PATH_3[] = "'"; -constexpr const char STR_RESPONSE_SUBSCRIPTION_PATH_3_LEN = - sizeof(STR_RESPONSE_SUBSCRIPTION_PATH_3) - 1; - -class DBusSignalSubscriptionHandler { - private: - char* sub_cmd; - - public: - DBusSignalSubscriptionHandler() : sub_cmd(nullptr) {} - ~DBusSignalSubscriptionHandler() { - if (sub_cmd) Unsubscribe(); - } - - nfdresult_t Subscribe(const char* handle_path) { - if (sub_cmd) Unsubscribe(); - sub_cmd = MakeResponseSubscriptionPath(handle_path, dbus_unique_name); - DBusError err; - dbus_error_init(&err); - dbus_bus_add_match(dbus_conn, sub_cmd, &err); - if (dbus_error_is_set(&err)) { - dbus_error_free(&dbus_err); - dbus_move_error(&err, &dbus_err); - NFDi_SetError(dbus_err.message); - return NFD_ERROR; - } - return NFD_OKAY; - } - - void Unsubscribe() { - DBusError err; - dbus_error_init(&err); - dbus_bus_remove_match(dbus_conn, sub_cmd, &err); - NFDi_Free(sub_cmd); - sub_cmd = nullptr; - dbus_error_free( - &err); // silence unsubscribe errors, because this is intuitively part of 'cleanup' - } - - private: - static char* MakeResponseSubscriptionPath(const char* handle_path, const char* unique_name) { - const size_t handle_path_len = strlen(handle_path); - const size_t unique_name_len = strlen(unique_name); - const size_t sz = STR_RESPONSE_SUBSCRIPTION_PATH_1_LEN + handle_path_len + - STR_RESPONSE_SUBSCRIPTION_PATH_2_LEN + unique_name_len + - STR_RESPONSE_SUBSCRIPTION_PATH_3_LEN; - char* res = NFDi_Malloc(sz + 1); - char* res_ptr = res; - res_ptr = copy(STR_RESPONSE_SUBSCRIPTION_PATH_1, - STR_RESPONSE_SUBSCRIPTION_PATH_1 + STR_RESPONSE_SUBSCRIPTION_PATH_1_LEN, - res_ptr); - res_ptr = copy(handle_path, handle_path + handle_path_len, res_ptr); - res_ptr = copy(STR_RESPONSE_SUBSCRIPTION_PATH_2, - STR_RESPONSE_SUBSCRIPTION_PATH_2 + STR_RESPONSE_SUBSCRIPTION_PATH_2_LEN, - res_ptr); - res_ptr = copy(unique_name, unique_name + unique_name_len, res_ptr); - res_ptr = copy(STR_RESPONSE_SUBSCRIPTION_PATH_3, - STR_RESPONSE_SUBSCRIPTION_PATH_3 + STR_RESPONSE_SUBSCRIPTION_PATH_3_LEN, - res_ptr); - *res_ptr = '\0'; - return res; - } -}; - -// Returns true if the given file URI is decodable (i.e. not malformed), and false otherwise. -// If this function returns true, then `out` will be populated with the length of the decoded URI -// and `fileUriEnd` will point to the trailing null byte of `fileUri`. Otherwise, `out` and -// `fileUriEnd` will be unmodified. -bool TryUriDecodeLen(const char* fileUri, size_t& out, const char*& fileUriEnd) { - size_t len = 0; - while (*fileUri) { - if (*fileUri != '%') { - ++fileUri; - } else { - if (*(fileUri + 1) == '\0' || *(fileUri + 2) == '\0') { - return false; - } - if (!IsHex(*(fileUri + 1)) || !IsHex(*(fileUri + 2))) { - return false; - } - fileUri += 3; - } - ++len; - } - out = len; - fileUriEnd = fileUri; - return true; -} - -// Decodes the given URI and writes it to `outPath`. The caller must ensure that the given URI is -// not malformed (typically with a prior call to `TryUriDecodeLen`). This function does not write -// any trailing null character. -char* UriDecodeUnchecked(const char* fileUri, const char* fileUriEnd, char* outPath) { - while (fileUri != fileUriEnd) { - if (*fileUri != '%') { - *outPath++ = *fileUri++; - } else { - ++fileUri; - const char high_nibble = ParseHexUnchecked(*fileUri++); - const char low_nibble = ParseHexUnchecked(*fileUri++); - *outPath++ = (high_nibble << 4) | low_nibble; - } - } - return outPath; -} - -constexpr const char FILE_URI_PREFIX[] = "file://"; -constexpr size_t FILE_URI_PREFIX_LEN = sizeof(FILE_URI_PREFIX) - 1; - -// If fileUri starts with "file://", strips that prefix and URI-decodes the remaining part to a new -// buffer, and make outPath point to it, and returns NFD_OKAY. Otherwise, does not modify outPath -// and returns NFD_ERROR (with the correct error set) -nfdresult_t AllocAndCopyFilePath(const char* fileUri, char*& outPath) { - const char* file_uri_iter = fileUri; - const char* prefix_begin = FILE_URI_PREFIX; - const char* const prefix_end = FILE_URI_PREFIX + FILE_URI_PREFIX_LEN; - for (; prefix_begin != prefix_end; ++prefix_begin, ++file_uri_iter) { - if (*prefix_begin != *file_uri_iter) { - NFDi_SetFormattedError( - "D-Bus freedesktop portal returned \"%s\", which is not a file URI.", fileUri); - return NFD_ERROR; - } - } - size_t decoded_len; - const char* file_uri_end; - if (!TryUriDecodeLen(file_uri_iter, decoded_len, file_uri_end)) { - NFDi_SetFormattedError("D-Bus freedesktop portal returned a malformed URI \"%s\".", - fileUri); - return NFD_ERROR; - } - char* const path_without_prefix = NFDi_Malloc(decoded_len + 1); - char* const out_end = UriDecodeUnchecked(file_uri_iter, file_uri_end, path_without_prefix); - *out_end = '\0'; - outPath = path_without_prefix; - return NFD_OKAY; -} - -#ifdef NFD_APPEND_EXTENSION -bool TryGetValidExtension(const char* extn, - const char*& trimmed_extn, - const char*& trimmed_extn_end) { - if (!extn) return false; - if (*extn != '*') return false; - ++extn; - if (*extn != '.') return false; - trimmed_extn = extn; - for (++extn; *extn != '\0'; ++extn) - ; - ++extn; - trimmed_extn_end = extn; - return true; -} - -// Like AllocAndCopyFilePath, but if `fileUri` has no extension and `extn` is usable, appends the -// extension. `extn` could be null, in which case no extension will ever be appended. `extn` is -// expected to be either in the form "*.abc" or "*", but this function will check for it, and ignore -// the extension if it is not in the correct form. -nfdresult_t AllocAndCopyFilePathWithExtn(const char* fileUri, const char* extn, char*& outPath) { - const char* file_uri_iter = fileUri; - const char* prefix_begin = FILE_URI_PREFIX; - const char* const prefix_end = FILE_URI_PREFIX + FILE_URI_PREFIX_LEN; - for (; prefix_begin != prefix_end; ++prefix_begin, ++file_uri_iter) { - if (*prefix_begin != *file_uri_iter) { - NFDi_SetFormattedError( - "D-Bus freedesktop portal returned \"%s\", which is not a file URI.", fileUri); - return NFD_ERROR; - } - } - - size_t decoded_len; - const char* file_uri_end; - if (!TryUriDecodeLen(file_uri_iter, decoded_len, file_uri_end)) { - NFDi_SetFormattedError("D-Bus freedesktop portal returned a malformed URI \"%s\".", - fileUri); - return NFD_ERROR; - } - - const char* file_it = file_uri_end; - // The following loop condition is safe because `FILE_URI_PREFIX` ends with '/', - // so we won't iterate past the beginning of the URI. - // Also in UTF-8 all non-ASCII code points are encoded using bytes 128-255 so every '.' or '/' - // is also '.' or '/' in UTF-8. - do { - --file_it; - } while (*file_it != '/' && *file_it != '.'); - const char* trimmed_extn; // includes the '.' - const char* trimmed_extn_end; // includes the '\0' - if (*file_it == '.' || !TryGetValidExtension(extn, trimmed_extn, trimmed_extn_end)) { - // has file extension already or no valid extension in `extn` - char* const path_without_prefix = NFDi_Malloc(decoded_len + 1); - char* const out_end = UriDecodeUnchecked(file_uri_iter, file_uri_end, path_without_prefix); - *out_end = '\0'; - outPath = path_without_prefix; - } else { - // no file extension and we have a valid extension - char* const path_without_prefix = - NFDi_Malloc(decoded_len + (trimmed_extn_end - trimmed_extn)); - char* const out_mid = UriDecodeUnchecked(file_uri_iter, file_uri_end, path_without_prefix); - char* const out_end = copy(trimmed_extn, trimmed_extn_end, out_mid); - *out_end = '\0'; - outPath = path_without_prefix; - } - return NFD_OKAY; -} -#endif - -// DBus wrapper function that helps invoke the portal for all OpenFile() variants. -// This function returns NFD_OKAY iff outMsg gets set (to the returned message). -// Caller is responsible for freeing the outMsg using dbus_message_unref() (or use -// DBusMessage_Guard). -template -nfdresult_t NFD_DBus_OpenFile(DBusMessage*& outMsg, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdwindowhandle_t& parentWindow) { - const char* handle_token_ptr; - char* handle_obj_path = MakeUniqueObjectPath(&handle_token_ptr); - Free_Guard handle_obj_path_guard(handle_obj_path); - - DBusError err; // need a separate error object because we don't want to mess with the old one - // if it's stil set - dbus_error_init(&err); - - // Subscribe to the signal using the handle_obj_path - DBusSignalSubscriptionHandler signal_sub; - nfdresult_t res = signal_sub.Subscribe(handle_obj_path); - if (res != NFD_OKAY) return res; - - // TODO: use XOpenDisplay()/XGetInputFocus() to find xid of window... but what should one do on - // Wayland? - - DBusMessage* query = dbus_message_new_method_call( - DBUS_DESTINATION, DBUS_PATH, DBUS_FILECHOOSER_IFACE, "OpenFile"); - DBusMessage_Guard query_guard(query); - AppendOpenFileQueryParams( - query, handle_token_ptr, filterList, filterCount, defaultPath, parentWindow); - - DBusMessage* reply = - dbus_connection_send_with_reply_and_block(dbus_conn, query, DBUS_TIMEOUT_INFINITE, &err); - if (!reply) { - dbus_error_free(&dbus_err); - dbus_move_error(&err, &dbus_err); - NFDi_SetError(dbus_err.message); - return NFD_ERROR; - } - DBusMessage_Guard reply_guard(reply); - - // Check the reply and update our signal subscription if necessary - { - DBusMessageIter iter; - if (!dbus_message_iter_init(reply, &iter)) { - NFDi_SetError("D-Bus reply is missing an argument."); - return NFD_ERROR; - } - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) { - NFDi_SetError("D-Bus reply is not an object path."); - return NFD_ERROR; - } - - const char* path; - dbus_message_iter_get_basic(&iter, &path); - if (strcmp(path, handle_obj_path) != 0) { - // needs to change our signal subscription - signal_sub.Subscribe(path); - } - } - - // Wait and read the response - // const char* file = nullptr; - do { - while (true) { - DBusMessage* msg = dbus_connection_pop_message(dbus_conn); - if (!msg) break; - - if (dbus_message_is_signal(msg, DBUS_REQUEST_IFACE, "Response")) { - // this is the response we're looking for - outMsg = msg; - return NFD_OKAY; - } - - dbus_message_unref(msg); - } - } while (dbus_connection_read_write(dbus_conn, -1)); - - NFDi_SetError("D-Bus freedesktop portal did not give us a reply."); - return NFD_ERROR; -} - -// DBus wrapper function that helps invoke the portal for the SaveFile() API. -// This function returns NFD_OKAY iff outMsg gets set (to the returned message). -// Caller is responsible for freeing the outMsg using dbus_message_unref() (or use -// DBusMessage_Guard). -nfdresult_t NFD_DBus_SaveFile(DBusMessage*& outMsg, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName, - const nfdwindowhandle_t& parentWindow) { - const char* handle_token_ptr; - char* handle_obj_path = MakeUniqueObjectPath(&handle_token_ptr); - Free_Guard handle_obj_path_guard(handle_obj_path); - - DBusError err; // need a separate error object because we don't want to mess with the old one - // if it's stil set - dbus_error_init(&err); - - // Subscribe to the signal using the handle_obj_path - DBusSignalSubscriptionHandler signal_sub; - nfdresult_t res = signal_sub.Subscribe(handle_obj_path); - if (res != NFD_OKAY) return res; - - // TODO: use XOpenDisplay()/XGetInputFocus() to find xid of window... but what should one do on - // Wayland? - - DBusMessage* query = dbus_message_new_method_call( - DBUS_DESTINATION, DBUS_PATH, DBUS_FILECHOOSER_IFACE, "SaveFile"); - DBusMessage_Guard query_guard(query); - AppendSaveFileQueryParams( - query, handle_token_ptr, filterList, filterCount, defaultPath, defaultName, parentWindow); - - DBusMessage* reply = - dbus_connection_send_with_reply_and_block(dbus_conn, query, DBUS_TIMEOUT_INFINITE, &err); - if (!reply) { - dbus_error_free(&dbus_err); - dbus_move_error(&err, &dbus_err); - NFDi_SetError(dbus_err.message); - return NFD_ERROR; - } - DBusMessage_Guard reply_guard(reply); - - // Check the reply and update our signal subscription if necessary - { - DBusMessageIter iter; - if (!dbus_message_iter_init(reply, &iter)) { - NFDi_SetError("D-Bus reply is missing an argument."); - return NFD_ERROR; - } - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) { - NFDi_SetError("D-Bus reply is not an object path."); - return NFD_ERROR; - } - - const char* path; - dbus_message_iter_get_basic(&iter, &path); - if (strcmp(path, handle_obj_path) != 0) { - // needs to change our signal subscription - signal_sub.Subscribe(path); - } - } - - // Wait and read the response - // const char* file = nullptr; - do { - while (true) { - DBusMessage* msg = dbus_connection_pop_message(dbus_conn); - if (!msg) break; - - if (dbus_message_is_signal(msg, DBUS_REQUEST_IFACE, "Response")) { - // this is the response we're looking for - outMsg = msg; - return NFD_OKAY; - } - - dbus_message_unref(msg); - } - } while (dbus_connection_read_write(dbus_conn, -1)); - - NFDi_SetError("D-Bus freedesktop portal did not give us a reply."); - return NFD_ERROR; -} - -nfdresult_t NFD_DBus_GetVersion(dbus_uint32_t& outVersion) { - DBusError err; // need a separate error object because we don't want to mess with the old one - // if it's stil set - dbus_error_init(&err); - - DBusMessage* query = dbus_message_new_method_call("org.freedesktop.portal.Desktop", - "/org/freedesktop/portal/desktop", - "org.freedesktop.DBus.Properties", - "Get"); - DBusMessage_Guard query_guard(query); - { - DBusMessageIter iter; - dbus_message_iter_init_append(query, &iter); - - constexpr const char* STR_INTERFACE = "org.freedesktop.portal.FileChooser"; - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_INTERFACE); - constexpr const char* STR_VERSION = "version"; - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &STR_VERSION); - } - - DBusMessage* reply = - dbus_connection_send_with_reply_and_block(dbus_conn, query, DBUS_TIMEOUT_INFINITE, &err); - if (!reply) { - dbus_error_free(&dbus_err); - dbus_move_error(&err, &dbus_err); - NFDi_SetError(dbus_err.message); - return NFD_ERROR; - } - DBusMessage_Guard reply_guard(reply); - { - DBusMessageIter iter; - if (!dbus_message_iter_init(reply, &iter)) { - NFDi_SetError("D-Bus reply for version query is missing an argument."); - return NFD_ERROR; - } - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { - NFDi_SetError("D-Bus reply for version query is not a variant."); - return NFD_ERROR; - } - DBusMessageIter variant_iter; - dbus_message_iter_recurse(&iter, &variant_iter); - if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_UINT32) { - NFDi_SetError("D-Bus reply for version query is not a uint32."); - return NFD_ERROR; - } - dbus_message_iter_get_basic(&variant_iter, &outVersion); - } - - return NFD_OKAY; -} - -} // namespace - -/* public */ - -const char* NFD_GetError(void) { - return err_ptr; -} - -void NFD_ClearError(void) { - NFDi_SetError(nullptr); - dbus_error_free(&dbus_err); -} - -nfdresult_t NFD_Init(void) { - // Initialize dbus_err - dbus_error_init(&dbus_err); - // Get DBus connection - dbus_conn = dbus_bus_get(DBUS_BUS_SESSION, &dbus_err); - if (!dbus_conn) { - NFDi_SetError(dbus_err.message); - return NFD_ERROR; - } - dbus_unique_name = dbus_bus_get_unique_name(dbus_conn); - if (!dbus_unique_name) { - NFDi_SetError("Unable to get the unique name of our D-Bus connection."); - return NFD_ERROR; - } - return NFD_OKAY; -} -void NFD_Quit(void) { - dbus_connection_unref(dbus_conn); - // Note: We do not free dbus_error since NFD_Init might set it. - // To avoid leaking memory, the caller should explicitly call NFD_ClearError after reading the - // error. -} - -void NFD_FreePathN(nfdnchar_t* filePath) { - assert(filePath); - NFDi_Free(filePath); -} - -void NFD_FreePathU8(nfdu8char_t* filePath) __attribute__((alias("NFD_FreePathN"))); - -nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - DBusMessage* msg; - { - const nfdresult_t res = NFD_DBus_OpenFile( - msg, args->filterList, args->filterCount, args->defaultPath, args->parentWindow); - if (res != NFD_OKAY) { - return res; - } - } - DBusMessage_Guard msg_guard(msg); - - const char* uri; - { - const nfdresult_t res = ReadResponseUrisSingle(msg, uri); - if (res != NFD_OKAY) { - return res; - } - } - - return AllocAndCopyFilePath(uri, *outPath); -} - -nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_OpenDialogN"))); - -nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdopendialogu8args_t* args) - __attribute__((alias("NFD_OpenDialogN_With_Impl"))); - -nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - DBusMessage* msg; - { - const nfdresult_t res = NFD_DBus_OpenFile( - msg, args->filterList, args->filterCount, args->defaultPath, args->parentWindow); - if (res != NFD_OKAY) { - return res; - } - } - - DBusMessageIter uri_iter; - const nfdresult_t res = ReadResponseUris(msg, uri_iter); - if (res != NFD_OKAY) { - dbus_message_unref(msg); - return res; - } - - *outPaths = msg; - return NFD_OKAY; -} - -nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_OpenDialogMultipleN"))); - -nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialogu8args_t* args) - __attribute__((alias("NFD_OpenDialogMultipleN_With_Impl"))); - -nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName) { - nfdsavedialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - args.defaultName = defaultName; - return NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdsavedialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - DBusMessage* msg; - { - const nfdresult_t res = NFD_DBus_SaveFile(msg, - args->filterList, - args->filterCount, - args->defaultPath, - args->defaultName, - args->parentWindow); - if (res != NFD_OKAY) { - return res; - } - } - DBusMessage_Guard msg_guard(msg); - -#ifdef NFD_APPEND_EXTENSION - const char* uri; - const char* extn; - { - const nfdresult_t res = ReadResponseUrisSingleAndCurrentExtension(msg, uri, extn); - if (res != NFD_OKAY) { - return res; - } - } - - return AllocAndCopyFilePathWithExtn(uri, extn, *outPath); -#else - const char* uri; - { - const nfdresult_t res = ReadResponseUrisSingle(msg, uri); - if (res != NFD_OKAY) { - return res; - } - } - - return AllocAndCopyFilePath(uri, *outPath); -#endif -} - -nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) - __attribute__((alias("NFD_SaveDialogN"))); - -nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdsavedialogu8args_t* args) - __attribute__((alias("NFD_SaveDialogN_With_Impl"))); - -nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - { - dbus_uint32_t portal_version; - const nfdresult_t res = NFD_DBus_GetVersion(portal_version); - if (res != NFD_OKAY) { - return res; - } - if (portal_version < 3) { - NFDi_SetFormattedError( - "The xdg-desktop-portal installed on this system does not support a folder picker; " - "at least version 3 of the org.freedesktop.portal.FileChooser interface is " - "required but the installed interface version is %u.", - portal_version); - return NFD_ERROR; - } - } - - DBusMessage* msg; - { - const nfdresult_t res = - NFD_DBus_OpenFile(msg, nullptr, 0, args->defaultPath, args->parentWindow); - if (res != NFD_OKAY) { - return res; - } - } - DBusMessage_Guard msg_guard(msg); - - const char* uri; - { - const nfdresult_t res = ReadResponseUrisSingle(msg, uri); - if (res != NFD_OKAY) { - return res; - } - } - - return AllocAndCopyFilePath(uri, *outPath); -} - -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_PickFolderN"))); - -nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdpickfolderu8args_t* args) - __attribute__((alias("NFD_PickFolderN_With_Impl"))); - -nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - { - dbus_uint32_t portal_version; - const nfdresult_t res = NFD_DBus_GetVersion(portal_version); - if (res != NFD_OKAY) { - return res; - } - if (portal_version < 3) { - NFDi_SetFormattedError( - "The xdg-desktop-portal installed on this system does not support a folder picker; " - "at least version 3 of the org.freedesktop.portal.FileChooser interface is " - "required but the installed interface version is %u.", - portal_version); - return NFD_ERROR; - } - } - - DBusMessage* msg; - { - const nfdresult_t res = - NFD_DBus_OpenFile(msg, nullptr, 0, args->defaultPath, args->parentWindow); - if (res != NFD_OKAY) { - return res; - } - } - - DBusMessageIter uri_iter; - const nfdresult_t res = ReadResponseUris(msg, uri_iter); - if (res != NFD_OKAY) { - dbus_message_unref(msg); - return res; - } - - *outPaths = msg; - return NFD_OKAY; -} - -nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, const nfdu8char_t* defaultPath) - __attribute__((alias("NFD_PickFolderMultipleN"))); - -nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfolderu8args_t* args) - __attribute__((alias("NFD_PickFolderMultipleN_With_Impl"))); - -nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count) { - assert(pathSet); - DBusMessage* msg = const_cast(static_cast(pathSet)); - *count = ReadResponseUrisUncheckedGetArraySize(msg); - return NFD_OKAY; -} - -nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdnchar_t** outPath) { - assert(pathSet); - DBusMessage* msg = const_cast(static_cast(pathSet)); - DBusMessageIter uri_iter; - ReadResponseUrisUnchecked(msg, uri_iter); - nfdpathsetsize_t rem_index = index; - while (rem_index > 0) { - --rem_index; - if (!dbus_message_iter_next(&uri_iter)) { - NFDi_SetFormattedError( - "Index out of bounds; you asked for index %u but there are only %u file paths " - "available.", - index, - index - rem_index); - return NFD_ERROR; - } - } - if (dbus_message_iter_get_arg_type(&uri_iter) != DBUS_TYPE_STRING) { - NFDi_SetError("D-Bus response signal URI sub iter is not a string."); - return NFD_ERROR; - } - const char* uri; - dbus_message_iter_get_basic(&uri_iter, &uri); - return AllocAndCopyFilePath(uri, *outPath); -} - -nfdresult_t NFD_PathSet_GetPathU8(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdu8char_t** outPath) - __attribute__((alias("NFD_PathSet_GetPathN"))); - -void NFD_PathSet_FreePathN(const nfdnchar_t* filePath) { - assert(filePath); - NFD_FreePathN(const_cast(filePath)); -} - -void NFD_PathSet_FreePathU8(const nfdu8char_t* filePath) - __attribute__((alias("NFD_PathSet_FreePathN"))); - -void NFD_PathSet_Free(const nfdpathset_t* pathSet) { - assert(pathSet); - DBusMessage* msg = const_cast(static_cast(pathSet)); - dbus_message_unref(msg); -} - -nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, nfdpathsetenum_t* outEnumerator) { - assert(pathSet); - DBusMessage* msg = const_cast(static_cast(pathSet)); - ReadResponseUrisUnchecked(msg, *reinterpret_cast(outEnumerator)); - return NFD_OKAY; -} - -void NFD_PathSet_FreeEnum(nfdpathsetenum_t*) { - // Do nothing, because the enumeration is just a message iterator -} - -nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath) { - DBusMessageIter& uri_iter = *reinterpret_cast(enumerator); - const int arg_type = dbus_message_iter_get_arg_type(&uri_iter); - if (arg_type == DBUS_TYPE_INVALID) { - *outPath = nullptr; - return NFD_OKAY; - } - if (arg_type != DBUS_TYPE_STRING) { - NFDi_SetError("D-Bus response signal URI sub iter is not a string."); - return NFD_ERROR; - } - const char* uri; - dbus_message_iter_get_basic(&uri_iter, &uri); - const nfdresult_t res = AllocAndCopyFilePath(uri, *outPath); - if (res != NFD_OKAY) return res; - dbus_message_iter_next(&uri_iter); - return NFD_OKAY; -} - -nfdresult_t NFD_PathSet_EnumNextU8(nfdpathsetenum_t* enumerator, nfdu8char_t** outPath) - __attribute__((alias("NFD_PathSet_EnumNextN"))); diff --git a/externals/shared/lib/znfde/nativefiledialog/src/nfd_win.cpp b/externals/shared/lib/znfde/nativefiledialog/src/nfd_win.cpp deleted file mode 100644 index 0170b02a2..000000000 --- a/externals/shared/lib/znfde/nativefiledialog/src/nfd_win.cpp +++ /dev/null @@ -1,1185 +0,0 @@ -/* - Native File Dialog Extended - Repository: https://github.com/btzy/nativefiledialog-extended - License: Zlib - Author: Bernard Teo - */ - -/* only locally define UNICODE in this compilation unit */ -#ifndef UNICODE -#define UNICODE -#endif - -#ifdef __MINGW32__ -// Explicitly setting NTDDI version, this is necessary for the MinGW compiler -#define NTDDI_VERSION NTDDI_VISTA -#define _WIN32_WINNT _WIN32_WINNT_VISTA -#endif - -#if _MSC_VER -// see -// https://developercommunity.visualstudio.com/content/problem/185399/error-c2760-in-combaseapih-with-windows-sdk-81-and.html -struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error: 'identifier' was - // unexpected here" when using /permissive- -#endif - -#include -#include -#include -#include -#include -#include "nfd.h" - -namespace { - -/* current error */ -const char* g_errorstr = nullptr; - -void NFDi_SetError(const char* msg) { - g_errorstr = msg; -} - -template -T* NFDi_Malloc(size_t bytes) { - void* ptr = malloc(bytes); - if (!ptr) NFDi_SetError("NFDi_Malloc failed."); - - return static_cast(ptr); -} - -template -void NFDi_Free(T* ptr) { - assert(ptr); - free(static_cast(ptr)); -} - -/* guard objects */ -template -struct Release_Guard { - T* data; - Release_Guard(T* releasable) noexcept : data(releasable) {} - ~Release_Guard() { data->Release(); } -}; - -template -struct Free_Guard { - T* data; - Free_Guard(T* freeable) noexcept : data(freeable) {} - ~Free_Guard() { NFDi_Free(data); } -}; - -template -struct FreeCheck_Guard { - T* data; - FreeCheck_Guard(T* freeable = nullptr) noexcept : data(freeable) {} - ~FreeCheck_Guard() { - if (data) NFDi_Free(data); - } -}; - -/* helper functions */ -nfdresult_t AddFiltersToDialog(::IFileDialog* fileOpenDialog, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - /* filterCount plus 1 because we hardcode the *.* wildcard after the while loop */ - COMDLG_FILTERSPEC* specList = - NFDi_Malloc(sizeof(COMDLG_FILTERSPEC) * (filterCount + 1)); - if (!specList) { - return NFD_ERROR; - } - - /* ad-hoc RAII object to free memory when destructing */ - struct COMDLG_FILTERSPEC_Guard { - COMDLG_FILTERSPEC* _specList; - nfdfiltersize_t index; - COMDLG_FILTERSPEC_Guard(COMDLG_FILTERSPEC* specList) noexcept - : _specList(specList), index(0) {} - ~COMDLG_FILTERSPEC_Guard() { - for (--index; index != static_cast(-1); --index) { - NFDi_Free(const_cast(_specList[index].pszSpec)); - } - NFDi_Free(_specList); - } - }; - - COMDLG_FILTERSPEC_Guard specListGuard(specList); - - if (filterCount) { - assert(filterList); - - // we have filters to add ... format and add them - - // use the index that comes from the RAII object (instead of making a copy), so the RAII - // object will know which memory to free - nfdfiltersize_t& index = specListGuard.index; - - for (; index != filterCount; ++index) { - // set the friendly name of this filter - specList[index].pszName = filterList[index].name; - - // set the specification of this filter... - - // count number of file extensions - size_t sep = 1; - for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) { - if (*p_spec == L',') { - ++sep; - } - } - - // calculate space needed (including the trailing '\0') - size_t specSize = sep * 2 + wcslen(filterList[index].spec) + 1; - - // malloc the required memory and populate it - nfdnchar_t* specBuf = NFDi_Malloc(sizeof(nfdnchar_t) * specSize); - - if (!specBuf) { - // automatic freeing of memory via COMDLG_FILTERSPEC_Guard - return NFD_ERROR; - } - - // convert "png,jpg" to "*.png;*.jpg" as required by Windows ... - nfdnchar_t* p_specBuf = specBuf; - *p_specBuf++ = L'*'; - *p_specBuf++ = L'.'; - for (const nfdnchar_t* p_spec = filterList[index].spec; *p_spec; ++p_spec) { - if (*p_spec == L',') { - *p_specBuf++ = L';'; - *p_specBuf++ = L'*'; - *p_specBuf++ = L'.'; - } else { - *p_specBuf++ = *p_spec; - } - } - *p_specBuf++ = L'\0'; - - // assert that we had allocated exactly the correct amount of memory that we used - assert(static_cast(p_specBuf - specBuf) == specSize); - - // save the buffer to the guard object - specList[index].pszSpec = specBuf; - } - } - - /* Add wildcard */ - specList[filterCount].pszName = L"All files"; - specList[filterCount].pszSpec = L"*.*"; - - // add the filter to the dialog - if (!SUCCEEDED(fileOpenDialog->SetFileTypes(filterCount + 1, specList))) { - NFDi_SetError("Failed to set the allowable file types for the drop-down menu."); - return NFD_ERROR; - } - - // automatic freeing of memory via COMDLG_FILTERSPEC_Guard - return NFD_OKAY; -} - -/* call after AddFiltersToDialog */ -nfdresult_t SetDefaultExtension(::IFileDialog* fileOpenDialog, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount) { - // if there are no filters, then don't set default extensions - if (!filterCount) { - return NFD_OKAY; - } - - assert(filterList); - - // set the first item as the default index, and set the default extension - if (!SUCCEEDED(fileOpenDialog->SetFileTypeIndex(1))) { - NFDi_SetError("Failed to set the selected file type index."); - return NFD_ERROR; - } - - // set the first item as the default file extension - const nfdnchar_t* p_spec = filterList[0].spec; - for (; *p_spec; ++p_spec) { - if (*p_spec == ',') { - break; - } - } - if (*p_spec) { - // multiple file extensions for this type (need to allocate memory) - size_t numChars = p_spec - filterList[0].spec; - // allocate one more char space for the '\0' - nfdnchar_t* extnBuf = NFDi_Malloc(sizeof(nfdnchar_t) * (numChars + 1)); - if (!extnBuf) { - return NFD_ERROR; - } - Free_Guard extnBufGuard(extnBuf); - - // copy the extension - for (size_t i = 0; i != numChars; ++i) { - extnBuf[i] = filterList[0].spec[i]; - } - // pad with trailing '\0' - extnBuf[numChars] = L'\0'; - - if (!SUCCEEDED(fileOpenDialog->SetDefaultExtension(extnBuf))) { - NFDi_SetError("Failed to set default extension."); - return NFD_ERROR; - } - } else { - // single file extension for this type (no need to allocate memory) - if (!SUCCEEDED(fileOpenDialog->SetDefaultExtension(filterList[0].spec))) { - NFDi_SetError("Failed to set default extension."); - return NFD_ERROR; - } - } - - return NFD_OKAY; -} - -nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) { - if (!defaultPath || !*defaultPath) return NFD_OKAY; - - IShellItem* folder; - HRESULT result = SHCreateItemFromParsingName(defaultPath, nullptr, IID_PPV_ARGS(&folder)); - - // Valid non results. - if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || - result == HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE)) { - return NFD_OKAY; - } - - if (!SUCCEEDED(result)) { - NFDi_SetError("Failed to create ShellItem for setting the default path."); - return NFD_ERROR; - } - - Release_Guard folderGuard(folder); - -#ifdef NFD_OVERRIDE_RECENT_WITH_DEFAULT - // Use SetFolder() if you always want to use the default folder - if (!SUCCEEDED(dialog->SetFolder(folder))) { - NFDi_SetError("Failed to set default path."); - return NFD_ERROR; - } -#else - // SetDefaultFolder() might use another recently used folder if available, so the user - // doesn't need to keep navigating back to the default folder (recommended by Windows). - if (!SUCCEEDED(dialog->SetDefaultFolder(folder))) { - NFDi_SetError("Failed to set default path."); - return NFD_ERROR; - } -#endif - - return NFD_OKAY; -} - -nfdresult_t SetDefaultName(IFileDialog* dialog, const nfdnchar_t* defaultName) { - if (!defaultName || !*defaultName) return NFD_OKAY; - - if (!SUCCEEDED(dialog->SetFileName(defaultName))) { - NFDi_SetError("Failed to set default file name."); - return NFD_ERROR; - } - - return NFD_OKAY; -} - -nfdresult_t AddOptions(IFileDialog* dialog, FILEOPENDIALOGOPTIONS options) { - FILEOPENDIALOGOPTIONS existingOptions; - if (!SUCCEEDED(dialog->GetOptions(&existingOptions))) { - NFDi_SetError("Failed to get options."); - return NFD_ERROR; - } - if (!SUCCEEDED(dialog->SetOptions(existingOptions | options))) { - NFDi_SetError("Failed to set options."); - return NFD_ERROR; - } - return NFD_OKAY; -} - -HWND GetNativeWindowHandle(const nfdwindowhandle_t& parentWindow) { - if (parentWindow.type != NFD_WINDOW_HANDLE_TYPE_WINDOWS) { - return nullptr; - } - return static_cast(parentWindow.handle); -} -} // namespace - -const char* NFD_GetError(void) { - return g_errorstr; -} - -void NFD_ClearError(void) { - NFDi_SetError(nullptr); -} - -/* public */ - -namespace { -// The user might have initialized with COINIT_MULTITHREADED before, -// in which case we will fail to do CoInitializeEx(), but file dialogs will still work. -// See https://github.com/mlabbe/nativefiledialog/issues/72 for more information. -bool needs_uninitialize; -} // namespace - -nfdresult_t NFD_Init(void) { - // Init COM library. - HRESULT result = - ::CoInitializeEx(nullptr, ::COINIT_APARTMENTTHREADED | ::COINIT_DISABLE_OLE1DDE); - - if (SUCCEEDED(result)) { - needs_uninitialize = true; - return NFD_OKAY; - } else if (result == RPC_E_CHANGED_MODE) { - // If this happens, the user already initialized COM using COINIT_MULTITHREADED, - // so COM will still work, but we shouldn't uninitialize it later. - needs_uninitialize = false; - return NFD_OKAY; - } else { - NFDi_SetError("Failed to initialize COM."); - return NFD_ERROR; - } -} -void NFD_Quit(void) { - if (needs_uninitialize) ::CoUninitialize(); -} - -void NFD_FreePathN(nfdnchar_t* filePath) { - assert(filePath); - ::CoTaskMemFree(filePath); -} - -nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_OpenDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - ::IFileOpenDialog* fileOpenDialog; - - // Create dialog - HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, - nullptr, - CLSCTX_ALL, - ::IID_IFileOpenDialog, - reinterpret_cast(&fileOpenDialog)); - - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not create dialog."); - return NFD_ERROR; - } - - // make sure we remember to free the dialog - Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog); - - // Build the filter list - if (!AddFiltersToDialog(fileOpenDialog, args->filterList, args->filterCount)) { - return NFD_ERROR; - } - - // Set auto-completed default extension - if (!SetDefaultExtension(fileOpenDialog, args->filterList, args->filterCount)) { - return NFD_ERROR; - } - - // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { - return NFD_ERROR; - } - - // Only show file system items - if (!AddOptions(fileOpenDialog, ::FOS_FORCEFILESYSTEM)) { - return NFD_ERROR; - } - - // Show the dialog. - result = fileOpenDialog->Show(GetNativeWindowHandle(args->parentWindow)); - if (SUCCEEDED(result)) { - // Get the file name - ::IShellItem* psiResult; - result = fileOpenDialog->GetResult(&psiResult); - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not get shell item from dialog."); - return NFD_ERROR; - } - Release_Guard<::IShellItem> psiResultGuard(psiResult); - - nfdnchar_t* filePath; - result = psiResult->GetDisplayName(::SIGDN_FILESYSPATH, &filePath); - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not get file path from shell item returned by dialog."); - return NFD_ERROR; - } - - *outPath = filePath; - - return NFD_OKAY; - } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { - return NFD_CANCEL; - } else { - NFDi_SetError("File dialog box show failed."); - return NFD_ERROR; - } -} - -nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath) { - nfdopendialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_OpenDialogMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - ::IFileOpenDialog* fileOpenDialog; - - // Create dialog - HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, - nullptr, - CLSCTX_ALL, - ::IID_IFileOpenDialog, - reinterpret_cast(&fileOpenDialog)); - - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not create dialog."); - return NFD_ERROR; - } - - // make sure we remember to free the dialog - Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog); - - // Build the filter list - if (!AddFiltersToDialog(fileOpenDialog, args->filterList, args->filterCount)) { - return NFD_ERROR; - } - - // Set auto-completed default extension - if (!SetDefaultExtension(fileOpenDialog, args->filterList, args->filterCount)) { - return NFD_ERROR; - } - - // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { - return NFD_ERROR; - } - - // Set a flag for multiple options and file system items only - if (!AddOptions(fileOpenDialog, ::FOS_FORCEFILESYSTEM | ::FOS_ALLOWMULTISELECT)) { - return NFD_ERROR; - } - - // Show the dialog. - result = fileOpenDialog->Show(GetNativeWindowHandle(args->parentWindow)); - if (SUCCEEDED(result)) { - ::IShellItemArray* shellItems; - result = fileOpenDialog->GetResults(&shellItems); - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not get shell items."); - return NFD_ERROR; - } - - // save the path set to the output - *outPaths = static_cast(shellItems); - - return NFD_OKAY; - } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { - return NFD_CANCEL; - } else { - NFDi_SetError("File dialog box show failed."); - return NFD_ERROR; - } -} - -nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, - const nfdnfilteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdnchar_t* defaultPath, - const nfdnchar_t* defaultName) { - nfdsavedialognargs_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - args.defaultName = defaultName; - return NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_SaveDialogN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdsavedialognargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - ::IFileSaveDialog* fileSaveDialog; - - // Create dialog - HRESULT result = ::CoCreateInstance(::CLSID_FileSaveDialog, - nullptr, - CLSCTX_ALL, - ::IID_IFileSaveDialog, - reinterpret_cast(&fileSaveDialog)); - - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not create dialog."); - return NFD_ERROR; - } - - // make sure we remember to free the dialog - Release_Guard<::IFileSaveDialog> fileSaveDialogGuard(fileSaveDialog); - - // Build the filter list - if (!AddFiltersToDialog(fileSaveDialog, args->filterList, args->filterCount)) { - return NFD_ERROR; - } - - // Set default extension - if (!SetDefaultExtension(fileSaveDialog, args->filterList, args->filterCount)) { - return NFD_ERROR; - } - - // Set the default path - if (!SetDefaultPath(fileSaveDialog, args->defaultPath)) { - return NFD_ERROR; - } - - // Set the default name - if (!SetDefaultName(fileSaveDialog, args->defaultName)) { - return NFD_ERROR; - } - - // Only show file system items - if (!AddOptions(fileSaveDialog, ::FOS_FORCEFILESYSTEM)) { - return NFD_ERROR; - } - - // Show the dialog. - result = fileSaveDialog->Show(GetNativeWindowHandle(args->parentWindow)); - if (SUCCEEDED(result)) { - // Get the file name - ::IShellItem* psiResult; - result = fileSaveDialog->GetResult(&psiResult); - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not get shell item from dialog."); - return NFD_ERROR; - } - Release_Guard<::IShellItem> psiResultGuard(psiResult); - - nfdnchar_t* filePath; - result = psiResult->GetDisplayName(::SIGDN_FILESYSPATH, &filePath); - if (!SUCCEEDED(result)) { - NFDi_SetError("Could not get file path from shell item returned by dialog."); - return NFD_ERROR; - } - - *outPath = filePath; - - return NFD_OKAY; - } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { - return NFD_CANCEL; - } else { - NFDi_SetError("File dialog box show failed."); - return NFD_ERROR; - } -} - -nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_PickFolderN_With_Impl(nfdversion_t version, - nfdnchar_t** outPath, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - ::IFileOpenDialog* fileOpenDialog; - - // Create dialog - if (!SUCCEEDED(::CoCreateInstance(::CLSID_FileOpenDialog, - nullptr, - CLSCTX_ALL, - ::IID_IFileOpenDialog, - reinterpret_cast(&fileOpenDialog)))) { - NFDi_SetError("Could not create dialog."); - return NFD_ERROR; - } - - Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog); - - // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { - return NFD_ERROR; - } - - // Only show items that are folders and on the file system - if (!AddOptions(fileOpenDialog, ::FOS_FORCEFILESYSTEM | ::FOS_PICKFOLDERS)) { - return NFD_ERROR; - } - - // Show the dialog to the user - const HRESULT result = fileOpenDialog->Show(GetNativeWindowHandle(args->parentWindow)); - if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { - return NFD_CANCEL; - } else if (!SUCCEEDED(result)) { - NFDi_SetError("File dialog box show failed."); - return NFD_ERROR; - } - - // Get the shell item result - ::IShellItem* psiResult; - if (!SUCCEEDED(fileOpenDialog->GetResult(&psiResult))) { - return NFD_ERROR; - } - - Release_Guard<::IShellItem> psiResultGuard(psiResult); - - // Finally get the path - nfdnchar_t* filePath; - // Why are we not using SIGDN_FILESYSPATH? - if (!SUCCEEDED(psiResult->GetDisplayName(::SIGDN_DESKTOPABSOLUTEPARSING, &filePath))) { - NFDi_SetError("Could not get file path from shell item returned by dialog."); - return NFD_ERROR; - } - - *outPath = filePath; - - return NFD_OKAY; -} - -nfdresult_t NFD_PickFolderMultipleN(const nfdpathset_t** outPaths, const nfdnchar_t* defaultPath) { - nfdpickfoldernargs_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_PickFolderMultipleN_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfoldernargs_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - ::IFileOpenDialog* fileOpenDialog; - - // Create dialog - if (!SUCCEEDED(::CoCreateInstance(::CLSID_FileOpenDialog, - nullptr, - CLSCTX_ALL, - ::IID_IFileOpenDialog, - reinterpret_cast(&fileOpenDialog)))) { - NFDi_SetError("Could not create dialog."); - return NFD_ERROR; - } - - Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog); - - // Set the default path - if (!SetDefaultPath(fileOpenDialog, args->defaultPath)) { - return NFD_ERROR; - } - - // Allow multiple selection; only show items that are folders and on the file system - if (!AddOptions(fileOpenDialog, - ::FOS_FORCEFILESYSTEM | ::FOS_PICKFOLDERS | ::FOS_ALLOWMULTISELECT)) { - return NFD_ERROR; - } - - // Show the dialog. - const HRESULT result = fileOpenDialog->Show(GetNativeWindowHandle(args->parentWindow)); - if (SUCCEEDED(result)) { - ::IShellItemArray* shellItems; - if (!SUCCEEDED(fileOpenDialog->GetResults(&shellItems))) { - NFDi_SetError("Could not get shell items."); - return NFD_ERROR; - } - - // save the path set to the output - *outPaths = static_cast(shellItems); - - return NFD_OKAY; - } else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { - return NFD_CANCEL; - } else { - NFDi_SetError("File dialog box show failed."); - return NFD_ERROR; - } -} - -nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, nfdpathsetsize_t* count) { - assert(pathSet); - // const_cast because methods on IShellItemArray aren't const, but it should act like const to - // the caller - ::IShellItemArray* psiaPathSet = - const_cast<::IShellItemArray*>(static_cast(pathSet)); - - DWORD numPaths; - if (!SUCCEEDED(psiaPathSet->GetCount(&numPaths))) { - NFDi_SetError("Could not get path count."); - return NFD_ERROR; - } - *count = numPaths; - return NFD_OKAY; -} - -nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdnchar_t** outPath) { - assert(pathSet); - // const_cast because methods on IShellItemArray aren't const, but it should act like const to - // the caller - ::IShellItemArray* psiaPathSet = - const_cast<::IShellItemArray*>(static_cast(pathSet)); - - ::IShellItem* psiPath; - if (!SUCCEEDED(psiaPathSet->GetItemAt(index, &psiPath))) { - NFDi_SetError("Could not get shell item."); - return NFD_ERROR; - } - - Release_Guard<::IShellItem> psiPathGuard(psiPath); - - nfdnchar_t* name; - if (!SUCCEEDED(psiPath->GetDisplayName(::SIGDN_FILESYSPATH, &name))) { - NFDi_SetError("Could not get file path from shell item."); - return NFD_ERROR; - } - - *outPath = name; - return NFD_OKAY; -} - -void NFD_PathSet_FreePathN(const nfdnchar_t* filePath) { - NFD_FreePathN(const_cast(filePath)); -} - -nfdresult_t NFD_PathSet_GetEnum(const nfdpathset_t* pathSet, nfdpathsetenum_t* outEnumerator) { - assert(pathSet); - // const_cast because methods on IShellItemArray aren't const, but it should act like const to - // the caller - ::IShellItemArray* psiaPathSet = - const_cast<::IShellItemArray*>(static_cast(pathSet)); - - ::IEnumShellItems* pesiPaths; - if (!SUCCEEDED(psiaPathSet->EnumItems(&pesiPaths))) { - NFDi_SetError("Could not get enumerator."); - return NFD_ERROR; - } - - outEnumerator->ptr = static_cast(pesiPaths); - return NFD_OKAY; -} - -void NFD_PathSet_FreeEnum(nfdpathsetenum_t* enumerator) { - assert(enumerator->ptr); - - ::IEnumShellItems* pesiPaths = static_cast<::IEnumShellItems*>(enumerator->ptr); - - // free the enumerator memory - pesiPaths->Release(); -} - -nfdresult_t NFD_PathSet_EnumNextN(nfdpathsetenum_t* enumerator, nfdnchar_t** outPath) { - assert(enumerator->ptr); - - ::IEnumShellItems* pesiPaths = static_cast<::IEnumShellItems*>(enumerator->ptr); - - ::IShellItem* psiPath; - HRESULT res = pesiPaths->Next(1, &psiPath, NULL); - if (!SUCCEEDED(res)) { - NFDi_SetError("Could not get next item of enumerator."); - return NFD_ERROR; - } - if (res != S_OK) { - *outPath = nullptr; - return NFD_OKAY; - } - - Release_Guard<::IShellItem> psiPathGuard(psiPath); - - nfdnchar_t* name; - if (!SUCCEEDED(psiPath->GetDisplayName(::SIGDN_FILESYSPATH, &name))) { - NFDi_SetError("Could not get file path from shell item."); - return NFD_ERROR; - } - - *outPath = name; - return NFD_OKAY; -} - -void NFD_PathSet_Free(const nfdpathset_t* pathSet) { - assert(pathSet); - // const_cast because methods on IShellItemArray aren't const, but it should act like const to - // the caller - ::IShellItemArray* psiaPathSet = - const_cast<::IShellItemArray*>(static_cast(pathSet)); - - // free the path set memory - psiaPathSet->Release(); -} - -namespace { -// allocs the space in outStr -- call NFDi_Free() -nfdresult_t CopyCharToWChar(const nfdu8char_t* inStr, nfdnchar_t*& outStr) { - int charsNeeded = MultiByteToWideChar(CP_UTF8, 0, inStr, -1, nullptr, 0); - assert(charsNeeded); - - nfdnchar_t* tmp_outStr = NFDi_Malloc(sizeof(nfdnchar_t) * charsNeeded); - if (!tmp_outStr) { - return NFD_ERROR; - } - - int ret = MultiByteToWideChar(CP_UTF8, 0, inStr, -1, tmp_outStr, charsNeeded); - assert(ret && ret == charsNeeded); - (void)ret; // prevent warning in release build - outStr = tmp_outStr; - return NFD_OKAY; -} - -// allocs the space in outPath -- call NFDi_Free() -nfdresult_t CopyWCharToNFDChar(const nfdnchar_t* inStr, nfdu8char_t*& outStr) { - int bytesNeeded = WideCharToMultiByte(CP_UTF8, 0, inStr, -1, nullptr, 0, nullptr, nullptr); - assert(bytesNeeded); - - nfdu8char_t* tmp_outStr = NFDi_Malloc(sizeof(nfdu8char_t) * bytesNeeded); - if (!tmp_outStr) { - return NFD_ERROR; - } - - int ret = WideCharToMultiByte(CP_UTF8, 0, inStr, -1, tmp_outStr, bytesNeeded, nullptr, nullptr); - assert(ret && ret == bytesNeeded); - (void)ret; // prevent warning in release build - outStr = tmp_outStr; - return NFD_OKAY; -} - -struct FilterItem_Guard { - nfdnfilteritem_t* data; - nfdfiltersize_t index; - FilterItem_Guard() noexcept : data(nullptr), index(0) {} - ~FilterItem_Guard() { - assert(data || index == 0); - for (--index; index != static_cast(-1); --index) { - NFDi_Free(const_cast(data[index].spec)); - NFDi_Free(const_cast(data[index].name)); - } - if (data) NFDi_Free(data); - } -}; - -nfdresult_t CopyFilterItem(const nfdu8filteritem_t* filterList, - nfdfiltersize_t count, - FilterItem_Guard& filterItemsNGuard) { - if (count) { - nfdnfilteritem_t*& filterItemsN = filterItemsNGuard.data; - filterItemsN = NFDi_Malloc(sizeof(nfdnfilteritem_t) * count); - if (!filterItemsN) { - return NFD_ERROR; - } - - nfdfiltersize_t& index = filterItemsNGuard.index; - for (; index != count; ++index) { - nfdresult_t res = CopyCharToWChar(filterList[index].name, - const_cast(filterItemsN[index].name)); - if (!res) { - return NFD_ERROR; - } - res = CopyCharToWChar(filterList[index].spec, - const_cast(filterItemsN[index].spec)); - if (!res) { - // remember to free the name, because we also created it (and it won't be protected - // by the guard, because we have not incremented the index) - NFDi_Free(const_cast(filterItemsN[index].name)); - return NFD_ERROR; - } - } - } - return NFD_OKAY; -} -nfdresult_t ConvertU8ToNative(const nfdu8char_t* u8Text, FreeCheck_Guard& nativeText) { - if (u8Text) { - nfdresult_t res = CopyCharToWChar(u8Text, nativeText.data); - if (!res) { - return NFD_ERROR; - } - } - return NFD_OKAY; -} -void NormalizePathSeparator(nfdnchar_t* path) { - if (path) { - for (; *path; ++path) { - if (*path == L'/') *path = L'\\'; - } - } -} -} // namespace - -void NFD_FreePathU8(nfdu8char_t* outPath) { - NFDi_Free(outPath); -} - -nfdresult_t NFD_OpenDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { - nfdopendialogu8args_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogU8_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_OpenDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdopendialogu8args_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - // populate the real nfdnfilteritem_t - FilterItem_Guard filterItemsNGuard; - if (!CopyFilterItem(args->filterList, args->filterCount, filterItemsNGuard)) { - return NFD_ERROR; - } - - // convert and normalize the default path, but only if it is not nullptr - FreeCheck_Guard defaultPathNGuard; - ConvertU8ToNative(args->defaultPath, defaultPathNGuard); - NormalizePathSeparator(defaultPathNGuard.data); - - // call the native function - nfdnchar_t* outPathN; - const nfdopendialognargs_t argsN{ - filterItemsNGuard.data, args->filterCount, defaultPathNGuard.data, args->parentWindow}; - nfdresult_t res = NFD_OpenDialogN_With_Impl(NFD_INTERFACE_VERSION, &outPathN, &argsN); - - if (res != NFD_OKAY) { - return res; - } - - // convert the outPath to UTF-8 - res = CopyWCharToNFDChar(outPathN, *outPath); - - // free the native out path, and return the result - NFD_FreePathN(outPathN); - return res; -} - -/* multiple file open dialog */ -/* It is the caller's responsibility to free `outPaths` via NFD_PathSet_Free() if this function - * returns NFD_OKAY */ -nfdresult_t NFD_OpenDialogMultipleU8(const nfdpathset_t** outPaths, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath) { - nfdopendialogu8args_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - return NFD_OpenDialogMultipleU8_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_OpenDialogMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdopendialogu8args_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - // populate the real nfdnfilteritem_t - FilterItem_Guard filterItemsNGuard; - if (!CopyFilterItem(args->filterList, args->filterCount, filterItemsNGuard)) { - return NFD_ERROR; - } - - // convert and normalize the default path, but only if it is not nullptr - FreeCheck_Guard defaultPathNGuard; - ConvertU8ToNative(args->defaultPath, defaultPathNGuard); - NormalizePathSeparator(defaultPathNGuard.data); - - // call the native function - const nfdopendialognargs_t argsN{ - filterItemsNGuard.data, args->filterCount, defaultPathNGuard.data, args->parentWindow}; - return NFD_OpenDialogMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &argsN); -} - -/* save dialog */ -/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns - * NFD_OKAY */ -nfdresult_t NFD_SaveDialogU8(nfdu8char_t** outPath, - const nfdu8filteritem_t* filterList, - nfdfiltersize_t filterCount, - const nfdu8char_t* defaultPath, - const nfdu8char_t* defaultName) { - nfdsavedialogu8args_t args{}; - args.filterList = filterList; - args.filterCount = filterCount; - args.defaultPath = defaultPath; - args.defaultName = defaultName; - return NFD_SaveDialogU8_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_SaveDialogU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdsavedialogu8args_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - // populate the real nfdnfilteritem_t - FilterItem_Guard filterItemsNGuard; - if (!CopyFilterItem(args->filterList, args->filterCount, filterItemsNGuard)) { - return NFD_ERROR; - } - - // convert and normalize the default path, but only if it is not nullptr - FreeCheck_Guard defaultPathNGuard; - ConvertU8ToNative(args->defaultPath, defaultPathNGuard); - NormalizePathSeparator(defaultPathNGuard.data); - - // convert the default name, but only if it is not nullptr - FreeCheck_Guard defaultNameNGuard; - ConvertU8ToNative(args->defaultName, defaultNameNGuard); - - // call the native function - nfdnchar_t* outPathN; - const nfdsavedialognargs_t argsN{filterItemsNGuard.data, - args->filterCount, - defaultPathNGuard.data, - defaultNameNGuard.data, - args->parentWindow}; - nfdresult_t res = NFD_SaveDialogN_With_Impl(NFD_INTERFACE_VERSION, &outPathN, &argsN); - - if (res != NFD_OKAY) { - return res; - } - - // convert the outPath to UTF-8 - res = CopyWCharToNFDChar(outPathN, *outPath); - - // free the native out path, and return the result - NFD_FreePathN(outPathN); - return res; -} - -/* select folder dialog */ -/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns - * NFD_OKAY */ -nfdresult_t NFD_PickFolderU8(nfdu8char_t** outPath, const nfdu8char_t* defaultPath) { - nfdpickfolderu8args_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderU8_With_Impl(NFD_INTERFACE_VERSION, outPath, &args); -} - -nfdresult_t NFD_PickFolderU8_With_Impl(nfdversion_t version, - nfdu8char_t** outPath, - const nfdpickfolderu8args_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - // convert and normalize the default path, but only if it is not nullptr - FreeCheck_Guard defaultPathNGuard; - ConvertU8ToNative(args->defaultPath, defaultPathNGuard); - NormalizePathSeparator(defaultPathNGuard.data); - - // call the native function - nfdnchar_t* outPathN; - const nfdpickfoldernargs_t argsN{defaultPathNGuard.data, args->parentWindow}; - nfdresult_t res = NFD_PickFolderN_With_Impl(NFD_INTERFACE_VERSION, &outPathN, &argsN); - - if (res != NFD_OKAY) { - return res; - } - - // convert the outPath to UTF-8 - res = CopyWCharToNFDChar(outPathN, *outPath); - - // free the native out path, and return the result - NFD_FreePathN(outPathN); - return res; -} - -/* select multiple folders dialog */ -/* It is the caller's responsibility to free `outPaths` via NFD_PathSet_FreeU8() if this function - * returns NFD_OKAY. */ -nfdresult_t NFD_PickFolderMultipleU8(const nfdpathset_t** outPaths, - const nfdu8char_t* defaultPath) { - nfdpickfolderu8args_t args{}; - args.defaultPath = defaultPath; - return NFD_PickFolderMultipleU8_With_Impl(NFD_INTERFACE_VERSION, outPaths, &args); -} - -nfdresult_t NFD_PickFolderMultipleU8_With_Impl(nfdversion_t version, - const nfdpathset_t** outPaths, - const nfdpickfolderu8args_t* args) { - // We haven't needed to bump the interface version yet. - (void)version; - - // convert and normalize the default path, but only if it is not nullptr - FreeCheck_Guard defaultPathNGuard; - ConvertU8ToNative(args->defaultPath, defaultPathNGuard); - NormalizePathSeparator(defaultPathNGuard.data); - - // call the native function - const nfdpickfoldernargs_t argsN{defaultPathNGuard.data, args->parentWindow}; - return NFD_PickFolderMultipleN_With_Impl(NFD_INTERFACE_VERSION, outPaths, &argsN); -} - -/* Get the UTF-8 path at offset index */ -/* It is the caller's responsibility to free `outPath` via NFD_FreePathU8() if this function returns - * NFD_OKAY */ -nfdresult_t NFD_PathSet_GetPathU8(const nfdpathset_t* pathSet, - nfdpathsetsize_t index, - nfdu8char_t** outPath) { - // call the native function - nfdnchar_t* outPathN; - nfdresult_t res = NFD_PathSet_GetPathN(pathSet, index, &outPathN); - - if (res != NFD_OKAY) { - return res; - } - - // convert the outPath to UTF-8 - res = CopyWCharToNFDChar(outPathN, *outPath); - - // free the native out path, and return the result - NFD_FreePathN(outPathN); - return res; -} - -void NFD_PathSet_FreePathU8(const nfdu8char_t* filePath) { - NFD_FreePathU8(const_cast(filePath)); -} - -nfdresult_t NFD_PathSet_EnumNextU8(nfdpathsetenum_t* enumerator, nfdu8char_t** outPath) { - // call the native function - nfdnchar_t* outPathN; - nfdresult_t res = NFD_PathSet_EnumNextN(enumerator, &outPathN); - - if (res != NFD_OKAY) { - return res; - } - - if (outPathN) { - // convert the outPath to UTF-8 - res = CopyWCharToNFDChar(outPathN, *outPath); - - // free the native out path, and return the result - NFD_FreePathN(outPathN); - } else { - *outPath = nullptr; - res = NFD_OKAY; - } - - return res; -} diff --git a/externals/shared/lib/znfde/src/c.zig b/externals/shared/lib/znfde/src/c.zig deleted file mode 100644 index d240d23f8..000000000 --- a/externals/shared/lib/znfde/src/c.zig +++ /dev/null @@ -1,3 +0,0 @@ -pub usingnamespace @cImport({ - @cInclude("nfd.h"); -}); diff --git a/externals/shared/lib/znfde/src/znfde.zig b/externals/shared/lib/znfde/src/znfde.zig deleted file mode 100644 index 1ac86683e..000000000 --- a/externals/shared/lib/znfde/src/znfde.zig +++ /dev/null @@ -1,103 +0,0 @@ -const std = @import("std"); -const c = @import("c.zig"); -const log = std.log.scoped(.znfde); - -pub const Error = error{ - ZnfdeError, -}; - -pub fn makeError() Error { - if (c.NFD_GetError()) |ptr| { - log.err("{s}\n", .{ - std.mem.sliceTo(ptr, 0), - }); - } - return error.ZnfdeError; -} - -const FilterItem = extern struct { - name: [*:0]const u8, - spec: [*:0]const u8, -}; - -/// Open single file dialog -pub fn openFileDialog(allocator: std.mem.Allocator, filter: ?[]const FilterItem, default_path: ?[:0]const u8) !?[:0]const u8 { - var out_path: [*c]u8 = null; - - const result = c.NFD_OpenDialog( - &out_path, - if (filter) |f| @ptrCast(f.ptr) else null, - if (filter) |f| @intCast(f.len) else 0, - if (default_path != null) default_path.? else null, - ); - - return switch (result) { - c.NFD_OKAY => { - if (out_path == null) { - return null; - } - - defer std.c.free(out_path); - return try allocator.dupeZ(u8, std.mem.sliceTo(out_path, 0)); - }, - c.NFD_ERROR => makeError(), - else => null, - }; -} - -/// Open save dialog -pub fn saveFileDialog(allocator: std.mem.Allocator, filter: ?[]const FilterItem, default_path: ?[:0]const u8, default_name: ?[:0]const u8) !?[:0]const u8 { - var out_path: [*c]u8 = null; - - const result = c.NFD_SaveDialog( - &out_path, - if (filter) |f| @ptrCast(f.ptr) else null, - if (filter) |f| @intCast(f.len) else 0, - if (default_path != null) default_path.? else null, - if (default_name != null) default_name.? else null, - ); - - return switch (result) { - c.NFD_OKAY => { - if (out_path == null) { - return null; - } - - defer std.c.free(out_path); - return try allocator.dupeZ(u8, std.mem.sliceTo(out_path, 0)); - }, - c.NFD_ERROR => makeError(), - else => null, - }; -} - -/// Open folder dialog -pub fn openFolderDialog(allocator: std.mem.Allocator, default_path: ?[:0]const u8) !?[:0]const u8 { - var out_path: [*c]u8 = null; - - const result = c.NFD_PickFolder(&out_path, if (default_path != null) default_path.?.ptr else null); - - return switch (result) { - c.NFD_OKAY => { - if (out_path == null) { - return null; - } - defer std.c.free(out_path); - return try allocator.dupeZ(u8, std.mem.sliceTo(out_path, 0)); - }, - c.NFD_ERROR => makeError(), - else => null, - }; -} - -pub fn init() !void { - const result = c.NFD_Init(); - return switch (result) { - c.NFD_ERROR => makeError(), - else => {}, - }; -} - -pub fn deinit() void { - c.NFD_Quit(); -} diff --git a/externals/shared/tools/zls b/externals/shared/tools/zls deleted file mode 160000 index ea2c303b0..000000000 --- a/externals/shared/tools/zls +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ea2c303b0ddb08a0d364b8eb7959d685fe9e65c6 diff --git a/public/build.zig.zon b/public/build.zig.zon index 442ee6240..cade7956e 100644 --- a/public/build.zig.zon +++ b/public/build.zig.zon @@ -12,7 +12,7 @@ }, .dependencies = .{ - .zmath = .{ .path = "../externals/shared/lib/zig-gamedev/libs/zmath" }, + .zmath = .{ .path = "../externals/shared/lib/zmath" }, .ziglangSet = .{ .path = "../externals/shared/lib/ziglang-set" }, }, } diff --git a/tools/generate_vscode.zig b/tools/generate_vscode.zig index d40fce1de..0b9a55ff1 100644 --- a/tools/generate_vscode.zig +++ b/tools/generate_vscode.zig @@ -184,7 +184,7 @@ fn createOrUpdateSettingsJson(allocator: std.mem.Allocator, vscode_dir: std.fs.D defer allocator.free(base_path); // Zig - const zig_path = try std.fs.path.join(allocator, &.{ base_path, "zig", "bin", osBasedZigDir(), osBasedProgram("zig") }); + const zig_path = try std.fs.path.join(allocator, &.{ base_path, "externals", "shared", "zig", "bin", osBasedZigDir(), osBasedProgram("zig") }); defer allocator.free(zig_path); try parsed.value.object.put("zig.path", .{ .string = zig_path }); diff --git a/zig b/zig deleted file mode 160000 index cfa9968f4..000000000 --- a/zig +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cfa9968f4520ba6988c5267db66df241560e6003 diff --git a/zig b/zig new file mode 120000 index 000000000..7ce699b45 --- /dev/null +++ b/zig @@ -0,0 +1 @@ +externals/shared/zig \ No newline at end of file