7 Module implementing the network part of the IRC widget. |
7 Module implementing the network part of the IRC widget. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QPoint, QFileInfo, QUrl |
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QPoint, QFileInfo, QUrl, QThread |
13 from PyQt5.QtGui import QDesktopServices |
13 from PyQt5.QtGui import QDesktopServices |
14 from PyQt5.QtWidgets import QWidget, QApplication, QMenu |
14 from PyQt5.QtWidgets import QWidget, QApplication, QMenu |
15 |
15 |
16 from E5Gui import E5MessageBox, E5FileDialog |
16 from E5Gui import E5MessageBox, E5FileDialog |
|
17 from E5Gui.E5Application import e5App |
17 |
18 |
18 from .Ui_IrcNetworkWidget import Ui_IrcNetworkWidget |
19 from .Ui_IrcNetworkWidget import Ui_IrcNetworkWidget |
19 |
20 |
20 from .IrcUtilities import ircFilter, ircTimestamp |
21 from .IrcUtilities import ircFilter, ircTimestamp |
21 |
22 |
26 |
27 |
27 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget): |
28 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget): |
28 """ |
29 """ |
29 Class implementing the network part of the IRC widget. |
30 Class implementing the network part of the IRC widget. |
30 |
31 |
31 @signal connectNetwork(str,bool) emitted to connect or disconnect from |
32 @signal connectNetwork(str,bool,bool) emitted to connect or disconnect from |
32 a network |
33 a network |
33 @signal editNetwork(str) emitted to edit a network configuration |
34 @signal editNetwork(str) emitted to edit a network configuration |
34 @signal joinChannel(str) emitted to join a channel |
35 @signal joinChannel(str) emitted to join a channel |
35 @signal nickChanged(str) emitted to change the nick name |
36 @signal nickChanged(str) emitted to change the nick name |
36 @signal sendData(str) emitted to send a message to the channel |
37 @signal sendData(str) emitted to send a message to the channel |
37 @signal away(bool) emitted to indicate the away status |
38 @signal away(bool) emitted to indicate the away status |
38 @signal autoConnected() emitted after an automatic connection was initiated |
39 @signal autoConnected() emitted after an automatic connection was initiated |
39 """ |
40 """ |
40 connectNetwork = pyqtSignal(str, bool) |
41 connectNetwork = pyqtSignal(str, bool, bool) |
41 editNetwork = pyqtSignal(str) |
42 editNetwork = pyqtSignal(str) |
42 joinChannel = pyqtSignal(str) |
43 joinChannel = pyqtSignal(str) |
43 nickChanged = pyqtSignal(str) |
44 nickChanged = pyqtSignal(str) |
44 sendData = pyqtSignal(str) |
45 sendData = pyqtSignal(str) |
45 away = pyqtSignal(bool) |
46 away = pyqtSignal(bool) |
89 |
90 |
90 self.__manager.networksChanged.connect(self.__refreshNetworks) |
91 self.__manager.networksChanged.connect(self.__refreshNetworks) |
91 self.__manager.identitiesChanged.connect(self.__refreshNetworks) |
92 self.__manager.identitiesChanged.connect(self.__refreshNetworks) |
92 |
93 |
93 def autoConnect(self): |
94 def autoConnect(self): |
|
95 """ |
|
96 Public method to perform the IRC auto connection. |
|
97 """ |
|
98 userInterface = e5App().getObject("UserInterface") |
|
99 online = userInterface.isOnline() |
|
100 self.connectButton.setEnabled(online) |
|
101 userInterface.onlineStateChanged.connect(self.__onlineStateChanged) |
|
102 if online: |
|
103 self.__autoConnect() |
|
104 |
|
105 def __autoConnect(self): |
94 """ |
106 """ |
95 Public method to perform the IRC auto connection. |
107 Public method to perform the IRC auto connection. |
96 """ |
108 """ |
97 for networkName in self.__manager.getNetworkNames(): |
109 for networkName in self.__manager.getNetworkNames(): |
98 if self.__manager.getNetwork(networkName).autoConnect(): |
110 if self.__manager.getNetwork(networkName).autoConnect(): |
99 row = self.networkCombo.findText(networkName) |
111 row = self.networkCombo.findText(networkName) |
100 self.networkCombo.setCurrentIndex(row) |
112 self.networkCombo.setCurrentIndex(row) |
101 self.on_connectButton_clicked() |
113 self.on_connectButton_clicked() |
102 self.autoConnected.emit() |
114 self.autoConnected.emit() |
103 break |
115 break |
|
116 |
|
117 @pyqtSlot(bool) |
|
118 def __onlineStateChanged(self, online): |
|
119 """ |
|
120 Private slot handling online state changes. |
|
121 |
|
122 @param online online state |
|
123 @type bool |
|
124 """ |
|
125 self.connectButton.setEnabled(online) |
|
126 if online: |
|
127 # delay a bit because the signal seems to be sent before the |
|
128 # network interface is fully up |
|
129 QThread.msleep(200) |
|
130 self.__autoConnect() |
|
131 else: |
|
132 network = self.networkCombo.currentText() |
|
133 self.connectNetwork.emit(network, online, True) |
104 |
134 |
105 @pyqtSlot() |
135 @pyqtSlot() |
106 def __refreshNetworks(self): |
136 def __refreshNetworks(self): |
107 """ |
137 """ |
108 Private slot to refresh all network related widgets. |
138 Private slot to refresh all network related widgets. |
127 def on_connectButton_clicked(self): |
157 def on_connectButton_clicked(self): |
128 """ |
158 """ |
129 Private slot to connect to a network. |
159 Private slot to connect to a network. |
130 """ |
160 """ |
131 network = self.networkCombo.currentText() |
161 network = self.networkCombo.currentText() |
132 self.connectNetwork.emit(network, not self.__connected) |
162 self.connectNetwork.emit(network, not self.__connected, False) |
133 |
163 |
134 @pyqtSlot() |
164 @pyqtSlot() |
135 def on_awayButton_clicked(self): |
165 def on_awayButton_clicked(self): |
136 """ |
166 """ |
137 Private slot to toggle the away status. |
167 Private slot to toggle the away status. |