updated bluemonkey irc abilities
authorKevron Rees <kevron.m.rees@intel.com>
Mon, 9 Sep 2013 17:33:51 +0000 (10:33 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Mon, 9 Sep 2013 17:33:51 +0000 (10:33 -0700)
CMakeLists.txt
plugins/bluemonkey/CMakeLists.txt
plugins/bluemonkey/irccoms.cpp
plugins/bluemonkey/irccoms.h

index 51efa45..8e428b8 100644 (file)
@@ -80,7 +80,11 @@ if(qtmainloop)
                message(STATUS "using Qt5")
                set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS})
                set(QT_LIBRARIES ${Qt5Core_LIBRARIES})
-               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} -mcmodel=large")
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
+               if(CMAKE_SIZEOF_VOID_P MATCHES "8")
+                       message(STATUS "can has 64bits")
+                       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large")
+               endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
                add_definitions(${Qt5Core_DEFINITIONS})
        else(Qt5Core_FOUND)
                message(STATUS "using Qt4")
index 23251d2..ff04573 100644 (file)
@@ -20,7 +20,7 @@ if(Qt5Core_FOUND)
 endif(Qt5Core_FOUND)
 
 set(CMAKE_AUTOMOC ON)
-set(communi_INCLUDE_DIRS /usr/include/qt4/Communi)
+set(communi_INCLUDE_DIRS /usr/include/qt5/Communi)
 set(communi_LIBRARIES -lCommuni)
 add_definitions(-DCOMMUNI_SHARED)
 
index 1450c27..55b95e8 100644 (file)
@@ -3,35 +3,31 @@
 #include <IrcCommand>
 #include <IrcMessage>
 #include <QSslSocket>
+#include <QSslError>
 #include <QFile>
 #include <QNetworkProxy>
 #include <QTimer>
 #include <QScriptEngine>
+#include <debugout.h>
 
 #define foreach Q_FOREACH
 
 IrcCommunication::IrcCommunication(std::map<std::string, std::string> config, QObject* parent)
-       :QObject(parent)
+       :IrcSession(parent)
 {
 
-       session = new IrcSession(this);
-       mSsl=false;
-
-       QObject::connect(session, &IrcSession::connected, [this](){
-               connectedChanged();
-               connected();
+       QObject::connect(this, &IrcCommunication::connected, [this](){
                announceDequeue();
+               connectedChanged(true);
        });
 
-       QObject::connect(session, &IrcSession::disconnected, [this](){
-               connectedChanged();
-               disconnected();
+       QObject::connect(this, &IrcCommunication::disconnected, [this](){
+               connectedChanged(false);
                reconnect();
        });
 
-       QObject::connect(session,SIGNAL(socketError(QAbstractSocket::SocketError)),this,SLOT(socketError(QAbstractSocket::SocketError)));
-       QObject::connect(session,SIGNAL(connecting()),this,SIGNAL(connecting()));
-       QObject::connect(session,SIGNAL(messageReceived(IrcMessage*)),this,SLOT(messageReceived(IrcMessage*)));
+       QObject::connect(this,SIGNAL(socketError(QAbstractSocket::SocketError)),this,SLOT(socketError(QAbstractSocket::SocketError)));
+       QObject::connect(this,SIGNAL(messageReceived(IrcMessage*)),this,SLOT(onMessageReceived(IrcMessage*)));
 
        QScriptEngine *engine = new QScriptEngine(this);
 
@@ -43,7 +39,7 @@ IrcCommunication::IrcCommunication(std::map<std::string, std::string> config, QO
        QFile file(str);
        if(!file.open(QIODevice::ReadOnly))
        {
-               qDebug()<<"failed to open irc config file: "<<str;
+               DebugOut(DebugOut::Error)<<"failed to open irc config file: "<<str.toStdString()<<endl;
                return;
        }
 
@@ -51,13 +47,10 @@ IrcCommunication::IrcCommunication(std::map<std::string, std::string> config, QO
 
        file.close();
 
-       engine->evaluate(script);
+       QScriptValue response = engine->evaluate(script);
 
-}
+       DebugOut()<<response.toString().toStdString()<<endl;
 
-bool IrcCommunication::isConnected()
-{
-       return session->isConnected();
 }
 
 void IrcCommunication::announceDequeue()
@@ -84,20 +77,20 @@ void IrcCommunication::announce(QString s)
                IrcCommand command;
                command.setType(IrcCommand::Message);
                command.setParameters(QStringList()<<channel<<s);
-               session->sendCommand(&command);
+               sendCommand(&command);
        }
 }
 
 void IrcCommunication::respond(QString target, QString s)
 {
        IrcCommand *command = IrcCommand::createMessage(target,s);
-       session->sendCommand(command);
+       sendCommand(command);
 
        delete command;
 
 }
 
-void IrcCommunication::messageReceived(IrcMessage *msg)
+void IrcCommunication::onMessageReceived(IrcMessage *msg)
 {
        qDebug()<<"message received "<<msg->type()<<" prefix: "<<msg->sender().prefix()<<" params:"<<msg->parameters();
 
@@ -116,11 +109,11 @@ void IrcCommunication::messageReceived(IrcMessage *msg)
 
 void IrcCommunication::connect(QString host, int port, QString proxy, QString user, QString nick, QString pass)
 {
-       session->setHost(host);
-       session->setPort(port);
-       session->setUserName(user);
-       session->setNickName(nick);
-       session->setRealName(nick);
+       setHost(host);
+       setPort(port);
+       setUserName(user);
+       setNickName(nick);
+       setRealName(nick);
 
        if(!proxy.isEmpty())
        {
@@ -141,13 +134,15 @@ void IrcCommunication::connect(QString host, int port, QString proxy, QString us
        }
 
        qDebug()<<"opening irc session";
-       session->open();
+       open();
 }
 
 void IrcCommunication::setSsl(bool use)
 {
        if(use)
-               session->setSocket(new QSslSocket(this));
+       {
+               setSecure(true);
+       }
 }
 
 void IrcCommunication::join(QString channel)
@@ -158,26 +153,26 @@ void IrcCommunication::join(QString channel)
        IrcCommand command;
        command.setType(IrcCommand::Join);
        command.setParameters(QStringList()<<channel);
-       session->sendCommand(&command);
+       sendCommand(&command);
 }
 
 void IrcCommunication::reconnect()
 {
-       if(session->socket()->state() == QAbstractSocket::ConnectingState)
+       if(socket()->state() == QAbstractSocket::ConnectingState)
                QTimer::singleShot(5000,this,SLOT(reconnect()));
        else
-               QTimer::singleShot(5000,session,SLOT(open()));
+               QTimer::singleShot(5000,this,SLOT(open()));
 }
 
-/*void IrcCommunication::sslError(QList<QSslError>)
+void IrcCommunication::sslError(QList<QSslError> &)
 {
        qDebug()<<"some ssl errors!! trying to ignore them";
-       QSslSocket* socket = qobject_cast<QSslSocket*>(session->socket());
-       if(socket)
+       QSslSocket* sock = qobject_cast<QSslSocket*>(socket());
+       if(sock)
        {
-               socket->ignoreSslErrors();
+               sock->ignoreSslErrors();
        }
-}*/
+}
 
 void IrcCommunication::socketError(QAbstractSocket::SocketError error)
 {
@@ -188,5 +183,5 @@ void IrcCommunication::socketError(QAbstractSocket::SocketError error)
 void IrcCommunication::setIgnoreInvalidCert(bool ignore)
 {
        if(ignore)
-               QObject::connect(session->socket(),SIGNAL(),this,SLOT(sslError(QList<QSslError>)));
+               QObject::connect(socket(),SIGNAL(sslErrors(QList<QSslError>&)),this,SLOT(sslError(QList<QSslError>&)));
 }
index 20f1994..261d016 100644 (file)
@@ -3,23 +3,23 @@
 #include <QObject>
 #include <QVariant>
 #include <QStringList>
+#include <QSslError>
 #include <map>
+#include <QAbstractSocket>
 
 #include <IrcSession>
 #include <IrcMessage>
 
-class IrcCommunication: public QObject
+class IrcCommunication: public IrcSession
 {
        Q_OBJECT
        Q_PROPERTY(QStringList channels READ channels WRITE setChannels)
        Q_PROPERTY(bool ssl WRITE setSsl)
-       Q_PROPERTY(bool isConnected READ isConnected NOTIFY connectedChanged)
 public:
        IrcCommunication(std::map<std::string, std::string> config, QObject* parent=0);
        QStringList channels() { return mChannels; }
        void setChannels(QStringList c) { mChannels = c; }
 
-       bool isConnected();
        void announceDequeue();
 
 public Q_SLOTS:
@@ -33,22 +33,16 @@ public Q_SLOTS:
        void reconnect();
 
 private Q_SLOTS:
-       void messageReceived(IrcMessage*);
-//     void sslError(QList<QSslError>);
+       void onMessageReceived(IrcMessage*);
+       void sslError(QList<QSslError> &);
        void socketError(QAbstractSocket::SocketError);
 
 Q_SIGNALS:
        void message(QString sender, QString prefix, QString codes);
-       void connecting();
-       void connected();
-       void disconnected();
-       void connectedChanged();
 
 private:
-       bool mSsl;
        QStringList announceQueue;
        QStringList mChannels;
-       IrcSession *session;
 };
 
 #endif // COMMUNICATION_H