mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-06 02:32:44 +00:00
Guess device icons
Device icons for the local device is now determined by looking at what the value of the deviceType property of the ApiClient is. This property was newly introduced, so that applications using JellyfinQt can set their own device type. For other devices, a guess is made based on the client name. This guess has been derived from what Jellyfin Web does.
This commit is contained in:
parent
1b27847c94
commit
9266f65c2f
7 changed files with 86 additions and 12 deletions
|
@ -47,6 +47,7 @@ public:
|
|||
QString appName;
|
||||
QString deviceName;
|
||||
QString deviceId;
|
||||
Model::DeviceType deviceType = Model::DeviceType::Unknown;
|
||||
QString userId;
|
||||
|
||||
bool online = true;
|
||||
|
@ -135,6 +136,17 @@ const QString &ApiClient::deviceId() const {
|
|||
return d->deviceId;
|
||||
}
|
||||
|
||||
Model::DeviceType ApiClient::deviceType() const {
|
||||
Q_D(const ApiClient);
|
||||
return d->deviceType;
|
||||
}
|
||||
|
||||
void ApiClient::setDeviceType(Model::DeviceType newDeviceType) {
|
||||
Q_D(ApiClient);
|
||||
d->deviceType =newDeviceType;
|
||||
emit deviceTypeChanged();
|
||||
}
|
||||
|
||||
EventBus *ApiClient::eventbus() const {
|
||||
Q_D(const ApiClient);
|
||||
return d->eventbus;
|
||||
|
|
|
@ -32,11 +32,11 @@ QString LocalSession::name() const {
|
|||
}
|
||||
|
||||
DeviceType LocalSession::deviceType() const {
|
||||
return DeviceType::Unknown;
|
||||
return m_apiClient.deviceType();
|
||||
}
|
||||
|
||||
QString LocalSession::userName() const {
|
||||
return m_apiClient.userId();
|
||||
return QString(); //m_apiClient.userId();
|
||||
}
|
||||
|
||||
PlaybackManager *LocalSession::createPlaybackManager() const {
|
||||
|
@ -64,7 +64,42 @@ QString ControllableJellyfinSession::name() const {
|
|||
}
|
||||
|
||||
DeviceType ControllableJellyfinSession::deviceType() const {
|
||||
return DeviceType::Unknown;
|
||||
// This is surely not the best way
|
||||
// I based this of https://github.com/jellyfin/jellyfin-web/blob/45793052fa7c854ec97133878c75937065ae4650/src/utils/image.ts
|
||||
const QStringList tvDevices = {
|
||||
"Samsung Smart TV",
|
||||
"Xbox One",
|
||||
"Sony PS4",
|
||||
"Kodi",
|
||||
"Kodi JellyCon",
|
||||
"AndroidTV",
|
||||
"Android TV",
|
||||
"Infuse",
|
||||
"Jellyfin Roku",
|
||||
"DLNA"
|
||||
};
|
||||
|
||||
const QStringList pcDevices = {
|
||||
"Jellyfin Web",
|
||||
};
|
||||
|
||||
const QStringList phoneDevices = {
|
||||
"FinAmp",
|
||||
"Jellyfin Mobile (iOS)",
|
||||
"Jellyfin Mobile (iPadOS)",
|
||||
"Jellyfin Android",
|
||||
"Sailfin"
|
||||
};
|
||||
|
||||
if (tvDevices.contains(m_data->client())) {
|
||||
return DeviceType::Tv;
|
||||
} else if (pcDevices.contains(m_data->client())) {
|
||||
return DeviceType::Computer;
|
||||
} else if (phoneDevices.contains(m_data->client())) {
|
||||
return DeviceType::Phone;
|
||||
} else {
|
||||
return DeviceType::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
QString ControllableJellyfinSession::userName() const {
|
||||
|
@ -101,21 +136,23 @@ void RemoteJellyfinSessionScanner::startScanning() {
|
|||
Q_D(RemoteJellyfinSessionScanner);
|
||||
if (d->loader != nullptr) return;
|
||||
|
||||
LocalSession *localSession = new LocalSession(*d->apiClient);
|
||||
|
||||
emit resetSessions();
|
||||
emit sessionFound(new LocalSession(*d->apiClient));
|
||||
emit sessionFound(localSession);
|
||||
|
||||
Loader::GetSessionsParams params;
|
||||
params.setControllableByUserId(d->apiClient->userId());
|
||||
d->loader = new GetSessionsLoader(d->apiClient);
|
||||
d->loader->setParameters(params);
|
||||
connect(d->loader, &Loader::HTTP::GetSessionsLoader::ready, this, [this, d]() {
|
||||
connect(d->loader, &Loader::HTTP::GetSessionsLoader::ready, this, [this, d, localSession]() {
|
||||
if (d->loader == nullptr) return;
|
||||
QList<DTO::SessionInfo> sessions = d->loader->result();
|
||||
|
||||
for(auto it = sessions.begin(); it != sessions.end(); it++) {
|
||||
|
||||
// Skip this device
|
||||
if (it->jellyfinId() == d->apiClient->deviceId()) continue;
|
||||
if (it->deviceId() == localSession->id()) continue;
|
||||
|
||||
emit sessionFound(new ControllableJellyfinSession(QSharedPointer<DTO::SessionInfo>::create(*it), *d->apiClient));
|
||||
}
|
||||
|
|
|
@ -155,11 +155,13 @@ int PlaybackManager::queueIndex() const {
|
|||
|
||||
void PlaybackManager::swap(PlaybackManager &other) {
|
||||
other.queue()->clearList();
|
||||
other.queue()->appendToList(this->queue()->queueAndList());
|
||||
other.playItemInList(this->queue()->queueAndList(), this->queue()->currentItemIndexInList() >= 0
|
||||
? this->queue()->currentItemIndexInList()
|
||||
: 0);
|
||||
other.seek(position());
|
||||
if (other.queue()->listSize() > 0) {
|
||||
other.queue()->appendToList(this->queue()->queueAndList());
|
||||
other.playItemInList(this->queue()->queueAndList(), this->queue()->currentItemIndexInList() >= 0
|
||||
? this->queue()->currentItemIndexInList()
|
||||
: 0);
|
||||
other.seek(position());
|
||||
}
|
||||
}
|
||||
|
||||
void PlaybackManager::playItemId(const QString &id) {}
|
||||
|
|
|
@ -182,8 +182,12 @@ void PlaybackManager::setControllingSession(QSharedPointer<Model::ControllableSe
|
|||
// Stop playing locally when switching to another session
|
||||
if (thisIsLocal) {
|
||||
d->m_impl->stop();
|
||||
if (other != nullptr) {
|
||||
d->m_impl->swap(*other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d->m_displayQueue->setPlaylistModel(other->queue());
|
||||
d->m_impl.reset(other);
|
||||
d->m_session.swap(session);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue