import QtQuick 2.4
import Konvergo 1.0
import QtWebEngine 1.1
import QtWebChannel 1.0
import QtQuick.Window 2.2
KonvergoWindow
{
id: mainWindow
title: "Plex Media Player"
objectName: "mainWindow"
visible: true
minimumHeight: 240
minimumWidth: 426
height: 720
width: 1280
function getMaxHeightArg()
{
if (webMaxHeight > 0)
return "?maxHeight=" + (webMaxHeight / Screen.devicePixelRatio);
return ""
}
MpvVideo
{
id: video
objectName: "video"
// It's not a real item. Its renderer draws onto the view's background.
width: 0
height: 0
visible: false
}
WebEngineView
{
id: web
objectName: "web"
anchors.centerIn: parent
settings.errorPageEnabled: false
settings.localContentCanAccessRemoteUrls: true
profile.httpUserAgent: components.system.getUserAgent()
url: components.settings.value("path", "startupurl") + getMaxHeightArg()
transformOrigin: Item.TopLeft
width: Math.min((parent.height * 16) / 9, parent.width)
height: Math.min((parent.width * 9) / 16, parent.height)
function getDesiredScale()
{
var verticalScale = height / 720;
var horizontalScale = width / 1280;
return Math.min(verticalScale, horizontalScale);
}
scale:
{
var desiredScale = getDesiredScale();
var maximumScale = webMaxHeight ? ((webMaxHeight / Screen.devicePixelRatio) / 720) : 10;
if (desiredScale < maximumScale) {
// Web renders at windows scale, no scaling
return 1;
} else {
// Web should max out at maximum scaling
return desiredScale / maximumScale;
}
}
zoomFactor:
{
var desiredScale = getDesiredScale();
if (desiredScale < 1)
return desiredScale;
else
return 1;
}
Component.onCompleted:
{
// set the transparency
// (setting this here as a UserAgent workaround at least for qt5.5)
backgroundColor : "#111111"
forceActiveFocus()
mainWindow.reloadWebClient.connect(reload)
}
onLoadingChanged:
{
// we use a timer here to switch to the webview since
// it take a few moments for the webview to render
// after it has loaded.
//
if (loadRequest.status == WebEngineView.LoadSucceededStatus)
{
console.log("Loaded web-client successfully from: " + web.url);
}
else if (loadRequest.status == WebEngineView.LoadFailedStatus)
{
errorLabel.visible = true
errorLabel.text = "Error loading client, this is bad and should not happen
" +
"You can try to reload or head to our support page
Actual Error:
" + loadRequest.url + "\n" + loadRequest.errorString + " [" + loadRequest.errorCode + "]