import QtQuick 2.4
import Konvergo 1.0
import QtWebEngine 1.1
import QtWebChannel 1.0
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
KonvergoWindow
{
id: mainWindow
title: "Plex Media Player"
objectName: "mainWindow"
minimumHeight: windowMinSize.height
minimumWidth: windowMinSize.width
function runWebAction(action)
{
if (mainWindow.webDesktopMode)
web.triggerWebAction(action)
}
function actionEnable(enable)
{
action_switchmode.enabled = enable
action_copy.enabled = enable
action_cut.enabled = enable
action_paste.enabled = enable
action_undo.enabled = enable
action_redo.enabled = enable
action_selectall.enabled = enable
action_fullscreen_win.enabled = enable
action_fullscreen_mac.enabled = enable
action_fullscreen_win_alt.enabled = enable
action_quit.enabled = enable
action_quit_win.enabled = enable
}
Action
{
id: action_quit
shortcut: "Ctrl+Q"
onTriggered: mainWindow.close()
}
Action
{
id: action_quit_win
shortcut: "Alt+F4"
onTriggered: mainWindow.close()
}
Action
{
id: action_debug_overlay
shortcut: "Ctrl+Shift+D"
onTriggered: mainWindow.toggleDebug()
}
Action
{
id: action_fullscreen_win_alt
shortcut: "Alt+Return"
onTriggered: mainWindow.toggleFullscreen()
}
Action
{
id: action_fullscreen_win
shortcut: "F11"
onTriggered: mainWindow.toggleFullscreen()
}
Action
{
id: action_fullscreen_mac
shortcut: "Ctrl+Meta+F"
onTriggered: mainWindow.toggleFullscreen()
}
Action
{
id: action_switchmode
shortcut: "Ctrl+M"
onTriggered:
{
if (mainWindow.webDesktopMode)
components.settings.cycleSetting("main.webMode")
}
}
Action
{
shortcut: StandardKey.Copy
onTriggered: runWebAction(WebEngineView.Copy)
id: action_copy
}
Action
{
shortcut: StandardKey.Cut
onTriggered: runWebAction(WebEngineView.Cut)
id: action_cut
}
Action
{
shortcut: StandardKey.Paste
onTriggered: runWebAction(WebEngineView.Paste)
id: action_paste
}
Action
{
shortcut: StandardKey.SelectAll
onTriggered: runWebAction(WebEngineView.SelectAll)
id: action_selectall
}
Action
{
shortcut: StandardKey.Undo
onTriggered: runWebAction(WebEngineView.Undo)
id: action_undo
}
Action
{
shortcut: StandardKey.Redo
onTriggered: runWebAction(WebEngineView.Redo)
id: action_redo
}
function maxWebScale()
{
return webHeightMax ? ((webHeightMax / Screen.devicePixelRatio) / 720) : 10;
}
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()
transformOrigin: Item.TopLeft
url: mainWindow.webUrl
focus: true
property string currentHoveredUrl: ""
onLinkHovered: web.currentHoveredUrl = hoveredUrl
width: mainWindow.webUIWidth
height: mainWindow.webUIHeight
scale:
{
if (mainWindow.webDesktopMode)
return 1;
if (mainWindow.windowScale < mainWindow.maxWebScale())
{
// Web renders at windows scale, no scaling
return 1;
}
else
{
// Web should max out at maximum scaling
return mainWindow.windowScale / mainWindow.maxWebScale();
}
}
Component.onCompleted:
{
// set the transparency
// (setting this here as a UserAgent workaround at least for qt5.5)
backgroundColor : "#111111"
forceActiveFocus()
mainWindow.reloadWebClient.connect(reload)
actionEnable(mainWindow.webDesktopMode)
}
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)
{
console.log("FAILED TO LOAD web-client successfully from: " + web.url);
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.errorString + " [" + loadRequest.errorCode + "]