mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Toggle Discovery
This commit is contained in:
parent
696cf7823f
commit
fd0bf8600d
8 changed files with 134 additions and 31 deletions
|
@ -36,7 +36,9 @@ add_executable(chiaki
|
|||
include/avopenglframeuploader.h
|
||||
src/avopenglframeuploader.cpp
|
||||
include/servericonwidget.h
|
||||
src/servericonwidget.cpp)
|
||||
src/servericonwidget.cpp
|
||||
include/settings.h
|
||||
src/settings.cpp)
|
||||
target_include_directories(chiaki PRIVATE include)
|
||||
|
||||
target_link_libraries(chiaki chiaki-lib chiaki-cli-lib)
|
||||
|
|
|
@ -43,6 +43,7 @@ class DiscoveryManager : public QObject
|
|||
private:
|
||||
ChiakiLog log;
|
||||
ChiakiDiscoveryService service;
|
||||
bool service_active;
|
||||
QList<DiscoveryHost> hosts;
|
||||
|
||||
private slots:
|
||||
|
@ -52,6 +53,8 @@ class DiscoveryManager : public QObject
|
|||
explicit DiscoveryManager(QObject *parent = nullptr);
|
||||
~DiscoveryManager();
|
||||
|
||||
void SetActive(bool active);
|
||||
|
||||
const QList<DiscoveryHost> GetHosts() const { return hosts; }
|
||||
|
||||
signals:
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
class DynamicGridWidget;
|
||||
class ServerItemWidget;
|
||||
class Settings;
|
||||
|
||||
struct DisplayServer
|
||||
{
|
||||
|
@ -36,6 +37,10 @@ class MainWindow : public QMainWindow
|
|||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Settings *settings;
|
||||
|
||||
QAction *discover_action;
|
||||
|
||||
DynamicGridWidget *grid_widget;
|
||||
QList<ServerItemWidget *> server_item_widgets;
|
||||
|
||||
|
@ -47,14 +52,14 @@ class MainWindow : public QMainWindow
|
|||
void ServerItemWidgetSelected();
|
||||
void ServerItemWidgetTriggered();
|
||||
|
||||
void RunDiscovery();
|
||||
void UpdateDiscoveryEnabled();
|
||||
void ShowSettings();
|
||||
|
||||
void UpdateDisplayServers();
|
||||
void UpdateServerWidgets();
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
explicit MainWindow(Settings *settings, QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
};
|
||||
|
||||
|
|
35
gui/include/settings.h
Normal file
35
gui/include/settings.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHIAKI_SETTINGS_H
|
||||
#define CHIAKI_SETTINGS_H
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
class Settings
|
||||
{
|
||||
private:
|
||||
QSettings settings;
|
||||
|
||||
public:
|
||||
Settings();
|
||||
|
||||
bool GetDiscoveryEnabled() { return settings.value("settings/auto_discovery", true).toBool(); }
|
||||
void SetDiscoveryEnabled(bool enabled) { settings.setValue("settings/auto_discovery", enabled); }
|
||||
};
|
||||
|
||||
#endif // CHIAKI_SETTINGS_H
|
|
@ -31,28 +31,51 @@ DiscoveryManager::DiscoveryManager(QObject *parent) : QObject(parent)
|
|||
{
|
||||
chiaki_log_init(&log, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, nullptr);
|
||||
|
||||
ChiakiDiscoveryServiceOptions options;
|
||||
options.ping_ms = PING_MS;
|
||||
options.hosts_max = HOSTS_MAX;
|
||||
options.host_drop_pings = DROP_PINGS;
|
||||
options.cb = DiscoveryServiceHostsCallback;
|
||||
options.cb_user = this;
|
||||
|
||||
sockaddr_in addr = {};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(CHIAKI_DISCOVERY_PORT);
|
||||
addr.sin_addr.s_addr = 0xffffffff; // 255.255.255.255
|
||||
options.send_addr = reinterpret_cast<sockaddr *>(&addr);
|
||||
options.send_addr_size = sizeof(addr);
|
||||
|
||||
ChiakiErrorCode err = chiaki_discovery_service_init(&service, &options, &log);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
throw std::exception();
|
||||
service_active = false;
|
||||
}
|
||||
|
||||
DiscoveryManager::~DiscoveryManager()
|
||||
{
|
||||
chiaki_discovery_service_fini(&service);
|
||||
if(service_active)
|
||||
chiaki_discovery_service_fini(&service);
|
||||
}
|
||||
|
||||
void DiscoveryManager::SetActive(bool active)
|
||||
{
|
||||
if(service_active == active)
|
||||
return;
|
||||
service_active = active;
|
||||
|
||||
if(active)
|
||||
{
|
||||
ChiakiDiscoveryServiceOptions options;
|
||||
options.ping_ms = PING_MS;
|
||||
options.hosts_max = HOSTS_MAX;
|
||||
options.host_drop_pings = DROP_PINGS;
|
||||
options.cb = DiscoveryServiceHostsCallback;
|
||||
options.cb_user = this;
|
||||
|
||||
sockaddr_in addr = {};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(CHIAKI_DISCOVERY_PORT);
|
||||
addr.sin_addr.s_addr = 0xffffffff; // 255.255.255.255
|
||||
options.send_addr = reinterpret_cast<sockaddr *>(&addr);
|
||||
options.send_addr_size = sizeof(addr);
|
||||
|
||||
ChiakiErrorCode err = chiaki_discovery_service_init(&service, &options, &log);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&log, "DiscoveryManager failed to init Discovery Service");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chiaki_discovery_service_fini(&service);
|
||||
hosts = {};
|
||||
emit HostsUpdated();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DiscoveryManager::DiscoveryServiceHosts(QList<DiscoveryHost> hosts)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <videodecoder.h>
|
||||
#include <mainwindow.h>
|
||||
#include <streamsession.h>
|
||||
#include <settings.h>
|
||||
|
||||
#include <chiaki-cli.h>
|
||||
|
||||
|
@ -28,13 +29,16 @@ static const QMap<QString, CLICommand> cli_commands = {
|
|||
};
|
||||
|
||||
int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info);
|
||||
int RunMain(QApplication &app);
|
||||
int RunMain(QApplication &app, Settings *settings);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qRegisterMetaType<DiscoveryHost>();
|
||||
qRegisterMetaType<ChiakiQuitReason>();
|
||||
|
||||
QApplication::setOrganizationName("Chiaki");
|
||||
QApplication::setApplicationName("Chiaki");
|
||||
|
||||
ChiakiErrorCode err = chiaki_lib_init();
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
|
@ -43,7 +47,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
QApplication app(argc, argv);
|
||||
QApplication::setApplicationName("Chiaki");
|
||||
|
||||
Settings settings;
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments);
|
||||
|
@ -76,7 +81,7 @@ int main(int argc, char *argv[])
|
|||
QStringList args = parser.positionalArguments();
|
||||
|
||||
if(args.length() == 0)
|
||||
return RunMain(app);
|
||||
return RunMain(app, &settings);
|
||||
|
||||
if(args[0] == "stream")
|
||||
{
|
||||
|
@ -129,9 +134,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
int RunMain(QApplication &app)
|
||||
int RunMain(QApplication &app, Settings *settings)
|
||||
{
|
||||
MainWindow main_window;
|
||||
MainWindow main_window(settings);
|
||||
main_window.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <mainwindow.h>
|
||||
#include <dynamicgridwidget.h>
|
||||
#include <serveritemwidget.h>
|
||||
#include <settings.h>
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -25,7 +26,9 @@
|
|||
#include <QToolBar>
|
||||
#include <QDebug>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
MainWindow::MainWindow(Settings *settings, QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
settings(settings)
|
||||
{
|
||||
auto main_widget = new QWidget(this);
|
||||
auto layout = new QVBoxLayout();
|
||||
|
@ -37,9 +40,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||
tool_bar->setMovable(false);
|
||||
addToolBar(tool_bar);
|
||||
|
||||
auto discover_action = new QAction(tr("Discover"), this);
|
||||
discover_action = new QAction(tr("Automatically Search for Consoles"), this);
|
||||
discover_action->setCheckable(true);
|
||||
discover_action->setChecked(settings->GetDiscoveryEnabled());
|
||||
tool_bar->addAction(discover_action);
|
||||
connect(discover_action, &QAction::triggered, this, &MainWindow::RunDiscovery);
|
||||
connect(discover_action, &QAction::triggered, this, &MainWindow::UpdateDiscoveryEnabled);
|
||||
|
||||
auto tool_bar_spacer = new QWidget();
|
||||
tool_bar_spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||
|
@ -69,6 +74,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||
connect(&discovery_manager, &DiscoveryManager::HostsUpdated, this, &MainWindow::UpdateDisplayServers);
|
||||
|
||||
UpdateDisplayServers();
|
||||
UpdateDiscoveryEnabled();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -98,9 +104,11 @@ void MainWindow::ServerItemWidgetTriggered()
|
|||
// TODO: connect
|
||||
}
|
||||
|
||||
void MainWindow::RunDiscovery()
|
||||
void MainWindow::UpdateDiscoveryEnabled()
|
||||
{
|
||||
qDebug() << "TODO: RunDiscovery()";
|
||||
bool enabled = discover_action->isChecked();
|
||||
settings->SetDiscoveryEnabled(enabled);
|
||||
discovery_manager.SetActive(enabled);
|
||||
}
|
||||
|
||||
void MainWindow::ShowSettings()
|
||||
|
|
22
gui/src/settings.cpp
Normal file
22
gui/src/settings.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <settings.h>
|
||||
|
||||
Settings::Settings()
|
||||
{
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue