From 9b2b861a2af451eb160c3771db6453deb90cf792 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 11 Jul 2021 21:30:20 -0400 Subject: [PATCH] Removed / Consolidated unnecessary header files --- src/CMakeLists.txt | 1 - src/browser/BrowserEntryConfig.cpp | 4 +-- src/browser/CMakeLists.txt | 2 +- src/browser/Variant.cpp | 38 -------------------------- src/browser/Variant.h | 26 ------------------ src/core/Compare.cpp | 16 ----------- src/core/Tools.cpp | 20 ++++++++++++++ src/core/Tools.h | 2 ++ tests/TestGlobal.h | 43 ------------------------------ 9 files changed, 25 insertions(+), 127 deletions(-) delete mode 100644 src/browser/Variant.cpp delete mode 100644 src/browser/Variant.h delete mode 100644 src/core/Compare.cpp delete mode 100644 tests/TestGlobal.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ec868cbd..0cfe26e6a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,7 +36,6 @@ set(keepassx_SOURCES core/Base32.cpp core/Bootstrap.cpp core/Clock.cpp - core/Compare.cpp core/Config.cpp core/CsvParser.cpp core/CustomData.cpp diff --git a/src/browser/BrowserEntryConfig.cpp b/src/browser/BrowserEntryConfig.cpp index 80710e2c1..a5bd3263f 100644 --- a/src/browser/BrowserEntryConfig.cpp +++ b/src/browser/BrowserEntryConfig.cpp @@ -18,8 +18,8 @@ #include "BrowserEntryConfig.h" -#include "browser/Variant.h" #include "core/Entry.h" +#include "core/Tools.h" #include #include @@ -105,7 +105,7 @@ bool BrowserEntryConfig::load(const Entry* entry) void BrowserEntryConfig::save(Entry* entry) { - QVariantMap v = qo2qv(this); + QVariantMap v = Tools::qo2qvm(this); QJsonObject o = QJsonObject::fromVariantMap(v); QByteArray json = QJsonDocument(o).toJson(QJsonDocument::Compact); entry->customData()->set(KEEPASSXCBROWSER_NAME, json); diff --git a/src/browser/CMakeLists.txt b/src/browser/CMakeLists.txt index d5833cfc4..e2fa9d831 100755 --- a/src/browser/CMakeLists.txt +++ b/src/browser/CMakeLists.txt @@ -29,7 +29,7 @@ if(WITH_XC_BROWSER) BrowserSettings.cpp BrowserShared.cpp NativeMessageInstaller.cpp - Variant.cpp) + ) add_library(keepassxcbrowser STATIC ${keepassxcbrowser_SOURCES}) target_link_libraries(keepassxcbrowser Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network ${BOTAN2_LIBRARIES}) diff --git a/src/browser/Variant.cpp b/src/browser/Variant.cpp deleted file mode 100644 index 0db5899fd..000000000 --- a/src/browser/Variant.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2017 KeePassXC Team - * - * 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 3 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, see . - */ - -#include -#include - -QVariantMap qo2qv(const QObject* object, const QStringList& ignoredProperties) -{ - QVariantMap result; - const QMetaObject* metaobject = object->metaObject(); - int count = metaobject->propertyCount(); - for (int i = 0; i < count; ++i) { - QMetaProperty metaproperty = metaobject->property(i); - const char* name = metaproperty.name(); - - if (ignoredProperties.contains(QLatin1String(name)) || (!metaproperty.isReadable())) { - continue; - } - - QVariant value = object->property(name); - result[QLatin1String(name)] = value; - } - return result; -} diff --git a/src/browser/Variant.h b/src/browser/Variant.h deleted file mode 100644 index 084dc4a09..000000000 --- a/src/browser/Variant.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2017 KeePassXC Team - * - * 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 3 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, see . - */ - -#ifndef VARIANT_H -#define VARIANT_H - -#include - -QVariantMap qo2qv(const QObject* object, - const QStringList& ignoredProperties = QStringList(QString(QLatin1String("objectName")))); - -#endif // VARIANT_H diff --git a/src/core/Compare.cpp b/src/core/Compare.cpp deleted file mode 100644 index 414f97e0a..000000000 --- a/src/core/Compare.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2018 KeePassXC Team - * - * 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 or (at your option) - * version 3 of the License. - * - * 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, see . - */ diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index 2011a2d44..50145acd0 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -342,4 +343,23 @@ namespace Tools return subbed; } + + QVariantMap qo2qvm(const QObject* object, const QStringList& ignoredProperties) + { + QVariantMap result; + const QMetaObject* metaobject = object->metaObject(); + int count = metaobject->propertyCount(); + for (int i = 0; i < count; ++i) { + QMetaProperty metaproperty = metaobject->property(i); + const char* name = metaproperty.name(); + + if (ignoredProperties.contains(QLatin1String(name)) || (!metaproperty.isReadable())) { + continue; + } + + QVariant value = object->property(name); + result[QLatin1String(name)] = value; + } + return result; + } } // namespace Tools diff --git a/src/core/Tools.h b/src/core/Tools.h index e60d46633..45bc86669 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -72,6 +72,8 @@ namespace Tools return version; } + + QVariantMap qo2qvm(const QObject* object, const QStringList& ignoredProperties = {"objectName"}); } // namespace Tools #endif // KEEPASSX_TOOLS_H diff --git a/tests/TestGlobal.h b/tests/TestGlobal.h deleted file mode 100644 index 7b7fb816a..000000000 --- a/tests/TestGlobal.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2018 KeePassXC Team - * - * 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 or (at your option) - * version 3 of the License. - * - * 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, see . - */ - -#ifndef KEEPASSXC_TESTGLOBAL_H -#define KEEPASSXC_TESTGLOBAL_H - -#include "core/Group.h" - -namespace QTest -{ - - template <> inline char* toString(const Group::TriState& triState) - { - QString value; - - if (triState == Group::Inherit) { - value = "null"; - } else if (triState == Group::Enable) { - value = "true"; - } else { - value = "false"; - } - - return qstrdup(value.toLocal8Bit().constData()); - } - -} // namespace QTest - -#endif // KEEPASSXC_TESTGLOBAL_H