Add in a few extra plugins
This commit is contained in:
44
plugins/IrcClientPlugin/CMakeLists.txt
Normal file
44
plugins/IrcClientPlugin/CMakeLists.txt
Normal file
@@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(IrcClientPlugin VERSION 1.0 LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Network Widgets)
|
||||
|
||||
qt_add_plugin(IrcClientPlugin)
|
||||
target_sources(IrcClientPlugin PRIVATE
|
||||
IrcClientPlugin.cpp IrcClientPlugin.h
|
||||
client.cpp client.h
|
||||
hostmask.cpp hostmask.h
|
||||
joinmessagehandler.cpp joinmessagehandler.h
|
||||
message.cpp message.h
|
||||
messagehandler.cpp messagehandler.h
|
||||
pingmessagehandler.cpp pingmessagehandler.h
|
||||
privmsgmessagehandler.cpp privmsgmessagehandler.h
|
||||
quitmessagehandler.cpp quitmessagehandler.h
|
||||
testhandler.cpp testhandler.h
|
||||
topichandler.cpp topichandler.h
|
||||
)
|
||||
|
||||
target_link_libraries(IrcClientPlugin PRIVATE
|
||||
Qt::Core
|
||||
Qt::Gui
|
||||
Qt::Network
|
||||
Qt::Widgets
|
||||
)
|
||||
|
||||
|
||||
# Resources:
|
||||
set(IrcClientPlugin_resource_files
|
||||
"images/smile.png"
|
||||
)
|
||||
|
||||
qt_add_resources(IrcClientPlugin "IrcClientPlugin"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${IrcClientPlugin_resource_files}
|
||||
)
|
||||
269
plugins/IrcClientPlugin/IrcClientPlugin.cpp
Normal file
269
plugins/IrcClientPlugin/IrcClientPlugin.cpp
Normal file
@@ -0,0 +1,269 @@
|
||||
#include "IrcClientPlugin.h"
|
||||
#include "pingmessagehandler.h"
|
||||
#include "privmsgmessagehandler.h"
|
||||
#include "testhandler.h"
|
||||
#include "topichandler.h"
|
||||
#include "joinmessagehandler.h"
|
||||
#include "quitmessagehandler.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QtWidgets>
|
||||
|
||||
|
||||
QString IrcClientPlugin::pname()
|
||||
{
|
||||
return "Irc Client Plugin";
|
||||
}
|
||||
|
||||
QString IrcClientPlugin::pdesc()
|
||||
{
|
||||
return "Simple Irc Client Plugin";
|
||||
}
|
||||
|
||||
QWidget* IrcClientPlugin::pcontent()
|
||||
{
|
||||
connectButton = new QPushButton(tr("Connect"));
|
||||
connect(connectButton, SIGNAL(clicked()), this, SLOT(connectToServer()));
|
||||
sendButton = new QPushButton(tr("Send"));
|
||||
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMsg()));
|
||||
joinButton = new QPushButton(tr("Join"));
|
||||
connect(joinButton, SIGNAL(clicked()), this, SLOT(joinRoom()));
|
||||
smallEditor = new QLineEdit;
|
||||
smallEditor->setText("");
|
||||
topic = new QLineEdit;
|
||||
topic->setText("");
|
||||
msgs = new QTextBrowser;
|
||||
nicks = new QTextEdit;
|
||||
nicks->setMinimumWidth(100);
|
||||
nicks->setMaximumWidth(100);
|
||||
msgs->setOpenExternalLinks(true);
|
||||
connect(msgs, SIGNAL(textChanged()), this, SLOT(changePixmap())) ;
|
||||
test = new QWidget();
|
||||
test->setWindowTitle(tr("Irc Client Plugin"));
|
||||
test->resize(400, 300);
|
||||
|
||||
QHBoxLayout *topLayout = new QHBoxLayout;
|
||||
topLayout->addWidget(connectButton);
|
||||
topLayout->addWidget(joinButton);
|
||||
|
||||
QHBoxLayout *midleLayout = new QHBoxLayout;
|
||||
midleLayout->addWidget(msgs);
|
||||
midleLayout->addWidget(nicks);
|
||||
|
||||
|
||||
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
||||
// topLayout->addWidget(ftpServerLabel);
|
||||
bottomLayout->addWidget(smallEditor);
|
||||
//topLayout->addWidget(cdToParentButton);
|
||||
bottomLayout->addWidget(sendButton);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(topLayout);
|
||||
mainLayout->addWidget(topic);
|
||||
mainLayout->addLayout(midleLayout);
|
||||
// mainLayout->addWidget(msgs);
|
||||
//mainLayout->addWidget(statusLabel);
|
||||
mainLayout->addLayout(bottomLayout);
|
||||
test->setLayout(mainLayout);
|
||||
QIcon icon = QIcon(":/images/monkey.png");
|
||||
test->setWindowIcon(icon);
|
||||
return test;
|
||||
}
|
||||
|
||||
void IrcClientPlugin::changePixmap()
|
||||
{
|
||||
QRegularExpression reg1(":\\)");
|
||||
QTextCursor cursor1(msgs->document()->find(reg1));
|
||||
|
||||
if (!cursor1.isNull()) {
|
||||
cursor1.insertHtml("<img src=\":/images/smile.png\">");
|
||||
}
|
||||
|
||||
//auto text = msgs->toHtml();
|
||||
// if(text != ""){
|
||||
// QRegExp exp("<\sa\s+[^>]href\s=\s\"([^\"])\"\s>(.)<\/\sa\s*>");
|
||||
// text.replace(exp, "{{\1}}");
|
||||
// msgs->setHtml(text);
|
||||
//}
|
||||
|
||||
|
||||
//QRegExp reg(":\\("); // you can improve regular expression
|
||||
QRegularExpression reg("https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)");
|
||||
QTextCursor cursor(msgs->document()->find(reg));
|
||||
|
||||
if (!cursor.isNull()) {
|
||||
|
||||
QString nlink = "<a href=\"http://barosonix.com\">http://barosonix.com</a>";
|
||||
|
||||
cursor.insertHtml(nlink);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void IrcClientPlugin::connectToServer()
|
||||
{
|
||||
_client = new Client(test);
|
||||
connect(_client, SIGNAL(PrivmsgReceived(Hostmask,QString,QString)), SLOT(onPrivmsgReceived(Hostmask,QString,QString)));
|
||||
connect(_client, SIGNAL(NamesListReceived(QString)), SLOT(onNamesListReceived(QString)));
|
||||
connect(_client, SIGNAL(JoinMsgReceived(Hostmask,QString,QString)), SLOT(onJoinMsgReceived(Hostmask,QString,QString)));
|
||||
connect(_client, SIGNAL(QuitMsgReceived(Hostmask,QString,QString)), SLOT(onQuitMsgReceived(Hostmask,QString,QString)));
|
||||
connect(_client, SIGNAL(TopicReceived(Hostmask,QString,QString)), SLOT(onTopicReceived(Hostmask,QString,QString)));
|
||||
|
||||
_client->setNickname("ahf_");
|
||||
_client->setUsername("ahf");
|
||||
_client->setRealname(QString::fromUtf8("Alexander Færøy"));
|
||||
|
||||
_client->setServerHostname("127.0.0.1");
|
||||
_client->setServerPort(6667);
|
||||
|
||||
_client->registerMessageHandler("PING", new PingMessageHandler);
|
||||
_client->registerMessageHandler("PRIVMSG", new PrivmsgMessageHandler);
|
||||
_client->registerMessageHandler("353", new testhandler);
|
||||
_client->registerMessageHandler("332", new topichandler);
|
||||
_client->registerMessageHandler("JOIN", new joinmessagehandler);
|
||||
_client->registerMessageHandler("PART", new quitmessagehandler);
|
||||
|
||||
_client->connectToServer();
|
||||
}
|
||||
|
||||
void IrcClientPlugin::sendMsg()
|
||||
{
|
||||
QString input;
|
||||
|
||||
input = smallEditor->text();
|
||||
|
||||
if (input.isEmpty())
|
||||
return;
|
||||
|
||||
if (input.at(0) == '/')
|
||||
{
|
||||
QString command = input.mid(1);
|
||||
_client->sendRaw(command);
|
||||
}
|
||||
else
|
||||
{
|
||||
_client->sendPrivmsg("#test", input);
|
||||
|
||||
QString format;
|
||||
format = "<font style='color: blue'>" + _client->getNickname() + "</font> " + input;
|
||||
append(format);
|
||||
}
|
||||
|
||||
smallEditor->clear();
|
||||
|
||||
}
|
||||
|
||||
void IrcClientPlugin::joinRoom()
|
||||
{
|
||||
_client->sendJoin("#test");
|
||||
}
|
||||
|
||||
void IrcClientPlugin::onPrivmsgReceived(const Hostmask &hostmask, const QString &target, const QString &text)
|
||||
{
|
||||
QString format;
|
||||
|
||||
format = "<" + hostmask.getNickname() + "> " + text;
|
||||
|
||||
append(format);
|
||||
}
|
||||
|
||||
void IrcClientPlugin::onNamesListReceived(const QString &text)
|
||||
{
|
||||
//QString format;
|
||||
int marker = 0;
|
||||
// qDebug() << "GOT:" << text;
|
||||
QStringList list1 = text.split(QLatin1Char(' '));
|
||||
for (QString data : list1) // iterate over array fibonacci
|
||||
{
|
||||
marker = marker +1;
|
||||
if(marker > 2)
|
||||
{
|
||||
nicks->append(data);
|
||||
// qDebug() << "GOT:" << data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//format = "<" + hostmask.getNickname() + "> " + text;
|
||||
|
||||
//append(format);
|
||||
}
|
||||
|
||||
void IrcClientPlugin::onJoinMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text)
|
||||
{
|
||||
if(hostmask.getNickname() != _client->getNickname())
|
||||
{
|
||||
QString format;
|
||||
qDebug() << "GOT:" << text;
|
||||
format = "<" + hostmask.getNickname() + "> Has Joined.";
|
||||
nicks->append(hostmask.getNickname());
|
||||
append(format);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void IrcClientPlugin::onTopicReceived(const Hostmask& hostmask, const QString& target, const QString& text)
|
||||
{
|
||||
int marker = 0;
|
||||
|
||||
QString ftext = "";
|
||||
QStringList list1 = text.split(QLatin1Char(' '));
|
||||
for (QString data : list1) // iterate over array fibonacci
|
||||
{
|
||||
marker = marker +1;
|
||||
if(marker > 1)
|
||||
{
|
||||
if(ftext != "")
|
||||
{
|
||||
ftext += " " + data;
|
||||
}
|
||||
else
|
||||
{
|
||||
ftext += data;
|
||||
}
|
||||
|
||||
// qDebug() << "GOT:" << data;
|
||||
}
|
||||
|
||||
}
|
||||
// if(hostmask.getNickname() != _client->getNickname())
|
||||
//{
|
||||
// QString format;
|
||||
qDebug() << "GOT:" << ftext;
|
||||
topic->setText(ftext);
|
||||
// format = "<" + hostmask.getNickname() + "> Has Joined.";
|
||||
// nicks->append(hostmask.getNickname());
|
||||
// append(format);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void IrcClientPlugin::onQuitMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text)
|
||||
{
|
||||
QString format;
|
||||
qDebug() << "GOT:" << text;
|
||||
format = "<" + hostmask.getNickname() + "> Has Quit.";
|
||||
QStringList lines = nicks->toPlainText().split("\n");
|
||||
|
||||
int i = 0;
|
||||
while(i < lines.size())
|
||||
{
|
||||
QString line = lines.at(i);
|
||||
if(line.contains(hostmask.getNickname()))
|
||||
{
|
||||
lines.removeAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
nicks->setPlainText(lines.join("\n"));
|
||||
append(format);
|
||||
}
|
||||
|
||||
void IrcClientPlugin::append(const QString &line)
|
||||
{
|
||||
msgs->append(line);
|
||||
}
|
||||
59
plugins/IrcClientPlugin/IrcClientPlugin.h
Normal file
59
plugins/IrcClientPlugin/IrcClientPlugin.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef TESTPLUGIN_H
|
||||
#define TESTPLUGIN_H
|
||||
|
||||
|
||||
#include <../../src/interface.h>
|
||||
#include "client.h"
|
||||
#include "hostmask.h"
|
||||
#include <QtWidgets>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDialogButtonBox;
|
||||
class QFile;
|
||||
class QFtp;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QTreeWidget;
|
||||
class QTreeWidgetItem;
|
||||
class QPushButton;
|
||||
class QUrlInfo;
|
||||
class QNetworkSession;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class IrcClientPlugin : public QObject, public Interface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.SOM.Interface" FILE "IrcClientPlugin.json")
|
||||
Q_INTERFACES(Interface)
|
||||
|
||||
public:
|
||||
QString pname() override;
|
||||
QString pdesc() override;
|
||||
QWidget *pcontent() override;
|
||||
|
||||
private:
|
||||
void append(const QString& line);
|
||||
QWidget *test;
|
||||
QPushButton *sendButton;
|
||||
QPushButton *connectButton;
|
||||
QPushButton *joinButton;
|
||||
QLineEdit *smallEditor;
|
||||
QLineEdit *topic;
|
||||
QTextBrowser *msgs;
|
||||
QTextEdit *nicks;
|
||||
|
||||
Client *_client;
|
||||
|
||||
private slots:
|
||||
void connectToServer();
|
||||
void changePixmap();
|
||||
void joinRoom();
|
||||
void sendMsg();
|
||||
void onPrivmsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
void onNamesListReceived(const QString& text);
|
||||
void onJoinMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
void onQuitMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
void onTopicReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
|
||||
};
|
||||
#endif
|
||||
1
plugins/IrcClientPlugin/IrcClientPlugin.json
Normal file
1
plugins/IrcClientPlugin/IrcClientPlugin.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
5
plugins/IrcClientPlugin/IrcClientPlugin.qrc
Normal file
5
plugins/IrcClientPlugin/IrcClientPlugin.qrc
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/smile.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
183
plugins/IrcClientPlugin/client.cpp
Normal file
183
plugins/IrcClientPlugin/client.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
#include "client.h"
|
||||
|
||||
//#include <QtDebug>
|
||||
|
||||
Client::Client(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
_socket = new QSslSocket(this);
|
||||
|
||||
// We ignore SSL errors since most IRC servers uses invalid certificates.
|
||||
connect(_socket, SIGNAL(sslErrors(QList<QSslError>)), _socket, SLOT(ignoreSslErrors()));
|
||||
|
||||
connect(_socket, SIGNAL(connected()), SLOT(connectionEstablished()));
|
||||
connect(_socket, SIGNAL(readyRead()), SLOT(readData()));
|
||||
|
||||
// Send messages to dispatching.
|
||||
connect(this, SIGNAL(ReceivedMessage(Message)), SLOT(dispatchMessage(Message)));
|
||||
}
|
||||
|
||||
Client::~Client()
|
||||
{
|
||||
}
|
||||
|
||||
void Client::sendNick(const QString &nickname)
|
||||
{
|
||||
writeLine(QString("NICK %1").arg(nickname));
|
||||
|
||||
// We set it here to keep track of it.
|
||||
_nickname = nickname;
|
||||
}
|
||||
|
||||
void Client::sendUser(const QString &username, const QString &realname, const QString &hostname)
|
||||
{
|
||||
writeLine(QString("USER %1 %1 %2 :%3").arg(username).arg(hostname).arg(realname));
|
||||
}
|
||||
|
||||
void Client::sendJoin(const QString &channel)
|
||||
{
|
||||
writeLine(QString("JOIN %1").arg(channel));
|
||||
}
|
||||
|
||||
void Client::sendQuit(const QString &message)
|
||||
{
|
||||
writeLine(QString("QUIT :%1").arg(message));
|
||||
}
|
||||
|
||||
void Client::sendPong(const QString &message)
|
||||
{
|
||||
writeLine(QString("PONG :%1").arg(message));
|
||||
}
|
||||
|
||||
void Client::sendRaw(const QString &message)
|
||||
{
|
||||
writeLine(message);
|
||||
}
|
||||
|
||||
void Client::sendPrivmsg(const QString &target, const QString &text)
|
||||
{
|
||||
writeLine(QString("PRIVMSG %1 :%2").arg(target).arg(text));
|
||||
}
|
||||
|
||||
void Client::didReceivePrivmsg(const Hostmask &hostmask, const QString &target, const QString &text)
|
||||
{
|
||||
emit PrivmsgReceived(hostmask, target, text);
|
||||
}
|
||||
|
||||
void Client::didReceiveNamesList(const QString &text)
|
||||
{
|
||||
emit NamesListReceived(text);
|
||||
}
|
||||
|
||||
void Client::didReceiveQuitMsg(const Hostmask& hostmask, const QString& target, const QString& text)
|
||||
{
|
||||
emit QuitMsgReceived(hostmask, target, text);
|
||||
}
|
||||
|
||||
void Client::didReceiveTopic(const Hostmask& hostmask, const QString& target, const QString& text)
|
||||
{
|
||||
emit TopicReceived(hostmask, target, text);
|
||||
}
|
||||
|
||||
void Client::didReceiveJoinMsg(const Hostmask &hostmask, const QString &target, const QString &text)
|
||||
{
|
||||
emit JoinMsgReceived(hostmask, target, text);
|
||||
}
|
||||
|
||||
void Client::connectToServer()
|
||||
{
|
||||
_socket->connectToHost(_server_hostname, _server_port);
|
||||
}
|
||||
|
||||
void Client::writeLine(const QString &line)
|
||||
{
|
||||
qDebug() << "Send:" << line;
|
||||
_socket->write(QString("%1\r\n").arg(line).toUtf8());
|
||||
}
|
||||
|
||||
void Client::connectionEstablished()
|
||||
{
|
||||
qDebug() << "Connection Established";
|
||||
|
||||
sendNick(_nickname);
|
||||
sendUser(_username, _realname, _socket->peerName());
|
||||
|
||||
emit Connected();
|
||||
}
|
||||
|
||||
void Client::readData()
|
||||
{
|
||||
while (_socket->canReadLine())
|
||||
{
|
||||
QString line = QString::fromUtf8(_socket->readLine());
|
||||
line.remove("\r\n");
|
||||
|
||||
qDebug() << "Recv:" << line;
|
||||
|
||||
emit ReceivedMessage(Message::parse(line));
|
||||
}
|
||||
}
|
||||
|
||||
void Client::registerMessageHandler(const QString& command, MessageHandler* handler)
|
||||
{
|
||||
_message_handlers[command.toLower()].append(handler);
|
||||
handler->setParent(this);
|
||||
}
|
||||
|
||||
void Client::dispatchMessage(const Message& message)
|
||||
{
|
||||
foreach (MessageHandler* handler, _message_handlers[message.getCommand().toLower()])
|
||||
{
|
||||
handler->handle(this, message);
|
||||
}
|
||||
}
|
||||
|
||||
void Client::setServerHostname(const QString &hostname)
|
||||
{
|
||||
_server_hostname = hostname;
|
||||
}
|
||||
|
||||
void Client::setServerPort(quint16 port)
|
||||
{
|
||||
_server_port = port;
|
||||
}
|
||||
|
||||
QString Client::getServerHostname() const
|
||||
{
|
||||
return _server_hostname;
|
||||
}
|
||||
|
||||
quint16 Client::getServerPort() const
|
||||
{
|
||||
return _server_port;
|
||||
}
|
||||
|
||||
QString Client::getNickname() const
|
||||
{
|
||||
return _nickname;
|
||||
}
|
||||
|
||||
QString Client::getUsername() const
|
||||
{
|
||||
return _nickname;
|
||||
}
|
||||
|
||||
QString Client::getRealname() const
|
||||
{
|
||||
return _realname;
|
||||
}
|
||||
|
||||
void Client::setNickname(const QString &nickname)
|
||||
{
|
||||
_nickname = nickname;
|
||||
}
|
||||
|
||||
void Client::setUsername(const QString &username)
|
||||
{
|
||||
_username = username;
|
||||
}
|
||||
|
||||
void Client::setRealname(const QString &realname)
|
||||
{
|
||||
_realname = realname;
|
||||
}
|
||||
83
plugins/IrcClientPlugin/client.h
Normal file
83
plugins/IrcClientPlugin/client.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSslSocket>
|
||||
#include <QHash>
|
||||
|
||||
#include "messagehandler.h"
|
||||
#include "message.h"
|
||||
#include "hostmask.h"
|
||||
|
||||
class Client : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Client(QObject *parent = 0);
|
||||
~Client();
|
||||
|
||||
void connectToServer();
|
||||
|
||||
void setNickname(const QString& nickname);
|
||||
void setRealname(const QString& realname);
|
||||
void setUsername(const QString& username);
|
||||
|
||||
QString getNickname() const;
|
||||
QString getUsername() const;
|
||||
QString getRealname() const;
|
||||
|
||||
void setServerHostname(const QString& hostname);
|
||||
void setServerPort(quint16 port);
|
||||
|
||||
QString getServerHostname() const;
|
||||
quint16 getServerPort() const;
|
||||
|
||||
void registerMessageHandler(const QString& command, MessageHandler* handler);
|
||||
|
||||
void sendNick(const QString& nickname);
|
||||
void sendUser(const QString& username, const QString& realname, const QString& hostname);
|
||||
void sendJoin(const QString& channel);
|
||||
void sendQuit(const QString& message);
|
||||
void sendPong(const QString& message);
|
||||
void sendRaw(const QString& message);
|
||||
void sendPrivmsg(const QString& target, const QString& text);
|
||||
|
||||
void didReceivePrivmsg(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
|
||||
void didReceiveNamesList(const QString& text);
|
||||
void didReceiveJoinMsg(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
void didReceiveQuitMsg(const Hostmask &hostmask, const QString &target, const QString& text);
|
||||
void didReceiveTopic(const Hostmask &hostmask, const QString &target, const QString& text);
|
||||
|
||||
signals:
|
||||
void ReceivedMessage(const Message& message);
|
||||
void Connected();
|
||||
|
||||
void PrivmsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
void NamesListReceived(const QString& text);
|
||||
void JoinMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
void QuitMsgReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
void TopicReceived(const Hostmask& hostmask, const QString& target, const QString& text);
|
||||
|
||||
private slots:
|
||||
void readData();
|
||||
void connectionEstablished();
|
||||
void dispatchMessage(const Message& message);
|
||||
|
||||
private:
|
||||
void writeLine(const QString& line);
|
||||
|
||||
QString _nickname;
|
||||
QString _username;
|
||||
QString _realname;
|
||||
|
||||
QString _server_hostname;
|
||||
int _server_port;
|
||||
|
||||
QSslSocket *_socket;
|
||||
|
||||
QHash<QString, QList<MessageHandler*> > _message_handlers;
|
||||
};
|
||||
|
||||
#endif // CLIENT_H
|
||||
44
plugins/IrcClientPlugin/hostmask.cpp
Normal file
44
plugins/IrcClientPlugin/hostmask.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "hostmask.h"
|
||||
|
||||
Hostmask::Hostmask(const QString& nickname, const QString& username, const QString& hostname) :
|
||||
_nickname(nickname),
|
||||
_username(username),
|
||||
_hostname(hostname)
|
||||
{
|
||||
}
|
||||
|
||||
QString Hostmask::toString() const
|
||||
{
|
||||
return _nickname + "!" + _username + "@" + _hostname;
|
||||
}
|
||||
|
||||
QString Hostmask::getNickname() const
|
||||
{
|
||||
return _nickname;
|
||||
}
|
||||
|
||||
QString Hostmask::getUsername() const
|
||||
{
|
||||
return _username;
|
||||
}
|
||||
|
||||
QString Hostmask::getHostname() const
|
||||
{
|
||||
return _hostname;
|
||||
}
|
||||
|
||||
Hostmask Hostmask::parse(const QString &l)
|
||||
{
|
||||
QString nickname;
|
||||
QString username;
|
||||
QString hostname;
|
||||
|
||||
int at_pos = l.indexOf('@');
|
||||
int exclamation_mark_pos = l.indexOf('!');
|
||||
|
||||
nickname = l.left(exclamation_mark_pos);
|
||||
username = l.mid(exclamation_mark_pos + 1, at_pos - exclamation_mark_pos - 1);
|
||||
hostname = l.mid(at_pos + 1, l.size());
|
||||
|
||||
return Hostmask(nickname, username, hostname);
|
||||
}
|
||||
27
plugins/IrcClientPlugin/hostmask.h
Normal file
27
plugins/IrcClientPlugin/hostmask.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef HOSTMASK_H
|
||||
#define HOSTMASK_H
|
||||
|
||||
// nick!~ahf@hostname
|
||||
|
||||
#include <QString>
|
||||
|
||||
class Hostmask
|
||||
{
|
||||
public:
|
||||
QString getNickname() const;
|
||||
QString getUsername() const;
|
||||
QString getHostname() const;
|
||||
QString toString() const;
|
||||
|
||||
static Hostmask parse(const QString& l);
|
||||
|
||||
protected:
|
||||
Hostmask(const QString& nickname, const QString& username, const QString& hostname);
|
||||
|
||||
private:
|
||||
QString _nickname;
|
||||
QString _username;
|
||||
QString _hostname;
|
||||
};
|
||||
|
||||
#endif // HOSTMASK_H
|
||||
BIN
plugins/IrcClientPlugin/images/smile.png
Normal file
BIN
plugins/IrcClientPlugin/images/smile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 819 B |
24
plugins/IrcClientPlugin/joinmessagehandler.cpp
Normal file
24
plugins/IrcClientPlugin/joinmessagehandler.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "joinmessagehandler.h"
|
||||
|
||||
joinmessagehandler::joinmessagehandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void joinmessagehandler::handle(Client *client, const Message &message)
|
||||
{
|
||||
|
||||
QString target = message.getTarget();
|
||||
QString text = message.getArguments().join(" ");
|
||||
Hostmask from = Hostmask::parse(message.getPrefix());
|
||||
|
||||
|
||||
client->didReceiveJoinMsg(from, target, text);
|
||||
|
||||
// for (QString data : message.getArguments()) // iterate over array fibonacci
|
||||
// {
|
||||
// qDebug() << "GOT:" << data;
|
||||
// }
|
||||
//QString pongMessage = message.getTarget();
|
||||
//client->sendPong(pongMessage);
|
||||
}
|
||||
15
plugins/IrcClientPlugin/joinmessagehandler.h
Normal file
15
plugins/IrcClientPlugin/joinmessagehandler.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef JOINMESSAGEHANDLER_H
|
||||
#define JOINMESSAGEHANDLER_H
|
||||
|
||||
#include "message.h"
|
||||
#include "client.h"
|
||||
#include "messagehandler.h"
|
||||
|
||||
class joinmessagehandler: public MessageHandler
|
||||
{
|
||||
public:
|
||||
joinmessagehandler();
|
||||
virtual void handle(Client *client, const Message& message);
|
||||
};
|
||||
|
||||
#endif // JOINMESSAGEHANDLER_H
|
||||
81
plugins/IrcClientPlugin/message.cpp
Normal file
81
plugins/IrcClientPlugin/message.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "message.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
Message::Message(const QString& prefix, const QString& target, const QString& command, const QString& raw, const QStringList& arguments) :
|
||||
_prefix(prefix),
|
||||
_target(target),
|
||||
_command(command),
|
||||
_raw_line(raw),
|
||||
_arguments(arguments)
|
||||
{
|
||||
}
|
||||
|
||||
Message Message::parse(const QString &l)
|
||||
{
|
||||
QString prefix;
|
||||
QString target;
|
||||
QString command;
|
||||
QStringList arguments;
|
||||
QString raw(l);
|
||||
QString line(l);
|
||||
|
||||
int pos = 0;
|
||||
|
||||
if (line.startsWith(':'))
|
||||
{
|
||||
pos = line.indexOf(' ', 1);
|
||||
prefix = line.mid(1, pos - 1);
|
||||
line = line.mid(pos + 1, line.length());
|
||||
}
|
||||
|
||||
if (-1 != (pos = line.indexOf(" :")))
|
||||
{
|
||||
QString tmp(line.mid(pos + 2, line.length()));
|
||||
arguments.append(line.left(pos).split(' '));
|
||||
arguments.append(tmp.split(' '));
|
||||
}
|
||||
else
|
||||
{
|
||||
arguments = line.split(' ');
|
||||
}
|
||||
|
||||
if (! arguments.isEmpty())
|
||||
{
|
||||
command = arguments.front();
|
||||
arguments.pop_front();
|
||||
}
|
||||
|
||||
if (! arguments.isEmpty())
|
||||
{
|
||||
target = arguments.front();
|
||||
arguments.pop_front();
|
||||
}
|
||||
|
||||
return Message(prefix, target, command, raw, arguments);
|
||||
}
|
||||
|
||||
QString Message::getPrefix() const
|
||||
{
|
||||
return _prefix;
|
||||
}
|
||||
|
||||
QString Message::getTarget() const
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
QString Message::getCommand() const
|
||||
{
|
||||
return _command;
|
||||
}
|
||||
|
||||
QString Message::getRawLine() const
|
||||
{
|
||||
return _raw_line;
|
||||
}
|
||||
|
||||
QStringList Message::getArguments() const
|
||||
{
|
||||
return _arguments;
|
||||
}
|
||||
30
plugins/IrcClientPlugin/message.h
Normal file
30
plugins/IrcClientPlugin/message.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
static Message parse(const QString& l);
|
||||
|
||||
QString getPrefix() const;
|
||||
QString getTarget() const;
|
||||
QString getCommand() const;
|
||||
QString getRawLine() const;
|
||||
QStringList getArguments() const;
|
||||
|
||||
protected:
|
||||
Message(const QString& prefix, const QString& target, const QString& command, const QString& raw, const QStringList& arguments);
|
||||
|
||||
private:
|
||||
QString _prefix;
|
||||
QString _target;
|
||||
QString _command;
|
||||
QString _raw_line;
|
||||
QStringList _arguments;
|
||||
|
||||
};
|
||||
|
||||
#endif // MESSAGE_H
|
||||
6
plugins/IrcClientPlugin/messagehandler.cpp
Normal file
6
plugins/IrcClientPlugin/messagehandler.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "messagehandler.h"
|
||||
|
||||
MessageHandler::MessageHandler() :
|
||||
QObject(0)
|
||||
{
|
||||
}
|
||||
20
plugins/IrcClientPlugin/messagehandler.h
Normal file
20
plugins/IrcClientPlugin/messagehandler.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef MESSAGEHANDLER_H
|
||||
#define MESSAGEHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Client;
|
||||
class Message;
|
||||
|
||||
class MessageHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
MessageHandler();
|
||||
|
||||
public:
|
||||
virtual void handle(Client* client, const Message &message) = 0;
|
||||
};
|
||||
|
||||
#endif // MESSAGEHANDLER_H
|
||||
11
plugins/IrcClientPlugin/pingmessagehandler.cpp
Normal file
11
plugins/IrcClientPlugin/pingmessagehandler.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "pingmessagehandler.h"
|
||||
|
||||
PingMessageHandler::PingMessageHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void PingMessageHandler::handle(Client *client, const Message &message)
|
||||
{
|
||||
QString pongMessage = message.getTarget();
|
||||
client->sendPong(pongMessage);
|
||||
}
|
||||
15
plugins/IrcClientPlugin/pingmessagehandler.h
Normal file
15
plugins/IrcClientPlugin/pingmessagehandler.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef PINGMESSAGEHANDLER_H
|
||||
#define PINGMESSAGEHANDLER_H
|
||||
|
||||
#include "message.h"
|
||||
#include "client.h"
|
||||
#include "messagehandler.h"
|
||||
|
||||
class PingMessageHandler : public MessageHandler
|
||||
{
|
||||
public:
|
||||
PingMessageHandler();
|
||||
virtual void handle(Client *client, const Message& message);
|
||||
};
|
||||
|
||||
#endif // PINGMESSAGEHANDLER_H
|
||||
19
plugins/IrcClientPlugin/privmsgmessagehandler.cpp
Normal file
19
plugins/IrcClientPlugin/privmsgmessagehandler.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "privmsgmessagehandler.h"
|
||||
#include "hostmask.h"
|
||||
|
||||
PrivmsgMessageHandler::PrivmsgMessageHandler()
|
||||
{
|
||||
// _tray_icon = new QSystemTrayIcon(this);
|
||||
// _tray_icon->show();
|
||||
}
|
||||
|
||||
void PrivmsgMessageHandler::handle(Client *client, const Message &message)
|
||||
{
|
||||
QString target = message.getTarget();
|
||||
QString text = message.getArguments().join(" ");
|
||||
Hostmask from = Hostmask::parse(message.getPrefix());
|
||||
|
||||
client->didReceivePrivmsg(from, target, text);
|
||||
|
||||
// _tray_icon->showMessage("Message Received", text);
|
||||
}
|
||||
21
plugins/IrcClientPlugin/privmsgmessagehandler.h
Normal file
21
plugins/IrcClientPlugin/privmsgmessagehandler.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef PRIVMSGMESSAGEHANDLER_H
|
||||
#define PRIVMSGMESSAGEHANDLER_H
|
||||
|
||||
#include "messagehandler.h"
|
||||
#include "client.h"
|
||||
#include "message.h"
|
||||
|
||||
//#include <QSystemTrayIcon>
|
||||
|
||||
class PrivmsgMessageHandler : public MessageHandler
|
||||
{
|
||||
public:
|
||||
PrivmsgMessageHandler();
|
||||
|
||||
virtual void handle(Client *client, const Message &message);
|
||||
|
||||
private:
|
||||
//QSystemTrayIcon *_tray_icon;
|
||||
};
|
||||
|
||||
#endif // PRIVMSGMESSAGEHANDLER_H
|
||||
23
plugins/IrcClientPlugin/quitmessagehandler.cpp
Normal file
23
plugins/IrcClientPlugin/quitmessagehandler.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "quitmessagehandler.h"
|
||||
|
||||
quitmessagehandler::quitmessagehandler()
|
||||
{
|
||||
|
||||
}
|
||||
void quitmessagehandler::handle(Client *client, const Message &message)
|
||||
{
|
||||
|
||||
QString target = message.getTarget();
|
||||
QString text = message.getArguments().join(" ");
|
||||
Hostmask from = Hostmask::parse(message.getPrefix());
|
||||
|
||||
|
||||
client->didReceiveQuitMsg(from, target, text);
|
||||
|
||||
// for (QString data : message.getArguments()) // iterate over array fibonacci
|
||||
// {
|
||||
// qDebug() << "GOT:" << data;
|
||||
// }
|
||||
//QString pongMessage = message.getTarget();
|
||||
//client->sendPong(pongMessage);
|
||||
}
|
||||
15
plugins/IrcClientPlugin/quitmessagehandler.h
Normal file
15
plugins/IrcClientPlugin/quitmessagehandler.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef QUITMESSAGEHANDLER_H
|
||||
#define QUITMESSAGEHANDLER_H
|
||||
|
||||
#include "message.h"
|
||||
#include "client.h"
|
||||
#include "messagehandler.h"
|
||||
|
||||
class quitmessagehandler: public MessageHandler
|
||||
{
|
||||
public:
|
||||
quitmessagehandler();
|
||||
virtual void handle(Client *client, const Message& message);
|
||||
};
|
||||
|
||||
#endif // QUITMESSAGEHANDLER_H
|
||||
21
plugins/IrcClientPlugin/testhandler.cpp
Normal file
21
plugins/IrcClientPlugin/testhandler.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "testhandler.h"
|
||||
#include <QDebug>
|
||||
|
||||
testhandler::testhandler()
|
||||
{
|
||||
|
||||
}
|
||||
void testhandler::handle(Client *client, const Message &message)
|
||||
{
|
||||
|
||||
QString text = message.getArguments().join(" ");
|
||||
|
||||
client->didReceiveNamesList(text);
|
||||
|
||||
// for (QString data : message.getArguments()) // iterate over array fibonacci
|
||||
// {
|
||||
// qDebug() << "GOT:" << data;
|
||||
// }
|
||||
//QString pongMessage = message.getTarget();
|
||||
//client->sendPong(pongMessage);
|
||||
}
|
||||
15
plugins/IrcClientPlugin/testhandler.h
Normal file
15
plugins/IrcClientPlugin/testhandler.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef TESTHANDLER_H
|
||||
#define TESTHANDLER_H
|
||||
|
||||
#include "message.h"
|
||||
#include "client.h"
|
||||
#include "messagehandler.h"
|
||||
|
||||
class testhandler: public MessageHandler
|
||||
{
|
||||
public:
|
||||
testhandler();
|
||||
virtual void handle(Client *client, const Message& message);
|
||||
};
|
||||
|
||||
#endif // TESTHANDLER_H
|
||||
24
plugins/IrcClientPlugin/topichandler.cpp
Normal file
24
plugins/IrcClientPlugin/topichandler.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "topichandler.h"
|
||||
|
||||
topichandler::topichandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void topichandler::handle(Client *client, const Message &message)
|
||||
{
|
||||
|
||||
QString target = message.getTarget();
|
||||
QString text = message.getArguments().join(" ");
|
||||
Hostmask from = Hostmask::parse(message.getPrefix());
|
||||
|
||||
|
||||
client->didReceiveTopic(from, target, text);
|
||||
|
||||
// for (QString data : message.getArguments()) // iterate over array fibonacci
|
||||
// {
|
||||
// qDebug() << "GOT:" << data;
|
||||
// }
|
||||
//QString pongMessage = message.getTarget();
|
||||
//client->sendPong(pongMessage);
|
||||
}
|
||||
15
plugins/IrcClientPlugin/topichandler.h
Normal file
15
plugins/IrcClientPlugin/topichandler.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef TOPICHANDLER_H
|
||||
#define TOPICHANDLER_H
|
||||
|
||||
#include "message.h"
|
||||
#include "client.h"
|
||||
#include "messagehandler.h"
|
||||
|
||||
class topichandler: public MessageHandler
|
||||
{
|
||||
public:
|
||||
topichandler();
|
||||
virtual void handle(Client *client, const Message& message);
|
||||
};
|
||||
|
||||
#endif // TOPICHANDLER_H
|
||||
Reference in New Issue
Block a user