libdrmconf  0.11.3
A library to program DMR radios.
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 
22 class UserDatabase : public QAbstractTableModel
23 {
24  Q_OBJECT
25 
26 public:
28  class User {
29  public:
31  User();
33  User(const QJsonObject &obj);
34 
36  inline bool isValid() const { return 0 != id; }
37 
39  unsigned distance(unsigned id) const;
40 
42  unsigned id;
44  QString call;
46  QString name;
48  QString surname;
50  QString city;
52  QString state;
54  QString country;
56  QString comment;
57  };
58 
59 public:
63  explicit UserDatabase(unsigned updatePeriodDays=30, QObject *parent=nullptr);
64 
66  qint64 count() const;
67 
69  bool load();
71  bool load(const QString &filename);
72 
74  void sortUsers(unsigned id);
76  void sortUsers(const QSet<unsigned> &ids);
77 
79  const User &user(int idx) const;
80 
82  unsigned dbAge() const;
83 
85  int rowCount(const QModelIndex &parent=QModelIndex()) const;
87  int columnCount(const QModelIndex &parent=QModelIndex()) const;
89  QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
90 
91 signals:
93  void loaded();
95  void error(const QString &msg);
96 
97 public slots:
99  void download();
100 
101 private slots:
103  void downloadFinished(QNetworkReply *reply);
104 
105 private:
107  QVector<User> _user;
109  QNetworkAccessManager _network;
110 };
111 
112 
113 #endif // USERDATABASE_HH
Represents the user information within the UserDatabase.
Definition: userdatabase.hh:28
QString surname
The surname of the user.
Definition: userdatabase.hh:48
QString comment
Some arbitrary comment or text.
Definition: userdatabase.hh:56
QString country
The country of the user.
Definition: userdatabase.hh:54
unsigned distance(unsigned id) const
Returns the "distance" between this user and the given ID.
Definition: userdatabase.cc:32
bool isValid() const
Returns true if the entry is valid.
Definition: userdatabase.hh:36
unsigned id
The DMR ID of the user.
Definition: userdatabase.hh:42
QString call
The callsign of the user.
Definition: userdatabase.hh:44
QString city
The city of the user.
Definition: userdatabase.hh:50
QString name
The name of the user.
Definition: userdatabase.hh:46
User()
Empty constructor.
Definition: userdatabase.cc:16
QString state
The state of the user.
Definition: userdatabase.hh:52
Auto-updating DMR user database.
Definition: userdatabase.hh:23
qint64 count() const
Returns the number of users.
Definition: userdatabase.cc:62
int columnCount(const QModelIndex &parent=QModelIndex()) const
Implements the QAbstractTableModel interface, returns the number of columns.
Definition: userdatabase.cc:220
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Implements the QAbstractTableModel interface, return the entry data.
Definition: userdatabase.cc:226
int rowCount(const QModelIndex &parent=QModelIndex()) const
Implements the QAbstractTableModel interface, returns the number of rows (number of entries).
Definition: userdatabase.cc:214
bool load()
Loads all entries from the downloaded user database.
Definition: userdatabase.cc:67
unsigned dbAge() const
Returns the age of the database in days.
Definition: userdatabase.cc:205
const User & user(int idx) const
Returns the user with index idx.
Definition: userdatabase.cc:73
void loaded()
Gets emitted once the call-sign database has been loaded.
UserDatabase(unsigned updatePeriodDays=30, QObject *parent=nullptr)
Constructs the user-database.
Definition: userdatabase.cc:51
void sortUsers(unsigned id)
Sorts users with respect to the distance to the given ID.
Definition: userdatabase.cc:139
void download()
Starts the download of the user database.
Definition: userdatabase.cc:165
void error(const QString &msg)
Gets emitted if the loading of the call-sign database fails.