summaryrefslogtreecommitdiff
path: root/src/cprquerydialog.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-05-21 11:41:33 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-05-21 11:41:33 +0200
commit47bda1b593220afcd17df66fe38b6683b8500a4b (patch)
tree37ef14c3621b8469ed5f2049668bd18273f2a0cf /src/cprquerydialog.cc
parent848bd6a41575e518e3c2e19454f4b505e8d9bf1f (diff)
Reinstate cprlistener.
Diffstat (limited to 'src/cprquerydialog.cc')
-rw-r--r--src/cprquerydialog.cc37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/cprquerydialog.cc b/src/cprquerydialog.cc
index 8ea0986..c58a8ed 100644
--- a/src/cprquerydialog.cc
+++ b/src/cprquerydialog.cc
@@ -60,7 +60,8 @@ CPRQueryDialog::CPRQueryDialog(QLabel *lcpr,
cprSocket = new QTcpSocket(this);
connect(cprSocket, SIGNAL(readyRead()), SLOT(cprSocket_readyRead()));
connect(cprSocket, SIGNAL(connected()), SLOT(cprSocket_connected()));
- connect(cprSocket, SIGNAL(error(int)), SLOT(cprSocket_error(int)));
+ connect(cprSocket, SIGNAL(error(QAbstractSocket::SocketError)),
+ SLOT(cprSocket_error(QAbstractSocket::SocketError)));
lbl_cpr->setText("Indtast CPR");
@@ -113,11 +114,35 @@ CPRQueryDialog::CPRQueryDialog(QLabel *lcpr,
connect(bca,SIGNAL(clicked()), SLOT(b_c_clicked()));
this->move(175,150);
+
+ listen = new CPRListen(config->readInt("cprlisten_port"));
+ listen_timer = new QTimer(this);
+ connect(listen_timer, SIGNAL(timeout()), SLOT(listen_timeout()));
+ listen->run();
+ listen_timer->start(500); // Check every 500 ms
+
show();
}
CPRQueryDialog::~CPRQueryDialog()
{
+ // Cleanup after cpr listen
+ listen->stop();
+ // listen->wait_stop();
+ delete listen;
+}
+
+void CPRQueryDialog::listen_timeout()
+{
+ string newcpr;
+ if(listen->cprChanged()) {
+ char newcpr_buf[32];
+ newcpr = listen->getCpr();
+ sprintf(newcpr_buf, "%s-%s", newcpr.substr(0,6).c_str(), newcpr.substr(6,4).c_str());
+ //printf("cprbuf[%s]\n", newcpr_buf);
+ lbl_cpr->setText(newcpr_buf);
+ verifycpr(newcpr_buf);
+ }
}
/**
@@ -159,7 +184,7 @@ void CPRQueryDialog::b_c_clicked() { remove_all();}
void CPRQueryDialog::b_clicked(int value)
{
- printf("%d\n", value);
+ //printf("%d\n", value);
switch(value) {
case 10:
if (digits>0) digits--;
@@ -212,9 +237,9 @@ void CPRQueryDialog::remove_all()
*/
void CPRQueryDialog::insert_digit(int value)
{
- printf("insert_digit(%d)\n", value);
+ //printf("insert_digit(%d)\n", value);
char temp[3];
- printf("strlen(cpr) = %d cpr: '%s'\n", strlen(cpr), cpr);
+ //printf("strlen(cpr) = %d cpr: '%s'\n", strlen(cpr), cpr);
switch(strlen(cpr)) {
case 5: // Automaticaly add a hyphen after the sixth digit
sprintf(temp, "%d-", value);
@@ -327,8 +352,10 @@ int CPRQueryDialog::test_cpr(const char *s)
* Called if an error occurres in the corsocket connection.
* Writes out the appropriate error message.
*/
-void CPRQueryDialog::cprSocket_error(int errnum)
+void CPRQueryDialog::cprSocket_error(QAbstractSocket::SocketError err)
{
+ (void)err;
+
QString msg = QString("cprSocket encountered an error: ");
timer->stop();