webview.qml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. import QtQuick 2.4
  2. import Konvergo 1.0
  3. import QtWebEngine 1.1
  4. import QtWebChannel 1.0
  5. import QtQuick.Window 2.2
  6. import QtQuick.Controls 1.4
  7. KonvergoWindow
  8. {
  9. id: mainWindow
  10. title: "Plex Media Player"
  11. objectName: "mainWindow"
  12. minimumHeight: windowMinSize.height
  13. minimumWidth: windowMinSize.width
  14. function runWebAction(action)
  15. {
  16. if (mainWindow.webDesktopMode)
  17. web.triggerWebAction(action)
  18. }
  19. function actionEnable(enable)
  20. {
  21. action_switchmode.enabled = enable
  22. action_copy.enabled = enable
  23. action_cut.enabled = enable
  24. action_paste.enabled = enable
  25. action_undo.enabled = enable
  26. action_redo.enabled = enable
  27. action_selectall.enabled = enable
  28. action_fullscreen_win.enabled = enable
  29. action_fullscreen_mac.enabled = enable
  30. action_fullscreen_win_alt.enabled = enable
  31. action_quit.enabled = enable
  32. action_quit_win.enabled = enable
  33. }
  34. Action
  35. {
  36. id: action_quit
  37. shortcut: "Ctrl+Q"
  38. onTriggered: mainWindow.close()
  39. }
  40. Action
  41. {
  42. id: action_quit_win
  43. shortcut: "Alt+F4"
  44. onTriggered: mainWindow.close()
  45. }
  46. Action
  47. {
  48. id: action_debug_overlay
  49. shortcut: "Ctrl+Shift+D"
  50. onTriggered: mainWindow.toggleDebug()
  51. }
  52. Action
  53. {
  54. id: action_fullscreen_win_alt
  55. shortcut: "Alt+Return"
  56. onTriggered: mainWindow.toggleFullscreen()
  57. }
  58. Action
  59. {
  60. id: action_fullscreen_win
  61. shortcut: "F11"
  62. onTriggered: mainWindow.toggleFullscreen()
  63. }
  64. Action
  65. {
  66. id: action_fullscreen_mac
  67. shortcut: "Ctrl+Meta+F"
  68. onTriggered: mainWindow.toggleFullscreen()
  69. }
  70. Action
  71. {
  72. id: action_switchmode
  73. shortcut: "Ctrl+M"
  74. onTriggered:
  75. {
  76. if (mainWindow.webDesktopMode)
  77. components.settings.cycleSetting("main.webMode")
  78. }
  79. }
  80. Action
  81. {
  82. shortcut: StandardKey.Copy
  83. onTriggered: runWebAction(WebEngineView.Copy)
  84. id: action_copy
  85. }
  86. Action
  87. {
  88. shortcut: StandardKey.Cut
  89. onTriggered: runWebAction(WebEngineView.Cut)
  90. id: action_cut
  91. }
  92. Action
  93. {
  94. shortcut: StandardKey.Paste
  95. onTriggered: runWebAction(WebEngineView.Paste)
  96. id: action_paste
  97. }
  98. Action
  99. {
  100. shortcut: StandardKey.SelectAll
  101. onTriggered: runWebAction(WebEngineView.SelectAll)
  102. id: action_selectall
  103. }
  104. Action
  105. {
  106. shortcut: StandardKey.Undo
  107. onTriggered: runWebAction(WebEngineView.Undo)
  108. id: action_undo
  109. }
  110. Action
  111. {
  112. shortcut: StandardKey.Redo
  113. onTriggered: runWebAction(WebEngineView.Redo)
  114. id: action_redo
  115. }
  116. function maxWebScale()
  117. {
  118. return webHeightMax ? ((webHeightMax / Screen.devicePixelRatio) / 720) : 10;
  119. }
  120. MpvVideo
  121. {
  122. id: video
  123. objectName: "video"
  124. // It's not a real item. Its renderer draws onto the view's background.
  125. width: 0
  126. height: 0
  127. visible: false
  128. }
  129. WebEngineView
  130. {
  131. id: web
  132. objectName: "web"
  133. anchors.centerIn: parent
  134. settings.errorPageEnabled: false
  135. settings.localContentCanAccessRemoteUrls: true
  136. profile.httpUserAgent: components.system.getUserAgent()
  137. transformOrigin: Item.TopLeft
  138. url: mainWindow.webUrl
  139. focus: true
  140. property string currentHoveredUrl: ""
  141. onLinkHovered: web.currentHoveredUrl = hoveredUrl
  142. width: mainWindow.webUIWidth
  143. height: mainWindow.webUIHeight
  144. scale:
  145. {
  146. if (mainWindow.webDesktopMode)
  147. return 1;
  148. if (mainWindow.windowScale < mainWindow.maxWebScale())
  149. {
  150. // Web renders at windows scale, no scaling
  151. return 1;
  152. }
  153. else
  154. {
  155. // Web should max out at maximum scaling
  156. return mainWindow.windowScale / mainWindow.maxWebScale();
  157. }
  158. }
  159. Component.onCompleted:
  160. {
  161. // set the transparency
  162. // (setting this here as a UserAgent workaround at least for qt5.5)
  163. backgroundColor : "#111111"
  164. forceActiveFocus()
  165. mainWindow.reloadWebClient.connect(reload)
  166. actionEnable(mainWindow.webDesktopMode)
  167. }
  168. onLoadingChanged:
  169. {
  170. // we use a timer here to switch to the webview since
  171. // it take a few moments for the webview to render
  172. // after it has loaded.
  173. //
  174. if (loadRequest.status == WebEngineView.LoadSucceededStatus)
  175. {
  176. console.log("Loaded web-client successfully from: " + web.url);
  177. }
  178. else if (loadRequest.status == WebEngineView.LoadFailedStatus)
  179. {
  180. console.log("FAILED TO LOAD web-client successfully from: " + web.url);
  181. errorLabel.visible = true
  182. errorLabel.text = "Error loading client, this is bad and should not happen<br>" +
  183. "You can try to <a href='reload'>reload</a> or head to our <a href='http://plex.tv/support'>support page</a><br><br>Actual Error: <pre>" +
  184. loadRequest.errorString + " [" + loadRequest.errorCode + "]</pre><br><br>" +
  185. "Provide the <a target='_blank' href='file://"+ components.system.logFilePath + "'>logfile</a> as well."
  186. }
  187. actionEnable(mainWindow.webDesktopMode)
  188. }
  189. onNewViewRequested:
  190. {
  191. if (request.userInitiated)
  192. {
  193. console.log("Opening external URL: " + web.currentHoveredUrl)
  194. components.system.openExternalUrl(web.currentHoveredUrl)
  195. }
  196. }
  197. onFullScreenRequested:
  198. {
  199. console.log("Request fullscreen: " + request.toggleOn)
  200. mainWindow.setFullScreen(request.toggleOn)
  201. request.accept()
  202. }
  203. onJavaScriptConsoleMessage:
  204. {
  205. components.system.info(message)
  206. }
  207. onCertificateError:
  208. {
  209. console.log(error.url + " :" + error.description + error.error)
  210. }
  211. }
  212. Text
  213. {
  214. id: errorLabel
  215. z: 5
  216. anchors.centerIn: parent
  217. color: "#999999"
  218. linkColor: "#cc7b19"
  219. text: "Generic error"
  220. font.pixelSize: 32
  221. font.bold: true
  222. visible: false
  223. verticalAlignment: Text.AlignVCenter
  224. textFormat: Text.StyledText
  225. onLinkActivated:
  226. {
  227. if (link == "reload")
  228. {
  229. errorLabel.visible = false
  230. web.reload()
  231. }
  232. else
  233. {
  234. Qt.openUrlExternally(link)
  235. }
  236. }
  237. }
  238. Rectangle
  239. {
  240. id: debug
  241. color: "black"
  242. z: 10
  243. anchors.centerIn: parent
  244. width: parent.width
  245. height: parent.height
  246. opacity: 0.7
  247. visible: mainWindow.showDebugLayer
  248. Text
  249. {
  250. id: debugLabel
  251. width: (parent.width - 50) / 2
  252. height: parent.height - 25
  253. anchors.left: parent.left
  254. anchors.leftMargin: 64
  255. anchors.top: parent.top
  256. anchors.topMargin: 54
  257. anchors.bottomMargin: 54
  258. color: "white"
  259. font.pixelSize: width / 45
  260. wrapMode: Text.WrapAnywhere
  261. function windowDebug()
  262. {
  263. var dbg = mainWindow.debugInfo + "Window and web\n";
  264. dbg += " Window size: " + parent.width + "x" + parent.height + " - " + web.width + "x" + web.height + "\n";
  265. dbg += " DevicePixel ratio: " + Screen.devicePixelRatio + "\n";
  266. dbg += " Web Max Height: " + (webHeightMax / Screen.devicePixelRatio) + " / Max scale: " + mainWindow.maxWebScale() + "\n";
  267. dbg += " Web scale: " + webScale + " / Window scale: " + windowScale + "\n";
  268. dbg += " Scale applied: " + web.scale + "\n";
  269. return dbg;
  270. }
  271. text: windowDebug()
  272. }
  273. Text
  274. {
  275. id: videoLabel
  276. width: (parent.width - 50) / 2
  277. height: parent.height - 25
  278. anchors.right: parent.right
  279. anchors.left: debugLabel.right
  280. anchors.rightMargin: 64
  281. anchors.top: parent.top
  282. anchors.topMargin: 54
  283. anchors.bottomMargin: 54
  284. color: "white"
  285. font.pixelSize: width / 45
  286. wrapMode: Text.WrapAnywhere
  287. text: mainWindow.videoInfo
  288. }
  289. }
  290. property QtObject webChannel: web.webChannel
  291. }