Project

General

Profile

Possiable Scripting Object » History » Version 1

stitch, 05/21/2010 11:39 AM

1 1 stitch
h1. Possiable Scripting Object
2 1 stitch
3 1 stitch
This is nothing more than a rough 4am-coffee-powered rough concept.
4 1 stitch
5 1 stitch
Header File:
6 1 stitch
<pre>
7 1 stitch
#ifndef SCRIPTINTERFACE_H
8 1 stitch
#define SCRIPTINTERFACE_H
9 1 stitch
10 1 stitch
#include <QObject>
11 1 stitch
12 1 stitch
struct userjoin_t
13 1 stitch
{
14 1 stitch
    QString network;
15 1 stitch
    QString channel;
16 1 stitch
    QString userhost;
17 1 stitch
};
18 1 stitch
19 1 stitch
struct userpart_t
20 1 stitch
{
21 1 stitch
    QString network;
22 1 stitch
    QString channel;
23 1 stitch
    QString userhost;
24 1 stitch
    QString reason;
25 1 stitch
};
26 1 stitch
27 1 stitch
struct modeset_t
28 1 stitch
{
29 1 stitch
    QString network;
30 1 stitch
    QString channel;
31 1 stitch
    QChar mode;
32 1 stitch
    QString paramaters;
33 1 stitch
};
34 1 stitch
35 1 stitch
struct numeric_t
36 1 stitch
{
37 1 stitch
    QString network;
38 1 stitch
    int numeric;
39 1 stitch
    QByteArray data;
40 1 stitch
};
41 1 stitch
42 1 stitch
Q_DECLARE_METATYPE(userjoin_t);
43 1 stitch
Q_DECLARE_METATYPE(userpart_t);
44 1 stitch
Q_DECLARE_METATYPE(modeset_t);
45 1 stitch
Q_DECLARE_METATYPE(numeric_t);
46 1 stitch
47 1 stitch
class ScriptInterface : public QObject
48 1 stitch
{
49 1 stitch
    Q_OJBECT
50 1 stitch
public:
51 1 stitch
    ScriptInterface();
52 1 stitch
    void exposeToScripting(Command cmd, QVariant data);
53 1 stitch
    enum Command { NetworkConnected, NetworkDisconnected, UserJoin, UserPart, ModeSet, ModeRemove, RawNumeric };
54 1 stitch
55 1 stitch
signals:
56 1 stitch
    void networkConnected(QString network);
57 1 stitch
    void networkDisconnected(QString network);
58 1 stitch
    void userJoined(QString network, QString channel, QString userHost);
59 1 stitch
    void userParted(QString network, QString channel, QString userHost, QString reason);
60 1 stitch
    void modeSet(QString network, QString channel, QChar mode, QString paramaters);
61 1 stitch
    void modeRemove(QString network, QString channel, QChar mode, QString parameters);
62 1 stitch
    void rawNumeric(QString network, int numeric, QByteArray data);
63 1 stitch
};
64 1 stitch
65 1 stitch
#endif // SCRIPTINTERFACE_H
66 1 stitch
</pre>
67 1 stitch
68 1 stitch
Code
69 1 stitch
<pre>
70 1 stitch
#include "scriptinterface.h"
71 1 stitch
72 1 stitch
ScriptInterface::ScriptInterface()
73 1 stitch
{
74 1 stitch
}
75 1 stitch
76 1 stitch
void ScriptInterface::exposeToScripting(Command cmd, QVariant data)
77 1 stitch
{
78 1 stitch
    switch(cmd)
79 1 stitch
    {
80 1 stitch
    case NetworkConnected:
81 1 stitch
        QString network = qobject_cast<QString>(data);
82 1 stitch
        emit networkConnected(network);
83 1 stitch
        break;
84 1 stitch
    case NetworkDisconnected:
85 1 stitch
        QString network = qobject_cast<QString>(data);
86 1 stitch
        emit networkDisonnected(network);
87 1 stitch
        break;
88 1 stitch
    case UserJoin:
89 1 stitch
        userjoin_t mydata = qobject_cast<userjoin_t>(data);
90 1 stitch
        emit userJoined(mydata.network, mydata.channel, mydata.userhost);
91 1 stitch
        break;
92 1 stitch
    case UserPart:
93 1 stitch
        userpart_t mydata = qobject_cast<userpart_t>(data);
94 1 stitch
        emit userParted(mydata.network, mydata.channel, mydata.userhost, mydata.reason);
95 1 stitch
        break;
96 1 stitch
    case ModeSet:
97 1 stitch
        modeset_t mydata = qobject_cast<modeset_t>(data);
98 1 stitch
        emit modeSet(mydata.network, mydata.channel, mydata.mode, mydata.paramaters);
99 1 stitch
        break;
100 1 stitch
    case ModeRemove:
101 1 stitch
        modeset_t mydata = qobject_cast<modeset_t>(data);
102 1 stitch
        emit modeRemove(mydata.network, mydata.channel, mydata.mode, mydata.paramaters);
103 1 stitch
        break;
104 1 stitch
    case RawNumeric:
105 1 stitch
        numeric_t mydata = qobject_cast<numeric_t>(data);
106 1 stitch
        emit networkConnected(mydata.network, mydata.numeric, mydata.data);
107 1 stitch
        break;
108 1 stitch
    default:
109 1 stitch
        /* no clue, ignore */
110 1 stitch
        break;
111 1 stitch
    }
112 1 stitch
}
113 1 stitch
</pre>