refactor: use QtXml in place of pugixml
This commit is contained in:
@ -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"
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -24,7 +24,6 @@ depends=(
|
||||
'libxkbcommon-x11'
|
||||
'libnotify'
|
||||
'hicolor-icon-theme'
|
||||
'pugixml'
|
||||
'qt6-base'
|
||||
'qt6-tools'
|
||||
'libei'
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -10,11 +10,13 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QFile>
|
||||
|
||||
#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<std::string> &parts, const std::string &line, char de
|
||||
|
||||
} // namespace
|
||||
|
||||
bool X11LayoutsParser::readXMLConfigItemElem(const pugi::xml_node *root, std::vector<Lang> &langList)
|
||||
bool X11LayoutsParser::readXMLConfigItemElem(const QDomNode &node, std::vector<Lang> &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::Lang> X11LayoutsParser::getAllLanguageData(const std::string &pathToEvdevFile)
|
||||
{
|
||||
std::vector<Lang> 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;
|
||||
}
|
||||
|
||||
|
||||
@ -11,9 +11,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace pugi {
|
||||
class xml_node;
|
||||
}
|
||||
class QDomNode;
|
||||
|
||||
class X11LayoutsParser
|
||||
{
|
||||
@ -31,7 +29,7 @@ private:
|
||||
std::vector<Lang> variants;
|
||||
};
|
||||
|
||||
static bool readXMLConfigItemElem(const pugi::xml_node *root, std::vector<Lang> &langList);
|
||||
static bool readXMLConfigItemElem(const QDomNode &node, std::vector<Lang> &langList);
|
||||
|
||||
static std::vector<Lang> getAllLanguageData(const std::string &pathToEvdevFile);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user