libdrmconf 0.13.3
A library to program DMR radios.
Loading...
Searching...
No Matches
userdatabase.hh
1#ifndef USERDATABASE_HH
2#define USERDATABASE_HH
3
4#include <QObject>
5#include <QVector>
6#include <QHash>
7#include <QJsonObject>
8#include <QNetworkAccessManager>
9#include <QAbstractTableModel>
10#include <QSortFilterProxyModel>
11#include <QGeoPositionInfoSource>
12#include <QFuture>
13
23class UserDatabase : public QAbstractTableModel
24{
25 Q_OBJECT
26
28 Q_PROPERTY(bool ready READ ready NOTIFY readyChanged FINAL)
29
30public:
32 class User {
33 public:
35 User();
37 User(const QJsonObject &obj);
38
40 inline bool isValid() const { return 0 != id; }
41
43 unsigned distance(unsigned id) const;
44
46 unsigned id;
48 QString call;
50 QString name;
52 QString surname;
54 QString city;
56 QString state;
58 QString country;
60 QString comment;
61 };
62
63public:
67 explicit UserDatabase(bool parallel, unsigned updatePeriodDays=30, QObject *parent=nullptr);
68
70 qint64 count() const;
71
73 bool exists() const;
74
76 bool load();
78 bool load(const QString &filename);
80 bool ready() const;
81
83 void sortUsers(unsigned id);
85 void sortUsers(const QSet<unsigned> &ids);
86
88 const User &user(int idx) const;
89
91 unsigned dbAge() const;
92
94 int rowCount(const QModelIndex &parent=QModelIndex()) const;
96 int columnCount(const QModelIndex &parent=QModelIndex()) const;
98 QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
99
100signals:
102 void loaded();
104 void error(const QString &msg);
107 void readyChanged(bool ready);
108
109public slots:
111 void download();
112
113private slots:
115 void downloadFinished(QNetworkReply *reply);
117 bool parse(QList<User> &users);
119 bool parse(const QString &filename, QList<User> &users);
121 bool load(const QList<User> &users);
122
123private:
125 QVector<User> _user;
127 QNetworkAccessManager _network;
129 QFuture<bool> _parsing;
130};
131
132
133#endif // USERDATABASE_HH
Represents the user information within the UserDatabase.
Definition userdatabase.hh:32
QString surname
The surname of the user.
Definition userdatabase.hh:52
QString comment
Some arbitrary comment or text.
Definition userdatabase.hh:60
QString country
The country of the user.
Definition userdatabase.hh:58
unsigned distance(unsigned id) const
Returns the "distance" between this user and the given ID.
Definition userdatabase.cc:33
bool isValid() const
Returns true if the entry is valid.
Definition userdatabase.hh:40
unsigned id
The DMR ID of the user.
Definition userdatabase.hh:46
QString call
The callsign of the user.
Definition userdatabase.hh:48
QString city
The city of the user.
Definition userdatabase.hh:54
QString name
The name of the user.
Definition userdatabase.hh:50
User()
Empty constructor.
Definition userdatabase.cc:17
QString state
The state of the user.
Definition userdatabase.hh:56
qint64 count() const
Returns the number of users.
Definition userdatabase.cc:71
void readyChanged(bool ready)
Gets emitted, once the database has been loaded or cleard.
int columnCount(const QModelIndex &parent=QModelIndex()) const
Implements the QAbstractTableModel interface, returns the number of columns.
Definition userdatabase.cc:268
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Implements the QAbstractTableModel interface, return the entry data.
Definition userdatabase.cc:274
bool ready
Get notification, once the database has been loaded.
Definition userdatabase.hh:28
UserDatabase(bool parallel, unsigned updatePeriodDays=30, QObject *parent=nullptr)
Constructs the user-database.
Definition userdatabase.cc:52
int rowCount(const QModelIndex &parent=QModelIndex()) const
Implements the QAbstractTableModel interface, returns the number of rows (number of entries).
Definition userdatabase.cc:262
bool load()
Loads all entries from the downloaded user database.
Definition userdatabase.cc:88
unsigned dbAge() const
Returns the age of the database in days.
Definition userdatabase.cc:253
const User & user(int idx) const
Returns the user with index idx.
Definition userdatabase.cc:94
void loaded()
Gets emitted once the call-sign database has been loaded.
bool exists() const
Retruns true, if the user database file exists.
Definition userdatabase.cc:76
void sortUsers(unsigned id)
Sorts users with respect to the distance to the given ID.
Definition userdatabase.cc:187
void download()
Starts the download of the user database.
Definition userdatabase.cc:213
void error(const QString &msg)
Gets emitted if the loading of the call-sign database fails.