[clients_icons] 7.10.6
This commit is contained in:
@@ -1 +1 @@
|
||||
from .clients_icons import ClientsIconsPlugin
|
||||
from .clients_icons import ClientsIconsPlugin # type: ignore
|
||||
|
||||
@@ -13,16 +13,24 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
|
||||
from collections import UserDict
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
ClientData = namedtuple('ClientData', ['default', 'variations'])
|
||||
ClientData.__new__.__defaults__ = (None,)
|
||||
|
||||
@dataclass
|
||||
class ClientData:
|
||||
default: Optional[tuple[str, str]] = None
|
||||
variations: Optional[dict[str, str]] = None
|
||||
|
||||
|
||||
def get_variations(client_name):
|
||||
def get_variations(client_name: str) -> list[str]:
|
||||
# get_variations('Conversation Legacy 1.2.3')
|
||||
#
|
||||
# Returns List:
|
||||
@@ -32,29 +40,32 @@ def get_variations(client_name):
|
||||
if client_name is None:
|
||||
return []
|
||||
alts = client_name.split()
|
||||
alts = [" ".join(alts[:(i + 1)]) for i in range(len(alts))]
|
||||
alts = [' '.join(alts[:(i + 1)]) for i in range(len(alts))]
|
||||
alts.reverse()
|
||||
return alts
|
||||
|
||||
|
||||
class ClientsDict(UserDict):
|
||||
def get_client_data(self, name, node):
|
||||
class ClientsDict(UserDict[str, ClientData]):
|
||||
def get_client_data(self, name: str, node: str) -> tuple[str, str]:
|
||||
client_data = self.get(node)
|
||||
if client_data is None:
|
||||
return _('Unknown'), 'xmpp-client-unknown'
|
||||
|
||||
if client_data.variations is None:
|
||||
assert client_data.default is not None
|
||||
client_name, icon_name = client_data.default
|
||||
return client_name, 'xmpp-client-%s' % icon_name
|
||||
return client_name, f'xmpp-client-{icon_name}'
|
||||
|
||||
variations = get_variations(name)
|
||||
for var in variations:
|
||||
try:
|
||||
return var, 'xmpp-client-%s' % client_data.variations[var]
|
||||
return var, f'xmpp-client-{client_data.variations[var]}'
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
assert client_data.default is not None
|
||||
client_name, icon_name = client_data.default
|
||||
return client_name, 'xmpp-client-%s' % icon_name
|
||||
return client_name, f'xmpp-client-{icon_name}'
|
||||
|
||||
|
||||
# ClientData(
|
||||
@@ -62,6 +73,7 @@ class ClientsDict(UserDict):
|
||||
# variations={Shown name, icon name}
|
||||
# )
|
||||
|
||||
# pylint: disable=too-many-lines
|
||||
CLIENTS = ClientsDict({
|
||||
'http://gajim.org': ClientData(('Gajim', 'gajim')),
|
||||
'https://gajim.org': ClientData(('Gajim', 'gajim')),
|
||||
@@ -193,7 +205,8 @@ CLIENTS = ClientsDict({
|
||||
'http://www.xfire.com/caps': ClientData(('Xfire', 'xfire')),
|
||||
'http://xu-6.jabbrik.ru/caps': ClientData(('XU-6', 'bot')),
|
||||
})
|
||||
# pylint: enable=too-many-lines
|
||||
|
||||
|
||||
def get_data(*args):
|
||||
def get_data(*args: Any) -> tuple[str, str]:
|
||||
return CLIENTS.get_client_data(*args)
|
||||
|
||||
@@ -13,18 +13,29 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import cast
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from functools import partial
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
from nbxmpp.structs import DiscoInfo
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.gui.util import load_icon_surface
|
||||
from gajim.common.modules.contacts import GroupchatParticipant
|
||||
from gajim.common.modules.contacts import ResourceContact
|
||||
|
||||
from gajim.plugins import GajimPlugin
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from gajim.gui.util import load_icon_surface
|
||||
|
||||
from clients_icons import clients
|
||||
from clients_icons.config_dialog import ClientsIconsConfigDialog
|
||||
|
||||
@@ -32,7 +43,7 @@ log = logging.getLogger('gajim.p.client_icons')
|
||||
|
||||
|
||||
class ClientsIconsPlugin(GajimPlugin):
|
||||
def init(self):
|
||||
def init(self) -> None:
|
||||
self.description = _('Shows client icons in your contact list '
|
||||
'and in the groupchat participants list.')
|
||||
self.config_dialog = partial(ClientsIconsConfigDialog, self)
|
||||
@@ -41,10 +52,7 @@ class ClientsIconsPlugin(GajimPlugin):
|
||||
'roster_tooltip_resource_populate': (
|
||||
self._roster_tooltip_resource_populate,
|
||||
None),
|
||||
'gc_tooltip_populate': (
|
||||
self._gc_roster_tooltip_populate,
|
||||
None),
|
||||
}
|
||||
}
|
||||
|
||||
self.config_default_values = {
|
||||
'show_in_tooltip': (True, ''),
|
||||
@@ -56,12 +64,18 @@ class ClientsIconsPlugin(GajimPlugin):
|
||||
_icon_theme.append_search_path(str(Path(__file__).parent))
|
||||
|
||||
@staticmethod
|
||||
def _get_client_identity_name(disco_info):
|
||||
def _get_client_identity_name(disco_info: DiscoInfo) -> Optional[str]:
|
||||
for identity in disco_info.identities:
|
||||
if identity.category == 'client':
|
||||
return identity.name
|
||||
return None
|
||||
|
||||
def _get_image_and_client_name(self,
|
||||
contact: Union[
|
||||
GroupchatParticipant, ResourceContact],
|
||||
_widget: Gtk.Widget
|
||||
) -> Optional[tuple[Gtk.Image, str]]:
|
||||
|
||||
def _get_image_and_client_name(self, contact, _widget):
|
||||
disco_info = app.storage.cache.get_last_disco_info(contact.jid)
|
||||
if disco_info is None:
|
||||
return None
|
||||
@@ -77,7 +91,11 @@ class ClientsIconsPlugin(GajimPlugin):
|
||||
surface = load_icon_surface(icon_name)
|
||||
return Gtk.Image.new_from_surface(surface), client_name
|
||||
|
||||
def _roster_tooltip_resource_populate(self, resource_box, resource):
|
||||
def _roster_tooltip_resource_populate(self,
|
||||
resource_box: Gtk.Box,
|
||||
resource: ResourceContact
|
||||
) -> None:
|
||||
|
||||
if not self.config['show_in_tooltip']:
|
||||
return
|
||||
|
||||
@@ -94,26 +112,5 @@ class ClientsIconsPlugin(GajimPlugin):
|
||||
client_box.add(label)
|
||||
|
||||
children = resource_box.get_children()
|
||||
children[0].add(client_box)
|
||||
|
||||
def _gc_roster_tooltip_populate(self, tooltip, contact, tooltip_grid):
|
||||
if not self.config['show_in_tooltip']:
|
||||
return
|
||||
|
||||
result = self._get_image_and_client_name(contact, tooltip_grid)
|
||||
if result is None:
|
||||
return
|
||||
|
||||
image, client_name = result
|
||||
|
||||
label = Gtk.Label(label=client_name)
|
||||
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
box.add(image)
|
||||
box.add(label)
|
||||
box.show_all()
|
||||
|
||||
tooltip_grid.insert_next_to(tooltip._ui.affiliation,
|
||||
Gtk.PositionType.BOTTOM)
|
||||
tooltip_grid.attach_next_to(box, tooltip._ui.affiliation,
|
||||
Gtk.PositionType.BOTTOM, 1, 1)
|
||||
box = cast(Gtk.Box, children[9])
|
||||
box.add(client_box)
|
||||
|
||||
@@ -13,34 +13,50 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from gajim.gui.settings import SettingsDialog
|
||||
from gajim.gui.const import Setting
|
||||
from gajim.gui.const import SettingKind
|
||||
from gajim.gui.const import SettingType
|
||||
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
if TYPE_CHECKING:
|
||||
from .clients_icons import ClientsIconsPlugin
|
||||
|
||||
|
||||
class ClientsIconsConfigDialog(SettingsDialog):
|
||||
def __init__(self, plugin, parent):
|
||||
def __init__(self, plugin: ClientsIconsPlugin, parent: Gtk.Window) -> None:
|
||||
|
||||
self.plugin = plugin
|
||||
settings = [
|
||||
Setting(SettingKind.SWITCH,
|
||||
_('Show Icons in Tooltip'),
|
||||
SettingType.VALUE,
|
||||
self.plugin.config['show_in_tooltip'],
|
||||
callback=self._on_setting,
|
||||
data='show_in_tooltip'),
|
||||
|
||||
Setting(SettingKind.SWITCH, _('Show Icons in Tooltip'),
|
||||
SettingType.VALUE, self.plugin.config['show_in_tooltip'],
|
||||
callback=self._on_setting, data='show_in_tooltip'),
|
||||
Setting(SettingKind.SWITCH,
|
||||
_('Show Icon for Unknown Clients'),
|
||||
SettingType.VALUE,
|
||||
self.plugin.config['show_unknown_icon'],
|
||||
callback=self._on_setting,
|
||||
data='show_unknown_icon'),
|
||||
]
|
||||
|
||||
Setting(SettingKind.SWITCH, _('Show Icon for Unknown Clients'),
|
||||
SettingType.VALUE, self.plugin.config['show_unknown_icon'],
|
||||
callback=self._on_setting, data='show_unknown_icon'),
|
||||
SettingsDialog.__init__(self,
|
||||
parent,
|
||||
_('Clients Icons Configuration'),
|
||||
Gtk.DialogFlags.MODAL,
|
||||
settings,
|
||||
'')
|
||||
|
||||
]
|
||||
|
||||
SettingsDialog.__init__(self, parent, _('Clients Icons Configuration'),
|
||||
Gtk.DialogFlags.MODAL, settings, None)
|
||||
|
||||
def _on_setting(self, value, data):
|
||||
def _on_setting(self, value: Any, data: Any) -> None:
|
||||
self.plugin.config[data] = value
|
||||
|
||||
@@ -18,5 +18,5 @@
|
||||
"gajim>=1.4.0"
|
||||
],
|
||||
"short_name": "clients_icons",
|
||||
"version": "7.10.5"
|
||||
"version": "7.10.6"
|
||||
}
|
||||
Reference in New Issue
Block a user