Browse Source

Add switch between desktop and tv mode

Tobias Hieta 7 years ago
parent
commit
c9b01472c0

+ 1 - 0
resources/inputmaps/keyboard.json

@@ -46,6 +46,7 @@
     "Home": "step_backward",
     "End": "step_forward",
     "Ctrl\\+F": "search",
+    "Ctrl\\+M": "host:cycle_setting main.webMode",
 
     // application shortcuts
     "Ctrl\\+Shift\\+F": "host:fullscreen",

+ 14 - 1
resources/settings/settings_description.json

@@ -18,6 +18,15 @@
   {
     "section": "main",
     "values": [
+      {
+        "value": "webMode",
+        "default": "tv",
+        "platforms": [ "windows", "macosx" ],
+        "possible_values": [
+          [ "desktop", "desktop" ],
+          [ "tv", "tv" ]
+        ]
+      },
       {
         "value": "remoteInspector",
         "default": false,
@@ -372,7 +381,11 @@
     "hidden": true,
     "values": [
       {
-        "value": "startupurl",
+        "value": "startupurl_tv",
+        "default": "bundled"
+      },
+      {
+        "value": "startupurl_desktop",
         "default": "bundled"
       },
       {

+ 12 - 4
src/settings/SettingsComponent.cpp

@@ -699,7 +699,13 @@ bool SettingsComponent::resetAndSaveOldConfiguration()
 /////////////////////////////////////////////////////////////////////////////////////////
 QString SettingsComponent::getWebClientUrl()
 {
-  auto url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl").toString();
+  auto mode = SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode").toString();
+  QString url;
+
+  if (url == "desktop")
+    url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_desktop").toString();
+  else
+    url = SettingsComponent::Get().value(SETTINGS_SECTION_PATH, "startupurl_tv").toString();
 
   // Transition to the new value so that old users are not screwed.
   if (url == "qrc:/konvergo/index.html")
@@ -710,12 +716,14 @@ QString SettingsComponent::getWebClientUrl()
 
   if (url == "bundled")
   {
-    auto path = Paths::webClientPath();
+    auto path = Paths::webClientPath(mode);
     if (path.startsWith("/"))
-      return "file://" + path;
-    return "file:///" + path;
+      url = "file://" + path;
+    url = "file:///" + path;
   }
 
+  QLOG_DEBUG() << "Using web-client URL: " << url;
+
   return url;
 }
 

+ 1 - 1
src/settings/SettingsComponent.h

@@ -58,7 +58,7 @@ public:
   Q_INVOKABLE QString getWebClientUrl();
 
   // host commands
-  Q_SLOT void cycleSetting(const QString& args);
+  Q_SLOT Q_INVOKABLE void cycleSetting(const QString& args);
 
   void updatePossibleValues(const QString& sectionID, const QString& key, const QVariantList& possibleValues);
 

+ 2 - 2
src/shared/Paths.cpp

@@ -128,8 +128,8 @@ QString Paths::soundsPath(const QString& sound)
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
-QString Paths::webClientPath()
+QString Paths::webClientPath(const QString& mode)
 {
-  QString webName = QString("web-client-%1").arg(Version::GetWebVersion());
+  QString webName = QString("web-client/%1").arg(mode);
   return resourceDir(webName + "/index.html");
 }

+ 1 - 1
src/shared/Paths.h

@@ -17,7 +17,7 @@ namespace Paths
   QString logDir(const QString& file = QString());
   QString socketName(const QString& serverName);
   QString soundsPath(const QString& sound);
-  QString webClientPath();
+  QString webClientPath(const QString& mode = "tv");
 };
 
 #endif //KONVERGO_PATHS_H

+ 3 - 0
src/system/SystemComponent.cpp

@@ -183,6 +183,9 @@ void SystemComponent::info(QString text)
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 void SystemComponent::setCursorVisibility(bool visible)
 {
+  if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode") == "desktop")
+    visible = true;
+
   if (visible)
   {
     m_mouseOutTimer->start(MOUSE_TIMEOUT);

+ 7 - 0
src/ui/EventFilter.cpp

@@ -6,12 +6,19 @@
 #include "system/SystemComponent.h"
 #include "settings/SettingsComponent.h"
 #include "input/InputKeyboard.h"
+#include "KonvergoWindow.h"
 
 #include <QKeyEvent>
+#include <QObject>
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 bool EventFilter::eventFilter(QObject* watched, QEvent* event)
 {
+  KonvergoWindow* window = qobject_cast<KonvergoWindow*>(parent());
+
+  if (window && window->property("webDesktopMode").toBool())
+    return QObject::eventFilter(watched, event);
+
   SystemComponent& system = SystemComponent::Get();
 
   // ignore mouse events if mouse is disabled

+ 13 - 0
src/ui/KonvergoWindow.cpp

@@ -25,6 +25,7 @@ KonvergoWindow::KonvergoWindow(QWindow* parent) : QQuickWindow(parent), m_debugL
 
   m_infoTimer = new QTimer(this);
   m_infoTimer->setInterval(1000);
+  m_webDesktopMode = (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode").toString() == "desktop");
 
   installEventFilter(new EventFilter(this));
 
@@ -243,6 +244,18 @@ void KonvergoWindow::updateMainSectionSettings(const QVariantMap& values)
     InputComponent::Get().cancelAutoRepeat();
     updateWindowState();
   }
+
+  if (values.contains("webMode"))
+  {
+    m_webDesktopMode = (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "webMode").toString() == "desktop");
+    emit webDesktopModeChanged();
+    emit webUrlChanged();
+  }
+
+  if (values.contains("startupurl"))
+  {
+    emit webUrlChanged();
+  }
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////

+ 7 - 0
src/ui/KonvergoWindow.h

@@ -3,6 +3,7 @@
 
 #include <QQuickWindow>
 #include <QEvent>
+#include <settings/SettingsComponent.h>
 
 
 // This controls how big the web view will zoom using semantic zoom
@@ -34,6 +35,8 @@ class KonvergoWindow : public QQuickWindow
   Q_PROPERTY(qreal windowScale READ windowScale NOTIFY webScaleChanged)
   Q_PROPERTY(QSize windowMinSize READ windowMinSize NOTIFY webScaleChanged)
   Q_PROPERTY(bool alwaysOnTop READ isAlwaysOnTop WRITE setAlwaysOnTop)
+  Q_PROPERTY(bool webDesktopMode MEMBER m_webDesktopMode NOTIFY webDesktopModeChanged)
+  Q_PROPERTY(QString webUrl READ webUrl NOTIFY webUrlChanged)
 
 public:
   static void RegisterClass();
@@ -89,6 +92,7 @@ public:
   QSize windowMinSize() { return WINDOWW_MIN_SIZE; }
   static qreal CalculateScale(const QSize& size);
   static qreal CalculateWebScale(const QSize& size, qreal devicePixelRatio);
+  QString webUrl() { return SettingsComponent::Get().getWebClientUrl(); }
 
 Q_SIGNALS:
   void fullScreenSwitched();
@@ -97,6 +101,8 @@ Q_SIGNALS:
   void debugLayerChanged();
   void debugInfoChanged();
   void reloadWebClient();
+  void webDesktopModeChanged();
+  void webUrlChanged();
 
 protected:
   void focusOutEvent(QFocusEvent* ev) override;
@@ -125,6 +131,7 @@ private:
   QTimer* m_infoTimer;
   QString m_debugInfo, m_systemDebugInfo, m_videoInfo;
   int m_ignoreFullscreenSettingsChange;
+  bool m_webDesktopMode;
 };
 
 #endif // KONVERGOWINDOW_H

+ 20 - 3
src/ui/webview.qml

@@ -3,6 +3,7 @@ import Konvergo 1.0
 import QtWebEngine 1.1
 import QtWebChannel 1.0
 import QtQuick.Window 2.2
+import QtQuick.Controls 1.4
 
 KonvergoWindow
 {
@@ -41,12 +42,29 @@ KonvergoWindow
     settings.localContentCanAccessRemoteUrls: true
     profile.httpUserAgent: components.system.getUserAgent()
     transformOrigin: Item.TopLeft
+    url: mainWindow.webUrl
 
-    width: Math.round(Math.min((parent.height * 16) / 9, parent.width))
-    height: Math.round(Math.min((parent.width * 9) / 16, parent.height))
+    width: {
+      if (!mainWindow.webDesktopMode) {
+        return Math.round(Math.min((parent.height * 16) / 9, parent.width));
+      } else {
+        return parent.width;
+      }
+    }
+    height: {
+      if (!mainWindow.webDesktopMode) {
+        return Math.round(Math.min((parent.width * 9) / 16, parent.height));
+      } else {
+        return parent.height;
+      }
+
+    }
     
     scale:
     {
+      if (mainWindow.webDesktopMode)
+        return 1;
+
       if (mainWindow.windowScale < mainWindow.maxWebScale()) {
         // Web renders at windows scale, no scaling
         return 1;
@@ -63,7 +81,6 @@ KonvergoWindow
       backgroundColor : "#111111"
       forceActiveFocus()
       mainWindow.reloadWebClient.connect(reload)
-      url = components.settings.getWebClientUrl() + getInitialScaleArg();
     }
 
     onLoadingChanged: