mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added irc support
This commit is contained in:
parent
9ee286f60f
commit
cf23838099
11 changed files with 455 additions and 13 deletions
|
@ -129,6 +129,7 @@ SOURCES += \
|
|||
src/providers/ffz/FfzEmotes.cpp \
|
||||
src/providers/ffz/FfzModBadge.cpp \
|
||||
src/providers/irc/AbstractIrcServer.cpp \
|
||||
src/providers/irc/Irc2.cpp \
|
||||
src/providers/irc/IrcAccount.cpp \
|
||||
src/providers/irc/IrcChannel2.cpp \
|
||||
src/providers/irc/IrcConnection2.cpp \
|
||||
|
@ -177,6 +178,8 @@ SOURCES += \
|
|||
src/widgets/AccountSwitchWidget.cpp \
|
||||
src/widgets/AttachedWindow.cpp \
|
||||
src/widgets/dialogs/EmotePopup.cpp \
|
||||
src/widgets/dialogs/IrcConnectionEditor.cpp \
|
||||
src/widgets/dialogs/IrcConnectionPopup.cpp \
|
||||
src/widgets/dialogs/LastRunCrashDialog.cpp \
|
||||
src/widgets/dialogs/LoginDialog.cpp \
|
||||
src/widgets/dialogs/LogsPopup.cpp \
|
||||
|
@ -294,6 +297,7 @@ HEADERS += \
|
|||
src/providers/ffz/FfzEmotes.hpp \
|
||||
src/providers/ffz/FfzModBadge.hpp \
|
||||
src/providers/irc/AbstractIrcServer.hpp \
|
||||
src/providers/irc/Irc2.hpp \
|
||||
src/providers/irc/IrcAccount.hpp \
|
||||
src/providers/irc/IrcChannel2.hpp \
|
||||
src/providers/irc/IrcConnection2.hpp \
|
||||
|
@ -354,6 +358,8 @@ HEADERS += \
|
|||
src/widgets/AccountSwitchWidget.hpp \
|
||||
src/widgets/AttachedWindow.hpp \
|
||||
src/widgets/dialogs/EmotePopup.hpp \
|
||||
src/widgets/dialogs/IrcConnectionEditor.hpp \
|
||||
src/widgets/dialogs/IrcConnectionPopup.hpp \
|
||||
src/widgets/dialogs/LastRunCrashDialog.hpp \
|
||||
src/widgets/dialogs/LoginDialog.hpp \
|
||||
src/widgets/dialogs/LogsPopup.hpp \
|
||||
|
@ -405,7 +411,8 @@ RESOURCES += \
|
|||
|
||||
DISTFILES +=
|
||||
|
||||
FORMS +=
|
||||
FORMS += \
|
||||
src/widgets/dialogs/IrcConnectionEditor.ui
|
||||
|
||||
# do not use windows min/max macros
|
||||
#win32 {
|
||||
|
|
|
@ -116,6 +116,8 @@ void Application::save()
|
|||
|
||||
void Application::initNm(Paths &paths)
|
||||
{
|
||||
(void)paths;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# if defined QT_NO_DEBUG || defined C_DEBUG_NM
|
||||
registerNmHost(paths);
|
||||
|
|
73
src/providers/irc/Irc2.cpp
Normal file
73
src/providers/irc/Irc2.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "Irc2.hpp"
|
||||
|
||||
#include "common/SignalVectorModel.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
class Model : public SignalVectorModel<IrcConnection_>
|
||||
{
|
||||
public:
|
||||
Model(QObject *parent)
|
||||
: SignalVectorModel<IrcConnection_>(6, parent)
|
||||
{
|
||||
}
|
||||
|
||||
// turn a vector item into a model row
|
||||
IrcConnection_ getItemFromRow(std::vector<QStandardItem *> &row,
|
||||
const IrcConnection_ &original)
|
||||
{
|
||||
return IrcConnection_{
|
||||
row[0]->data(Qt::EditRole).toString(), // host
|
||||
row[1]->data(Qt::EditRole).toInt(), // port
|
||||
row[2]->data(Qt::Checked).toBool(), // ssl
|
||||
row[3]->data(Qt::EditRole).toString(), // user
|
||||
row[4]->data(Qt::EditRole).toString(), // nick
|
||||
row[5]->data(Qt::EditRole).toString(), // password
|
||||
original.id, // id
|
||||
};
|
||||
}
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
void getRowFromItem(const IrcConnection_ &item,
|
||||
std::vector<QStandardItem *> &row)
|
||||
{
|
||||
setStringItem(row[0], item.host);
|
||||
setStringItem(row[1], QString::number(item.port));
|
||||
setBoolItem(row[2], item.ssl);
|
||||
setStringItem(row[3], item.user);
|
||||
setStringItem(row[4], item.nick);
|
||||
setStringItem(row[5], item.password);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static std::atomic_int currentId;
|
||||
|
||||
Irc::Irc()
|
||||
{
|
||||
}
|
||||
|
||||
IrcConnection_ IrcConnection_::unique()
|
||||
{
|
||||
IrcConnection_ c;
|
||||
c.id = currentId++;
|
||||
c.port = 6697;
|
||||
return c;
|
||||
}
|
||||
|
||||
QAbstractTableModel *Irc::newConnectionModel(QObject *parent)
|
||||
{
|
||||
auto model = new Model(parent);
|
||||
model->init(&this->connections);
|
||||
return model;
|
||||
}
|
||||
|
||||
Irc &Irc::getInstance()
|
||||
{
|
||||
static Irc irc;
|
||||
return irc;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
38
src/providers/irc/Irc2.hpp
Normal file
38
src/providers/irc/Irc2.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <common/SignalVector.hpp>
|
||||
|
||||
class QAbstractTableModel;
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct IrcConnection_ {
|
||||
QString host;
|
||||
int port;
|
||||
bool ssl;
|
||||
|
||||
QString user;
|
||||
QString nick;
|
||||
QString password;
|
||||
|
||||
int id;
|
||||
|
||||
// makes an IrcConnection with a unique id
|
||||
static IrcConnection_ unique();
|
||||
};
|
||||
|
||||
class Irc
|
||||
{
|
||||
public:
|
||||
Irc();
|
||||
|
||||
static Irc &getInstance();
|
||||
|
||||
UnsortedSignalVector<IrcConnection_> connections;
|
||||
QAbstractTableModel *newConnectionModel(QObject *parent);
|
||||
|
||||
signals:
|
||||
void connectionUpdated(int id);
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -126,6 +126,20 @@ public:
|
|||
return LayoutCreator<T2>(item);
|
||||
}
|
||||
|
||||
template <typename Slot, typename Func>
|
||||
LayoutCreator<T> connect(Slot slot, QObject *receiver, Func func)
|
||||
{
|
||||
QObject::connect(this->getElement(), slot, receiver, func);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
LayoutCreator<T> onClick(QObject *receiver, Func func)
|
||||
{
|
||||
QObject::connect(this->getElement(), &T::clicked, receiver, func);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
T *item_;
|
||||
|
||||
|
@ -169,4 +183,12 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
LayoutCreator<T> makeDialog(Args &&... args)
|
||||
{
|
||||
T *t = new T(std::forward<Args>(args)...);
|
||||
t->setAttribute(Qt::WA_DeleteOnClose);
|
||||
return LayoutCreator<T>(t);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
16
src/widgets/dialogs/IrcConnectionEditor.cpp
Normal file
16
src/widgets/dialogs/IrcConnectionEditor.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "IrcConnectionEditor.hpp"
|
||||
#include "ui_IrcConnectionEditor.h"
|
||||
|
||||
IrcConnectionEditor::IrcConnectionEditor(bool isAdd, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::IrcConnectionEditor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->setWindowTitle(QString(isAdd ? "Add " : "Edit ") + "Irc Connection");
|
||||
}
|
||||
|
||||
IrcConnectionEditor::~IrcConnectionEditor()
|
||||
{
|
||||
delete ui;
|
||||
}
|
19
src/widgets/dialogs/IrcConnectionEditor.hpp
Normal file
19
src/widgets/dialogs/IrcConnectionEditor.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class IrcConnectionEditor;
|
||||
}
|
||||
|
||||
class IrcConnectionEditor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IrcConnectionEditor(bool isAdd = false, QWidget *parent = nullptr);
|
||||
~IrcConnectionEditor();
|
||||
|
||||
private:
|
||||
Ui::IrcConnectionEditor *ui;
|
||||
};
|
159
src/widgets/dialogs/IrcConnectionEditor.ui
Normal file
159
src/widgets/dialogs/IrcConnectionEditor.ui
Normal file
|
@ -0,0 +1,159 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>IrcConnectionEditor</class>
|
||||
<widget class="QDialog" name="IrcConnectionEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>264</width>
|
||||
<height>258</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="serverLabel">
|
||||
<property name="text">
|
||||
<string>Server:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="serverLineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="portLabel">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="portSpinBox">
|
||||
<property name="maximum">
|
||||
<number>65636</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>6697</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="securityLabel">
|
||||
<property name="text">
|
||||
<string>SSL:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="securityCheckBox">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="userNameLabel">
|
||||
<property name="text">
|
||||
<string>User Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="userNameLineEdit"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="nickNameLabel">
|
||||
<property name="text">
|
||||
<string>Nick Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="nickNameLineEdit"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="passwordLabel">
|
||||
<property name="text">
|
||||
<string>Password:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="passwordLineEdit">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>IrcConnectionEditor</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>IrcConnectionEditor</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
36
src/widgets/dialogs/IrcConnectionPopup.cpp
Normal file
36
src/widgets/dialogs/IrcConnectionPopup.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "IrcConnectionPopup.hpp"
|
||||
|
||||
#include "providers/irc/Irc2.hpp"
|
||||
#include "util/LayoutHelper.hpp"
|
||||
#include "widgets/helper/EditableModelView.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QTableView>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
IrcConnectionPopup::IrcConnectionPopup(QWidget *parent)
|
||||
: BaseWindow(parent, BaseWindow::Flags::EnableCustomFrame)
|
||||
{
|
||||
this->setWindowTitle("Edit Irc Connections");
|
||||
|
||||
// view
|
||||
auto view =
|
||||
new EditableModelView(Irc::getInstance().newConnectionModel(this));
|
||||
|
||||
view->setTitles({"host", "port", "ssl", "user", "nick", "password"});
|
||||
view->getTableView()->horizontalHeader()->resizeSection(0, 140);
|
||||
view->getTableView()->horizontalHeader()->resizeSection(1, 30);
|
||||
view->getTableView()->horizontalHeader()->resizeSection(2, 30);
|
||||
|
||||
this->setScaleIndependantSize(800, 500);
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
Irc::getInstance().connections.appendItem(IrcConnection_::unique());
|
||||
});
|
||||
|
||||
// init layout
|
||||
this->getLayoutContainer()->setLayout(makeLayout<QHBoxLayout>({view}));
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
13
src/widgets/dialogs/IrcConnectionPopup.hpp
Normal file
13
src/widgets/dialogs/IrcConnectionPopup.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class IrcConnectionPopup : public BaseWindow
|
||||
{
|
||||
public:
|
||||
IrcConnectionPopup(QWidget *parent);
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -5,6 +5,8 @@
|
|||
#include "singletons/Theme.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/dialogs/IrcConnectionEditor.hpp"
|
||||
#include "widgets/dialogs/IrcConnectionPopup.hpp"
|
||||
#include "widgets/helper/NotebookTab.hpp"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
|
@ -14,6 +16,10 @@
|
|||
#include <QLineEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <QTableView>
|
||||
#include "providers/irc/Irc2.hpp"
|
||||
#include "widgets/helper/EditableModelView.hpp"
|
||||
|
||||
#define TAB_TWITCH 0
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -122,21 +128,72 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
|||
}
|
||||
|
||||
// irc
|
||||
/*
|
||||
{
|
||||
LayoutCreator<QWidget> obj(new QWidget());
|
||||
auto vbox = obj.setLayoutType<QVBoxLayout>();
|
||||
auto form = vbox.emplace<QFormLayout>();
|
||||
auto outerBox = obj.setLayoutType<QVBoxLayout>();
|
||||
// outerBox.emplace<QLabel>("Connection:");
|
||||
|
||||
form->addRow(new QLabel("User name:"), new QLineEdit());
|
||||
form->addRow(new QLabel("First nick choice:"), new QLineEdit());
|
||||
form->addRow(new QLabel("Second nick choice:"), new QLineEdit());
|
||||
form->addRow(new QLabel("Third nick choice:"), new QLineEdit());
|
||||
{
|
||||
auto view = new EditableModelView(
|
||||
Irc::getInstance().newConnectionModel(this));
|
||||
|
||||
view->setTitles(
|
||||
{"host", "port", "ssl", "user", "nick", "password"});
|
||||
view->getTableView()->horizontalHeader()->resizeSection(0, 140);
|
||||
view->getTableView()->horizontalHeader()->resizeSection(1, 30);
|
||||
view->getTableView()->horizontalHeader()->resizeSection(2, 30);
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
Irc::getInstance().connections.appendItem(
|
||||
IrcConnection_::unique());
|
||||
});
|
||||
|
||||
outerBox->addWidget(view);
|
||||
|
||||
// auto box = outerBox.emplace<QHBoxLayout>().withoutMargin();
|
||||
|
||||
// auto conns = box.emplace<QListView>();
|
||||
// conns->addActions({new QAction("hackint")});
|
||||
|
||||
// auto buttons = box.emplace<QVBoxLayout>().withoutMargin();
|
||||
|
||||
// buttons.emplace<QPushButton>("Add").onClick(this, [this]() {
|
||||
// (new IrcConnectionPopup(this))
|
||||
// ->show(); // XXX: don't show multiple
|
||||
// });
|
||||
|
||||
// buttons.emplace<QPushButton>("Edit");
|
||||
// buttons.emplace<QPushButton>("Remove");
|
||||
// buttons->addStretch(1);
|
||||
}
|
||||
|
||||
{
|
||||
auto box = outerBox.emplace<QHBoxLayout>().withoutMargin();
|
||||
box.emplace<QLabel>("Channel:");
|
||||
box.emplace<QLineEdit>();
|
||||
}
|
||||
|
||||
// auto vbox = obj.setLayoutType<QVBoxLayout>();
|
||||
// auto form = vbox.emplace<QFormLayout>();
|
||||
|
||||
// auto servers = new QComboBox;
|
||||
// auto accounts = new QComboBox;
|
||||
//servers->setEditable(true);
|
||||
//servers->addItems(
|
||||
// {"irc://irc.hackint.org:6697", "irc://irc.somethingelse.com:6667"});
|
||||
|
||||
// form->addRow("Server:", servers);
|
||||
// form->addRow("Account:", accounts);
|
||||
// form->addRow("Channel:", new QLineEdit());
|
||||
|
||||
// form->addRow("User name:", new QLineEdit());
|
||||
// form->addRow("First nick choice:", new QLineEdit());
|
||||
// form->addRow("Second nick choice:", new QLineEdit());
|
||||
// form->addRow("Third nick choice:", new QLineEdit());
|
||||
|
||||
auto tab = notebook->addPage(obj.getElement());
|
||||
tab->setCustomTitle("Irc");
|
||||
}
|
||||
*/
|
||||
|
||||
layout->setStretchFactor(notebook.getElement(), 1);
|
||||
|
||||
|
@ -151,7 +208,7 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
|||
[=](bool) { this->close(); });
|
||||
}
|
||||
|
||||
this->setScaleIndependantSize(300, 310);
|
||||
this->setMinimumSize(300, 310);
|
||||
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
||||
this->ui_.twitch.channel->setFocus();
|
||||
|
||||
|
|
Loading…
Reference in a new issue