added loading and saving of irc servers
This commit is contained in:
@@ -1,16 +1,50 @@
|
||||
#include "IrcConnectionEditor.hpp"
|
||||
#include "ui_IrcConnectionEditor.h"
|
||||
|
||||
IrcConnectionEditor::IrcConnectionEditor(bool isAdd, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::IrcConnectionEditor)
|
||||
namespace chatterino {
|
||||
|
||||
IrcConnectionEditor::IrcConnectionEditor(const IrcConnection_ &data, bool isAdd,
|
||||
QWidget *parent)
|
||||
|
||||
: QDialog(parent, Qt::WindowStaysOnTopHint)
|
||||
, ui_(new Ui::IrcConnectionEditor)
|
||||
, data_(data)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->ui_->setupUi(this);
|
||||
|
||||
this->setWindowTitle(QString(isAdd ? "Add " : "Edit ") + "Irc Connection");
|
||||
}
|
||||
|
||||
QObject::connect(this->ui_->userNameLineEdit, &QLineEdit::textChanged, this,
|
||||
[this](const QString &text) {
|
||||
this->ui_->nickNameLineEdit->setPlaceholderText(text);
|
||||
this->ui_->realNameLineEdit->setPlaceholderText(text);
|
||||
});
|
||||
|
||||
this->ui_->serverLineEdit->setText(data.host);
|
||||
this->ui_->portSpinBox->setValue(data.port);
|
||||
this->ui_->securityCheckBox->setChecked(data.ssl);
|
||||
this->ui_->userNameLineEdit->setText(data.user);
|
||||
this->ui_->nickNameLineEdit->setText(data.nick);
|
||||
this->ui_->realNameLineEdit->setText(data.real);
|
||||
this->ui_->passwordLineEdit->setText(data.password);
|
||||
} // namespace chatterino
|
||||
|
||||
IrcConnectionEditor::~IrcConnectionEditor()
|
||||
{
|
||||
delete ui;
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
IrcConnection_ IrcConnectionEditor::data()
|
||||
{
|
||||
auto data = this->data_;
|
||||
data.host = this->ui_->serverLineEdit->text();
|
||||
data.port = this->ui_->portSpinBox->value();
|
||||
data.ssl = this->ui_->securityCheckBox->isChecked();
|
||||
data.user = this->ui_->userNameLineEdit->text();
|
||||
data.nick = this->ui_->nickNameLineEdit->text();
|
||||
data.real = this->ui_->realNameLineEdit->text();
|
||||
data.password = this->ui_->passwordLineEdit->text();
|
||||
return data;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "providers/irc/Irc2.hpp"
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
|
||||
namespace Ui {
|
||||
class IrcConnectionEditor;
|
||||
}
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct IrcConnection_;
|
||||
|
||||
class IrcConnectionEditor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IrcConnectionEditor(bool isAdd = false, QWidget *parent = nullptr);
|
||||
explicit IrcConnectionEditor(const IrcConnection_ &data, bool isAdd = false,
|
||||
QWidget *parent = nullptr);
|
||||
~IrcConnectionEditor();
|
||||
|
||||
IrcConnection_ data();
|
||||
|
||||
private:
|
||||
Ui::IrcConnectionEditor *ui;
|
||||
Ui::IrcConnectionEditor *ui_;
|
||||
IrcConnection_ data_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>IrcConnectionEditor</class>
|
||||
<widget class="QDialog" name="IrcConnectionEditor">
|
||||
<widget class="QWidget" name="IrcConnectionEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>264</width>
|
||||
<height>258</height>
|
||||
<height>350</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -19,12 +19,16 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="serverLabel">
|
||||
<property name="text">
|
||||
<string>Server:</string>
|
||||
<string>Host:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="serverLineEdit"/>
|
||||
<widget class="QLineEdit" name="serverLineEdit">
|
||||
<property name="placeholderText">
|
||||
<string>irc.example.com</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="portLabel">
|
||||
@@ -94,21 +98,78 @@
|
||||
<widget class="QLineEdit" name="nickNameLineEdit"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="realNameLabel">
|
||||
<property name="text">
|
||||
<string>Real Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="realNameLineEdit"/>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="loginMethodLabel">
|
||||
<property name="text">
|
||||
<string>Login method:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="passwordLabel">
|
||||
<property name="text">
|
||||
<string>Password:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<item row="9" column="1">
|
||||
<widget class="QLineEdit" name="passwordLineEdit">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<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="8" column="1">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Anonymous</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>PASS</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<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>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
@@ -121,6 +182,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>serverLineEdit</tabstop>
|
||||
<tabstop>portSpinBox</tabstop>
|
||||
<tabstop>securityCheckBox</tabstop>
|
||||
<tabstop>userNameLineEdit</tabstop>
|
||||
<tabstop>nickNameLineEdit</tabstop>
|
||||
<tabstop>realNameLineEdit</tabstop>
|
||||
<tabstop>comboBox</tabstop>
|
||||
<tabstop>passwordLineEdit</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
@@ -130,8 +201,8 @@
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
<x>254</x>
|
||||
<y>248</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
@@ -146,8 +217,8 @@
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
<x>254</x>
|
||||
<y>248</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
|
||||
@@ -26,7 +26,9 @@ IrcConnectionPopup::IrcConnectionPopup(QWidget *parent)
|
||||
this->setScaleIndependantSize(800, 500);
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
Irc::getInstance().connections.appendItem(IrcConnection_::unique());
|
||||
auto unique = IrcConnection_{};
|
||||
unique.id = Irc::getInstance().uniqueId();
|
||||
Irc::getInstance().connections.appendItem(unique);
|
||||
});
|
||||
|
||||
// init layout
|
||||
|
||||
@@ -138,34 +138,52 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||
auto view = this->ui_.irc.servers = new EditableModelView(
|
||||
Irc::getInstance().newConnectionModel(this));
|
||||
|
||||
view->setTitles(
|
||||
{"real", "port", "ssl", "user", "nick", "real", "password"});
|
||||
view->setTitles({"host", "port", "ssl", "user", "nick", "real",
|
||||
"password", "login command"});
|
||||
view->getTableView()->horizontalHeader()->resizeSection(0, 140);
|
||||
view->getTableView()->horizontalHeader()->resizeSection(1, 30);
|
||||
view->getTableView()->horizontalHeader()->resizeSection(1, 40);
|
||||
view->getTableView()->horizontalHeader()->resizeSection(2, 30);
|
||||
//view->getTableView()->horizontalHeader()->setVisible(false);
|
||||
|
||||
view->getTableView()->horizontalHeader()->setSectionHidden(1, true);
|
||||
view->getTableView()->horizontalHeader()->setSectionHidden(2, true);
|
||||
view->getTableView()->horizontalHeader()->setSectionHidden(6, true);
|
||||
view->getTableView()->horizontalHeader()->setSectionHidden(7, true);
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
Irc::getInstance().connections.appendItem(
|
||||
IrcConnection_::unique());
|
||||
auto unique = IrcConnection_{};
|
||||
unique.id = Irc::getInstance().uniqueId();
|
||||
Irc::getInstance().connections.appendItem(unique);
|
||||
});
|
||||
|
||||
QObject::connect(
|
||||
view->getTableView(), &QTableView::clicked,
|
||||
[](const QModelIndex &index) {
|
||||
auto data =
|
||||
Irc::getInstance()
|
||||
.connections.getVector()[size_t(index.row())];
|
||||
|
||||
auto editor = new IrcConnectionEditor(data);
|
||||
if (editor->exec() == QDialog::Accepted)
|
||||
{
|
||||
auto data = editor->data();
|
||||
auto &&conns =
|
||||
Irc::getInstance().connections.getVector();
|
||||
int i = 0;
|
||||
for (auto &&conn : conns)
|
||||
{
|
||||
if (conn.id == data.id)
|
||||
{
|
||||
Irc::getInstance().connections.removeItem(i);
|
||||
Irc::getInstance().connections.insertItem(data,
|
||||
i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -174,24 +192,6 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||
this->ui_.irc.channel = box.emplace<QLineEdit>().getElement();
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user