Adding upstream version 2.0.0.

upstream/2.0.0
Alf Gaida 8 years ago
parent 7aa602d177
commit 1e3819068c

8
.gitignore vendored

@ -0,0 +1,8 @@
build*
*.qm
*~
*.autosave
*-swp
*.swp
CMakeLists.txt.user*
nbproject/

@ -0,0 +1,361 @@
libqtxdg-2.0.0 / 2016-09-17
===========================
* Bump version to 2.0.0
* Extend README.md
* Updates dependencies
* Fixes QIcon::hasThemeIcon() behavior with our Icon Loader Engine
* Adds Qt5Svg explicitly to the required packages
* QIconLoader: Use the GTK+ icon caches
* QIcon: add a hook in the engine so a non null QIconEngine can still be a null icon
* QIconLoader: don't make QIconDirInfo::type a bit-field
* Do not support static QIcon instances
* Respect manual set icon themes.
* Remove <qhash.h> where it's not used
* Make it more obvious that Q_WS_ is dead code, and should perhaps be ported
* XdgDesktopFileData: Explicitly initialize members (#91)
* build: Create separate Qt5XdgIconLoader target
* XdgDesktopFile: Adds tests
* xdgdesktopfile: Removes an not needed debug info
* xdgdesktopfile: Removes double QLatin1String's contruction
* XdgDesktopFileCache: Check if a file isValid() only when needed
* XdgDesktopFile: Reworks XdgDesktopFileCache::getFile()
* XdgDesktopFileCache: Check new acquired objects before using it
* XdgDesktopFile: Removes unneeded assignment
* XdgDesktopFile: Add break to switch case
* qtxdg: Get the HOME environment variable just one time
* Replace the QString % operator by the + operator
* No more implicit string conversions
* Moves QT_USE_QSTRINGBUILDER to the compiler_settings CMake module
* XdgDesktopFileCache: Fixes an coding typing error
* xdgiconloader: Fix typo in directoryMatchesSize
* Xdgiconloader (#84)
* Improve foreach iteraror performance
* XdgDesktopFile: Improve the performance of the foreach loop
* XdgDesktopFile: Use XdgDirs::userDir(), drop QStandardPaths()
* XdgDesktopFile: Standardize text strings scope
* XdgDesktopFile: Adds a Desktop File ID calculator method
* XdgDesktopFile: Document Exec fallback when DBusActivatable fails
* Adds QT_USE_QSTRINGBUILDER to the compile definitions
* Adds the BUILD_DEV_UTILS to README.md
* Makes the development utils build/install optional
* XdgDesktopFile: Adds Exec fallback when DBusActivatable fails
* Adds an .desktop file start tester
* XdgDirs: Use Q_ASSERT to check for XdgDirs::userDirectory invalid values
* XdgDirs: Use XdgDirs::UserDirectory enum instead of int
* XdgDirs: Makes XdgDirs::userDir use userDirectoryFallback()
* XdgDirs: Adds userDirDefault() method.
* Adds XdgDesktopFile::mimeTypes() member
* build: Enable C++11 usage
* iconloader: Fix actualSize() for non-themed icons
* desktopfile: Change validity check
* Added Digia-Qt-LGPL-Exception-1.1
* Update years and Licenses
* desktopfile: Check validity of DBus object path
* desktopfile: Don't invoke DBus call on invalid interface
* XdgUserDirs: Return a fallback when the path is empty
* README.md: Fix grammatical error, adjust wording
* Update and rename README to README.md
* xdgdesktopfile: handle 'Path' entry for application's working directory
* Fix possible use of cachedIcon after free
* Update release.sh server url
1.3.0 / 2015-10-27
==================
* Release 1.3.0
* desktopfile: Remove support for $XDG_MOVIES_DIR (which doesn't exist)
* Assorted style cleanups
* Adds XdgDesktopFile != operator
* Fixes the XdgMimeType == operator
* Handles CMake policy CMP0063
* Adds an compiler_settings CMake "module"
* CMake: Adds Runtime install COMPONENT
* Drops find_package(), use find_dependency()
* Marks link libraries as PUBLIC
* Handles in-tree builds headers the right way.
* Narrows the scope of compile definitions
* Improves create_pkgconfig_file.cmake
* Use the Targets CMake stuff
* Adds package version config info file
* Code reordering
* Use Qt5 style library names
* Remove unneeded add_definitions()
* Simplifies version variables a little bit
* Removes unneeded include_directories()
* Uses standard GNUInstallDirs instead of FindLibSuffix
* Remove trailing whitespaces
* added missing licensing headers
* Backports Fixed icons lookup in QIcon::fromTheme
* Adds XdgDirs tests
* Adds XdgDirs::configHome() fallback default locations
* XdgDesktopFile: Handles NotShowIn correctly
* Fixes XdgDirs::dataHome() regression
* QIconLoader: Change the order fallback icon lookup order
* Gets rid of translations stuff
* Cleans up empty comment lines
* Remove Qt4 stuff from the documentation
* Remove Qt4 stuff from the example and tests
* Remove Qt4 stuff from the source files
* Get rid of Qt4 stuff in the build system
1.2.0 / 2015-03-29
==================
* Release 1.2.0
* Fixes XdgDesktop::isShow() caching mechanism
* Add QtDBus/Qt5DBus dependency
* Adds support for X-Categories
* Adds support for X-OnlyShowIn and X-NotShowIn
* Fixes an Qt4 FTBFS
* Use QLatin1Char()
* Adds platform-data handling
* Make DBusActivatable work for Qt4 too
* desktopfile: support for DBusActivatable applications
* Adds a list of special non detachable execs
* desktopfile: run new process as a direct child
* Qt5: Use QStandardPaths() where possible
* XdgDirs: Updates documentation.
* String manipulation enhancements
* Make sure returned directories don't have an trailing '/'
* XdgDirs: postfix should always start with an /
* XdgDirs::configHome() handle postfix slash
* Fix XdgDirs::dataDirs() postfix handling
* Replace empty quotes by QString()
* XdgDesktopFileCache: Retrieve apps of a category
* Quote all paths in the CMake stuff
* Qt5: Use Qt5 private headers
* Ignore empty dirs in xdgDirList()
* Makes needed helper functions available to tests
* - Fix compilation when using internal mime
* Release with a proper versioned prefix
* Avoid adding empty parent icon theme
* Update license headers and add new license files
* Use QPlatformTheme::SystemIconFallbackThemeName in static QString fallbackTheme()
* QIconLoader: enable an easy case of transactional processing
* QIconLoader: don't inherit QObject
* QIconLoader: replace an inefficient QList with a QVector
* QIconLoader: mark virtual overrides
* QIconLoader: mark a helper type as movable
* QIconLoader: replace while(!empty()) delete takeLast() with qDeleteAll()
* QIconLoader: don't re-evaluate container.size() all the time (II)
* QIconLoader: don't re-evaluate container.size() all the time
* QIconLoader: remove another unused variable
* QIconLoader: remove an unused variable
1.1.0 / 2015-02-07
==================
* Update the release script to sign packages
* Sets visibility to hidden symbols for Clang
* Move static const variable from a public .h file to the .cpp
* Use gcc visibility attribute and Q_DECL_EXPORT macro to avoid exporting private symbols in the lib. This greatly reduced the size of dynamic symbol table and might potentially speed up loading. Also, turn off exception handling to save more since we don't use it. For non-gcc compilers, this change does nothing.
* Makes the Qt5 build the default
* Qt5: Updates CMake minimum required version
* Qt4: Backport add fallback for unthemed app icons
* add fallback for unthemed app icons
* XdgDesktopFileCache::getFile(): Don't insert/removes non existent files
* Enhance the loading of a .desktop file.
* Adds helper functions prototypes
* Fixes issue #7
* Updates .gitignore
* Removes i18n/i10n
* Updates translations
* Updates the translation infrastructure
* Update Russian translation
* Qt4: Fixes an FTBFS on Gentoo x86_64 when USE_QTMIMETYPES=On
* Add a release script
1.0.0 / 2014-09-06
==================
* Release 1.0.0
* Replaces XdgMimeInfo with XdgMimeType
* Updates the cmake_minimum_required() version
* Build system maintenance
* if QT_VERSION < 5 load the qt4 header
* Allows QIconLoader to search in multiple theme directories.
* Fixes an FTBFS in the Qt4 build
* Merge branch 'use-qt5-qiconloader'
* Revert "Merge branch 'use-qt5-qiconloader'"
* Revert "Fixes an FTBFS in the Qt4 build"
* Fixes an FTBFS in the Qt4 build
* Get and set XDG user dirs variables in config file
* Honors /usr/share/pixmaps when searching for icons.
* Adds xpm icon support
* Adds Qt5 QIconLoader for the Qt5 build
* Ports Qt5 commit: Make sure QIconLoader is always initialized
* Use environment to trigger Qt5 builds
* Fixes an XdgMimeInfo memory leak
* Use case insensitive comparisons with desktop environment names
* Updates some XdgDesktopFile methods documentation
* Make desktop enviroment names comparisons case insensitive
* solve failed comp LXQT with LXQt (OnlyShowIn=LXQt;) in desktop files
* Re-adds Support XDG_CURRENT_DESKTOP in autostart handling
* Deprecates non desktop environment neutral XdgDesktopFile methods
* Revert "Support XDG_CURRENT_DESKTOP in autostart handling."
* Adds QTXDG_DEPRECATED macro
* Install pkgconfig files to /usr/local/libdata/pkgconfig in FreeBSD.
* Set library dirs properly in qtxdg-config and use files.
0.5.3 / 2014-05-08
==================
* Release 0.5.3
* Update some comments
0.5.1 / 2014-05-05
==================
* libqtxdg 0.5.1
* Revert "Change default environment to LXQt"
* Revert "Check for lxqt-applications instead of razor-applications"
* Support XDG_CURRENT_DESKTOP in autostart handling.
* Update .gitignore
* Check for lxqt-applications instead of razor-applications
* Change default environment to LXQt
* Avoid XdgAction mnemonics caused by '&' symbol in the name of desktop app.
0.1.0 / 2014-04-29
==================
* Update AUTHORS and COPYING
* Add CPack rules for creating tarball
* Put iconloaderfix into own namespace
* Adds an uninstall target
* Fixes an FTBFS on the test target
* Fixes an FTBFS when a mix of PIC and PIE compiler flags are used
* Updates CMake's minimum required version
* Adds Qt5Widgets to the required pkg-config required packages
* test: Removes meaningless add_dependencies(..... razorqt)
* Don't use STREQUAL to test the BUILD_TESTS option
* Removed CMAKE_SOURCE_DIR usage from test/CMakeLists.txt
* Adds missing ${CMAKE_INSTALL_PREFIX}
* Fixes bugs in create_pkgconfig_file cmake macro
* Use GNU installation directories
* prefix parameter for autostartDirs, configDirs and dataDirs. (part2)
* prefix parameter for autostartDirs, configDirs and dataDirs.
* Updates buildsystem typical use documentation
* Reformatting for an easy reading in a 80x24 terminal
* Documents the QTXDG_QT_LIBRARIES variable
* Adds an tiny example on how to use the lib
* RazorLibSuffix.cmake -> ../cmake/FindLibSuffix.cmake and QUIET mode for find_package
* Adds ${CMAKE_CURRENT_BINARY_DIR} to the include_directories list
* Fix qtxdg_use.cmake and qtxdg-config.cmake generation location
* Replace QDomNodeList::length() by QDomNodeList::size()
* Portable headers
* Adds pkg-config to Qt5Xdg
* Renames the Qt5 build
* Packs Qt version specific stuff
* Removes unneeded set(QT_USE_QTXML TRUE)
* qtxdg/test: Adapts the build system to support Qt4 and Qt5
* qtxdg/test: Removes Qt4 CMake stuff
* Adds missing library (Qt5Xml) to qtxdg target
* qtxdg/test: Removes the project command and cmake_minimum_required()
* Explicitly requires QtTest module
* Make BUILD_TESTS an option
* Replace Q_GLOBAL_STATIC_WITH_INITIALIZER
* Replaces QIconEngineV2 with QIconEngine
* Adds QMimeData include file
* Port QString::toAscii()
* Port QDesktopServices
* Ran fixqt4headers
* Adds support to Qt5 in the buildsystem
* Adds test target to CMake
* Use the QtTestLib facilities
* Cmake find_package files for the QtXdg
* Revert "Cmake find_package files"
* Cmake find_package files
* Add COPYING and AUTHORS files
* X-RAZOR changed to Razor in desktop files
* config-file-associations, mimetypeviewer: Replaced QTreeWidget with QTreeView and new class MimetypeItemModel as model
* Improved (hopefuly) layout and look of config-fileassociations, application chooser
* Clang complained about type mismatch
* application-x-executable now fallback icon for desktopfiles of type Application
* Added XdgMimeInfoCache
* Added more info to XdgMime
* XdgDesktopFileCache now holds list of all apps that can handle a given mimetype
* Make QtXdg build by itself again
* libraries: Removes unneeded include(RazorLibSuffix)
* libraries: Removes unneeded cmake_minimum_required(VERSION 2.6)
* libraries: Removes unneeded find_package(Qt4)
* xdgdesktopfilecache now looks in <datadir or datahome>/applications/defaults.list for default app
* Add getApps method to XdgDesktopFileCache - returns all applications that can handle a mimetype
* Fix building with C++11
* XdgDesktopFile: Don't strip quotes
* initial fix for #520 XdgDesktopFileCache::getDefaultApp cache wrong behavior
* Closes Issue #487
* Set minimum percent to 1% for transifex in cmake
* Translations updated
* Translations updated
* Soname was changed
* Update translations
* Translations updated
* Removed line num from TS files.
* Fix autostart dir detection when the env var is set
* Updated .tx file
* version bump to 0.4.99 (public "release candiates") for qtxdg
* Translation for razor-sesion
* Fixes in the qtxdg translations
* Transifex resource renamed qtxdg->libqtxdg
* Fix for Issue #290 Fails to build on BSD
* New translations for libqtxdg
* Starting the razor-confupdate from the razor-session.
* Razor-confupdate: fixes and .upd file for 0.4.1-0.5
* Language name zh_CN.GB2312 braked cmake process.
* Translations updated
* Add operator== for XdgDesktopFile
* Don't replace space with \s
* Fixed for Preloading menu
* Cleaning the code.
* Move autostart directory code to XdgDirs
* Improvements to the XdgMenu. Added changed signal.
* Small speed opetimistaion in the qiconloader
* Add function to remove entries from desktop files
* Transifex desktop: sr_BA.ts should be a local
* Transifex desktop: local translations
* Transifex desktop: Translations pulled
* Icons for the desktop menu
* Add Traditional Chinese Translations
* Translations update
* Added support for the online translation service. www.transifex.net
* Serbian translation files
* Class documentation for XdgMimeInfo
* Greek translation by iosifidis
* Fix for issue #170. Escaping.
* Fix for issue #170. Escaping.
* Fix for issue #170
* Fix for issue #170
* Added danish translations
* X-RAZOR -> Razor for autostart
* Russian translation
* RAZOR -> X-RAZOR
* MINOR_VERSION & PATCH_VERSION for libraries
* fix #169: italian translation
* XdgAutoStart rewriten (lgpl2+)
* Closes #158
* Support icons with absolute path file names
* LGPL2+ for qtxdg
* Escape &'s to prevent Qt from using them for mnemonics
* Revert "XdgDesktopFile: Display an actual ampersand character"
* Update german [de] translation
* Add setLocalizedValue() function
* fixed qtxdg/translations/translate.sh
* Add a constructor to generate basic XdgDesktopFiles
* Correct the XdgAutoStart behavior
* SVK translation finalized
* Replaces return"" by return QString()
* License audit
* implemented #70: pkg-config for libs
* Add Chinese(simplified) translation files.
* fix #119 qtxdg bug and patch
* License audit
* Add Slovak (sk) translation
* Czech translations (cs_CZ)
* Fix doxygen documentation in xdgdesktopfile
* New doxygen ifrastructure
* devel-docs generated in CMAKE_BINARY_DIR/docs includig dummy index.html
* missing translations in CMakeLists
* XdgDesktopFile is implicitly shared
* huge refactoring of the libraries build organization

@ -25,8 +25,8 @@ else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(QTXDG_MAJOR_VERSION 1)
set(QTXDG_MINOR_VERSION 3)
set(QTXDG_MAJOR_VERSION 2)
set(QTXDG_MINOR_VERSION 0)
set(QTXDG_PATCH_VERSION 0)
set(QTXDG_VERSION_STRING ${QTXDG_MAJOR_VERSION}.${QTXDG_MINOR_VERSION}.${QTXDG_PATCH_VERSION})
@ -38,6 +38,7 @@ include(create_pkgconfig_file)
include(compiler_settings NO_POLICY_SCOPE)
find_package(Qt5Widgets REQUIRED QUIET)
find_package(Qt5Svg REQUIRED QUIET)
find_package(Qt5Xml REQUIRED QUIET)
find_package(Qt5DBus REQUIRED QUIET)
@ -56,7 +57,7 @@ set(QTXDGX_PKG_CONFIG_DESCRIPTION "Qt5Xdg, a Qt5 implementation of XDG standards
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_ICONLOADER_PKG_CONFIG_REQUIRES "Qt5Gui, Qt5Svg")
set(QTXDGX_INTREE_INCLUDEDIR "${CMAKE_CURRENT_BINARY_DIR}/InTreeBuild/include")

@ -1,21 +1,27 @@
##Overview
# libqtxdg
```libqtxdg``` is a Qt implementation of freedesktop.org XDG specifications which is built with Qt5.
## Overview
##Dependencies
`libqtxdg` is a Qt 5 implementation of freedesktop.org XDG specifications.
- Qt5
It is maintained by the LXQt project and nearly all LXQt components are depending on it. Yet it can be used independently from this desktop environment, too.
##Configuration
The library is able to use GTK+ icon theme caches for faster icon lookup. The cache file can be generated with utility `gtk-update-icon-cache` on a theme directory. If the cache is not present, corrupted, or outdated, the normal slow lookup is still run.
```libqtxdg``` uses the CMake build system. Everything that applies to CMake also
applies here.
## Installation
###Configuration options:
BUILD_TESTS Builds tests, defaults to OFF
BUILD_DEV_UTILS Builds and install development utils, defaults to OFF
### Sources
###Configuration Examples:
Build library and build self tests: ```cmake -DBUILD_TESTS=ON ..```
At runtime qtbase is needed. gtk-update-icon-cache represents an optional runtime dependency for the reasons stated above.
Additional build dependencies are CMake, qtsvg, qttools and optionally Git to pull latest VCS checkouts.
Build the library without building self tests : ```cmake ..```
The code configuration is handled by CMake so all corresponding generic instructions apply. Specific CMake variables are
* BUILD_TESTS to build tests. Disabled by default (`OFF`).
* BUILD_DEV_UTILS which builds and installs development utils. Disabled by default as well.
To build and install run `make` and `make install`respectively.
### Binary packages
The library is provided by all major Linux distributions like Arch Linux, Debian, Fedora and openSUSE.
Just use the distributions' package managers to search for string `libqtxdg`.

@ -3,6 +3,7 @@
include(CMakeFindDependencyMacro)
find_dependency(Qt5Gui)
find_dependency(Qt5Svg)
if (CMAKE_VERSION VERSION_GREATER 2.8.12)
cmake_policy(SET CMP0024 OLD)

@ -54,6 +54,7 @@ target_include_directories(${QTXDGX_ICONLOADER_LIBRARY_NAME}
target_link_libraries(${QTXDGX_ICONLOADER_LIBRARY_NAME}
PUBLIC
Qt5::Gui
Qt5::Svg
)
set_target_properties(${QTXDGX_ICONLOADER_LIBRARY_NAME}

@ -42,12 +42,11 @@
#include <QtGui/QIconEngine>
#include <QtGui/QPalette>
#include <QtCore/QList>
#include <QtCore/QHash>
#include <QtCore/QDir>
#include <QtCore/QSettings>
#include <QtGui/QPainter>
#ifdef Q_WS_MAC
#ifdef Q_DEAD_CODE_FROM_QT4_MAC
#include <private/qt_cocoa_helpers_mac_p.h>
#endif
@ -74,9 +73,6 @@ XdgIconLoader::XdgIconLoader() :
{
}
// We lazily initialize the loader to make static icons
// work. Though we do not officially support this.
static inline QString systemThemeName()
{
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
@ -164,6 +160,141 @@ QStringList XdgIconLoader::themeSearchPaths() const
return m_iconDirs;
}
/*!
\class QIconCacheGtkReader
\internal
Helper class that reads and looks up into the icon-theme.cache generated with
gtk-update-icon-cache. If at any point we detect a corruption in the file
(because the offsets point at wrong locations for example), the reader
is marked as invalid.
*/
class QIconCacheGtkReader
{
public:
explicit QIconCacheGtkReader(const QString &themeDir);
QVector<const char *> lookup(const QString &);
bool isValid() const { return m_isValid; }
private:
QFile m_file;
const unsigned char *m_data;
quint64 m_size;
bool m_isValid;
quint16 read16(uint offset)
{
if (offset > m_size - 2 || (offset & 0x1)) {
m_isValid = false;
return 0;
}
return m_data[offset+1] | m_data[offset] << 8;
}
quint32 read32(uint offset)
{
if (offset > m_size - 4 || (offset & 0x3)) {
m_isValid = false;
return 0;
}
return m_data[offset+3] | m_data[offset+2] << 8
| m_data[offset+1] << 16 | m_data[offset] << 24;
}
};
QIconCacheGtkReader::QIconCacheGtkReader(const QString &dirName)
: m_isValid(false)
{
QFileInfo info(dirName + QLatin1Literal("/icon-theme.cache"));
if (!info.exists() || info.lastModified() < QFileInfo(dirName).lastModified())
return;
m_file.setFileName(info.absoluteFilePath());
if (!m_file.open(QFile::ReadOnly))
return;
m_size = m_file.size();
m_data = m_file.map(0, m_size);
if (!m_data)
return;
if (read16(0) != 1) // VERSION_MAJOR
return;
m_isValid = true;
// Check that all the directories are older than the cache
auto lastModified = info.lastModified();
quint32 dirListOffset = read32(8);
quint32 dirListLen = read32(dirListOffset);
for (uint i = 0; i < dirListLen; ++i) {
quint32 offset = read32(dirListOffset + 4 + 4 * i);
if (!m_isValid || offset >= m_size || lastModified < QFileInfo(dirName + QLatin1Char('/')
+ QString::fromUtf8(reinterpret_cast<const char*>(m_data + offset))).lastModified()) {
m_isValid = false;
return;
}
}
}
static quint32 icon_name_hash(const char *p)
{
quint32 h = static_cast<signed char>(*p);
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
return h;
}
/*! \internal
lookup the icon name and return the list of subdirectories in which an icon
with this name is present. The char* are pointers to the mapped data.
For example, this would return { "32x32/apps", "24x24/apps" , ... }
*/
QVector<const char *> QIconCacheGtkReader::lookup(const QString &name)
{
QVector<const char *> ret;
if (!isValid())
return ret;
QByteArray nameUtf8 = name.toUtf8();
quint32 hash = icon_name_hash(nameUtf8.data());
quint32 hashOffset = read32(4);
quint32 hashBucketCount = read32(hashOffset);
if (!isValid() || hashBucketCount == 0) {
m_isValid = false;
return ret;
}
quint32 bucketIndex = hash % hashBucketCount;
quint32 bucketOffset = read32(hashOffset + 4 + bucketIndex * 4);
while (bucketOffset > 0 && bucketOffset <= m_size - 12) {
quint32 nameOff = read32(bucketOffset + 4);
if (nameOff < m_size && strcmp(reinterpret_cast<const char*>(m_data + nameOff), nameUtf8.constData()) == 0) {
quint32 dirListOffset = read32(8);
quint32 dirListLen = read32(dirListOffset);
quint32 listOffset = read32(bucketOffset+8);
quint32 listLen = read32(listOffset);
if (!m_isValid || listOffset + 4 + 8 * listLen > m_size) {
m_isValid = false;
return ret;
}
ret.reserve(listLen);
for (uint j = 0; j < listLen && m_isValid; ++j) {
quint32 dirIndex = read16(listOffset + 4 + 8 * j);
quint32 o = read32(dirListOffset + 4 + dirIndex*4);
if (!m_isValid || dirIndex >= dirListLen || o >= m_size) {
m_isValid = false;
return ret;
}
ret.append(reinterpret_cast<const char*>(m_data) + o);
}
return ret;
}
bucketOffset = read32(bucketOffset);
}
return ret;
}
QIconTheme::QIconTheme(const QString &themeName)
: m_valid(false)
{
@ -173,19 +304,17 @@ QIconTheme::QIconTheme(const QString &themeName)
for ( int i = 0 ; i < iconDirs.size() ; ++i) {
QDir iconDir(iconDirs[i]);
QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
if (themeIndex.exists()) {
m_contentDirs << themeDir;
m_valid = true;
QFileInfo themeDirInfo(themeDir);
QStringList themeSearchPaths = QIcon::themeSearchPaths();
foreach (QString path, themeSearchPaths)
{
if (!path.startsWith(QLatin1Char(':')) && QFileInfo(path).isDir())
m_contentDirs.append(path + QLatin1Char('/') + themeName);
}
if (themeDirInfo.isDir()) {
m_contentDirs << themeDir;
m_gtkCaches << QSharedPointer<QIconCacheGtkReader>::create(themeDir);
}
break;
if (!m_valid) {
themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
if (themeIndex.exists())
m_valid = true;
}
}
#ifndef QT_NO_SETTINGS
@ -270,7 +399,6 @@ QThemeIconInfo XdgIconLoader::findIconHelper(const QString &themeName,
}
const QStringList contentDirs = theme.contentDirs();
const QVector<XdgIconDirInfo> subDirs = theme.keyList();
const QString svgext(QLatin1String(".svg"));
const QString pngext(QLatin1String(".png"));
@ -287,6 +415,29 @@ QThemeIconInfo XdgIconLoader::findIconHelper(const QString &themeName,
// Add all relevant files
for (int i = 0; i < contentDirs.size(); ++i) {
QVector<XdgIconDirInfo> subDirs = theme.keyList();
// Try to reduce the amount of subDirs by looking in the GTK+ cache in order to save
// a massive amount of file stat (especially if the icon is not there)
auto cache = theme.m_gtkCaches.at(i);
if (cache->isValid()) {
auto result = cache->lookup(iconNameFallback);
if (cache->isValid()) {
const QVector<XdgIconDirInfo> subDirsCopy = subDirs;
subDirs.clear();
subDirs.reserve(result.count());
foreach (const char *s, result) {
QString path = QString::fromUtf8(s);
auto it = std::find_if(subDirsCopy.cbegin(), subDirsCopy.cend(),
[&](const XdgIconDirInfo &info) {
return info.path == path; } );
if (it != subDirsCopy.cend()) {
subDirs.append(*it);
}
}
}
}
QString contentDir = contentDirs.at(i) + QLatin1Char('/');
for (int j = 0; j < subDirs.size() ; ++j) {
const XdgIconDirInfo &dirInfo = subDirs.at(j);
@ -487,7 +638,7 @@ void XdgIconLoaderEngine::paint(QPainter *painter, const QRect &rect,
QIcon::Mode mode, QIcon::State state)
{
QSize pixmapSize = rect.size();
#if defined(Q_WS_MAC)
#if defined(Q_DEAD_CODE_FROM_QT4_MAC)
pixmapSize *= qt_mac_get_scalefactor();
#endif
painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
@ -693,9 +844,16 @@ void XdgIconLoaderEngine::virtual_hook(int id, void *data)
case QIconEngine::IconNameHook:
{
QString &name = *reinterpret_cast<QString*>(data);
name = m_iconName;
name = m_info.iconName;
}
break;
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
case QIconEngine::IsNullHook:
{
*reinterpret_cast<bool*>(data) = m_info.entries.isEmpty();
}
break;
#endif
default:
QIconEngine::virtual_hook(id, data);
}

@ -78,7 +78,7 @@ struct XdgIconDirInfo
short maxSize;
short minSize;
short threshold;
Type type : 4;
Type type;
};
class XdgIconLoaderEngineEntry
@ -141,6 +141,8 @@ private:
friend class XdgIconLoader;
};
class QIconCacheGtkReader;
class QIconTheme
{
public:
@ -150,12 +152,13 @@ public:
QVector <XdgIconDirInfo> keyList() { return m_keyList; }
QStringList contentDirs() { return m_contentDirs; }
bool isValid() { return m_valid; }
private:
QStringList m_contentDirs;
QVector <XdgIconDirInfo> m_keyList;
QStringList m_parents;
bool m_valid;
public:
QVector<QSharedPointer<QIconCacheGtkReader>> m_gtkCaches;
};
class XDGICONLOADER_EXPORT XdgIconLoader
@ -175,6 +178,7 @@ public:
void updateSystemTheme();
void invalidateKey() { m_themeKey++; }
void ensureInitialized();
bool hasUserTheme() const { return !m_userTheme.isEmpty(); }
private:
QThemeIconInfo findIconHelper(const QString &themeName,

Loading…
Cancel
Save