-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmsSender.h
63 lines (50 loc) · 1.58 KB
/
SmsSender.h
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
#ifndef SMSSENDER_H
#define SMSSENDER_H
#include "Singleton.h"
#include <QObject>
#include <QMap>
class Sms;
class SmsSender : public QObject, public Singleton<SmsSender>
{
Q_OBJECT
friend class Singleton<SmsSender>;
enum class MSG_STATE : char {SENDING = 0, SENT, DELIVERED, ERROR, CANCELLED};
struct SmsStatus
{
const int msgId;
int nbParts;
MSG_STATE state;
QPair<int, int> nbSent; //!< first is for OK, second for Errors
QPair<int, int> nbDelivered;
bool allPartsSent() const {return nbSent.first + nbSent.second == nbParts;}
bool allPartsDelivered() const {return nbDelivered.first + nbDelivered.second == nbParts;}
SmsStatus(int msgId_):
msgId(msgId_), nbParts(0), state(MSG_STATE::SENDING),
nbSent(0, 0), nbDelivered(0, 0){}
};
private:
int _nextMsgId;
QMap<int, SmsStatus*> _sendingMsgs;
long _nbMsgs;
long _nbSent;
long _nbDelivered;
long _nbErrors;
signals:
void error(const QString &txt);
void log(const QString &txt);
void sigSmsSent(int msgId, bool success);
void sigSmsDelivered(int msgId, bool success);
public:
~SmsSender();
Q_INVOKABLE int sendText(const QString &destMobile, const QString &msg);
void msgParts(int msgId, int nbParts);
void msgSent(int msgId, bool success);
void msgDelivered(int msgId, bool success);
private:
void _log(const QString &txt);
void _error(const QString &txt);
void _dispPopupOnPhone(const QString &txt);
private:
SmsSender();
};
#endif // SMSSENDER_H