mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-30 13:30:28 -05:00
Adjust to new Item, ItemSelection, and ItemSettingsDialog classes
This commit is contained in:
@@ -799,13 +799,6 @@ AdvSceneSwitcher.variable.add="Add new variable"
|
|||||||
|
|
||||||
AdvSceneSwitcher.connection.select="--select connection--"
|
AdvSceneSwitcher.connection.select="--select connection--"
|
||||||
AdvSceneSwitcher.connection.add="Add new connection"
|
AdvSceneSwitcher.connection.add="Add new connection"
|
||||||
AdvSceneSwitcher.connection.rename="Rename"
|
|
||||||
AdvSceneSwitcher.connection.remove="Remove"
|
|
||||||
AdvSceneSwitcher.connection.properties="Properties"
|
|
||||||
AdvSceneSwitcher.connection.newName="New name:"
|
|
||||||
AdvSceneSwitcher.connection.emptyName="Empty name not allowed!"
|
|
||||||
AdvSceneSwitcher.connection.nameNotAvailable="Name not available!"
|
|
||||||
AdvSceneSwitcher.connection.nameReserved="Name reserved!"
|
|
||||||
AdvSceneSwitcher.connection.name="Name:"
|
AdvSceneSwitcher.connection.name="Name:"
|
||||||
AdvSceneSwitcher.connection.address="Address:"
|
AdvSceneSwitcher.connection.address="Address:"
|
||||||
AdvSceneSwitcher.connection.port="Port:"
|
AdvSceneSwitcher.connection.port="Port:"
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ struct SwitcherData {
|
|||||||
|
|
||||||
Curlhelper curl;
|
Curlhelper curl;
|
||||||
|
|
||||||
std::deque<Connection> connections;
|
std::deque<std::shared_ptr<Item>> connections;
|
||||||
std::vector<std::string> websocketMessages;
|
std::vector<std::string> websocketMessages;
|
||||||
|
|
||||||
std::deque<std::shared_ptr<Item>> variables;
|
std::deque<std::shared_ptr<Item>> variables;
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ Q_DECLARE_METATYPE(Connection *);
|
|||||||
void SwitcherData::saveConnections(obs_data_t *obj)
|
void SwitcherData::saveConnections(obs_data_t *obj)
|
||||||
{
|
{
|
||||||
obs_data_array_t *connectionArray = obs_data_array_create();
|
obs_data_array_t *connectionArray = obs_data_array_create();
|
||||||
for (Connection &c : connections) {
|
for (const auto &c : connections) {
|
||||||
obs_data_t *array_obj = obs_data_create();
|
obs_data_t *array_obj = obs_data_create();
|
||||||
c.Save(array_obj);
|
c->Save(array_obj);
|
||||||
obs_data_array_push_back(connectionArray, array_obj);
|
obs_data_array_push_back(connectionArray, array_obj);
|
||||||
obs_data_release(array_obj);
|
obs_data_release(array_obj);
|
||||||
}
|
}
|
||||||
@@ -34,8 +34,9 @@ void SwitcherData::loadConnections(obs_data_t *obj)
|
|||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
obs_data_t *array_obj = obs_data_array_item(connectionArray, i);
|
obs_data_t *array_obj = obs_data_array_item(connectionArray, i);
|
||||||
connections.emplace_back();
|
auto con = Connection::Create();
|
||||||
connections.back().Load(array_obj);
|
connections.emplace_back(con);
|
||||||
|
connections.back()->Load(array_obj);
|
||||||
obs_data_release(array_obj);
|
obs_data_release(array_obj);
|
||||||
}
|
}
|
||||||
obs_data_array_release(connectionArray);
|
obs_data_array_release(connectionArray);
|
||||||
@@ -44,7 +45,7 @@ void SwitcherData::loadConnections(obs_data_t *obj)
|
|||||||
Connection::Connection(std::string name, std::string address, uint64_t port,
|
Connection::Connection(std::string name, std::string address, uint64_t port,
|
||||||
std::string pass, bool connectOnStart, bool reconnect,
|
std::string pass, bool connectOnStart, bool reconnect,
|
||||||
int reconnectDelay)
|
int reconnectDelay)
|
||||||
: _name(name),
|
: Item(name),
|
||||||
_address(address),
|
_address(address),
|
||||||
_port(port),
|
_port(port),
|
||||||
_password(pass),
|
_password(pass),
|
||||||
@@ -125,8 +126,8 @@ Connection *GetConnectionByName(const QString &name)
|
|||||||
Connection *GetConnectionByName(const std::string &name)
|
Connection *GetConnectionByName(const std::string &name)
|
||||||
{
|
{
|
||||||
for (auto &con : switcher->connections) {
|
for (auto &con : switcher->connections) {
|
||||||
if (con.GetName() == name) {
|
if (con->Name() == name) {
|
||||||
return &con;
|
return dynamic_cast<Connection *>(con.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -142,54 +143,38 @@ bool ConnectionNameAvailable(const std::string &name)
|
|||||||
return ConnectionNameAvailable(QString::fromStdString(name));
|
return ConnectionNameAvailable(QString::fromStdString(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSelection::ConnectionSelection(QWidget *parent)
|
static bool AskForSettingsWrapper(QWidget *parent, Item &settings)
|
||||||
: QWidget(parent), _selection(new QComboBox), _modify(new QPushButton)
|
|
||||||
{
|
{
|
||||||
_modify->setMaximumWidth(22);
|
Connection &ConnectionSettings = dynamic_cast<Connection &>(settings);
|
||||||
setButtonIcon(_modify, ":/settings/images/settings/general.svg");
|
return ConnectionSettingsDialog::AskForSettings(parent,
|
||||||
_modify->setFlat(true);
|
ConnectionSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionSelection::ConnectionSelection(QWidget *parent)
|
||||||
|
: ItemSelection(switcher->connections, Connection::Create,
|
||||||
|
AskForSettingsWrapper,
|
||||||
|
"AdvSceneSwitcher.connection.select",
|
||||||
|
"AdvSceneSwitcher.connection.add", parent)
|
||||||
|
{
|
||||||
// Connect to slots
|
// Connect to slots
|
||||||
QWidget::connect(_selection,
|
|
||||||
SIGNAL(currentTextChanged(const QString &)), this,
|
|
||||||
SLOT(ChangeSelection(const QString &)));
|
|
||||||
QWidget::connect(_modify, SIGNAL(clicked()), this,
|
|
||||||
SLOT(ModifyButtonClicked()));
|
|
||||||
QWidget::connect(
|
QWidget::connect(
|
||||||
window(),
|
window(),
|
||||||
SIGNAL(ConnectionRenamed(const QString &, const QString &)),
|
SIGNAL(ConnectionRenamed(const QString &, const QString &)),
|
||||||
this, SLOT(RenameConnection(const QString &, const QString &)));
|
this, SLOT(RenameItem(const QString &, const QString &)));
|
||||||
QWidget::connect(window(), SIGNAL(ConnectionAdded(const QString &)),
|
QWidget::connect(window(), SIGNAL(ConnectionAdded(const QString &)),
|
||||||
this, SLOT(AddConnection(const QString &)));
|
this, SLOT(AddItem(const QString &)));
|
||||||
QWidget::connect(window(), SIGNAL(ConnectionRemoved(const QString &)),
|
QWidget::connect(window(), SIGNAL(ConnectionRemoved(const QString &)),
|
||||||
this, SLOT(RemoveConnection(const QString &)));
|
this, SLOT(RemoveItem(const QString &)));
|
||||||
|
|
||||||
// Forward signals
|
// Forward signals
|
||||||
QWidget::connect(
|
QWidget::connect(
|
||||||
this,
|
this, SIGNAL(ItemRenamed(const QString &, const QString &)),
|
||||||
SIGNAL(ConnectionRenamed(const QString &, const QString &)),
|
|
||||||
window(),
|
window(),
|
||||||
SIGNAL(ConnectionRenamed(const QString &, const QString &)));
|
SIGNAL(ConnectionRenamed(const QString &, const QString &)));
|
||||||
QWidget::connect(this, SIGNAL(ConnectionAdded(const QString &)),
|
QWidget::connect(this, SIGNAL(ItemAdded(const QString &)), window(),
|
||||||
window(), SIGNAL(ConnectionAdded(const QString &)));
|
SIGNAL(ConnectionAdded(const QString &)));
|
||||||
QWidget::connect(this, SIGNAL(ConnectionRemoved(const QString &)),
|
QWidget::connect(this, SIGNAL(ItemRemoved(const QString &)), window(),
|
||||||
window(), SIGNAL(ConnectionRemoved(const QString &)));
|
SIGNAL(ConnectionRemoved(const QString &)));
|
||||||
|
|
||||||
QHBoxLayout *layout = new QHBoxLayout;
|
|
||||||
layout->addWidget(_selection);
|
|
||||||
layout->addWidget(_modify);
|
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
setLayout(layout);
|
|
||||||
|
|
||||||
for (const auto &c : switcher->connections) {
|
|
||||||
_selection->addItem(QString::fromStdString(c._name));
|
|
||||||
}
|
|
||||||
_selection->model()->sort(0);
|
|
||||||
addSelectionEntry(
|
|
||||||
_selection,
|
|
||||||
obs_module_text("AdvSceneSwitcher.connection.select"));
|
|
||||||
_selection->insertSeparator(_selection->count());
|
|
||||||
_selection->addItem(obs_module_text("AdvSceneSwitcher.connection.add"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSelection::SetConnection(const std::string &con)
|
void ConnectionSelection::SetConnection(const std::string &con)
|
||||||
@@ -202,166 +187,11 @@ void ConnectionSelection::SetConnection(const std::string &con)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSelection::ChangeSelection(const QString &sel)
|
|
||||||
{
|
|
||||||
if (sel == obs_module_text("AdvSceneSwitcher.connection.add")) {
|
|
||||||
Connection connection;
|
|
||||||
bool accepted = ConnectionSettingsDialog::AskForSettings(
|
|
||||||
this, connection);
|
|
||||||
if (!accepted) {
|
|
||||||
_selection->setCurrentIndex(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switcher->connections.emplace_back(connection);
|
|
||||||
const QSignalBlocker b(_selection);
|
|
||||||
const QString name = QString::fromStdString(connection._name);
|
|
||||||
AddConnection(name);
|
|
||||||
_selection->setCurrentText(name);
|
|
||||||
emit ConnectionAdded(name);
|
|
||||||
emit SelectionChanged(name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto connection = GetCurrentConnection();
|
|
||||||
if (connection) {
|
|
||||||
emit SelectionChanged(
|
|
||||||
QString::fromStdString(connection->_name));
|
|
||||||
} else {
|
|
||||||
emit SelectionChanged("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionSelection::ModifyButtonClicked()
|
|
||||||
{
|
|
||||||
auto connection = GetCurrentConnection();
|
|
||||||
if (!connection) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto properties = [&]() {
|
|
||||||
const auto oldName = connection->_name;
|
|
||||||
bool accepted = ConnectionSettingsDialog::AskForSettings(
|
|
||||||
this, *connection);
|
|
||||||
if (!accepted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (oldName != connection->_name) {
|
|
||||||
emit ConnectionRenamed(
|
|
||||||
QString::fromStdString(oldName),
|
|
||||||
QString::fromStdString(connection->_name));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
QMenu menu(this);
|
|
||||||
|
|
||||||
QAction *action = new QAction(
|
|
||||||
obs_module_text("AdvSceneSwitcher.connection.rename"), &menu);
|
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(RenameConnection()));
|
|
||||||
action->setProperty("connetion", QVariant::fromValue(connection));
|
|
||||||
menu.addAction(action);
|
|
||||||
|
|
||||||
action = new QAction(
|
|
||||||
obs_module_text("AdvSceneSwitcher.connection.remove"), &menu);
|
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(RemoveConnection()));
|
|
||||||
menu.addAction(action);
|
|
||||||
|
|
||||||
action = new QAction(
|
|
||||||
obs_module_text("AdvSceneSwitcher.connection.properties"),
|
|
||||||
&menu);
|
|
||||||
connect(action, &QAction::triggered, properties);
|
|
||||||
menu.addAction(action);
|
|
||||||
|
|
||||||
menu.exec(QCursor::pos());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionSelection::RenameConnection()
|
|
||||||
{
|
|
||||||
QAction *action = reinterpret_cast<QAction *>(sender());
|
|
||||||
QVariant variant = action->property("connetion");
|
|
||||||
Connection *connection = variant.value<Connection *>();
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
bool accepted = AdvSSNameDialog::AskForName(
|
|
||||||
this, obs_module_text("AdvSceneSwitcher.windowTitle"),
|
|
||||||
obs_module_text("AdvSceneSwitcher.connection.newName"), name,
|
|
||||||
QString::fromStdString(name));
|
|
||||||
if (!accepted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (name.empty()) {
|
|
||||||
DisplayMessage("AdvSceneSwitcher.connection.emptyName");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_selection->currentText().toStdString() != name &&
|
|
||||||
!ConnectionNameAvailable(name)) {
|
|
||||||
DisplayMessage("AdvSceneSwitcher.connection.nameNotAvailable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto oldName = connection->_name;
|
|
||||||
connection->_name = name;
|
|
||||||
emit ConnectionRenamed(QString::fromStdString(oldName),
|
|
||||||
QString::fromStdString(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionSelection::RenameConnection(const QString &oldName,
|
|
||||||
const QString &name)
|
|
||||||
{
|
|
||||||
int idx = _selection->findText(oldName);
|
|
||||||
if (idx == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_selection->setItemText(idx, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionSelection::AddConnection(const QString &name)
|
|
||||||
{
|
|
||||||
if (_selection->findText(name) == -1) {
|
|
||||||
_selection->insertItem(1, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionSelection::RemoveConnection()
|
|
||||||
{
|
|
||||||
auto connection = GetCurrentConnection();
|
|
||||||
if (!connection) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int idx =
|
|
||||||
_selection->findText(QString::fromStdString(connection->_name));
|
|
||||||
if (idx == -1 || idx == _selection->count()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit ConnectionRemoved(QString::fromStdString(connection->_name));
|
|
||||||
|
|
||||||
for (auto it = switcher->connections.begin();
|
|
||||||
it != switcher->connections.end(); ++it) {
|
|
||||||
if (it->_name == connection->_name) {
|
|
||||||
switcher->connections.erase(it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionSelection::RemoveConnection(const QString &name)
|
|
||||||
{
|
|
||||||
const int idx = _selection->findText(name);
|
|
||||||
if (idx == _selection->currentIndex()) {
|
|
||||||
_selection->setCurrentIndex(0);
|
|
||||||
}
|
|
||||||
_selection->removeItem(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
Connection *ConnectionSelection::GetCurrentConnection()
|
|
||||||
{
|
|
||||||
return GetConnectionByName(_selection->currentText());
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
||||||
const Connection &settings)
|
const Connection &settings)
|
||||||
: QDialog(parent),
|
: ItemSettingsDialog(settings, switcher->connections,
|
||||||
_name(new QLineEdit()),
|
"AdvSceneSwitcher.connection.select",
|
||||||
_nameHint(new QLabel),
|
"AdvSceneSwitcher.connection.add", parent),
|
||||||
_address(new QLineEdit()),
|
_address(new QLineEdit()),
|
||||||
_port(new QSpinBox()),
|
_port(new QSpinBox()),
|
||||||
_password(new QLineEdit()),
|
_password(new QLineEdit()),
|
||||||
@@ -371,16 +201,8 @@ ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
|||||||
_reconnectDelay(new QSpinBox()),
|
_reconnectDelay(new QSpinBox()),
|
||||||
_test(new QPushButton(
|
_test(new QPushButton(
|
||||||
obs_module_text("AdvSceneSwitcher.connection.test"))),
|
obs_module_text("AdvSceneSwitcher.connection.test"))),
|
||||||
_status(new QLabel()),
|
_status(new QLabel())
|
||||||
_buttonbox(new QDialogButtonBox(QDialogButtonBox::Ok |
|
|
||||||
QDialogButtonBox::Cancel))
|
|
||||||
{
|
{
|
||||||
setModal(true);
|
|
||||||
setWindowModality(Qt::WindowModality::WindowModal);
|
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
||||||
setFixedWidth(555);
|
|
||||||
setMinimumHeight(100);
|
|
||||||
|
|
||||||
_port->setMaximum(65535);
|
_port->setMaximum(65535);
|
||||||
_showPassword->setMaximumWidth(22);
|
_showPassword->setMaximumWidth(22);
|
||||||
_showPassword->setFlat(true);
|
_showPassword->setFlat(true);
|
||||||
@@ -388,10 +210,7 @@ ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
|||||||
"QPushButton { background-color: transparent; border: 0px }");
|
"QPushButton { background-color: transparent; border: 0px }");
|
||||||
_reconnectDelay->setMaximum(9999);
|
_reconnectDelay->setMaximum(9999);
|
||||||
_reconnectDelay->setSuffix("s");
|
_reconnectDelay->setSuffix("s");
|
||||||
_buttonbox->setCenterButtons(true);
|
|
||||||
_buttonbox->button(QDialogButtonBox::Ok)->setDisabled(true);
|
|
||||||
|
|
||||||
_name->setText(QString::fromStdString(settings._name));
|
|
||||||
_address->setText(QString::fromStdString(settings._address));
|
_address->setText(QString::fromStdString(settings._address));
|
||||||
_port->setValue(settings._port);
|
_port->setValue(settings._port);
|
||||||
_password->setText(QString::fromStdString(settings._password));
|
_password->setText(QString::fromStdString(settings._password));
|
||||||
@@ -399,8 +218,6 @@ ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
|||||||
_reconnect->setChecked(settings._reconnect);
|
_reconnect->setChecked(settings._reconnect);
|
||||||
_reconnectDelay->setValue(settings._reconnectDelay);
|
_reconnectDelay->setValue(settings._reconnectDelay);
|
||||||
|
|
||||||
QWidget::connect(_name, SIGNAL(textEdited(const QString &)), this,
|
|
||||||
SLOT(NameChanged(const QString &)));
|
|
||||||
QWidget::connect(_reconnect, SIGNAL(stateChanged(int)), this,
|
QWidget::connect(_reconnect, SIGNAL(stateChanged(int)), this,
|
||||||
SLOT(ReconnectChanged(int)));
|
SLOT(ReconnectChanged(int)));
|
||||||
QWidget::connect(_showPassword, SIGNAL(pressed()), this,
|
QWidget::connect(_showPassword, SIGNAL(pressed()), this,
|
||||||
@@ -410,11 +227,6 @@ ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
|||||||
QWidget::connect(_test, SIGNAL(clicked()), this,
|
QWidget::connect(_test, SIGNAL(clicked()), this,
|
||||||
SLOT(TestConnection()));
|
SLOT(TestConnection()));
|
||||||
|
|
||||||
QWidget::connect(_buttonbox, &QDialogButtonBox::accepted, this,
|
|
||||||
&QDialog::accept);
|
|
||||||
QWidget::connect(_buttonbox, &QDialogButtonBox::rejected, this,
|
|
||||||
&QDialog::reject);
|
|
||||||
|
|
||||||
QGridLayout *layout = new QGridLayout;
|
QGridLayout *layout = new QGridLayout;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
layout->addWidget(
|
layout->addWidget(
|
||||||
@@ -466,33 +278,10 @@ ConnectionSettingsDialog::ConnectionSettingsDialog(QWidget *parent,
|
|||||||
layout->addWidget(_buttonbox, row, 0, 1, -1);
|
layout->addWidget(_buttonbox, row, 0, 1, -1);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
NameChanged(_name->text());
|
|
||||||
ReconnectChanged(_reconnect->isChecked());
|
ReconnectChanged(_reconnect->isChecked());
|
||||||
HidePassword();
|
HidePassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSettingsDialog::NameChanged(const QString &text)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (text != _name->text() && !ConnectionNameAvailable(text)) {
|
|
||||||
SetNameWarning(obs_module_text(
|
|
||||||
"AdvSceneSwitcher.connection.nameNotAvailable"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (text.isEmpty()) {
|
|
||||||
SetNameWarning(obs_module_text(
|
|
||||||
"AdvSceneSwitcher.connection.emptyName"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (text == obs_module_text("AdvSceneSwitcher.connection.select") ||
|
|
||||||
text == obs_module_text("AdvSceneSwitcher.connection.add")) {
|
|
||||||
SetNameWarning(obs_module_text(
|
|
||||||
"AdvSceneSwitcher.connection.nameReserved"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetNameWarning("");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionSettingsDialog::ReconnectChanged(int state)
|
void ConnectionSettingsDialog::ReconnectChanged(int state)
|
||||||
{
|
{
|
||||||
_reconnectDelay->setEnabled(state);
|
_reconnectDelay->setEnabled(state);
|
||||||
@@ -566,21 +355,9 @@ bool ConnectionSettingsDialog::AskForSettings(QWidget *parent,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSettingsDialog::SetNameWarning(const QString warn)
|
|
||||||
{
|
|
||||||
if (warn.isEmpty()) {
|
|
||||||
_nameHint->hide();
|
|
||||||
_buttonbox->button(QDialogButtonBox::Ok)->setDisabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_nameHint->setText(warn);
|
|
||||||
_nameHint->show();
|
|
||||||
_buttonbox->button(QDialogButtonBox::Ok)->setDisabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::Load(obs_data_t *obj)
|
void Connection::Load(obs_data_t *obj)
|
||||||
{
|
{
|
||||||
_name = obs_data_get_string(obj, "name");
|
Item::Load(obj);
|
||||||
_address = obs_data_get_string(obj, "address");
|
_address = obs_data_get_string(obj, "address");
|
||||||
_port = obs_data_get_int(obj, "port");
|
_port = obs_data_get_int(obj, "port");
|
||||||
_password = obs_data_get_string(obj, "password");
|
_password = obs_data_get_string(obj, "password");
|
||||||
@@ -594,9 +371,9 @@ void Connection::Load(obs_data_t *obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::Save(obs_data_t *obj)
|
void Connection::Save(obs_data_t *obj) const
|
||||||
{
|
{
|
||||||
obs_data_set_string(obj, "name", _name.c_str());
|
Item::Save(obj);
|
||||||
obs_data_set_string(obj, "address", _address.c_str());
|
obs_data_set_string(obj, "address", _address.c_str());
|
||||||
obs_data_set_int(obj, "port", _port);
|
obs_data_set_int(obj, "port", _port);
|
||||||
obs_data_set_string(obj, "password", _password.c_str());
|
obs_data_set_string(obj, "password", _password.c_str());
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "item-selection-helpers.hpp"
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@@ -7,7 +8,6 @@
|
|||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
class ConnectionSelection;
|
class ConnectionSelection;
|
||||||
class ConnectionSettingsDialog;
|
class ConnectionSettingsDialog;
|
||||||
|
|
||||||
class Connection {
|
class Connection : public Item {
|
||||||
public:
|
public:
|
||||||
Connection(std::string name, std::string address, uint64_t port,
|
Connection(std::string name, std::string address, uint64_t port,
|
||||||
std::string pass, bool connectOnStart, bool reconnect,
|
std::string pass, bool connectOnStart, bool reconnect,
|
||||||
@@ -27,16 +27,19 @@ public:
|
|||||||
Connection(const Connection &);
|
Connection(const Connection &);
|
||||||
Connection &operator=(const Connection &);
|
Connection &operator=(const Connection &);
|
||||||
~Connection();
|
~Connection();
|
||||||
|
static std::shared_ptr<Item> Create()
|
||||||
|
{
|
||||||
|
return std::make_shared<Connection>();
|
||||||
|
}
|
||||||
|
|
||||||
void Reconnect();
|
void Reconnect();
|
||||||
void SendMsg(const std::string &msg);
|
void SendMsg(const std::string &msg);
|
||||||
void Load(obs_data_t *obj);
|
void Load(obs_data_t *obj);
|
||||||
void Save(obs_data_t *obj);
|
void Save(obs_data_t *obj) const;
|
||||||
std::string GetName() { return _name; }
|
std::string GetName() { return _name; }
|
||||||
std::vector<std::string> &Events() { return _client.Events(); }
|
std::vector<std::string> &Events() { return _client.Events(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _name = "";
|
|
||||||
std::string _address = "localhost";
|
std::string _address = "localhost";
|
||||||
uint64_t _port = 4455;
|
uint64_t _port = 4455;
|
||||||
std::string _password = "password";
|
std::string _password = "password";
|
||||||
@@ -54,7 +57,7 @@ private:
|
|||||||
Connection *GetConnectionByName(const QString &);
|
Connection *GetConnectionByName(const QString &);
|
||||||
Connection *GetConnectionByName(const std::string &);
|
Connection *GetConnectionByName(const std::string &);
|
||||||
|
|
||||||
class ConnectionSettingsDialog : public QDialog {
|
class ConnectionSettingsDialog : public ItemSettingsDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -62,7 +65,6 @@ public:
|
|||||||
static bool AskForSettings(QWidget *parent, Connection &settings);
|
static bool AskForSettings(QWidget *parent, Connection &settings);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void NameChanged(const QString &);
|
|
||||||
void ReconnectChanged(int);
|
void ReconnectChanged(int);
|
||||||
void ShowPassword();
|
void ShowPassword();
|
||||||
void HidePassword();
|
void HidePassword();
|
||||||
@@ -70,10 +72,6 @@ private slots:
|
|||||||
void TestConnection();
|
void TestConnection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetNameWarning(const QString);
|
|
||||||
|
|
||||||
QLineEdit *_name;
|
|
||||||
QLabel *_nameHint;
|
|
||||||
QLineEdit *_address;
|
QLineEdit *_address;
|
||||||
QSpinBox *_port;
|
QSpinBox *_port;
|
||||||
QLineEdit *_password;
|
QLineEdit *_password;
|
||||||
@@ -83,36 +81,15 @@ private:
|
|||||||
QSpinBox *_reconnectDelay;
|
QSpinBox *_reconnectDelay;
|
||||||
QPushButton *_test;
|
QPushButton *_test;
|
||||||
QLabel *_status;
|
QLabel *_status;
|
||||||
QDialogButtonBox *_buttonbox;
|
|
||||||
|
|
||||||
QTimer _statusTimer;
|
QTimer _statusTimer;
|
||||||
WSConnection _testConnection;
|
WSConnection _testConnection;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConnectionSelection : public QWidget {
|
class ConnectionSelection : public ItemSelection {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConnectionSelection(QWidget *parent = 0);
|
ConnectionSelection(QWidget *parent = 0);
|
||||||
void SetConnection(const std::string &);
|
void SetConnection(const std::string &);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void ModifyButtonClicked();
|
|
||||||
void ChangeSelection(const QString &);
|
|
||||||
void RenameConnection();
|
|
||||||
void RenameConnection(const QString &oldName, const QString &name);
|
|
||||||
void AddConnection(const QString &);
|
|
||||||
void RemoveConnection();
|
|
||||||
void RemoveConnection(const QString &);
|
|
||||||
signals:
|
|
||||||
void SelectionChanged(const QString &);
|
|
||||||
void ConnectionAdded(const QString &);
|
|
||||||
void ConnectionRemoved(const QString &);
|
|
||||||
void ConnectionRenamed(const QString &oldName, const QString &name);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Connection *GetCurrentConnection();
|
|
||||||
|
|
||||||
QComboBox *_selection;
|
|
||||||
QPushButton *_modify;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ void ClearWebsocketMessages()
|
|||||||
{
|
{
|
||||||
switcher->websocketMessages.clear();
|
switcher->websocketMessages.clear();
|
||||||
for (auto &connection : switcher->connections) {
|
for (auto &connection : switcher->connections) {
|
||||||
connection.Events().clear();
|
Connection *c = dynamic_cast<Connection *>(connection.get());
|
||||||
|
if (c) {
|
||||||
|
c->Events().clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user