diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py
index 338abc4a0..c06d71ee9 100644
--- a/openlp/plugins/remotes/lib/remotetab.py
+++ b/openlp/plugins/remotes/lib/remotetab.py
@@ -198,21 +198,7 @@ class RemoteTab(SettingsTab):
"""
Update the display based on the data input on the screen
"""
- ip_address = 'localhost'
- if self.address_edit.text() == ZERO_URL:
- interfaces = QtNetwork.QNetworkInterface.allInterfaces()
- for interface in interfaces:
- if not interface.isValid():
- continue
- if not (interface.flags() & (QtNetwork.QNetworkInterface.IsUp | QtNetwork.QNetworkInterface.IsRunning)):
- continue
- for address in interface.addressEntries():
- ip = address.ip()
- if ip.protocol() == 0 and ip != QtNetwork.QHostAddress.LocalHost:
- ip_address = ip
- break
- else:
- ip_address = self.address_edit.text()
+ ip_address = self.get_ip_address(self.address_edit.text())
http_url = 'http://%s:%s/' % (ip_address, self.port_spin_box.value())
https_url = 'https://%s:%s/' % (ip_address, self.https_port_spin_box.value())
self.remote_url.setText('%s' % (http_url, http_url))
@@ -226,6 +212,25 @@ class RemoteTab(SettingsTab):
self.live_url.setText('%s' % (http_url_temp, http_url_temp))
self.live_https_url.setText('%s' % (https_url_temp, https_url_temp))
+ def get_ip_address(self, ip_address):
+ """
+ returns the IP address in dependency of the passed address
+ ip_address == 0.0.0.0: return the IP address of the first valid interface
+ else: return ip_address
+ """
+ if ip_address == ZERO_URL:
+ interfaces = QtNetwork.QNetworkInterface.allInterfaces()
+ for interface in interfaces:
+ if not interface.isValid():
+ continue
+ if not (interface.flags() & (QtNetwork.QNetworkInterface.IsUp | QtNetwork.QNetworkInterface.IsRunning)):
+ continue
+ for address in interface.addressEntries():
+ ip = address.ip()
+ if ip.protocol() == QtNetwork.QAbstractSocket.IPv4Protocol and ip != QtNetwork.QHostAddress.LocalHost:
+ return ip.toString()
+ return ip_address
+
def load(self):
"""
Load the configuration and update the server configuration if necessary
diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py
index 9ff795e73..e683699cd 100644
--- a/tests/functional/openlp_plugins/remotes/test_remotetab.py
+++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py
@@ -2,6 +2,7 @@
This module contains tests for the lib submodule of the Remotes plugin.
"""
import os
+import re
from unittest import TestCase
from tempfile import mkstemp
@@ -52,6 +53,27 @@ class TestRemoteTab(TestCase):
del self.form
os.unlink(self.ini_file)
+ def get_ip_address_default_test(self):
+ """
+ Test the get_ip_address function with ZERO_URL
+ """
+ # WHEN: the default ip address is given
+ ip_address = self.form.get_ip_address(ZERO_URL)
+ # THEN: the default ip address will be returned
+ self.assertTrue(re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip_address), 'The return value should be a valid ip address')
+
+ def get_ip_address_with_ip_test(self):
+ """
+ Test the get_ip_address function with given ip address
+ """
+ # GIVEN: A mocked location
+ # GIVEN: An ip address
+ given_ip = '192.168.1.1'
+ # WHEN: the default ip address is given
+ ip_address = self.form.get_ip_address(given_ip)
+ # THEN: the default ip address will be returned
+ self.assertEqual(ip_address, given_ip, 'The return value should be %s' % given_ip)
+
def set_basic_urls_test(self):
"""
Test the set_urls function with standard defaults