diff --git a/SparrowBot.pro b/SparrowBot.pro index 2071559..98f9b11 100644 --- a/SparrowBot.pro +++ b/SparrowBot.pro @@ -18,7 +18,8 @@ SOURCES += mainwindow.cpp \ ircbot.cpp \ botapp.cpp \ module.cpp \ - basemodule.cpp + basemodule.cpp \ + main.cpp HEADERS += mainwindow.h \ socketirc.h \ diff --git a/basemodule.h b/basemodule.h index a5057ad..c16a1e8 100644 --- a/basemodule.h +++ b/basemodule.h @@ -2,6 +2,7 @@ #define BASEMODULE_H #include "module.h" +#include "user.h" class BaseModule : public Module { diff --git a/botapp.cpp b/botapp.cpp index b43eeec..25caa8e 100644 --- a/botapp.cpp +++ b/botapp.cpp @@ -1,4 +1,7 @@ #include "botapp.h" +#include "mainwindow.h" +#include "ircbot.h" +#include "socketirc.h" BotApp::BotApp(int argc, char** argv) : nogui(false), @@ -65,8 +68,7 @@ int BotApp::exec() return sock->connectToServer(coreApp); } -int main(int argc, char *argv[]) +void BotApp::addModule(Module* module) { - BotApp app = BotApp(argc, argv); - return app.exec(); + bot->addModule(module); } diff --git a/botapp.h b/botapp.h index 2797870..67ded7a 100644 --- a/botapp.h +++ b/botapp.h @@ -1,13 +1,17 @@ #ifndef BOTAPP_H #define BOTAPP_H -#include "mainwindow.h" -#include "socketirc.h" -#include "ircbot.h" #include -class BotApp +class Module; +class IRCBot; +class SocketIRC; +class MainWindow; + +class BotApp : public QObject { + Q_OBJECT + bool nogui = false; QString server = "irc.freenode.net"; int port = 6667; @@ -21,6 +25,7 @@ class BotApp public: BotApp(int argc, char** argv); + void addModule(Module* module); ~BotApp(); int exec(); }; diff --git a/ircbot.cpp b/ircbot.cpp index 12458df..702556e 100644 --- a/ircbot.cpp +++ b/ircbot.cpp @@ -1,9 +1,6 @@ #include "ircbot.h" -#include -#include -#include - -using namespace std; +#include "basemodule.h" +#include "message.h" IRCBot::IRCBot(QString nick_, QString chan_) : nick(nick_), chan(chan_) { diff --git a/ircbot.h b/ircbot.h index f30b5b7..8bcaea4 100644 --- a/ircbot.h +++ b/ircbot.h @@ -1,12 +1,12 @@ #ifndef IRCBOT_H #define IRCBOT_H -#include "user.h" -#include "message.h" #include #include -#include "module.h" -#include "basemodule.h" + + +class Module; +class BaseModule; class IRCBot : public QObject { @@ -20,7 +20,7 @@ class IRCBot : public QObject public: IRCBot(QString nick_, QString chan_); -protected: +public: void addModule(Module* module); public slots: diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a65de32 --- /dev/null +++ b/main.cpp @@ -0,0 +1,25 @@ +#include "botapp.h" +#include "module.h" +#include "message.h" + +class CustomModule : public Module +{ + CustomModule() : Module(), answer("coucou") {} + + bool messageHandler(Message msg) + { + return msg.args.compare("plop ?") == 0; + } + + QString getName() + { + return "custom"; + } +}; + +int main(int argc, char *argv[]) +{ + BotApp app = BotApp(argc, argv); + app.addModule(new CustomModule()); + return app.exec(); +} diff --git a/mainwindow.h b/mainwindow.h index b518d61..d9f9669 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,11 +1,12 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include "prompt.h" #include -#include -#include -#include + +class Prompt; +class QTextBrowser; +class QSlider; +class QProgressBar; namespace Ui { class MainWindow; diff --git a/message.cpp b/message.cpp index 9b2fe3a..c3ae9d4 100644 --- a/message.cpp +++ b/message.cpp @@ -1,9 +1,7 @@ #include "message.h" #include -#include - -using namespace std; +#include Message::Message(QString str) { diff --git a/message.h b/message.h index 91705f6..f165a03 100644 --- a/message.h +++ b/message.h @@ -1,10 +1,8 @@ #ifndef MESSAGE_H #define MESSAGE_H -#include #include -#include -#include "user.h" + class Message { diff --git a/module.cpp b/module.cpp index f901cd2..804039b 100644 --- a/module.cpp +++ b/module.cpp @@ -15,22 +15,22 @@ void Module::setEnabled(bool newStatus) enabled = newStatus; } -QString getNick() +QString Module::getNick() { return nick; } -QString getChan() +QString Module::getChan() { return chan; } -void setNick(QString nick_) +void Module::setNick(QString nick_) { nick = nick_; } -void setChan(QString chan_) +void Module::setChan(QString chan_) { chan = chan_; } diff --git a/socketirc.cpp b/socketirc.cpp index c75c439..e86b503 100644 --- a/socketirc.cpp +++ b/socketirc.cpp @@ -1,5 +1,6 @@ #include "socketirc.h" #include +#include SocketIRC::SocketIRC() : server("irc.freenode.net"), port(6667), isConnected(false) { diff --git a/socketirc.h b/socketirc.h index 3a50630..962b3f4 100644 --- a/socketirc.h +++ b/socketirc.h @@ -2,9 +2,8 @@ #define SOCKETIRC_H #include -#include -#include -#include + +class QCoreApplication; class SocketIRC : public QObject { diff --git a/ui_mainwindow.h b/ui_mainwindow.h new file mode 100644 index 0000000..c283a1c --- /dev/null +++ b/ui_mainwindow.h @@ -0,0 +1,74 @@ +/******************************************************************************** +** Form generated from reading UI file 'mainwindow.ui' +** +** Created by: Qt User Interface Compiler version 5.4.1 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_MAINWINDOW_H +#define UI_MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "prompt.h" + +QT_BEGIN_NAMESPACE + +class Ui_MainWindow +{ +public: + QWidget *centralWidget; + QGridLayout *gridLayout; + QTextBrowser *monitoringConsole; + Prompt *prompt; + + void setupUi(QMainWindow *MainWindow) + { + if (MainWindow->objectName().isEmpty()) + MainWindow->setObjectName(QStringLiteral("MainWindow")); + MainWindow->resize(374, 404); + centralWidget = new QWidget(MainWindow); + centralWidget->setObjectName(QStringLiteral("centralWidget")); + gridLayout = new QGridLayout(centralWidget); + gridLayout->setSpacing(6); + gridLayout->setContentsMargins(11, 11, 11, 11); + gridLayout->setObjectName(QStringLiteral("gridLayout")); + monitoringConsole = new QTextBrowser(centralWidget); + monitoringConsole->setObjectName(QStringLiteral("monitoringConsole")); + + gridLayout->addWidget(monitoringConsole, 1, 0, 1, 2); + + prompt = new Prompt(centralWidget); + prompt->setObjectName(QStringLiteral("prompt")); + + gridLayout->addWidget(prompt, 0, 0, 1, 2); + + MainWindow->setCentralWidget(centralWidget); + + retranslateUi(MainWindow); + + QMetaObject::connectSlotsByName(MainWindow); + } // setupUi + + void retranslateUi(QMainWindow *MainWindow) + { + MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0)); + } // retranslateUi + +}; + +namespace Ui { + class MainWindow: public Ui_MainWindow {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_MAINWINDOW_H