first re-commit.

This commit is contained in:
2025-08-05 22:37:51 +02:00
commit 5295a82aa3
109 changed files with 9928 additions and 0 deletions

126
libMiniCash/mcsender.cpp Normal file
View File

@@ -0,0 +1,126 @@
/***************************************************************************
miniCashConnect
Copyright © 2022 christoph holzheuer
c.holzheuer@sourceworx.org
This program 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.
***************************************************************************/
#include <QAbstractSocket>
#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QHostAddress>
#include <QMessageBox>
#include <QMetaType>
#include <QString>
#include <QStandardPaths>
#include <QTcpSocket>
#include <mcsender.h>
/**
* @brief MCSender::MCSender
*/
MCSender::MCSender()
{
}
/**
* @brief MCSender::~MCSender
*/
MCSender::~MCSender()
{
if( isOpen() )
close();
}
void MCSender::setupConnection( const QString& host, int port )
{
//qDebug() << "\n\nMCSender::setupConnection(): " << host << " : " << port;
_port = port;
_host = host;
}
/**
* @brief MCSender::initConnection
* @param parent
* @param host
* @param port
* @return
*/
void MCSender::onCreateConnection()
{
if( isOpen() )
onDiscardConnection();
//qDebug() << "MCSender::onCreateConnection()";
connectToHost( _host, _port, QIODevice::WriteOnly );
if( waitForConnected( miniCash::senderTimeout ) )
{
emit connectionChanged( miniCash::Connected );
return; // allet jut
}
emit errorOccurred( error() );
}
/**
* @brief MCSender::onDiscardConnection
*/
void MCSender::onDiscardConnection()
{
// qDebug() << "MCSender::onDiscardConnection()";
flush();
if( isOpen() )
close();
emit connectionChanged( miniCash::UnConnected );
}
/**
* @brief MCSender::writeTransaction
* @param transaction
*/
void MCSender::onSendTransaction( const QString& transaction )
{
if( !isOpen() )
{
emit connectionChanged( miniCash::UnConnected );
//qDebug( "---QTCPClient: Not connected");
return;
}
QDataStream socketStream( this );
socketStream.setVersion(QDataStream::Qt_5_15);
QByteArray byteArray = transaction.toUtf8();
socketStream << byteArray;
}