diff --git a/cmake/rules_PyKF5.py b/cmake/rules_PyKF5.py index 72bee90..3204a5e 100644 --- a/cmake/rules_PyKF5.py +++ b/cmake/rules_PyKF5.py @@ -1,310 +1,304 @@ # # Copyright 2016 by Shaheed Haque (srhaque@theiet.org) # Copyright 2016 Stephen Kelly # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os, sys import rules_engine sys.path.append(os.path.dirname(os.path.dirname(rules_engine.__file__))) import Qt5Ruleset from copy import deepcopy from clang.cindex import AccessSpecifier, CursorKind def set_skeleton_item_base(container, sip, matcher): if not sip["base_specifiers"] or sip["base_specifiers"][-1].endswith(">"): sip["base_specifiers"] = ["KConfigSkeletonItem"] def set_skeleton_item_base_gui(container, sip, matcher): sip["base_specifiers"] = ["KConfigSkeletonItem"] def mark_and_discard_QSharedData(container, sip, matcher): rules_engine.container_mark_abstract(container, sip, matcher) rules_engine.discard_QSharedData_base(container, sip, matcher) def discard_base(container, sip, matcher): sip["base_specifiers"] = [] def local_container_rules(): return [ - [".*", "KConfigBackend", ".*", ".*", ".*", mark_and_discard_QSharedData], [".*", "KConfigBase", ".*", ".*", ".*", rules_engine.container_mark_abstract], [".*KCoreConfigSkeleton.*", ".*ItemString", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemUrl", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemProperty", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemBool", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemInt", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemLongLong", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemUInt", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemULongLong", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemDouble", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemRect", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemPoint", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemSize", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemDateTime", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemStringList", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemUrlList", ".*", ".*", ".*", set_skeleton_item_base], [".*KCoreConfigSkeleton.*", ".*ItemIntList", ".*", ".*", ".*", set_skeleton_item_base], ["KConfigSkeleton", "ItemColor", ".*", ".*", ".*", set_skeleton_item_base_gui], ["KConfigSkeleton", "ItemFont", ".*", ".*", ".*", set_skeleton_item_base_gui], [".*", "KSharedConfig", ".*", ".*", ".*", rules_engine.discard_QSharedData_base], [".*", "KConfigCompilerSignallingItem", ".*", ".*", ".*", rules_engine.container_discard], [".*", "KEntryMap", ".*", ".*", ".*", discard_base], ] def local_function_rules(): return [ ["KConfigBase", "group", ".*", ".*", ".*const char.*", rules_engine.function_discard], ["KConfigBase", "group", ".*", ".*", ".*QByteArray.*", rules_engine.function_discard], ["KConfigBase", "group", ".*", "const KConfigGroup", ".*", rules_engine.function_discard], ["KConfigBase", "groupImpl", ".*", "const KConfigGroup", ".*", rules_engine.function_discard], ["KConfig", "groupImpl", ".*", "const KConfigGroup", ".*", rules_engine.function_discard], ["KSharedConfig", "openConfig", ".*", ".*", ".*", rules_engine.function_discard], ["KConfigGroup", "KConfigGroup", ".*", ".*", ".*KConfigBase.*", rules_engine.function_discard], ["KConfigGroup", "config", ".*", "const KConfig.*", ".*", rules_engine.function_discard], ["KDesktopFile", ".*", ".*", "const KConfigGroup", ".*", rules_engine.function_discard], ["KConfigGroup", ".*", ".*", "KConfigGroup", ".*", rules_engine.function_discard], ["KCoreConfigSkeleton", "config", ".*", "const KConfig.*", ".*", rules_engine.function_discard], ["KCoreConfigSkeleton", "sharedConfig", ".*", ".*", ".*", rules_engine.function_discard], ["KEntryMap", "getEntryOption", ".*", ".*", ".*", rules_engine.function_discard], ["KEntryMap", "setEntryOption", ".*", ".*", ".*", rules_engine.function_discard], ["KEntryMap", "findEntry", ".*", ".*", ".*", rules_engine.function_discard], ["KEntryMap", "findExactEntry", ".*", ".*", ".*", rules_engine.function_discard], - - ["KConfigBackend", "registerMappings", ".*", ".*", ".*", rules_engine.function_discard], - ["KConfigBackend", "parseConfig", ".*", ".*", ".*", rules_engine.function_discard], - ["KConfigBackend", "writeConfig", ".*", ".*", ".*", rules_engine.function_discard], - ] def local_typedef_rules(): return [ ["KConfigSkeletonItem", "DictIterator", rules_engine.typedef_discard], [".*", "KEntryMapIterator", rules_engine.typedef_discard], [".*", "KEntryMapConstIterator", rules_engine.typedef_discard], ] def _kcoreconfigskeleton_item_xxx(function, sip, entry): sip["code"] = """ %MethodCode sipCpp = new sipKCoreConfigSkeleton_Item{} (*a0, *a1, a2, a3); %End """.replace("{}", entry["ctx"]) sip["parameters"][2] = sip["parameters"][2].replace("&", "") def _kcoreconfigskeleton_item_enum(function, sip, entry): sip["code"] = """ %MethodCode sipCpp = new sipKCoreConfigSkeleton_ItemEnum (*a0, *a1, a2, *a3, a4); %End """.replace("{}", entry["ctx"]) sip["parameters"][2] = sip["parameters"][2].replace("&", "") def _kcoreconfigskeleton_add_item_xxx(function, sip, entry): sip["code"] = """ %MethodCode sipRes = new PyItem{} (sipCpp->currentGroup(), a3->isNull() ? *a0 : *a3, a1, a2); sipCpp->addItem(sipRes, *a0); %End """.format(entry["ctx"]) def _kcoreconfigskeleton_item_add_py_subclass(filename, sip, entry): result = """ %ModuleHeaderCode #include """ for ctx in ({"Type": "Bool", "cpptype": "bool", "defaultValue": 1}, {"Type": "Int", "cpptype": "qint32", "defaultValue": 1}, {"Type": "UInt", "cpptype": "quint32", "defaultValue": 1}, {"Type": "LongLong", "cpptype": "qint64", "defaultValue": 1}, {"Type": "ULongLong", "cpptype": "quint64", "defaultValue": 1}, {"Type": "Double", "cpptype": "double", "defaultValue": 1}, ): result += """ class PyItem{Type} : public KCoreConfigSkeleton::Item{Type} {{ public: PyItem{Type} (const QString &group, const QString &key, {cpptype}& val, {cpptype} defaultValue = {defaultValue}) : KCoreConfigSkeleton::Item{Type} (group, key, this->value, defaultValue), value(val) {{ }} private: {cpptype} value; }}; """.format(**ctx) result += """ class PyItemEnum : public KCoreConfigSkeleton::ItemEnum { public: PyItemEnum (const QString& group, const QString& key, int& val, const QList& choices, int defaultValue = 0) : KCoreConfigSkeleton::ItemEnum(group, key, this->value, choices, defaultValue), value(val) { }; private: int value; }; %End\n """ sip["code"] = result class RuleSet(Qt5Ruleset.RuleSet): def __init__(self): Qt5Ruleset.RuleSet.__init__(self) self._fn_db = rules_engine.FunctionRuleDb(lambda: local_function_rules() + Qt5Ruleset.function_rules()) self._container_db = rules_engine.ContainerRuleDb(lambda: local_container_rules() + Qt5Ruleset.container_rules()) self._typedef_db = rules_engine.TypedefRuleDb(lambda: local_typedef_rules() + Qt5Ruleset.typedef_rules()) self._methodcode = rules_engine.MethodCodeDb({ "KCoreConfigSkeleton::ItemBool": { "ItemBool": { "code": _kcoreconfigskeleton_item_xxx, "ctx": "Bool", }, }, "KCoreConfigSkeleton::ItemInt": { "ItemInt": { "code": _kcoreconfigskeleton_item_xxx, "ctx": "Int", }, }, "KCoreConfigSkeleton::ItemLongLong": { "ItemLongLong": { "code": _kcoreconfigskeleton_item_xxx, "ctx": "LongLong", }, }, "KCoreConfigSkeleton::ItemEnum": { "ItemEnum": { "code": _kcoreconfigskeleton_item_enum, "ctx": "Enum", }, }, "KCoreConfigSkeleton::ItemUInt": { "ItemUInt": { "code": _kcoreconfigskeleton_item_xxx, "ctx": "UInt", }, }, "KCoreConfigSkeleton::ItemULongLong": { "ItemULongLong": { "code": _kcoreconfigskeleton_item_xxx, "ctx": "ULongLong", }, }, "KCoreConfigSkeleton::ItemDouble": { "ItemDouble": { "code": _kcoreconfigskeleton_item_xxx, "ctx": "Double", }, }, "KCoreConfigSkeleton": { "addItemBool": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "Bool", }, "addItemInt": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "Int", }, "addItemUInt": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "UInt", }, "addItemLongLong": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "LongLong", }, "addItemInt64": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "LongLong", }, "addItemULongLong": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "ULongLong", }, "addItemUInt64": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "ULongLong", }, "addItemDouble": { "code": _kcoreconfigskeleton_add_item_xxx, "ctx": "Double", }, }, }) self._modulecode = rules_engine.ModuleCodeDb({ "kcoreconfigskeleton.h": { "code": _kcoreconfigskeleton_item_add_py_subclass, }, }) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 72a46b9..ed7edba 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,90 +1,88 @@ find_package(Qt5Core ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE) set(libkconfigcore_SRCS kconfig.cpp kconfigbase.cpp kconfigdata.cpp kconfiggroup.cpp kconfigbackend.cpp kconfigini.cpp kdesktopfile.cpp ksharedconfig.cpp kcoreconfigskeleton.cpp kauthorized.cpp kemailsettings.cpp ) add_library(KF5ConfigCore ${libkconfigcore_SRCS}) generate_export_header(KF5ConfigCore BASE_NAME KConfigCore) add_library(KF5::ConfigCore ALIAS KF5ConfigCore) target_compile_definitions(KF5ConfigCore PRIVATE KCONF_UPDATE_INSTALL_LOCATION="${KDE_INSTALL_FULL_LIBEXECDIR_KF5}/$" ) target_include_directories(KF5ConfigCore INTERFACE "$") target_link_libraries(KF5ConfigCore PUBLIC Qt5::Core) if(WIN32) target_link_libraries(KF5ConfigCore PRIVATE ${KDEWIN_LIBRARIES}) endif() set_target_properties(KF5ConfigCore PROPERTIES VERSION ${KCONFIG_VERSION_STRING} SOVERSION ${KCONFIG_SOVERSION} EXPORT_NAME ConfigCore ) ecm_generate_headers(KConfigCore_HEADERS HEADER_NAMES KAuthorized KConfig - KConfigBackend KConfigBase KConfigGroup KDesktopFile KSharedConfig KCoreConfigSkeleton KEMailSettings ConversionCheck REQUIRED_HEADERS KConfigCore_HEADERS ) find_package(PythonModuleGeneration) if (PythonModuleGeneration_FOUND) ecm_generate_python_binding( TARGET KF5::ConfigCore PYTHONNAMESPACE PyKF5 MODULENAME KConfigCore RULES_FILE "${CMAKE_SOURCE_DIR}/cmake/rules_PyKF5.py" INSTALL_DIR_SUFFIX ${KDE_INSTALL_PYTHONBINDINGSDIR} SIP_DEPENDS QtCore/QtCoremod.sip HEADERS kauthorized.h kconfig.h - kconfigbackend.h kconfigbase.h kconfiggroup.h kdesktopfile.h ksharedconfig.h kcoreconfigskeleton.h kemailsettings.h conversioncheck.h ) endif() install(TARGETS KF5ConfigCore EXPORT KF5ConfigTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kconfigcore_export.h ${KConfigCore_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigCore COMPONENT Devel ) include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KConfigCore LIB_NAME KF5ConfigCore DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigCore) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/core/kconfigbackend.h b/src/core/kconfigbackend.h index 7dec4b8..332a0b4 100644 --- a/src/core/kconfigbackend.h +++ b/src/core/kconfigbackend.h @@ -1,210 +1,214 @@ /* This file is part of the KDE libraries Copyright (c) 2006, 2007 Thomas Braxton Copyright (c) 1999 Preston Brown Portions copyright (c) 1997 Matthias Kalle Dalheimer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KCONFIGBACKEND_H #define KCONFIGBACKEND_H #include #include #include #include #include class KConfigBackendPrivate; class KEntryMap; class QFile; class QByteArray; class QDateTime; /** * \class KConfigBackend kconfigbackend.h * * Provides the implementation for accessing configuration sources. * - * KDELibs only provides an INI backend, but this class can be used + * KConfig only provides an INI backend, but this class can be used * to create plugins that allow access to other file formats and * configuration systems. + * + * \internal */ -class KCONFIGCORE_EXPORT KConfigBackend : public QObject, public QSharedData +class KConfigBackend : public QObject, public QSharedData { Q_OBJECT public: /** * Creates a new KConfig backend. * * If no @p system is given, or the given @p system is unknown, this method tries * to determine the correct backend to use. * * @param fileName the absolute file name of the configuration file * @param system the configuration system to use * @return a KConfigBackend object to be used with KConfig */ static QExplicitlySharedDataPointer create(const QString &fileName = QString(), const QString &system = QString()); /** * Registers mappings from directories/files to configuration systems * * Allows you to tell KConfigBackend that create() should use a particular * backend for a particular file or directory. * * @warning currently does nothing * * @param entryMap the KEntryMap to build the mappings from */ static void registerMappings(const KEntryMap &entryMap); /** Destroys the backend */ virtual ~KConfigBackend(); /** Allows the behaviour of parseConfig() to be tuned */ enum ParseOption { ParseGlobal = 1, /// entries should be marked as @em global ParseDefaults = 2, /// entries should be marked as @em default ParseExpansions = 4 /// entries are allowed to be marked as @em expandable }; Q_FLAG(ParseOption) /// @typedef typedef QFlags ParseOptions Q_DECLARE_FLAGS(ParseOptions, ParseOption) /** Allows the behaviour of writeConfig() to be tuned */ enum WriteOption { WriteGlobal = 1 /// only write entries marked as "global" }; Q_FLAG(WriteOption) /// @typedef typedef QFlags WriteOptions Q_DECLARE_FLAGS(WriteOptions, WriteOption) /** Return value from parseConfig() */ enum ParseInfo { ParseOk, /// the configuration was opened read/write ParseImmutable, /// the configuration is @em immutable ParseOpenError /// the configuration could not be opened }; /** * Read persistent storage * * @param locale the locale to read entries for (if the backend supports localized entries) * @param pWriteBackMap the KEntryMap where the entries are placed * @param options See ParseOptions * @return See ParseInfo */ virtual ParseInfo parseConfig(const QByteArray &locale, KEntryMap &pWriteBackMap, ParseOptions options = ParseOptions()) = 0; /** * Write the @em dirty entries to permanent storage * * @param locale the locale to write entries for (if the backend supports localized entries) * @param entryMap the KEntryMap containing the config object's entries. * @param options See WriteOptions * * @return @c true if the write was successful, @c false if writing the configuration failed */ virtual bool writeConfig(const QByteArray &locale, KEntryMap &entryMap, WriteOptions options) = 0; /** * If isWritable() returns false, writeConfig() will always fail. * * @return @c true if the configuration is writable, @c false if it is immutable */ virtual bool isWritable() const = 0; /** * When isWritable() returns @c false, return an error message to * explain to the user why saving configuration will not work. * * The return value when isWritable() returns @c true is undefined. * * @returns a translated user-visible explanation for the configuration * object not being writable */ virtual QString nonWritableErrorMessage() const = 0; /** * @return the read/write status of the configuration object * * @see KConfigBase::AccessMode */ virtual KConfigBase::AccessMode accessMode() const = 0; /** * Create the enclosing object of the configuration object * * For example, if the configuration object is a file, this should create * the parent directory. */ virtual void createEnclosing() = 0; /** * Set the file path. * * @note @p path @b MUST be @em absolute. * * @param path the absolute file path */ virtual void setFilePath(const QString &path) = 0; /** * Lock the file */ virtual bool lock() = 0; /** * Release the lock on the file */ virtual void unlock() = 0; /** * @return @c true if the file is locked, @c false if it is not locked */ virtual bool isLocked() const = 0; /** * @return the date and time when the object was last modified */ QDateTime lastModified() const; /** @return the absolute path to the object */ QString filePath() const; /** @return the size of the object */ qint64 size() const; protected: KConfigBackend(); void setLastModified(const QDateTime &dt); void setSize(qint64 sz); void setLocalFilePath(const QString &file); private: KConfigBackendPrivate *const d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(KConfigBackend::ParseOptions) Q_DECLARE_OPERATORS_FOR_FLAGS(KConfigBackend::WriteOptions) +#if 0 // TODO re-enable if the plugin loading code is re-enabled /** * Register a KConfig backend when it is contained in a loadable module */ #define K_EXPORT_KCONFIGBACKEND(libname, classname) \ K_PLUGIN_FACTORY(factory, registerPlugin();) +#endif #endif // KCONFIGBACKEND_H