o
    \c                     @   s   d dl m Z d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ er0d dlmZ d dlmZ d d	lmZ d d
lmZ d dlZd dlmZmZ G dd dZG dd dZG dd dZG dd deZdS )    )gettext)CallableUnionTYPE_CHECKING)RFCOMMError)GLib)Service)BluezDBusException)NMConnectionError)AppletPlugin)Device)get_serviceN)SerialServiceNetworkServicec                   @   s4   e Zd ZdededdfddZdeddfddZdS )	RFCOMMConnectedListenerserviceportreturnNc                 C      d S N )selfr   r   r   r   D/usr/lib/python3/dist-packages/blueman/plugins/applet/DBusService.pyon_rfcomm_connected      z+RFCOMMConnectedListener.on_rfcomm_connectedc                 C   r   r   r   )r   r   r   r   r   on_rfcomm_disconnect   r   z,RFCOMMConnectedListener.on_rfcomm_disconnect)__name__
__module____qualname__r   strr   intr   r   r   r   r   r      s    r   c                	   @   sD   e Zd Zdedeegdf deeeej	f gdf de
fddZdS )RFCOMMConnectHandlerr   replyNerrr   c                 C   r   r   r   )r   r   r"   r#   r   r   r   rfcomm_connect_handler      z+RFCOMMConnectHandler.rfcomm_connect_handler)r   r   r   r   r   r   r   r   r   Errorboolr$   r   r   r   r   r!      s    r!   c                	   @   sx   e Zd Zdedeg df deedejf gdf defddZ	dedeg df deedejf gdf defd	d
Z
dS )ServiceConnectHandlerr   okNr#   r
   r   c                 C   r   r   r   r   r   r)   r#   r   r   r   service_connect_handler#   r%   z-ServiceConnectHandler.service_connect_handlerc                 C   r   r   r   r*   r   r   r   service_disconnect_handler'   r%   z0ServiceConnectHandler.service_disconnect_handler)r   r   r   r   r   r   r   r&   r'   r+   r,   r   r   r   r   r(   "   s    
r(   c                   @   s   e Zd ZdgZdZedZdZdddZd	e	d
e	de
g df de
eedeeje	f gdf ddf
ddZd	e	d
e	dede
g df de
eedeje	f gdf ddfddZdddZdS )DBusService
StatusIconFz.Provides DBus API for other Blueman componentsWalmisr   Nc                    s     ddd jjj   ddd fdd   ddd	 jjj  j d
dd	 jdd  j ddd	 jdd   ddd	 j d S )NQueryPluginsr   asQueryAvailablePluginsc                      s   t  jj S r   )listparentPluginsget_classesr   r   r   r   <lambda>4   s    z%DBusService.on_load.<locals>.<lambda>SetPluginConfig)sb ConnectService)or:   T)is_asyncDisconnectService)r>   r:   dOpenPluginDialog)_add_dbus_methodr4   r5   
get_loaded
set_configconnect_service_disconnect_service_open_plugin_dialogr7   r   r7   r   on_load2   s   zDBusService.on_loadobject_pathuuidr)   r#   r
   c                    sF  zj jj W n ty   td Y n
w j jj|| |dkr1t|d}|j d d S t	t|d|d us?J t
 fddj jtD rSd S ttrdtdd ffd	d
t
 fddj jtD sjfdd d d S d S ttrjfdd d d S td  d d S )Nz!RecentConns plugin is unavailable$00000000-0000-0000-0000-000000000000obj_pathreply_handlererror_handlerc                 3       | ]
}|  V  qd S r   )r+   .0pluginr#   r)   r   r   r   	<genexpr>K       z.DBusService.connect_service.<locals>.<genexpr>rfcommr   c                    s8   t tsJ jjtD ]}||  q   d S r   )
isinstancer   r4   r5   get_loaded_pluginsr   r   )rY   rU   )r)   r   r   r   r   r"   O   s   
z*DBusService.connect_service.<locals>.replyc                 3   rR   r   )r$   rS   )r#   r"   r   r   r   rW   U   rX   c                         S r   r   )r   r)   r   r   r8   W       z-DBusService.connect_service.<locals>.<lambda>c                    r\   r   r   )	interfacer]   r   r   r8   Y   r^   zNo handler registeredzQService not supported
Possibly the plugin that handles this service is not loaded)r4   r5   RecentConnsKeyErrorloggingwarningnotifyr   connectr   anyr[   r(   rZ   r   r   r!   r   info)r   rJ   rK   r)   r#   devicer   )r#   r)   r"   r   r   r   rF   :   s4   



zDBusService.connect_servicer   c                    s   |dkrt |d}|j d d S tt |d|d us J t fdd| jjtD r4d S tt	rWj| d | jjt
D ]}|| qHtd d S ttrej d d S d S )NrL   rM   rO   c                 3   rR   r   )r,   rS   rV   r   r   rW   h   rX   z2DBusService._disconnect_service.<locals>.<genexpr>zDisconnecting rfcomm device)r   
disconnectr   rf   r4   r5   r[   r(   rZ   r   r   r   rb   rg   r   )r   rJ   rK   r   r)   r#   rh   rU   r   rV   r   rG   ^   s"   


zDBusService._disconnect_servicec                 C   s   | j jj  d S r   )r4   r5   StandardItems
on_pluginsr7   r   r   r   rH   u   s   zDBusService._open_plugin_dialog)r   N)r   r   r   __depends____unloadable_____description__
__author__rI   r   r   r   r	   r   r   r&   rF   r    rG   rH   r   r   r   r   r-   ,   s2    

$
r-   )r   rn   typingr   r   r   _bluemanr   gi.repositoryr   blueman.Servicer   blueman.bluez.errorsr	   blueman.main.NetworkManagerr
   blueman.plugins.AppletPluginr   blueman.bluez.Devicer   blueman.services.Functionsr   rb   blueman.services.metar   r   r   r!   r(   r-   r   r   r   r   <module>   s"    
