51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#include "mainwindow.h"
|
|
#include "socketirc.h"
|
|
#include "sparrowbot.h"
|
|
#include <QApplication>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
// create the socket
|
|
SocketIRC sock;
|
|
sock.setServer("irc.freenode.net");
|
|
sock.setPort(6667);
|
|
|
|
// create the bot
|
|
SparrowBot* bot = new SparrowBot("SparrowBot", "epicsparrow");
|
|
|
|
// connect the bot to the socket
|
|
QObject::connect(&sock, SIGNAL(receivedMsg(QString)), bot, SLOT(receiveMsg(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), &sock, SLOT(sendMsg(QString)));
|
|
|
|
// parsing arguments
|
|
bool nogui = argc > 1 && QString(argv[1]).compare("-nogui") == 0;
|
|
|
|
// set up UI
|
|
if(!nogui)
|
|
{
|
|
QApplication app(argc, argv);
|
|
|
|
// init window
|
|
MainWindow w;
|
|
QObject::connect(&sock, SIGNAL(receivedMsg(QString)), w.getConsole(), SLOT(append(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), w.getConsole(), SLOT(append(QString)));
|
|
QObject::connect(w.getPrompt(), SIGNAL(sendMsg(QString)), &sock, SLOT(sendMsg(QString)));
|
|
QObject::connect(w.getPrompt(), SIGNAL(returnPressed()), w.getPrompt(), SLOT(confirmationPerformed()));
|
|
w.show();
|
|
|
|
QObject::connect(&app, SIGNAL(aboutToQuit()), bot, SLOT(disconnect()));
|
|
|
|
sock.connectToServer(&app);
|
|
}
|
|
else
|
|
{
|
|
QCoreApplication coreApp(argc, argv);
|
|
|
|
QObject::connect(&coreApp, SIGNAL(aboutToQuit()), bot, SLOT(disconnect()));
|
|
|
|
sock.connectToServer(&coreApp);
|
|
}
|
|
delete(bot);
|
|
return 0;
|
|
}
|