File indexing completed on 2024-07-21 12:17:09

0001 // Copyright (c) 2015 Pino Toscano <pino@kde.org>
0002 //
0003 // This program is free software; you can redistribute it and/or
0004 // modify it under the terms of the GNU General Public License
0005 // version 2 as published by the Free Software Foundation.
0006 //
0007 // This program is distributed in the hope that it will be useful,
0008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0010 // General Public License for more details.
0011 //
0012 // You should have received a copy of the GNU General Public License
0013 // along with this program; see the file COPYING.  If not, write to
0014 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015 // Boston, MA 02110-1301, USA.
0016 
0017 #ifndef ATLANTIK_METATLANTIC_H
0018 #define ATLANTIK_METATLANTIC_H
0019 
0020 #include <kjob.h>
0021 
0022 #include <QTextStream>
0023 #include <QAbstractSocket>
0024 
0025 class QTcpSocket;
0026 
0027 class Metatlantic : public KJob
0028 {
0029 Q_OBJECT
0030 
0031 public:
0032     Metatlantic(const QString &host, int port, QObject *parent = nullptr);
0033     ~Metatlantic();
0034     void start() override;
0035 
0036 Q_SIGNALS:
0037     void metatlanticAdd(const QString &host, int port, const QString &version, int users);
0038 
0039 protected:
0040     bool doKill() override;
0041 
0042 private Q_SLOTS:
0043     void slotSocketError(QAbstractSocket::SocketError socketError);
0044     void slotSocketConnected();
0045     void slotSocketRead();
0046 
0047 private:
0048     void closeSocket(bool doEmitResult = true);
0049     void processMsg(const QString &msg);
0050 
0051     QString m_host;
0052     int m_port;
0053     QTcpSocket *m_socket;
0054     QTextStream m_stream;
0055 };
0056 
0057 #endif