moonlight-qt/app/gui/PcView.qml

169 lines
5 KiB
QML
Raw Normal View History

2018-07-04 23:40:21 +00:00
import QtQuick 2.9
import QtQuick.Controls 2.2
2018-07-05 01:48:09 +00:00
import QtQuick.Dialogs 1.3
import QtQuick.Layouts 1.11
2018-07-04 23:40:21 +00:00
import ComputerModel 1.0
GridView {
anchors.fill: parent
anchors.leftMargin: 5
anchors.topMargin: 5
anchors.rightMargin: 5
anchors.bottomMargin: 5
cellWidth: 350; cellHeight: 350;
focus: true
model: ComputerModel {}
delegate: Item {
width: 300; height: 300;
Image {
id: pcIcon
anchors.horizontalCenter: parent.horizontalCenter;
source: {
model.addPc ? "ic_add_to_queue_white_48px.svg" : "ic_tv_white_48px.svg"
2018-07-04 23:40:21 +00:00
}
sourceSize {
width: 200
height: 200
2018-07-04 23:40:21 +00:00
}
}
Text {
id: pcNameText
text: model.name
color: "white"
width: parent.width
anchors.top: pcIcon.bottom
minimumPointSize: 12
font.pointSize: 48
horizontalAlignment: Text.AlignHCenter
fontSizeMode: Text.HorizontalFit
}
2018-07-04 23:40:21 +00:00
Text {
function getStatusText(model)
{
if (model.online) {
var text = "<font color=\"green\">Online</font>"
text += "<font color=\"white\"> - </font>"
if (model.paired) {
text += "<font color=\"skyblue\">Paired</font>"
}
else if (model.busy) {
text += "<font color=\"red\">Busy</font>"
2018-07-04 23:40:21 +00:00
}
else {
text += "<font color=\"red\">Not Paired</font>"
2018-07-04 23:40:21 +00:00
}
return text
}
else {
return "<font color=\"red\">Offline</font>";
2018-07-04 23:40:21 +00:00
}
}
2018-07-04 23:40:21 +00:00
id: pcPairedText
text: getStatusText(model)
visible: !model.addPc
2018-07-04 23:40:21 +00:00
width: parent.width
anchors.top: pcNameText.bottom
minimumPointSize: 12
font.pointSize: 36
horizontalAlignment: Text.AlignHCenter
fontSizeMode: Text.HorizontalFit
}
2018-07-04 23:40:21 +00:00
MouseArea {
anchors.fill: parent
onClicked: {
if (model.addPc) {
addPcDialog.open()
}
else if (model.online) {
if (model.paired) {
// go to game view
var component = Qt.createComponent("AppView.qml")
var appView = component.createObject(stackView)
appView.computerIndex = index
stackView.push(appView)
}
else {
if (!model.busy) {
// TODO: generate pin
pairDialog.text = pairDialog.text.replace("XXXX", "1234")
// TODO: initiate pairing request
pairDialog.open()
}
else {
// cannot pair while something is streaming or attempting to pair
pairingFailedDialog.open()
}
}
}
else {
// TODO: Wake on LAN and delete PC options
2018-07-05 01:48:09 +00:00
}
}
}
}
MessageDialog {
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"
standardButtons: Dialog.OK
}
2018-07-05 01:48:09 +00:00
MessageDialog {
id: pairDialog
// don't allow edits to the rest of the window while open
modality:Qt.WindowModal
text:"Please enter XXXX on your GameStream PC. This dialog will close when pairing is completed."
standardButtons: Dialog.Cancel
2018-07-05 01:48:09 +00:00
onRejected: {
// FIXME: We should interrupt pairing here
2018-07-05 01:48:09 +00:00
}
}
Dialog {
id: addPcDialog
property string label: "Enter the IP address of your GameStream PC"
property string hint: "192.168.1.100"
2018-07-05 01:48:09 +00:00
property alias editText : editTextItem
standardButtons: StandardButton.Ok | StandardButton.Cancel
onVisibleChanged: {
editTextItem.focus = true
editTextItem.selectAll()
}
onAccepted: {
console.log("accepted, with value: " + editText.text)
}
ColumnLayout {
Text {
id: addPcDialogLabel
text: addPcDialog.label
2018-07-05 01:48:09 +00:00
}
Rectangle {
implicitWidth: parent.parent.width
height: editTextItem.height
TextInput {
id: editTextItem
inputMethodHints: Qt.ImhPreferUppercase
text: addPcDialog.hint
2018-07-04 23:40:21 +00:00
}
}
}
}
}