mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-17 22:23:31 +00:00
Additional work in MainWindow for integration with new classes
This commit is contained in:
+73
-14
@@ -4,20 +4,23 @@
|
|||||||
#include "http/identitymanager.h"
|
#include "http/identitymanager.h"
|
||||||
#include "http/nvpairingmanager.h"
|
#include "http/nvpairingmanager.h"
|
||||||
#include "http/nvhttp.h"
|
#include "http/nvhttp.h"
|
||||||
|
#include "streaming/streaming.h"
|
||||||
|
#include "http/computermanager.h"
|
||||||
|
#include "http/boxartmanager.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow),
|
||||||
|
m_BoxArtManager(this),
|
||||||
|
m_ComputerManager(this)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
connect(&m_BoxArtManager, SIGNAL(boxArtLoadComplete(NvComputer*,NvApp,QImage)),
|
||||||
// sample code for an iconized button performing an action
|
this, SLOT(boxArtLoadComplete(NvComputer*,NvApp,QImage)));
|
||||||
// will be useful to implement the game grid UI later
|
connect(&m_ComputerManager, SIGNAL(computerStateChanged(NvComputer*)),
|
||||||
// myButton = new QPushButton(this);
|
this, SLOT(computerStateChanged(NvComputer*)));
|
||||||
// myButton->setIcon(QIcon(":/res/icon128.png"));
|
m_ComputerManager.startPolling();
|
||||||
// myButton->setIconSize(QSize(128, 128));
|
qDebug() << "Cached computers: " << m_ComputerManager.getComputers().count();
|
||||||
// myButton->resize(QSize(128, 128));
|
|
||||||
// connect(myButton, &QAbstractButton::clicked, this, &MainWindow::on_actionExit_triggered);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -25,20 +28,76 @@ MainWindow::~MainWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::boxArtLoadComplete(NvComputer* computer, NvApp app, QImage image)
|
||||||
|
{
|
||||||
|
qDebug() << "Loaded image";
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExit_triggered()
|
void MainWindow::on_actionExit_triggered()
|
||||||
{
|
{
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::computerStateChanged(NvComputer* computer)
|
||||||
|
{
|
||||||
|
QReadLocker lock(&computer->lock);
|
||||||
|
|
||||||
|
NvHTTP http(computer->activeAddress);
|
||||||
|
|
||||||
|
if (computer->pairState == NvComputer::PS_NOT_PAIRED) {
|
||||||
|
NvPairingManager pm(computer->activeAddress);
|
||||||
|
QString pin = pm.generatePinString();
|
||||||
|
pm.pair(http.getServerInfo(), pin);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QImage im = m_BoxArtManager.loadBoxArt(computer, computer->appList[0]);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
STREAM_CONFIGURATION sc;
|
||||||
|
LiInitializeStreamConfiguration(&sc);
|
||||||
|
sc.width = 1280;
|
||||||
|
sc.height = 720;
|
||||||
|
sc.fps = 60;
|
||||||
|
sc.packetSize = 1024;
|
||||||
|
sc.bitrate = 10000;
|
||||||
|
sc.audioConfiguration = AUDIO_CONFIGURATION_51_SURROUND;
|
||||||
|
|
||||||
|
QMessageBox* box = new QMessageBox(nullptr);
|
||||||
|
box->setAttribute(Qt::WA_DeleteOnClose); //makes sure the msgbox is deleted automatically when closed
|
||||||
|
box->setStandardButtons(QMessageBox::Cancel);
|
||||||
|
box->setText("Launching game...");
|
||||||
|
box->open();
|
||||||
|
|
||||||
|
if (computer->currentGameId != 0) {
|
||||||
|
http.resumeApp(&sc);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
http.launchApp(999999, &sc, true, false, SdlGetAttachedGamepadMask());
|
||||||
|
}
|
||||||
|
|
||||||
|
SERVER_INFORMATION si;
|
||||||
|
QString serverInfo = http.getServerInfo();
|
||||||
|
|
||||||
|
QByteArray hostnameStr = computer->activeAddress.toLatin1();
|
||||||
|
QByteArray siAppVersion = http.getXmlString(serverInfo, "appversion").toLatin1();
|
||||||
|
QByteArray siGfeVersion = http.getXmlString(serverInfo, "GfeVersion").toLatin1();
|
||||||
|
|
||||||
|
si.address = hostnameStr.data();
|
||||||
|
si.serverInfoAppVersion = siAppVersion.data();
|
||||||
|
si.serverInfoGfeVersion = siGfeVersion.data();
|
||||||
|
|
||||||
|
StartConnection(&si, &sc, box);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_newHostBtn_clicked()
|
void MainWindow::on_newHostBtn_clicked()
|
||||||
{
|
{
|
||||||
QString hostname = popupmanager::getHostnameDialog(this);
|
QString hostname = popupmanager::getHostnameDialog(this);
|
||||||
if (!hostname.isEmpty()) {
|
if (!hostname.isEmpty()) {
|
||||||
|
m_ComputerManager.addNewHost(hostname, false);
|
||||||
NvPairingManager pm(hostname);
|
QThread::sleep(10);
|
||||||
|
m_ComputerManager.stopPollingAsync();
|
||||||
QString pin = pm.generatePinString();
|
|
||||||
pm.pair(http.getServerInfo(), pin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -189,6 +189,32 @@ void ComputerManager::startPolling()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<NvComputer*> ComputerManager::getComputers()
|
||||||
|
{
|
||||||
|
QReadLocker lock(&m_Lock);
|
||||||
|
|
||||||
|
return QVector<NvComputer*>::fromList(m_KnownHosts.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComputerManager::deleteHost(NvComputer* computer)
|
||||||
|
{
|
||||||
|
QWriteLocker lock(&m_Lock);
|
||||||
|
|
||||||
|
QThread* pollingThread = m_PollThreads[computer->uuid];
|
||||||
|
if (pollingThread != nullptr) {
|
||||||
|
pollingThread->requestInterruption();
|
||||||
|
|
||||||
|
// We must wait here because we're going to delete computer
|
||||||
|
// and we can't do that out from underneath the poller.
|
||||||
|
pollingThread->wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_PollThreads.remove(computer->uuid);
|
||||||
|
m_KnownHosts.remove(computer->uuid);
|
||||||
|
|
||||||
|
delete computer;
|
||||||
|
}
|
||||||
|
|
||||||
void ComputerManager::stopPollingAsync()
|
void ComputerManager::stopPollingAsync()
|
||||||
{
|
{
|
||||||
QWriteLocker lock(&m_Lock);
|
QWriteLocker lock(&m_Lock);
|
||||||
|
|||||||
@@ -222,6 +222,11 @@ public:
|
|||||||
|
|
||||||
bool addNewHost(QString address, bool mdns);
|
bool addNewHost(QString address, bool mdns);
|
||||||
|
|
||||||
|
QVector<NvComputer*> getComputers();
|
||||||
|
|
||||||
|
// computer is deleted inside this call
|
||||||
|
void deleteHost(NvComputer* computer);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void computerStateChanged(NvComputer* computer);
|
void computerStateChanged(NvComputer* computer);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user