mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 21:43:12 -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
|
include/avopenglframeuploader.h
|
||||||
src/avopenglframeuploader.cpp
|
src/avopenglframeuploader.cpp
|
||||||
include/servericonwidget.h
|
include/servericonwidget.h
|
||||||
src/servericonwidget.cpp)
|
src/servericonwidget.cpp
|
||||||
|
include/settings.h
|
||||||
|
src/settings.cpp)
|
||||||
target_include_directories(chiaki PRIVATE include)
|
target_include_directories(chiaki PRIVATE include)
|
||||||
|
|
||||||
target_link_libraries(chiaki chiaki-lib chiaki-cli-lib)
|
target_link_libraries(chiaki chiaki-lib chiaki-cli-lib)
|
||||||
|
|
|
@ -43,6 +43,7 @@ class DiscoveryManager : public QObject
|
||||||
private:
|
private:
|
||||||
ChiakiLog log;
|
ChiakiLog log;
|
||||||
ChiakiDiscoveryService service;
|
ChiakiDiscoveryService service;
|
||||||
|
bool service_active;
|
||||||
QList<DiscoveryHost> hosts;
|
QList<DiscoveryHost> hosts;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -52,6 +53,8 @@ class DiscoveryManager : public QObject
|
||||||
explicit DiscoveryManager(QObject *parent = nullptr);
|
explicit DiscoveryManager(QObject *parent = nullptr);
|
||||||
~DiscoveryManager();
|
~DiscoveryManager();
|
||||||
|
|
||||||
|
void SetActive(bool active);
|
||||||
|
|
||||||
const QList<DiscoveryHost> GetHosts() const { return hosts; }
|
const QList<DiscoveryHost> GetHosts() const { return hosts; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
class DynamicGridWidget;
|
class DynamicGridWidget;
|
||||||
class ServerItemWidget;
|
class ServerItemWidget;
|
||||||
|
class Settings;
|
||||||
|
|
||||||
struct DisplayServer
|
struct DisplayServer
|
||||||
{
|
{
|
||||||
|
@ -36,6 +37,10 @@ class MainWindow : public QMainWindow
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Settings *settings;
|
||||||
|
|
||||||
|
QAction *discover_action;
|
||||||
|
|
||||||
DynamicGridWidget *grid_widget;
|
DynamicGridWidget *grid_widget;
|
||||||
QList<ServerItemWidget *> server_item_widgets;
|
QList<ServerItemWidget *> server_item_widgets;
|
||||||
|
|
||||||
|
@ -47,14 +52,14 @@ class MainWindow : public QMainWindow
|
||||||
void ServerItemWidgetSelected();
|
void ServerItemWidgetSelected();
|
||||||
void ServerItemWidgetTriggered();
|
void ServerItemWidgetTriggered();
|
||||||
|
|
||||||
void RunDiscovery();
|
void UpdateDiscoveryEnabled();
|
||||||
void ShowSettings();
|
void ShowSettings();
|
||||||
|
|
||||||
void UpdateDisplayServers();
|
void UpdateDisplayServers();
|
||||||
void UpdateServerWidgets();
|
void UpdateServerWidgets();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(Settings *settings, QWidget *parent = nullptr);
|
||||||
~MainWindow() override;
|
~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,6 +31,23 @@ DiscoveryManager::DiscoveryManager(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
chiaki_log_init(&log, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, nullptr);
|
chiaki_log_init(&log, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, nullptr);
|
||||||
|
|
||||||
|
service_active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscoveryManager::~DiscoveryManager()
|
||||||
|
{
|
||||||
|
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;
|
ChiakiDiscoveryServiceOptions options;
|
||||||
options.ping_ms = PING_MS;
|
options.ping_ms = PING_MS;
|
||||||
options.hosts_max = HOSTS_MAX;
|
options.hosts_max = HOSTS_MAX;
|
||||||
|
@ -47,12 +64,18 @@ DiscoveryManager::DiscoveryManager(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
ChiakiErrorCode err = chiaki_discovery_service_init(&service, &options, &log);
|
ChiakiErrorCode err = chiaki_discovery_service_init(&service, &options, &log);
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
throw std::exception();
|
{
|
||||||
|
CHIAKI_LOGE(&log, "DiscoveryManager failed to init Discovery Service");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DiscoveryManager::~DiscoveryManager()
|
else
|
||||||
{
|
{
|
||||||
chiaki_discovery_service_fini(&service);
|
chiaki_discovery_service_fini(&service);
|
||||||
|
hosts = {};
|
||||||
|
emit HostsUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscoveryManager::DiscoveryServiceHosts(QList<DiscoveryHost> hosts)
|
void DiscoveryManager::DiscoveryServiceHosts(QList<DiscoveryHost> hosts)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <videodecoder.h>
|
#include <videodecoder.h>
|
||||||
#include <mainwindow.h>
|
#include <mainwindow.h>
|
||||||
#include <streamsession.h>
|
#include <streamsession.h>
|
||||||
|
#include <settings.h>
|
||||||
|
|
||||||
#include <chiaki-cli.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 RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info);
|
||||||
int RunMain(QApplication &app);
|
int RunMain(QApplication &app, Settings *settings);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
qRegisterMetaType<DiscoveryHost>();
|
qRegisterMetaType<DiscoveryHost>();
|
||||||
qRegisterMetaType<ChiakiQuitReason>();
|
qRegisterMetaType<ChiakiQuitReason>();
|
||||||
|
|
||||||
|
QApplication::setOrganizationName("Chiaki");
|
||||||
|
QApplication::setApplicationName("Chiaki");
|
||||||
|
|
||||||
ChiakiErrorCode err = chiaki_lib_init();
|
ChiakiErrorCode err = chiaki_lib_init();
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
@ -43,7 +47,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
QApplication::setApplicationName("Chiaki");
|
|
||||||
|
Settings settings;
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments);
|
parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments);
|
||||||
|
@ -76,7 +81,7 @@ int main(int argc, char *argv[])
|
||||||
QStringList args = parser.positionalArguments();
|
QStringList args = parser.positionalArguments();
|
||||||
|
|
||||||
if(args.length() == 0)
|
if(args.length() == 0)
|
||||||
return RunMain(app);
|
return RunMain(app, &settings);
|
||||||
|
|
||||||
if(args[0] == "stream")
|
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();
|
main_window.show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <mainwindow.h>
|
#include <mainwindow.h>
|
||||||
#include <dynamicgridwidget.h>
|
#include <dynamicgridwidget.h>
|
||||||
#include <serveritemwidget.h>
|
#include <serveritemwidget.h>
|
||||||
|
#include <settings.h>
|
||||||
|
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
@ -25,7 +26,9 @@
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QDebug>
|
#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 main_widget = new QWidget(this);
|
||||||
auto layout = new QVBoxLayout();
|
auto layout = new QVBoxLayout();
|
||||||
|
@ -37,9 +40,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||||
tool_bar->setMovable(false);
|
tool_bar->setMovable(false);
|
||||||
addToolBar(tool_bar);
|
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);
|
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();
|
auto tool_bar_spacer = new QWidget();
|
||||||
tool_bar_spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
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);
|
connect(&discovery_manager, &DiscoveryManager::HostsUpdated, this, &MainWindow::UpdateDisplayServers);
|
||||||
|
|
||||||
UpdateDisplayServers();
|
UpdateDisplayServers();
|
||||||
|
UpdateDiscoveryEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -98,9 +104,11 @@ void MainWindow::ServerItemWidgetTriggered()
|
||||||
// TODO: connect
|
// 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()
|
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