1
/***************************************************************************
2
* Copyright (C) 2005 by Volker Schroer *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#include "processlogdata.h"
23
#include <QHostAddress>
25
#include <QMessageBox>
28
ProcessLogData::ProcessLogData ( QObject *parent )
32
connectionEstablished = false;
33
connectionError = false;
37
ProcessLogData::~ProcessLogData()
40
void ProcessLogData::saveQsoData ( QString s )
42
qDebug ( "Request save" );
47
void ProcessLogData::requestCallSign ( QLabel **r, QString s )
49
qDebug ( "Request Callsign" );
50
requestType = Request;
52
actionString.append ( "@@@@" );
53
actionString.append ( s );
54
actionString.append ( "\r\n" );
56
for ( int i = 0; i < 6;i++ )
60
void ProcessLogData::run()
62
connectionEstablished = false;
63
connectionError = false;
64
qRegisterMetaType<QAbstractSocket::SocketError> ( "QAbstractSocket::SocketError" );
65
tcpSocket = new QTcpSocket();
66
connect ( tcpSocket, SIGNAL ( disconnected() ), this, SLOT ( connectionClosedbyHost() ) );
67
connect ( tcpSocket, SIGNAL ( readyRead() ), this, SLOT ( readAnswer() ) );
68
connect ( tcpSocket, SIGNAL ( connected() ), this, SLOT ( setConnected() ) );
69
connect ( tcpSocket, SIGNAL ( error ( QAbstractSocket::SocketError ) ), this, SLOT ( setError ( QAbstractSocket::SocketError ) ) );
70
tcpSocket->connectToHost ( QHostAddress::LocalHost, 8080, QIODevice::ReadWrite );
73
void ProcessLogData::doAction()
75
if ( !connectionEstablished )
77
if ( !connectionEstablished && tcpSocket->state() != 3)
79
qDebug ( "Waiting for Socket timed out: %d",tcpSocket->state() );
80
QMessageBox::StandardButton reply;
81
reply = QMessageBox::question ( 0, "LinPSK", tr ( "Cannot connect to LinLogBook\nTry again later ?" ), QMessageBox::Yes | QMessageBox::No );
82
if ( reply == QMessageBox::No )
83
emit unabletoConnect();
91
// if ( tcpSocket->state() != QAbstractSocket::ConnectedState )
94
qDebug ( "SocketError %d", tcpSocket->state() );
95
if ( tcpSocket->state() == QAbstractSocket::UnconnectedState )
97
QMessageBox::information ( 0, "LinPSK", tr ( "Cannot connect to LinLogBook" ) );
100
int n = tcpSocket->write ( actionString.toLatin1(), actionString.length() );
101
qDebug ( "Written %d, to be written %d", n, actionString.length() );
102
if ( n < 0 ) // Retry
105
n = tcpSocket->write ( actionString.toLatin1(), actionString.length() );
106
qDebug ( "Written %d, to be written %d", n, actionString.length() );
110
void ProcessLogData::connectionClosedbyHost()
112
connectionEstablished = false;
113
if ( tcpSocket != 0 )
120
void ProcessLogData::readAnswer()
122
qDebug ( "Read Answer" );
123
//Has to be improved, to get safer
126
for ( i = 0; i < 6; i++ )
128
while ( ! tcpSocket->canReadLine() )
130
s = QLatin1String ( tcpSocket->readLine() );
131
s.remove ( QLatin1Char ( '\n' ) );
132
results[i]->setText ( s );
135
qDebug ( "%d Zeilen gelesen", i );
136
emit answerAvailable();
138
void ProcessLogData::setConnected()
140
connectionEstablished = true;
142
void ProcessLogData::setError ( QAbstractSocket::SocketError )
144
connectionEstablished = false;
145
connectionError = true;
146
if ( tcpSocket != 0 )
147
qDebug ( "SocketError %d", tcpSocket->state() );