Network Settings: Show a warning that proxy settings do not apply to localhost
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 21 Oct 2019 10:35:27 +0000 (12:35 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:03 +0000 (10:59 +0100)
Only show this if at least one account is detected to have an url that looks
like localhost, because this could otherwise be confusing

Issue #7169

src/gui/networksettings.cpp
src/gui/networksettings.h
src/gui/networksettings.ui

index b2b72ed0882a6ce7395596ebab31bc0a7596b3dc..1c3631d4f9ff6e11bc60c8fd8d1e96e4202e353b 100644 (file)
@@ -55,6 +55,8 @@ NetworkSettings::NetworkSettings(QWidget *parent)
         _ui->manualSettings, &QWidget::setEnabled);
     connect(_ui->manualProxyRadioButton, &QAbstractButton::toggled,
         _ui->typeComboBox, &QWidget::setEnabled);
+    connect(_ui->manualProxyRadioButton, &QAbstractButton::toggled,
+        this, &NetworkSettings::checkAccountLocalhost);
 
     loadProxySettings();
     loadBWLimitSettings();
@@ -80,6 +82,7 @@ NetworkSettings::NetworkSettings(QWidget *parent)
     // Warn about empty proxy host
     connect(_ui->hostLineEdit, &QLineEdit::textChanged, this, &NetworkSettings::checkEmptyProxyHost);
     checkEmptyProxyHost();
+    checkAccountLocalhost();
 }
 
 NetworkSettings::~NetworkSettings()
@@ -233,8 +236,27 @@ void NetworkSettings::showEvent(QShowEvent *event)
         checkEmptyProxyHost();
         saveProxySettings();
     }
+    checkAccountLocalhost();
 
     QWidget::showEvent(event);
 }
 
+
+void NetworkSettings::checkAccountLocalhost()
+{
+    bool visible = false;
+    if (_ui->manualProxyRadioButton->isChecked()) {
+        // Check if at least one account is using localhost, because Qt proxy settings have no
+        // effect for localhost (#7169)
+        for (const auto &account : AccountManager::instance()->accounts()) {
+            const auto host = account->account()->url().host();
+            // Some typical url for localhost
+            if (host == "localhost" || host.startsWith("127.") || host == "[::1]")
+                visible = true;
+        }
+    }
+    _ui->labelLocalhost->setVisible(visible);
+}
+
+
 } // namespace OCC
index ee07a39d10becb040bf858f010cac38c95bcd1a5..4fd6db5720a4568157acbe0c3e4efa3f0e40f7df 100644 (file)
@@ -44,6 +44,8 @@ private slots:
     /// Red marking of host field if empty and enabled
     void checkEmptyProxyHost();
 
+    void checkAccountLocalhost();
+
 protected:
     void showEvent(QShowEvent *event) override;
 
index 2ee1122260104799490c55d42df26ec7a56cb8e7..dd21dc646f0f8e79978a21044419c4917b41f0e1 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>516</width>
-    <height>444</height>
+    <width>623</width>
+    <height>581</height>
    </rect>
   </property>
   <property name="windowTitle">
       <string>Proxy Settings</string>
      </property>
      <layout class="QGridLayout" name="gridLayout">
+      <item row="2" column="1">
+       <widget class="QComboBox" name="typeComboBox">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
       <item row="0" column="0">
        <widget class="QRadioButton" name="noProxyRadioButton">
         <property name="text">
         </attribute>
        </widget>
       </item>
-      <item row="2" column="1">
-       <widget class="QComboBox" name="typeComboBox">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-       </widget>
-      </item>
       <item row="3" column="0" colspan="2">
        <widget class="QWidget" name="manualSettings" native="true">
         <property name="enabled">
            </layout>
           </widget>
          </item>
+         <item>
+          <widget class="QLabel" name="labelLocalhost">
+           <property name="text">
+            <string>Note: proxy settings have no effects for accounts on localhost</string>
+           </property>
+          </widget>
+         </item>
         </layout>
        </widget>
       </item>