o
    \c                     @   sz   d dl m Z d dl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 d dlmZ G d	d
 d
e
eZdS )    )gettextN)OptionalAnyList)GLib)AppletPlugin)ngettext)StatusIconProvider)PluginManagerc                   @   s   e Zd ZdZdgZdZedZd!ddZd!d	d
Z	de
e fddZdefddZd!ddZdeddfddZdedededdfddZdeddfddZdeddfddZdededdfdd ZdS )"ShowConnectedWalmis
StatusIconzbluetooth-symboliczrAdds an indication on the status icon when Bluetooth is active and shows the number of connections in the tooltip.returnNc                 C   sP   d| _ d| _d| _g | _| j| jjd| j | j| jjd| j d S )Nr   Fzplugin-loadedzplugin-unloaded)	num_connectionsactiveinitialized	_handlersappendparentPluginsconnect_on_plugins_changedself r   F/usr/lib/python3/dist-packages/blueman/plugins/applet/ShowConnected.pyon_load   s   zShowConnected.on_loadc                 C   sH   | j jjd  d| _| j jj  | jD ]	}| j j| qg | _d S )Nr   )r   r   r   set_tooltip_textr   icon_should_changer   
disconnect)r   handlerr   r   r   	on_unload   s   

zShowConnected.on_unloadc                 C   s   | j dkr
d| _dS d| _d S )Nr   Tzblueman-activeF)r   r   r   r   r   r   on_status_icon_query_icon$   s
   
z'ShowConnected.on_status_icon_query_iconc                 C   sx   d| _ | jj D ]}|d r|  j d7  _ q	td| j   | j dkr'| jr/| j dkr6| jr6| jjj	  | 
  dS )Nr   	Connected   zFound %d existing connectionsF)r   r   Managerget_deviceslogginginfor   r   r   r   update_statusicon)r   devicer   r   r   enumerate_connections,   s   z#ShowConnected.enumerate_connectionsc                 C   s   | j dkr#| jjjtd | jjjtdd| j d| j i  d S | jjjd  d| jj v rT| jjj	
 }|rH| jjjtd d S | jjjtd d S | jjjd	 d S )
Nr   zBluetooth Activez(<b>%(connections)d Active Connection</b>z)<b>%(connections)d Active Connections</b>connectionsPowerManagerzBluetooth EnabledzBluetooth DisabledBlueman)r   r   r   r   set_tooltip_title_r   r   
get_loadedr-   get_bluetooth_status)r   statusr   r   r   r)   ;   s"   

zShowConnected.update_statusiconstatec                 C   sF   |r| j std| j d| _ d S td| j d S d| _|   d S )Nr   Ti  )r   r   timeout_addr+   r   r)   )r   r4   r   r   r   on_manager_state_changedM   s   
z&ShowConnected.on_manager_state_changed_pathkeyvaluec                 C   sh   |dkr2|r|  j d7  _ n|  j d8  _ | j dkr| jr%| j dkr,| jr,| jjj  |   d S d S )Nr#   r$   r   )r   r   r   r   r   r   r)   )r   r7   r8   r9   r   r   r   on_device_property_changedX   s    z(ShowConnected.on_device_property_changedc                 C      |    d S Nr+   r   r7   r   r   r   on_adapter_addedd      zShowConnected.on_adapter_addedc                 C   r;   r<   r=   r>   r   r   r   on_adapter_removedg   r@   z ShowConnected.on_adapter_removed_pluginmngrnamec                 C   s   |dkr
|    d S d S )Nr-   )r)   )r   rB   rC   r   r   r   r   j   s   z!ShowConnected._on_plugins_changed)r   N)__name__
__module____qualname__
__author____depends____icon__r0   __description__r   r!   r   strr"   boolr+   r)   r6   r   r:   r?   rA   r
   r   r   r   r   r   r      s    


r   )r   r0   r'   typingr   r   r   gi.repositoryr   blueman.plugins.AppletPluginr   r   !blueman.plugins.applet.StatusIconr	   blueman.main.PluginManagerr
   r   r   r   r   r   <module>   s    