Add new icon and change color to orange for status "connecting"

This commit is contained in:
Sébastien Helleu 2021-11-14 09:13:35 +01:00
parent 72c425baea
commit 6958c2352f
4 changed files with 44 additions and 27 deletions

View File

@ -10,8 +10,8 @@ Files: weechat.png, bullet_green_8x8.png, bullet_yellow_8x8.png
Files: application-exit.png, dialog-close.png, dialog-ok-apply.png, Files: application-exit.png, dialog-close.png, dialog-ok-apply.png,
document-save.png, edit-find.png, help-about.png, network-connect.png, dialog-warning.png, document-save.png, edit-find.png, help-about.png,
network-disconnect.png, preferences-other.png network-connect.png, network-disconnect.png, preferences-other.png
Files come from Debian package "oxygen-icon-theme": Files come from Debian package "oxygen-icon-theme":

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

View File

@ -45,6 +45,27 @@ _PROTO_SYNC_CMDS = [
'' ''
] ]
STATUS_DISCONNECTED = 'disconnected'
STATUS_CONNECTING = 'connecting'
STATUS_CONNECTED = 'connected'
NETWORK_STATUS = {
'disconnected': {
'label': 'Disconnected',
'color': '#aa0000',
'icon': 'dialog-close.png',
},
'connecting': {
'label': 'Connecting…',
'color': '#ff7f00',
'icon': 'dialog-warning.png',
},
'connected': {
'label': 'Connected',
'color': 'green',
'icon': 'dialog-ok-apply.png',
},
}
class Network(QtCore.QObject): class Network(QtCore.QObject):
"""I/O with WeeChat/relay.""" """I/O with WeeChat/relay."""
@ -54,9 +75,6 @@ class Network(QtCore.QObject):
def __init__(self, *args): def __init__(self, *args):
super().__init__(*args) super().__init__(*args)
self.status_disconnected = 'disconnected'
self.status_connecting = 'connecting...'
self.status_connected = 'connected'
self._server = None self._server = None
self._port = None self._port = None
self._ssl = None self._ssl = None
@ -71,7 +89,7 @@ class Network(QtCore.QObject):
def _socket_connected(self): def _socket_connected(self):
"""Slot: socket connected.""" """Slot: socket connected."""
self.statusChanged.emit(self.status_connected, None) self.statusChanged.emit(STATUS_CONNECTED, None)
if self._password: if self._password:
self.send_to_weechat('\n'.join(_PROTO_INIT_CMD + _PROTO_SYNC_CMDS) self.send_to_weechat('\n'.join(_PROTO_INIT_CMD + _PROTO_SYNC_CMDS)
% {'password': str(self._password), % {'password': str(self._password),
@ -80,7 +98,7 @@ class Network(QtCore.QObject):
def _socket_error(self, error): def _socket_error(self, error):
"""Slot: socket error.""" """Slot: socket error."""
self.statusChanged.emit( self.statusChanged.emit(
self.status_disconnected, STATUS_DISCONNECTED,
'Failed, error: %s' % self._socket.errorString()) 'Failed, error: %s' % self._socket.errorString())
def _socket_read(self): def _socket_read(self):
@ -111,7 +129,7 @@ class Network(QtCore.QObject):
self._port = None self._port = None
self._ssl = None self._ssl = None
self._password = "" self._password = ""
self.statusChanged.emit(self.status_disconnected, None) self.statusChanged.emit(STATUS_DISCONNECTED, None)
def is_connected(self): def is_connected(self):
"""Return True if the socket is connected, False otherwise.""" """Return True if the socket is connected, False otherwise."""
@ -143,7 +161,7 @@ class Network(QtCore.QObject):
self._socket.connectToHostEncrypted(self._server, self._port) self._socket.connectToHostEncrypted(self._server, self._port)
else: else:
self._socket.connectToHost(self._server, self._port) self._socket.connectToHost(self._server, self._port)
self.statusChanged.emit(self.status_connecting, "") self.statusChanged.emit(STATUS_CONNECTING, "")
def disconnect_weechat(self): def disconnect_weechat(self):
"""Disconnect from WeeChat.""" """Disconnect from WeeChat."""
@ -153,7 +171,7 @@ class Network(QtCore.QObject):
self.send_to_weechat('quit\n') self.send_to_weechat('quit\n')
self._socket.waitForBytesWritten(1000) self._socket.waitForBytesWritten(1000)
else: else:
self.statusChanged.emit(self.status_disconnected, None) self.statusChanged.emit(STATUS_DISCONNECTED, None)
self._socket.abort() self._socket.abort()
def send_to_weechat(self, message): def send_to_weechat(self, message):
@ -168,14 +186,17 @@ class Network(QtCore.QObject):
"""Synchronize with WeeChat.""" """Synchronize with WeeChat."""
self.send_to_weechat('\n'.join(_PROTO_SYNC_CMDS)) self.send_to_weechat('\n'.join(_PROTO_SYNC_CMDS))
def status_label(self, status):
"""Return the label for a given status."""
return NETWORK_STATUS.get(status, {}).get('label', '')
def status_color(self, status):
"""Return the color for a given status."""
return NETWORK_STATUS.get(status, {}).get('color', 'black')
def status_icon(self, status): def status_icon(self, status):
"""Return the name of icon for a given status.""" """Return the name of icon for a given status."""
icon = { return NETWORK_STATUS.get(status, {}).get('icon', '')
self.status_disconnected: 'dialog-close.png',
self.status_connecting: 'dialog-close.png',
self.status_connected: 'dialog-ok-apply.png',
}
return icon.get(status, '')
def get_options(self): def get_options(self):
"""Get connection options.""" """Get connection options."""

View File

@ -41,7 +41,7 @@ from PySide6 import QtCore, QtGui, QtWidgets
from qweechat import config from qweechat import config
from qweechat.weechat import protocol from qweechat.weechat import protocol
from qweechat.network import Network from qweechat.network import Network, STATUS_DISCONNECTED, NETWORK_STATUS
from qweechat.connection import ConnectionDialog from qweechat.connection import ConnectionDialog
from qweechat.buffer import BufferListWidget, Buffer from qweechat.buffer import BufferListWidget, Buffer
from qweechat.debug import DebugDialog from qweechat.debug import DebugDialog
@ -154,7 +154,7 @@ class MainWindow(QtWidgets.QMainWindow):
if hasattr(self.menu, 'setCornerWidget'): if hasattr(self.menu, 'setCornerWidget'):
self.menu.setCornerWidget(self.network_status, self.menu.setCornerWidget(self.network_status,
QtCore.Qt.TopRightCorner) QtCore.Qt.TopRightCorner)
self.network_status_set(self.network.status_disconnected) self.network_status_set(STATUS_DISCONNECTED)
# toolbar # toolbar
toolbar = self.addToolBar('toolBar') toolbar = self.addToolBar('toolBar')
@ -283,13 +283,9 @@ class MainWindow(QtWidgets.QMainWindow):
def network_status_set(self, status): def network_status_set(self, status):
"""Set the network status.""" """Set the network status."""
pal = self.network_status.palette() pal = self.network_status.palette()
if status == self.network.status_connected: pal.setColor(self.network_status.foregroundRole(),
pal.setColor(self.network_status.foregroundRole(), self.network.status_color(status))
QtGui.QColor('green')) ssl = ' (SSL)' if status != STATUS_DISCONNECTED \
else:
pal.setColor(self.network_status.foregroundRole(),
QtGui.QColor('#aa0000'))
ssl = ' (SSL)' if status != self.network.status_disconnected \
and self.network.is_ssl() else '' and self.network.is_ssl() else ''
self.network_status.setPalette(pal) self.network_status.setPalette(pal)
icon = self.network.status_icon(status) icon = self.network.status_icon(status)
@ -297,10 +293,10 @@ class MainWindow(QtWidgets.QMainWindow):
self.network_status.setText( self.network_status.setText(
'<img src="%s"> %s' % '<img src="%s"> %s' %
(resource_filename(__name__, 'data/icons/%s' % icon), (resource_filename(__name__, 'data/icons/%s' % icon),
status.capitalize() + ssl)) self.network.status_label(status) + ssl))
else: else:
self.network_status.setText(status.capitalize()) self.network_status.setText(status.capitalize())
if status == self.network.status_disconnected: if status == STATUS_DISCONNECTED:
self.actions['connect'].setEnabled(True) self.actions['connect'].setEnabled(True)
self.actions['disconnect'].setEnabled(False) self.actions['disconnect'].setEnabled(False)
else: else: