File: talkgroupdatabase.hh

package info (click to toggle)
qdmr 0.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,420 kB
  • sloc: cpp: 95,929; xml: 10,749; python: 1,108; makefile: 78; sh: 9
file content (74 lines) | stat: -rw-r--r-- 2,436 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef TALKGROUPDATABASE_HH
#define TALKGROUPDATABASE_HH

#include <QAbstractTableModel>
#include <QNetworkAccessManager>

/** Downloads, periodically updates and provides a list of talk group IDs and their names.
 *
 * @ingroup utils */
class TalkGroupDatabase : public QAbstractTableModel
{
  Q_OBJECT

  /** A talk group entry in the database. */
  class TalkGroup {
  public:
    /** Empty constructor. */
    TalkGroup();
    /** Constructor form name and DMR ID. */
    TalkGroup(const QString &name, unsigned number);
    /** The DMR ID of the talk group. */
    unsigned id;
    /** The Name of the talk group. */
    QString name;
  };

public:
  /** Constructs a talk group database.
   * @param updatePeriodDays Specifies the update period of the DB in days.
   * @param parent Specifies the QObject parent. */
  TalkGroupDatabase(unsigned updatePeriodDays=30, QObject *parent=nullptr);

  /** Returns the number of talk groups. */
  qint64 count() const;
  /** Returns the age of the database in days. */
  unsigned dbAge() const;

  /** Returns the talk group entry at the given index. */
  TalkGroup talkgroup(int index) const;

  /** Loads all entries from the downloaded talk group db. */
  bool load();
  /** Loads all entries from the talk group db at the specified location. */
  bool load(const QString &filename);

  /** Implements the QAbstractTableModel interface, returns the number of rows (number of entries). */
  int rowCount(const QModelIndex &parent=QModelIndex()) const;
  /** Implements the QAbstractTableModel interface, returns the number of columns. */
  int columnCount(const QModelIndex &parent=QModelIndex()) const;
  /** Implements the QAbstractTableModel interface, return the entry data. */
  QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;

signals:
  /** Gets emitted once the talk group database has been loaded. */
  void loaded();
  /** Gets emitted if the loading of the talk group database fails. */
  void error(const QString &msg);

public slots:
  /** Starts the download of the talk group database. */
  void download();

private slots:
  /** Gets called whenever the download is complete. */
  void downloadFinished(QNetworkReply *reply);

protected:
  /** Holds all talk groups as id->name table. */
  QVector<TalkGroup>    _talkgroups;
  /** The network access used for downloading. */
  QNetworkAccessManager _network;
};

#endif // TALKGROUPDATABASE_HH