1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-28 01:01:21 +01:00

Improve device icon loading

This commit is contained in:
Jonas Kvinge 2021-05-04 21:55:05 +02:00
parent 5fbdbffa23
commit 240dcf2e5c
3 changed files with 39 additions and 26 deletions

View File

@ -98,29 +98,41 @@ void DeviceInfo::LoadIcon(const QVariantList &icons, const QString &name_hint) {
// Try to load the icon with that exact name first
for (const QVariant &icon : icons) {
if (!icon.value<QPixmap>().isNull()) {
if (icon.isNull()) continue;
if (icon.userType() == QMetaType::QString) {
QString icon_name = icon.toString();
if (!icon_name.isEmpty()) {
icon_ = IconLoader::Load(icon_name);
if (!icon_.isNull()) {
icon_name_ = icon_name;
return;
}
}
}
else if (!icon.value<QPixmap>().isNull()) {
icon_ = QIcon(icon.value<QPixmap>());
return;
}
else {
if (!icon.toString().isEmpty()) icon_ = IconLoader::Load(icon.toString());
if (!icon_.isNull()) {
icon_name_ = icon.toString();
return;
}
for (const QVariant &icon : icons) {
if (!icon.isNull() && icon.userType() == QMetaType::QString) {
QString icon_name = icon.toString();
if (!icon_name.isEmpty()) {
QString hint = QString(icons.first().toString() + name_hint).toLower();
if (hint.contains("phone")) icon_name_ = "device-phone";
else if (hint.contains("ipod") || hint.contains("apple")) icon_name_ = "device-ipod";
else if ((hint.contains("usb")) && (hint.contains("reader"))) icon_name_ = "device-usb-flash";
else if (hint.contains("usb")) icon_name_ = "device-usb-drive";
icon_ = IconLoader::Load(icon_name_);
if (!icon_.isNull()) {
return;
}
}
}
}
QString hint = QString(icons.first().toString() + name_hint).toLower();
if (hint.contains("phone")) icon_name_ = "device-phone";
else if (hint.contains("ipod") || hint.contains("apple")) icon_name_ = "device-ipod";
else if ((hint.contains("usb")) && (hint.contains("reader"))) icon_name_ = "device-usb-flash";
else if (hint.contains("usb")) icon_name_ = "device-usb-drive";
else icon_name_ = "device";
icon_name_ = "device";
icon_ = IconLoader::Load(icon_name_);
}

View File

@ -30,8 +30,7 @@
#include <QFile>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QStringBuilder>
#include <QVariantList>
#include <QUrl>
#include "devicelister.h"
@ -228,15 +227,15 @@ bool DeviceLister::IsIpod(const QString &path) const {
QFile::exists(path + "/iTunes/iTunes_Control");
}
QStringList DeviceLister::GuessIconForPath(const QString &path) {
QVariantList DeviceLister::GuessIconForPath(const QString &path) {
QStringList ret;
QVariantList ret;
#ifdef HAVE_LIBGPOD
if (IsIpod(path)) {
Itdb_Device* device = itdb_device_new();
Itdb_Device *device = itdb_device_new();
itdb_device_set_mountpoint(device, path.toLocal8Bit().constData());
const Itdb_IpodInfo* info = itdb_device_get_ipod_info(device);
const Itdb_IpodInfo *info = itdb_device_get_ipod_info(device);
if (info->ipod_model == ITDB_IPOD_MODEL_INVALID) {
ret << "device-ipod";
@ -271,9 +270,9 @@ QStringList DeviceLister::GuessIconForPath(const QString &path) {
}
QStringList DeviceLister::GuessIconForModel(const QString &vendor, const QString &model) {
QVariantList DeviceLister::GuessIconForModel(const QString &vendor, const QString &model) {
QStringList ret;
QVariantList ret;
if (vendor.startsWith("Google") && model.contains("Nexus")) {
ret << "phone-google-nexus-one";
}

View File

@ -28,6 +28,8 @@
#include <QObject>
#include <QList>
#include <QMetaType>
#include <QVariantList>
#include <QVariantMap>
#include <QString>
#include <QStringList>
#include <QUrl>
@ -91,8 +93,8 @@ class DeviceLister : public QObject {
QUrl MakeUrlFromLocalPath(const QString &path) const;
bool IsIpod(const QString &path) const;
QStringList GuessIconForPath(const QString &path);
QStringList GuessIconForModel(const QString &vendor, const QString &model);
QVariantList GuessIconForPath(const QString &path);
QVariantList GuessIconForModel(const QString &vendor, const QString &model);
protected:
QThread *thread_;