mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
Move `FavIconCache` into a new `transmission::app` namespace. I intend to add a couple more pieces into libtransmission to avoid code duplication between the Qt and GTK apps. We should consider making another module for these pieces if they start to pile up; but for now, let's cordon them into their own namespace.
52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
|
|
// This file Copyright © Mnemosyne LLC.
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
// License text can be found in the licenses/ folder.
|
|
|
|
#include <libtransmission/favicon-cache.h>
|
|
|
|
#include <QApplication>
|
|
#include <QPixmap>
|
|
#include <QStandardPaths>
|
|
|
|
using namespace transmission::app;
|
|
using Icon = QPixmap;
|
|
|
|
template<>
|
|
Icon FaviconCache<Icon>::create_from_file(std::string_view filename) const // NOLINT(readability-identifier-naming)
|
|
{
|
|
auto icon = QPixmap{};
|
|
if (!icon.load(QString::fromUtf8(std::data(filename), std::size(filename))))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
return icon.scaled({ Width, Height }, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
}
|
|
|
|
template<>
|
|
Icon FaviconCache<Icon>::create_from_data(void const* data, size_t datalen) const // NOLINT(readability-identifier-naming)
|
|
{
|
|
auto icon = QPixmap{};
|
|
if (!icon.loadFromData(static_cast<uchar const*>(data), datalen))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
return icon.scaled({ Width, Height }, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
}
|
|
|
|
template<>
|
|
std::string FaviconCache<Icon>::app_cache_dir() const // NOLINT(readability-identifier-naming)
|
|
{
|
|
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toStdString();
|
|
}
|
|
|
|
template<>
|
|
void FaviconCache<Icon>::add_to_ui_thread(std::function<void()> idlefunc) // NOLINT(readability-identifier-naming)
|
|
{
|
|
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
|
|
QMetaObject::invokeMethod(qApp, std::move(idlefunc), Qt::QueuedConnection);
|
|
}
|