[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktorrent] /: store interface name as string in cfg file, thanks Alan for the patch
From:       Nick Shaforostoff <shafff () ukr ! net>
Date:       2016-04-17 14:53:59
Message-ID: E1aro5H-0006Oh-4b () scm ! kde ! org
[Download RAW message or body]

Git commit 74d7b94f12e8357c4ed402917342ac1999572376 by Nick Shaforostoff.
Committed on 17/04/2016 at 14:51.
Pushed by shaforo into branch 'master'.

store interface name as string in cfg file, thanks Alan for the patch

CCMAIL: alan.ezust@gmail.com

M  +4    -7    ktmagnetdownloader/magnettest.cpp
M  +4    -7    ktorrent/core.cpp
M  +26   -4    ktorrent/pref/networkpref.cpp
M  +1    -0    ktorrent/pref/networkpref.h
M  +1    -1    ktorrent/pref/networkpref.ui
M  +2    -2    libktcore/dbus/dbussettings.cpp
M  +2    -2    libktcore/dbus/dbussettings.h
M  +1    -16   libktcore/interfaces/functions.cpp
M  +1    -4    libktcore/ktorrent.kcfg

http://commits.kde.org/ktorrent/74d7b94f12e8357c4ed402917342ac1999572376

diff --git a/ktmagnetdownloader/magnettest.cpp b/ktmagnetdownloader/magnettest.cpp
index ad09750..481a3db 100644
--- a/ktmagnetdownloader/magnettest.cpp
+++ b/ktmagnetdownloader/magnettest.cpp
@@ -79,14 +79,11 @@ void MagnetTest::start()
     }
 
     // Make sure network interface is set properly before server is initialized
-    if (Settings::networkInterface() != 0)
+    if (!Settings::networkInterface().isEmpty())
     {
-        QList<QNetworkInterface> iface_list = QNetworkInterface::allInterfaces();
-        int iface = Settings::networkInterface();
-        if (iface > iface_list.count())
-            SetNetworkInterface(QString::null);
-        else
-            SetNetworkInterface(iface_list[iface - 1].name());
+        //QList<QNetworkInterface> iface_list = QNetworkInterface::allInterfaces();
+        QString iface = Settings::networkInterface();
+        SetNetworkInterface(iface);
     }
 
 
diff --git a/ktorrent/core.cpp b/ktorrent/core.cpp
index d579ae4..0274f9d 100644
--- a/ktorrent/core.cpp
+++ b/ktorrent/core.cpp
@@ -101,14 +101,11 @@ namespace kt
         connect(&update_timer, &QTimer::timeout, this, &Core::update);
 
         // Make sure network interface is set properly before server is initialized
-        if (Settings::networkInterface() != 0)
+        if (!Settings::networkInterface().isEmpty())
         {
-            QList<QNetworkInterface> iface_list = QNetworkInterface::allInterfaces();
-            int iface = Settings::networkInterface();
-            if (iface > iface_list.count())
-                SetNetworkInterface(QString::null);
-            else
-                SetNetworkInterface(iface_list[iface - 1].name());
+        //    QList<QNetworkInterface> iface_list = QNetworkInterface::allInterfaces();
+            QString iface = Settings::networkInterface();
+            SetNetworkInterface(iface);
         }
 
 
diff --git a/ktorrent/pref/networkpref.cpp b/ktorrent/pref/networkpref.cpp
index e159876..07b2078 100644
--- a/ktorrent/pref/networkpref.cpp
+++ b/ktorrent/pref/networkpref.cpp
@@ -44,6 +44,7 @@ namespace kt
     {
     }
 
+
     void NetworkPref::loadSettings()
     {
         kcfg_maxDownloadRate->setValue(Settings::maxDownloadRate());
@@ -51,8 +52,8 @@ namespace kt
         kcfg_maxConnections->setValue(Settings::maxConnections());
         kcfg_maxTotalConnections->setValue(Settings::maxTotalConnections());
 
-        kcfg_networkInterface->clear();
-        kcfg_networkInterface->addItem(QIcon::fromTheme("network-wired"), i18n("All interfaces"));
+        combo_networkInterface->clear();
+        combo_networkInterface->addItem(QIcon::fromTheme("network-wired"), i18n("All interfaces"));
 
         kcfg_onlyUseUtp->setEnabled(Settings::utpEnabled());
         kcfg_primaryTransportProtocol->setEnabled(Settings::utpEnabled() && !Settings::onlyUseUtp());
@@ -79,10 +80,31 @@ namespace kt
             }
 #endif
 
-            kcfg_networkInterface->addItem(icon, iface.name());
+            combo_networkInterface->addItem(icon, iface.name());
         }
+        QString iface = Settings::networkInterface();
+        int idx = (iface.isEmpty())? 0 /*all*/: combo_networkInterface->findText(iface);
+        if (idx < 0)
+        {
+            bool ok;
+            iface.toInt(&ok);
+            if (ok)
+            {
+                idx = 0;
+            }
+            else
+            {
+                combo_networkInterface->addItem(iface);
+                idx = combo_networkInterface->findText(iface);
+            }
+        }
+        combo_networkInterface->setCurrentIndex(idx);
+    }
 
-        kcfg_networkInterface->setCurrentIndex(Settings::networkInterface());
+    void NetworkPref::updateSettings()
+    {
+        QString iface = combo_networkInterface->currentText();
+        Settings::setNetworkInterface(iface);
     }
 
     void NetworkPref::loadDefaults()
diff --git a/ktorrent/pref/networkpref.h b/ktorrent/pref/networkpref.h
index 67ab858..3fb6261 100644
--- a/ktorrent/pref/networkpref.h
+++ b/ktorrent/pref/networkpref.h
@@ -39,6 +39,7 @@ namespace kt
 
         virtual void loadSettings();
         virtual void loadDefaults();
+        virtual void updateSettings();
     signals:
         void calculateRecommendedSettings();
 
diff --git a/ktorrent/pref/networkpref.ui b/ktorrent/pref/networkpref.ui
index f1dd4c9..38b25a3 100644
--- a/ktorrent/pref/networkpref.ui
+++ b/ktorrent/pref/networkpref.ui
@@ -211,7 +211,7 @@
          </widget>
         </item>
         <item row="2" column="1">
-         <widget class="QComboBox" name="kcfg_networkInterface">
+         <widget class="QComboBox" name="combo_networkInterface">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
             <horstretch>0</horstretch>
diff --git a/libktcore/dbus/dbussettings.cpp b/libktcore/dbus/dbussettings.cpp
index 5c785d4..e2eb1af 100644
--- a/libktcore/dbus/dbussettings.cpp
+++ b/libktcore/dbus/dbussettings.cpp
@@ -598,12 +598,12 @@ namespace kt
         Settings::setMaxSeedTime(val);
     }
 
-    int DBusSettings::networkInterface()
+    QString DBusSettings::networkInterface()
     {
         return Settings::networkInterface();
     }
 
-    void DBusSettings::setNetworkInterface(int val)
+    void DBusSettings::setNetworkInterface(const QString &val)
     {
         Settings::setNetworkInterface(val);
     }
diff --git a/libktcore/dbus/dbussettings.h b/libktcore/dbus/dbussettings.h
index e7337d3..2425f13 100644
--- a/libktcore/dbus/dbussettings.h
+++ b/libktcore/dbus/dbussettings.h
@@ -149,8 +149,8 @@ namespace kt
         Q_SCRIPTABLE void setCompletedDir(QString val);
         Q_SCRIPTABLE double maxSeedTime();
         Q_SCRIPTABLE void setMaxSeedTime(double val);
-        Q_SCRIPTABLE int networkInterface();
-        Q_SCRIPTABLE void setNetworkInterface(int val);
+        Q_SCRIPTABLE QString networkInterface();
+        Q_SCRIPTABLE void setNetworkInterface(const QString &val);
         Q_SCRIPTABLE bool openMultipleTorrentsSilently();
         Q_SCRIPTABLE void setOpenMultipleTorrentsSilently(bool val);
         Q_SCRIPTABLE bool openAllTorrentsSilently();
diff --git a/libktcore/interfaces/functions.cpp b/libktcore/interfaces/functions.cpp
index 3d7e56a..3516203 100644
--- a/libktcore/interfaces/functions.cpp
+++ b/libktcore/interfaces/functions.cpp
@@ -160,22 +160,7 @@ namespace kt
 
         bt::TorrentControl::setDataCheckWhenCompleted(Settings::checkWhenFinished());
         bt::TorrentControl::setMinimumDiskSpace(Settings::minDiskSpace());
-
-
-        if (Settings::networkInterface() == 0)
-        {
-            SetNetworkInterface(QString::null);
-        }
-        else
-        {
-            QList<QNetworkInterface> iface_list = QNetworkInterface::allInterfaces();
-            int iface = Settings::networkInterface();
-            if (iface > iface_list.count())
-                SetNetworkInterface(QString::null);
-            else
-                SetNetworkInterface(iface_list[iface - 1].name());
-        }
-
+        bt::SetNetworkInterface(Settings::networkInterface());
         net::Socks::setSocksEnabled(Settings::socksEnabled());
         net::Socks::setSocksVersion(Settings::socksVersion());
         net::Socks::setSocksServerAddress(Settings::socksProxy(), Settings::socksPort());
diff --git a/libktcore/ktorrent.kcfg b/libktcore/ktorrent.kcfg
index 80f8882..c29643d 100644
--- a/libktcore/ktorrent.kcfg
+++ b/libktcore/ktorrent.kcfg
@@ -244,10 +244,7 @@
 			<default>0</default>
 			<min>0</min>
 		</entry>
-		<entry name="networkInterface" type="Int">
-			<default>0</default>
-			<min>0</min>
-			<max>255</max>
+		<entry name="networkInterface" type="String">
 		</entry>
 		<entry name="openMultipleTorrentsSilently" type="Bool">
 			<default>false</default>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic