Implement pairing via GUI
This commit is contained in:
parent
1b1ad86271
commit
6687936e2f
9 changed files with 155 additions and 33 deletions
|
|
@ -8,6 +8,8 @@ import ComputerModel 1.0
|
|||
import ComputerManager 1.0
|
||||
|
||||
GridView {
|
||||
property ComputerModel computerModel : createModel()
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 5
|
||||
anchors.topMargin: 5
|
||||
|
|
@ -26,10 +28,26 @@ GridView {
|
|||
ComputerManager.stopPollingAsync()
|
||||
}
|
||||
|
||||
function pairingComplete(error)
|
||||
{
|
||||
// Close the PIN dialog
|
||||
pairDialog.close()
|
||||
|
||||
// Start polling again
|
||||
ComputerManager.startPolling()
|
||||
|
||||
// Display a failed dialog if we got an error
|
||||
if (error !== null) {
|
||||
pairingFailedDialog.text = error
|
||||
pairingFailedDialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
function createModel()
|
||||
{
|
||||
var model = Qt.createQmlObject('import ComputerModel 1.0; ComputerModel {}', parent, '')
|
||||
model.initialize(ComputerManager)
|
||||
model.pairingCompleted.connect(pairingComplete)
|
||||
return model
|
||||
}
|
||||
|
||||
|
|
@ -114,12 +132,20 @@ GridView {
|
|||
else {
|
||||
if (!model.busy) {
|
||||
var pin = ("0000" + Math.floor(Math.random() * 10000)).slice(-4)
|
||||
|
||||
// Stop polling, since pairing may make GFE unresponsive
|
||||
ComputerManager.stopPollingAsync()
|
||||
|
||||
// Kick off pairing in the background
|
||||
computerModel.pairComputer(index, pin)
|
||||
|
||||
// Display the pairing dialog
|
||||
pairDialog.pin = pin
|
||||
// TODO: initiate pairing request
|
||||
pairDialog.open()
|
||||
}
|
||||
else {
|
||||
// cannot pair while something is streaming or attempting to pair
|
||||
pairingFailedDialog.text = "This PC is currently busy. Make sure to quit any running games and try again."
|
||||
pairingFailedDialog.open()
|
||||
}
|
||||
}
|
||||
|
|
@ -135,8 +161,7 @@ GridView {
|
|||
id: pairingFailedDialog
|
||||
// don't allow edits to the rest of the window while open
|
||||
modality:Qt.WindowModal
|
||||
|
||||
text:"This PC is busy: make sure no game is streaming, and try again"
|
||||
icon: StandardIcon.Critical
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "computermodel.h"
|
||||
#include "backend/nvpairingmanager.h"
|
||||
|
||||
ComputerModel::ComputerModel(QObject* object)
|
||||
: QAbstractListModel(object) {}
|
||||
|
|
@ -9,6 +8,8 @@ void ComputerModel::initialize(ComputerManager* computerManager)
|
|||
m_ComputerManager = computerManager;
|
||||
connect(m_ComputerManager, &ComputerManager::computerStateChanged,
|
||||
this, &ComputerModel::handleComputerStateChanged);
|
||||
connect(m_ComputerManager, &ComputerManager::pairingCompleted,
|
||||
this, &ComputerModel::handlePairingCompleted);
|
||||
|
||||
m_Computers = m_ComputerManager->getComputers();
|
||||
}
|
||||
|
|
@ -92,6 +93,18 @@ void ComputerModel::deleteComputer(int computerIndex)
|
|||
endRemoveRows();
|
||||
}
|
||||
|
||||
void ComputerModel::pairComputer(int computerIndex, QString pin)
|
||||
{
|
||||
Q_ASSERT(computerIndex < m_Computers.count());
|
||||
|
||||
m_ComputerManager->pairHost(m_Computers[computerIndex], pin);
|
||||
}
|
||||
|
||||
void ComputerModel::handlePairingCompleted(NvComputer*, QString error)
|
||||
{
|
||||
emit pairingCompleted(error.isNull() ? QVariant() : error);
|
||||
}
|
||||
|
||||
void ComputerModel::handleComputerStateChanged(NvComputer* computer)
|
||||
{
|
||||
// If this is an existing computer, we can report the data changed
|
||||
|
|
|
|||
|
|
@ -29,9 +29,16 @@ public:
|
|||
|
||||
Q_INVOKABLE void deleteComputer(int computerIndex);
|
||||
|
||||
Q_INVOKABLE void pairComputer(int computerIndex, QString pin);
|
||||
|
||||
signals:
|
||||
void pairingCompleted(QVariant error);
|
||||
|
||||
private slots:
|
||||
void handleComputerStateChanged(NvComputer* computer);
|
||||
|
||||
void handlePairingCompleted(NvComputer* computer, QString error);
|
||||
|
||||
private:
|
||||
QVector<NvComputer*> m_Computers;
|
||||
ComputerManager* m_ComputerManager;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue