
    |~gC                         d dl m Z d dlZd dlmZ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 d d	lmZ d d
lmZ d dlmZ  G d dee      Zy)    )gettextN)OptionalAnyListSet)GLib)Battery)Device)BluezDBusException)BatteryWatcher)AppletPlugin)StatusIconProvider)PluginManagerc                       e Zd ZdZdgZdZ ed      ZddZddZ	de
e   fd	Zdefd
ZddZdeddfdZdedededdfdZdeddfdZdeddfdZdee   deddfdZy)ShowConnectedWalmis
StatusIconzbluetooth-symboliczhAdds an indication on the status icon when Bluetooth is active and shows the connections in the tooltip.returnNc                     t                _        d _        d _        g  _         j                  j                   j                  j                  j                  d j                                j                  j                   j                  j                  j                  d j                               t         fd       _        y )NFzplugin-loadedzplugin-unloadedc                  $    j                         S Nupdate_statusicon)argsselfs    F/usr/lib/python3/dist-packages/blueman/plugins/applet/ShowConnected.py<lambda>z'ShowConnected.on_load.<locals>.<lambda>   s    T=S=S=U     )set_connectionsactiveinitialized	_handlersappendparentPluginsconnect_on_plugins_changedr   _battery_watcherr   s   `r   on_loadzShowConnected.on_load   s    &)e $&dkk1199/4KcKcdedkk1199:KTMeMefg ./U Vr   c                 Z   | j                   j                  j                  j                  d        t	               | _        | j                   j                  j                  j                          | j                  D ]'  }| j                   j                  j                  |       ) g | _        | `	y r   )
r%   r&   r   set_tooltip_textr   r    icon_should_changer#   
disconnectr)   )r   handlers     r   	on_unloadzShowConnected.on_unload!   s~    &&77=E&&99;~~ 	4GKK**73	4!r   c                 :    | j                   rd| _        yd| _        y )NTzblueman-activeF)r    r!   r*   s    r   on_status_icon_query_iconz'ShowConnected.on_status_icon_query_icon*   s    DK#DKr   c                    | j                   j                  j                         D ch c]  }|d   r|j                          c}| _        t        j                  dt        | j                        dd       | j                  r| j                  r| j                  s:| j                  r.| j                   j                  j                  j                          | j                          yc c}w )N	ConnectedzFound dz existing connectionsF)r%   Managerget_devicesget_object_pathr    logginginfolenr!   r&   r   r.   r   )r   devices     r   enumerate_connectionsz#ShowConnected.enumerate_connections2   s    +/;;+>+>+J+J+L5!' &{ 3 $335 5 	vc$"3"34Q77LMNdkk4;L;LQUQ\Q\KK**==? 5s   C'c                    | j                   rdt        dt        fd}| j                  j                  j                  j                  t        d             | j                  j                  j                  j                  dj                  t        || j                                      y | j                  j                  j                  j                  d        d| j                  j                  j                         v r| j                  j                  j                  j                         }|r9| j                  j                  j                  j                  t        d             y | j                  j                  j                  j                  t        d             y | j                  j                  j                  j                  d	       y )
Nobj_pathr   c                 n    t        |       d   }	 | dt        |       d    dS # t        $ r |cY S w xY w)N)r@   Aliasu    🔋
Percentage%)r
   r	   r   )r@   lines     r   
build_linez3ShowConnected.update_statusicon.<locals>.build_lineA   sI    "H5g> "V5()CL)Q(RRSTT)  K s   & 44zBluetooth Active
PowerManagerzBluetooth EnabledzBluetooth DisabledBlueman)r    strr%   r&   r   set_tooltip_title_r-   joinmap
get_loadedrH   get_bluetooth_status)r   rF   statuss      r   r   zShowConnected.update_statusicon?   s9    S  S   KK**<<Q?Q=RSKK**;;DIIc*VZVgVgFh<ijKK**;;DA!4!4!?!?!AA,,99NNPKK''22DDQGZE[\KK''22DDQG[E\]##..@@Kr   statec                     |rU| j                   s(t        j                  d| j                         d| _         y t        j                  d| j                         y t	               | _        | j                          y )Nr   Ti  )r"   r   timeout_addr>   r   r    r   )r   rR   s     r   on_manager_state_changedz&ShowConnected.on_manager_state_changedU   sX    ##  D$>$>?#'   t'A'AB #D""$r   pathkeyvaluec                 ^   |dk(  r|r| j                   j                  |       n| j                   j                  |       | j                   r| j                  r| j                   s:| j                  r.| j                  j
                  j                  j                          | j                          y y )Nr5   )	r    addremover!   r%   r&   r   r.   r   )r   rV   rW   rX   s       r   on_device_property_changedz(ShowConnected.on_device_property_changed`   s    +!!%%d+!!((.!!$++t?P?PUYU`U`##..AAC""$ r   _pathc                 $    | j                          y r   r>   r   r]   s     r   on_adapter_addedzShowConnected.on_adapter_addedl       ""$r   c                 $    | j                          y r   r_   r`   s     r   on_adapter_removedz ShowConnected.on_adapter_removedo   rb   r   _pluginmngrnamec                 0    |dk(  r| j                          y y )NrH   r   )r   re   rf   s      r   r(   z!ShowConnected._on_plugins_changedr   s    >!""$ "r   )r   N)__name__
__module____qualname__
__author____depends____icon__rL   __description__r+   r1   r   rJ   r3   boolr>   r   rU   r   r\   ra   rd   r   r   r(    r   r   r   r      s    J.K#H 6 7OW"8C= t L,	%d 	%t 	%
%s 
% 
%S 
%T 
%%c %d %% % %%}\/J %RU %Z^ %r   r   )r   rL   r:   typingr   r   r   r   gi.repositoryr   blueman.bluez.Batteryr	   blueman.bluez.Devicer
   blueman.bluez.errorsr   blueman.main.BatteryWatcherr   blueman.plugins.AppletPluginr   !blueman.plugins.applet.StatusIconr   blueman.main.PluginManagerr   r   rp   r   r   <module>rz      s:       + +  ) ' 3 6 5 @ 4c%L"4 c%r   