From fdf1df1a3082de784ed9d2e0c042ab089a8b81ea Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Wed, 26 Mar 2025 20:39:25 -0400 Subject: [PATCH] refactor: use QtXml in place of pugixml --- .../actions/install-dependencies/action.yml | 8 +-- cmake/Libraries.cmake | 5 +- deploy/linux/arch/PKGBUILD.in | 1 - .../linux/flatpak/org.deskflow.deskflow.yml | 7 --- src/lib/deskflow/CMakeLists.txt | 2 +- src/lib/deskflow/unix/X11LayoutsParser.cpp | 61 ++++++++++--------- src/lib/deskflow/unix/X11LayoutsParser.h | 6 +- 7 files changed, 40 insertions(+), 50 deletions(-) diff --git a/.github/actions/install-dependencies/action.yml b/.github/actions/install-dependencies/action.yml index 44964cb97..486351c33 100644 --- a/.github/actions/install-dependencies/action.yml +++ b/.github/actions/install-dependencies/action.yml @@ -39,14 +39,14 @@ runs: xorg-dev libx11-dev libxtst-dev libssl-dev \ libglib2.0-dev libnotify-dev \ libxkbfile-dev qt6-base-dev qt6-tools-dev \ - libgtk-3-dev libgtest-dev libgmock-dev libpugixml-dev \ + libgtk-3-dev libgtest-dev libgmock-dev \ libei-dev libportal-dev libtomlplusplus-dev libcli11-dev -y >/dev/null elif [ ${{inputs.like}} == "fedora" ]; then dnf install -y cmake make ninja-build gcc-c++ \ rpm-build openssl-devel glib2-devel \ libXtst-devel libnotify-devel \ libxkbfile-devel qt6-qtbase-devel qt6-qttools-devel \ - gtk3-devel gtest-devel gmock-devel pugixml-devel \ + gtk3-devel gtest-devel gmock-devel \ libei-devel libportal-devel tomlplusplus-devel \ cli11-devel elif [ ${{inputs.like}} == "suse" ]; then @@ -55,12 +55,12 @@ runs: cmake make ninja gcc-c++ rpm-build libopenssl-devel \ glib2-devel libXtst-devel libnotify-devel \ libxkbfile-devel qt6-base-devel qt6-tools-devel gtk3-devel \ - googletest-devel googlemock-devel pugixml-devel libei-devel \ + googletest-devel googlemock-devel libei-devel \ libportal-devel tomlplusplus-devel cli11-devel elif [ ${{ inputs.like }} == "arch" ]; then pacman -Syu --noconfirm base-devel cmake ninja \ gcc openssl glib2 libxtst libnotify \ - libxkbfile gtest pugixml libei libportal \ + libxkbfile gtest libei libportal \ qt6-base qt6-tools gtk3 tomlplusplus cli11 else echo "Unknown like" diff --git a/cmake/Libraries.cmake b/cmake/Libraries.cmake index ef33538e6..09ed2ee4c 100644 --- a/cmake/Libraries.cmake +++ b/cmake/Libraries.cmake @@ -21,7 +21,7 @@ macro(configure_libs) find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Widgets Network) if(UNIX AND NOT APPLE) - find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS DBus) + find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS DBus Xml) endif() # Define the location of Qt deployment tool @@ -160,9 +160,6 @@ macro(configure_unix_libs) message(WARNING "pkg-config not found, skipping wayland libraries") endif() - - find_package(pugixml REQUIRED) - find_package(PkgConfig) if(PKG_CONFIG_FOUND) pkg_check_modules(lib_glib REQUIRED IMPORTED_TARGET glib-2.0) diff --git a/deploy/linux/arch/PKGBUILD.in b/deploy/linux/arch/PKGBUILD.in index 69c63674e..3a2cc7720 100644 --- a/deploy/linux/arch/PKGBUILD.in +++ b/deploy/linux/arch/PKGBUILD.in @@ -24,7 +24,6 @@ depends=( 'libxkbcommon-x11' 'libnotify' 'hicolor-icon-theme' - 'pugixml' 'qt6-base' 'qt6-tools' 'libei' diff --git a/deploy/linux/flatpak/org.deskflow.deskflow.yml b/deploy/linux/flatpak/org.deskflow.deskflow.yml index ebfaf130a..745d26f96 100644 --- a/deploy/linux/flatpak/org.deskflow.deskflow.yml +++ b/deploy/linux/flatpak/org.deskflow.deskflow.yml @@ -72,13 +72,6 @@ modules: url: https://github.com/flatpak/libportal.git tag: 0.9.1 commit: 8f5dc8d192f6e31dafe69e35219e3b707bde71ce - - name: puixml - buildsystem: cmake-ninja - sources: - - type: git - url: https://github.com/zeux/pugixml - tag: v1.14 - commit: db78afc2b7d8f043b4bc6b185635d949ea2ed2a8 - name: cli11 buildsystem: cmake-ninja config-opts: diff --git a/src/lib/deskflow/CMakeLists.txt b/src/lib/deskflow/CMakeLists.txt index 0f552434f..359095211 100644 --- a/src/lib/deskflow/CMakeLists.txt +++ b/src/lib/deskflow/CMakeLists.txt @@ -177,7 +177,7 @@ if(UNIX) ) if(NOT APPLE) - target_link_libraries(${lib_name} PRIVATE pugixml) + target_link_libraries(${lib_name} PRIVATE Qt6::Xml) find_package(PkgConfig) if(PKG_CONFIG_FOUND) diff --git a/src/lib/deskflow/unix/X11LayoutsParser.cpp b/src/lib/deskflow/unix/X11LayoutsParser.cpp index 05782dfbe..f889fd0c7 100644 --- a/src/lib/deskflow/unix/X11LayoutsParser.cpp +++ b/src/lib/deskflow/unix/X11LayoutsParser.cpp @@ -10,11 +10,13 @@ #include #include +#include +#include + #include "DeskflowXkbKeyboard.h" #include "ISO639Table.h" #include "X11LayoutsParser.h" #include "base/Log.h" -#include "pugixml.hpp" namespace { @@ -30,24 +32,24 @@ void splitLine(std::vector &parts, const std::string &line, char de } // namespace -bool X11LayoutsParser::readXMLConfigItemElem(const pugi::xml_node *root, std::vector &langList) +bool X11LayoutsParser::readXMLConfigItemElem(const QDomNode &node, std::vector &langList) { - auto configItemElem = root->child("configItem"); - if (!configItemElem) { + auto configItemElem = node.firstChildElement("configItem"); + if (configItemElem.isNull()) { LOG((CLOG_WARN "failed to read \"configItem\" in xml file")); return false; } langList.emplace_back(); - auto nameElem = configItemElem.child("name"); - if (nameElem) { - langList.back().name = nameElem.text().as_string(); - } + auto nameElem = configItemElem.firstChildElement("name"); + if (!nameElem.isNull()) + langList.back().name = nameElem.toElement().text().toStdString(); - auto languageListElem = configItemElem.child("languageList"); - if (languageListElem) { - for (pugi::xml_node isoElem : languageListElem.children("iso639Id")) { - langList.back().layoutBaseISO639_2.emplace_back(isoElem.text().as_string()); + auto languageListElem = configItemElem.elementsByTagName("languageList"); + if (!languageListElem.isEmpty()) { + for (int i = 0; i < languageListElem.count(); i++) { + const auto isoElem = languageListElem.at(i).namedItem("iso639Id").toElement(); + langList.back().layoutBaseISO639_2.emplace_back(isoElem.text().toStdString()); } } @@ -57,37 +59,38 @@ bool X11LayoutsParser::readXMLConfigItemElem(const pugi::xml_node *root, std::ve std::vector X11LayoutsParser::getAllLanguageData(const std::string &pathToEvdevFile) { std::vector allCodes; - pugi::xml_document doc; - if (!doc.load_file(pathToEvdevFile.c_str())) { - LOG((CLOG_WARN "failed to open %s", pathToEvdevFile.c_str())); + + QFile inFile(QString::fromStdString(pathToEvdevFile)); + if (!inFile.open(QIODevice::ReadOnly)) { + LOG((CLOG_WARN "unable to open %s", pathToEvdevFile.c_str())); return allCodes; } - auto xkbConfigElem = doc.child("xkbConfigRegistry"); - if (!xkbConfigElem) { + QDomDocument xmlDoc; + xmlDoc.setContent(inFile.readAll()); + + const auto xkbConfigElem = xmlDoc.firstChildElement("xkbConfigRegistry"); + if (xkbConfigElem.isNull()) { LOG((CLOG_WARN "failed to read xkbConfigRegistry in %s", pathToEvdevFile.c_str())); return allCodes; } - auto layoutListElem = xkbConfigElem.child("layoutList"); - if (!layoutListElem) { + auto layoutListElem = xkbConfigElem.firstChildElement("layoutList"); + if (layoutListElem.isNull()) { LOG((CLOG_WARN "failed to read layoutList in %s", pathToEvdevFile.c_str())); return allCodes; } - for (pugi::xml_node layoutElem : layoutListElem.children("layout")) { - if (!readXMLConfigItemElem(&layoutElem, allCodes)) { + const auto layouts = layoutListElem.elementsByTagName("layout"); + for (int i = 0; i < layouts.count(); i++) { + auto item = layouts.at(i); + if (!readXMLConfigItemElem(item, allCodes)) continue; - } - auto variantListElem = layoutElem.child("variantList"); - if (variantListElem) { - for (pugi::xml_node variantElem : variantListElem.children("variant")) { - readXMLConfigItemElem(&variantElem, allCodes.back().variants); - } - } + auto variantListElem = item.namedItem("variantList").childNodes(); + for (int i = 0; i < variantListElem.count(); i++) + readXMLConfigItemElem(variantListElem.at(i), allCodes.back().variants); } - return allCodes; } diff --git a/src/lib/deskflow/unix/X11LayoutsParser.h b/src/lib/deskflow/unix/X11LayoutsParser.h index aa7be66be..ab43e6b39 100644 --- a/src/lib/deskflow/unix/X11LayoutsParser.h +++ b/src/lib/deskflow/unix/X11LayoutsParser.h @@ -11,9 +11,7 @@ #include #include -namespace pugi { -class xml_node; -} +class QDomNode; class X11LayoutsParser { @@ -31,7 +29,7 @@ private: std::vector variants; }; - static bool readXMLConfigItemElem(const pugi::xml_node *root, std::vector &langList); + static bool readXMLConfigItemElem(const QDomNode &node, std::vector &langList); static std::vector getAllLanguageData(const std::string &pathToEvdevFile);