diff --git a/autotests/pythontest.py b/autotests/pythontest.py new file mode 100644 index 0000000..4b17880 --- /dev/null +++ b/autotests/pythontest.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- + +from __future__ import print_function + +import sys + +sys.path.append(sys.argv[1]) + +from PyQt5 import QtCore +from PyQt5 import QtWidgets + +from PyKF5 import KCoreAddons + +def main(): + app = QtWidgets.QApplication(sys.argv) + + assert(KCoreAddons.KStringHandler.capwords("the quick brown fox jumped over the lazy dog") == "The Quick Brown Fox Jumped Over The Lazy Dog") + +if __name__ == '__main__': + sys.exit(main()) diff --git a/cmake/rules_PyKF5.py b/cmake/rules_PyKF5.py new file mode 100644 index 0000000..f5e5286 --- /dev/null +++ b/cmake/rules_PyKF5.py @@ -0,0 +1,86 @@ +# +# 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 clang.cindex import AccessSpecifier + +def discard_base(container, sip, matcher): + sip["base_specifiers"] = [] + +def local_container_rules(): + return [ + [".*", "KUserId", ".*", ".*", ".*", discard_base], + [".*", "KGroupId", ".*", ".*", ".*", discard_base] + ] + +def local_forward_declaration_rules(): + return [ + [".*", "QWidget", ".*", rules_engine.mark_forward_declaration_external] + ] + +def local_function_rules(): + return [ + + ["KUser", "KUser", ".*", ".*", ".*passwd.*", rules_engine.function_discard], + ["KUserGroup", "KUserGroup", ".*", ".*", ".*group.*", rules_engine.function_discard], + + ["KCrash", "defaultCrashHandler", ".*", ".*", ".*", rules_engine.function_discard], + + # Deprecated + ["KPluginFactory", "createPartObject", ".*", ".*", ".*", rules_engine.function_discard], + + # Multiple overloads with same python signature + ["KMacroExpanderBase", "expandMacrosShellQuote", ".*", ".*", ".*, int ", rules_engine.function_discard], + ["KRandomSequence", "setSeed", ".*", ".*", "int.*", rules_engine.function_discard], + + [".*", "qobject_cast", ".*", ".*", ".*", rules_engine.function_discard], + [".*", "qobject_interface_iid", ".*", ".*", ".*", rules_engine.function_discard], + ] + +def rewrite_typedef_as_unsigned_int(container, typedef, sip, matcher): + sip["decl"] = "unsigned int" + +def local_typedef_rules(): + return [ + ["KPluginFactory", "CreateInstanceFunction", rules_engine.typedef_discard], + [".*", "K_GID", rewrite_typedef_as_unsigned_int], + [".*", "K_UID", rewrite_typedef_as_unsigned_int], + ] + +class RuleSet(Qt5Ruleset.RuleSet): + def __init__(self): + Qt5Ruleset.RuleSet.__init__(self) + self._forward_declaration_db = rules_engine.ForwardDeclarationRuleDb(lambda: local_forward_declaration_rules() + Qt5Ruleset.forward_declaration_rules()) + 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()) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 00f2f2c..3ca9682 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,216 +1,260 @@ # Configure checks for the caching subdir include(CheckIncludeFiles) check_include_files("sys/types.h;sys/mman.h" HAVE_SYS_MMAN_H) configure_file(caching/config-caching.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-caching.h) include(CheckSymbolExists) check_symbol_exists("getgrouplist" "grp.h" HAVE_GETGROUPLIST) configure_file(util/config-getgrouplist.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-getgrouplist.h) set (KDE4_DEFAULT_HOME ".kde${_KDE4_DEFAULT_HOME_POSTFIX}" CACHE STRING "The default KDE home directory" ) configure_file(util/config-kde4home.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kde4home.h) set (ACCOUNTS_SERVICE_ICON_DIR "/var/lib/AccountsService/icons" CACHE STRING "Accounts Services icon storage directory") configure_file(util/config-accountsservice.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-accountsservice.h) ecm_create_qm_loader(kcoreaddons_QM_LOADER kcoreaddons5_qt) set(kcoreaddons_OPTIONAL_SRCS ) set(kcoreaddons_OPTIONAL_LIBS ) if (FAM_FOUND) include_directories(${FAM_INCLUDE_DIR}) set(kcoreaddons_OPTIONAL_LIBS ${kcoreaddons_OPTIONAL_LIBS} ${FAM_LIBRARIES}) endif () if(NOT WIN32) set(kcoreaddons_OPTIONAL_SRCS caching/kshareddatacache.cpp) set(kcoreaddons_OPTIONAL_LIBS ${kcoreaddons_OPTIONAL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) set_source_files_properties(caching/kshareddatacache.cpp PROPERTIES COMPILE_FLAGS -fexceptions) else() set(kcoreaddons_OPTIONAL_SRCS caching/kshareddatacache_win.cpp ) endif() if (WIN32) set(kcoreaddons_OPTIONAL_SRCS ${kcoreaddons_OPTIONAL_SRCS} text/kmacroexpander_win.cpp util/kshell_win.cpp util/kuser_win.cpp ) endif () if (UNIX) set(kcoreaddons_OPTIONAL_SRCS ${kcoreaddons_OPTIONAL_SRCS} text/kmacroexpander_unix.cpp util/kuser_unix.cpp util/kshell_unix.cpp ) endif () set(libkcoreaddons_SRCS kaboutdata.cpp kcoreaddons.cpp io/kautosavefile.cpp io/kdirwatch.cpp io/kfilesystemtype.cpp io/kmessage.cpp io/kprocess.cpp io/kbackup.cpp io/kurlmimedata.cpp jobs/kcompositejob.cpp jobs/kjob.cpp jobs/kjobtrackerinterface.cpp jobs/kjobuidelegate.cpp plugin/kpluginfactory.cpp plugin/kpluginloader.cpp plugin/kpluginmetadata.cpp plugin/desktopfileparser.cpp randomness/krandom.cpp randomness/krandomsequence.cpp text/kmacroexpander.cpp text/kstringhandler.cpp text/ktexttohtml.cpp util/kdelibs4migration.cpp util/kdelibs4configmigrator.cpp util/kformat.cpp util/kformatprivate.cpp util/kshell.cpp ${kcoreaddons_OPTIONAL_SRCS} ${kcoreaddons_QM_LOADER} ) set(kcoreaddons_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/../.. # for kcoreaddons_version.h ${CMAKE_CURRENT_SOURCE_DIR}/caching/ ${CMAKE_CURRENT_BINARY_DIR}/io/ ${CMAKE_CURRENT_SOURCE_DIR}/io/ ${CMAKE_CURRENT_SOURCE_DIR}/jobs/ ${CMAKE_CURRENT_SOURCE_DIR}/plugin/ ${CMAKE_CURRENT_SOURCE_DIR}/randomness/ ${CMAKE_CURRENT_SOURCE_DIR}/text/ ${CMAKE_CURRENT_SOURCE_DIR}/util/ ) ecm_qt_declare_logging_category(libkcoreaddons_SRCS HEADER kcoreaddons_debug.h IDENTIFIER KCOREADDONS_DEBUG CATEGORY_NAME org.kde.kcoreaddons) add_library(KF5CoreAddons ${libkcoreaddons_SRCS}) generate_export_header(KF5CoreAddons BASE_NAME KCoreAddons) add_library(KF5::CoreAddons ALIAS KF5CoreAddons) target_include_directories(KF5CoreAddons PUBLIC "$") target_link_libraries(KF5CoreAddons PUBLIC Qt5::Core PRIVATE ${kcoreaddons_OPTIONAL_LIBS} ) target_link_libraries(KF5CoreAddons PRIVATE ${CMAKE_THREAD_LIBS_INIT}) if(WIN32) target_link_libraries(KF5CoreAddons PRIVATE netapi32 userenv) endif() target_include_directories(KF5CoreAddons INTERFACE "$" ) target_compile_definitions(KF5CoreAddons INTERFACE "$") set_target_properties(KF5CoreAddons PROPERTIES VERSION ${KCOREADDONS_VERSION_STRING} SOVERSION ${KCOREADDONS_SOVERSION} EXPORT_NAME CoreAddons ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KAboutData KCoreAddons REQUIRED_HEADERS KCoreAddons_HEADERS ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KSharedDataCache RELATIVE caching REQUIRED_HEADERS KCoreAddons_HEADERS ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KAutoSaveFile KDirWatch KMessage KProcess KBackup KUrlMimeData KFileSystemType RELATIVE io REQUIRED_HEADERS KCoreAddons_HEADERS ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KCompositeJob KJob KJobTrackerInterface KJobUiDelegate RELATIVE jobs REQUIRED_HEADERS KCoreAddons_HEADERS ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KExportPlugin KPluginFactory KPluginLoader KPluginMetaData RELATIVE plugin REQUIRED_HEADERS KCoreAddons_HEADERS ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KRandom KRandomSequence RELATIVE randomness REQUIRED_HEADERS KCoreAddons_HEADERS ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KMacroExpander KStringHandler KTextToHTML KTextToHTMLEmoticonsInterface RELATIVE text REQUIRED_HEADERS KCoreAddons_HEADERS ) ecm_generate_headers(KCoreAddons_HEADERS HEADER_NAMES KFormat KUser KShell Kdelibs4Migration Kdelibs4ConfigMigrator RELATIVE util REQUIRED_HEADERS KCoreAddons_HEADERS ) +find_package(PythonModuleGeneration) + +if (PythonModuleGeneration_FOUND) + ecm_generate_python_binding( + TARGET KF5::CoreAddons + PYTHONNAMESPACE PyKF5 + MODULENAME KCoreAddons + RULES_FILE "${CMAKE_SOURCE_DIR}/cmake/rules_PyKF5.py" + INSTALL_DIR_SUFFIX ${KDE_INSTALL_PYTHONBINDINGSDIR} + SIP_DEPENDS + QtCore/QtCoremod.sip + HEADERS + kaboutdata.h + kcoreaddons.h + caching/kshareddatacache.h + io/kautosavefile.h + io/kdirwatch.h + io/kmessage.h + io/kprocess.h + io/kbackup.h + io/kurlmimedata.h + io/kfilesystemtype.h + jobs/kcompositejob.h + jobs/kjob.h + jobs/kjobtrackerinterface.h + jobs/kjobuidelegate.h + plugin/kexportplugin.h + plugin/kpluginfactory.h + plugin/kpluginloader.h + plugin/kpluginmetadata.h + randomness/krandom.h + randomness/krandomsequence.h + text/kmacroexpander.h + text/kstringhandler.h + text/ktexttohtml.h + text/ktexttohtmlemoticonsinterface.h + util/kformat.h + util/kuser.h + util/kshell.h + util/kdelibs4migration.h + util/kdelibs4configmigrator.h + ) +endif() + install(TARGETS KF5CoreAddons EXPORT KF5CoreAddonsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${KCoreAddons_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/kcoreaddons_export.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KCoreAddons COMPONENT Devel ) # Includes CMake code to install open-source license texts for KAboutData. add_subdirectory(licenses) include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KCoreAddons LIB_NAME KF5CoreAddons DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KCoreAddons) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})