Network/IRC/IrcNetworkWidget.py

changeset 4630
7b0e38956b5c
parent 4021
195a471c327b
child 4631
5c1a96925da4
--- a/Network/IRC/IrcNetworkWidget.py	Tue Dec 29 15:13:23 2015 +0100
+++ b/Network/IRC/IrcNetworkWidget.py	Tue Dec 29 18:59:46 2015 +0100
@@ -9,11 +9,12 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSlot, pyqtSignal, QPoint, QFileInfo, QUrl
+from PyQt5.QtCore import pyqtSlot, pyqtSignal, QPoint, QFileInfo, QUrl, QThread
 from PyQt5.QtGui import QDesktopServices
 from PyQt5.QtWidgets import QWidget, QApplication, QMenu
 
 from E5Gui import E5MessageBox, E5FileDialog
+from E5Gui.E5Application import e5App
 
 from .Ui_IrcNetworkWidget import Ui_IrcNetworkWidget
 
@@ -28,7 +29,7 @@
     """
     Class implementing the network part of the IRC widget.
     
-    @signal connectNetwork(str,bool) emitted to connect or disconnect from
+    @signal connectNetwork(str,bool,bool) emitted to connect or disconnect from
         a network
     @signal editNetwork(str) emitted to edit a network configuration
     @signal joinChannel(str) emitted to join a channel
@@ -37,7 +38,7 @@
     @signal away(bool) emitted to indicate the away status
     @signal autoConnected() emitted after an automatic connection was initiated
     """
-    connectNetwork = pyqtSignal(str, bool)
+    connectNetwork = pyqtSignal(str, bool, bool)
     editNetwork = pyqtSignal(str)
     joinChannel = pyqtSignal(str)
     nickChanged = pyqtSignal(str)
@@ -94,6 +95,17 @@
         """
         Public method to perform the IRC auto connection.
         """
+        userInterface = e5App().getObject("UserInterface")
+        online = userInterface.isOnline()
+        self.connectButton.setEnabled(online)
+        userInterface.onlineStateChanged.connect(self.__onlineStateChanged)
+        if online:
+            self.__autoConnect()
+    
+    def __autoConnect(self):
+        """
+        Public method to perform the IRC auto connection.
+        """
         for networkName in self.__manager.getNetworkNames():
             if self.__manager.getNetwork(networkName).autoConnect():
                 row = self.networkCombo.findText(networkName)
@@ -102,6 +114,24 @@
                 self.autoConnected.emit()
                 break
     
+    @pyqtSlot(bool)
+    def __onlineStateChanged(self, online):
+        """
+        Private slot handling online state changes.
+        
+        @param online online state
+        @type bool
+        """
+        self.connectButton.setEnabled(online)
+        if online:
+            # delay a bit because the signal seems to be sent before the
+            # network interface is fully up
+            QThread.msleep(200)
+            self.__autoConnect()
+        else:
+            network = self.networkCombo.currentText()
+            self.connectNetwork.emit(network, online, True)
+    
     @pyqtSlot()
     def __refreshNetworks(self):
         """
@@ -129,7 +159,7 @@
         Private slot to connect to a network.
         """
         network = self.networkCombo.currentText()
-        self.connectNetwork.emit(network, not self.__connected)
+        self.connectNetwork.emit(network, not self.__connected, False)
     
     @pyqtSlot()
     def on_awayButton_clicked(self):

eric ide

mercurial