summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qt/RGBController/irc.cpp19
-rw-r--r--qt/RGBController/irc.h5
2 files changed, 22 insertions, 2 deletions
diff --git a/qt/RGBController/irc.cpp b/qt/RGBController/irc.cpp
index 9c3c14d..4365e19 100644
--- a/qt/RGBController/irc.cpp
+++ b/qt/RGBController/irc.cpp
@@ -2,7 +2,7 @@
irc::irc(QObject *parent) : QObject(parent)
{
-
+
}
void irc::setup(QString srv, int p, QString c, QString n)
@@ -15,6 +15,8 @@ void irc::setup(QString srv, int p, QString c, QString n)
/* setup socket, connect signal/slot */
socket = new QTcpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
+ contest = new QTimer(this);
+ connect(contest, SIGNAL(timeout()), this, SLOT(testcon()));
/* connect */
con();
}
@@ -37,7 +39,6 @@ void irc::read()
handle(line);
if(socket->canReadLine())
read();
-
}
void irc::con()
@@ -47,12 +48,14 @@ void irc::con()
socket->write(buf.toUtf8());
buf = "USER " + name + " 8 * :" + name + "\r\n";
socket->write(buf.toUtf8());
+ contest->start(60000);
}
void irc::discon()
{
socket->write("QUIT :elegant quit \r\n");
socket->close();
+ contest->stop();
}
void irc::handle(QString str)
@@ -94,3 +97,15 @@ void irc::sendmsg(QString msg)
buf = "PRIVMSG " + channel + " :" + msg + " \r\n";
socket->write(buf.toUtf8());
}
+
+void irc::testcon()
+{
+ qDebug() << socket->state();
+ if (socket->state() == QAbstractSocket::UnconnectedState)
+ {
+ qDebug() << "reconnect needed";
+ discon();
+ name = name + "_";
+ con();
+ }
+}
diff --git a/qt/RGBController/irc.h b/qt/RGBController/irc.h
index b9bdefc..d6c88e6 100644
--- a/qt/RGBController/irc.h
+++ b/qt/RGBController/irc.h
@@ -3,6 +3,7 @@
#include <QtNetwork/QTcpSocket>
#include <QDebug>
+#include <QTimer>
class irc : public QObject
{
@@ -19,10 +20,14 @@ class irc : public QObject
QString channel;
QString name;
QString buf;
+ int pingcount;
+ QTimer *contest;
+
private slots:
void read();
void con();
void handle(QString str);
+ void testcon();
signals:
void sendcmd(QString cmd);