Signed-off-by: Andrew Lee (李健秋) <ajqlee@debian.org>upstream/1.2.0+20150807
parent
8762635176
commit
f0d36ad500
@ -1,23 +0,0 @@
|
|||||||
FIND_PATH(LIBMAGIC_INCLUDE_DIR magic.h)
|
|
||||||
|
|
||||||
FIND_LIBRARY(LIBMAGIC_LIBRARY NAMES magic)
|
|
||||||
|
|
||||||
IF (LIBMAGIC_INCLUDE_DIR AND LIBMAGIC_LIBRARY)
|
|
||||||
SET(LIBMAGIC_FOUND TRUE)
|
|
||||||
ENDIF (LIBMAGIC_INCLUDE_DIR AND LIBMAGIC_LIBRARY)
|
|
||||||
|
|
||||||
IF (LIBMAGIC_FOUND)
|
|
||||||
IF (NOT LibMagic_FIND_QUIETLY)
|
|
||||||
MESSAGE(STATUS "Found libmagic: ${LIBMAGIC_LIBRARY}")
|
|
||||||
MESSAGE(STATUS " includes: ${LIBMAGIC_INCLUDE_DIR}")
|
|
||||||
ENDIF (NOT LibMagic_FIND_QUIETLY)
|
|
||||||
ELSE (LIBMAGIC_FOUND)
|
|
||||||
IF (LibMagic_FIND_REQUIRED)
|
|
||||||
MESSAGE(STATUS "")
|
|
||||||
MESSAGE(STATUS "libmagic development package cannot be found. Install it, please")
|
|
||||||
MESSAGE(STATUS "For example in (open)SUSE it's file-devel package")
|
|
||||||
MESSAGE(STATUS "")
|
|
||||||
MESSAGE(FATAL_ERROR "Could not find libmagic")
|
|
||||||
ENDIF (LibMagic_FIND_REQUIRED)
|
|
||||||
ENDIF (LIBMAGIC_FOUND)
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
|||||||
# some system (rpm builds) setup LIB_SUFFIX for cmake. If there is no set, try to get it from system
|
|
||||||
IF(NOT DEFINED LIB_SUFFIX AND LIB_SUFFIX_ALREADY_SET)
|
|
||||||
MESSAGE(STATUS "*********************************************************************")
|
|
||||||
MESSAGE(STATUS "LIB_SUFFIX variable is not defined. It will be autodetected now")
|
|
||||||
MESSAGE(STATUS "You can set it manually with -DLIB_SUFFIX=<value> (64 for example)")
|
|
||||||
|
|
||||||
# All 32bit system have empty lib suffix
|
|
||||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
||||||
# If there is lib64 dir, set suffix to 64
|
|
||||||
if(IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib64")
|
|
||||||
set(LIB_SUFFIX 64)
|
|
||||||
elseif(IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib")
|
|
||||||
set(LIB_SUFFIX "")
|
|
||||||
else()
|
|
||||||
message(WARNING "LIB_SUFFIX cannot be autodetected. No \"${CMAKE_INSTALL_PREFIX}/lib\" neither \"${CMAKE_INSTALL_PREFIX}/lib64\" found.")
|
|
||||||
set(LIB_SUFFIX "")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
set(LIB_SUFFIX "")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(LIB_SUFFIX_ALREADY_SET 1)
|
|
||||||
|
|
||||||
message(STATUS "LIB_SUFFIX autodetected as '${LIB_SUFFIX}', libraries will be installed into \"${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}\"")
|
|
||||||
MESSAGE(STATUS "*********************************************************************")
|
|
||||||
ENDIF(NOT DEFINED LIB_SUFFIX AND LIB_SUFFIX_ALREADY_SET)
|
|
@ -0,0 +1,94 @@
|
|||||||
|
#=============================================================================
|
||||||
|
# Copyright 2015 Luís Pereira <luis.artur.pereira@gmail.com>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#=============================================================================
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Honor visibility properties for all target types.
|
||||||
|
#
|
||||||
|
# The ``<LANG>_VISIBILITY_PRESET`` and
|
||||||
|
# ``VISIBILITY_INLINES_HIDDEN`` target properties affect visibility
|
||||||
|
# of symbols during dynamic linking. When first introduced these properties
|
||||||
|
# affected compilation of sources only in shared libraries, module libraries,
|
||||||
|
# and executables with the ``ENABLE_EXPORTS`` property set. This
|
||||||
|
# was sufficient for the basic use cases of shared libraries and executables
|
||||||
|
# with plugins. However, some sources may be compiled as part of static
|
||||||
|
# libraries or object libraries and then linked into a shared library later.
|
||||||
|
# CMake 3.3 and above prefer to honor these properties for sources compiled
|
||||||
|
# in all target types. This policy preserves compatibility for projects
|
||||||
|
# expecting the properties to work only for some target types.
|
||||||
|
#
|
||||||
|
# The ``OLD`` behavior for this policy is to ignore the visibility properties
|
||||||
|
# for static libraries, object libraries, and executables without exports.
|
||||||
|
# The ``NEW`` behavior for this policy is to honor the visibility properties
|
||||||
|
# for all target types.
|
||||||
|
#
|
||||||
|
# This policy was introduced in CMake version 3.3. CMake version
|
||||||
|
# 3.3.0 warns when the policy is not set and uses ``OLD`` behavior. Use
|
||||||
|
# the ``cmake_policy()`` command to set it to ``OLD`` or ``NEW``
|
||||||
|
# explicitly.
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
if(COMMAND CMAKE_POLICY)
|
||||||
|
if (POLICY CMP0063)
|
||||||
|
cmake_policy(SET CMP0063 NEW)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Detect Clang compiler
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||||
|
set(QTXDG_COMPILER_IS_CLANGCXX 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Set visibility to hidden to hide symbols, unless they're exported manually
|
||||||
|
# in the code
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||||
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Disable exceptions
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
if (CMAKE_COMPILER_IS_GNUCXX OR QTXDG_COMPILER_IS_CLANGCXX)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Common warning flags
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
set(QTXDG_COMMON_WARNING_FLAGS "-Wall")
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Warning flags
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
list(APPEND QTXDG_WARNING_FLAGS ${QTXDG_COMMON_WARNING_FLAGS})
|
||||||
|
add_definitions(${QTXDG_WARNING_FLAGS})
|
@ -1,36 +1,245 @@
|
|||||||
|
#=============================================================================
|
||||||
|
# Copyright 2015 Luís Pereira <luis.artur.pereira@gmail.com>
|
||||||
#
|
#
|
||||||
# Write a pkg-config pc file for given "name" with "decription"
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# Arguments:
|
# modification, are permitted provided that the following conditions
|
||||||
# name: a library name (withoud "lib" prefix and "so" suffixes
|
# are met:
|
||||||
# desc: a desription string
|
|
||||||
# requires: required libraries
|
|
||||||
# include_rel_dir: include directory, relative to includedir
|
|
||||||
# version: package version
|
|
||||||
#
|
#
|
||||||
macro (create_pkgconfig_file name desc requires include_rel_dir version)
|
# 1. Redistributions of source code must retain the copyright
|
||||||
set(_pkgfname "${CMAKE_CURRENT_BINARY_DIR}/${name}.pc")
|
# notice, this list of conditions and the following disclaimer.
|
||||||
message(STATUS "${name}: writing pkgconfig file ${_pkgfname}")
|
# 2. Redistributions in binary form must reproduce the copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in the
|
||||||
file(WRITE "${_pkgfname}"
|
# documentation and/or other materials provided with the distribution.
|
||||||
"# file generated by razor-qt cmake build\n"
|
# 3. The name of the author may not be used to endorse or promote products
|
||||||
"prefix=${CMAKE_INSTALL_PREFIX}\n"
|
# derived from this software without specific prior written permission.
|
||||||
"libdir=\${prefix}/${CMAKE_INSTALL_LIBDIR}\n"
|
#
|
||||||
"includedir=\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}\n"
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
"\n"
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
"Name: ${name}\n"
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
"Description: ${desc}\n"
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
"Version: ${version}\n"
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
"Requires: ${requires}\n"
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
"Libs: -L\${libdir} -l${name}\n"
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
"Cflags: -I\${includedir} -I\${includedir}/${include_rel_dir}\n"
|
# 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.
|
||||||
|
#=============================================================================#
|
||||||
|
|
||||||
|
# create_pkgconfig_file(PACKAGE_NAME <package_name>
|
||||||
|
# VERSION <version>
|
||||||
|
# [PREFIX <path>]
|
||||||
|
# [EXEC_PREFIX <path>]
|
||||||
|
# [INCLUDEDIR_PREFIX <path>]
|
||||||
|
# [INCLUDEDIRS <path1> <path2> ... <path3>]
|
||||||
|
# [LIBDIR_PREFIX <path>]
|
||||||
|
# [DESCRIPTIVE_NAME <name>]
|
||||||
|
# [DESCRIPTION <description>]
|
||||||
|
# [URL <url>]
|
||||||
|
# [REQUIRES <dep1> <dep2> ... <dep3>]
|
||||||
|
# [REQUIRES_PRIVATE <dep1> <dep2> ... <dep3>]
|
||||||
|
# [LIB_INSTALLDIR <dir>]
|
||||||
|
# [CFLAGS <cflags>]
|
||||||
|
# [PATH <path>]
|
||||||
|
# [INSTALL])
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# PACKAGE_NAME and VERSION are mandatory. Everything else is optional
|
||||||
|
|
||||||
|
include(CMakeParseArguments)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
function(create_pkgconfig_file)
|
||||||
|
set(options INSTALL)
|
||||||
|
set(oneValueArgs
|
||||||
|
PACKAGE_NAME
|
||||||
|
PREFIX
|
||||||
|
EXEC_PREFIX
|
||||||
|
INCLUDEDIR_PREFIX
|
||||||
|
LIBDIR_PREFIX
|
||||||
|
DESCRIPTIVE_NAME
|
||||||
|
DESCRIPTION
|
||||||
|
URL
|
||||||
|
VERSION
|
||||||
|
PATH
|
||||||
|
)
|
||||||
|
set(multiValueArgs
|
||||||
|
INCLUDEDIRS
|
||||||
|
REQUIRES
|
||||||
|
REQUIRES_PRIVATE
|
||||||
|
CONFLICTS
|
||||||
|
CFLAGS
|
||||||
|
LIBS
|
||||||
|
LIBS_PRIVATE
|
||||||
|
)
|
||||||
|
|
||||||
|
cmake_parse_arguments(USER "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
|
if (USER_UNPARSED_ARGUMENTS)
|
||||||
|
message(FATAL_ERROR "Unknown keywords given to create_pkgconfig_file(): \"${USER_UNPARSED_ARGUMENTS}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check for mandatory args. Abort if not set
|
||||||
|
if (NOT DEFINED USER_PACKAGE_NAME)
|
||||||
|
message(FATAL_ERROR "Required argument PACKAGE_NAME missing in generate_pkgconfig_file() call")
|
||||||
|
else()
|
||||||
|
set(_PKGCONFIG_PACKAGE_NAME "${USER_PACKAGE_NAME}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_VERSION)
|
||||||
|
message(FATAL_ERROR "Required argument VERSION missing in generate_pkgconfig_file() call")
|
||||||
|
else()
|
||||||
|
set(_PKGCONFIG_VERSION "${USER_VERSION}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# Optional args
|
||||||
|
if (NOT DEFINED USER_PREFIX)
|
||||||
|
set(_PKGCONFIG_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_EXEC_PREFIX)
|
||||||
|
set(_PKGCONFIG_EXEC_PREFIX "\${prefix}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_INCLUDEDIR_PREFIX)
|
||||||
|
set(_PKGCONFIG_INCLUDEDIR_PREFIX "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_LIBDIR_PREFIX)
|
||||||
|
set(_PKGCONFIG_LIBDIR_PREFIX "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_DESCRIPTIVE_NAME)
|
||||||
|
set(_PKGCONFIG_DESCRIPTIVE_NAME "")
|
||||||
|
else()
|
||||||
|
set(_PKGCONFIG_DESCRIPTIVE_NAME "${USER_DESCRIPTIVE_NAME}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED USER_INCLUDEDIRS)
|
||||||
|
set(tmp "")
|
||||||
|
foreach(dir ${USER_INCLUDEDIRS})
|
||||||
|
if (NOT IS_ABSOLUTE "${dir}")
|
||||||
|
list(APPEND tmp "-I\${includedir}/${dir}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
string(REPLACE ";" " " _INCLUDEDIRS "${tmp}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED USER_REQUIRES)
|
||||||
|
string(REPLACE ";" ", " _PKGCONFIG_REQUIRES "${USER_REQUIRES}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED USER_REQUIRES_PRIVATE)
|
||||||
|
string(REPLACE ";" ", " _PKGCONFIG_REQUIRES_PRIVATE "${USER_REQUIRES_PRIVATE}")
|
||||||
|
else()
|
||||||
|
set(_PKGCONFIG_REQUIRES_PRIVATE "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_CFLAGS)
|
||||||
|
set(_PKGCONFIG_CFLAGS "-I\${includedir} ${_INCLUDEDIRS}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_LIBS)
|
||||||
|
set(_PKGCONFIG_LIBS "-L\${libdir}")
|
||||||
|
else()
|
||||||
|
set(tmp "-L\${libdir}")
|
||||||
|
set(_libs "${USER_LIBS}")
|
||||||
|
foreach(lib ${_libs})
|
||||||
|
list(APPEND tmp "-l${lib}")
|
||||||
|
endforeach()
|
||||||
|
string(REPLACE ";" " " _PKGCONFIG_LIBS "${tmp}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_LIBS_PRIVATE)
|
||||||
|
set(PKGCONFIG_LIBS "-L\${libdir}")
|
||||||
|
else()
|
||||||
|
set(tmp "")
|
||||||
|
set(_libs "${USER_LIBS_PRIVATE}")
|
||||||
|
foreach(lib ${_libs})
|
||||||
|
list(APPEND tmp "-l${lib}")
|
||||||
|
endforeach()
|
||||||
|
string(REPLACE ";" " " _PKGCONFIG_LIBS_PRIVATE "${tmp}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED USER_DESCRIPTION)
|
||||||
|
set(_PKGCONFIG_DESCRIPTION "${USER_DESCRIPTION}")
|
||||||
|
else()
|
||||||
|
set(_PKGCONFIG_DESCRIPTION "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED USER_URL)
|
||||||
|
set(_PKFCONFIG_URL "${USER_URL}")
|
||||||
|
else()
|
||||||
|
set(_PKGCONFIG_URL "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT DEFINED USER_PATH)
|
||||||
|
set(_PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${_PKGCONFIG_PACKAGE_NAME}.pc")
|
||||||
|
else()
|
||||||
|
if (IS_ABSOLUTE "${USER_PATH}")
|
||||||
|
set(_PKGCONFIG_FILE "${USER_PATH}/${_PKGCONFIG_PACKAGE_NAME}.pc")
|
||||||
|
else()
|
||||||
|
set(_PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${USER_PATH}/${_PKGCONFIG_PACKAGE_NAME}.pc")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Write the .pc file
|
||||||
|
FILE(WRITE "${_PKGCONFIG_FILE}"
|
||||||
|
"# file generated by create_pkgconfig_file()\n"
|
||||||
|
"prefix=${_PKGCONFIG_PREFIX}\n"
|
||||||
|
"exec_prefix=${_PKGCONFIG_EXEC_PREFIX}\n"
|
||||||
|
"libdir=${_PKGCONFIG_LIBDIR_PREFIX}\n"
|
||||||
|
"includedir=${_PKGCONFIG_INCLUDEDIR_PREFIX}\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"Name: ${_PKGCONFIG_DESCRIPTIVE_NAME}\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (NOT "${_PKGCONFIG_DESCRIPTION}" STREQUAL "")
|
||||||
|
FILE(APPEND ${_PKGCONFIG_FILE}
|
||||||
|
"Description: ${_PKGCONFIG_DESCRIPTION}\n"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT "${_PKGCONFIG_URL}" STREQUAL "")
|
||||||
|
FILE(APPEND ${_PKGCONFIG_FILE} "URL: ${_PKGCONFIG_URL}\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
FILE(APPEND ${_PKGCONFIG_FILE} "Version: ${_PKGCONFIG_VERSION}\n")
|
||||||
|
|
||||||
|
if (NOT "${_PKGCONFIG_REQUIRES}" STREQUAL "")
|
||||||
|
FILE(APPEND ${_PKGCONFIG_FILE} "Requires: ${_PKGCONFIG_REQUIRES}\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT "${_PKGCONFIG_REQUIRES_PRIVATE}" STREQUAL "")
|
||||||
|
FILE(APPEND ${_PKGCONFIG_FILE}
|
||||||
|
"Requires.private: ${_PKGCONFIG_REQUIRES_PRIVATE}\n"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
FILE(APPEND ${_PKGCONFIG_FILE}
|
||||||
|
"Cflags: ${_PKGCONFIG_CFLAGS}\n"
|
||||||
|
"Libs: ${_PKGCONFIG_LIBS}\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT "${_PKGCONFIG_LIBS_PRIVATE}" STREQUAL "")
|
||||||
|
FILE(APPEND ${_PKGCONFIG_FILE}
|
||||||
|
"Libs.private: ${_PKGCONFIG_REQUIRES_PRIVATE}\n"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (DEFINED USER_INSTALL)
|
||||||
# FreeBSD loves to install files to different locations
|
# FreeBSD loves to install files to different locations
|
||||||
# http://www.freebsd.org/doc/handbook/dirstructure.html
|
# http://www.freebsd.org/doc/handbook/dirstructure.html
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
||||||
install(FILES ${_pkgfname} DESTINATION libdata/pkgconfig)
|
set(_PKGCONFIG_INSTALL_DESTINATION "libdata/pkgconfig")
|
||||||
else()
|
else()
|
||||||
install(FILES ${_pkgfname} DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
set(_PKGCONFIG_INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Make the COMPONENT an parameter ?
|
||||||
|
install(FILES "${_PKGCONFIG_FILE}"
|
||||||
|
DESTINATION "${_PKGCONFIG_INSTALL_DESTINATION}"
|
||||||
|
COMPONENT Devel)
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endfunction()
|
||||||
|
@ -1,54 +1,12 @@
|
|||||||
# - Find the QtXdg include and library dirs and define a some macros
|
@PACKAGE_INIT@
|
||||||
#
|
|
||||||
# The module defines the following variables
|
|
||||||
# QTXDG_FOUND - Set to TRUE if all of the above has been found
|
|
||||||
#
|
|
||||||
# QTXDG_INCLUDE_DIR - The QtXdg include directory
|
|
||||||
#
|
|
||||||
# QTXDG_INCLUDE_DIRS - The QtXdg lib and it's dependencies include directories
|
|
||||||
#
|
|
||||||
# QTXDG_LIBRARY_DIRS - The QtXdg lib and it's dependencies linker search paths
|
|
||||||
#
|
|
||||||
# QTXDG_LIBRARY - The QtXdg library itself
|
|
||||||
# QTXDG_LIBRARIES - The QtXdg library and all it's dependencies
|
|
||||||
#
|
|
||||||
# QTXDG_USE_FILE - The variable QTXDG_USE_FILE is set which is the path
|
|
||||||
# to a CMake file that can be included to compile qtxdg
|
|
||||||
# applications and libraries. It sets up the compilation
|
|
||||||
# environment for include directories and populates a
|
|
||||||
# QTXDG_LIBRARIES variable.
|
|
||||||
#
|
|
||||||
# QTXDG_QT_LIBRARIES - The QtXdg Qt dependencies libraries
|
|
||||||
#
|
|
||||||
# Typical usage:
|
|
||||||
# option(USE_QT5 "Build using Qt5. Default off" OFF)
|
|
||||||
# if (USE_QT5)
|
|
||||||
# find_package(QT5XDG)
|
|
||||||
# else()
|
|
||||||
# find_package(QTXDG)
|
|
||||||
# endif()
|
|
||||||
#
|
|
||||||
# include(${QTXDG_USE_FILE})
|
|
||||||
# add_executable(use-qtxdg main.cpp)
|
|
||||||
# target_link_libraries(use-qtxdg ${QTXDG_LIBRARIES})
|
|
||||||
|
|
||||||
set(QTXDG_INCLUDE_DIR "@QTXDG_INCLUDE_DIR@")
|
include(CMakeFindDependencyMacro)
|
||||||
set(QTXDG_LIBRARY @QTXDGX_LIBRARY_NAME@)
|
|
||||||
set(QTXDG_PRIVATE_INCLUDE_DIR "@QTXDG_PRIVATE_INCLUDE_DIR@" CACHE PATH "Qt5Xdg private include dir")
|
|
||||||
|
|
||||||
set(QTXDG_LIBRARIES ${QTXDG_LIBRARY})
|
find_dependency(Qt5Widgets)
|
||||||
set(QTXDG_INCLUDE_DIRS "${QTXDG_INCLUDE_DIR}")
|
find_dependency(Qt5Xml)
|
||||||
set(QTXDG_PRIVATE_INCLUDE_DIRS "${QTXDG_PRIVATE_INCLUDE_DIR}")
|
find_dependency(Qt5DBus)
|
||||||
|
|
||||||
set(QTXDG_LIBRARY_DIRS "@CMAKE_INSTALL_FULL_LIBDIR@")
|
if (CMAKE_VERSION VERSION_GREATER 2.8.12)
|
||||||
|
cmake_policy(SET CMP0024 OLD)
|
||||||
set(QTXDG_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/@QTXDGX_FILE_NAME@_use.cmake")
|
endif()
|
||||||
set(QTXDG_FOUND 1)
|
include("${CMAKE_CURRENT_LIST_DIR}/qt5xdg-targets.cmake")
|
||||||
set(QTXDG_QTMIMETYPES @USE_QTMIMETYPES@)
|
|
||||||
|
|
||||||
set(QTXDG_MAJOR_VERSION @QTXDG_MAJOR_VERSION@)
|
|
||||||
set(QTXDG_MINOR_VERSION @QTXDG_MINOR_VERSION@)
|
|
||||||
set(QTXDG_PATCH_VERSION @QTXDG_PATCH_VERSION@)
|
|
||||||
set(QTXDG_VERSION @QTXDG_MAJOR_VERSION@.@QTXDG_MINOR_VERSION@.@QTXDG_PATCH_VERSION@)
|
|
||||||
|
|
||||||
mark_as_advanced(QTXDG_LIBRARY QTXDG_INCLUDE_DIR QTXDG_PRIVATE_INCLUDE_DIR)
|
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
find_package(Qt5Widgets REQUIRED)
|
|
||||||
find_package(Qt5Xml REQUIRED)
|
|
||||||
find_package(Qt5DBus REQUIRED)
|
|
||||||
|
|
||||||
if (QTXDG_QTMIMETYPES)
|
|
||||||
add_definitions("-DQT_MIMETYPES")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_definitions(${Qt5Core_DEFINITIONS})
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}"
|
|
||||||
)
|
|
||||||
set(QTXDG_QT_LIBRARIES ${Qt5Widgets_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5DBus_LIBRARIES})
|
|
||||||
set(QTXDG_LIBRARIES ${QTXDG_LIBRARIES} ${QTXDG_QT_LIBRARIES})
|
|
||||||
set(QTXDG_INCLUDE_DIRS
|
|
||||||
"${QTXDG_INCLUDE_DIRS}"
|
|
||||||
"${Qt5Widgets_INCLUDE_DIRS}"
|
|
||||||
"${Qt5Xml_INCLUDE_DIRS}"
|
|
||||||
"${Qt5DBus_INCLUDE_DIRS}"
|
|
||||||
)
|
|
||||||
|
|
||||||
link_directories("${QTXDG_LIBRARY_DIRS}")
|
|
||||||
include_directories("${QTXDG_INCLUDE_DIRS}")
|
|
@ -1,53 +0,0 @@
|
|||||||
# - Find the QtXdg include and library dirs and define a some macros
|
|
||||||
#
|
|
||||||
# The module defines the following variables
|
|
||||||
# QTXDG_FOUND - Set to TRUE if all of the above has been found
|
|
||||||
#
|
|
||||||
# QTXDG_INCLUDE_DIR - The QtXdg include directory
|
|
||||||
#
|
|
||||||
# QTXDG_INCLUDE_DIRS - The QtXdg lib and it's dependencies include directories
|
|
||||||
#
|
|
||||||
# QTXDG_LIBRARY_DIRS - The QtXdg lib and it's dependencies linker search paths
|
|
||||||
#
|
|
||||||
# QTXDG_LIBRARY - The QtXdg library itself
|
|
||||||
# QTXDG_LIBRARIES - The QtXdg library and all it's dependencies
|
|
||||||
#
|
|
||||||
# QTXDG_USE_FILE - The variable QTXDG_USE_FILE is set which is the path
|
|
||||||
# to a CMake file that can be included to compile qtxdg
|
|
||||||
# applications and libraries. It sets up the compilation
|
|
||||||
# environment for include directories and populates a
|
|
||||||
# QTXDG_LIBRARIES variable.
|
|
||||||
#
|
|
||||||
# QTXDG_QT_LIBRARIES - The QtXdg Qt dependencies libraries
|
|
||||||
#
|
|
||||||
# Typical usage:
|
|
||||||
# option(USE_QT5 "Build using Qt5. Default off" OFF)
|
|
||||||
# if (USE_QT5)
|
|
||||||
# find_package(QT5XDG)
|
|
||||||
# else()
|
|
||||||
# find_package(QTXDG)
|
|
||||||
# endif()
|
|
||||||
#
|
|
||||||
# include(${QTXDG_USE_FILE})
|
|
||||||
# add_executable(use-qtxdg main.cpp)
|
|
||||||
# target_link_libraries(use-qtxdg ${QTXDG_LIBRARIES})
|
|
||||||
|
|
||||||
set(QTXDG_INCLUDE_DIR "@QTXDG_INCLUDE_DIR@")
|
|
||||||
set(QTXDG_PRIVATE_INCLUDE_DIR "@QTXDG_PRIVATE_INCLUDE_DIR@")
|
|
||||||
set(QTXDG_LIBRARY @QTXDGX_LIBRARY_NAME@)
|
|
||||||
|
|
||||||
set(QTXDG_LIBRARIES ${QTXDG_LIBRARY})
|
|
||||||
set(QTXDG_INCLUDE_DIRS "${QTXDG_INCLUDE_DIR}")
|
|
||||||
|
|
||||||
set(QTXDG_LIBRARY_DIRS "@CMAKE_INSTALL_FULL_LIBDIR@")
|
|
||||||
|
|
||||||
set(QTXDG_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/@QTXDGX_FILE_NAME@_use.cmake")
|
|
||||||
set(QTXDG_FOUND 1)
|
|
||||||
set(QTXDG_QTMIMETYPES @USE_QTMIMETYPES@)
|
|
||||||
|
|
||||||
set(QTXDG_MAJOR_VERSION @QTXDG_MAJOR_VERSION@)
|
|
||||||
set(QTXDG_MINOR_VERSION @QTXDG_MINOR_VERSION@)
|
|
||||||
set(QTXDG_PATCH_VERSION @QTXDG_PATCH_VERSION@)
|
|
||||||
set(QTXDG_VERSION @QTXDG_MAJOR_VERSION@.@QTXDG_MINOR_VERSION@.@QTXDG_PATCH_VERSION@)
|
|
||||||
|
|
||||||
mark_as_advanced(QTXDG_LIBRARY QTXDG_INCLUDE_DIR)
|
|
@ -1,42 +0,0 @@
|
|||||||
# - Find the Razor-qt include and library dirs and define a some macros
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
find_package(Qt4 REQUIRED QtCore QtGui QtXml QtDBus QUIET)
|
|
||||||
include(${QT_USE_FILE})
|
|
||||||
|
|
||||||
set(QTXDG_QT_LIBRARIES
|
|
||||||
${QT_QTCORE_LIBRARY}
|
|
||||||
${QT_QTGUI_LIBRARY}
|
|
||||||
${QT_QTXML_LIBRARY}
|
|
||||||
${QT_DBUS_LIBRARY}
|
|
||||||
)
|
|
||||||
|
|
||||||
set(QTXDG_LIBRARIES ${QTXDG_LIBRARY} ${QTXDG_QT_LIBRARIES})
|
|
||||||
|
|
||||||
set(QTXDG_INCLUDE_DIRS
|
|
||||||
${QTXDG_INCLUDE_DIRS}
|
|
||||||
${QT_QTCORE_INCLUDE_DIR}
|
|
||||||
${QT_QTGUI_INCLUDE_DIR}
|
|
||||||
${QT_QTXML_INCLUDE_DIR}
|
|
||||||
${QT_QTDBUS_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
set(QTXDG_DEFINITIONS ${QT_DEFINITIONS})
|
|
||||||
|
|
||||||
if (QTXDG_QTMIMETYPES)
|
|
||||||
find_package(PkgConfig)
|
|
||||||
pkg_check_modules(QTMIMETYPES REQUIRED
|
|
||||||
QtMimeTypes
|
|
||||||
)
|
|
||||||
|
|
||||||
set(QTXDG_LIBRARIES ${QTXDG_LIBRARY} ${QTMIMETYPES_LIBRARIES})
|
|
||||||
set(QTXDG_LIBRARY_DIRS ${QTXDG_LIBRARY_DIRS} ${QTMIMETYPES_LIBRARY_DIRS})
|
|
||||||
set(QTXDG_DEFINITIONS ${QTXDG_DEFINITIONS} "-DQT_MIMETYPES")
|
|
||||||
include_directories(${QTXDG_INCLUDE_DIR} ${QTMIMETYPES_INCLUDE_DIRS})
|
|
||||||
link_directories(${QTXDG_LIBRARY_DIRS})
|
|
||||||
add_definitions("-DQT_MIMETYPES")
|
|
||||||
else()
|
|
||||||
include_directories(${QTXDG_INCLUDE_DIR} ${QTMIMETYPES_INCLUDE_DIRS})
|
|
||||||
link_directories(${QTXDG_LIBRARY_DIRS})
|
|
||||||
endif()
|
|
@ -1,18 +1,6 @@
|
|||||||
project(use-qtxdg)
|
project(use-qtxdg)
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
|
||||||
option(USE_QT5 "Build using Qt5. Default off" OFF)
|
|
||||||
|
|
||||||
if (USE_QT5)
|
|
||||||
find_package(QT5XDG)
|
|
||||||
else()
|
|
||||||
find_package(QTXDG)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(${QTXDG_USE_FILE})
|
|
||||||
|
|
||||||
|
find_package(QT5XDG)
|
||||||
add_executable(use-qtxdg main.cpp)
|
add_executable(use-qtxdg main.cpp)
|
||||||
|
target_link_libraries(use-qtxdg Qt5Xdg)
|
||||||
# The QTXDG_QT_LIBRARIES variable contains the needed Qt libraries. They are
|
|
||||||
# set taking in account the choosed Qt version.
|
|
||||||
target_link_libraries(use-qtxdg ${QTXDG_QT_LIBRARIES} ${QTXDG_LIBRARIES})
|
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
An example of how to write an CMakeLists.txt to use libqtxdg in a portable
|
An example of how to write an CMakeLists.txt to use libqtxdg.
|
||||||
way.
|
|
||||||
|
|
||||||
Building with Qt4 is the default. Ex:
|
To build this example just use:
|
||||||
cmake..
|
cmake ..
|
||||||
|
|
||||||
To build with Qt5 just pass to set the USE_QT5 to Yes. Ex:
|
|
||||||
|
|
||||||
cmake -DUSE_QT5=On ..
|
|
||||||
|
@ -1,216 +0,0 @@
|
|||||||
/* BEGIN_COMMON_COPYRIGHT_HEADER
|
|
||||||
* (c)LGPL2
|
|
||||||
*/
|
|
||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
||||||
** All rights reserved.
|
|
||||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
||||||
**
|
|
||||||
** This file is part of the QtGui module of the Qt Toolkit.
|
|
||||||
**
|
|
||||||
** $QT_BEGIN_LICENSE:LGPL$
|
|
||||||
** GNU Lesser General Public License Usage
|
|
||||||
** This file may be used under the terms of the GNU Lesser General Public
|
|
||||||
** License version 2.1 as published by the Free Software Foundation and
|
|
||||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
||||||
** file. Please review the following information to ensure the GNU Lesser
|
|
||||||
** General Public License version 2.1 requirements will be met:
|
|
||||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
||||||
**
|
|
||||||
** In addition, as a special exception, Nokia gives you certain additional
|
|
||||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU General
|
|
||||||
** Public License version 3.0 as published by the Free Software Foundation
|
|
||||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
||||||
** file. Please review the following information to ensure the GNU General
|
|
||||||
** Public License version 3.0 requirements will be met:
|
|
||||||
** http://www.gnu.org/copyleft/gpl.html.
|
|
||||||
**
|
|
||||||
** Other Usage
|
|
||||||
** Alternatively, this file may be used in accordance with the terms and
|
|
||||||
** conditions contained in a signed written agreement between you and Nokia.
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
** $QT_END_LICENSE$
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
//END_COMMON_COPYRIGHT_HEADER
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
It's fixes the following bugs:
|
|
||||||
* QIcon::fromTheme returns pixmaps that are bigger than requested
|
|
||||||
https://bugreports.qt.nokia.com/browse/QTBUG-17953
|
|
||||||
|
|
||||||
* Qt should honor /usr/share/pixmaps as a valid icon directory on Linux
|
|
||||||
https://bugreports.qt.nokia.com/browse/QTBUG-12874
|
|
||||||
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef QDESKTOPICON_P_H
|
|
||||||
#define QDESKTOPICON_P_H
|
|
||||||
|
|
||||||
#ifndef QT_NO_ICON
|
|
||||||
//
|
|
||||||
// W A R N I N G
|
|
||||||
// -------------
|
|
||||||
//
|
|
||||||
// This file is not part of the Qt API. It exists purely as an
|
|
||||||
// implementation detail. This header file may change from version to
|
|
||||||
// version without notice, or even be removed.
|
|
||||||
//
|
|
||||||
// We mean it.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <QtGui/QIcon>
|
|
||||||
#include <QtGui/QIconEngine>
|
|
||||||
#include <QtGui/QPixmapCache>
|
|
||||||
//#include "qt/qicon_p.h"
|
|
||||||
//#include "qt/qfactoryloader_p.h"
|
|
||||||
#include <QHash>
|
|
||||||
|
|
||||||
namespace QtXdg {
|
|
||||||
|
|
||||||
class QIconLoader;
|
|
||||||
|
|
||||||
struct QIconDirInfo
|
|
||||||
{
|
|
||||||
enum Type { Fixed, Scalable, Threshold };
|
|
||||||
QIconDirInfo(const QString &_path = QString()) :
|
|
||||||
path(_path),
|
|
||||||
size(0),
|
|
||||||
maxSize(0),
|
|
||||||
minSize(0),
|
|
||||||
threshold(0),
|
|
||||||
type(Threshold) {}
|
|
||||||
QString path;
|
|
||||||
short size;
|
|
||||||
short maxSize;
|
|
||||||
short minSize;
|
|
||||||
short threshold;
|
|
||||||
Type type : 4;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QIconLoaderEngineEntry
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~QIconLoaderEngineEntry() {}
|
|
||||||
virtual QPixmap pixmap(const QSize &size,
|
|
||||||
QIcon::Mode mode,
|
|
||||||
QIcon::State state) = 0;
|
|
||||||
QString filename;
|
|
||||||
QIconDirInfo dir;
|
|
||||||
static int count;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ScalableEntry : public QIconLoaderEngineEntry
|
|
||||||
{
|
|
||||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
|
|
||||||
QIcon svgIcon;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PixmapEntry : public QIconLoaderEngineEntry
|
|
||||||
{
|
|
||||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
|
|
||||||
QPixmap basePixmap;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef QList<QIconLoaderEngineEntry*> QThemeIconEntries;
|
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
class QIconLoaderEngineFixed : public QIconEngineV2
|
|
||||||
#else
|
|
||||||
class QIconLoaderEngineFixed : public QIconEngine
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QIconLoaderEngineFixed(const QString& iconName = QString());
|
|
||||||
~QIconLoaderEngineFixed();
|
|
||||||
|
|
||||||
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
|
|
||||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
|
|
||||||
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
QIconEngineV2 *clone() const;
|
|
||||||
#else
|
|
||||||
QIconEngine *clone() const;
|
|
||||||
#endif
|
|
||||||
bool read(QDataStream &in);
|
|
||||||
bool write(QDataStream &out) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString key() const;
|
|
||||||
bool hasIcon() const;
|
|
||||||
void ensureLoaded();
|
|
||||||
void virtual_hook(int id, void *data);
|
|
||||||
QIconLoaderEngineEntry *entryForSize(const QSize &size);
|
|
||||||
QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other);
|
|
||||||
QThemeIconEntries m_entries;
|
|
||||||
QString m_iconName;
|
|
||||||
uint m_key;
|
|
||||||
|
|
||||||
friend class QIconLoader;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QIconTheme
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QIconTheme(const QString &name);
|
|
||||||
QIconTheme() : m_valid(false) {}
|
|
||||||
QStringList parents() { return m_parents; }
|
|
||||||
QList <QIconDirInfo> keyList() { return m_keyList; }
|
|
||||||
QString contentDir() { return m_contentDir; }
|
|
||||||
QStringList contentDirs() { return m_contentDirs; }
|
|
||||||
bool isValid() { return m_valid; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_contentDir;
|
|
||||||
QStringList m_contentDirs;
|
|
||||||
QList <QIconDirInfo> m_keyList;
|
|
||||||
QStringList m_parents;
|
|
||||||
bool m_valid;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QIconLoader : public QObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QIconLoader();
|
|
||||||
QThemeIconEntries loadIcon(const QString &iconName) const;
|
|
||||||
uint themeKey() const { return m_themeKey; }
|
|
||||||
|
|
||||||
QString themeName() const { return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme; }
|
|
||||||
void setThemeName(const QString &themeName);
|
|
||||||
QIconTheme theme() { return themeList.value(themeName()); }
|
|
||||||
void setThemeSearchPath(const QStringList &searchPaths);
|
|
||||||
QStringList themeSearchPaths() const;
|
|
||||||
QIconDirInfo dirInfo(int dirindex);
|
|
||||||
static QIconLoader *instance();
|
|
||||||
void updateSystemTheme();
|
|
||||||
void invalidateKey() { m_themeKey++; }
|
|
||||||
void ensureInitialized();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QThemeIconEntries findIconHelper(const QString &themeName,
|
|
||||||
const QString &iconName,
|
|
||||||
QStringList &visited) const;
|
|
||||||
uint m_themeKey;
|
|
||||||
bool m_supportsSvg;
|
|
||||||
bool m_initialized;
|
|
||||||
|
|
||||||
mutable QString m_userTheme;
|
|
||||||
mutable QString m_systemTheme;
|
|
||||||
mutable QStringList m_iconDirs;
|
|
||||||
mutable QHash <QString, QIconTheme> themeList;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // QtXdg
|
|
||||||
|
|
||||||
#endif // QDESKTOPICON_P_H
|
|
||||||
|
|
||||||
#endif //QT_NO_ICON
|
|
@ -1,737 +0,0 @@
|
|||||||
/* BEGIN_COMMON_COPYRIGHT_HEADER
|
|
||||||
* (c)LGPL2
|
|
||||||
*/
|
|
||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
||||||
** All rights reserved.
|
|
||||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
||||||
**
|
|
||||||
** This file is part of the QtGui module of the Qt Toolkit.
|
|
||||||
**
|
|
||||||
** $QT_BEGIN_LICENSE:LGPL$
|
|
||||||
** GNU Lesser General Public License Usage
|
|
||||||
** This file may be used under the terms of the GNU Lesser General Public
|
|
||||||
** License version 2.1 as published by the Free Software Foundation and
|
|
||||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
||||||
** file. Please review the following information to ensure the GNU Lesser
|
|
||||||
** General Public License version 2.1 requirements will be met:
|
|
||||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
||||||
**
|
|
||||||
** In addition, as a special exception, Nokia gives you certain additional
|
|
||||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU General
|
|
||||||
** Public License version 3.0 as published by the Free Software Foundation
|
|
||||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
||||||
** file. Please review the following information to ensure the GNU General
|
|
||||||
** Public License version 3.0 requirements will be met:
|
|
||||||
** http://www.gnu.org/copyleft/gpl.html.
|
|
||||||
**
|
|
||||||
** Other Usage
|
|
||||||
** Alternatively, this file may be used in accordance with the terms and
|
|
||||||
** conditions contained in a signed written agreement between you and Nokia.
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
** $QT_END_LICENSE$
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
//END_COMMON_COPYRIGHT_HEADER
|
|
||||||
|
|
||||||
#ifndef QT_NO_ICON
|
|
||||||
#include "qiconloader_p_qt4.h"
|
|
||||||
|
|
||||||
//#include "qt/qapplication_p.h"
|
|
||||||
//#include <qt/qicon_p.h>
|
|
||||||
//#include <qt/qguiplatformplugin_p.h>
|
|
||||||
|
|
||||||
#include <QtGui/QIconEnginePlugin>
|
|
||||||
#include <QtGui/QPixmapCache>
|
|
||||||
#include <QtGui/QIconEngine>
|
|
||||||
#include <QStyleOption>
|
|
||||||
#include <QList>
|
|
||||||
#include <QHash>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QSettings>
|
|
||||||
#include <QtGui/QPainter>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QLatin1Literal>
|
|
||||||
//#ifdef Q_WS_MAC
|
|
||||||
//#include <private/qt_cocoa_helpers_mac_p.h>
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
//#ifdef Q_WS_X11
|
|
||||||
//#include "qt/qt_x11_p.h"
|
|
||||||
//#endif
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#if QT_VERSION < 0x040700
|
|
||||||
#include <limits.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace QtXdg {
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
|
|
||||||
|
|
||||||
/* Theme to use in last resort, if the theme does not have the icon, neither the parents */
|
|
||||||
/*static QString fallbackTheme()
|
|
||||||
{
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
if (X11->desktopEnvironment == DE_GNOME) {
|
|
||||||
return QLatin1String("gnome");
|
|
||||||
} else if (X11->desktopEnvironment == DE_KDE) {
|
|
||||||
return X11->desktopVersion >= 4
|
|
||||||
? QString::fromLatin1("oxygen")
|
|
||||||
: QString::fromLatin1("crystalsvg");
|
|
||||||
} else {
|
|
||||||
return QLatin1String("hicolor");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
QIconLoader::QIconLoader() :
|
|
||||||
m_themeKey(1), m_supportsSvg(false), m_initialized(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// We lazily initialize the loader to make static icons
|
|
||||||
// work. Though we do not officially support this.
|
|
||||||
void QIconLoader::ensureInitialized()
|
|
||||||
{
|
|
||||||
if (!m_initialized) {
|
|
||||||
m_initialized = true;
|
|
||||||
|
|
||||||
Q_ASSERT(qApp);
|
|
||||||
|
|
||||||
m_systemTheme = QIcon::themeName();
|
|
||||||
|
|
||||||
#ifndef QT_NO_LIBRARY
|
|
||||||
// QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
|
|
||||||
// QLatin1String("/iconengines"),
|
|
||||||
// Qt::CaseInsensitive);
|
|
||||||
// if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
|
|
||||||
m_supportsSvg = true;
|
|
||||||
#endif //QT_NO_LIBRARY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QIconLoader *QIconLoader::instance()
|
|
||||||
{
|
|
||||||
return iconLoaderInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Queries the system theme and invalidates existing
|
|
||||||
// icons if the theme has changed.
|
|
||||||
void QIconLoader::updateSystemTheme()
|
|
||||||
{
|
|
||||||
// Only change if this is not explicitly set by the user
|
|
||||||
if (m_userTheme.isEmpty()) {
|
|
||||||
QString theme = QIcon::themeName();//qt_guiPlatformPlugin()->systemIconThemeName();
|
|
||||||
//if (theme.isEmpty())
|
|
||||||
// theme = fallbackTheme();
|
|
||||||
if (theme != m_systemTheme) {
|
|
||||||
m_systemTheme = theme;
|
|
||||||
invalidateKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconLoader::setThemeName(const QString &themeName)
|
|
||||||
{
|
|
||||||
m_userTheme = themeName;
|
|
||||||
invalidateKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)
|
|
||||||
{
|
|
||||||
m_iconDirs = searchPaths;
|
|
||||||
themeList.clear();
|
|
||||||
invalidateKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList QIconLoader::themeSearchPaths() const
|
|
||||||
{
|
|
||||||
if (m_iconDirs.isEmpty())
|
|
||||||
{
|
|
||||||
m_iconDirs = QIcon::themeSearchPaths();//qt_guiPlatformPlugin()->iconThemeSearchPaths();
|
|
||||||
// Always add resource directory as search path
|
|
||||||
m_iconDirs.append(QLatin1String(":/icons"));
|
|
||||||
}
|
|
||||||
return m_iconDirs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QIconTheme::QIconTheme(const QString &themeName)
|
|
||||||
: m_valid(false)
|
|
||||||
{
|
|
||||||
|
|
||||||
QFile themeIndex;
|
|
||||||
|
|
||||||
QList <QIconDirInfo> keyList;
|
|
||||||
QStringList iconDirs = QIcon::themeSearchPaths();
|
|
||||||
for ( int i = 0 ; i < iconDirs.size() ; ++i) {
|
|
||||||
QDir iconDir(iconDirs[i]);
|
|
||||||
QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
|
|
||||||
themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
|
|
||||||
if (themeIndex.exists()) {
|
|
||||||
m_contentDir = themeDir;
|
|
||||||
m_valid = true;
|
|
||||||
|
|
||||||
QStringList themeSearchPaths = QIcon::themeSearchPaths();
|
|
||||||
foreach (QString path, themeSearchPaths)
|
|
||||||
{
|
|
||||||
if (!path.startsWith(':') && QFileInfo(path).isDir())
|
|
||||||
m_contentDirs.append(path + QLatin1Char('/') + themeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef QT_NO_SETTINGS
|
|
||||||
if (themeIndex.exists()) {
|
|
||||||
const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
|
|
||||||
QStringListIterator keyIterator(indexReader.allKeys());
|
|
||||||
while (keyIterator.hasNext()) {
|
|
||||||
|
|
||||||
const QString key = keyIterator.next();
|
|
||||||
if (key.endsWith(QLatin1String("/Size"))) {
|
|
||||||
// Note the QSettings ini-format does not accept
|
|
||||||
// slashes in key names, hence we have to cheat
|
|
||||||
if (int size = indexReader.value(key).toInt()) {
|
|
||||||
QString directoryKey = key.left(key.size() - 5);
|
|
||||||
QIconDirInfo dirInfo(directoryKey);
|
|
||||||
dirInfo.size = size;
|
|
||||||
QString type = indexReader.value(directoryKey +
|
|
||||||
QLatin1String("/Type")
|
|
||||||
).toString();
|
|
||||||
|
|
||||||
if (type == QLatin1String("Fixed"))
|
|
||||||
dirInfo.type = QIconDirInfo::Fixed;
|
|
||||||
else if (type == QLatin1String("Scalable"))
|
|
||||||
dirInfo.type = QIconDirInfo::Scalable;
|
|
||||||
else
|
|
||||||
dirInfo.type = QIconDirInfo::Threshold;
|
|
||||||
|
|
||||||
dirInfo.threshold = indexReader.value(directoryKey +
|
|
||||||
QLatin1String("/Threshold"),
|
|
||||||
2).toInt();
|
|
||||||
|
|
||||||
dirInfo.minSize = indexReader.value(directoryKey +
|
|
||||||
QLatin1String("/MinSize"),
|
|
||||||
size).toInt();
|
|
||||||
|
|
||||||
dirInfo.maxSize = indexReader.value(directoryKey +
|
|
||||||
QLatin1String("/MaxSize"),
|
|
||||||
size).toInt();
|
|
||||||
m_keyList.append(dirInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent themes provide fallbacks for missing icons
|
|
||||||
m_parents = indexReader.value(
|
|
||||||
QLatin1String("Icon Theme/Inherits")).toStringList();
|
|
||||||
|
|
||||||
// Ensure a default platform fallback for all themes
|
|
||||||
if (m_parents.isEmpty())
|
|
||||||
m_parents.append(QIcon::themeName());//fallbackTheme());
|
|
||||||
|
|
||||||
// Ensure that all themes fall back to hicolor
|
|
||||||
if (!m_parents.contains(QLatin1String("hicolor")))
|
|
||||||
m_parents.append(QLatin1String("hicolor"));
|
|
||||||
}
|
|
||||||
#endif //QT_NO_SETTINGS
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName,
|
|
||||||
const QString &iconName,
|
|
||||||
QStringList &visited) const
|
|
||||||
{
|
|
||||||
QThemeIconEntries entries;
|
|
||||||
Q_ASSERT(!themeName.isEmpty());
|
|
||||||
|
|
||||||
QPixmap pixmap;
|
|
||||||
|
|
||||||
// Used to protect against potential recursions
|
|
||||||
visited << themeName;
|
|
||||||
|
|
||||||
QIconTheme theme = themeList.value(themeName);
|
|
||||||
if (!theme.isValid()) {
|
|
||||||
theme = QIconTheme(themeName);
|
|
||||||
if (!theme.isValid())
|
|
||||||
theme = QIconTheme(QIcon::themeName());//fallbackTheme());
|
|
||||||
|
|
||||||
themeList.insert(themeName, theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList contentDirs = theme.contentDirs();
|
|
||||||
QList<QIconDirInfo> subDirs = theme.keyList();
|
|
||||||
|
|
||||||
const QString svgext(QLatin1String(".svg"));
|
|
||||||
const QString pngext(QLatin1String(".png"));
|
|
||||||
const QString xpmext(QLatin1String(".xpm"));
|
|
||||||
|
|
||||||
// Add all relevant files
|
|
||||||
for (int i = 0; i < subDirs.size() ; ++i)
|
|
||||||
{
|
|
||||||
const QIconDirInfo &dirInfo = subDirs.at(i);
|
|
||||||
QString subdir = dirInfo.path;
|
|
||||||
|
|
||||||
foreach (QString contentDir, contentDirs)
|
|
||||||
{
|
|
||||||
QDir currentDir(contentDir + '/' + subdir);
|
|
||||||
|
|
||||||
if (currentDir.exists(iconName + pngext))
|
|
||||||
{
|
|
||||||
PixmapEntry *iconEntry = new PixmapEntry;
|
|
||||||
iconEntry->dir = dirInfo;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + pngext);
|
|
||||||
// Notice we ensure that pixmap entries always come before
|
|
||||||
// scalable to preserve search order afterwards
|
|
||||||
entries.prepend(iconEntry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (m_supportsSvg &&
|
|
||||||
currentDir.exists(iconName + svgext))
|
|
||||||
{
|
|
||||||
ScalableEntry *iconEntry = new ScalableEntry;
|
|
||||||
iconEntry->dir = dirInfo;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + svgext);
|
|
||||||
entries.append(iconEntry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (currentDir.exists(iconName + xpmext))
|
|
||||||
{
|
|
||||||
PixmapEntry *iconEntry = new PixmapEntry;
|
|
||||||
iconEntry->dir = dirInfo;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + xpmext);
|
|
||||||
// Notice we ensure that pixmap entries always come before
|
|
||||||
// scalable to preserve search order afterwards
|
|
||||||
entries.append(iconEntry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entries.isEmpty()) {
|
|
||||||
const QStringList parents = theme.parents();
|
|
||||||
// Search recursively through inherited themes
|
|
||||||
for (int i = 0 ; i < parents.size() ; ++i) {
|
|
||||||
|
|
||||||
const QString parentTheme = parents.at(i).trimmed();
|
|
||||||
|
|
||||||
if (!visited.contains(parentTheme)) // guard against recursion
|
|
||||||
entries = findIconHelper(parentTheme, iconName, visited);
|
|
||||||
|
|
||||||
if (!entries.isEmpty()) // success
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
Author: Kaitlin Rupert <kaitlin.rupert@intel.com>
|
|
||||||
Date: Aug 12, 2010
|
|
||||||
Description: Make it so that the QIcon loader honors /usr/share/pixmaps
|
|
||||||
directory. This is a valid directory per the Freedesktop.org
|
|
||||||
icon theme specification.
|
|
||||||
Bug: https://bugreports.qt.nokia.com/browse/QTBUG-12874
|
|
||||||
*********************************************************************/
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
/* Freedesktop standard says to look in /usr/share/pixmaps last */
|
|
||||||
if (entries.isEmpty()) {
|
|
||||||
const QString pixmaps(QLatin1String("/usr/share/pixmaps"));
|
|
||||||
|
|
||||||
QDir currentDir(pixmaps);
|
|
||||||
QIconDirInfo dirInfo(pixmaps);
|
|
||||||
if (currentDir.exists(iconName + pngext)) {
|
|
||||||
PixmapEntry *iconEntry = new PixmapEntry;
|
|
||||||
iconEntry->dir = dirInfo;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + pngext);
|
|
||||||
// Notice we ensure that pixmap entries always come before
|
|
||||||
// scalable to preserve search order afterwards
|
|
||||||
entries.prepend(iconEntry);
|
|
||||||
} else if (m_supportsSvg &&
|
|
||||||
currentDir.exists(iconName + svgext)) {
|
|
||||||
ScalableEntry *iconEntry = new ScalableEntry;
|
|
||||||
iconEntry->dir = dirInfo;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + svgext);
|
|
||||||
entries.append(iconEntry);
|
|
||||||
} else if (currentDir.exists(iconName + xpmext)) {
|
|
||||||
PixmapEntry *iconEntry = new PixmapEntry;
|
|
||||||
iconEntry->dir = dirInfo;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + xpmext);
|
|
||||||
// Notice we ensure that pixmap entries always come before
|
|
||||||
// scalable to preserve search order afterwards
|
|
||||||
entries.append(iconEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (entries.isEmpty()) {
|
|
||||||
// Search for unthemed icons in main dir of search paths
|
|
||||||
QStringList themeSearchPaths = QIcon::themeSearchPaths();
|
|
||||||
foreach (QString contentDir, themeSearchPaths) {
|
|
||||||
QDir currentDir(contentDir);
|
|
||||||
|
|
||||||
if (currentDir.exists(iconName + pngext)) {
|
|
||||||
PixmapEntry *iconEntry = new PixmapEntry;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + pngext);
|
|
||||||
// Notice we ensure that pixmap entries always come before
|
|
||||||
// scalable to preserve search order afterwards
|
|
||||||
entries.prepend(iconEntry);
|
|
||||||
} else if (m_supportsSvg &&
|
|
||||||
currentDir.exists(iconName + svgext)) {
|
|
||||||
ScalableEntry *iconEntry = new ScalableEntry;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + svgext);
|
|
||||||
entries.append(iconEntry);
|
|
||||||
break;
|
|
||||||
} else if (currentDir.exists(iconName + xpmext)) {
|
|
||||||
PixmapEntry *iconEntry = new PixmapEntry;
|
|
||||||
iconEntry->filename = currentDir.filePath(iconName + xpmext);
|
|
||||||
// Notice we ensure that pixmap entries always come before
|
|
||||||
// scalable to preserve search order afterwards
|
|
||||||
entries.append(iconEntry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
QThemeIconEntries QIconLoader::loadIcon(const QString &name) const
|
|
||||||
{
|
|
||||||
if (!themeName().isEmpty()) {
|
|
||||||
QStringList visited;
|
|
||||||
return findIconHelper(themeName(), name, visited);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QThemeIconEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -------- Icon Loader Engine -------- //
|
|
||||||
|
|
||||||
|
|
||||||
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QString& iconName)
|
|
||||||
: m_iconName(iconName), m_key(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QIconLoaderEngineFixed::~QIconLoaderEngineFixed()
|
|
||||||
{
|
|
||||||
while (!m_entries.isEmpty())
|
|
||||||
delete m_entries.takeLast();
|
|
||||||
Q_ASSERT(m_entries.size() == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other)
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
: QIconEngineV2(other),
|
|
||||||
#else
|
|
||||||
: QIconEngine(other),
|
|
||||||
#endif
|
|
||||||
m_iconName(other.m_iconName),
|
|
||||||
m_key(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
QIconEngineV2 *QIconLoaderEngineFixed::clone() const
|
|
||||||
#else
|
|
||||||
QIconEngine *QIconLoaderEngineFixed::clone() const
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
return new QIconLoaderEngineFixed(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QIconLoaderEngineFixed::read(QDataStream &in) {
|
|
||||||
in >> m_iconName;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QIconLoaderEngineFixed::write(QDataStream &out) const
|
|
||||||
{
|
|
||||||
out << m_iconName;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QIconLoaderEngineFixed::hasIcon() const
|
|
||||||
{
|
|
||||||
return !(m_entries.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lazily load the icon
|
|
||||||
void QIconLoaderEngineFixed::ensureLoaded()
|
|
||||||
{
|
|
||||||
|
|
||||||
iconLoaderInstance()->ensureInitialized();
|
|
||||||
|
|
||||||
if (!(iconLoaderInstance()->themeKey() == m_key)) {
|
|
||||||
|
|
||||||
while (!m_entries.isEmpty())
|
|
||||||
delete m_entries.takeLast();
|
|
||||||
|
|
||||||
Q_ASSERT(m_entries.size() == 0);
|
|
||||||
m_entries = iconLoaderInstance()->loadIcon(m_iconName);
|
|
||||||
m_key = iconLoaderInstance()->themeKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconLoaderEngineFixed::paint(QPainter *painter, const QRect &rect,
|
|
||||||
QIcon::Mode mode, QIcon::State state)
|
|
||||||
{
|
|
||||||
QSize pixmapSize = rect.size();
|
|
||||||
#if defined(Q_WS_MAC)
|
|
||||||
pixmapSize *= qt_mac_get_scalefactor();
|
|
||||||
#endif
|
|
||||||
painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This algorithm is defined by the freedesktop spec:
|
|
||||||
* http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
|
|
||||||
*/
|
|
||||||
static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
|
|
||||||
{
|
|
||||||
if (dir.type == QIconDirInfo::Fixed) {
|
|
||||||
return dir.size == iconsize;
|
|
||||||
|
|
||||||
} else if (dir.type == QIconDirInfo::Scalable) {
|
|
||||||
return dir.size <= dir.maxSize &&
|
|
||||||
iconsize >= dir.minSize;
|
|
||||||
|
|
||||||
} else if (dir.type == QIconDirInfo::Threshold) {
|
|
||||||
return iconsize >= dir.size - dir.threshold &&
|
|
||||||
iconsize <= dir.size + dir.threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(1); // Not a valid value
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This algorithm is defined by the freedesktop spec:
|
|
||||||
* http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
|
|
||||||
*/
|
|
||||||
static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)
|
|
||||||
{
|
|
||||||
if (dir.type == QIconDirInfo::Fixed) {
|
|
||||||
return qAbs(dir.size - iconsize);
|
|
||||||
|
|
||||||
} else if (dir.type == QIconDirInfo::Scalable) {
|
|
||||||
if (iconsize < dir.minSize)
|
|
||||||
return dir.minSize - iconsize;
|
|
||||||
else if (iconsize > dir.maxSize)
|
|
||||||
return iconsize - dir.maxSize;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} else if (dir.type == QIconDirInfo::Threshold) {
|
|
||||||
if (iconsize < dir.size - dir.threshold)
|
|
||||||
return dir.minSize - iconsize;
|
|
||||||
else if (iconsize > dir.size + dir.threshold)
|
|
||||||
return iconsize - dir.maxSize;
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(1); // Not a valid value
|
|
||||||
return INT_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
|
|
||||||
{
|
|
||||||
int iconsize = qMin(size.width(), size.height());
|
|
||||||
|
|
||||||
// Note that m_entries are sorted so that png-files
|
|
||||||
// come first
|
|
||||||
|
|
||||||
// Search for exact matches first
|
|
||||||
for (int i = 0; i < m_entries.count(); ++i) {
|
|
||||||
QIconLoaderEngineEntry *entry = m_entries.at(i);
|
|
||||||
if (directoryMatchesSize(entry->dir, iconsize)) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the minimum distance icon
|
|
||||||
int minimalSize = INT_MAX;
|
|
||||||
QIconLoaderEngineEntry *closestMatch = 0;
|
|
||||||
for (int i = 0; i < m_entries.count(); ++i) {
|
|
||||||
QIconLoaderEngineEntry *entry = m_entries.at(i);
|
|
||||||
int distance = directorySizeDistance(entry->dir, iconsize);
|
|
||||||
if (distance < minimalSize) {
|
|
||||||
minimalSize = distance;
|
|
||||||
closestMatch = entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return closestMatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns the actual icon size. For scalable svg's this is equivalent
|
|
||||||
* to the requested size. Otherwise the closest match is returned but
|
|
||||||
* we can never return a bigger size than the requested size.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
QSize QIconLoaderEngineFixed::actualSize(const QSize &size, QIcon::Mode mode,
|
|
||||||
QIcon::State state)
|
|
||||||
{
|
|
||||||
ensureLoaded();
|
|
||||||
QIconLoaderEngineEntry *entry = entryForSize(size);
|
|
||||||
if (entry) {
|
|
||||||
const QIconDirInfo &dir = entry->dir;
|
|
||||||
if (dir.type == QIconDirInfo::Scalable)
|
|
||||||
{
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (dir.size == 0)
|
|
||||||
{
|
|
||||||
entry->dir.size = QPixmap(entry->filename).size().width();
|
|
||||||
entry->dir.minSize = dir.size;
|
|
||||||
entry->dir.maxSize = dir.size;
|
|
||||||
}
|
|
||||||
int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
|
|
||||||
|
|
||||||
return QSize(result, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
return QIconEngineV2::actualSize(size, mode, state);
|
|
||||||
#else
|
|
||||||
return QIconEngine::actualSize(size, mode, state);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
|
|
||||||
{
|
|
||||||
Q_UNUSED(state);
|
|
||||||
|
|
||||||
// Ensure that basePixmap is lazily initialized before generating the
|
|
||||||
// key, otherwise the cache key is not unique
|
|
||||||
if (basePixmap.isNull())
|
|
||||||
basePixmap.load(filename);
|
|
||||||
|
|
||||||
QSize actualSize = basePixmap.size();
|
|
||||||
if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
|
|
||||||
actualSize.scale(size, Qt::KeepAspectRatio);
|
|
||||||
|
|
||||||
|
|
||||||
QString key = QString("$qt_theme_%1%2%3%4%5")
|
|
||||||
.arg(basePixmap.cacheKey(), 16, 16, QChar('0'))
|
|
||||||
.arg(mode, 8, 16, QChar('0'))
|
|
||||||
.arg(qApp->palette().cacheKey(),16, 16, QChar('0'))
|
|
||||||
.arg(actualSize.width(), 8, 16, QChar('0'))
|
|
||||||
.arg(actualSize.height(), 8, 16, QChar('0'));
|
|
||||||
|
|
||||||
QPixmap cachedPixmap;
|
|
||||||
if (QPixmapCache::find(key, &cachedPixmap)) {
|
|
||||||
return cachedPixmap;
|
|
||||||
} else {
|
|
||||||
if (basePixmap.size() != actualSize)
|
|
||||||
basePixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
||||||
|
|
||||||
QStyleOption opt(0);
|
|
||||||
opt.palette = qApp->palette();
|
|
||||||
cachedPixmap = qApp->style()->generatedIconPixmap(mode, basePixmap, &opt);
|
|
||||||
QPixmapCache::insert(key, cachedPixmap);
|
|
||||||
}
|
|
||||||
return cachedPixmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
|
|
||||||
{
|
|
||||||
if (svgIcon.isNull())
|
|
||||||
svgIcon = QIcon(filename);
|
|
||||||
|
|
||||||
// Simply reuse svg icon engine
|
|
||||||
return svgIcon.pixmap(size, mode, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap QIconLoaderEngineFixed::pixmap(const QSize &size, QIcon::Mode mode,
|
|
||||||
QIcon::State state)
|
|
||||||
{
|
|
||||||
|
|
||||||
ensureLoaded();
|
|
||||||
|
|
||||||
QIconLoaderEngineEntry *entry = entryForSize(size);
|
|
||||||
|
|
||||||
if (entry)
|
|
||||||
return entry->pixmap(size, mode, state);
|
|
||||||
|
|
||||||
return QPixmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QIconLoaderEngineFixed::key() const
|
|
||||||
{
|
|
||||||
return QLatin1String("QIconLoaderEngineFixed");
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconLoaderEngineFixed::virtual_hook(int id, void *data)
|
|
||||||
{
|
|
||||||
ensureLoaded();
|
|
||||||
|
|
||||||
switch (id) {
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
case QIconEngineV2::AvailableSizesHook:
|
|
||||||
#else
|
|
||||||
case QIconEngine::AvailableSizesHook:
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
QIconEngineV2::AvailableSizesArgument &arg
|
|
||||||
= *reinterpret_cast<QIconEngineV2::AvailableSizesArgument*>(data);
|
|
||||||
#else
|
|
||||||
QIconEngine::AvailableSizesArgument &arg
|
|
||||||
= *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data);
|
|
||||||
#endif
|
|
||||||
const QList<QIconDirInfo> directoryKey = iconLoaderInstance()->theme().keyList();
|
|
||||||
arg.sizes.clear();
|
|
||||||
|
|
||||||
// Gets all sizes from the DirectoryInfo entries
|
|
||||||
for (int i = 0 ; i < m_entries.size() ; ++i) {
|
|
||||||
int size = m_entries.at(i)->dir.size;
|
|
||||||
arg.sizes.append(QSize(size, size));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#if (QT_VERSION >= 0x040700) && (QT_VERSION < 0x050000)
|
|
||||||
case QIconEngineV2::IconNameHook:
|
|
||||||
{
|
|
||||||
QString &name = *reinterpret_cast<QString*>(data);
|
|
||||||
name = m_iconName;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#elif QT_VERSION > QT_VERSION_CHECK(5,0,0)
|
|
||||||
case QIconEngine::IconNameHook:
|
|
||||||
{
|
|
||||||
QString &name = *reinterpret_cast<QString*>(data);
|
|
||||||
name = m_iconName;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#else// QT_VERSION > QT_VERSION_CHECK(5,0,0)
|
|
||||||
#warning QIconEngineV2::IconNameHook is ignored due Qt version. Upgrade to 4.7.x
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
|
||||||
QIconEngineV2::virtual_hook(id, data);
|
|
||||||
#else
|
|
||||||
QIconEngine::virtual_hook(id, data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // QtXdg
|
|
||||||
|
|
||||||
#endif //QT_NO_ICON
|
|
@ -1,52 +1,25 @@
|
|||||||
set(PROJECT_NAME "qtxdg_test")
|
set(PROJECT_NAME "qtxdg_test")
|
||||||
|
|
||||||
set(${PROJECT_NAME}_SRCS
|
set(CMAKE_AUTOMOC TRUE)
|
||||||
qtxdg_test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(${PROJECT_NAME}_MOCS
|
|
||||||
qtxdg_test.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(LIBRARIES
|
|
||||||
${QTXDGX_LIBRARY_NAME}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if (BUILD_TESTS)
|
macro(qtxdg_add_test)
|
||||||
add_definitions(-DQTXDG_BUILDING_TESTS=1)
|
foreach(_testname ${ARGN})
|
||||||
endif()
|
add_executable(${_testname} ${_testname}.cpp)
|
||||||
|
target_link_libraries(${_testname} Qt5::Test ${QTXDGX_LIBRARY_NAME})
|
||||||
if (USE_QT5)
|
add_test(NAME ${_testname} COMMAND ${_testname})
|
||||||
qt5_wrap_cpp(MOCS ${${PROJECT_NAME}_MOCS})
|
endforeach()
|
||||||
else()
|
endmacro()
|
||||||
qt4_wrap_cpp(MOCS ${${PROJECT_NAME}_MOCS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include_directories (
|
include_directories (
|
||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (USE_QT5)
|
set_property(DIRECTORY APPEND
|
||||||
add_definitions(${Qt5Test_DEFINITINS})
|
PROPERTY COMPILE_DEFINITIONS "QTXDG_BUILDING_TESTS=\"1\""
|
||||||
include_directories (
|
)
|
||||||
${Qt5Test_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} ${Qt5Test_EXECUTABLE_COMPILE_FLAGS}"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
include_directories (
|
|
||||||
${QT_QTCORE_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS} )
|
|
||||||
|
|
||||||
if (USE_QT5)
|
|
||||||
target_link_libraries ( ${PROJECT_NAME} ${Qt5Test_LIBRARIES} ${LIBRARIES} )
|
|
||||||
else()
|
|
||||||
target_link_libraries ( ${PROJECT_NAME} ${QT_LIBRARIES} ${LIBRARIES} )
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
|
qtxdg_add_test(
|
||||||
|
qtxdg_test
|
||||||
|
tst_xdgdirs
|
||||||
|
)
|
||||||
|
@ -0,0 +1,227 @@
|
|||||||
|
/* BEGIN_COMMON_COPYRIGHT_HEADER
|
||||||
|
* (c)LGPL2+
|
||||||
|
*
|
||||||
|
* LXQt - a lightweight, Qt based, desktop toolset
|
||||||
|
* http://lxqt.org
|
||||||
|
*
|
||||||
|
* Copyright: 2015 LXQt team
|
||||||
|
* Authors:
|
||||||
|
* Luís Pereira <luis.artur.pereira@gmail.com>
|
||||||
|
*
|
||||||
|
* This program or library is free software; you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU Lesser General
|
||||||
|
* Public License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* END_COMMON_COPYRIGHT_HEADER */
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "xdgdirs.h"
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
|
class tst_xdgdirs : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
void testDataHome();
|
||||||
|
void testConfigHome();
|
||||||
|
void testDataDirs();
|
||||||
|
void testConfigDirs();
|
||||||
|
void testCacheHome();
|
||||||
|
void testAutostartHome();
|
||||||
|
void testAutostartDirs();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setDefaultLocations();
|
||||||
|
void setCustomLocations();
|
||||||
|
|
||||||
|
QString m_configHome;
|
||||||
|
QTemporaryDir m_configHomeTemp;
|
||||||
|
QString m_configDirs;
|
||||||
|
QTemporaryDir m_configDirsTemp;
|
||||||
|
QString m_dataHome;
|
||||||
|
QTemporaryDir m_dataHomeTemp;
|
||||||
|
QString m_dataDirs;
|
||||||
|
QTemporaryDir m_dataDirsTemp;
|
||||||
|
QString m_cacheHome;
|
||||||
|
QTemporaryDir m_cacheHomeTemp;
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_xdgdirs::initTestCase()
|
||||||
|
{
|
||||||
|
QCoreApplication::instance()->setOrganizationName("QtXdg");
|
||||||
|
QCoreApplication::instance()->setApplicationName("tst_xdgdirs");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::cleanupTestCase()
|
||||||
|
{
|
||||||
|
QCoreApplication::instance()->setOrganizationName(QString());
|
||||||
|
QCoreApplication::instance()->setApplicationName(QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::setDefaultLocations()
|
||||||
|
{
|
||||||
|
qputenv("XDG_CONFIG_HOME", QByteArray());
|
||||||
|
qputenv("XDG_CONFIG_DIRS", QByteArray());
|
||||||
|
qputenv("XDG_DATA_HOME", QByteArray());
|
||||||
|
qputenv("XDG_DATA_DIRS", QByteArray());
|
||||||
|
qputenv("XDG_CACHE_HOME", QByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::setCustomLocations()
|
||||||
|
{
|
||||||
|
m_configHome = m_configHomeTemp.path();
|
||||||
|
m_configDirs = m_configDirsTemp.path();
|
||||||
|
m_dataHome = m_dataHomeTemp.path();
|
||||||
|
m_dataDirs = m_dataDirsTemp.path();
|
||||||
|
m_cacheHome = m_cacheHomeTemp.path();
|
||||||
|
qputenv("XDG_CONFIG_HOME", QFile::encodeName(m_configHome));
|
||||||
|
qputenv("XDG_CONFIG_DIRS", QFile::encodeName(m_configDirs));
|
||||||
|
qputenv("XDG_DATA_HOME", QFile::encodeName(m_dataHome));
|
||||||
|
qputenv("XDG_DATA_DIRS", QFile::encodeName(m_dataDirs));
|
||||||
|
qputenv("XDG_CACHE_HOME", QFile::encodeName(m_cacheHome));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::testDataHome()
|
||||||
|
{
|
||||||
|
setDefaultLocations();
|
||||||
|
const QString expectedDataHome = QDir::homePath() + QString::fromLatin1("/.local/share");
|
||||||
|
QCOMPARE(XdgDirs::dataHome(), expectedDataHome);
|
||||||
|
QCOMPARE(XdgDirs::dataHome(false), expectedDataHome);
|
||||||
|
|
||||||
|
setCustomLocations();
|
||||||
|
QCOMPARE(XdgDirs::dataHome(), m_dataHome);
|
||||||
|
QCOMPARE(XdgDirs::dataHome(false), m_dataHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::testConfigHome()
|
||||||
|
{
|
||||||
|
setDefaultLocations();
|
||||||
|
const QString expectedConfigHome = QDir::homePath() + QString::fromLatin1("/.config");
|
||||||
|
QCOMPARE(XdgDirs::configHome(), expectedConfigHome);
|
||||||
|
QCOMPARE(XdgDirs::configHome(false), expectedConfigHome);
|
||||||
|
|
||||||
|
setCustomLocations();
|
||||||
|
QCOMPARE(XdgDirs::configHome(), m_configHome);
|
||||||
|
QCOMPARE(XdgDirs::configHome(false), m_configHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::testDataDirs()
|
||||||
|
{
|
||||||
|
const QString postfix = QString::fromLatin1("/") + QCoreApplication::applicationName();
|
||||||
|
|
||||||
|
setDefaultLocations();
|
||||||
|
const QStringList dataDirs = XdgDirs::dataDirs();
|
||||||
|
QCOMPARE(dataDirs.count(), 2);
|
||||||
|
QCOMPARE(dataDirs.at(0), QString::fromLatin1("/usr/local/share"));
|
||||||
|
QCOMPARE(dataDirs.at(1), QString::fromLatin1("/usr/share"));
|
||||||
|
|
||||||
|
const QStringList dataDirsWithPostfix = XdgDirs::dataDirs(postfix);
|
||||||
|
QCOMPARE(dataDirsWithPostfix.count(), 2);
|
||||||
|
QCOMPARE(dataDirsWithPostfix.at(0), QString::fromLatin1("/usr/local/share") + postfix);
|
||||||
|
QCOMPARE(dataDirsWithPostfix.at(1), QString::fromLatin1("/usr/share") + postfix);
|
||||||
|
|
||||||
|
setCustomLocations();
|
||||||
|
const QStringList dataDirsCustom = XdgDirs::dataDirs();
|
||||||
|
QCOMPARE(dataDirsCustom.count(), 1);
|
||||||
|
QCOMPARE(dataDirsCustom.at(0), m_dataDirs);
|
||||||
|
|
||||||
|
const QStringList dataDirsCustomWithPostfix = XdgDirs::dataDirs(postfix);
|
||||||
|
QCOMPARE(dataDirsCustomWithPostfix.count(), 1);
|
||||||
|
QCOMPARE(dataDirsCustomWithPostfix.at(0), m_dataDirs + postfix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::testConfigDirs()
|
||||||
|
{
|
||||||
|
const QString postfix = QString::fromLatin1("/") + QCoreApplication::applicationName();
|
||||||
|
setDefaultLocations();
|
||||||
|
|
||||||
|
const QStringList configDirs = XdgDirs::configDirs();
|
||||||
|
QCOMPARE(configDirs.count(), 1);
|
||||||
|
QCOMPARE(configDirs.at(0), QString::fromLatin1("/etc/xdg"));
|
||||||
|
|
||||||
|
const QStringList configDirsWithPostfix = XdgDirs::configDirs(postfix);
|
||||||
|
QCOMPARE(configDirsWithPostfix.count(), 1);
|
||||||
|
QCOMPARE(configDirsWithPostfix.at(0), QString::fromLatin1("/etc/xdg") + postfix);
|
||||||
|
|
||||||
|
setCustomLocations();
|
||||||
|
const QStringList configDirsCustom = XdgDirs::configDirs();
|
||||||
|
QCOMPARE(configDirsCustom.count(), 1);
|
||||||
|
QCOMPARE(configDirsCustom.at(0), m_configDirs);
|
||||||
|
|
||||||
|
const QStringList configDirsCustomWithPostfix = XdgDirs::configDirs(postfix);
|
||||||
|
QCOMPARE(configDirsCustomWithPostfix.count(), 1);
|
||||||
|
QCOMPARE(configDirsCustomWithPostfix.at(0), m_configDirs + postfix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::testCacheHome()
|
||||||
|
{
|
||||||
|
setDefaultLocations();
|
||||||
|
const QString expectedCacheHome = QDir::homePath() + QString("/.cache");
|
||||||
|
QCOMPARE(XdgDirs::cacheHome(), expectedCacheHome);
|
||||||
|
QCOMPARE(XdgDirs::cacheHome(false), expectedCacheHome);
|
||||||
|
|
||||||
|
setCustomLocations();
|
||||||
|
const QString expectedCacheHomeCustom = XdgDirs::cacheHome();
|
||||||
|
QCOMPARE(XdgDirs::cacheHome(), expectedCacheHomeCustom);
|
||||||
|
QCOMPARE(XdgDirs::cacheHome(false), expectedCacheHomeCustom);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::testAutostartHome()
|
||||||
|
{
|
||||||
|
setDefaultLocations();
|
||||||
|
const QString expectedAutoStartHome = QDir::homePath() + QString::fromLatin1("/.config/autostart");
|
||||||
|
QCOMPARE(XdgDirs::autostartHome(), expectedAutoStartHome);
|
||||||
|
QCOMPARE(XdgDirs::autostartHome(false), expectedAutoStartHome);
|
||||||
|
|
||||||
|
setCustomLocations();
|
||||||
|
const QString expectedAutostartHomeCustom = XdgDirs::configHome() + QString::fromLatin1("/autostart");
|
||||||
|
QCOMPARE(XdgDirs::autostartHome(), expectedAutostartHomeCustom);
|
||||||
|
QCOMPARE(XdgDirs::autostartHome(false), expectedAutostartHomeCustom);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_xdgdirs::testAutostartDirs()
|
||||||
|
{
|
||||||
|
const QString postfix = QString::fromLatin1("/") + QCoreApplication::applicationName();
|
||||||
|
|
||||||
|
setDefaultLocations();
|
||||||
|
const QStringList autostartDirs = XdgDirs::autostartDirs();
|
||||||
|
QCOMPARE(autostartDirs.count(), 1);
|
||||||
|
QCOMPARE(autostartDirs.at(0), QString::fromLatin1("/etc/xdg/autostart"));
|
||||||
|
|
||||||
|
const QStringList autostartDirsWithPostfix = XdgDirs::autostartDirs(postfix);
|
||||||
|
QCOMPARE(autostartDirsWithPostfix.count(), 1);
|
||||||
|
QCOMPARE(autostartDirsWithPostfix.at(0), QString::fromLatin1("/etc/xdg/autostart") + postfix);
|
||||||
|
|
||||||
|
|
||||||
|
setCustomLocations();
|
||||||
|
const QStringList autostartDirsCustom = XdgDirs::autostartDirs();
|
||||||
|
QCOMPARE(autostartDirsCustom.count(), 1);
|
||||||
|
QCOMPARE(autostartDirsCustom.at(0), m_configDirs + QString::fromLatin1("/autostart"));
|
||||||
|
|
||||||
|
const QStringList autostartDirsCustomWithPostfix = XdgDirs::autostartDirs(postfix);
|
||||||
|
QCOMPARE(autostartDirsCustomWithPostfix.count(), 1);
|
||||||
|
QCOMPARE(autostartDirsCustomWithPostfix.at(0), m_configDirs + QString::fromLatin1("/autostart") + postfix);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_APPLESS_MAIN(tst_xdgdirs)
|
||||||
|
#include "tst_xdgdirs.moc"
|
@ -1,366 +0,0 @@
|
|||||||
/* BEGIN_COMMON_COPYRIGHT_HEADER
|
|
||||||
* (c)LGPL2+
|
|
||||||
*
|
|
||||||
* Razor - a lightweight, Qt based, desktop toolset
|
|
||||||
* http://razor-qt.org
|
|
||||||
*
|
|
||||||
* Copyright: 2010-2011 Razor team
|
|
||||||
* Authors:
|
|
||||||
* Alexander Sokoloff <sokoloff.a@gmail.com>
|
|
||||||
*
|
|
||||||
* This program or library is free software; you can redistribute it
|
|
||||||
* and/or modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
|
|
||||||
* You should have received a copy of the GNU Lesser General
|
|
||||||
* Public License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* END_COMMON_COPYRIGHT_HEADER */
|
|
||||||
|
|
||||||
|
|
||||||
#include "xdgmime.h"
|
|
||||||
#include "xdgicon.h"
|
|
||||||
#include "xdgdirs.h"
|
|
||||||
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <magic.h>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QMap>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QDomDocument>
|
|
||||||
#include <QDomElement>
|
|
||||||
#include <QSharedData>
|
|
||||||
|
|
||||||
|
|
||||||
struct XdgMimeData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
XdgMimeData(QString media, QString subtype);
|
|
||||||
bool readXml(QIODevice* xml);
|
|
||||||
|
|
||||||
QString mMedia;
|
|
||||||
QString mSubtype;
|
|
||||||
|
|
||||||
bool mDbLoaded;
|
|
||||||
QString mComment;
|
|
||||||
QMap<QString, QString> mLocalizedComments;
|
|
||||||
QStringList mPatterns;
|
|
||||||
QString mSubClassOf;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
|
|
||||||
************************************************/
|
|
||||||
XdgMimeInfo::XdgMimeInfo(const QString& mimeType)
|
|
||||||
{
|
|
||||||
QString media = mimeType.section('/', 0, 0);
|
|
||||||
QString subtype = mimeType.section('/', 1);
|
|
||||||
mData = new XdgMimeData(media, subtype);
|
|
||||||
}
|
|
||||||
|
|
||||||
XdgMimeInfo::~XdgMimeInfo()
|
|
||||||
{
|
|
||||||
delete mData;
|
|
||||||
mData = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
|
|
||||||
************************************************/
|
|
||||||
QString getFileMimeType(const QFileInfo& fileInfo, bool followSymLinks)
|
|
||||||
{
|
|
||||||
|
|
||||||
QString result("application/octet-stream");
|
|
||||||
|
|
||||||
magic_t magicMimePredictor;
|
|
||||||
magicMimePredictor = magic_open(MAGIC_MIME_TYPE); // Open predictor
|
|
||||||
if (!magicMimePredictor) {
|
|
||||||
qWarning() << "libmagic: Unable to initialize magic library";
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (magic_load(magicMimePredictor, 0)) { // if not 0 - error
|
|
||||||
qWarning() << QString("libmagic: Can't load magic database - %1").arg(magic_error(magicMimePredictor));
|
|
||||||
magic_close(magicMimePredictor); // Close predictor
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray ar = fileInfo.absoluteFilePath().toLocal8Bit();
|
|
||||||
if (followSymLinks && fileInfo.isSymLink())
|
|
||||||
{
|
|
||||||
ar = fileInfo.symLinkTarget().toLocal8Bit();
|
|
||||||
}
|
|
||||||
char *file = ar.data();
|
|
||||||
|
|
||||||
// getting mime-type ........................
|
|
||||||
const char *mime;
|
|
||||||
mime = magic_file(magicMimePredictor, file);
|
|
||||||
result = QString(mime);
|
|
||||||
|
|
||||||
// Close predictor ..........................
|
|
||||||
magic_close(magicMimePredictor);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
|
|
||||||
************************************************/
|
|
||||||
XdgMimeInfo::XdgMimeInfo(const QFileInfo& file, bool followSymLinks)
|
|
||||||
{
|
|
||||||
QString mimeType = getFileMimeType(file, followSymLinks);
|
|
||||||
QString media = mimeType.section('/', 0, 0);
|
|
||||||
QString subtype = mimeType.section('/', 1);
|
|
||||||
mData = new XdgMimeData(media, subtype);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
|
|
||||||
************************************************/
|
|
||||||
QString XdgMimeInfo::mimeType() const
|
|
||||||
{
|
|
||||||
return mData->mMedia + "/" + mData->mSubtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString XdgMimeInfo::mediaType() const
|
|
||||||
{
|
|
||||||
return mData->mMedia;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString XdgMimeInfo::subType() const
|
|
||||||
{
|
|
||||||
return mData->mSubtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString XdgMimeInfo::comment() const
|
|
||||||
{
|
|
||||||
return mData->mComment;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString XdgMimeInfo::localizedComment() const
|
|
||||||
{
|
|
||||||
// FIXME
|
|
||||||
return mData->mComment;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList XdgMimeInfo::patterns() const
|
|
||||||
{
|
|
||||||
return mData->mPatterns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
|
|
||||||
************************************************/
|
|
||||||
QString XdgMimeInfo::iconName() const
|
|
||||||
{
|
|
||||||
QStringList names;
|
|
||||||
names << QString("%1-x-%2").arg(mData->mMedia, mData->mSubtype);
|
|
||||||
names << QString("%1-%2").arg(mData->mMedia, mData->mSubtype);
|
|
||||||
names << QString("%1-x-generic").arg(mData->mMedia);
|
|
||||||
names << QString("%1-generic").arg(mData->mMedia);
|
|
||||||
|
|
||||||
foreach (QString s, names)
|
|
||||||
{
|
|
||||||
if (!XdgIcon::fromTheme(s).isNull())
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************************************
|
|
||||||
|
|
||||||
************************************************/
|
|
||||||
QIcon XdgMimeInfo::icon() const
|
|
||||||
{
|
|
||||||
return XdgIcon::fromTheme(iconName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString XdgMimeInfo::subClassOf() const
|
|
||||||
{
|
|
||||||
return mData->mSubClassOf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool XdgMimeInfo::loadFromDb(QIODevice* xml)
|
|
||||||
{
|
|
||||||
return mData->readXml(xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XdgMimeData::XdgMimeData(QString media, QString subtype):
|
|
||||||
mMedia(media),
|
|
||||||
mSubtype(subtype),
|
|
||||||
mDbLoaded(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XdgMimeData::readXml(QIODevice* xml)
|
|
||||||
{
|
|
||||||
QDomDocument domDocument;
|
|
||||||
if (! domDocument.setContent(xml, false))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement rootElement = domDocument.documentElement();
|
|
||||||
if (rootElement.nodeName() != "mime-type")
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rootElement.attribute("type") != mMedia + "/" + mSubtype)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomNodeList commentNodes = rootElement.elementsByTagName("comment");
|
|
||||||
for(int i = 0; i < commentNodes.size(); i++)
|
|
||||||
{
|
|
||||||
if (! commentNodes.item(i).isElement())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement commentElement = commentNodes.item(i).toElement();
|
|
||||||
|
|
||||||
if (commentElement.hasAttribute("xml:lang"))
|
|
||||||
{
|
|
||||||
mLocalizedComments[commentElement.attribute("xml:lang")] = commentElement.text();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mComment = commentElement.text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QSet<QString> collectedPatterns;
|
|
||||||
QDomNodeList globNodes = rootElement.elementsByTagName("glob");
|
|
||||||
for(int i = 0; i < globNodes.size(); i++)
|
|
||||||
{
|
|
||||||
if (globNodes.item(i).isElement() && globNodes.item(i).toElement().hasAttribute("pattern"))
|
|
||||||
{
|
|
||||||
collectedPatterns << globNodes.item(i).toElement().attribute("pattern");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mPatterns = collectedPatterns.toList();
|
|
||||||
mPatterns.sort();
|
|
||||||
|
|
||||||
QDomNodeList subClassOfElements = rootElement.elementsByTagName("sub-class-of");
|
|
||||||
if (subClassOfElements.size() > 0)
|
|
||||||
{
|
|
||||||
mSubClassOf = subClassOfElements.at(0).toElement().attribute("type");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList XdgMimeInfoCache::mediatypes()
|
|
||||||
{
|
|
||||||
return cache().keys();
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList XdgMimeInfoCache::subtypes(const QString& media)
|
|
||||||
{
|
|
||||||
return cache().value(media).keys();
|
|
||||||
}
|
|
||||||
|
|
||||||
XdgMimeInfo* XdgMimeInfoCache::xdgMimeInfo(const QString & media, const QString & subtype)
|
|
||||||
{
|
|
||||||
return cache().value(media).value(subtype);
|
|
||||||
}
|
|
||||||
|
|
||||||
XdgMimeInfo* XdgMimeInfoCache::xdgMimeInfo(const QString& mimetype)
|
|
||||||
{
|
|
||||||
QString media = mimetype.section("/", 0, 0);
|
|
||||||
QString subtype = mimetype.section("/", 1, 1);
|
|
||||||
return xdgMimeInfo(media, subtype);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void loadMimeInfoCache(QMap<QString, QMap<QString, XdgMimeInfo*> > & cache)
|
|
||||||
{
|
|
||||||
qDebug() << "loadMimeInfoCache";
|
|
||||||
QStringList datadirs = XdgDirs::dataDirs();
|
|
||||||
datadirs.prepend(XdgDirs::dataHome(false));
|
|
||||||
const QStringList filters = (QStringList() << "*.xml");
|
|
||||||
|
|
||||||
foreach (const QString datadir, datadirs)
|
|
||||||
{
|
|
||||||
QDir mimedir(datadir + "/mime");
|
|
||||||
|
|
||||||
if (! mimedir.exists())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
foreach (QFileInfo mediadirInfo, mimedir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot))
|
|
||||||
{
|
|
||||||
QString media = mediadirInfo.fileName();
|
|
||||||
|
|
||||||
QDir mediadir(mediadirInfo.absoluteFilePath());
|
|
||||||
foreach (QFileInfo subtypefileInfo, mediadir.entryInfoList(filters, QDir::Files))
|
|
||||||
{
|
|
||||||
QString subtype = subtypefileInfo.fileName().left(subtypefileInfo.fileName().length() - 4);
|
|
||||||
//qDebug() << "subtype:" << subtype;
|
|
||||||
QFile subtypefile(subtypefileInfo.absoluteFilePath());
|
|
||||||
XdgMimeInfo* mimeInfo = new XdgMimeInfo(media + "/" + subtype);
|
|
||||||
if (subtypefile.open(QIODevice::ReadOnly) && mimeInfo->loadFromDb(&subtypefile))
|
|
||||||
{
|
|
||||||
cache[media][subtype] = mimeInfo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete mimeInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TESTING
|
|
||||||
XdgMimeData data("application", "msword");
|
|
||||||
QFile mswordxml("/usr/share/mime/application/msword.xml");
|
|
||||||
mswordxml.open(QIODevice::ReadOnly);
|
|
||||||
data.readXml(&mswordxml);
|
|
||||||
qDebug() << "=================================================================================";
|
|
||||||
qDebug() << "data:" << data.mMedia << data.mSubtype << data.mComment << data.mLocalizedComments << data.mPatterns;
|
|
||||||
qDebug() << "=================================================================================";
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<QString, QMap<QString, XdgMimeInfo*> > & XdgMimeInfoCache::cache()
|
|
||||||
{
|
|
||||||
static QMap<QString, QMap<QString, XdgMimeInfo*> > _cache;
|
|
||||||
static bool cache_loaded = false;
|
|
||||||
|
|
||||||
if (! cache_loaded)
|
|
||||||
{
|
|
||||||
loadMimeInfoCache(_cache);
|
|
||||||
cache_loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _cache;
|
|
||||||
}
|
|
@ -1,99 +0,0 @@
|
|||||||
/* BEGIN_COMMON_COPYRIGHT_HEADER
|
|
||||||
* (c)LGPL2+
|
|
||||||
*
|
|
||||||
* Razor - a lightweight, Qt based, desktop toolset
|
|
||||||
* http://razor-qt.org
|
|
||||||
*
|
|
||||||
* Copyright: 2010-2011 Razor team
|
|
||||||
* Authors:
|
|
||||||
* Alexander Sokoloff <sokoloff.a@gmail.com>
|
|
||||||
*
|
|
||||||
* This program or library is free software; you can redistribute it
|
|
||||||
* and/or modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 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
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
|
|
||||||
* You should have received a copy of the GNU Lesser General
|
|
||||||
* Public License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* END_COMMON_COPYRIGHT_HEADER */
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef QTXDG_XDGMIME_H
|
|
||||||
#define QTXDG_XDGMIME_H
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QtGui/QIcon>
|
|
||||||
|
|
||||||
#include "xdgmacros.h"
|
|
||||||
|
|
||||||
struct XdgMimeData;
|
|
||||||
|
|
||||||
/*! @brief The XdgMimeInfo class provides mime information about file.
|
|
||||||
*/
|
|
||||||
class QTXDG_DEPRECATED QTXDG_API XdgMimeInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/// Constructs a XdgMimeInfo with the mimeType type.
|
|
||||||
explicit XdgMimeInfo(const QString& mimeType);
|
|
||||||
|
|
||||||
/**
|
|
||||||
Constructs a new XdgMimeInfo that gives mime information about the given file.
|
|
||||||
If file is symlink and followSymLinks is true function gives information for the
|
|
||||||
file the link references rather than for the link itself.
|
|
||||||
**/
|
|
||||||
explicit XdgMimeInfo(const QFileInfo& file, bool followSymLinks=true);
|
|
||||||
|
|
||||||
~XdgMimeInfo();
|
|
||||||
|
|
||||||
/// Returns the name of the mime type.
|
|
||||||
QString mimeType() const;
|
|
||||||
|
|
||||||
/// Returns the media type, eg. 'application' for mimetype 'application/pdf'
|
|
||||||
QString mediaType() const;
|
|
||||||
|
|
||||||
/// Returns the subtype, e.g. 'pdf' for 'application/pdf'
|
|
||||||
QString subType() const;
|
|
||||||
|
|
||||||
QString comment() const;
|
|
||||||
|
|
||||||
QString localizedComment() const;
|
|
||||||
|
|
||||||
QStringList patterns() const;
|
|
||||||
|
|
||||||
/// Returns an icon associated with the mime type.
|
|
||||||
QIcon icon() const;
|
|
||||||
|
|
||||||
/// Returns an icon associated with the mime type.
|
|
||||||
QString iconName() const;
|
|
||||||
|
|
||||||
QString subClassOf() const;
|
|
||||||
|
|
||||||
bool loadFromDb(QIODevice* xml);
|
|
||||||
|
|
||||||
private:
|
|
||||||
XdgMimeData *mData;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class QTXDG_DEPRECATED QTXDG_API XdgMimeInfoCache
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QStringList mediatypes();
|
|
||||||
static QStringList subtypes(const QString & media);
|
|
||||||
static XdgMimeInfo* xdgMimeInfo(const QString & media, const QString & subtype);
|
|
||||||
static XdgMimeInfo* xdgMimeInfo(const QString & mimetype);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static QMap<QString, QMap<QString, XdgMimeInfo*> > & cache();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QTXDG_XDGMIME_H
|
|
Loading…
Reference in new issue