2015-01-14 18:51:30 +00:00
/***************************************************************************
dxcluster . cpp - description
- - - - - - - - - - - - - - - - - - -
begin : oct 2011
copyright : ( C ) 2011 by Jaime Robles
email : jaime @ robles . es
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*****************************************************************************
* This file is part of KLog . *
* *
* KLog is free software : you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation , either version 3 of the License , or *
* ( at your option ) any later version . *
* *
* KLog is distributed in the hope that it will be useful , *
* but WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the *
* GNU General Public License for more details . *
* *
* You should have received a copy of the GNU General Public License *
* along with KLog . If not , see < http : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "dxcluster.h"
DXClusterWidget : : DXClusterWidget ( QWidget * parent )
: QWidget ( parent )
{
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::DXClusterWidget" << endl;
2015-01-14 18:51:30 +00:00
awards = new Awards ( ) ;
2017-09-07 07:07:20 +00:00
dataProxy = new DataProxy_SQLite ( ) ;
2017-05-06 17:27:18 +00:00
2015-01-14 18:51:30 +00:00
initClass ( ) ;
2017-05-01 08:14:16 +00:00
//TESTADDSPOT();
2015-01-14 18:51:30 +00:00
}
void DXClusterWidget : : initClass ( )
{
dxClusterConnected = false ;
dxClusterAlreadyConnected = false ;
showhf = true ;
showvhf = true ;
showwarc = true ;
showworked = true ;
showconfirmed = true ;
showann = true ;
showwwv = true ;
showwcy = true ;
2017-05-06 17:27:18 +00:00
myQrz = QString ( ) ;
2015-01-14 18:51:30 +00:00
currentLog = 0 ;
}
2017-05-06 17:27:18 +00:00
void DXClusterWidget : : setMyQRZ ( const QString _qrz )
{
if ( _qrz . length ( ) > 2 )
{
myQrz = _qrz ;
}
}
2015-01-14 18:51:30 +00:00
DXClusterWidget : : DXClusterWidget ( const QString & clusterToConnect , const int portToConnect , QWidget * parent )
: QWidget ( parent )
{
2015-08-17 15:54:45 +00:00
//qDebug() << "DXClusterWidget::DXClusterWidget" << clusterToConnect << QString::number(portToConnect) << endl;
2015-01-14 18:51:30 +00:00
initClass ( ) ;
server = clusterToConnect ;
port = portToConnect ;
dxSpotColor . setNamedColor ( " slategrey " ) ;
//defaultColor.setNamedColor("slategrey");
//neededColor.setNamedColor("slategrey");
//workedColor.setNamedColor("slategrey");
//confirmedColor.setNamedColor("slategrey");
//newOneColor.setNamedColor("slategrey");
world = new World ( ) ;
awards = new Awards ( ) ;
dataProxy = new DataProxy_SQLite ( ) ;
tcpSocket = new QTcpSocket ( this ) ;
dxClusterListWidget = new QListWidget ( ) ;
inputCommand = new QLineEdit ;
sendButton = new QPushButton ;
clearButton = new QPushButton ;
inputCommand - > setDisabled ( true ) ;
inputCommand - > setToolTip ( tr ( " Click on Connect to connect to the DX-Cluster server " ) ) ;
dxClusterListWidget - > setMouseTracking ( true ) ;
sendButton - > setText ( tr ( " Connect " ) ) ;
clearButton - > setText ( tr ( " Clear " ) ) ;
QHBoxLayout * bottonLayout = new QHBoxLayout ;
bottonLayout - > addWidget ( inputCommand ) ;
bottonLayout - > addWidget ( sendButton ) ;
bottonLayout - > addWidget ( clearButton ) ;
QVBoxLayout * layout = new QVBoxLayout ;
layout - > addWidget ( dxClusterListWidget ) ;
layout - > addLayout ( bottonLayout ) ;
setLayout ( layout ) ;
connect ( sendButton , SIGNAL ( clicked ( ) ) , this , SLOT ( slotClusterSendToServer ( ) ) ) ;
connect ( inputCommand , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( slotClusterInputTextChanged ( ) ) ) ;
//connect(searchResultsTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotDoubleClickSearch(QTreeWidgetItem *, int)));
connect ( dxClusterListWidget , SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ) , this , SLOT ( slotClusterDXClusterWidgetItemDoubleClicked ( QListWidgetItem * ) ) ) ;
connect ( dxClusterListWidget , SIGNAL ( itemEntered ( QListWidgetItem * ) ) , this , SLOT ( slotClusterDXClusterWidgetItemEntered ( QListWidgetItem * ) ) ) ;
connect ( dxClusterListWidget , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( slotClusterDXClusterWidgetItemSelected ( ) ) ) ;
//void QListWidget::itemDoubleClicked ( QListWidgetItem * item ) [signal]
// TO BE DELETED
addData ( ) ;
2017-05-01 08:14:16 +00:00
//TESTADDSPOT();
2015-01-14 18:51:30 +00:00
}
void DXClusterWidget : : addData ( )
{
//qDebug() << "DXClusterWidget::addData " << endl;
2017-08-07 13:46:53 +00:00
/*
QTreeWidgetItem * item = new QTreeWidgetItem ( searchResultsTreeWidget ) ;
i = world - > getQRZARRLId ( _call ) ;
aux = world - > getEntityName ( i ) + " - CQ: " + QString : : number ( world - > getEntityCqz ( i ) ) ;
item - > setToolTip ( 0 , aux ) ;
item - > setToolTip ( 1 , aux ) ;
item - > setToolTip ( 2 , aux ) ;
item - > setToolTip ( 3 , aux ) ;
item - > setToolTip ( 4 , aux ) ;
item - > setToolTip ( 5 , aux ) ;
item - > setToolTip ( 6 , aux ) ;
*/
2015-01-14 18:51:30 +00:00
dxClusterSpotItem * item = new dxClusterSpotItem ( dxClusterListWidget , tr ( " Click on connect to connect to the DX-Cluster " ) , awards - > getDefaultColor ( ) ) ;
}
DXClusterWidget : : ~ DXClusterWidget ( )
{
//qDebug() << "DXClusterWidget::~DXClusterWidget" << endl;
}
void DXClusterWidget : : slotClusterDXClusterWidgetItemDoubleClicked ( QListWidgetItem * item )
{
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked: " << item->text() << endl;
2015-01-14 18:51:30 +00:00
QStringList ql ;
ql . clear ( ) ;
if ( item )
{
ql = readItem ( item ) ;
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked: Length: " << QString::number(ql.length()) << endl;
2015-01-14 18:51:30 +00:00
if ( ql . length ( ) = = 2 )
{
ql < < " double " ;
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked: EMMITED" << endl;
2015-01-14 18:51:30 +00:00
emit dxspotclicked ( ql ) ;
}
else
{
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked: NOT EMMITED-1" << endl;
2015-01-14 18:51:30 +00:00
}
}
else
{
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked: NOT EMMITED-2 (no item)" << endl;
2015-01-14 18:51:30 +00:00
}
}
void DXClusterWidget : : connectToDXCluster ( )
{
//qDebug() << "DXClusterWidget::connectToDXCluster" << endl;
if ( dxClusterConnected )
{
//qDebug() << "DXClusterWidget::connectToDXCluster: - Already connected!!" << endl;
return ; // If we are connected we don't want to start another connection
}
connect ( tcpSocket , SIGNAL ( connected ( ) ) , SLOT ( slotClusterSocketConnected ( ) ) ) ;
connect ( tcpSocket , SIGNAL ( readyRead ( ) ) , this , SLOT ( slotClusterDataArrived ( ) ) ) ;
connect ( tcpSocket , SIGNAL ( error ( QAbstractSocket : : SocketError ) ) , this , SLOT ( slotClusterDisplayError ( QAbstractSocket : : SocketError ) ) ) ;
connect ( tcpSocket , SIGNAL ( disconnected ( ) ) , SLOT ( slotClusterSocketConnectionClosed ( ) ) ) ;
connect ( inputCommand , SIGNAL ( returnPressed ( ) ) , this , SLOT ( slotClusterSendToServer ( ) ) ) ;
connect ( clearButton , SIGNAL ( clicked ( ) ) , this , SLOT ( slotClusterClearLineInput ( ) ) ) ;
tcpSocket - > connectToHost ( server , port ) ;
dxClusterListWidget - > setSortingEnabled ( false ) ;
2017-08-18 20:11:39 +00:00
dxClusterSpotItem * item = new dxClusterSpotItem ( dxClusterListWidget , tr ( " Trying to connect to the server " ) + " \n " , awards - > getDefaultColor ( ) ) ;
2015-01-14 18:51:30 +00:00
}
void DXClusterWidget : : slotClusterDisplayError ( QAbstractSocket : : SocketError socketError )
{
//qDebug() << "DXClusterWidget:displayError:" << endl;
switch ( socketError ) {
case QAbstractSocket : : RemoteHostClosedError :
break ;
case QAbstractSocket : : HostNotFoundError :
QMessageBox : : warning ( this , tr ( " KLog DXCluster " ) ,
tr ( " The host was not found. Please check: \n \n "
" - your network connection; \n "
" - the host name and port settings. " ) ) ;
break ;
case QAbstractSocket : : ConnectionRefusedError :
QMessageBox : : warning ( this , tr ( " KLog DXCluster " ) ,
tr ( " The connection was refused by the peer. "
" Make sure the DXCluster server is running, "
" and check that the host name and port "
" settings are correct. " ) ) ;
break ;
default :
QMessageBox : : warning ( this , tr ( " KLog DXCluster " ) ,
tr ( " The following error occurred: %1. " )
. arg ( tcpSocket - > errorString ( ) ) ) ;
}
}
bool DXClusterWidget : : checkIfNeedsToBePrinted ( const QString _dxCall , int const _band , const int _mode )
{
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: " << _dxCall << "/" << dataProxy->getNameFromBandId(_band) << QString::number(_mode)<< endl;
QStringList qs ;
qs . clear ( ) ;
qs < < _dxCall < < QString : : number ( _band ) < < QString : : number ( _mode ) < < QString : : number ( currentLog ) ;
2015-08-21 15:59:40 +00:00
//bool isConfirmed = false;
2015-07-28 16:57:40 +00:00
bool status = awards - > isThisSpotConfirmed ( qs ) ;
2015-01-14 18:51:30 +00:00
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: Status: " << _dxCall << "/" << QString::number(status);
2015-01-14 18:51:30 +00:00
if ( ! showconfirmed )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is confirmed? ("<< QString::number(status)<< ")" << endl;
2015-07-28 16:57:40 +00:00
if ( status )
2015-01-14 18:51:30 +00:00
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: It is confirmed: DON'T' print: " << _dxCall <<"/" << dataProxy->getNameFromBandId(_band) << endl;
2015-01-14 18:51:30 +00:00
return false ;
}
}
if ( ! showhf )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is HF?" << endl;
2015-01-14 18:51:30 +00:00
if ( dataProxy - > isHF ( _band ) )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: Not showing HF but... is it WARC?" << endl;
2015-01-14 18:51:30 +00:00
if ( ( showwarc ) & & dataProxy - > isWARC ( _band ) )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: Not showing HF but... is WARC, print!" << endl;
2015-01-14 18:51:30 +00:00
return true ;
}
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is HF: DON'T print: "<< _dxCall << "/" << dataProxy->getNameFromBandId(_band) << QString::number(_mode)<< endl;
2015-01-14 18:51:30 +00:00
return false ;
}
else
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is NOT HF" << endl;
2015-01-14 18:51:30 +00:00
}
}
if ( ! showwarc )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is WARC?" << endl;
2015-01-14 18:51:30 +00:00
if ( dataProxy - > isWARC ( _band ) )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is WARC, DON'T print: "<< _dxCall << "/" << dataProxy->getNameFromBandId(_band) << QString::number(_mode)<< endl;
2015-01-14 18:51:30 +00:00
return false ;
}
else
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is NOT WARC" << endl;
2015-01-14 18:51:30 +00:00
}
}
if ( ! showvhf )
{
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is VHF?" << endl;
if ( dataProxy - > isVHF ( _band ) )
{
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is VHF, DON'T print: "<< _dxCall << "/" << dataProxy->getNameFromBandId(_band) << QString::number(_mode)<< endl;
return false ;
}
else
{
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: is NOT VHF " << endl;
}
}
//qDebug() << "DXClusterWidget::checkIfNeedsToBePrinted: returns TRUE and will be printed: " << _dxCall << "/" << dataProxy->getNameFromBandId(_band) << QString::number(_mode)<< endl;
return true ;
}
void DXClusterWidget : : setCurrentLog ( const int _log )
{
2016-08-16 15:21:15 +00:00
if ( dataProxy - > doesThisLogExist ( _log ) )
{
currentLog = _log ;
}
else
{
currentLog = - 1 ;
}
2015-01-14 18:51:30 +00:00
}
void DXClusterWidget : : slotClusterDataArrived ( )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::slotClusterDataArrived" << endl;
2015-01-14 18:51:30 +00:00
QStringList qs ;
QString dxClusterString ;
QString dxCall ;
QString dxFrequency ;
QString spotBand ;
spotBand = " -1 " ;
bool isADXSpot = false ;
2016-08-11 17:37:59 +00:00
int dxEntity = - 1 ;
2015-01-14 18:51:30 +00:00
while ( tcpSocket - > canReadLine ( ) ) {
dxClusterString = tcpSocket - > readLine ( ) ;
dxClusterString = dxClusterString . trimmed ( ) ;
QStringList tokens = dxClusterString . split ( " " , QString : : SkipEmptyParts ) ;
if ( tokens . size ( ) < 2 ) {
return ;
}
// It is a "DX de SP0TTER FREC DXCALL"
//0 = DX, 1 = de, 2 = spotter, 3 = Freq, 4 = dxcall, 5 = comment
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::slotClusterDataArrived: " << "DXCLUSTER->" << dxClusterString << "\nTOKENS: " << tokens << endl;
2015-01-14 18:51:30 +00:00
if ( ( tokens [ 0 ] = = " DX " ) & & ( tokens [ 1 ] = = " de " ) )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "******************** DXClusterWidget::slotClusterDataArrived: DX DE" << endl;
2015-01-14 18:51:30 +00:00
isADXSpot = true ;
QString spotter = tokens [ 2 ] ;
spotter . truncate ( spotter . size ( ) - 1 ) ;
dxFrequency = tokens [ 3 ] ;
// Convert KHz to MHz...
//dxFrequency = QString::number(abs (dxFrequency.toFloat())/1000);
dxFrequency = QString : : number ( ( dxFrequency . toFloat ( ) ) / 1000 ) ;
2016-08-11 17:37:59 +00:00
dxEntity = world - > getQRZARRLId ( dxCall ) ;
2015-01-14 18:51:30 +00:00
//
2015-08-17 15:54:45 +00:00
spotBand = QString : : number ( dataProxy - > getBandIdFromFreq ( dxFrequency . toDouble ( ) ) ) ;
2015-01-14 18:51:30 +00:00
2015-08-17 15:54:45 +00:00
dxCall = tokens [ 4 ] ;
2015-01-14 18:51:30 +00:00
qs . clear ( ) ;
2015-08-17 15:54:45 +00:00
//spotBand = QString::number(world->getBandIdFromFreq( dxFrequency ) );
2015-07-28 16:42:38 +00:00
qs < < dxCall < < spotBand < < " -1 " < < QString : : number ( currentLog ) ;
2015-01-14 18:51:30 +00:00
dxSpotColor = awards - > getQRZDXStatusColor ( qs ) ;
2015-08-01 11:17:07 +00:00
2016-08-11 17:37:59 +00:00
if ( awards - > isDXMarathonNeed ( dxEntity , world - > getQRZCqz ( dxCall ) , QDateTime : : currentDateTime ( ) . date ( ) . year ( ) , currentLog ) )
2015-08-01 11:17:07 +00:00
{
dxClusterString = dxClusterString + " ### Needed for DXMarathon - " + QString : : number ( QDateTime : : currentDateTime ( ) . date ( ) . year ( ) ) + " ### " ;
}
2015-08-01 19:25:53 +00:00
//qDebug() << "DX de ->" << "Spotter: " << spotter << "Freq: "<< dxFrequency << "DX: " << dxCall << endl;
2015-01-14 18:51:30 +00:00
}
else if ( ( tokens [ 0 ] = = " To " ) & & ( tokens [ 1 ] = = " ALL " ) )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::slotClusterDataArrived: TO ALL" << endl;
2015-01-14 18:51:30 +00:00
dxSpotColor = awards - > getDefaultColor ( ) ;
}
2015-08-01 19:25:53 +00:00
else if ( ( dxClusterString . length ( ) > = 5 ) & & ( world - > checkQRZValidFormat ( tokens [ 1 ] ) ) & & ( tokens [ 0 ] ! = " login: " ) )
2015-01-14 18:51:30 +00:00
{ // Freq / DXCall / Date // time
//_qs << QRZ << Freq in MHz << lognumber;
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::slotClusterDataArrived: LENGTH >= 5" << endl;
//qDebug() << "DXClusterWidget::slotClusterDataArrived: token0=" << tokens[0] << " / token1=" << tokens[1] << endl;
2015-01-14 18:51:30 +00:00
isADXSpot = true ;
dxCall = tokens [ 1 ] ;
dxFrequency = tokens [ 0 ] ;
dxFrequency = QString : : number ( ( dxFrequency . toFloat ( ) ) / 1000 ) ;
qs . clear ( ) ;
2015-08-17 15:54:45 +00:00
spotBand = QString : : number ( dataProxy - > getBandIdFromFreq ( dxFrequency . toDouble ( ) ) ) ;
2015-07-28 16:42:38 +00:00
qs < < dxCall < < spotBand < < " -1 " < < QString : : number ( currentLog ) ;
2016-08-11 17:37:59 +00:00
dxEntity = world - > getQRZARRLId ( dxCall ) ;
2015-01-14 18:51:30 +00:00
dxSpotColor = awards - > getQRZDXStatusColor ( qs ) ;
2016-08-11 17:37:59 +00:00
if ( awards - > isDXMarathonNeed ( dxEntity , world - > getQRZCqz ( dxCall ) , QDateTime : : currentDateTime ( ) . date ( ) . year ( ) , currentLog ) )
2015-08-01 11:17:07 +00:00
{
dxClusterString = dxClusterString + " ### Needed for DXMarathon - " + QString : : number ( QDateTime : : currentDateTime ( ) . date ( ) . year ( ) ) + " ### " ;
}
2015-01-14 18:51:30 +00:00
}
else
{
//qDebug() << "DXClusterWidget::slotClusterDataArrived: DEFAULT" << endl;
dxSpotColor = awards - > getDefaultColor ( ) ;
}
// qs.clear();
//spotBand = QString::number(world->getBandIdFromFreq( dxFrequency ) );
//qs << dxCall << spotBand << "0";
//dxSpotColor = awards->getQRZDXStatusColor(qs);
//qDebug() << "DXClusterWidget::slotClusterDataArrived: Call/dxSpotColor: " << dxCall <<"/"<< dxSpotColor.name() << endl;
//dxClusterSpotItem * item = new dxClusterSpotItem(dxClusterListWidget, dxClusterString, dxSpotColor);
//TODO: Change the "-1" by the mode
if ( ! checkIfNeedsToBePrinted ( dxCall , spotBand . toInt ( ) , - 1 ) )
{
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::slotClusterDataArrived - Not to be printed!: " << dxCall << endl;
2015-01-14 18:51:30 +00:00
return ;
}
2016-08-11 17:37:59 +00:00
// QString flagSt;
// QString aux;
2015-01-14 18:51:30 +00:00
QListWidgetItem * item = new QListWidgetItem ( ) ;
item - > setForeground ( QBrush ( dxSpotColor ) ) ;
item - > setText ( dxClusterString ) ;
2017-05-01 08:14:16 +00:00
2016-08-11 17:37:59 +00:00
/*
if ( dxEntity > 0 )
{
flagSt . clear ( ) ;
aux = dataProxy - > getISOName ( dxEntity ) ;
if ( aux . length ( ) > 1 )
{
flagSt = " :/ " + aux + " .png " ;
}
else
{
flagSt . clear ( ) ;
}
flagSt = " :/flags/ " + dataProxy - > getISOName ( dxEntity ) + " .png " ;
QIcon flagIcon ( flagSt ) ;
item - > setIcon ( flagIcon ) ;
}
*/
2015-01-14 18:51:30 +00:00
dxClusterListWidget - > insertItem ( 0 , item ) ;
//dxClusterListWidget->insertItem(0,item);
//QListWidgetItem *item = new QListWidgetItem();
//item->setForeground(QBrush(awards->getQRZDXStatusColor(qs)));
//item->setText(dxClusterString);
//dxClusterListWidget->insertItem(0,item);
}
2015-07-26 19:02:47 +00:00
//qDebug() << "--------------------- DXClusterWidget::slotClusterDataArrived: " << dxClusterString << endl;
2015-08-01 19:25:53 +00:00
//qDebug() << "DXClusterWidget::slotClusterDataArrived: " << dxClusterString << endl;
2015-01-14 18:51:30 +00:00
}
void DXClusterWidget : : slotClusterSocketConnected ( )
{
//qDebug() << "DXClusterWidget::slotClusterSocketConnected" << endl;
QListWidgetItem * item = new QListWidgetItem ( ) ;
item - > setForeground ( QBrush ( awards - > getDefaultColor ( ) ) ) ;
item - > setText ( tr ( " Connected to server " ) ) ;
dxClusterListWidget - > insertItem ( 0 , item ) ;
// dxClusterSpotItem * item = new dxClusterSpotItem(dxclusterListWidget, i18n("Connected to server"), awards->getDefaultColor());
dxClusterConnected = true ;
inputCommand - > setFocus ( Qt : : OtherFocusReason ) ;
if ( ( dxClusterConnected ) & & ( ! dxClusterAlreadyConnected ) ) {
bool ok ;
2017-05-06 17:27:18 +00:00
QString callsignText ;
if ( myQrz . length ( ) > 2 )
{
callsignText = QInputDialog : : getText ( this , tr ( " KLog message " ) , tr ( " Enter your callsign to connect to the cluster: " ) , QLineEdit : : Normal , myQrz , & ok ) ;
}
else
{
callsignText = QInputDialog : : getText ( this , tr ( " KLog message " ) , tr ( " Enter your callsign to connect to the cluster: " ) , QLineEdit : : Normal , " " , & ok ) ;
}
//QString callsignText = QInputDialog::getText(this, tr("KLog message"), tr("Enter your callsign to connect to the cluster:"), QLineEdit::Normal, "", &ok);
2015-07-28 16:57:40 +00:00
QString passwordText = QInputDialog : : getText ( this , tr ( " KLog message " ) , tr ( " Enter your password to connect to the cluster: \n (Just hit enter for no password) " ) , QLineEdit : : Normal , " " , & ok ) ;
2015-01-14 18:51:30 +00:00
QTextStream os ( tcpSocket ) ;
if ( callsignText . length ( ) > 2 & & ok ) {
os < < callsignText < < " \n " ;
//TODO: Check the DXCluster answer and enter the password if needed.
sendButton - > setText ( tr ( " Disconnect " ) ) ;
clearButton - > setText ( tr ( " Clear " ) ) ;
dxClusterAlreadyConnected = true ;
} else {
2017-08-18 13:38:15 +00:00
os < < tr ( " Not logged on, you may need to enter your callsign again. " ) < < " \n " ;
2015-01-14 18:51:30 +00:00
dxClusterAlreadyConnected = false ;
}
inputCommand - > setEnabled ( true ) ;
inputCommand - > setToolTip ( tr ( " Enter here the commands to be sent to the DX-Cluster server " ) ) ;
}
}
void DXClusterWidget : : slotClusterSocketConnectionClosed ( )
{
//qDebug() << "DXClusterWidget::slotClusterSocketConnectionClosed" << endl;
QListWidgetItem * item = new QListWidgetItem ( ) ;
item - > setForeground ( QBrush ( awards - > getDefaultColor ( ) ) ) ;
item - > setText ( tr ( " Connection closed by the server " ) ) ;
dxClusterListWidget - > insertItem ( 0 , item ) ;
dxClusterConnected = false ;
dxClusterAlreadyConnected = false ;
sendButton - > setText ( tr ( " Connect " ) ) ;
inputCommand - > setDisabled ( true ) ;
inputCommand - > setToolTip ( tr ( " Click on Connect to connect to the DX-Cluster server " ) ) ;
//connect(inputCommand, SIGNAL(returnPressed()), this, SLOT(slotClusterSendToServer()) );
disconnect ( inputCommand , SIGNAL ( returnPressed ( ) ) , this , SLOT ( slotClusterSendToServer ( ) ) ) ;
}
void DXClusterWidget : : slotClusterSendToServer ( )
{
//qDebug() << "DXClusterWidget::slotClusterSendToServer()" << endl;
if ( ! dxClusterConnected )
{
connectToDXCluster ( ) ;
return ; // If we try to connect...
}
if ( inputCommand - > text ( ) . length ( ) < 1 )
{
//qDebug() << "DXClusterWidget::slotClusterSendToServer() - Vacio..." << endl;
QTextStream os ( tcpSocket ) ;
os < < " bye \n " ;
return ;
}
// write to the server
QTextStream os ( tcpSocket ) ;
os < < inputCommand - > text ( ) < < " \n " ;
inputCommand - > clear ( ) ;
}
void DXClusterWidget : : slotClusterClearLineInput ( )
{
//qDebug() << "DXClusterWidget::slotClusterClearLineInput" << endl;
if ( ( ( inputCommand - > text ( ) ) . length ( ) ) < = 0 )
{
if ( dxClusterConnected )
{
QTextStream os ( tcpSocket ) ;
os < < " bye \n " ;
}
else
{
}
}
else
{
inputCommand - > clear ( ) ;
}
}
void DXClusterWidget : : slotClusterInputTextChanged ( )
{
//qDebug() << "DXClusterWidget::slotClusterInputTextChanged" << endl;
if ( ( ( inputCommand - > text ( ) ) . length ( ) ) < = 0 )
{
sendButton - > setText ( tr ( " Disconnect " ) ) ;
clearButton - > setText ( tr ( " Clear " ) ) ;
}
else if ( dxClusterConnected )
{
sendButton - > setText ( tr ( " Send " ) ) ;
clearButton - > setText ( tr ( " Clear " ) ) ;
}
else
{ }
}
void DXClusterWidget : : setColors ( const QString _newOne , const QString _needed , const QString _worked , const QString _confirmed , const QString _default )
{
//qDebug() << "DXClusterWidget::setColors: " << _newOne << "/" << _needed << "/" << _worked << "/" << _confirmed << "/" << _default << endl;
// Just to pass the colors to the awards class
awards - > setColors ( _newOne , _needed , _worked , _confirmed , _default ) ;
}
void DXClusterWidget : : setDXClusterSpotConfig ( bool _showhf , bool _showvhf , bool _showwarc , bool _showworked , bool _showconfirmed , bool _showann , bool _showwwv , bool _showwcy )
{
//qDebug() << "DXClusterWidget::setDXClusterSpotConfig " << endl;
showhf = _showhf ;
showvhf = _showvhf ;
showwarc = _showwarc ;
showworked = _showworked ;
showconfirmed = _showconfirmed ;
showann = _showann ;
showwwv = _showwwv ;
showwcy = _showwcy ;
}
void DXClusterWidget : : slotClusterDXClusterWidgetItemSelected ( )
{
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemSelected " << endl;
QListWidgetItem * item = dxClusterListWidget - > currentItem ( ) ;
QStringList ql ;
ql . clear ( ) ;
ql = readItem ( item ) ;
if ( ql . length ( ) = = 2 )
{
ql < < " selected " ;
emit dxspotclicked ( ql ) ;
}
else
{
}
}
void DXClusterWidget : : slotClusterDXClusterWidgetItemEntered ( QListWidgetItem * item )
{
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemEntered" << endl;
/*
This code comes from slotClusterDXClusterWidgetItemDoubleClicked
*/
QString tip ;
tip . clear ( ) ;
QStringList ql ;
ql . clear ( ) ;
if ( item )
{
ql = readItem ( item ) ;
if ( ql . length ( ) = = 2 )
{
tip = world - > getQRZEntityName ( ql . at ( 0 ) ) ;
item - > setToolTip ( tip ) ;
}
else
{
}
}
else
{
}
}
2015-11-09 07:50:38 +00:00
bool DXClusterWidget : : isConnected ( )
{
return dxClusterConnected ;
}
2015-01-14 18:51:30 +00:00
QStringList DXClusterWidget : : readItem ( QListWidgetItem * item )
{
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::readItem" << endl;
2015-01-14 18:51:30 +00:00
QStringList fields ;
QString dxClusterString ;
//int currentEntity;
QString dxCallsign , dxFreq ;
bool FirstFrecOK ;
if ( item ) {
fields . clear ( ) ;
dxClusterString = ( ( item - > data ( 0 ) ) . toString ( ) ) . simplified ( ) ;
fields < < dxClusterString . split ( " " ) ;
( fields . at ( 0 ) ) . toFloat ( & FirstFrecOK ) ; // Just to see if the first string is a frecuency
if ( ( fields . at ( 0 ) = = " DX " ) & & ( fields . at ( 1 ) = = " de " ) )
{ // DX de EA4TV: 21200.1 EA0JC The comment 1550
if ( world - > getQRZARRLId ( fields . at ( 4 ) ) > 0 )
{
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked: ARRLid: " << QString::number(world->getQRZARRLId(fields.at(4))) << endl;
dxCallsign = ( fields . at ( 4 ) ) . toUpper ( ) ;
( fields . at ( 3 ) ) . toFloat ( & FirstFrecOK ) ;
if ( FirstFrecOK )
{ // The frecuency is valid
dxFreq = fields . at ( 3 ) ;
fields . clear ( ) ;
//TODO: Change FREQ into bandId
fields < < dxCallsign < < dxFreq ;
return fields ;
}
else
{ // the frecuency is not a number!
dxCallsign . clear ( ) ;
dxFreq . clear ( ) ;
fields . clear ( ) ;
}
}
else
{ // The call is not from a valid country
// TODO: if it is from a new entity/prefix it would not work.
//qDebug() << "DXClusterWidget::slotClusterDXClusterWidgetItemDoubleClicked: Entity not valid" << endl;
dxCallsign . clear ( ) ;
dxFreq . clear ( ) ;
fields . clear ( ) ;
}
}
//else if (( isAFrecuency(fields.at(0) ) ) && ( isACall(fields.at(1)) ) )
else if ( ( ( ( fields . at ( 0 ) ) . toFloat ( ) ) > 0.0 ) & & ( world - > getQRZARRLId ( fields . at ( 1 ) ) > 0 ) )
{ // 14205.0 EA0JC 5-Mar-2012 1500Z <EA4TV>
dxCallsign = ( fields . at ( 1 ) ) . toUpper ( ) ;
dxFreq = fields . at ( 0 ) ;
fields . clear ( ) ;
fields < < dxCallsign < < dxFreq ;
return fields ;
}
else
{
dxCallsign . clear ( ) ;
dxFreq . clear ( ) ;
fields . clear ( ) ;
}
}
else
{ // No Item
}
return fields ;
}
void DXClusterWidget : : setDXClusterServer ( const QString & clusterToConnect , const int portToConnect )
{
server = clusterToConnect ;
port = portToConnect ;
//qDebug() << "DXClusterWidget::setDXClusterServer: " << server << ":"<< QString::number(port) << endl;
}
2017-05-01 08:14:16 +00:00
/*
void DXClusterWidget : : TESTADDSPOT ( )
{
2017-05-06 17:27:18 +00:00
//qDebug() << "DXClusterWidget::TESTADDSPOT " << endl;
2017-05-01 08:14:16 +00:00
; // Just a test spot
QListWidgetItem * item = new QListWidgetItem ( ) ;
item - > setForeground ( QBrush ( dxSpotColor ) ) ;
item - > setText ( " DX de SP0TTER 14.000 DX1CALL " ) ;
dxClusterListWidget - > insertItem ( 0 , item ) ;
}
*/
2015-01-14 18:51:30 +00:00
/***************************************************************************
* * This is an auxiliary class intended to provide color to the DX - Cluster * *
* * spots . * *
* * It may be moved to a self . h & . cpp archives * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
dxClusterSpotItem : : dxClusterSpotItem ( QListWidget * parent , const QString & spot , const QColor & color ) : QListWidgetItem ( parent ) {
//qDebug() << "dxClusterSpotItem::dxClusterSpotItem - Constructor" << endl;
spotColor = color ;
setText ( spot ) ;
// Experimenting with fonts for the cluster
QFont f ( " Helvetica " ) ;
f . setFixedPitch ( true ) ;
setFont ( f ) ;
}
dxClusterSpotItem : : ~ dxClusterSpotItem ( )
{
//qDebug() << "dxClusterSpotItem::dxClusterSpotItem - Destructor" << endl;
}