Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
Toggle main menu visibility
Loading...
Searching...
No Matches
serverdiscoverymodel.h
Go to the documentation of this file.
1
/*
2
Sailfin: a Jellyfin client written using Qt
3
Copyright (C) 2021 Chris Josten
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
#ifndef SERVER_DISCOVERY_MODEL_H
21
#define SERVER_DISCOVERY_MODEL_H
22
23
#include <vector>
24
25
#include <QAbstractListModel>
26
#include <QHash>
27
#include <QJsonDocument>
28
#include <QJsonObject>
29
#include <QJsonParseError>
30
31
#include <QHostAddress>
32
#include <QUdpSocket>
33
34
namespace
Jellyfin
{
35
struct
ServerDiscovery
{
36
QString
name
;
37
QString
address
;
38
QString
id
;
39
};
40
44
class
ServerDiscoveryModel
:
public
QAbstractListModel {
45
Q_OBJECT
46
public
:
47
enum
Roles
{
48
ROLE_NAME
= Qt::UserRole + 1,
49
ROLE_ADDRESS
,
50
ROLE_ID
51
};
52
explicit
ServerDiscoveryModel
(QObject *parent =
nullptr
);
53
54
QHash<int, QByteArray>
roleNames
()
const override
{
55
return
{
56
{
ROLE_NAME
,
"name"
},
57
{
ROLE_ADDRESS
,
"address"
},
58
{
ROLE_ID
,
"id"
}
59
};
60
}
61
62
int
rowCount
(
const
QModelIndex &parent = QModelIndex())
const override
{
63
if
(parent.isValid())
return
0;
64
return
static_cast<
int
>
(m_discoveredServers.size());
65
}
66
67
QVariant
data
(
const
QModelIndex &index,
int
role = Qt::DisplayRole)
const override
;
68
public
slots:
72
void
refresh
();
73
private
slots:
74
void
on_datagramsAvailable();
75
private
:
76
const
QByteArray MAGIC_PACKET =
"who is JellyfinServer?"
;
77
const
quint16 BROADCAST_PORT = 7359;
78
79
std::vector<ServerDiscovery> m_discoveredServers;
80
QUdpSocket m_socket;
81
};
82
}
83
#endif
//SERVER_DISCOVERY_MODEL_H
Jellyfin::ServerDiscoveryModel::Roles
Roles
Definition
serverdiscoverymodel.h:47
Jellyfin::ServerDiscoveryModel::ROLE_ID
@ ROLE_ID
Definition
serverdiscoverymodel.h:50
Jellyfin::ServerDiscoveryModel::ROLE_NAME
@ ROLE_NAME
Definition
serverdiscoverymodel.h:48
Jellyfin::ServerDiscoveryModel::ROLE_ADDRESS
@ ROLE_ADDRESS
Definition
serverdiscoverymodel.h:49
Jellyfin::ServerDiscoveryModel::refresh
void refresh()
Refreshes the model and searches for new servers.
Definition
serverdiscoverymodel.cpp:44
Jellyfin::ServerDiscoveryModel::ServerDiscoveryModel
ServerDiscoveryModel(QObject *parent=nullptr)
Definition
serverdiscoverymodel.cpp:22
Jellyfin::ServerDiscoveryModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition
serverdiscoverymodel.cpp:28
Jellyfin::ServerDiscoveryModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition
serverdiscoverymodel.h:62
Jellyfin::ServerDiscoveryModel::roleNames
QHash< int, QByteArray > roleNames() const override
Definition
serverdiscoverymodel.h:54
Jellyfin
Jellyfin::ServerDiscovery
Definition
serverdiscoverymodel.h:35
Jellyfin::ServerDiscovery::address
QString address
Definition
serverdiscoverymodel.h:37
Jellyfin::ServerDiscovery::id
QString id
Definition
serverdiscoverymodel.h:38
Jellyfin::ServerDiscovery::name
QString name
Definition
serverdiscoverymodel.h:36
core
include
JellyfinQt
serverdiscoverymodel.h
Generated by
1.17.0