2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2020-08-15 15:42:51 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-10-13 20:18:13 +00:00
|
|
|
#if !defined(_WIN32)
|
2020-08-15 15:42:51 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
#endif
|
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
#include <optional>
|
2020-10-13 20:18:13 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2020-11-02 01:13:32 +00:00
|
|
|
#include <QFileIconProvider>
|
2020-08-15 15:42:51 +00:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QString>
|
2021-12-09 08:13:04 +00:00
|
|
|
#include <QStyle>
|
2020-08-15 15:42:51 +00:00
|
|
|
|
2020-10-13 20:18:13 +00:00
|
|
|
#include "Utils.h" // std::hash<QString>()
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
class QFileInfo;
|
|
|
|
#endif
|
|
|
|
|
2020-08-15 15:42:51 +00:00
|
|
|
class QModelIndex;
|
|
|
|
|
|
|
|
class IconCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static IconCache& get();
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] constexpr auto const& folderIcon() const noexcept
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return folder_icon_;
|
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] constexpr auto const& fileIcon() const noexcept
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return file_icon_;
|
|
|
|
}
|
|
|
|
|
2020-09-03 00:28:36 +00:00
|
|
|
QIcon guessMimeIcon(QString const& filename, QIcon fallback = {}) const;
|
2020-10-13 15:33:56 +00:00
|
|
|
QIcon getMimeTypeIcon(QString const& mime_type, bool multifile) const;
|
2020-08-15 15:42:51 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
QIcon getThemeIcon(QString const& name, std::optional<QStyle::StandardPixmap> const& fallback = {}) const;
|
|
|
|
|
2020-08-15 15:42:51 +00:00
|
|
|
protected:
|
2020-11-02 01:13:32 +00:00
|
|
|
IconCache() = default;
|
2020-08-15 15:42:51 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-02 01:13:32 +00:00
|
|
|
QIcon const folder_icon_ = QFileIconProvider().icon(QFileIconProvider::Folder);
|
|
|
|
QIcon const file_icon_ = QFileIconProvider().icon(QFileIconProvider::File);
|
2020-08-15 15:42:51 +00:00
|
|
|
|
2020-10-13 15:33:56 +00:00
|
|
|
mutable std::unordered_map<QString, QIcon> name_to_icon_;
|
|
|
|
mutable std::unordered_map<QString, QIcon> name_to_emblem_icon_;
|
|
|
|
|
2020-08-15 15:42:51 +00:00
|
|
|
#if defined(_WIN32)
|
2020-10-13 20:18:13 +00:00
|
|
|
void addAssociatedFileIcon(QFileInfo const& file_info, unsigned int icon_size, QIcon& icon) const;
|
2020-08-15 15:42:51 +00:00
|
|
|
#else
|
|
|
|
mutable std::unordered_set<QString> suffixes_;
|
2020-10-13 15:33:56 +00:00
|
|
|
mutable std::unordered_map<QString, QIcon> ext_to_icon_;
|
2020-08-15 15:42:51 +00:00
|
|
|
QIcon getMimeIcon(QString const& filename) const;
|
|
|
|
#endif
|
2021-12-09 08:13:04 +00:00
|
|
|
|
|
|
|
QIcon getThemeIcon(
|
|
|
|
QString const& name,
|
|
|
|
QString const& fallbackName,
|
|
|
|
std::optional<QStyle::StandardPixmap> const& fallbackPixmap) const;
|
2020-08-15 15:42:51 +00:00
|
|
|
};
|