Project

General

Profile

Possiable Scripting Object

This is nothing more than a rough 4am-coffee-powered rough concept.

Header File:

#ifndef SCRIPTINTERFACE_H
#define SCRIPTINTERFACE_H

#include <QObject>

struct userjoin_t
{
    QString network;
    QString channel;
    QString userhost;
};

struct userpart_t
{
    QString network;
    QString channel;
    QString userhost;
    QString reason;
};

struct modeset_t
{
    QString network;
    QString channel;
    QChar mode;
    QString paramaters;
};

struct numeric_t
{
    QString network;
    int numeric;
    QByteArray data;
};

Q_DECLARE_METATYPE(userjoin_t);
Q_DECLARE_METATYPE(userpart_t);
Q_DECLARE_METATYPE(modeset_t);
Q_DECLARE_METATYPE(numeric_t);

class ScriptInterface : public QObject
{
    Q_OJBECT
public:
    ScriptInterface();
    void exposeToScripting(Command cmd, QVariant data);
    enum Command { NetworkConnected, NetworkDisconnected, UserJoin, UserPart, ModeSet, ModeRemove, RawNumeric };

signals:
    void networkConnected(QString network);
    void networkDisconnected(QString network);
    void userJoined(QString network, QString channel, QString userHost);
    void userParted(QString network, QString channel, QString userHost, QString reason);
    void modeSet(QString network, QString channel, QChar mode, QString paramaters);
    void modeRemove(QString network, QString channel, QChar mode, QString parameters);
    void rawNumeric(QString network, int numeric, QByteArray data);
};

#endif // SCRIPTINTERFACE_H

Code

#include "scriptinterface.h" 

ScriptInterface::ScriptInterface()
{
}

void ScriptInterface::exposeToScripting(Command cmd, QVariant data)
{
    switch(cmd)
    {
    case NetworkConnected:
        QString network = qobject_cast<QString>(data);
        emit networkConnected(network);
        break;
    case NetworkDisconnected:
        QString network = qobject_cast<QString>(data);
        emit networkDisonnected(network);
        break;
    case UserJoin:
        userjoin_t mydata = qobject_cast<userjoin_t>(data);
        emit userJoined(mydata.network, mydata.channel, mydata.userhost);
        break;
    case UserPart:
        userpart_t mydata = qobject_cast<userpart_t>(data);
        emit userParted(mydata.network, mydata.channel, mydata.userhost, mydata.reason);
        break;
    case ModeSet:
        modeset_t mydata = qobject_cast<modeset_t>(data);
        emit modeSet(mydata.network, mydata.channel, mydata.mode, mydata.paramaters);
        break;
    case ModeRemove:
        modeset_t mydata = qobject_cast<modeset_t>(data);
        emit modeRemove(mydata.network, mydata.channel, mydata.mode, mydata.paramaters);
        break;
    case RawNumeric:
        numeric_t mydata = qobject_cast<numeric_t>(data);
        emit networkConnected(mydata.network, mydata.numeric, mydata.data);
        break;
    default:
        /* no clue, ignore */
        break;
    }
}