Start work on launching a stream from QML and rip out remaining QtWidgets

This commit is contained in:
Cameron Gutman
2018-07-07 16:30:26 -07:00
parent d5cc07f107
commit 60ad95bb7b
11 changed files with 83 additions and 55 deletions

View File

@@ -7,6 +7,7 @@ import ComputerManager 1.0
GridView {
property int computerIndex
property AppModel appModel : createModel()
anchors.fill: parent
anchors.leftMargin: 5
@@ -33,7 +34,7 @@ GridView {
return model
}
model: createModel()
model: appModel
delegate: Item {
width: 200; height: 300;
@@ -64,7 +65,8 @@ GridView {
MouseArea {
anchors.fill: parent
onClicked: {
parent.GridView.view.currentIndex = index
var session = appModel.createSessionForGame(index);
session.exec();
}
}
}

View File

@@ -19,6 +19,14 @@ void AppModel::initialize(ComputerManager* computerManager, int computerIndex)
m_CurrentGameId = m_Computer->currentGameId;
}
Session* AppModel::createSessionForApp(int appIndex)
{
Q_ASSERT(appIndex < m_Apps.count());
NvApp app = m_Apps.at(appIndex);
return new Session(m_Computer, app);
}
int AppModel::rowCount(const QModelIndex &parent) const
{
// For list models only the root node (an invalid parent) should return the list's size. For all

View File

@@ -2,6 +2,7 @@
#include "backend/boxartmanager.h"
#include "backend/computermanager.h"
#include "streaming/session.hpp"
#include <QAbstractListModel>
@@ -22,6 +23,8 @@ public:
// Must be called before any QAbstractListModel functions
Q_INVOKABLE void initialize(ComputerManager* computerManager, int computerIndex);
Q_INVOKABLE Session* createSessionForApp(int appIndex);
QVariant data(const QModelIndex &index, int role) const override;
int rowCount(const QModelIndex &parent) const override;

View File

@@ -78,6 +78,26 @@ QHash<int, QByteArray> ComputerModel::roleNames() const
return names;
}
Session* ComputerModel::createSessionForCurrentGame(int computerIndex)
{
Q_ASSERT(computerIndex < m_Computers.count());
NvComputer* computer = m_Computers[computerIndex];
// We must currently be streaming a game to use this function
Q_ASSERT(computer->currentGameId != 0);
for (NvApp& app : computer->appList) {
if (app.id == computer->currentGameId) {
return new Session(computer, app);
}
}
// We have a current running app but it's not in our app list
Q_ASSERT(false);
return nullptr;
}
void ComputerModel::deleteComputer(int computerIndex)
{
Q_ASSERT(computerIndex < m_Computers.count());

View File

@@ -1,4 +1,5 @@
#include "backend/computermanager.h"
#include "streaming/session.hpp"
#include <QAbstractListModel>
@@ -33,6 +34,8 @@ public:
Q_INVOKABLE bool wakeComputer(int computerIndex);
Q_INVOKABLE Session* createSessionForCurrentGame(int computerIndex);
signals:
void pairingCompleted(QVariant error);