
    l
j'                         d dl Z d dlmZ d dlZd dlZd dlZd dlmZ d dlZe j                   Z G d d      Z	 G d d      Z
 G d d	      Z G d
 d      Z G d d      Z G d d      Zy)    N)Gio)OpStatusc                   <    e Zd Zd Zej
                  d        Zd Zy)NewOpUserNotificationc                 2    || _         | j                          y Nopsend_notificationselfr
   s     (/usr/libexec/warpinator/notifications.py__init__zNewOpUserNotification.__init__            c                     t        j                         rt        j                  j	                  t        d            }t        j                         rt        j                  t        d      t        d       j                  j                         j                  j                   j                  j                   j                  j                  d   dz  }|j                  |       |j                  t        j                  d             |j!                  t        d      d	       |j!                  t        d
      d       |j#                  d       |j%                  t        j&                  j(                         t        j*                  j-                         j/                  d      j1                  d j2                   j                          j                  j1                  d fd       nt        j                  t        d      t        d       j                  j                         j                  j                   j                  j                   j                  j                  d   dz  }|j                  |       |j                  t        j                  d             t        j*                  j-                         j5                   j                  j6                  |       y y )NzNew incoming fileszK%(sender_name)s would like to send you %(file_count)d file (%(file_name)s).z;%(sender_name)s would like to send you %(file_count)d filesr   )sender_name
file_count	file_nameorg.x.Warpinator-symbolicnameAcceptz!app.notification-response::acceptDeclinez"app.notification-response::decline app.notification-response::focusnotification-responseactivatezstatus-changedc                     j                   j                  t        j                  k7  rj	                  | j
                        S d S r   )r
   statusr   WAITING_PERMISSIONwithdraw_notificationsender)r
   appr   s    r   <lambda>z9NewOpUserNotification.send_notification.<locals>.<lambda>3   s1    dggnnX`XsXsFsc77		B y} r   zC%(sender_name)s is sending you %(file_count)d file (%(file_name)s).z3%(sender_name)s is sending you %(file_count)d files)prefsget_show_notificationsr   Notificationnew_require_permission_for_transfergettextngettextr
   total_countr   top_dir_basenamesset_bodyset_icon
ThemedIcon
add_buttonset_default_actionset_priorityNotificationPriorityURGENTApplicationget_defaultlookup_actionconnect_notification_responser   r"   r   notificationbodyr#   s   `  @r   r   z'NewOpUserNotification.send_notification   s.   '')++//2F0GHL446 &&cdSTUYU\U\UhUhj .2WW-@-@,0GG,?,?+/77+D+DQ+G %%d+%%cnn:U&VW''(5XY'')6Z[//0RS))#*B*B*I*IJoo113!!"9:BB:tOjOjlplslst 0}
 &&[\KLdggNaNac .2WW-@-@,0GG,?,?+/77+D+DQ+G %%d+%%cnn:U&VWOO'');;DGGNNLYY *r   c                 ,   |j                         }|dk(  r|j                          n&|dk(  r|j                          n|j                          t        j
                  j                         }|j                  d      j                  | j                         y )Nacceptdecliner   )
unpackaccept_transferdecline_transfer_requestfocusr   r7   r8   r9   disconnect_by_funcr;   r   actionvariantr
   responser#   s         r   r;   z,NewOpUserNotification._notification_responseE   sq    >>#x "'')HHJoo))+12EEdFaFabr   N__name__
__module____qualname__r   misc_idler   r;    r   r   r   r      s(    !
 
ZZ-Z -Z^cr   r   c                   >    e Zd ZddZej
                  d        Zd Zy)TransferCompleteNotificationc                 N    || _         || _        || _        | j                          y r   )r
   r"   warnr   )r   r
   r"   rU   s       r   r   z%TransferCompleteNotification.__init__S   s#    	 r   c                    t        j                         rt        j                  j	                  t        d            }| j                  rR| j                  r#t        d      | j                  j                  z  }ntt        d      | j                  j                  z  }nQ| j                  r#t        d      | j                  j                  z  }n"t        d      | j                  j                  z  }|j                  |       | j                  rd}nd}|j                  t        j                  |             |j                  d	       |j                  t        j                   j"                         t        j$                  j'                         }|j)                  d
      j+                  d| j,                  | j                         |j'                         j/                  | j                  j                  |       y y )NzTransfer completez0The transfer to %s has finished, but with errorsz,The transfer to %s has finished successfullyz2The transfer from %s has finished, but with errorsz.The transfer from %s has finished successfullyzxsi-dialog-warning-symboliczxsi-emblem-ok-symbolicr   r   r   r   )r%   r&   r   r'   r(   r)   r"   rU   r
   receiver_namer   r/   r0   r1   r3   r4   r5   NORMALr7   r8   r9   r:   r;   r   )r   r=   r>   	icon_namer#   s        r   r   z.TransferCompleteNotification.send_notificationZ   ss   '')++//2E0FGL{{99PQTXT[T[TiTiiDLMPTPWPWPePeeD99RSVZV]V]ViViiDNORVRYRYReReeD!!$'yy9	4	!!#..i"@A++,NO%%c&>&>&E&EF//--/C56>>z4KfKfhlhohopOO//M7 *r   c                     |j                          t        j                  j                         }|j	                  d      j                  | j                         y Nr   rE   r   r7   r8   r9   rF   r;   r   rH   rI   r
   r#   s        r   r;   z3TransferCompleteNotification._notification_responsey   =    

oo))+12EEdFaFabr   N)TFrK   rQ   r   r   rS   rS   R   s'    ! 
ZZN N<cr   rS   c                   >    e Zd ZddZej
                  d        Zd Zy)TransferFailedNotificationc                 @    || _         || _        | j                          y r   r
   r"   r   r   r
   r"   s      r   r   z#TransferFailedNotification.__init__        r   c                    t        j                         rrt        j                  j	                  t        d            }| j                  r#t        d      | j                  j                  z  }n"t        d      | j                  j                  z  }|j                  |       |j                  t        j                  d             |j                  d       |j                  t        j                  j                          t        j"                  j%                         }|j'                  d      j)                  d| j*                  | j                         |j%                         j-                  | j                  j                  |       y y )	NzTransfer failedz,Something went wrong with the transfer to %sz.Something went wrong with the transfer from %szxsi-dialog-error-symbolicr   r   r   r   r%   r&   r   r'   r(   r)   r"   r
   rW   r   r/   r0   r1   r3   r4   r5   rX   r7   r8   r9   r:   r;   r   r<   s       r   r   z,TransferFailedNotification.send_notification   s   '')++//2C0DEL{{HIDGGLaLaaJKdggNaNaa!!$'!!#..6Q"RS++,NO%%c&>&>&E&EF//--/C56>>z4KfKfhlhohopOO//M# *r   c                     |j                          t        j                  j                         }|j	                  d      j                  | j                         y r[   r\   r]   s        r   r;   z1TransferFailedNotification._notification_response   r^   r   NTrK   rQ   r   r   r`   r`      '    ! 
ZZN N(cr   r`   c                   >    e Zd ZddZej
                  d        Zd Zy)TransferStoppedNotificationc                 @    || _         || _        | j                          y r   rb   rc   s      r   r   z$TransferStoppedNotification.__init__   rd   r   c                    t        j                         rrt        j                  j	                  t        d            }| j                  r#t        d      | j                  j                  z  }n"t        d      | j                  j                  z  }|j                  |       |j                  t        j                  d             |j                  d       |j                  t        j                  j                          t        j"                  j%                         }|j'                  d      j)                  d| j*                  | j                         |j%                         j-                  | j                  j                  |       y y )	NzTransfer cancelledz!Your transfer to %s was cancelledz*An incoming transfer from %s was cancelleddialog-info-symbolicr   r   r   r   rf   r<   s       r   r   z-TransferStoppedNotification.send_notification   s   '')++//2F0GHL{{=>AVAVVFG$''J]J]]!!$'!!#..6L"MN++,NO%%c&>&>&E&EF//--/C56>>z4KfKfhlhohopOO//M# *r   c                     |j                          t        j                  j                         }|j	                  d      j                  | j                         y r[   r\   r]   s        r   r;   z2TransferStoppedNotification._notification_response   r^   r   Nrh   rK   rQ   r   r   rk   rk      ri   r   rk   c                   <    e Zd Zd Zej
                  d        Zd Zy)WarpinatorSendNotificationc                 2    || _         | j                          y r   r	   r   s     r   r   z#WarpinatorSendNotification.__init__   r   r   c                    t        j                         rt        j                  j	                  t        d            }| j                  j                  dkD  r9t        d      | j                  j                  | j                  j                  fz  }n;t        d      | j                  j                  d   | j                  j                  fz  }|j                  |       |j                  t        j                  d             |j                  d       |j                  t        j                  j                          t        j"                  j%                         }|j'                  d	      j)                  d
| j*                  | j                         |j%                         j-                  | j                  j.                  |       y y )NzSending files   zSending %d files to %szSending '%s' to %sr   rn   r   r   r   r   )r%   r&   r   r'   r(   r)   r
   r-   rW   r.   r/   r0   r1   r3   r4   r5   rX   r7   r8   r9   r:   r;   r   r"   r<   s       r   r   z,WarpinatorSendNotification.send_notification   sE   '')++///0BCLww""Q&23tww7J7JDGGLaLa6bb./4773L3LQ3OQUQXQXQfQf2gg!!$'!!#..6L"MN++,NO%%c&>&>&E&EF//--/C56>>z4KfKfhlhohopOO//M# *r   c                     |j                          t        j                  j                         }|j	                  d      j                  | j                         y r[   r\   r]   s        r   r;   z1WarpinatorSendNotification._notification_response   r^   r   NrK   rQ   r   r   rq   rq      s'    !
 
ZZN N(cr   rq   c                   <    e Zd Zd Zej
                  d        Zd Zy)TextMessageNotificationc                 2    || _         | j                          y r   r	   r   s     r   r   z TextMessageNotification.__init__   s     r   c                    t        j                         rYt        j                  j	                  t        d      | j                  j                  z        }|j                  | j                  j                         |j                  t        j                  d             |j                  t        j                  j                         |j                  t        d      d       |j!                  d       t        j"                  j%                         }|j'                  d      j)                  d| j*                  | j                         |j-                  | j                  j.                  |       y y )	NzNew message from %sr   r   Copyzapp.notification-response::copyr   r   r   )r%   r&   r   r'   r(   r)   r
   r   r/   messager0   r1   r4   r5   r6   r2   r3   r7   r8   r9   r:   r;   r   r"   )r   r=   r#   s      r   r   z)TextMessageNotification.send_notification   s    '')++//2G0H477K^K^0^_L!!$''//2!!#..6Q"RS%%c&>&>&E&EF##AfI/PQ++,NO//--/C56>>z4KfKfhlhohop!!$''..,? *r   c                     |j                         }|dk(  r|j                          n|j                          t        j                  j                         }|j                  d      j                  | j                         y )Ncopyr   )	rB   copy_messagerE   r   r7   r8   r9   rF   r;   rG   s         r   r;   z.TextMessageNotification._notification_response   s[    >>#vOOHHJoo))+12EEdFaFabr   NrK   rQ   r   r   rw   rw      s'    ! 
ZZ@ @	cr   rw   )r+   gi.repositoryr   configrO   utilr   r%   r)   r   rS   r`   rk   rq   rw   rQ   r   r   <module>r      st          OOAc AcF+c +cZ c  cD c  cDc cBc cr   