Adding upstream version 1.3.1~50-g4fde773.
This commit is contained in:
parent
9e92aa7936
commit
7aa602d177
7
AUTHORS
7
AUTHORS
@ -4,7 +4,8 @@ Upstream Authors:
|
||||
|
||||
Copyright:
|
||||
Copyright (c) 2010-2012 Razor team
|
||||
Copyright (c) 2012-2014 LXQt team
|
||||
Copyright (c) 2012-2016 LXQt team
|
||||
|
||||
License: GPL-2 and LGPL-2.1+
|
||||
The full text of the licenses can be found in the 'COPYING' file.
|
||||
License: LGPL-2.1+ and LGPL-2.1-or-3-with-Digia-1.1-exception
|
||||
The full text of the LGPL-2.1+ license can be found in the 'COPYING' file.
|
||||
The Digia-1.1 exception can be found in the 'Digia-Qt-LGPL-Exception-1.1' file.
|
||||
|
301
CMakeLists.txt
301
CMakeLists.txt
@ -2,10 +2,29 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
|
||||
project(libqtxdg)
|
||||
|
||||
option(BUILD_TESTS "Builds tests" OFF)
|
||||
option(BUILD_DEV_UTILS "Builds and install development utils" OFF)
|
||||
|
||||
# additional cmake files
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
if(COMPILER_SUPPORTS_CXX11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
else()
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||
# -std=c++0x is deprecated but some tools e.g. qmake or older gcc are still using it
|
||||
if(COMPILER_SUPPORTS_CXX0X)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
else()
|
||||
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} does not support c++11/c++0x")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
endif()
|
||||
|
||||
set(QTXDG_MAJOR_VERSION 1)
|
||||
set(QTXDG_MINOR_VERSION 3)
|
||||
set(QTXDG_PATCH_VERSION 0)
|
||||
@ -13,6 +32,7 @@ set(QTXDG_VERSION_STRING ${QTXDG_MAJOR_VERSION}.${QTXDG_MINOR_VERSION}.${QTXDG_P
|
||||
|
||||
include(GNUInstallDirs) # Standard directories for installation
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GenerateExportHeader)
|
||||
include(create_portable_headers)
|
||||
include(create_pkgconfig_file)
|
||||
include(compiler_settings NO_POLICY_SCOPE)
|
||||
@ -20,6 +40,7 @@ include(compiler_settings NO_POLICY_SCOPE)
|
||||
find_package(Qt5Widgets REQUIRED QUIET)
|
||||
find_package(Qt5Xml REQUIRED QUIET)
|
||||
find_package(Qt5DBus REQUIRED QUIET)
|
||||
|
||||
if (BUILD_TESTS)
|
||||
find_package(Qt5Test REQUIRED QUIET)
|
||||
endif()
|
||||
@ -28,206 +49,25 @@ endif()
|
||||
set(QTXDGX_LIBRARY_NAME "Qt5Xdg")
|
||||
set(QTXDGX_FILE_NAME "qt5xdg")
|
||||
|
||||
set(QTXDGX_ICONLOADER_LIBRARY_NAME "Qt5XdgIconLoader")
|
||||
set(QTXDGX_ICONLOADER_FILE_NAME "qt5xdgiconloader")
|
||||
|
||||
set(QTXDGX_PKG_CONFIG_DESCRIPTION "Qt5Xdg, a Qt5 implementation of XDG standards")
|
||||
set(QTXDGX_PKG_CONFIG_REQUIRES "Qt5Core, Qt5Xml, Qt5Widgets, Qt5DBus")
|
||||
set(QTXDGX_PKG_CONFIG_REQUIRES "Qt5Core, Qt5Xml, Qt5Widgets, Qt5DBus, Qt5XdgIconLoader")
|
||||
|
||||
set(QTXDGX_ICONLOADER_PKG_CONFIG_DESCRIPTION "Qt5XdgIconLader, a Qt5 XDG Icon Loader")
|
||||
set(QTXDGX_ICONLOADER_PKG_CONFIG_REQUIRES "Qt5Gui")
|
||||
|
||||
set(QTXDGX_INTREE_INCLUDEDIR "${CMAKE_CURRENT_BINARY_DIR}/InTreeBuild/include")
|
||||
|
||||
include_directories(
|
||||
"${Qt5Gui_PRIVATE_INCLUDE_DIRS}"
|
||||
)
|
||||
|
||||
set(QTX_LIBRARIES Qt5::Widgets Qt5::Xml Qt5::DBus)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set ( CMAKE_BUILD_TYPE Release )
|
||||
endif (NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
message(STATUS "Building with Qt ${Qt5Core_VERSION_STRING}")
|
||||
|
||||
set(libqtxdg_PUBLIC_H_FILES
|
||||
xdgaction.h
|
||||
xdgdesktopfile.h
|
||||
xdgdirs.h
|
||||
xdgicon.h
|
||||
xdgmenu.h
|
||||
xdgmenuwidget.h
|
||||
xmlhelper.h
|
||||
xdgautostart.h
|
||||
xdgmacros.h
|
||||
xdgmimetype.h
|
||||
)
|
||||
|
||||
set(libqtxdg_PUBLIC_CLASSES
|
||||
XdgAction
|
||||
XdgDesktopFile
|
||||
XdgDirs
|
||||
XdgIcon
|
||||
XdgMenu
|
||||
XdgMenuWidget
|
||||
XmlHelper
|
||||
XdgAutoStart
|
||||
XdgMimeType
|
||||
)
|
||||
|
||||
set(libqtxdg_PRIVATE_H_FILES
|
||||
xdgmenuapplinkprocessor.h
|
||||
xdgmenulayoutprocessor.h
|
||||
xdgmenu_p.h
|
||||
xdgmenureader.h
|
||||
xdgmenurules.h
|
||||
xdgdesktopfile_p.h
|
||||
)
|
||||
|
||||
set(libqtxdg_CPP_FILES
|
||||
xdgaction.cpp
|
||||
xdgdesktopfile.cpp
|
||||
xdgdirs.cpp
|
||||
xdgicon.cpp
|
||||
xdgmenuapplinkprocessor.cpp
|
||||
xdgmenu.cpp
|
||||
xdgmenulayoutprocessor.cpp
|
||||
xdgmenureader.cpp
|
||||
xdgmenurules.cpp
|
||||
xdgmenuwidget.cpp
|
||||
xmlhelper.cpp
|
||||
xdgautostart.cpp
|
||||
xdgmimetype.cpp
|
||||
qiconfix/qiconloader.cpp
|
||||
)
|
||||
|
||||
set(libqtxdg_MOCS
|
||||
xdgaction.h
|
||||
xdgmenuapplinkprocessor.h
|
||||
xdgmenu.h
|
||||
xdgmenu_p.h
|
||||
xdgmenureader.h
|
||||
xdgmenurules.h
|
||||
xdgmenuwidget.h
|
||||
)
|
||||
|
||||
set(libqtxdg_PRIVATE_INSTALLABLE_H_FILES
|
||||
qiconfix/qiconloader_p.h
|
||||
)
|
||||
|
||||
QT5_WRAP_CPP(libqtxdg_CXX_FILES ${libqtxdg_MOCS})
|
||||
|
||||
add_library(${QTXDGX_LIBRARY_NAME} SHARED
|
||||
${libqtxdg_PUBLIC_H_FILES}
|
||||
${libqtxdg_PRIVATE_H_FILES}
|
||||
${libqtxdg_PRIVATE_INSTALLABLE_H_FILES}
|
||||
${libqtxdg_PRIVATE_H_FILES}
|
||||
${libqtxdg_CPP_FILES}
|
||||
${libqtxdg_CXX_FILES}
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(${QTXDGX_LIBRARY_NAME}
|
||||
PUBLIC
|
||||
${QTX_LIBRARIES}
|
||||
)
|
||||
|
||||
set_target_properties(${QTXDGX_LIBRARY_NAME} PROPERTIES
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
SOVERSION ${QTXDG_MAJOR_VERSION}
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${QTXDGX_FILE_NAME}-config.cmake.in"
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config.cmake"
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME}"
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config-version.cmake"
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
create_pkgconfig_file(
|
||||
PACKAGE_NAME ${QTXDGX_LIBRARY_NAME}
|
||||
DESCRIPTIVE_NAME ${QTXDGX_LIBRARY_NAME}
|
||||
DESCRIPTION ${QTXDGX_PKG_CONFIG_DESCRIPTION}
|
||||
INCLUDEDIRS ${QTXDGX_FILE_NAME}
|
||||
LIBS ${QTXDGX_LIBRARY_NAME}
|
||||
REQUIRES ${QTXDGX_PKG_CONFIG_REQUIRES}
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
INSTALL
|
||||
)
|
||||
|
||||
target_compile_definitions(${QTXDGX_LIBRARY_NAME}
|
||||
PRIVATE "QTXDG_COMPILATION=\"1\""
|
||||
)
|
||||
|
||||
target_include_directories(${QTXDGX_LIBRARY_NAME}
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}>"
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${QTXDG_VERSION_STRING}>"
|
||||
)
|
||||
|
||||
# include directories and targets for the in tree build
|
||||
target_include_directories(${QTXDGX_LIBRARY_NAME}
|
||||
INTERFACE "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}>"
|
||||
INTERFACE "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}>"
|
||||
INTERFACE "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${QTXDG_VERSION_STRING}>"
|
||||
)
|
||||
|
||||
export(TARGETS ${QTXDGX_LIBRARY_NAME} FILE "${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-targets.cmake")
|
||||
# end of in tree build stuff
|
||||
|
||||
# create the portble headers
|
||||
create_portable_headers(libqtxdg_PORTABLE_HEADERS
|
||||
HEADER_NAMES ${libqtxdg_PUBLIC_CLASSES}
|
||||
OUTPUT_DIR "${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}"
|
||||
)
|
||||
|
||||
# Copy public headers (in tree building)
|
||||
foreach(h ${libqtxdg_PUBLIC_H_FILES})
|
||||
get_filename_component(bh ${h} NAME)
|
||||
configure_file(${h} "${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${bh}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
# Copy private headers (in tree building)
|
||||
foreach(h ${libqtxdg_PRIVATE_INSTALLABLE_H_FILES})
|
||||
get_filename_component(bh ${h} NAME)
|
||||
configure_file(${h} "${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${QTXDG_VERSION_STRING}/private/qtxdg/${bh}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
install(TARGETS
|
||||
${QTXDGX_LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
EXPORT "${QTXDGX_FILE_NAME}-targets"
|
||||
COMPONENT Runtime
|
||||
)
|
||||
|
||||
install(EXPORT
|
||||
"${QTXDGX_FILE_NAME}-targets"
|
||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${libqtxdg_PUBLIC_H_FILES}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${libqtxdg_PRIVATE_INSTALLABLE_H_FILES}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${QTXDG_VERSION_STRING}/private/qtxdg"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config.cmake"
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config-version.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${libqtxdg_PORTABLE_HEADERS}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
||||
add_subdirectory(xdgiconloader)
|
||||
add_subdirectory(qtxdg)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
@ -241,6 +81,85 @@ else()
|
||||
message(STATUS "")
|
||||
endif()
|
||||
|
||||
if (BUILD_DEV_UTILS)
|
||||
add_subdirectory(util)
|
||||
endif()
|
||||
|
||||
configure_package_config_file(
|
||||
"${PROJECT_SOURCE_DIR}/cmake/${QTXDGX_FILE_NAME}-config.cmake.in"
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config.cmake"
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME}"
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config-version.cmake"
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
"${PROJECT_SOURCE_DIR}/cmake/${QTXDGX_ICONLOADER_FILE_NAME}-config.cmake.in"
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_ICONLOADER_FILE_NAME}-config.cmake"
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_ICONLOADER_FILE_NAME}"
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_ICONLOADER_FILE_NAME}-config-version.cmake"
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
create_pkgconfig_file(
|
||||
PACKAGE_NAME ${QTXDGX_LIBRARY_NAME}
|
||||
DESCRIPTIVE_NAME ${QTXDGX_LIBRARY_NAME}
|
||||
DESCRIPTION ${QTXDGX_PKG_CONFIG_DESCRIPTION}
|
||||
INCLUDEDIRS ${QTXDGX_FILE_NAME}
|
||||
LIBS ${QTXDGX_LIBRARY_NAME}
|
||||
REQUIRES ${QTXDGX_PKG_CONFIG_REQUIRES}
|
||||
REQUIRES_PRIVATE ${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
INSTALL
|
||||
)
|
||||
|
||||
create_pkgconfig_file(
|
||||
PACKAGE_NAME ${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
DESCRIPTIVE_NAME ${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
DESCRIPTION ${QTXDGX_ICONLOADER_PKG_CONFIG_DESCRIPTION}
|
||||
INCLUDEDIRS ${QTXDGX_ICONLOADER_FILE_NAME}
|
||||
LIBS ${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
REQUIRES ${QTXDGX_ICONLOADER_PKG_CONFIG_REQUIRES}
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
INSTALL
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config.cmake"
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-config-version.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_ICONLOADER_FILE_NAME}-config.cmake"
|
||||
"${CMAKE_BINARY_DIR}/${QTXDGX_ICONLOADER_FILE_NAME}-config-version.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_ICONLOADER_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(EXPORT
|
||||
"${QTXDGX_FILE_NAME}-targets"
|
||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_FILE_NAME}"
|
||||
FILE "${QTXDGX_FILE_NAME}-targets.cmake"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(EXPORT
|
||||
"${QTXDGX_ICONLOADER_FILE_NAME}-targets"
|
||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${QTXDGX_ICONLOADER_FILE_NAME}"
|
||||
FILE "${QTXDGX_ICONLOADER_FILE_NAME}-targets.cmake"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
# uninstall target
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
||||
|
22
Digia-Qt-LGPL-Exception-1.1
Normal file
22
Digia-Qt-LGPL-Exception-1.1
Normal file
@ -0,0 +1,22 @@
|
||||
Digia Qt LGPL Exception version 1.1
|
||||
|
||||
As an additional permission to the GNU Lesser General Public License version
|
||||
2.1, the object code form of a "work that uses the Library" may incorporate
|
||||
material from a header file that is part of the Library. You may distribute
|
||||
such object code under terms of your choice, provided that:
|
||||
(i) the header files of the Library have not been modified; and
|
||||
(ii) the incorporated material is limited to numerical parameters, data
|
||||
structure layouts, accessors, macros, inline functions and
|
||||
templates; and
|
||||
(iii) you comply with the terms of Section 6 of the GNU Lesser General
|
||||
Public License version 2.1.
|
||||
|
||||
Moreover, you may apply this exception to a modified version of the Library,
|
||||
provided that such modification does not involve copying material from the
|
||||
Library into the modified Library's header files unless such material is
|
||||
limited to (i) numerical parameters; (ii) data structure layouts;
|
||||
(iii) accessors; and (iv) small macros, templates and inline functions of
|
||||
five lines or less in length.
|
||||
|
||||
Furthermore, you are not required to apply this additional permission to a
|
||||
modified version of the Library.
|
25
README
25
README
@ -1,25 +0,0 @@
|
||||
Overview
|
||||
========
|
||||
libqtxdg is An Qt implementation of freedesktop.org xdg specifications.
|
||||
It's built with Qt5.
|
||||
|
||||
|
||||
Dependencies
|
||||
============
|
||||
Qt5
|
||||
|
||||
|
||||
Configuration
|
||||
============
|
||||
libqtxdg uses the CMake build system. Everything that applies to CMake also
|
||||
applies here.
|
||||
|
||||
Configuration options:
|
||||
BUILD_TESTS Builds tests, defaults to OFF
|
||||
|
||||
Configuration Examples:
|
||||
Build library and build self tests:
|
||||
cmake -DBUILD_TESTS=ON ..
|
||||
|
||||
Build the library without building self tests
|
||||
cmake ..
|
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
||||
##Overview
|
||||
|
||||
```libqtxdg``` is a Qt implementation of freedesktop.org XDG specifications which is built with Qt5.
|
||||
|
||||
##Dependencies
|
||||
|
||||
- Qt5
|
||||
|
||||
##Configuration
|
||||
|
||||
```libqtxdg``` uses the CMake build system. Everything that applies to CMake also
|
||||
applies here.
|
||||
|
||||
###Configuration options:
|
||||
BUILD_TESTS Builds tests, defaults to OFF
|
||||
BUILD_DEV_UTILS Builds and install development utils, defaults to OFF
|
||||
|
||||
###Configuration Examples:
|
||||
Build library and build self tests: ```cmake -DBUILD_TESTS=ON ..```
|
||||
|
||||
Build the library without building self tests : ```cmake ..```
|
@ -92,3 +92,14 @@ set(QTXDG_COMMON_WARNING_FLAGS "-Wall")
|
||||
#-----------------------------------------------------------------------------
|
||||
list(APPEND QTXDG_WARNING_FLAGS ${QTXDG_COMMON_WARNING_FLAGS})
|
||||
add_definitions(${QTXDG_WARNING_FLAGS})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# String conversion flags
|
||||
#-----------------------------------------------------------------------------
|
||||
add_definitions(
|
||||
-DQT_USE_QSTRINGBUILDER
|
||||
-DQT_NO_CAST_FROM_ASCII
|
||||
-DQT_NO_CAST_TO_ASCII
|
||||
-DQT_NO_URL_CAST_FROM_STRING
|
||||
-DQT_NO_CAST_FROM_BYTEARRAY
|
||||
)
|
||||
|
@ -5,6 +5,7 @@ include(CMakeFindDependencyMacro)
|
||||
find_dependency(Qt5Widgets)
|
||||
find_dependency(Qt5Xml)
|
||||
find_dependency(Qt5DBus)
|
||||
find_dependency(Qt5XdgIconLoader)
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER 2.8.12)
|
||||
cmake_policy(SET CMP0024 OLD)
|
||||
|
10
cmake/qt5xdgiconloader-config.cmake.in
Normal file
10
cmake/qt5xdgiconloader-config.cmake.in
Normal file
@ -0,0 +1,10 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
find_dependency(Qt5Gui)
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER 2.8.12)
|
||||
cmake_policy(SET CMP0024 OLD)
|
||||
endif()
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/qt5xdgiconloader-targets.cmake")
|
146
qtxdg/CMakeLists.txt
Normal file
146
qtxdg/CMakeLists.txt
Normal file
@ -0,0 +1,146 @@
|
||||
set(QTX_LIBRARIES Qt5::Widgets Qt5::Xml Qt5::DBus)
|
||||
|
||||
include_directories(
|
||||
"${Qt5Gui_PRIVATE_INCLUDE_DIRS}"
|
||||
)
|
||||
set(libqtxdg_PUBLIC_H_FILES
|
||||
xdgaction.h
|
||||
xdgdesktopfile.h
|
||||
xdgdirs.h
|
||||
xdgicon.h
|
||||
xdgmenu.h
|
||||
xdgmenuwidget.h
|
||||
xmlhelper.h
|
||||
xdgautostart.h
|
||||
xdgmacros.h
|
||||
xdgmimetype.h
|
||||
)
|
||||
|
||||
set(libqtxdg_PUBLIC_CLASSES
|
||||
XdgAction
|
||||
XdgDesktopFile
|
||||
XdgDirs
|
||||
XdgIcon
|
||||
XdgMenu
|
||||
XdgMenuWidget
|
||||
XmlHelper
|
||||
XdgAutoStart
|
||||
XdgMimeType
|
||||
)
|
||||
|
||||
set(libqtxdg_PRIVATE_H_FILES
|
||||
xdgmenuapplinkprocessor.h
|
||||
xdgmenulayoutprocessor.h
|
||||
xdgmenu_p.h
|
||||
xdgmenureader.h
|
||||
xdgmenurules.h
|
||||
xdgdesktopfile_p.h
|
||||
)
|
||||
|
||||
set(libqtxdg_CPP_FILES
|
||||
xdgaction.cpp
|
||||
xdgdesktopfile.cpp
|
||||
xdgdirs.cpp
|
||||
xdgicon.cpp
|
||||
xdgmenuapplinkprocessor.cpp
|
||||
xdgmenu.cpp
|
||||
xdgmenulayoutprocessor.cpp
|
||||
xdgmenureader.cpp
|
||||
xdgmenurules.cpp
|
||||
xdgmenuwidget.cpp
|
||||
xmlhelper.cpp
|
||||
xdgautostart.cpp
|
||||
xdgmimetype.cpp
|
||||
)
|
||||
|
||||
set(libqtxdg_MOCS
|
||||
xdgaction.h
|
||||
xdgmenuapplinkprocessor.h
|
||||
xdgmenu.h
|
||||
xdgmenu_p.h
|
||||
xdgmenureader.h
|
||||
xdgmenurules.h
|
||||
xdgmenuwidget.h
|
||||
)
|
||||
|
||||
QT5_WRAP_CPP(libqtxdg_CXX_FILES ${libqtxdg_MOCS})
|
||||
|
||||
add_library(${QTXDGX_LIBRARY_NAME} SHARED
|
||||
${libqtxdg_PUBLIC_H_FILES}
|
||||
${libqtxdg_PRIVATE_H_FILES}
|
||||
${libqtxdg_PRIVATE_H_FILES}
|
||||
${libqtxdg_CPP_FILES}
|
||||
${libqtxdg_CXX_FILES}
|
||||
)
|
||||
|
||||
target_link_libraries(${QTXDGX_LIBRARY_NAME}
|
||||
PUBLIC
|
||||
${QTX_LIBRARIES}
|
||||
${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
)
|
||||
|
||||
set_target_properties(${QTXDGX_LIBRARY_NAME} PROPERTIES
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
SOVERSION ${QTXDG_MAJOR_VERSION}
|
||||
)
|
||||
|
||||
target_compile_definitions(${QTXDGX_LIBRARY_NAME}
|
||||
PRIVATE "QTXDG_COMPILATION=\"1\""
|
||||
PRIVATE "QTXDG_VERSION=\"${QTXDG_VERSION_STRING}\""
|
||||
)
|
||||
|
||||
target_include_directories(${QTXDGX_LIBRARY_NAME}
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}>"
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
|
||||
# include directories and targets for the in tree build
|
||||
target_include_directories(${QTXDGX_LIBRARY_NAME}
|
||||
INTERFACE "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}>"
|
||||
INTERFACE "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}>"
|
||||
)
|
||||
|
||||
export(TARGETS ${QTXDGX_LIBRARY_NAME} APPEND FILE "${CMAKE_BINARY_DIR}/${QTXDGX_FILE_NAME}-targets.cmake")
|
||||
# end of in tree build stuff
|
||||
|
||||
# create the portble headers
|
||||
create_portable_headers(libqtxdg_PORTABLE_HEADERS
|
||||
HEADER_NAMES ${libqtxdg_PUBLIC_CLASSES}
|
||||
OUTPUT_DIR "${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}"
|
||||
)
|
||||
|
||||
# Copy public headers (in tree building)
|
||||
foreach(h ${libqtxdg_PUBLIC_H_FILES})
|
||||
get_filename_component(bh ${h} NAME)
|
||||
configure_file(${h} "${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${bh}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
# Copy private headers (in tree building)
|
||||
foreach(h ${libqtxdg_PRIVATE_INSTALLABLE_H_FILES})
|
||||
get_filename_component(bh ${h} NAME)
|
||||
configure_file(${h} "${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${QTXDG_VERSION_STRING}/private/qtxdg/${bh}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
install(TARGETS
|
||||
${QTXDGX_LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
EXPORT "${QTXDGX_FILE_NAME}-targets"
|
||||
COMPONENT Runtime
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${libqtxdg_PUBLIC_H_FILES}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${libqtxdg_PRIVATE_INSTALLABLE_H_FILES}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}/${QTXDG_VERSION_STRING}/private/qtxdg"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${libqtxdg_PORTABLE_HEADERS}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_FILE_NAME}"
|
||||
COMPONENT Devel
|
||||
)
|
@ -91,7 +91,7 @@ void XdgAction::load(const XdgDesktopFile& desktopFile)
|
||||
if (mDesktopFile.isValid())
|
||||
{
|
||||
// & is reserved for mnemonics
|
||||
setText(mDesktopFile.name().replace('&', QLatin1String("&&")));
|
||||
setText(mDesktopFile.name().replace(QLatin1Char('&'), QLatin1String("&&")));
|
||||
setToolTip(mDesktopFile.comment());
|
||||
|
||||
connect(this, SIGNAL(triggered()), this, SLOT(runConmmand()));
|
||||
@ -117,6 +117,6 @@ void XdgAction::updateIcon()
|
||||
{
|
||||
setIcon(mDesktopFile.icon());
|
||||
if (icon().isNull())
|
||||
setIcon(XdgIcon::fromTheme("application-x-executable"));
|
||||
setIcon(XdgIcon::fromTheme(QLatin1String("application-x-executable")));
|
||||
QCoreApplication::processEvents();
|
||||
}
|
@ -57,14 +57,14 @@ XdgDesktopFileList XdgAutoStart::desktopFileList(QStringList dirs, bool excludeH
|
||||
|
||||
QSet<QString> processed;
|
||||
XdgDesktopFileList ret;
|
||||
foreach (QString dirName, dirs)
|
||||
foreach (const QString &dirName, dirs)
|
||||
{
|
||||
QDir dir(dirName);
|
||||
if (!dir.exists())
|
||||
continue;
|
||||
|
||||
QFileInfoList files = dir.entryInfoList(QStringList("*.desktop"), QDir::Files | QDir::Readable);
|
||||
foreach (QFileInfo fi, files)
|
||||
const QFileInfoList files = dir.entryInfoList(QStringList(QLatin1String("*.desktop")), QDir::Files | QDir::Readable);
|
||||
foreach (const QFileInfo &fi, files)
|
||||
{
|
||||
if (processed.contains(fi.fileName()))
|
||||
continue;
|
||||
@ -88,5 +88,5 @@ XdgDesktopFileList XdgAutoStart::desktopFileList(QStringList dirs, bool excludeH
|
||||
QString XdgAutoStart::localPath(const XdgDesktopFile& file)
|
||||
{
|
||||
QFileInfo fi(file.fileName());
|
||||
return QString("%1/%2").arg(XdgDirs::autostartHome(), fi.fileName());
|
||||
return QString::fromLatin1("%1/%2").arg(XdgDirs::autostartHome(), fi.fileName());
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -79,7 +79,7 @@ public:
|
||||
- ApplicationType, "value" should be the Exec value;
|
||||
- LinkType, "value" should be the URL;
|
||||
- DirectoryType, "value" should be omitted */
|
||||
XdgDesktopFile(XdgDesktopFile::Type type, const QString& name, const QString& value = 0);
|
||||
XdgDesktopFile(XdgDesktopFile::Type type, const QString& name, const QString& value = QString());
|
||||
|
||||
//! Destroys the object.
|
||||
virtual ~XdgDesktopFile();
|
||||
@ -146,11 +146,18 @@ public:
|
||||
//! Returns an icon name specified in this file.
|
||||
QString const iconName() const;
|
||||
|
||||
//! Returns an list of mimetypes specified in this file.
|
||||
/*! @return Returns a list of the "MimeType=" entries.
|
||||
* If the file doens't contain the MimeType entry, an empty QStringList is
|
||||
* returned. Empty values are removed from the returned list.
|
||||
*/
|
||||
QStringList mimeTypes() const;
|
||||
|
||||
//! This function is provided for convenience. It's equivalent to calling localizedValue("Name").toString().
|
||||
QString name() const { return localizedValue("Name").toString(); }
|
||||
QString name() const { return localizedValue(QLatin1String("Name")).toString(); }
|
||||
|
||||
//! This function is provided for convenience. It's equivalent to calling localizedValue("Comment").toString().
|
||||
QString comment() const { return localizedValue("Comment").toString(); }
|
||||
QString comment() const { return localizedValue(QLatin1String("Comment")).toString(); }
|
||||
|
||||
/*! Returns the desktop file type.
|
||||
@see XdgDesktopFile::Type */
|
||||
@ -177,9 +184,16 @@ public:
|
||||
/*! Returns the URL for the Link desktop file; otherwise an empty string is returned. */
|
||||
QString url() const;
|
||||
|
||||
/*! The desktop entry specification defines a number of fields to control the visibility of the application menu. This function
|
||||
checks whether to display a this application or not. */
|
||||
QTXDG_DEPRECATED bool isShow(const QString& environment = "Razor") const;
|
||||
/*! Computes the desktop file ID. It is the identifier of an installed
|
||||
* desktop entry file.
|
||||
* @par fileName - The desktop file complete name.
|
||||
* @par checkFileExists If true and the file doesn't exist the computed ID
|
||||
* will be an empty QString(). Defaults to true.
|
||||
* @return The computed ID. Returns an empty QString() if it's impossible to
|
||||
* compute the ID. Reference:
|
||||
* https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id
|
||||
*/
|
||||
static QString id(const QString &fileName, bool checkFileExists = true);
|
||||
|
||||
/*! The desktop entry specification defines a number of fields to control
|
||||
the visibility of the application menu. Thisfunction checks whether
|
||||
@ -192,12 +206,6 @@ public:
|
||||
*/
|
||||
bool isShown(const QString &environment = QString()) const;
|
||||
|
||||
/*! This fuction returns true if the desktop file is applicable to the current environment.
|
||||
@par excludeHidden - if set to true (default), files with "Hidden=true" will be considered "not applicable".
|
||||
Setting this to false is be useful when the user wants to enable/disable items and wants to see those
|
||||
that are Hidden */
|
||||
QTXDG_DEPRECATED bool isApplicable(bool excludeHidden = true, const QString& environment = "Razor") const;
|
||||
|
||||
/*! This fuction returns true if the desktop file is applicable to the
|
||||
current environment.
|
||||
@par excludeHidden - if set to true (default), files with
|
||||
@ -213,7 +221,7 @@ public:
|
||||
bool isSuitable(bool excludeHidden = true, const QString &environment = QString()) const;
|
||||
|
||||
protected:
|
||||
virtual QString prefix() const { return "Desktop Entry"; }
|
||||
virtual QString prefix() const { return QLatin1String("Desktop Entry"); }
|
||||
virtual bool check() const { return true; }
|
||||
private:
|
||||
/*! Returns the localized version of the key if the Desktop File already contains a localized version of it.
|
||||
@ -261,5 +269,3 @@ private:
|
||||
|
||||
|
||||
#endif // QTXDG_XDGDESKTOPFILE_H
|
||||
|
||||
|
@ -28,21 +28,20 @@
|
||||
#include "xdgdirs.h"
|
||||
#include <stdlib.h>
|
||||
#include <QDir>
|
||||
#include <QStringBuilder> // for the % operator
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
|
||||
|
||||
static const QString userDirectoryString[8] =
|
||||
{
|
||||
"Desktop",
|
||||
"Download",
|
||||
"Templates",
|
||||
"Publicshare",
|
||||
"Documents",
|
||||
"Music",
|
||||
"Pictures",
|
||||
"Videos"
|
||||
QLatin1String("Desktop"),
|
||||
QLatin1String("Download"),
|
||||
QLatin1String("Templates"),
|
||||
QLatin1String("Publicshare"),
|
||||
QLatin1String("Documents"),
|
||||
QLatin1String("Music"),
|
||||
QLatin1String("Pictures"),
|
||||
QLatin1String("Videos")
|
||||
};
|
||||
|
||||
// Helper functions prototypes
|
||||
@ -51,7 +50,7 @@ void removeEndingSlash(QString &s);
|
||||
QString createDirectory(const QString &dir);
|
||||
|
||||
void cleanAndAddPostfix(QStringList &dirs, const QString& postfix);
|
||||
|
||||
QString userDirFallback(XdgDirs::UserDirectory dir);
|
||||
|
||||
/************************************************
|
||||
Helper func.
|
||||
@ -59,7 +58,7 @@ void cleanAndAddPostfix(QStringList &dirs, const QString& postfix);
|
||||
void fixBashShortcuts(QString &s)
|
||||
{
|
||||
if (s.startsWith(QLatin1Char('~')))
|
||||
s = QString(getenv("HOME")) + (s).mid(1);
|
||||
s = QFile::decodeName(qgetenv("HOME")) + (s).mid(1);
|
||||
}
|
||||
|
||||
|
||||
@ -78,9 +77,9 @@ QString createDirectory(const QString &dir)
|
||||
QDir d(dir);
|
||||
if (!d.exists())
|
||||
{
|
||||
if (!d.mkpath("."))
|
||||
if (!d.mkpath(QLatin1String(".")))
|
||||
{
|
||||
qWarning() << QString("Can't create %1 directory.").arg(d.absolutePath());
|
||||
qWarning() << QString::fromLatin1("Can't create %1 directory.").arg(d.absolutePath());
|
||||
}
|
||||
}
|
||||
QString r = d.absolutePath();
|
||||
@ -101,31 +100,53 @@ void cleanAndAddPostfix(QStringList &dirs, const QString& postfix)
|
||||
}
|
||||
|
||||
|
||||
QString userDirFallback(XdgDirs::UserDirectory dir)
|
||||
{
|
||||
QString fallback;
|
||||
const QString home = QFile::decodeName(qgetenv("HOME"));
|
||||
|
||||
if (home.isEmpty())
|
||||
return QString::fromLatin1("/tmp");
|
||||
else if (dir == XdgDirs::Desktop)
|
||||
fallback = QString::fromLatin1("%1/%2").arg(home).arg(QLatin1String("Desktop"));
|
||||
else
|
||||
fallback = home;
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
|
||||
QString XdgDirs::userDirDefault(XdgDirs::UserDirectory dir)
|
||||
{
|
||||
// possible values for UserDirectory
|
||||
Q_ASSERT(!(dir < XdgDirs::Desktop || dir > XdgDirs::Videos));
|
||||
if (dir < XdgDirs::Desktop || dir > XdgDirs::Videos)
|
||||
return QString();
|
||||
|
||||
return userDirFallback(dir);
|
||||
}
|
||||
|
||||
|
||||
QString XdgDirs::userDir(XdgDirs::UserDirectory dir)
|
||||
{
|
||||
// possible values for UserDirectory
|
||||
if (dir < 0 || dir > 7)
|
||||
Q_ASSERT(!(dir < XdgDirs::Desktop || dir > XdgDirs::Videos));
|
||||
if (dir < XdgDirs::Desktop || dir > XdgDirs::Videos)
|
||||
return QString();
|
||||
|
||||
QString folderName = userDirectoryString[dir];
|
||||
|
||||
QString fallback;
|
||||
if (getenv("HOME") == NULL)
|
||||
return QString("/tmp");
|
||||
else if (dir == XdgDirs::Desktop)
|
||||
fallback = QString("%1/%2").arg(getenv("HOME")).arg("Desktop");
|
||||
else
|
||||
fallback = QString(getenv("HOME"));
|
||||
const QString fallback = userDirFallback(dir);
|
||||
|
||||
QString configDir(configHome());
|
||||
QFile configFile(configDir + "/user-dirs.dirs");
|
||||
QFile configFile(configDir + QLatin1String("/user-dirs.dirs"));
|
||||
if (!configFile.exists())
|
||||
return fallback;
|
||||
|
||||
if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return fallback;
|
||||
|
||||
QString userDirVar("XDG_" + folderName.toUpper() + "_DIR");
|
||||
QString userDirVar(QLatin1String("XDG_") + folderName.toUpper() + QLatin1String("_DIR"));
|
||||
QTextStream in(&configFile);
|
||||
QString line;
|
||||
while (!in.atEnd())
|
||||
@ -137,6 +158,8 @@ QString XdgDirs::userDir(XdgDirs::UserDirectory dir)
|
||||
|
||||
// get path between quotes
|
||||
line = line.section(QLatin1Char('"'), 1, 1);
|
||||
if (line.isEmpty())
|
||||
return fallback;
|
||||
line.replace(QLatin1String("$HOME"), QLatin1String("~"));
|
||||
fixBashShortcuts(line);
|
||||
return line;
|
||||
@ -151,18 +174,19 @@ QString XdgDirs::userDir(XdgDirs::UserDirectory dir)
|
||||
bool XdgDirs::setUserDir(XdgDirs::UserDirectory dir, const QString& value, bool createDir)
|
||||
{
|
||||
// possible values for UserDirectory
|
||||
if (dir < 0 || dir > 7)
|
||||
Q_ASSERT(!(dir < XdgDirs::Desktop || dir > XdgDirs::Videos));
|
||||
if (dir < XdgDirs::Desktop || dir > XdgDirs::Videos)
|
||||
return false;
|
||||
|
||||
if (!(value.startsWith(QLatin1String("$HOME"))
|
||||
|| value.startsWith(QLatin1String("~/"))
|
||||
|| value.startsWith(QString(getenv("HOME")))))
|
||||
|| value.startsWith(QFile::decodeName(qgetenv("HOME")))))
|
||||
return false;
|
||||
|
||||
QString folderName = userDirectoryString[dir];
|
||||
|
||||
QString configDir(configHome());
|
||||
QFile configFile(configDir % QLatin1String("/user-dirs.dirs"));
|
||||
QFile configFile(configDir + QLatin1String("/user-dirs.dirs"));
|
||||
|
||||
// create the file if doesn't exist and opens it
|
||||
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text))
|
||||
@ -191,10 +215,10 @@ bool XdgDirs::setUserDir(XdgDirs::UserDirectory dir, const QString& value, bool
|
||||
stream.reset();
|
||||
configFile.resize(0);
|
||||
if (!foundVar)
|
||||
stream << QString("XDG_%1_DIR=\"%2\"\n").arg(folderName.toUpper()).arg(value);
|
||||
stream << QString::fromLatin1("XDG_%1_DIR=\"%2\"\n").arg(folderName.toUpper()).arg(value);
|
||||
|
||||
for (QVector<QString>::iterator i = lines.begin(); i != lines.end(); ++i)
|
||||
stream << *i << "\n";
|
||||
stream << *i << QLatin1Char('\n');
|
||||
|
||||
configFile.close();
|
||||
|
||||
@ -293,7 +317,7 @@ QString XdgDirs::runtimeDir()
|
||||
|
||||
QString XdgDirs::autostartHome(bool createDir)
|
||||
{
|
||||
QString s = QString("%1/autostart").arg(configHome(createDir));
|
||||
QString s = QString::fromLatin1("%1/autostart").arg(configHome(createDir));
|
||||
fixBashShortcuts(s);
|
||||
|
||||
if (createDir)
|
||||
@ -309,9 +333,9 @@ QString XdgDirs::autostartHome(bool createDir)
|
||||
QStringList XdgDirs::autostartDirs(const QString &postfix)
|
||||
{
|
||||
QStringList dirs;
|
||||
QStringList s = configDirs();
|
||||
foreach(QString dir, s)
|
||||
dirs << QString("%1/autostart").arg(dir) + postfix;
|
||||
const QStringList s = configDirs();
|
||||
foreach(const QString &dir, s)
|
||||
dirs << QString::fromLatin1("%1/autostart").arg(dir) + postfix;
|
||||
|
||||
return dirs;
|
||||
}
|
@ -62,6 +62,14 @@ public:
|
||||
*/
|
||||
static QString userDir(UserDirectory dir);
|
||||
|
||||
|
||||
/*! @brief Returns the default path to the user specified directory.
|
||||
* Returns /tmp if no $HOME defined, $HOME/Desktop if dir equals
|
||||
* XdgDirs::Desktop or $HOME othewise. If dir value is invalid, an empty
|
||||
* QString is returned.
|
||||
*/
|
||||
static QString userDirDefault(UserDirectory dir);
|
||||
|
||||
/*! @brief Returns true if writting into configuration file $XDG_CONFIG_HOME/user-dirs.dirs
|
||||
* the path in value for the directory in dir is succesfull. Returns false otherwise. If
|
||||
* createDir is true, dir will be created if it doesn't exist.
|
@ -33,10 +33,10 @@
|
||||
#include <QStringList>
|
||||
#include <QFileInfo>
|
||||
#include <QCache>
|
||||
#include "qiconfix/qiconloader_p.h"
|
||||
#include "../xdgiconloader/xdgiconloader_p.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
#define DEFAULT_APP_ICON "application-x-executable"
|
||||
static const QLatin1String DEFAULT_APP_ICON("application-x-executable");
|
||||
|
||||
static void qt_cleanup_icon_cache();
|
||||
typedef QCache<QString, QIcon> IconCache;
|
||||
@ -83,7 +83,7 @@ QString XdgIcon::themeName()
|
||||
void XdgIcon::setThemeName(const QString& themeName)
|
||||
{
|
||||
QIcon::setThemeName(themeName);
|
||||
QtXdg::QIconLoader::instance()->updateSystemTheme();
|
||||
XdgIconLoader::instance()->updateSystemTheme();
|
||||
}
|
||||
|
||||
|
||||
@ -96,12 +96,12 @@ QIcon XdgIcon::fromTheme(const QString& iconName, const QIcon& fallback)
|
||||
if (iconName.isEmpty())
|
||||
return fallback;
|
||||
|
||||
bool isAbsolute = (iconName[0] == '/');
|
||||
bool isAbsolute = (iconName[0] == QLatin1Char('/'));
|
||||
|
||||
QString name = QFileInfo(iconName).fileName();
|
||||
if (name.endsWith(".png", Qt::CaseInsensitive) ||
|
||||
name.endsWith(".svg", Qt::CaseInsensitive) ||
|
||||
name.endsWith(".xpm", Qt::CaseInsensitive))
|
||||
if (name.endsWith(QLatin1String(".png"), Qt::CaseInsensitive) ||
|
||||
name.endsWith(QLatin1String(".svg"), Qt::CaseInsensitive) ||
|
||||
name.endsWith(QLatin1String(".xpm"), Qt::CaseInsensitive))
|
||||
{
|
||||
name.truncate(name.length() - 4);
|
||||
}
|
||||
@ -113,11 +113,12 @@ QIcon XdgIcon::fromTheme(const QString& iconName, const QIcon& fallback)
|
||||
} else {
|
||||
QIcon *cachedIcon;
|
||||
if (!isAbsolute)
|
||||
cachedIcon = new QIcon(new QtXdg::QIconLoaderEngineFixed(name));
|
||||
cachedIcon = new QIcon(new XdgIconLoaderEngine(name));
|
||||
else
|
||||
cachedIcon = new QIcon(iconName);
|
||||
qtIconCache()->insert(name, cachedIcon);
|
||||
icon = *cachedIcon;
|
||||
|
||||
qtIconCache()->insert(name, cachedIcon);
|
||||
}
|
||||
|
||||
// Note the qapp check is to allow lazy loading of static icons
|
||||
@ -136,7 +137,7 @@ QIcon XdgIcon::fromTheme(const QString& iconName, const QIcon& fallback)
|
||||
************************************************/
|
||||
QIcon XdgIcon::fromTheme(const QStringList& iconNames, const QIcon& fallback)
|
||||
{
|
||||
foreach (QString iconName, iconNames)
|
||||
foreach (const QString &iconName, iconNames)
|
||||
{
|
||||
QIcon icon = fromTheme(iconName);
|
||||
if (!icon.isNull())
|
@ -157,37 +157,37 @@ bool XdgMenu::read(const QString& menuFileName)
|
||||
|
||||
d->mXml = reader.xml();
|
||||
QDomElement root = d->mXml.documentElement();
|
||||
d->saveLog("00-reader.xml");
|
||||
d->saveLog(QLatin1String("00-reader.xml"));
|
||||
|
||||
d->simplify(root);
|
||||
d->saveLog("01-simplify.xml");
|
||||
d->saveLog(QLatin1String("01-simplify.xml"));
|
||||
|
||||
d->mergeMenus(root);
|
||||
d->saveLog("02-mergeMenus.xml");
|
||||
d->saveLog(QLatin1String("02-mergeMenus.xml"));
|
||||
|
||||
d->moveMenus(root);
|
||||
d->saveLog("03-moveMenus.xml");
|
||||
d->saveLog(QLatin1String("03-moveMenus.xml"));
|
||||
|
||||
d->mergeMenus(root);
|
||||
d->saveLog("04-mergeMenus.xml");
|
||||
d->saveLog(QLatin1String("04-mergeMenus.xml"));
|
||||
|
||||
d->deleteDeletedMenus(root);
|
||||
d->saveLog("05-deleteDeletedMenus.xml");
|
||||
d->saveLog(QLatin1String("05-deleteDeletedMenus.xml"));
|
||||
|
||||
d->processDirectoryEntries(root, QStringList());
|
||||
d->saveLog("06-processDirectoryEntries.xml");
|
||||
d->saveLog(QLatin1String("06-processDirectoryEntries.xml"));
|
||||
|
||||
d->processApps(root);
|
||||
d->saveLog("07-processApps.xml");
|
||||
d->saveLog(QLatin1String("07-processApps.xml"));
|
||||
|
||||
d->processLayouts(root);
|
||||
d->saveLog("08-processLayouts.xml");
|
||||
d->saveLog(QLatin1String("08-processLayouts.xml"));
|
||||
|
||||
d->deleteEmpty(root);
|
||||
d->saveLog("09-deleteEmpty.xml");
|
||||
d->saveLog(QLatin1String("09-deleteEmpty.xml"));
|
||||
|
||||
d->fixSeparators(root);
|
||||
d->saveLog("10-fixSeparators.xml");
|
||||
d->saveLog(QLatin1String("10-fixSeparators.xml"));
|
||||
|
||||
|
||||
d->mOutDated = false;
|
||||
@ -204,7 +204,7 @@ void XdgMenu::save(const QString& fileName)
|
||||
QFile file(fileName);
|
||||
if (!file.open(QFile::WriteOnly | QFile::Text))
|
||||
{
|
||||
qWarning() << QString("Cannot write file %1:\n%2.")
|
||||
qWarning() << QString::fromLatin1("Cannot write file %1:\n%2.")
|
||||
.arg(fileName)
|
||||
.arg(file.errorString());
|
||||
return;
|
||||
@ -225,7 +225,7 @@ void XdgMenuPrivate::load(const QString& fileName)
|
||||
QFile file(fileName);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
qWarning() << QString("%1 not loading: %2").arg(fileName).arg(file.errorString());
|
||||
qWarning() << QString::fromLatin1("%1 not loading: %2").arg(fileName).arg(file.errorString());
|
||||
return;
|
||||
}
|
||||
mXml.setContent(&file, true);
|
||||
@ -236,7 +236,7 @@ void XdgMenuPrivate::saveLog(const QString& logFileName)
|
||||
{
|
||||
Q_Q(XdgMenu);
|
||||
if (!mLogDir.isEmpty())
|
||||
q->save(mLogDir + "/" + logFileName);
|
||||
q->save(mLogDir + QLatin1Char('/') + logFileName);
|
||||
}
|
||||
|
||||
|
||||
@ -244,13 +244,13 @@ void XdgMenuPrivate::mergeMenus(QDomElement& element)
|
||||
{
|
||||
QHash<QString, QDomElement> menus;
|
||||
|
||||
MutableDomElementIterator it(element, "Menu");
|
||||
MutableDomElementIterator it(element, QLatin1String("Menu"));
|
||||
|
||||
it.toFront();
|
||||
while(it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
menus[it.current().attribute("name")] = it.current();
|
||||
menus[it.current().attribute(QLatin1String("name"))] = it.current();
|
||||
}
|
||||
|
||||
|
||||
@ -258,7 +258,7 @@ void XdgMenuPrivate::mergeMenus(QDomElement& element)
|
||||
while (it.hasPrevious())
|
||||
{
|
||||
QDomElement src = it.previous();
|
||||
QDomElement dest = menus[src.attribute("name")];
|
||||
QDomElement dest = menus[src.attribute(QLatin1String("name"))];
|
||||
if (dest != src)
|
||||
{
|
||||
prependChilds(src, dest);
|
||||
@ -267,11 +267,11 @@ void XdgMenuPrivate::mergeMenus(QDomElement& element)
|
||||
}
|
||||
|
||||
|
||||
QDomElement n = element.firstChildElement("Menu");
|
||||
QDomElement n = element.firstChildElement(QLatin1String("Menu"));
|
||||
while (!n.isNull())
|
||||
{
|
||||
mergeMenus(n);
|
||||
n = n.nextSiblingElement("Menu");
|
||||
n = n.nextSiblingElement(QLatin1String("Menu"));
|
||||
}
|
||||
|
||||
it.toFront();
|
||||
@ -288,46 +288,46 @@ void XdgMenuPrivate::simplify(QDomElement& element)
|
||||
{
|
||||
QDomElement n = it.next();
|
||||
|
||||
if (n.tagName() == "Name")
|
||||
if (n.tagName() == QLatin1String("Name"))
|
||||
{
|
||||
// The <Name> field must not contain the slash character ("/");
|
||||
// implementations should discard any name containing a slash.
|
||||
element.setAttribute("name", n.text().remove('/'));
|
||||
element.setAttribute(QLatin1String("name"), n.text().remove(QLatin1Char('/')));
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// ......................................
|
||||
else if(n.tagName() == "Deleted")
|
||||
else if(n.tagName() == QLatin1String("Deleted"))
|
||||
{
|
||||
element.setAttribute("deleted", true);
|
||||
element.setAttribute(QLatin1String("deleted"), true);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
else if(n.tagName() == "NotDeleted")
|
||||
else if(n.tagName() == QLatin1String("NotDeleted"))
|
||||
{
|
||||
element.setAttribute("deleted", false);
|
||||
element.setAttribute(QLatin1String("deleted"), false);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// ......................................
|
||||
else if(n.tagName() == "OnlyUnallocated")
|
||||
else if(n.tagName() == QLatin1String("OnlyUnallocated"))
|
||||
{
|
||||
element.setAttribute("onlyUnallocated", true);
|
||||
element.setAttribute(QLatin1String("onlyUnallocated"), true);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
else if(n.tagName() == "NotOnlyUnallocated")
|
||||
else if(n.tagName() == QLatin1String(QLatin1String("NotOnlyUnallocated")))
|
||||
{
|
||||
element.setAttribute("onlyUnallocated", false);
|
||||
element.setAttribute(QLatin1String("onlyUnallocated"), false);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// ......................................
|
||||
else if(n.tagName() == "FileInfo")
|
||||
else if(n.tagName() == QLatin1String("FileInfo"))
|
||||
{
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// ......................................
|
||||
else if(n.tagName() == "Menu")
|
||||
else if(n.tagName() == QLatin1String("Menu"))
|
||||
{
|
||||
simplify(n);
|
||||
}
|
||||
@ -348,15 +348,15 @@ void XdgMenuPrivate::prependChilds(QDomElement& srcElement, QDomElement& destEle
|
||||
destElement.insertBefore(n, destElement.firstChild());
|
||||
}
|
||||
|
||||
if (srcElement.attributes().contains("deleted") &&
|
||||
!destElement.attributes().contains("deleted")
|
||||
if (srcElement.attributes().contains(QLatin1String("deleted")) &&
|
||||
!destElement.attributes().contains(QLatin1String("deleted"))
|
||||
)
|
||||
destElement.setAttribute("deleted", srcElement.attribute("deleted"));
|
||||
destElement.setAttribute(QLatin1String("deleted"), srcElement.attribute(QLatin1String("deleted")));
|
||||
|
||||
if (srcElement.attributes().contains("onlyUnallocated") &&
|
||||
!destElement.attributes().contains("onlyUnallocated")
|
||||
if (srcElement.attributes().contains(QLatin1String("onlyUnallocated")) &&
|
||||
!destElement.attributes().contains(QLatin1String("onlyUnallocated"))
|
||||
)
|
||||
destElement.setAttribute("onlyUnallocated", srcElement.attribute("onlyUnallocated"));
|
||||
destElement.setAttribute(QLatin1String("onlyUnallocated"), srcElement.attribute(QLatin1String("onlyUnallocated")));
|
||||
}
|
||||
|
||||
|
||||
@ -367,11 +367,11 @@ void XdgMenuPrivate::appendChilds(QDomElement& srcElement, QDomElement& destElem
|
||||
while(it.hasNext())
|
||||
destElement.appendChild(it.next());
|
||||
|
||||
if (srcElement.attributes().contains("deleted"))
|
||||
destElement.setAttribute("deleted", srcElement.attribute("deleted"));
|
||||
if (srcElement.attributes().contains(QLatin1String("deleted")))
|
||||
destElement.setAttribute(QLatin1String("deleted"), srcElement.attribute(QLatin1String("deleted")));
|
||||
|
||||
if (srcElement.attributes().contains("onlyUnallocated"))
|
||||
destElement.setAttribute("onlyUnallocated", srcElement.attribute("onlyUnallocated"));
|
||||
if (srcElement.attributes().contains(QLatin1String("onlyUnallocated")))
|
||||
destElement.setAttribute(QLatin1String("onlyUnallocated"), srcElement.attribute(QLatin1String("onlyUnallocated")));
|
||||
}
|
||||
|
||||
|
||||
@ -384,10 +384,10 @@ QDomElement XdgMenu::findMenu(QDomElement& baseElement, const QString& path, boo
|
||||
{
|
||||
Q_D(XdgMenu);
|
||||
// Absolute path ..................
|
||||
if (path.startsWith('/'))
|
||||
if (path.startsWith(QLatin1Char('/')))
|
||||
{
|
||||
QDomElement root = d->mXml.documentElement();
|
||||
return findMenu(root, path.section('/', 2), createNonExisting);
|
||||
return findMenu(root, path.section(QLatin1Char('/'), 2), createNonExisting);
|
||||
}
|
||||
|
||||
// Relative path ..................
|
||||
@ -395,13 +395,13 @@ QDomElement XdgMenu::findMenu(QDomElement& baseElement, const QString& path, boo
|
||||
return baseElement;
|
||||
|
||||
|
||||
QString name = path.section('/', 0, 0);
|
||||
QString name = path.section(QLatin1Char('/'), 0, 0);
|
||||
MutableDomElementIterator it(baseElement);
|
||||
while(it.hasNext())
|
||||
{
|
||||
QDomElement n = it.next();
|
||||
if (n.attribute("name") == name)
|
||||
return findMenu(n, path.section('/', 1), createNonExisting);
|
||||
if (n.attribute(QLatin1String("name")) == name)
|
||||
return findMenu(n, path.section(QLatin1Char('/'), 1), createNonExisting);
|
||||
}
|
||||
|
||||
|
||||
@ -411,14 +411,14 @@ QDomElement XdgMenu::findMenu(QDomElement& baseElement, const QString& path, boo
|
||||
return QDomElement();
|
||||
|
||||
|
||||
QStringList names = path.split('/', QString::SkipEmptyParts);
|
||||
const QStringList names = path.split(QLatin1Char('/'), QString::SkipEmptyParts);
|
||||
QDomElement el = baseElement;
|
||||
foreach (QString name, names)
|
||||
foreach (const QString &name, names)
|
||||
{
|
||||
QDomElement p = el;
|
||||
el = d->mXml.createElement("Menu");
|
||||
el = d->mXml.createElement(QLatin1String("Menu"));
|
||||
p.appendChild(el);
|
||||
el.setAttribute("name", name);
|
||||
el.setAttribute(QLatin1String("name"), name);
|
||||
}
|
||||
return el;
|
||||
|
||||
@ -454,17 +454,17 @@ void XdgMenuPrivate::moveMenus(QDomElement& element)
|
||||
Q_Q(XdgMenu);
|
||||
|
||||
{
|
||||
MutableDomElementIterator i(element, "Menu");
|
||||
MutableDomElementIterator i(element, QLatin1String("Menu"));
|
||||
while(i.hasNext())
|
||||
moveMenus(i.next());
|
||||
}
|
||||
|
||||
MutableDomElementIterator i(element, "Move");
|
||||
MutableDomElementIterator i(element, QLatin1String("Move"));
|
||||
while(i.hasNext())
|
||||
{
|
||||
i.next();
|
||||
QString oldPath = i.current().lastChildElement("Old").text();
|
||||
QString newPath = i.current().lastChildElement("New").text();
|
||||
QString oldPath = i.current().lastChildElement(QLatin1String("Old")).text();
|
||||
QString newPath = i.current().lastChildElement(QLatin1String("New")).text();
|
||||
|
||||
element.removeChild(i.current());
|
||||
|
||||
@ -494,12 +494,12 @@ void XdgMenuPrivate::moveMenus(QDomElement& element)
|
||||
************************************************/
|
||||
void XdgMenuPrivate::deleteDeletedMenus(QDomElement& element)
|
||||
{
|
||||
MutableDomElementIterator i(element, "Menu");
|
||||
MutableDomElementIterator i(element, QLatin1String("Menu"));
|
||||
while(i.hasNext())
|
||||
{
|
||||
QDomElement e = i.next();
|
||||
if (e.attribute("deleted") == "1" ||
|
||||
e.attribute("name") == ".hidden"
|
||||
if (e.attribute(QLatin1String("deleted")) == QLatin1String("1") ||
|
||||
e.attribute(QLatin1String("name")) == QLatin1String(".hidden")
|
||||
)
|
||||
element.removeChild(e);
|
||||
else
|
||||
@ -514,7 +514,7 @@ void XdgMenuPrivate::processDirectoryEntries(QDomElement& element, const QString
|
||||
QStringList dirs;
|
||||
QStringList files;
|
||||
|
||||
element.setAttribute("title", element.attribute("name"));
|
||||
element.setAttribute(QLatin1String("title"), element.attribute(QLatin1String("name")));
|
||||
|
||||
MutableDomElementIterator i(element, QString());
|
||||
i.toBack();
|
||||
@ -522,13 +522,13 @@ void XdgMenuPrivate::processDirectoryEntries(QDomElement& element, const QString
|
||||
{
|
||||
QDomElement e = i.previous();
|
||||
|
||||
if (e.tagName() == "Directory")
|
||||
if (e.tagName() == QLatin1String("Directory"))
|
||||
{
|
||||
files << e.text();
|
||||
element.removeChild(e);
|
||||
}
|
||||
|
||||
else if (e.tagName() == "DirectoryDir")
|
||||
else if (e.tagName() == QLatin1String("DirectoryDir"))
|
||||
{
|
||||
dirs << e.text();
|
||||
element.removeChild(e);
|
||||
@ -538,14 +538,14 @@ void XdgMenuPrivate::processDirectoryEntries(QDomElement& element, const QString
|
||||
dirs << parentDirs;
|
||||
|
||||
bool found = false;
|
||||
foreach(QString file, files){
|
||||
if (file.startsWith('/'))
|
||||
foreach(const QString &file, files){
|
||||
if (file.startsWith(QLatin1Char('/')))
|
||||
found = loadDirectoryFile(file, element);
|
||||
else
|
||||
{
|
||||
foreach (QString dir, dirs)
|
||||
foreach (const QString &dir, dirs)
|
||||
{
|
||||
found = loadDirectoryFile(dir + "/" + file, element);
|
||||
found = loadDirectoryFile(dir + QLatin1Char('/') + file, element);
|
||||
if (found) break;
|
||||
}
|
||||
}
|
||||
@ -553,7 +553,7 @@ void XdgMenuPrivate::processDirectoryEntries(QDomElement& element, const QString
|
||||
}
|
||||
|
||||
|
||||
MutableDomElementIterator it(element, "Menu");
|
||||
MutableDomElementIterator it(element, QLatin1String("Menu"));
|
||||
while(it.hasNext())
|
||||
{
|
||||
QDomElement e = it.next();
|
||||
@ -572,9 +572,9 @@ bool XdgMenuPrivate::loadDirectoryFile(const QString& fileName, QDomElement& ele
|
||||
return false;
|
||||
|
||||
|
||||
element.setAttribute("title", file.localizedValue("Name").toString());
|
||||
element.setAttribute("comment", file.localizedValue("Comment").toString());
|
||||
element.setAttribute("icon", file.value("Icon").toString());
|
||||
element.setAttribute(QLatin1String("title"), file.localizedValue(QLatin1String("Name")).toString());
|
||||
element.setAttribute(QLatin1String("comment"), file.localizedValue(QLatin1String("Comment")).toString());
|
||||
element.setAttribute(QLatin1String("icon"), file.value(QLatin1String("Icon")).toString());
|
||||
|
||||
Q_Q(XdgMenu);
|
||||
q->addWatchPath(QFileInfo(file.fileName()).absolutePath());
|
||||
@ -592,15 +592,15 @@ void XdgMenuPrivate::processApps(QDomElement& element)
|
||||
|
||||
void XdgMenuPrivate::deleteEmpty(QDomElement& element)
|
||||
{
|
||||
MutableDomElementIterator it(element, "Menu");
|
||||
MutableDomElementIterator it(element, QLatin1String("Menu"));
|
||||
while(it.hasNext())
|
||||
deleteEmpty(it.next());
|
||||
|
||||
if (element.attribute("keep") == "true")
|
||||
if (element.attribute(QLatin1String("keep")) == QLatin1String("true"))
|
||||
return;
|
||||
|
||||
QDomElement childMenu = element.firstChildElement("Menu");
|
||||
QDomElement childApps = element.firstChildElement("AppLink");
|
||||
QDomElement childMenu = element.firstChildElement(QLatin1String("Menu"));
|
||||
QDomElement childApps = element.firstChildElement(QLatin1String("AppLink"));
|
||||
|
||||
if (childMenu.isNull() && childApps.isNull())
|
||||
{
|
||||
@ -619,25 +619,25 @@ void XdgMenuPrivate::processLayouts(QDomElement& element)
|
||||
void XdgMenuPrivate::fixSeparators(QDomElement& element)
|
||||
{
|
||||
|
||||
MutableDomElementIterator it(element, "Separator");
|
||||
MutableDomElementIterator it(element, QLatin1String("Separator"));
|
||||
while(it.hasNext())
|
||||
{
|
||||
QDomElement s = it.next();
|
||||
if (s.previousSiblingElement().tagName() == "Separator")
|
||||
if (s.previousSiblingElement().tagName() == QLatin1String("Separator"))
|
||||
element.removeChild(s);
|
||||
}
|
||||
|
||||
|
||||
QDomElement first = element.firstChild().toElement();
|
||||
if (first.tagName() == "Separator")
|
||||
if (first.tagName() == QLatin1String("Separator"))
|
||||
element.removeChild(first);
|
||||
|
||||
QDomElement last = element.lastChild().toElement();
|
||||
if (last.tagName() == "Separator")
|
||||
if (last.tagName() == QLatin1String("Separator"))
|
||||
element.removeChild(last);
|
||||
|
||||
|
||||
MutableDomElementIterator mi(element, "Menu");
|
||||
MutableDomElementIterator mi(element, QLatin1String("Menu"));
|
||||
while(mi.hasNext())
|
||||
fixSeparators(mi.next());
|
||||
}
|
||||
@ -649,32 +649,32 @@ void XdgMenuPrivate::fixSeparators(QDomElement& element)
|
||||
************************************************/
|
||||
QString XdgMenu::getMenuFileName(const QString& baseName)
|
||||
{
|
||||
QStringList configDirs = XdgDirs::configDirs();
|
||||
QString menuPrefix = getenv("XDG_MENU_PREFIX");
|
||||
const QStringList configDirs = XdgDirs::configDirs();
|
||||
QString menuPrefix = QString::fromLocal8Bit(qgetenv("XDG_MENU_PREFIX"));
|
||||
|
||||
foreach(QString configDir, configDirs)
|
||||
foreach(const QString &configDir, configDirs)
|
||||
{
|
||||
QFileInfo file(QString("%1/menus/%2%3").arg(configDir, menuPrefix, baseName));
|
||||
QFileInfo file(QString::fromLatin1("%1/menus/%2%3").arg(configDir, menuPrefix, baseName));
|
||||
if (file.exists())
|
||||
return file.filePath();
|
||||
}
|
||||
|
||||
QStringList wellKnownFiles;
|
||||
// razor- is a priority for us
|
||||
wellKnownFiles << "razor-applications.menu";
|
||||
wellKnownFiles << QLatin1String("razor-applications.menu");
|
||||
// the "global" menu file name on suse and fedora
|
||||
wellKnownFiles << "applications.menu";
|
||||
wellKnownFiles << QLatin1String("applications.menu");
|
||||
// rest files ordered by priority (descending)
|
||||
wellKnownFiles << "kde4-applications.menu";
|
||||
wellKnownFiles << "kde-applications.menu";
|
||||
wellKnownFiles << "gnome-applications.menu";
|
||||
wellKnownFiles << "lxde-applications.menu";
|
||||
wellKnownFiles << QLatin1String("kde4-applications.menu");
|
||||
wellKnownFiles << QLatin1String("kde-applications.menu");
|
||||
wellKnownFiles << QLatin1String("gnome-applications.menu");
|
||||
wellKnownFiles << QLatin1String("lxde-applications.menu");
|
||||
|
||||
foreach(QString configDir, configDirs)
|
||||
foreach(const QString &configDir, configDirs)
|
||||
{
|
||||
foreach (QString f, wellKnownFiles)
|
||||
foreach (const QString &f, wellKnownFiles)
|
||||
{
|
||||
QFileInfo file(QString("%1/menus/%2").arg(configDir, f));
|
||||
QFileInfo file(QString::fromLatin1("%1/menus/%2").arg(configDir, f));
|
||||
if (file.exists())
|
||||
return file.filePath();
|
||||
}
|
@ -108,7 +108,7 @@ public:
|
||||
*/
|
||||
void setLogDir(const QString& directory);
|
||||
|
||||
static QString getMenuFileName(const QString& baseName = "applications.menu");
|
||||
static QString getMenuFileName(const QString& baseName = QLatin1String("applications.menu"));
|
||||
|
||||
bool isOutDated() const;
|
||||
|
@ -40,9 +40,9 @@ XdgMenuApplinkProcessor::XdgMenuApplinkProcessor(QDomElement& element, XdgMenu*
|
||||
mParent = parent;
|
||||
mMenu = menu;
|
||||
|
||||
mOnlyUnallocated = element.attribute("onlyUnallocated") == "1";
|
||||
mOnlyUnallocated = element.attribute(QLatin1String("onlyUnallocated")) == QLatin1String("1");
|
||||
|
||||
MutableDomElementIterator i(element, "Menu");
|
||||
MutableDomElementIterator i(element, QLatin1String("Menu"));
|
||||
while(i.hasNext())
|
||||
{
|
||||
QDomElement e = i.next();
|
||||
@ -122,18 +122,18 @@ void XdgMenuApplinkProcessor::step2()
|
||||
if (!show)
|
||||
continue;
|
||||
|
||||
QDomElement appLink = doc.createElement("AppLink");
|
||||
QDomElement appLink = doc.createElement(QLatin1String("AppLink"));
|
||||
|
||||
appLink.setAttribute("id", fileInfo->id());
|
||||
appLink.setAttribute("title", file->localizedValue("Name").toString());
|
||||
appLink.setAttribute("comment", file->localizedValue("Comment").toString());
|
||||
appLink.setAttribute("genericName", file->localizedValue("GenericName").toString());
|
||||
appLink.setAttribute("exec", file->value("Exec").toString());
|
||||
appLink.setAttribute("terminal", file->value("Terminal").toBool());
|
||||
appLink.setAttribute("startupNotify", file->value("StartupNotify").toBool());
|
||||
appLink.setAttribute("path", file->value("Path").toString());
|
||||
appLink.setAttribute("icon", file->value("Icon").toString());
|
||||
appLink.setAttribute("desktopFile", file->fileName());
|
||||
appLink.setAttribute(QLatin1String("id"), fileInfo->id());
|
||||
appLink.setAttribute(QLatin1String("title"), file->localizedValue(QLatin1String("Name")).toString());
|
||||
appLink.setAttribute(QLatin1String("comment"), file->localizedValue(QLatin1String("Comment")).toString());
|
||||
appLink.setAttribute(QLatin1String("genericName"), file->localizedValue(QLatin1String("GenericName")).toString());
|
||||
appLink.setAttribute(QLatin1String("exec"), file->value(QLatin1String("Exec")).toString());
|
||||
appLink.setAttribute(QLatin1String("terminal"), file->value(QLatin1String("Terminal")).toBool());
|
||||
appLink.setAttribute(QLatin1String("startupNoify"), file->value(QLatin1String("StartupNotify")).toBool());
|
||||
appLink.setAttribute(QLatin1String("path"), file->value(QLatin1String("Path")).toString());
|
||||
appLink.setAttribute(QLatin1String("icon"), file->value(QLatin1String("Icon")).toString());
|
||||
appLink.setAttribute(QLatin1String("desktopFile"), file->fileName());
|
||||
|
||||
mElement.appendChild(appLink);
|
||||
|
||||
@ -159,7 +159,7 @@ void XdgMenuApplinkProcessor::fillAppFileInfoList()
|
||||
{
|
||||
// Build a pool by collecting entries found in <AppDir>
|
||||
{
|
||||
MutableDomElementIterator i(mElement, "AppDir");
|
||||
MutableDomElementIterator i(mElement, QLatin1String("AppDir"));
|
||||
i.toBack();
|
||||
while(i.hasPrevious())
|
||||
{
|
||||
@ -187,9 +187,9 @@ void XdgMenuApplinkProcessor::findDesktopFiles(const QString& dirName, const QSt
|
||||
{
|
||||
QDir dir(dirName);
|
||||
mMenu->addWatchPath(dir.absolutePath());
|
||||
QFileInfoList files = dir.entryInfoList(QStringList("*.desktop"), QDir::Files);
|
||||
const QFileInfoList files = dir.entryInfoList(QStringList(QLatin1String("*.desktop")), QDir::Files);
|
||||
|
||||
foreach (QFileInfo file, files)
|
||||
foreach (const QFileInfo &file, files)
|
||||
{
|
||||
XdgDesktopFile* f = XdgDesktopFileCache::getFile(file.canonicalFilePath());
|
||||
if (f)
|
||||
@ -198,13 +198,13 @@ void XdgMenuApplinkProcessor::findDesktopFiles(const QString& dirName, const QSt
|
||||
|
||||
|
||||
// Working recursively ............
|
||||
QFileInfoList dirs = dir.entryInfoList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (QFileInfo d, dirs)
|
||||
const QFileInfoList dirs = dir.entryInfoList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (const QFileInfo &d, dirs)
|
||||
{
|
||||
QString dn = d.canonicalFilePath();
|
||||
if (dn != dirName)
|
||||
{
|
||||
findDesktopFiles(dn, QString("%1%2-").arg(prefix, d.fileName()));
|
||||
findDesktopFiles(dn, QString::fromLatin1("%1%2-").arg(prefix, d.fileName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,13 +216,13 @@ void XdgMenuApplinkProcessor::createRules()
|
||||
while(i.hasNext())
|
||||
{
|
||||
QDomElement e = i.next();
|
||||
if (e.tagName()=="Include")
|
||||
if (e.tagName()== QLatin1String("Include"))
|
||||
{
|
||||
mRules.addInclude(e);
|
||||
mElement.removeChild(e);
|
||||
}
|
||||
|
||||
else if (e.tagName()=="Exclude")
|
||||
else if (e.tagName()== QLatin1String("Exclude"))
|
||||
{
|
||||
mRules.addExclude(e);
|
||||
mElement.removeChild(e);
|
||||
@ -240,9 +240,9 @@ bool XdgMenuApplinkProcessor::checkTryExec(const QString& progName)
|
||||
if (progName.startsWith(QDir::separator()))
|
||||
return QFileInfo(progName).isExecutable();
|
||||
|
||||
QStringList dirs = QString(getenv("PATH")).split(":");
|
||||
const QStringList dirs = QFile::decodeName(qgetenv("PATH")).split(QLatin1Char(':'));
|
||||
|
||||
foreach (QString dir, dirs)
|
||||
foreach (const QString &dir, dirs)
|
||||
{
|
||||
if (QFileInfo(QDir(dir), progName).isExecutable())
|
||||
return true;
|
||||
@ -250,4 +250,3 @@ bool XdgMenuApplinkProcessor::checkTryExec(const QString& progName)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -68,20 +68,20 @@ XdgMenuLayoutProcessor::XdgMenuLayoutProcessor(QDomElement& element):
|
||||
mDefaultParams.mInlineHeader = true;
|
||||
mDefaultParams.mInlineAlias = false;
|
||||
|
||||
mDefaultLayout = findLastElementByTag(element, "DefaultLayout");
|
||||
mDefaultLayout = findLastElementByTag(element, QLatin1String("DefaultLayout"));
|
||||
|
||||
if (mDefaultLayout.isNull())
|
||||
{
|
||||
// Create DefaultLayout node
|
||||
QDomDocument doc = element.ownerDocument();
|
||||
mDefaultLayout = doc.createElement("DefaultLayout");
|
||||
mDefaultLayout = doc.createElement(QLatin1String("DefaultLayout"));
|
||||
|
||||
QDomElement menus = doc.createElement("Merge");
|
||||
menus.setAttribute("type", "menus");
|
||||
QDomElement menus = doc.createElement(QLatin1String("Merge"));
|
||||
menus.setAttribute(QLatin1String("type"), QLatin1String("menus"));
|
||||
mDefaultLayout.appendChild(menus);
|
||||
|
||||
QDomElement files = doc.createElement("Merge");
|
||||
files.setAttribute("type", "files");
|
||||
QDomElement files = doc.createElement(QLatin1String("Merge"));
|
||||
files.setAttribute(QLatin1String("type"), QLatin1String("files"));
|
||||
mDefaultLayout.appendChild(files);
|
||||
|
||||
mElement.appendChild(mDefaultLayout);
|
||||
@ -91,7 +91,7 @@ XdgMenuLayoutProcessor::XdgMenuLayoutProcessor(QDomElement& element):
|
||||
|
||||
// If a menu does not contain a <Layout> element or if it contains an empty <Layout> element
|
||||
// then the default layout should be used.
|
||||
mLayout = findLastElementByTag(element, "Layout");
|
||||
mLayout = findLastElementByTag(element, QLatin1String("Layout"));
|
||||
if (mLayout.isNull() || !mLayout.hasChildNodes())
|
||||
mLayout = mDefaultLayout;
|
||||
}
|
||||
@ -103,7 +103,7 @@ XdgMenuLayoutProcessor::XdgMenuLayoutProcessor(QDomElement& element, XdgMenuLayo
|
||||
mDefaultParams = parent->mDefaultParams;
|
||||
|
||||
// DefaultLayout ............................
|
||||
QDomElement defaultLayout = findLastElementByTag(element, "DefaultLayout");
|
||||
QDomElement defaultLayout = findLastElementByTag(element, QLatin1String("DefaultLayout"));
|
||||
|
||||
if (defaultLayout.isNull())
|
||||
mDefaultLayout = parent->mDefaultLayout;
|
||||
@ -114,7 +114,7 @@ XdgMenuLayoutProcessor::XdgMenuLayoutProcessor(QDomElement& element, XdgMenuLayo
|
||||
|
||||
// If a menu does not contain a <Layout> element or if it contains an empty <Layout> element
|
||||
// then the default layout should be used.
|
||||
mLayout = findLastElementByTag(element, "Layout");
|
||||
mLayout = findLastElementByTag(element, QLatin1String("Layout"));
|
||||
if (mLayout.isNull() || !mLayout.hasChildNodes())
|
||||
mLayout = mDefaultLayout;
|
||||
|
||||
@ -123,20 +123,20 @@ XdgMenuLayoutProcessor::XdgMenuLayoutProcessor(QDomElement& element, XdgMenuLayo
|
||||
|
||||
void XdgMenuLayoutProcessor::setParams(QDomElement defaultLayout, LayoutParams *result)
|
||||
{
|
||||
if (defaultLayout.hasAttribute("show_empty"))
|
||||
result->mShowEmpty = defaultLayout.attribute("show_empty") == "true";
|
||||
if (defaultLayout.hasAttribute(QLatin1String("show_empty")))
|
||||
result->mShowEmpty = defaultLayout.attribute(QLatin1String("show_empty")) == QLatin1String("true");
|
||||
|
||||
if (defaultLayout.hasAttribute("inline"))
|
||||
result->mInline = defaultLayout.attribute("inline") == "true";
|
||||
if (defaultLayout.hasAttribute(QLatin1String("inline")))
|
||||
result->mInline = defaultLayout.attribute(QLatin1String("inline")) == QLatin1String("true");
|
||||
|
||||
if (defaultLayout.hasAttribute("inline_limit"))
|
||||
result->mInlineLimit = defaultLayout.attribute("inline_limit").toInt();
|
||||
if (defaultLayout.hasAttribute(QLatin1String("inline_limit")))
|
||||
result->mInlineLimit = defaultLayout.attribute(QLatin1String("inline_limit")).toInt();
|
||||
|
||||
if (defaultLayout.hasAttribute("inline_header"))
|
||||
result->mInlineHeader = defaultLayout.attribute("inline_header") == "true";
|
||||
if (defaultLayout.hasAttribute(QLatin1String("inline_header")))
|
||||
result->mInlineHeader = defaultLayout.attribute(QLatin1String("inline_header")) == QLatin1String("true");
|
||||
|
||||
if (defaultLayout.hasAttribute("inline_alias"))
|
||||
result->mInlineAlias = defaultLayout.attribute("inline_alias") == "true";
|
||||
if (defaultLayout.hasAttribute(QLatin1String("inline_alias")))
|
||||
result->mInlineAlias = defaultLayout.attribute(QLatin1String("inline_alias")) == QLatin1String("true");
|
||||
}
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ int childsCount(const QDomElement& element)
|
||||
while (it.hasNext())
|
||||
{
|
||||
QString tag = it.next().tagName();
|
||||
if (tag == "AppLink" || tag == "Menu" || tag == "Separator")
|
||||
if (tag == QLatin1String("AppLink") || tag == QLatin1String("Menu") || tag == QLatin1String("Separator"))
|
||||
count ++;
|
||||
}
|
||||
|
||||
@ -174,12 +174,12 @@ int childsCount(const QDomElement& element)
|
||||
void XdgMenuLayoutProcessor::run()
|
||||
{
|
||||
QDomDocument doc = mLayout.ownerDocument();
|
||||
mResult = doc.createElement("Result");
|
||||
mResult = doc.createElement(QLatin1String("Result"));
|
||||
mElement.appendChild(mResult);
|
||||
|
||||
// Process childs menus ...............................
|
||||
{
|
||||
DomElementIterator it(mElement, "Menu");
|
||||
DomElementIterator it(mElement, QLatin1String("Menu"));
|
||||
while (it.hasNext())
|
||||
{
|
||||
QDomElement e = it.next();
|
||||
@ -196,26 +196,26 @@ void XdgMenuLayoutProcessor::run()
|
||||
{
|
||||
QDomElement e = it.next();
|
||||
|
||||
if (e.tagName() == "Filename")
|
||||
if (e.tagName() == QLatin1String("Filename"))
|
||||
processFilenameTag(e);
|
||||
|
||||
else if (e.tagName() == "Menuname")
|
||||
else if (e.tagName() == QLatin1String("Menuname"))
|
||||
processMenunameTag(e);
|
||||
|
||||
else if (e.tagName() == "Separator")
|
||||
else if (e.tagName() == QLatin1String("Separator"))
|
||||
processSeparatorTag(e);
|
||||
|
||||
else if (e.tagName() == "Merge")
|
||||
else if (e.tagName() == QLatin1String("Merge"))
|
||||
{
|
||||
QDomElement merge = mResult.ownerDocument().createElement("Merge");
|
||||
merge.setAttribute("type", e.attribute("type"));
|
||||
QDomElement merge = mResult.ownerDocument().createElement(QLatin1String("Merge"));
|
||||
merge.setAttribute(QLatin1String("type"), e.attribute(QLatin1String("type")));
|
||||
mResult.appendChild(merge);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2 ...................................
|
||||
{
|
||||
MutableDomElementIterator ri(mResult, "Merge");
|
||||
MutableDomElementIterator ri(mResult, QLatin1String("Merge"));
|
||||
while (ri.hasNext())
|
||||
{
|
||||
processMergeTag(ri.next());
|
||||
@ -249,7 +249,7 @@ void XdgMenuLayoutProcessor::processFilenameTag(const QDomElement &element)
|
||||
{
|
||||
QString id = element.text();
|
||||
|
||||
QDomElement appLink = searchElement("AppLink", "id", id);
|
||||
QDomElement appLink = searchElement(QLatin1String("AppLink"), QLatin1String("id"), id);
|
||||
if (!appLink.isNull())
|
||||
mResult.appendChild(appLink);
|
||||
}
|
||||
@ -290,7 +290,7 @@ void XdgMenuLayoutProcessor::processFilenameTag(const QDomElement &element)
|
||||
void XdgMenuLayoutProcessor::processMenunameTag(const QDomElement &element)
|
||||
{
|
||||
QString id = element.text();
|
||||
QDomElement menu = searchElement("Menu", "name", id);
|
||||
QDomElement menu = searchElement(QLatin1String("Menu"), QLatin1String("name"), id);
|
||||
if (menu.isNull())
|
||||
return;
|
||||
|
||||
@ -303,7 +303,7 @@ void XdgMenuLayoutProcessor::processMenunameTag(const QDomElement &element)
|
||||
{
|
||||
if (params.mShowEmpty)
|
||||
{
|
||||
menu.setAttribute("keep", "true");
|
||||
menu.setAttribute(QLatin1String("keep"), QLatin1String("true"));
|
||||
mResult.appendChild(menu);
|
||||
}
|
||||
return;
|
||||
@ -330,7 +330,7 @@ void XdgMenuLayoutProcessor::processMenunameTag(const QDomElement &element)
|
||||
// Header ....................................
|
||||
if (doHeader)
|
||||
{
|
||||
QDomElement header = mLayout.ownerDocument().createElement("Header");
|
||||
QDomElement header = mLayout.ownerDocument().createElement(QLatin1String("Header"));
|
||||
|
||||
QDomNamedNodeMap attrs = menu.attributes();
|
||||
for (int i=0; i < attrs.count(); ++i)
|
||||
@ -344,7 +344,7 @@ void XdgMenuLayoutProcessor::processMenunameTag(const QDomElement &element)
|
||||
// Alias .....................................
|
||||
if (doAlias)
|
||||
{
|
||||
menu.firstChild().toElement().setAttribute("title", menu.attribute("title"));
|
||||
menu.firstChild().toElement().setAttribute(QLatin1String("title"), menu.attribute(QLatin1String("title")));
|
||||
}
|
||||
|
||||
// Inline ....................................
|
||||
@ -364,7 +364,7 @@ void XdgMenuLayoutProcessor::processMenunameTag(const QDomElement &element)
|
||||
************************************************/
|
||||
void XdgMenuLayoutProcessor::processSeparatorTag(const QDomElement &element)
|
||||
{
|
||||
QDomElement separator = element.ownerDocument().createElement("Separator");
|
||||
QDomElement separator = element.ownerDocument().createElement(QLatin1String("Separator"));
|
||||
mResult.appendChild(separator);
|
||||
}
|
||||
|
||||
@ -387,7 +387,7 @@ void XdgMenuLayoutProcessor::processSeparatorTag(const QDomElement &element)
|
||||
************************************************/
|
||||
void XdgMenuLayoutProcessor::processMergeTag(const QDomElement &element)
|
||||
{
|
||||
QString type = element.attribute("type");
|
||||
QString type = element.attribute(QLatin1String("type"));
|
||||
QMap<QString, QDomElement> map;
|
||||
MutableDomElementIterator it(mElement);
|
||||
|
||||
@ -395,10 +395,10 @@ void XdgMenuLayoutProcessor::processMergeTag(const QDomElement &element)
|
||||
{
|
||||
QDomElement e = it.next();
|
||||
if (
|
||||
((type == "menus" || type == "all") && e.tagName() == "Menu" ) ||
|
||||
((type == "files" || type == "all") && e.tagName() == "AppLink")
|
||||
((type == QLatin1String("menus") || type == QLatin1String("all")) && e.tagName() == QLatin1String("Menu" )) ||
|
||||
((type == QLatin1String("files") || type == QLatin1String("all")) && e.tagName() == QLatin1String("AppLink"))
|
||||
)
|
||||
map.insert(e.attribute("title"), e);
|
||||
map.insert(e.attribute(QLatin1String("title")), e);
|
||||
}
|
||||
|
||||
QMapIterator<QString, QDomElement> mi(map);
|
@ -76,7 +76,7 @@ bool XdgMenuReader::load(const QString& fileName, const QString& baseDir)
|
||||
QFile file(mFileName);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
mErrorStr = QString("%1 not loading: %2").arg(fileName).arg(file.errorString());
|
||||
mErrorStr = QString::fromLatin1("%1 not loading: %2").arg(fileName).arg(file.errorString());
|
||||
return false;
|
||||
}
|
||||
//qDebug() << "Load file:" << mFileName;
|
||||
@ -88,7 +88,7 @@ bool XdgMenuReader::load(const QString& fileName, const QString& baseDir)
|
||||
|
||||
if (!mXml.setContent(&file, true, &errorStr, &errorLine, &errorColumn))
|
||||
{
|
||||
mErrorStr = QString("Parse error at line %1, column %2:\n%3")
|
||||
mErrorStr = QString::fromLatin1("Parse error at line %1, column %2:\n%3")
|
||||
.arg(errorLine)
|
||||
.arg(errorColumn)
|
||||
.arg(errorStr);
|
||||
@ -97,10 +97,10 @@ bool XdgMenuReader::load(const QString& fileName, const QString& baseDir)
|
||||
|
||||
QDomElement root = mXml.documentElement();
|
||||
|
||||
QDomElement debugElement = mXml.createElement("FileInfo");
|
||||
debugElement.setAttribute("file", mFileName);
|
||||
QDomElement debugElement = mXml.createElement(QLatin1String("FileInfo"));
|
||||
debugElement.setAttribute(QLatin1String("file"), mFileName);
|
||||
if (mParentReader)
|
||||
debugElement.setAttribute("parent", mParentReader->fileName());
|
||||
debugElement.setAttribute(QLatin1String("parent"), mParentReader->fileName());
|
||||
|
||||
QDomNode null;
|
||||
root.insertBefore(debugElement, null);
|
||||
@ -124,49 +124,49 @@ void XdgMenuReader::processMergeTags(QDomElement& element)
|
||||
{
|
||||
QDomElement next = n.previousSiblingElement();
|
||||
// MergeFile ..................
|
||||
if (n.tagName() == "MergeFile")
|
||||
if (n.tagName() == QLatin1String("MergeFile"))
|
||||
{
|
||||
processMergeFileTag(n, &mergedFiles);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// MergeDir ...................
|
||||
else if(n.tagName() == "MergeDir")
|
||||
else if(n.tagName() == QLatin1String("MergeDir"))
|
||||
{
|
||||
processMergeDirTag(n, &mergedFiles);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// DefaultMergeDirs ...........
|
||||
else if (n.tagName() == "DefaultMergeDirs")
|
||||
else if (n.tagName() == QLatin1String("DefaultMergeDirs"))
|
||||
{
|
||||
processDefaultMergeDirsTag(n, &mergedFiles);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// AppDir ...................
|
||||
else if(n.tagName() == "AppDir")
|
||||
else if(n.tagName() == QLatin1String("AppDir"))
|
||||
{
|
||||
processAppDirTag(n);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// DefaultAppDirs .............
|
||||
else if(n.tagName() == "DefaultAppDirs")
|
||||
else if(n.tagName() == QLatin1String("DefaultAppDirs"))
|
||||
{
|
||||
processDefaultAppDirsTag(n);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// DirectoryDir ...................
|
||||
else if(n.tagName() == "DirectoryDir")
|
||||
else if(n.tagName() == QLatin1String("DirectoryDir"))
|
||||
{
|
||||
processDirectoryDirTag(n);
|
||||
n.parentNode().removeChild(n);
|
||||
}
|
||||
|
||||
// DefaultDirectoryDirs ...........
|
||||
else if(n.tagName() == "DefaultDirectoryDirs")
|
||||
else if(n.tagName() == QLatin1String("DefaultDirectoryDirs"))
|
||||
{
|
||||
processDefaultDirectoryDirsTag(n);
|
||||
n.parentNode().removeChild(n);
|
||||
@ -174,7 +174,7 @@ void XdgMenuReader::processMergeTags(QDomElement& element)
|
||||
|
||||
|
||||
// Menu .......................
|
||||
else if(n.tagName() == "Menu")
|
||||
else if(n.tagName() == QLatin1String("Menu"))
|
||||
{
|
||||
processMergeTags(n);
|
||||
}
|
||||
@ -205,7 +205,7 @@ void XdgMenuReader::processMergeFileTag(QDomElement& element, QStringList* merge
|
||||
{
|
||||
//qDebug() << "Process " << element;// << "in" << mFileName;
|
||||
|
||||
if (element.attribute("type") != "parent")
|
||||
if (element.attribute(QLatin1String("type")) != QLatin1String("parent"))
|
||||
{
|
||||
mergeFile(element.text(), element, mergedFiles);
|
||||
}
|
||||
@ -215,7 +215,7 @@ void XdgMenuReader::processMergeFileTag(QDomElement& element, QStringList* merge
|
||||
QString relativeName;
|
||||
QStringList configDirs = XdgDirs::configDirs();
|
||||
|
||||
foreach (QString configDir, configDirs)
|
||||
foreach (const QString &configDir, configDirs)
|
||||
{
|
||||
if (mFileName.startsWith(configDir))
|
||||
{
|
||||
@ -236,7 +236,7 @@ void XdgMenuReader::processMergeFileTag(QDomElement& element, QStringList* merge
|
||||
if (relativeName.isEmpty())
|
||||
return;
|
||||
|
||||
foreach (QString configDir, configDirs)
|
||||
foreach (const QString &configDir, configDirs)
|
||||
{
|
||||
if (QFileInfo(configDir + relativeName).exists())
|
||||
{
|
||||
@ -288,20 +288,20 @@ void XdgMenuReader::processDefaultMergeDirsTag(QDomElement& element, QStringList
|
||||
//qDebug() << "Process " << element;// << "in" << mFileName;
|
||||
|
||||
QString menuBaseName = QFileInfo(mMenu->menuFileName()).baseName();
|
||||
int n = menuBaseName.lastIndexOf('-');
|
||||
int n = menuBaseName.lastIndexOf(QLatin1Char('-'));
|
||||
if (n>-1)
|
||||
menuBaseName = menuBaseName.mid(n+1);
|
||||
|
||||
QStringList dirs = XdgDirs::configDirs();
|
||||
dirs << XdgDirs::configHome();
|
||||
|
||||
foreach (QString dir, dirs)
|
||||
foreach (const QString &dir, dirs)
|
||||
{
|
||||
mergeDir(QString("%1/menus/%2-merged").arg(dir).arg(menuBaseName), element, mergedFiles);
|
||||
mergeDir(QString::fromLatin1("%1/menus/%2-merged").arg(dir).arg(menuBaseName), element, mergedFiles);
|
||||
}
|
||||
|
||||
if (menuBaseName == "applications")
|
||||
mergeFile(QString("%1/menus/applications-kmenuedit.menu").arg(XdgDirs::configHome()), element, mergedFiles);
|
||||
if (menuBaseName == QLatin1String("applications"))
|
||||
mergeFile(QString::fromLatin1("%1/menus/applications-kmenuedit.menu").arg(XdgDirs::configHome()), element, mergedFiles);
|
||||
}
|
||||
|
||||
|
||||
@ -312,7 +312,7 @@ void XdgMenuReader::processDefaultMergeDirsTag(QDomElement& element, QStringList
|
||||
void XdgMenuReader::processAppDirTag(QDomElement& element)
|
||||
{
|
||||
//qDebug() << "Process " << element;
|
||||
addDirTag(element, "AppDir", element.text());
|
||||
addDirTag(element, QLatin1String("AppDir"), element.text());
|
||||
}
|
||||
|
||||
|
||||
@ -329,10 +329,10 @@ void XdgMenuReader::processDefaultAppDirsTag(QDomElement& element)
|
||||
QStringList dirs = XdgDirs::dataDirs();
|
||||
dirs.prepend(XdgDirs::dataHome(false));
|
||||
|
||||
foreach (QString dir, dirs)
|
||||
foreach (const QString &dir, dirs)
|
||||
{
|
||||
//qDebug() << "Add AppDir: " << dir + "/applications/";
|
||||
addDirTag(element, "AppDir", dir + "/applications/");
|
||||
addDirTag(element, QLatin1String("AppDir"), dir + QLatin1String("/applications/"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ void XdgMenuReader::processDefaultAppDirsTag(QDomElement& element)
|
||||
void XdgMenuReader::processDirectoryDirTag(QDomElement& element)
|
||||
{
|
||||
//qDebug() << "Process " << element;
|
||||
addDirTag(element, "DirectoryDir", element.text());
|
||||
addDirTag(element, QLatin1String("DirectoryDir"), element.text());
|
||||
}
|
||||
|
||||
|
||||
@ -360,8 +360,8 @@ void XdgMenuReader::processDefaultDirectoryDirsTag(QDomElement& element)
|
||||
QStringList dirs = XdgDirs::dataDirs();
|
||||
dirs.prepend(XdgDirs::dataHome(false));
|
||||
|
||||
foreach (QString dir, dirs)
|
||||
addDirTag(element, "DirectoryDir", dir + "/desktop-directories/");
|
||||
foreach (const QString &dir, dirs)
|
||||
addDirTag(element, QLatin1String("DirectoryDir"), dir + QLatin1String("/desktop-directories/"));
|
||||
}
|
||||
|
||||
/************************************************
|
||||
@ -409,7 +409,7 @@ void XdgMenuReader::mergeFile(const QString& fileName, QDomElement& element, QSt
|
||||
{
|
||||
// As a special exception, remove the <Name> element from the root
|
||||
// element of each file being merged.
|
||||
if (n.tagName() != "Name")
|
||||
if (n.tagName() != QLatin1String("Name"))
|
||||
{
|
||||
QDomNode imp = mXml.importNode(n, true);
|
||||
element.parentNode().insertBefore(imp, element);
|
||||
@ -429,9 +429,9 @@ void XdgMenuReader::mergeDir(const QString& dirName, QDomElement& element, QStri
|
||||
{
|
||||
//qDebug() << "Merge dir: " << dirInfo.canonicalFilePath();
|
||||
QDir dir = QDir(dirInfo.canonicalFilePath());
|
||||
const QFileInfoList files = dir.entryInfoList(QStringList() << "*.menu", QDir::Files | QDir::Readable);
|
||||
const QFileInfoList files = dir.entryInfoList(QStringList() << QLatin1String("*.menu"), QDir::Files | QDir::Readable);
|
||||
|
||||
foreach (QFileInfo file, files)
|
||||
foreach (const QFileInfo &file, files)
|
||||
mergeFile(file.canonicalFilePath(), element, mergedFiles);
|
||||
}
|
||||
}
|
@ -63,26 +63,26 @@ XdgMenuRuleOr::XdgMenuRuleOr(const QDomElement& element, QObject* parent) :
|
||||
{
|
||||
QDomElement e = iter.next();
|
||||
|
||||
if (e.tagName() == "Or")
|
||||
if (e.tagName() == QLatin1String("Or"))
|
||||
mChilds.append(new XdgMenuRuleOr(e, this));
|
||||
|
||||
else if (e.tagName() == "And")
|
||||
else if (e.tagName() == QLatin1String("And"))
|
||||
mChilds.append(new XdgMenuRuleAnd(e, this));
|
||||
|
||||
else if (e.tagName() == "Not")
|
||||
else if (e.tagName() == QLatin1String("Not"))
|
||||
mChilds.append(new XdgMenuRuleNot(e, this));
|
||||
|
||||
else if (e.tagName() == "Filename")
|
||||
else if (e.tagName() == QLatin1String("Filename"))
|
||||
mChilds.append(new XdgMenuRuleFileName(e, this));
|
||||
|
||||
else if (e.tagName() == "Category")
|
||||
else if (e.tagName() == QLatin1String("Category"))
|
||||
mChilds.append(new XdgMenuRuleCategory(e, this));
|
||||
|
||||
else if (e.tagName() == "All")
|
||||
else if (e.tagName() == QLatin1String("All"))
|
||||
mChilds.append(new XdgMenuRuleAll(e, this));
|
||||
|
||||
else
|
||||
qWarning() << "Unknown rule" << e.tagName();
|
||||
qWarning() << QString::fromLatin1("Unknown rule") << e.tagName();
|
||||
}
|
||||
|
||||
}
|
@ -99,13 +99,13 @@ void XdgMenuWidgetPrivate::init(const QDomElement& xml)
|
||||
q->clear();
|
||||
|
||||
QString title;
|
||||
if (! xml.attribute("title").isEmpty())
|
||||
title = xml.attribute("title");
|
||||
if (! xml.attribute(QLatin1String("title")).isEmpty())
|
||||
title = xml.attribute(QLatin1String("title"));
|
||||
else
|
||||
title = xml.attribute("name");
|
||||
title = xml.attribute(QLatin1String("name"));
|
||||
q->setTitle(escape(title));
|
||||
|
||||
q->setToolTip(xml.attribute("comment"));
|
||||
q->setToolTip(xml.attribute(QLatin1String("comment")));
|
||||
|
||||
|
||||
QIcon parentIcon;
|
||||
@ -113,7 +113,7 @@ void XdgMenuWidgetPrivate::init(const QDomElement& xml)
|
||||
if (parentMenu)
|
||||
parentIcon = parentMenu->icon();
|
||||
|
||||
q->setIcon(XdgIcon::fromTheme(mXml.attribute("icon"), parentIcon));
|
||||
q->setIcon(XdgIcon::fromTheme(mXml.attribute(QLatin1String("icon")), parentIcon));
|
||||
|
||||
buildMenu();
|
||||
}
|
||||
@ -195,15 +195,15 @@ void XdgMenuWidgetPrivate::buildMenu()
|
||||
QDomElement xml = it.next();
|
||||
|
||||
// Build submenu ........................
|
||||
if (xml.tagName() == "Menu")
|
||||
if (xml.tagName() == QLatin1String("Menu"))
|
||||
q->insertMenu(first, new XdgMenuWidget(xml, q));
|
||||
|
||||
//Build application link ................
|
||||
else if (xml.tagName() == "AppLink")
|
||||
else if (xml.tagName() == QLatin1String("AppLink"))
|
||||
q->insertAction(first, createAction(xml));
|
||||
|
||||
//Build separator .......................
|
||||
else if (xml.tagName() == "Separator")
|
||||
else if (xml.tagName() == QLatin1String("Separator"))
|
||||
q->insertSeparator(first);
|
||||
|
||||
}
|
||||
@ -213,18 +213,18 @@ void XdgMenuWidgetPrivate::buildMenu()
|
||||
XdgAction* XdgMenuWidgetPrivate::createAction(const QDomElement& xml)
|
||||
{
|
||||
Q_Q(XdgMenuWidget);
|
||||
XdgAction* action = new XdgAction(xml.attribute("desktopFile"), q);
|
||||
XdgAction* action = new XdgAction(xml.attribute(QLatin1String("desktopFile")), q);
|
||||
|
||||
QString title;
|
||||
if (!xml.attribute("title").isEmpty())
|
||||
title = xml.attribute("title");
|
||||
if (!xml.attribute(QLatin1String("title")).isEmpty())
|
||||
title = xml.attribute(QLatin1String("title"));
|
||||
else
|
||||
title = xml.attribute("name");
|
||||
title = xml.attribute(QLatin1String("name"));
|
||||
|
||||
|
||||
if (!xml.attribute("genericName").isEmpty() &&
|
||||
xml.attribute("genericName") != title)
|
||||
title += QString(" (%1)").arg(xml.attribute("genericName"));
|
||||
if (!xml.attribute(QLatin1String("genericName")).isEmpty() &&
|
||||
xml.attribute(QLatin1String("genericName")) != title)
|
||||
title += QString::fromLatin1(" (%1)").arg(xml.attribute(QLatin1String("genericName")));
|
||||
|
||||
action->setText(escape(title));
|
||||
return action;
|
||||
@ -237,5 +237,5 @@ XdgAction* XdgMenuWidgetPrivate::createAction(const QDomElement& xml)
|
||||
************************************************/
|
||||
QString XdgMenuWidgetPrivate::escape(QString string)
|
||||
{
|
||||
return string.replace("&", "&&");
|
||||
return string.replace(QLatin1Char('&'), QLatin1String("&&"));
|
||||
}
|
@ -96,7 +96,7 @@ QString XdgMimeType::iconName() const
|
||||
names.append(QMimeType::iconName());
|
||||
names.append(QMimeType::genericIconName());
|
||||
|
||||
foreach (QString s, names) {
|
||||
foreach (const QString &s, names) {
|
||||
if (!XdgIcon::fromTheme(s).isNull()) {
|
||||
dx->iconName = s;
|
||||
break;
|
@ -39,10 +39,8 @@ QDebug operator<<(QDebug dbg, const QDomElement &el)
|
||||
|
||||
QString args;
|
||||
for (int i=0; i<map.count(); ++i)
|
||||
args += " " + map.item(i).nodeName() + "='" + map.item(i).nodeValue() + "'";
|
||||
args += QLatin1Char(' ') + map.item(i).nodeName() + QLatin1Char('=') + map.item(i).nodeValue() + QLatin1Char('\'');
|
||||
|
||||
dbg.nospace() << QString("<%1%2>%3</%1>").arg(el.tagName()).arg(args).arg(el.text());
|
||||
dbg.nospace() << QString::fromLatin1("<%1%2>%3</%1>").arg(el.tagName()).arg(args).arg(el.text());
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
|
@ -25,4 +25,4 @@ sha256sum --tag *.tar.gz *.tar.xz >> CHECKSUMS
|
||||
cd ..
|
||||
echo "Uploading to lxqt.org..."
|
||||
|
||||
scp -r "$version" "lxde.org:/var/www/lxqt/downloads/$PROJECT/"
|
||||
scp -r "$version" "downloads.lxqt.org:/srv/downloads.lxqt.org/$PROJECT/"
|
||||
|
@ -1,5 +1,10 @@
|
||||
set(PROJECT_NAME "qtxdg_test")
|
||||
|
||||
remove_definitions(
|
||||
-DQT_USE_QSTRINGBUILDER
|
||||
-DQT_NO_CAST_FROM_ASCII
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC TRUE)
|
||||
|
||||
macro(qtxdg_add_test)
|
||||
@ -11,7 +16,7 @@ macro(qtxdg_add_test)
|
||||
endmacro()
|
||||
|
||||
include_directories (
|
||||
${CMAKE_SOURCE_DIR}
|
||||
"${CMAKE_SOURCE_DIR}/qtxdg"
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
@ -22,4 +27,5 @@ set_property(DIRECTORY APPEND
|
||||
qtxdg_add_test(
|
||||
qtxdg_test
|
||||
tst_xdgdirs
|
||||
tst_xdgdesktopfile
|
||||
)
|
||||
|
118
test/tst_xdgdesktopfile.cpp
Normal file
118
test/tst_xdgdesktopfile.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* libqtxdg - An Qt implementation of freedesktop.org xdg specs.
|
||||
* Copyright (C) 2016 Luís Pereira <luis.artur.pereira@gmail.com>
|
||||
*
|
||||
* This 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tst_xdgdesktopfile.h"
|
||||
#include "XdgDesktopFile"
|
||||
#include <QtTest>
|
||||
|
||||
|
||||
class Language
|
||||
{
|
||||
public:
|
||||
Language (const QString& lang)
|
||||
: mPreviousLang(QString::fromLocal8Bit(qgetenv("LANG")))
|
||||
{
|
||||
qputenv("LANG", lang.toLocal8Bit());
|
||||
}
|
||||
~Language()
|
||||
{
|
||||
qputenv("LANG", mPreviousLang.toLocal8Bit());
|
||||
}
|
||||
private:
|
||||
QString mPreviousLang;
|
||||
};
|
||||
|
||||
|
||||
QTEST_MAIN(tst_xdgdesktopfile);
|
||||
|
||||
void tst_xdgdesktopfile::testRead()
|
||||
{
|
||||
QTemporaryFile file("testReadXXXXXX.desktop");
|
||||
QVERIFY(file.open());
|
||||
const QString fileName = file.fileName();
|
||||
QTextStream ts(&file);
|
||||
ts <<
|
||||
"[Desktop Entry]\n"
|
||||
"Type=Application\n"
|
||||
"Name=MyApp\n"
|
||||
"Icon=foobar\n"
|
||||
"MimeType=text/plain;image/png;;\n"
|
||||
"\n";
|
||||
file.close();
|
||||
QVERIFY(QFile::exists(fileName));
|
||||
|
||||
XdgDesktopFile df;
|
||||
df.load(fileName);
|
||||
|
||||
QVERIFY(df.isValid());
|
||||
QCOMPARE(df.type(), XdgDesktopFile::ApplicationType);
|
||||
QCOMPARE(df.name(), QString::fromLatin1("MyApp"));
|
||||
QCOMPARE(df.iconName(), QString::fromLatin1("foobar"));
|
||||
QCOMPARE(df.mimeTypes(), QStringList() << QString::fromLatin1("text/plain")
|
||||
<< QString::fromLatin1("image/png"));
|
||||
QCOMPARE(df.fileName(), QFileInfo(fileName).canonicalFilePath());
|
||||
}
|
||||
|
||||
void tst_xdgdesktopfile::testReadLocalized_data()
|
||||
{
|
||||
QTest::addColumn<QString>("locale");
|
||||
QTest::addColumn<QString>("translation");
|
||||
|
||||
const QString pt = QString::fromUtf8("A Minha Aplicação");
|
||||
const QString pt_BR = QString::fromUtf8("O Meu Aplicativo");
|
||||
|
||||
QTest::newRow("pt") << QStringLiteral("pt") << pt;
|
||||
QTest::newRow("pt_PT") << QStringLiteral("pt_PT") << pt;
|
||||
QTest::newRow("pt_BR") << QStringLiteral("pt_BR") << pt_BR;
|
||||
|
||||
QTest::newRow("de") << QStringLiteral("de") << QStringLiteral("My Application");
|
||||
}
|
||||
|
||||
void tst_xdgdesktopfile::testReadLocalized()
|
||||
{
|
||||
QTemporaryFile file("testReadLocalizedXXXXXX.desktop");
|
||||
QVERIFY(file.open());
|
||||
const QString fileName = file.fileName();
|
||||
QTextStream ts(&file);
|
||||
ts << QString::fromUtf8(
|
||||
"[Desktop Entry]\n"
|
||||
"Type=Application\n"
|
||||
"Name=My Application\n"
|
||||
"Name[pt]=A Minha Aplicação\n"
|
||||
"Name[pt_BR]=O Meu Aplicativo\n"
|
||||
"Icon=foo\n"
|
||||
"\n");
|
||||
file.close();
|
||||
|
||||
QVERIFY(QFile::exists(fileName));
|
||||
|
||||
XdgDesktopFile df;
|
||||
df.load(fileName);
|
||||
QVERIFY(df.isValid());
|
||||
|
||||
QFETCH(QString, locale);
|
||||
QFETCH(QString, translation);
|
||||
|
||||
Language lang(locale);
|
||||
|
||||
QCOMPARE(df.localizedValue("Name").toString(), translation);
|
||||
}
|
||||
|
||||
#include "test/tst_xdgdesktopfile.moc"
|
35
test/tst_xdgdesktopfile.h
Normal file
35
test/tst_xdgdesktopfile.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* libqtxdg - An Qt implementation of freedesktop.org xdg specs.
|
||||
* Copyright (C) 2016 Luís Pereira <luis.artur.pereira@gmail.com>
|
||||
*
|
||||
* This 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TST_XDGDESKTOPFILE_H
|
||||
#define TST_XDGDESKTOPFILE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class tst_xdgdesktopfile : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
|
||||
void testRead();
|
||||
void testReadLocalized();
|
||||
void testReadLocalized_data();
|
||||
};
|
||||
|
||||
#endif // TST_XDGDESKTOPFILE_H
|
26
util/CMakeLists.txt
Normal file
26
util/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
include_directories (
|
||||
"${CMAKE_PROJECT_DIR}/qtxdg"
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
set(QTXDG_DESKTOP_FILE_START_SRCS
|
||||
qtxdg-desktop-file-start.cpp
|
||||
)
|
||||
|
||||
add_executable(qtxdg-desktop-file-start
|
||||
${QTXDG_DESKTOP_FILE_START_SRCS}
|
||||
)
|
||||
|
||||
target_compile_definitions(qtxdg-desktop-file-start
|
||||
PRIVATE "-DQTXDG_VERSION=\"${QTXDG_VERSION_STRING}\""
|
||||
)
|
||||
|
||||
target_link_libraries(qtxdg-desktop-file-start
|
||||
${QTXDGX_LIBRARY_NAME}
|
||||
)
|
||||
|
||||
install(TARGETS
|
||||
qtxdg-desktop-file-start
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
COMPONENT Runtime
|
||||
)
|
71
util/qtxdg-desktop-file-start.cpp
Normal file
71
util/qtxdg-desktop-file-start.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* libqtxdg - An Qt implementation of freedesktop.org xdg specs
|
||||
* Copyright (C) 2016 Luís Pereira <luis.artur.pereira@gmail.com>
|
||||
*
|
||||
* This 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
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <XdgDesktopFile>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static void printErr(const QString & out)
|
||||
{
|
||||
std::cerr << qPrintable(out);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::setApplicationName(QLatin1String("qtxdg-desktop-file-start"));
|
||||
QCoreApplication::setApplicationVersion(QLatin1String(QTXDG_VERSION));
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QLatin1String("QtXdg XdgDesktopFile start Tester"));
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
parser.addPositionalArgument(QLatin1String("file [urls...]"), QLatin1String("desktop file to start and it's urls"),QLatin1String("file [urls...]"));
|
||||
parser.process(app);
|
||||
|
||||
if (parser.positionalArguments().isEmpty()) {
|
||||
parser.showHelp(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
QStringList userArgs = parser.positionalArguments();
|
||||
const QString userFileName = userArgs.takeFirst();
|
||||
const QFileInfo fileInfo(userFileName);
|
||||
const QString canonicalFileName = fileInfo.canonicalFilePath();
|
||||
|
||||
if (!fileInfo.exists()) {
|
||||
printErr(QString::fromLatin1("File %1 does not exist\n").arg(userFileName));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
XdgDesktopFile f;
|
||||
const bool valid = f.load(canonicalFileName);
|
||||
if (valid) {
|
||||
f.startDetached(userArgs);
|
||||
} else {
|
||||
printErr(QString::fromLatin1("%1 is not a valid .desktop file\n").arg(canonicalFileName));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
82
xdgiconloader/CMakeLists.txt
Normal file
82
xdgiconloader/CMakeLists.txt
Normal file
@ -0,0 +1,82 @@
|
||||
include_directories(
|
||||
"${Qt5Gui_PRIVATE_INCLUDE_DIRS}"
|
||||
)
|
||||
|
||||
set(xdgiconloader_PUBLIC_H_FILES
|
||||
)
|
||||
|
||||
set(xdgiconloader_PUBLIC_CLASSES
|
||||
)
|
||||
|
||||
set(xdgiconloader_PRIVATE_H_FILES
|
||||
)
|
||||
|
||||
set(xdgiconloader_CPP_FILES
|
||||
xdgiconloader.cpp
|
||||
)
|
||||
|
||||
set(xdgiconloader_MOCS
|
||||
)
|
||||
|
||||
set(xdgiconloader_PRIVATE_INSTALLABLE_H_FILES
|
||||
xdgiconloader_p.h
|
||||
)
|
||||
|
||||
|
||||
add_library(${QTXDGX_ICONLOADER_LIBRARY_NAME} SHARED
|
||||
${xdgiconloader_CPP_FILES}
|
||||
${xdgiconloader_PRIVATE_INSTALLABLE_H_FILES}
|
||||
)
|
||||
|
||||
generate_export_header(${QTXDGX_ICONLOADER_LIBRARY_NAME} BASE_NAME XdgIconLoader)
|
||||
|
||||
# Copy public headers (in tree building)
|
||||
set(XDGICONLOADER_EXPORT_FILE "xdgiconloader_export.h")
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${XDGICONLOADER_EXPORT_FILE}"
|
||||
"${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}/${XDGICONLOADER_EXPORT_FILE}"
|
||||
COPYONLY
|
||||
)
|
||||
|
||||
target_include_directories(${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}>"
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
INTERFACE "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}/${QTXDG_VERSION_STRING}>"
|
||||
)
|
||||
|
||||
# include directories and targets for the in tree build
|
||||
target_include_directories(${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
PUBLIC "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}>"
|
||||
PUBLIC "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}>"
|
||||
PUBLIC "$<BUILD_INTERFACE:${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}/${QTXDG_VERSION_STRING}>"
|
||||
)
|
||||
|
||||
target_link_libraries(${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
PUBLIC
|
||||
Qt5::Gui
|
||||
)
|
||||
|
||||
set_target_properties(${QTXDGX_ICONLOADER_LIBRARY_NAME}
|
||||
PROPERTIES
|
||||
VERSION ${QTXDG_VERSION_STRING}
|
||||
SOVERSION ${QTXDG_MAJOR_VERSION}
|
||||
)
|
||||
|
||||
export(TARGETS ${QTXDGX_ICONLOADER_LIBRARY_NAME} FILE "${CMAKE_BINARY_DIR}/${QTXDGX_ICONLOADER_FILE_NAME}-targets.cmake")
|
||||
|
||||
install(TARGETS
|
||||
${QTXDGX_ICONLOADER_LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
EXPORT "${QTXDGX_ICONLOADER_FILE_NAME}-targets"
|
||||
COMPONENT Runtime
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${xdgiconloader_PRIVATE_INSTALLABLE_H_FILES}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}/${QTXDG_VERSION_STRING}/private/xdgiconloader"
|
||||
COMPONENT Devel
|
||||
)
|
||||
|
||||
install(FILES
|
||||
"${QTXDGX_INTREE_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}/${XDGICONLOADER_EXPORT_FILE}"
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTXDGX_ICONLOADER_FILE_NAME}"
|
||||
)
|
@ -31,7 +31,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QT_NO_ICON
|
||||
#include "qiconloader_p.h"
|
||||
#include "xdgiconloader_p.h"
|
||||
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <private/qicon_p.h>
|
||||
@ -55,9 +55,8 @@
|
||||
|
||||
//QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QtXdg {
|
||||
|
||||
Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
|
||||
Q_GLOBAL_STATIC(XdgIconLoader, iconLoaderInstance)
|
||||
|
||||
/* Theme to use in last resort, if the theme does not have the icon, neither the parents */
|
||||
static QString fallbackTheme()
|
||||
@ -67,10 +66,10 @@ static QString fallbackTheme()
|
||||
if (themeHint.isValid())
|
||||
return themeHint.toString();
|
||||
}
|
||||
return QString("hicolor");
|
||||
return QLatin1String("hicolor");
|
||||
}
|
||||
|
||||
QIconLoader::QIconLoader() :
|
||||
XdgIconLoader::XdgIconLoader() :
|
||||
m_themeKey(1), m_supportsSvg(false), m_initialized(false)
|
||||
{
|
||||
}
|
||||
@ -102,7 +101,7 @@ static inline QStringList systemIconSearchPaths()
|
||||
//extern QFactoryLoader *qt_iconEngineFactoryLoader(); // qicon.cpp
|
||||
#endif
|
||||
|
||||
void QIconLoader::ensureInitialized()
|
||||
void XdgIconLoader::ensureInitialized()
|
||||
{
|
||||
if (!m_initialized) {
|
||||
m_initialized = true;
|
||||
@ -120,7 +119,7 @@ void QIconLoader::ensureInitialized()
|
||||
}
|
||||
}
|
||||
|
||||
QIconLoader *QIconLoader::instance()
|
||||
XdgIconLoader *XdgIconLoader::instance()
|
||||
{
|
||||
iconLoaderInstance()->ensureInitialized();
|
||||
return iconLoaderInstance();
|
||||
@ -128,7 +127,7 @@ QIconLoader *QIconLoader::instance()
|
||||
|
||||
// Queries the system theme and invalidates existing
|
||||
// icons if the theme has changed.
|
||||
void QIconLoader::updateSystemTheme()
|
||||
void XdgIconLoader::updateSystemTheme()
|
||||
{
|
||||
// Only change if this is not explicitly set by the user
|
||||
if (m_userTheme.isEmpty()) {
|
||||
@ -142,20 +141,20 @@ void QIconLoader::updateSystemTheme()
|
||||
}
|
||||
}
|
||||
|
||||
void QIconLoader::setThemeName(const QString &themeName)
|
||||
void XdgIconLoader::setThemeName(const QString &themeName)
|
||||
{
|
||||
m_userTheme = themeName;
|
||||
invalidateKey();
|
||||
}
|
||||
|
||||
void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)
|
||||
void XdgIconLoader::setThemeSearchPath(const QStringList &searchPaths)
|
||||
{
|
||||
m_iconDirs = searchPaths;
|
||||
themeList.clear();
|
||||
invalidateKey();
|
||||
}
|
||||
|
||||
QStringList QIconLoader::themeSearchPaths() const
|
||||
QStringList XdgIconLoader::themeSearchPaths() const
|
||||
{
|
||||
if (m_iconDirs.isEmpty()) {
|
||||
m_iconDirs = systemIconSearchPaths();
|
||||
@ -182,7 +181,7 @@ QIconTheme::QIconTheme(const QString &themeName)
|
||||
QStringList themeSearchPaths = QIcon::themeSearchPaths();
|
||||
foreach (QString path, themeSearchPaths)
|
||||
{
|
||||
if (!path.startsWith(':') && QFileInfo(path).isDir())
|
||||
if (!path.startsWith(QLatin1Char(':')) && QFileInfo(path).isDir())
|
||||
m_contentDirs.append(path + QLatin1Char('/') + themeName);
|
||||
}
|
||||
|
||||
@ -201,18 +200,18 @@ QIconTheme::QIconTheme(const QString &themeName)
|
||||
// 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);
|
||||
XdgIconDirInfo dirInfo(directoryKey);
|
||||
dirInfo.size = size;
|
||||
QString type = indexReader.value(directoryKey +
|
||||
QLatin1String("/Type")
|
||||
).toString();
|
||||
|
||||
if (type == QLatin1String("Fixed"))
|
||||
dirInfo.type = QIconDirInfo::Fixed;
|
||||
dirInfo.type = XdgIconDirInfo::Fixed;
|
||||
else if (type == QLatin1String("Scalable"))
|
||||
dirInfo.type = QIconDirInfo::Scalable;
|
||||
dirInfo.type = XdgIconDirInfo::Scalable;
|
||||
else
|
||||
dirInfo.type = QIconDirInfo::Threshold;
|
||||
dirInfo.type = XdgIconDirInfo::Threshold;
|
||||
|
||||
dirInfo.threshold = indexReader.value(directoryKey +
|
||||
QLatin1String("/Threshold"),
|
||||
@ -249,7 +248,7 @@ QIconTheme::QIconTheme(const QString &themeName)
|
||||
#endif //QT_NO_SETTINGS
|
||||
}
|
||||
|
||||
QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
||||
QThemeIconInfo XdgIconLoader::findIconHelper(const QString &themeName,
|
||||
const QString &iconName,
|
||||
QStringList &visited) const
|
||||
{
|
||||
@ -271,7 +270,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
||||
}
|
||||
|
||||
const QStringList contentDirs = theme.contentDirs();
|
||||
const QVector<QIconDirInfo> subDirs = theme.keyList();
|
||||
const QVector<XdgIconDirInfo> subDirs = theme.keyList();
|
||||
|
||||
const QString svgext(QLatin1String(".svg"));
|
||||
const QString pngext(QLatin1String(".png"));
|
||||
@ -290,7 +289,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
||||
for (int i = 0; i < contentDirs.size(); ++i) {
|
||||
QString contentDir = contentDirs.at(i) + QLatin1Char('/');
|
||||
for (int j = 0; j < subDirs.size() ; ++j) {
|
||||
const QIconDirInfo &dirInfo = subDirs.at(j);
|
||||
const XdgIconDirInfo &dirInfo = subDirs.at(j);
|
||||
QString subdir = dirInfo.path;
|
||||
QDir currentDir(contentDir + subdir);
|
||||
if (currentDir.exists(pngIconName)) {
|
||||
@ -390,7 +389,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
||||
const QString pixmaps(QLatin1String("/usr/share/pixmaps"));
|
||||
|
||||
const QDir currentDir(pixmaps);
|
||||
const QIconDirInfo dirInfo(pixmaps);
|
||||
const XdgIconDirInfo dirInfo(pixmaps);
|
||||
if (currentDir.exists(iconName + pngext)) {
|
||||
PixmapEntry *iconEntry = new PixmapEntry;
|
||||
iconEntry->dir = dirInfo;
|
||||
@ -418,7 +417,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
||||
return info;
|
||||
}
|
||||
|
||||
QThemeIconInfo QIconLoader::loadIcon(const QString &name) const
|
||||
QThemeIconInfo XdgIconLoader::loadIcon(const QString &name) const
|
||||
{
|
||||
if (!themeName().isEmpty()) {
|
||||
QStringList visited;
|
||||
@ -432,59 +431,59 @@ QThemeIconInfo QIconLoader::loadIcon(const QString &name) const
|
||||
// -------- Icon Loader Engine -------- //
|
||||
|
||||
|
||||
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QString& iconName)
|
||||
XdgIconLoaderEngine::XdgIconLoaderEngine(const QString& iconName)
|
||||
: m_iconName(iconName), m_key(0)
|
||||
{
|
||||
}
|
||||
|
||||
QIconLoaderEngineFixed::~QIconLoaderEngineFixed()
|
||||
XdgIconLoaderEngine::~XdgIconLoaderEngine()
|
||||
{
|
||||
qDeleteAll(m_info.entries);
|
||||
}
|
||||
|
||||
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other)
|
||||
XdgIconLoaderEngine::XdgIconLoaderEngine(const XdgIconLoaderEngine &other)
|
||||
: QIconEngine(other),
|
||||
m_iconName(other.m_iconName),
|
||||
m_key(0)
|
||||
{
|
||||
}
|
||||
|
||||
QIconEngine *QIconLoaderEngineFixed::clone() const
|
||||
QIconEngine *XdgIconLoaderEngine::clone() const
|
||||
{
|
||||
return new QIconLoaderEngineFixed(*this);
|
||||
return new XdgIconLoaderEngine(*this);
|
||||
}
|
||||
|
||||
bool QIconLoaderEngineFixed::read(QDataStream &in) {
|
||||
bool XdgIconLoaderEngine::read(QDataStream &in) {
|
||||
in >> m_iconName;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QIconLoaderEngineFixed::write(QDataStream &out) const
|
||||
bool XdgIconLoaderEngine::write(QDataStream &out) const
|
||||
{
|
||||
out << m_iconName;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QIconLoaderEngineFixed::hasIcon() const
|
||||
bool XdgIconLoaderEngine::hasIcon() const
|
||||
{
|
||||
return !(m_info.entries.isEmpty());
|
||||
}
|
||||
|
||||
// Lazily load the icon
|
||||
void QIconLoaderEngineFixed::ensureLoaded()
|
||||
void XdgIconLoaderEngine::ensureLoaded()
|
||||
{
|
||||
if (!(QIconLoader::instance()->themeKey() == m_key)) {
|
||||
if (!(XdgIconLoader::instance()->themeKey() == m_key)) {
|
||||
qDeleteAll(m_info.entries);
|
||||
m_info.entries.clear();
|
||||
m_info.iconName.clear();
|
||||
|
||||
Q_ASSERT(m_info.entries.size() == 0);
|
||||
m_info = QIconLoader::instance()->loadIcon(m_iconName);
|
||||
m_key = QIconLoader::instance()->themeKey();
|
||||
m_info = XdgIconLoader::instance()->loadIcon(m_iconName);
|
||||
m_key = XdgIconLoader::instance()->themeKey();
|
||||
}
|
||||
}
|
||||
|
||||
void QIconLoaderEngineFixed::paint(QPainter *painter, const QRect &rect,
|
||||
void XdgIconLoaderEngine::paint(QPainter *painter, const QRect &rect,
|
||||
QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
QSize pixmapSize = rect.size();
|
||||
@ -498,16 +497,16 @@ void QIconLoaderEngineFixed::paint(QPainter *painter, const QRect &rect,
|
||||
* 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)
|
||||
static bool directoryMatchesSize(const XdgIconDirInfo &dir, int iconsize)
|
||||
{
|
||||
if (dir.type == QIconDirInfo::Fixed) {
|
||||
if (dir.type == XdgIconDirInfo::Fixed) {
|
||||
return dir.size == iconsize;
|
||||
|
||||
} else if (dir.type == QIconDirInfo::Scalable) {
|
||||
return dir.size <= dir.maxSize &&
|
||||
} else if (dir.type == XdgIconDirInfo::Scalable) {
|
||||
return iconsize <= dir.maxSize &&
|
||||
iconsize >= dir.minSize;
|
||||
|
||||
} else if (dir.type == QIconDirInfo::Threshold) {
|
||||
} else if (dir.type == XdgIconDirInfo::Threshold) {
|
||||
return iconsize >= dir.size - dir.threshold &&
|
||||
iconsize <= dir.size + dir.threshold;
|
||||
}
|
||||
@ -520,12 +519,12 @@ static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
|
||||
* 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)
|
||||
static int directorySizeDistance(const XdgIconDirInfo &dir, int iconsize)
|
||||
{
|
||||
if (dir.type == QIconDirInfo::Fixed) {
|
||||
if (dir.type == XdgIconDirInfo::Fixed) {
|
||||
return qAbs(dir.size - iconsize);
|
||||
|
||||
} else if (dir.type == QIconDirInfo::Scalable) {
|
||||
} else if (dir.type == XdgIconDirInfo::Scalable) {
|
||||
if (iconsize < dir.minSize)
|
||||
return dir.minSize - iconsize;
|
||||
else if (iconsize > dir.maxSize)
|
||||
@ -533,7 +532,7 @@ static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)
|
||||
else
|
||||
return 0;
|
||||
|
||||
} else if (dir.type == QIconDirInfo::Threshold) {
|
||||
} else if (dir.type == XdgIconDirInfo::Threshold) {
|
||||
if (iconsize < dir.size - dir.threshold)
|
||||
return dir.minSize - iconsize;
|
||||
else if (iconsize > dir.size + dir.threshold)
|
||||
@ -545,7 +544,7 @@ static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)
|
||||
return INT_MAX;
|
||||
}
|
||||
|
||||
QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
|
||||
XdgIconLoaderEngineEntry *XdgIconLoaderEngine::entryForSize(const QSize &size)
|
||||
{
|
||||
int iconsize = qMin(size.width(), size.height());
|
||||
|
||||
@ -556,7 +555,7 @@ QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
|
||||
|
||||
// Search for exact matches first
|
||||
for (int i = 0; i < numEntries; ++i) {
|
||||
QIconLoaderEngineEntry *entry = m_info.entries.at(i);
|
||||
XdgIconLoaderEngineEntry *entry = m_info.entries.at(i);
|
||||
if (directoryMatchesSize(entry->dir, iconsize)) {
|
||||
return entry;
|
||||
}
|
||||
@ -564,9 +563,9 @@ QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
|
||||
|
||||
// Find the minimum distance icon
|
||||
int minimalSize = INT_MAX;
|
||||
QIconLoaderEngineEntry *closestMatch = 0;
|
||||
XdgIconLoaderEngineEntry *closestMatch = 0;
|
||||
for (int i = 0; i < numEntries; ++i) {
|
||||
QIconLoaderEngineEntry *entry = m_info.entries.at(i);
|
||||
XdgIconLoaderEngineEntry *entry = m_info.entries.at(i);
|
||||
int distance = directorySizeDistance(entry->dir, iconsize);
|
||||
if (distance < minimalSize) {
|
||||
minimalSize = distance;
|
||||
@ -582,18 +581,27 @@ QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
|
||||
* we can never return a bigger size than the requested size.
|
||||
*
|
||||
*/
|
||||
QSize QIconLoaderEngineFixed::actualSize(const QSize &size, QIcon::Mode mode,
|
||||
QSize XdgIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode,
|
||||
QIcon::State state)
|
||||
{
|
||||
ensureLoaded();
|
||||
|
||||
QIconLoaderEngineEntry *entry = entryForSize(size);
|
||||
XdgIconLoaderEngineEntry *entry = entryForSize(size);
|
||||
if (entry) {
|
||||
const QIconDirInfo &dir = entry->dir;
|
||||
if (dir.type == QIconDirInfo::Scalable)
|
||||
const XdgIconDirInfo &dir = entry->dir;
|
||||
if (dir.type == XdgIconDirInfo::Scalable || dynamic_cast<ScalableEntry *>(entry))
|
||||
return size;
|
||||
else {
|
||||
int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
|
||||
int dir_size = dir.size;
|
||||
//Note: fallback for directories that don't have its content size defined
|
||||
// -> get the actual size based on the image if possible
|
||||
PixmapEntry * pix_e;
|
||||
if (0 == dir_size && nullptr != (pix_e = dynamic_cast<PixmapEntry *>(entry)))
|
||||
{
|
||||
QSize pix_size = pix_e->basePixmap.size();
|
||||
dir_size = qMin(pix_size.width(), pix_size.height());
|
||||
}
|
||||
int result = qMin(dir_size, qMin(size.width(), size.height()));
|
||||
return QSize(result, result);
|
||||
}
|
||||
}
|
||||
@ -644,24 +652,24 @@ QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State
|
||||
return svgIcon.pixmap(size, mode, state);
|
||||
}
|
||||
|
||||
QPixmap QIconLoaderEngineFixed::pixmap(const QSize &size, QIcon::Mode mode,
|
||||
QPixmap XdgIconLoaderEngine::pixmap(const QSize &size, QIcon::Mode mode,
|
||||
QIcon::State state)
|
||||
{
|
||||
ensureLoaded();
|
||||
|
||||
QIconLoaderEngineEntry *entry = entryForSize(size);
|
||||
XdgIconLoaderEngineEntry *entry = entryForSize(size);
|
||||
if (entry)
|
||||
return entry->pixmap(size, mode, state);
|
||||
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
QString QIconLoaderEngineFixed::key() const
|
||||
QString XdgIconLoaderEngine::key() const
|
||||
{
|
||||
return QLatin1String("QIconLoaderEngineFixed");
|
||||
return QLatin1String("XdgIconLoaderEngine");
|
||||
}
|
||||
|
||||
void QIconLoaderEngineFixed::virtual_hook(int id, void *data)
|
||||
void XdgIconLoaderEngine::virtual_hook(int id, void *data)
|
||||
{
|
||||
ensureLoaded();
|
||||
|
||||
@ -693,7 +701,6 @@ void QIconLoaderEngineFixed::virtual_hook(int id, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
} // QtXdg
|
||||
|
||||
//QT_END_NAMESPACE
|
||||
|
@ -48,6 +48,8 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <xdgiconloader_export.h>
|
||||
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtGui/QIconEngine>
|
||||
#include <QtGui/QPixmapCache>
|
||||
@ -59,14 +61,12 @@
|
||||
|
||||
//QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QtXdg {
|
||||
class XdgIconLoader;
|
||||
|
||||
class QIconLoader;
|
||||
|
||||
struct QIconDirInfo
|
||||
struct XdgIconDirInfo
|
||||
{
|
||||
enum Type { Fixed, Scalable, Threshold };
|
||||
QIconDirInfo(const QString &_path = QString()) :
|
||||
XdgIconDirInfo(const QString &_path = QString()) :
|
||||
path(_path),
|
||||
size(0),
|
||||
maxSize(0),
|
||||
@ -81,31 +81,31 @@ struct QIconDirInfo
|
||||
Type type : 4;
|
||||
};
|
||||
|
||||
class QIconLoaderEngineEntry
|
||||
class XdgIconLoaderEngineEntry
|
||||
{
|
||||
public:
|
||||
virtual ~QIconLoaderEngineEntry() {}
|
||||
virtual ~XdgIconLoaderEngineEntry() {}
|
||||
virtual QPixmap pixmap(const QSize &size,
|
||||
QIcon::Mode mode,
|
||||
QIcon::State state) = 0;
|
||||
QString filename;
|
||||
QIconDirInfo dir;
|
||||
XdgIconDirInfo dir;
|
||||
static int count;
|
||||
};
|
||||
|
||||
struct ScalableEntry : public QIconLoaderEngineEntry
|
||||
struct ScalableEntry : public XdgIconLoaderEngineEntry
|
||||
{
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
|
||||
QIcon svgIcon;
|
||||
};
|
||||
|
||||
struct PixmapEntry : public QIconLoaderEngineEntry
|
||||
struct PixmapEntry : public XdgIconLoaderEngineEntry
|
||||
{
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
|
||||
QPixmap basePixmap;
|
||||
};
|
||||
|
||||
typedef QList<QIconLoaderEngineEntry*> QThemeIconEntries;
|
||||
typedef QList<XdgIconLoaderEngineEntry*> QThemeIconEntries;
|
||||
|
||||
struct QThemeIconInfo
|
||||
{
|
||||
@ -114,11 +114,11 @@ struct QThemeIconInfo
|
||||
};
|
||||
|
||||
//class QIconLoaderEngine : public QIconEngine
|
||||
class QIconLoaderEngineFixed : public QIconEngine
|
||||
class XDGICONLOADER_EXPORT XdgIconLoaderEngine : public QIconEngine
|
||||
{
|
||||
public:
|
||||
QIconLoaderEngineFixed(const QString& iconName = QString());
|
||||
~QIconLoaderEngineFixed();
|
||||
XdgIconLoaderEngine(const QString& iconName = QString());
|
||||
~XdgIconLoaderEngine();
|
||||
|
||||
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
|
||||
@ -132,13 +132,13 @@ private:
|
||||
bool hasIcon() const;
|
||||
void ensureLoaded();
|
||||
void virtual_hook(int id, void *data);
|
||||
QIconLoaderEngineEntry *entryForSize(const QSize &size);
|
||||
QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other);
|
||||
XdgIconLoaderEngineEntry *entryForSize(const QSize &size);
|
||||
XdgIconLoaderEngine(const XdgIconLoaderEngine &other);
|
||||
QThemeIconInfo m_info;
|
||||
QString m_iconName;
|
||||
uint m_key;
|
||||
|
||||
friend class QIconLoader;
|
||||
friend class XdgIconLoader;
|
||||
};
|
||||
|
||||
class QIconTheme
|
||||
@ -147,21 +147,21 @@ public:
|
||||
QIconTheme(const QString &name);
|
||||
QIconTheme() : m_valid(false) {}
|
||||
QStringList parents() { return m_parents; }
|
||||
QVector <QIconDirInfo> keyList() { return m_keyList; }
|
||||
QVector <XdgIconDirInfo> keyList() { return m_keyList; }
|
||||
QStringList contentDirs() { return m_contentDirs; }
|
||||
bool isValid() { return m_valid; }
|
||||
|
||||
private:
|
||||
QStringList m_contentDirs;
|
||||
QVector <QIconDirInfo> m_keyList;
|
||||
QVector <XdgIconDirInfo> m_keyList;
|
||||
QStringList m_parents;
|
||||
bool m_valid;
|
||||
};
|
||||
|
||||
class Q_GUI_EXPORT QIconLoader
|
||||
class XDGICONLOADER_EXPORT XdgIconLoader
|
||||
{
|
||||
public:
|
||||
QIconLoader();
|
||||
XdgIconLoader();
|
||||
QThemeIconInfo loadIcon(const QString &iconName) const;
|
||||
uint themeKey() const { return m_themeKey; }
|
||||
|
||||
@ -170,8 +170,8 @@ public:
|
||||
QIconTheme theme() { return themeList.value(themeName()); }
|
||||
void setThemeSearchPath(const QStringList &searchPaths);
|
||||
QStringList themeSearchPaths() const;
|
||||
QIconDirInfo dirInfo(int dirindex);
|
||||
static QIconLoader *instance();
|
||||
XdgIconDirInfo dirInfo(int dirindex);
|
||||
static XdgIconLoader *instance();
|
||||
void updateSystemTheme();
|
||||
void invalidateKey() { m_themeKey++; }
|
||||
void ensureInitialized();
|
||||
@ -190,11 +190,10 @@ private:
|
||||
mutable QHash <QString, QIconTheme> themeList;
|
||||
};
|
||||
|
||||
} // QtXdg
|
||||
|
||||
// Note: class template specialization of 'QTypeInfo' must occur at
|
||||
// global scope
|
||||
Q_DECLARE_TYPEINFO(QtXdg::QIconDirInfo, Q_MOVABLE_TYPE);
|
||||
Q_DECLARE_TYPEINFO(XdgIconDirInfo, Q_MOVABLE_TYPE);
|
||||
|
||||
//QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user