16 |
16 |
17 |
17 |
18 class EricNetworkIcon(QLabel): |
18 class EricNetworkIcon(QLabel): |
19 """ |
19 """ |
20 Class implementing a statusbar icon tracking the network status. |
20 Class implementing a statusbar icon tracking the network status. |
21 |
21 |
22 @signal onlineStateChanged(online) emitted to indicate a change of the |
22 @signal onlineStateChanged(online) emitted to indicate a change of the |
23 network state |
23 network state |
24 @signal reachabilityStateChanged(reachability) emitted to indicate a |
24 @signal reachabilityStateChanged(reachability) emitted to indicate a |
25 change of the network reachability |
25 change of the network reachability |
26 """ |
26 """ |
|
27 |
27 onlineStateChanged = pyqtSignal(bool) |
28 onlineStateChanged = pyqtSignal(bool) |
28 reachabilityStateChanged = pyqtSignal(QNetworkInformation.Reachability) |
29 reachabilityStateChanged = pyqtSignal(QNetworkInformation.Reachability) |
29 |
30 |
30 def __init__(self, parent=None): |
31 def __init__(self, parent=None): |
31 """ |
32 """ |
32 Constructor |
33 Constructor |
33 |
34 |
34 @param parent reference to the parent widget |
35 @param parent reference to the parent widget |
35 @type QWidget |
36 @type QWidget |
36 """ |
37 """ |
37 super().__init__(parent) |
38 super().__init__(parent) |
38 |
39 |
39 if ( |
40 if Preferences.getUI("DynamicOnlineCheck") and QNetworkInformation.load( |
40 Preferences.getUI("DynamicOnlineCheck") and |
41 QNetworkInformation.Feature.Reachability |
41 QNetworkInformation.load(QNetworkInformation.Feature.Reachability) |
|
42 ): |
42 ): |
43 self.__online = ( |
43 self.__online = ( |
44 QNetworkInformation.instance().reachability() == |
44 QNetworkInformation.instance().reachability() |
45 QNetworkInformation.Reachability.Online |
45 == QNetworkInformation.Reachability.Online |
46 ) |
46 ) |
47 self.__reachabilityChanged( |
47 self.__reachabilityChanged(QNetworkInformation.instance().reachability()) |
48 QNetworkInformation.instance().reachability()) |
|
49 QNetworkInformation.instance().reachabilityChanged.connect( |
48 QNetworkInformation.instance().reachabilityChanged.connect( |
50 self.__reachabilityChanged) |
49 self.__reachabilityChanged |
|
50 ) |
51 else: |
51 else: |
52 # assume to be 'always online' if no backend could be loaded or |
52 # assume to be 'always online' if no backend could be loaded or |
53 # dynamic online check is switched of |
53 # dynamic online check is switched of |
54 self.__online = True |
54 self.__online = True |
55 self.__reachabilityChanged(QNetworkInformation.Reachability.Online) |
55 self.__reachabilityChanged(QNetworkInformation.Reachability.Online) |
56 |
56 |
57 def __reachabilityChanged(self, reachability): |
57 def __reachabilityChanged(self, reachability): |
58 """ |
58 """ |
59 Private slot handling reachability state changes. |
59 Private slot handling reachability state changes. |
60 |
60 |
61 @param reachability new reachability state |
61 @param reachability new reachability state |
62 @type QNetworkInformation.Reachability |
62 @type QNetworkInformation.Reachability |
63 """ |
63 """ |
64 online = reachability == QNetworkInformation.Reachability.Online |
64 online = reachability == QNetworkInformation.Reachability.Online |
65 tooltip = self.tr("<p>Shows the Internet reachability status<br/><br/>" |
65 tooltip = self.tr( |
66 "<b>Internet:</b> {0}</p>") |
66 "<p>Shows the Internet reachability status<br/><br/>" |
67 |
67 "<b>Internet:</b> {0}</p>" |
|
68 ) |
|
69 |
68 if online: |
70 if online: |
69 self.setPixmap(UI.PixmapCache.getPixmap("network-online")) |
71 self.setPixmap(UI.PixmapCache.getPixmap("network-online")) |
70 tooltip = tooltip.format(self.tr("Reachable")) |
72 tooltip = tooltip.format(self.tr("Reachable")) |
71 else: |
73 else: |
72 self.setPixmap(UI.PixmapCache.getPixmap("network-offline")) |
74 self.setPixmap(UI.PixmapCache.getPixmap("network-offline")) |
73 tooltip = tooltip.format(self.tr("Not Reachable")) |
75 tooltip = tooltip.format(self.tr("Not Reachable")) |
74 |
76 |
75 self.setToolTip(tooltip) |
77 self.setToolTip(tooltip) |
76 |
78 |
77 if online != self.__online: |
79 if online != self.__online: |
78 self.__online = online |
80 self.__online = online |
79 self.onlineStateChanged.emit(online) |
81 self.onlineStateChanged.emit(online) |
80 |
82 |
81 self.reachabilityStateChanged.emit(reachability) |
83 self.reachabilityStateChanged.emit(reachability) |
82 |
84 |
83 def isOnline(self): |
85 def isOnline(self): |
84 """ |
86 """ |
85 Public method to get the online state. |
87 Public method to get the online state. |
86 |
88 |
87 @return online state |
89 @return online state |
88 @rtype bool |
90 @rtype bool |
89 """ |
91 """ |
90 return self.__online |
92 return self.__online |