-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncidclient.cpp
More file actions
89 lines (82 loc) · 2.59 KB
/
ncidclient.cpp
File metadata and controls
89 lines (82 loc) · 2.59 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "ncidclient.h"
#include <QtCore/QStringList>
NcidClient::NcidClient(QObject* parent): QTcpSocket(parent)
{
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
}
/**
* reads one line from the ncid server
*/
void NcidClient::readData()
{
int size = 1024;
char data[size];
this->readLine (data, size);
parseLine(QString(data));
if (this->canReadLine()) readData();
}
/**
* Checks for type of line recived from ncid server and hands
* it over to the line specific parsing function.
*
* @param line The line to parse
*/
void NcidClient::parseLine ( QString line )
{
line = line.simplified();
qDebug() << "parseLine():" << line;
if ( line.startsWith ( "200" ) ) {
emit connected(true);
} else if ( line.startsWith ( "300" ) ) {
// end of call log
} else if ( line.startsWith ( "CIDLOG:" ) ) {
parseCID(line);
} else if ( line.startsWith ( "CIDINFO:" ) ) {
// ringing
} else if ( line.startsWith ( "CID:" ) ) {
parseCID(line);
} else {
// not handeled
}
}
/**
* Parses CID and CIDLOG lines with the following format:
* CID: *DATE*18031012*TIME*1543*LINE*9876543210*NMBR*0987654321*MESG*NONE*NAME*NO NAME*
* CIDLOG: *DATE*11041012*TIME*1231*LINE*9876543210*NMBR*Anonym*MESG*NONE*NAME*NO NAME*
*
* @param line The line to parse
*/
void NcidClient::parseCID(QString line)
{
CallInfo entry;
QDate date = QDate(0,0,0);
QTime time = QTime(0,0);
QStringList f = line.split("*");
for (int i=1; i<f.length()-1; i+=2) {
if (f[i].compare("DATE",Qt::CaseInsensitive) == 0) {
date.setDate(f[i+1].right(4).toInt(),f[i+1].mid(2,2).toInt(),f[i+1].left(2).toInt());
}
else if (f[i].compare("TIME",Qt::CaseInsensitive) == 0) {
time = QTime::fromString(f[i+1],"hhmm");
}
else if (f[i].compare("LINE",Qt::CaseInsensitive) == 0) {
entry.phoneLine = f[i+1];
}
else if (f[i].compare("NMBR",Qt::CaseInsensitive) == 0) {
entry.phoneNmbr = f[i+1];
}
else if (f[i].compare("NAME",Qt::CaseInsensitive) == 0) {
entry.name = f[i+1];
}
else if (f[i].compare("MESG",Qt::CaseInsensitive) == 0) {
entry.msg = f[i+1];
}
else {
qDebug() << "parseCID(): Unkown part:" << f[i+1];
}
}
entry.date = QDateTime(date, time);
emit newCallInfo(entry);
qDebug() << "parseCID(): Number:" << entry.phoneNmbr << "Time:" << entry.date.toString();
if (line.startsWith("CID:",Qt::CaseInsensitive)) emit incomingCall(entry);
}