libdrmconf  0.11.3
A library to program DMR radios.
contact.hh
1 #ifndef CONTACT_HH
2 #define CONTACT_HH
3 
4 #include "configobject.hh"
5 #include <QVector>
6 #include <QAbstractTableModel>
7 
8 #include "anytone_extension.hh"
9 #include "opengd77_extension.hh"
10 
11 class Config;
12 
13 
17 class Contact: public ConfigObject
18 {
19  Q_OBJECT
20  Q_CLASSINFO("IdPrefix", "cont")
21 
22 
23  Q_PROPERTY(bool ring READ ring WRITE setRing)
24 
25 protected:
27  explicit Contact(QObject *parent=nullptr);
32  Contact(const QString &name, bool ring=true, QObject *parent=nullptr);
33 
34 public:
35  void clear();
36 
37 public:
39  bool ring() const;
41  void setRing(bool enable);
42 
46  template <class T>
47  bool is() const {
48  return 0 != dynamic_cast<const T *>(this);
49  }
51  template<class T>
52  T *as() {
53  return dynamic_cast<T *>(this);
54  }
56  template<class T>
57  const T *as() const {
58  return dynamic_cast<const T *>(this);
59  }
60 
61 public:
62  bool parse(const YAML::Node &node, Context &ctx, const ErrorStack &err=ErrorStack());
63  bool link(const YAML::Node &node, const Context &ctx, const ErrorStack &err=ErrorStack());
64 
65 protected:
67  bool _ring;
68 };
69 
70 
73 class AnalogContact: public Contact
74 {
75  Q_OBJECT
76 
77 protected:
79  explicit AnalogContact(QObject *parent=nullptr);
80 
82  AnalogContact(const QString &name, bool rxTone, QObject *parent=nullptr);
83 };
84 
85 
89 {
90  Q_OBJECT
91 
93  Q_PROPERTY(QString number READ number WRITE setNumber)
94 
95 public:
97  explicit DTMFContact(QObject *parent=nullptr);
103  DTMFContact(const QString &name, const QString &number, bool ring=false, QObject *parent=nullptr);
104 
105  ConfigItem *clone() const;
106  void clear();
107 
110  const QString &number() const;
112  bool setNumber(const QString &number);
113 
114 public:
115  YAML::Node serialize(const Context &context, const ErrorStack &err=ErrorStack());
116 
117 protected:
119  QString _number;
120 };
121 
122 
125 class DigitalContact: public Contact
126 {
127  Q_OBJECT
128 
129 protected:
131  explicit DigitalContact(QObject *parent=nullptr);
132 
134  DigitalContact(const QString &name, bool ring, QObject *parent=nullptr);
135 };
136 
137 
141 {
142  Q_OBJECT
143 
145  Q_PROPERTY(Type type READ type WRITE setType)
147  Q_PROPERTY(unsigned number READ number WRITE setNumber)
152 
153 public:
155  typedef enum {
158  AllCall
159  } Type;
160  Q_ENUM(Type)
161 
162 public:
164  explicit DMRContact(QObject *parent=nullptr);
165 
172  DMRContact(Type type, const QString &name, unsigned number, bool ring=false, QObject *parent=nullptr);
173 
174  ConfigItem *clone() const;
175  void clear();
176 
178  Type type() const;
180  void setType(Type type);
182  unsigned number() const;
184  bool setNumber(unsigned number);
185 
190 
195 
196 public:
197  YAML::Node serialize(const Context &context, const ErrorStack &err=ErrorStack());
198 
199 protected:
203  unsigned _number;
208 };
209 
210 
223 {
224  Q_OBJECT
225 
226 public:
228  explicit ContactList(QObject *parent=nullptr);
229 
230  int add(ConfigObject *obj, int row=-1);
231 
233  int digitalCount() const;
235  int dtmfCount() const;
236 
238  Contact *contact(int idx) const;
240  DMRContact *digitalContact(int idx) const;
242  DMRContact *findDigitalContact(unsigned number) const;
244  DTMFContact *dtmfContact(int idx) const;
245 
246 public:
247  ConfigItem *allocateChild(const YAML::Node &node, ConfigItem::Context &ctx, const ErrorStack &err=ErrorStack());
248 };
249 
250 #endif // CONTACT_HH
Base class for all analog contacts.
Definition: contact.hh:74
AnalogContact(QObject *parent=nullptr)
Hidden constructor.
Definition: contact.cc:62
Implements the AnyTone contact extension.
Definition: anytone_extension.hh:313
Parse context for config objects.
Definition: configobject.hh:48
Base class for all configuration objects (channels, zones, contacts, etc).
Definition: configobject.hh:40
List class for config objects.
Definition: configobject.hh:341
Base class of all labeled and named objects.
Definition: configobject.hh:199
QString name
The name of the object.
Definition: configobject.hh:203
The config class, representing the codeplug configuration.
Definition: config.hh:69
Represents the list of contacts within the abstract radio configuration.
Definition: contact.hh:223
Contact * contact(int idx) const
Returns the contact at index idx.
Definition: contact.cc:291
int dtmfCount() const
Returns the number of DTMF contacts.
Definition: contact.cc:281
int digitalCount() const
Returns the number of digital contacts.
Definition: contact.cc:272
ConfigItem * allocateChild(const YAML::Node &node, ConfigItem::Context &ctx, const ErrorStack &err=ErrorStack())
Allocates a member objects for the given YAML node.
Definition: contact.cc:335
DMRContact * digitalContact(int idx) const
Returns the digital contact at index idx among digital contacts.
Definition: contact.cc:298
DTMFContact * dtmfContact(int idx) const
Returns the DTMF contact at index idx among DTMF contacts.
Definition: contact.cc:322
ContactList(QObject *parent=nullptr)
Constructs an empty contact list.
Definition: contact.cc:258
DMRContact * findDigitalContact(unsigned number) const
Searches for a digital contact with the given number.
Definition: contact.cc:311
int add(ConfigObject *obj, int row=-1)
Adds an element to the list.
Definition: contact.cc:265
Represents the base-class for all contact types, analog (DTMF) or digital (DMR, M17).
Definition: contact.hh:18
bool link(const YAML::Node &node, const Context &ctx, const ErrorStack &err=ErrorStack())
Links the given object to the rest of the codeplug using the given context.
Definition: contact.cc:54
void setRing(bool enable)
Enables/disables the ring-tone for this contact.
Definition: contact.cc:33
bool parse(const YAML::Node &node, Context &ctx, const ErrorStack &err=ErrorStack())
Parses the given YAML node, updates the given object and updates the given context (IDs).
Definition: contact.cc:39
Contact(QObject *parent=nullptr)
Default constructor.
Definition: contact.cc:10
const T * as() const
Typecast contact.
Definition: contact.hh:57
void clear()
Clears the config object.
Definition: contact.cc:23
T * as()
Typecast contact.
Definition: contact.hh:52
bool is() const
Typecheck contact.
Definition: contact.hh:47
bool _ring
Ringtone enabled?
Definition: contact.hh:67
bool ring
If true and supported by radio, ring on call from this contact.
Definition: contact.hh:23
Represents a digital contact, that is a DMR number.
Definition: contact.hh:141
void setAnytoneExtension(AnytoneContactExtension *ext)
Sets the AnyTone extension.
Definition: contact.cc:243
void clear()
Clears the config object.
Definition: contact.cc:174
AnytoneContactExtension * anytone
The AnyTone extension to the digital contact.
Definition: contact.hh:149
OpenGD77ContactExtension * openGD77ContactExtension() const
Returns the OpenGD77 extension, or nullptr if not set.
Definition: contact.cc:221
OpenGD77ContactExtension * _openGD77
Owns the OpenGD77 extensions to the digital contacts.
Definition: contact.hh:207
ConfigItem * clone() const
Clones this item.
Definition: contact.cc:164
Type type
The type of the contact.
Definition: contact.hh:145
void setOpenGD77ContactExtension(OpenGD77ContactExtension *ext)
Sets the OpenGD77 extension.
Definition: contact.cc:226
DMRContact(QObject *parent=nullptr)
Default constructor.
Definition: contact.cc:151
AnytoneContactExtension * anytoneExtension() const
Returns the AnyTone extension, or nullptr if not set.
Definition: contact.cc:238
OpenGD77ContactExtension * openGD77
The OpenGD77 extension to the digital contact.
Definition: contact.hh:151
unsigned _number
The DMR number of the contact.
Definition: contact.hh:203
void setType(Type type)
(Re-)Sets the call-type.
Definition: contact.cc:192
bool setNumber(unsigned number)
(Re-)Sets the DMR number of the contact.
Definition: contact.cc:202
unsigned number
The number of the contact.
Definition: contact.hh:147
Type _type
The call type.
Definition: contact.hh:201
Type
Possible call types for a contact.
Definition: contact.hh:155
@ AllCall
An all-call.
Definition: contact.hh:158
@ PrivateCall
A private call.
Definition: contact.hh:156
@ GroupCall
A group call.
Definition: contact.hh:157
AnytoneContactExtension * _anytone
Owns the AnytoneContactextension to the digital contacts.
Definition: contact.hh:205
YAML::Node serialize(const Context &context, const ErrorStack &err=ErrorStack())
Recursively serializes the configuration to YAML nodes.
Definition: contact.cc:209
Represents an analog contact, that is a DTMF number.
Definition: contact.hh:89
YAML::Node serialize(const Context &context, const ErrorStack &err=ErrorStack())
Recursively serializes the configuration to YAML nodes.
Definition: contact.cc:121
bool setNumber(const QString &number)
(Re-)Sets the DTMF number of this contact.
Definition: contact.cc:112
ConfigItem * clone() const
Clones this item.
Definition: contact.cc:91
QString number
The contact number.
Definition: contact.hh:93
DTMFContact(QObject *parent=nullptr)
Default constructor.
Definition: contact.cc:78
void clear()
Clears the config object.
Definition: contact.cc:101
QString _number
The DTMF number.
Definition: contact.hh:119
Base class for all digital contacts.
Definition: contact.hh:126
DigitalContact(QObject *parent=nullptr)
Hidden constructor.
Definition: contact.cc:135
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
Implements the contact extensions for the OpenGD77 radios.
Definition: opengd77_extension.hh:81