Commit 3fda2ff0 authored by Adam Honse's avatar Adam Honse

Add button to disconnect clients

parent dc06fa95
......@@ -1378,6 +1378,20 @@ NetworkClient * Visualizer::OpenRGBConnect(const char * ip, unsigned short port)
return(rgb_client);
}
void Visualizer::OpenRGBDisconnect(NetworkClient * client)
{
client->StopClient();
for(unsigned int client_idx = 0; client_idx < rgb_clients.size(); client_idx++)
{
if(client == rgb_clients[client_idx])
{
rgb_clients.erase(rgb_clients.begin() + client_idx);
break;
}
}
}
void Visualizer::LEDUpdateThreadFunction()
{
while(1)
......
......@@ -96,6 +96,9 @@ public:
//Connect to OpenRGB
NetworkClient *OpenRGBConnect(const char *ip, unsigned short port);
//Disconnect from OpenRGB
void OpenRGBDisconnect(NetworkClient * client);
//Called when settings changed
void OnSettingsChanged();
......
......@@ -4,6 +4,7 @@
#include "ui_keyboardvisualizer.h"
#include <QTreeWidgetItem>
#include <QSignalMapper>
Visualizer* vis_ptr;
boolean startminimized;
......@@ -357,6 +358,12 @@ void Ui::KeyboardVisDlg::on_lineEdit_Background_Timeout_textChanged(const QStrin
vis_ptr->OnSettingsChanged();
}
class NetworkClientPointer : public QObject
{
public:
NetworkClient * net_client;
};
void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
{
ui->tree_Devices->clear();
......@@ -364,11 +371,25 @@ void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
//OpenRGB device list
ui->tree_Devices->setColumnCount(3);
ui->tree_Devices->setHeaderLabels(QStringList() << "Device Zones" << "LEDs" << "Type");
QSignalMapper* signalMapper = new QSignalMapper(this);
connect(signalMapper, SIGNAL(mapped(QObject *)), this, SLOT(on_button_Disconnect_clicked(QObject *)));
for(int client_idx = 0; client_idx < vis_ptr->rgb_clients.size(); client_idx++)
{
QTreeWidgetItem* new_top_item = new QTreeWidgetItem(ui->tree_Devices);
new_top_item->setText(0, QString::fromStdString(vis_ptr->rgb_clients[client_idx]->GetIP()));
QPushButton* new_button = new QPushButton( "Disconnect" );
ui->tree_Devices->setItemWidget(new_top_item, 2, new_button);
connect(new_button, SIGNAL(clicked()), signalMapper, SLOT(map()));
NetworkClientPointer * new_arg = new NetworkClientPointer();
new_arg->net_client = vis_ptr->rgb_clients[client_idx];
signalMapper->setMapping(new_button, new_arg);
for(int dev_idx = 0; dev_idx < vis_ptr->rgb_clients[client_idx]->server_controllers.size(); dev_idx++)
{
QTreeWidgetItem* new_item = new QTreeWidgetItem(new_top_item);
......@@ -402,6 +423,13 @@ void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
}
}
void Ui::KeyboardVisDlg::on_button_Disconnect_clicked(QObject * arg)
{
NetworkClient * disconnect_client = ((NetworkClientPointer *)arg)->net_client;
vis_ptr->OpenRGBDisconnect(disconnect_client);
}
void Ui::KeyboardVisDlg::on_button_Connect_clicked()
{
unsigned short port = std::stoi(ui->lineEdit_Port->text().toStdString());
......
......@@ -74,6 +74,8 @@ private slots:
void on_button_Connect_clicked();
void on_button_Disconnect_clicked(QObject *);
private:
Ui::KeyboardVisualizerDlg *ui;
QSystemTrayIcon* trayIcon;
......
Subproject commit e6aadc414bf8ba66220eb52bd0963ef9be56c010
Subproject commit bd6ec4c41e00b360f4f479869da79669d600b031
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment