summaryrefslogtreecommitdiff
path: root/src/cprquerydialog.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-05-14 14:24:34 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-05-14 14:24:34 +0200
commit0ff825e0e6fe5fc7238e3964d24779a07cb53518 (patch)
tree7b47a9fe58a09e12ed99fdfacc84fff198ce5ce1 /src/cprquerydialog.cc
parent29ae5ac36d4ffc520232ff393b2455130ec0227e (diff)
Split miav server and client apart. Port client to Qt4. Replace libraw1994 with libiec61883. Add unit tests for multiplexer and fix some bugs in it.
Diffstat (limited to 'src/cprquerydialog.cc')
-rw-r--r--src/cprquerydialog.cc95
1 files changed, 48 insertions, 47 deletions
diff --git a/src/cprquerydialog.cc b/src/cprquerydialog.cc
index 4506e42..8ea0986 100644
--- a/src/cprquerydialog.cc
+++ b/src/cprquerydialog.cc
@@ -24,13 +24,11 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <config.h>
-#ifdef USE_GUI
+#include "cprquerydialog.h"
-#include <qframe.h>
+#include <QFrame>
#include "messagebox.h"
-#include "cprquerydialog.h"
#include "miav_config.h"
CPRQueryDialog::CPRQueryDialog(QLabel *lcpr,
@@ -38,9 +36,10 @@ CPRQueryDialog::CPRQueryDialog(QLabel *lcpr,
QWidget *parent,
const char *name,
QStatusBar *status)
- : QDialog(parent, name, TRUE)
+ : QDialog(parent)
{
- setCaption(name);
+ setModal(true);
+ setWindowTitle(name);
// Load image
QPixmap pix_backspace;
@@ -58,7 +57,7 @@ CPRQueryDialog::CPRQueryDialog(QLabel *lcpr,
cpr[0] = '\0';
internalCpr[0] = '\0';
- cprSocket = new QSocket(this);
+ 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)));
@@ -70,21 +69,21 @@ CPRQueryDialog::CPRQueryDialog(QLabel *lcpr,
connect(timer, SIGNAL(timeout()), SLOT(cprSocket_timeout()));
// Generate input buttons
- QGridLayout *gl = new QGridLayout(this, 4, 3, 10, 2);
-
- QButton *b1 = createButton(this, "1", 1);
- QButton *b2 = createButton(this, "2", 2);
- QButton *b3 = createButton(this, "3", 3);
- QButton *b4 = createButton(this, "4", 4);
- QButton *b5 = createButton(this, "5", 5);
- QButton *b6 = createButton(this, "6", 6);
- QButton *b7 = createButton(this, "7", 7);
- QButton *b8 = createButton(this, "8", 8);
- QButton *b9 = createButton(this, "9", 9);
- QButton *b0 = createButton(this, "0", 0);
- QButton *bbs = createButton(this, "", 10);
- bbs->setPixmap(pix_backspace);
- QButton *bca = createButton(this, "CA", 11);
+ QGridLayout *gl = new QGridLayout(this);
+
+ QPushButton *b1 = createButton(this, "1", 1);
+ QPushButton *b2 = createButton(this, "2", 2);
+ QPushButton *b3 = createButton(this, "3", 3);
+ QPushButton *b4 = createButton(this, "4", 4);
+ QPushButton *b5 = createButton(this, "5", 5);
+ QPushButton *b6 = createButton(this, "6", 6);
+ QPushButton *b7 = createButton(this, "7", 7);
+ QPushButton *b8 = createButton(this, "8", 8);
+ QPushButton *b9 = createButton(this, "9", 9);
+ QPushButton *b0 = createButton(this, "0", 0);
+ QPushButton *bbs = createButton(this, "", 10);
+ bbs->setIcon(pix_backspace);
+ QPushButton *bca = createButton(this, "CA", 11);
gl->addWidget(b1, 0,0);
gl->addWidget(b2, 0,1);
@@ -129,7 +128,7 @@ QPushButton *CPRQueryDialog::createButton(QWidget *parent, const char *text, int
{
char buf[32];
sprintf(buf, "%d", value);
- QPushButton *q = new QPushButton(this, buf);
+ QPushButton *q = new QPushButton(this);// buf); // TODO
QFont f("Lucida", 48);
q->setFixedSize(150, 100);
@@ -213,7 +212,9 @@ void CPRQueryDialog::remove_all()
*/
void CPRQueryDialog::insert_digit(int value)
{
- char temp[2];
+ printf("insert_digit(%d)\n", value);
+ char temp[3];
+ 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);
@@ -333,21 +334,22 @@ void CPRQueryDialog::cprSocket_error(int errnum)
lbl_name->setText(NAME_NOT_AVAILABLE);
+ /* // TODO
// Print error message
switch(errnum) {
- case QSocket::ErrConnectionRefused: // if the connection was refused
+ case QTcpSocket::ErrConnectionRefused: // if the connection was refused
msg.append("ErrConnectionRefused");
break;
- case QSocket::ErrHostNotFound: // if the host was not found
+ case QTcpSocket::ErrHostNotFound: // if the host was not found
msg.append("ErrHostNotFound");
break;
- case QSocket::ErrSocketRead: // if a read from the socket failed
+ case QTcpSocket::ErrSocketRead: // if a read from the socket failed
msg.append("ErrSocketRead");
break;
}
-
- if(statusbar) statusbar->message(msg, 5000);
- MessageBox(this, "Fejl", msg, TYPE_OK, ICON_ERROR).exec();
+ */
+ if(statusbar) statusbar->showMessage(msg, 5000);
+ MessageBox(this, "Fejl", msg.toStdString().c_str(), TYPE_OK, ICON_ERROR).exec();
accept();
}
@@ -367,7 +369,7 @@ void CPRQueryDialog::cprSocket_readyRead()
if (!cprSocket->canReadLine()) return;
QString msg = QString("Recieving name from cpr database...");
- if(statusbar) statusbar->message(msg, 5000);
+ if(statusbar) statusbar->showMessage(msg, 5000);
timer->stop();
while(cprSocket->canReadLine()) {
@@ -375,13 +377,13 @@ void CPRQueryDialog::cprSocket_readyRead()
if (s.startsWith("0001")) {
name.append(s.right(s.length()-4));
lastname.append(s.right(s.length()-4));
- name.setLength(name.length()-1);
+ name = name.left(name.length()-1);
if (name.length()) name += QString(", ");
}
if (s.startsWith("0002")) {
name.append(s.right(s.length()-4));
firstname.append(s.right(s.length()-4));
- name.setLength(name.length()-1);
+ name = name.left(name.length()-1);
cprSocket->close();
lbl_name->setText(name);
accept();
@@ -408,11 +410,11 @@ void CPRQueryDialog::cprSocket_readyRead()
void CPRQueryDialog::cprSocket_connected()
{
QString msg = QString("Connected to cpr database, sending cpr number...");
- if(statusbar) statusbar->message(msg, 5000);
+ if(statusbar) statusbar->showMessage(msg, 5000);
timer->stop();
- cprSocket->writeBlock(internalCpr, 10);
- cprSocket->writeBlock("\n", 1);
+ cprSocket->write(internalCpr, 10);
+ cprSocket->write("\n", 1);
}
/**
@@ -426,29 +428,28 @@ void CPRQueryDialog::cprSocket_timeout()
lbl_name->setText(NAME_NOT_AVAILABLE);
-
+ /* // TODO
// Print connection status
switch(cprSocket->state()) {
- case QSocket::Idle: // if there is no connection
+ case QTcpSocket::Idle: // if there is no connection
msg.append("Idle");
break;
- case QSocket::HostLookup: // during a DNS lookup
+ case QTcpSocket::HostLookup: // during a DNS lookup
msg.append("HostLookup");
break;
- case QSocket::Connecting: // during TCP connection establishment
+ case QTcpSocket::Connecting: // during TCP connection establishment
msg.append("Connecting");
break;
- case QSocket::Connected: // when there is an operational connection
+ case QTcpSocket::Connected: // when there is an operational connection
msg.append("Conected");
break;
- case QSocket::Closing: // if the socket is closing down, but is not yet closed.
+ case QTcpSocket::Closing: // if the socket is closing down, but is not yet closed.
msg.append("Closing");
break;
}
-
- if(statusbar) statusbar->message(msg, 5000);
- MessageBox(this, "Fejl", msg, TYPE_OK, ICON_ERROR).exec();
+ */
+
+ if(statusbar) statusbar->showMessage(msg, 5000);
+ MessageBox(this, "Fejl", msg.toStdString().c_str(), TYPE_OK, ICON_ERROR).exec();
accept();
}
-
-#endif /* USE_GUI */