
    h'/                        d dl Z  e j                  dd       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j                        Zedk(  r ej                         Z e       Zej#                         Zej'                  dej(                  j*                         ej-                  d       ej/                  e       ej1                           ej2                          yy)    NGtkz3.0)r   )Gdk)GObject)Pango)gettext)open_urlc                   D    e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zy)ChangelogViewerNc                    t         j                   j                  |        d| _        d| _        | j	                  dd       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       t        j                         | _        | j                  | j                         | j                  d| j                         | j                  d| j                          | j                  d| j"                         | j                  j%                  d| j&                         || j                  j)                  |       y	y	)
z>Init the ChangelogViewer as an Inheritance of the Gtk.TextViewFTeditable   zbutton-press-eventzmotion-notify-eventzvisibility-notify-eventzinsert-textN)r   __init__hoveringfirstset_propertyset_cursor_visibleset_right_marginset_left_marginset_pixels_above_linesset_vexpandr   
TextBufferbuffer
set_bufferconnectbutton_press_eventmotion_notify_eventvisibility_notify_eventconnect_afteron_insert_textset_text)self	changelogs     ?/usr/lib/python3/dist-packages/UpdateManager/ChangelogViewer.pyr   zChangelogViewer.__init__*   s    	  &
*e,&a Q##A&nn&$)4+B+BC*D,D,DE.0L0LM!!-1D1DE KK  + !    c                     t        j                         | _        t        j                         }|j	                  |       |j                  d| j                  d|       t        j                         }t        j                         }|j	                  t        d             |j                  d| j                  d|       t        j                         }|j	                  t        d             |j                  d| j                  d|       | j                  j                  |       | j                  j                  |       | j                  j                  |       | j                  j                  |       | j                  j                          y)zLCreate the context menu to be displayed when links are right
        clickedactivateopenzOpen Link in BrowserzCopy Link to ClipboardcopyN)
r   MenumenuMenuItem	set_labelr   handle_context_menu_addshow_all)r!   urlitem_grey_linkitem_seperatoritem_open_linkitem_copy_links         r#   create_context_menuz#ChangelogViewer.create_context_menuE   s"    HHJ	   %00&#	
   #9!:;00&#	
   #;!<=00&#	

 			n%		n%		n%		n%		r$   c                 0   |dk(  rt        |       |dk(  rt        j                  j                         }t        j                  j                  dd      }t        j                  j                  ||      }|j                  |d       |j                          yy)z1Handle activate event for the links' context menur'   r(   	CLIPBOARDFN)r   r   Displayget_defaultAtominternr   	Clipboardget_for_displayr    store)r!   menuitemactionr1   display	selectioncbs          r#   r-   z#ChangelogViewer.handle_context_menuc   ss    VSMV
 kk--/GU;I..w	BBKKR HHJ r$   c                    |j                         }|D ]  }t        |dd      }|dk7  s y | j                  j                  ddt        j
                  j                        }||_        | j                  j                  |||       y)z@Apply the tag that marks links to the specified buffer selectionr1   N blue)
foreground	underline)	get_tagsgetattrr   
create_tagr   	UnderlineSINGLEr1   	apply_tag)r!   startendr1   tagstags         r#   tag_linkzChangelogViewer.tag_linkr   s    ~~ 	C#ud+Cby	 kk$$Vu/E/E % 
 c5#.r$   c                    d}d}d}g d}g d}	g d}
dg|
z   }dg}d	||	z   |
z   |z   d	fd
||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fd||	z   |z   |fg}|D ]  \  }}}|j                  |j                         t        |      z
        }	 |j                  |t        j
                  j                  |      }|sb|\  }}|j                         }|j                         }	 |j                         rM|j                  |      }||v rnI|j                          |j                  |      }||v rn#|j                          nn|j                         }o||j                  |      z   }| j                  |||       |} y)zLSearch for http URLs in newly inserted text
        and tag them accordinglyzhttps://launchpad.net/bugs/zhttp://bugs.debian.org/z2http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-) 	
))]>),!:.z.
zhttp://zLP#zlp#zLP: #zlp: #zLP:#zlp:#z	Malone: #zMalone:#z	Ubuntu: #zUbuntu:#z	Closes: #zCloses:#zcloses:#z	closes: #zCVE-N)get_iter_at_offset
get_offsetlenforward_searchr   TextSearchFlagsVISIBLE_ONLYr(   forward_charget_textbackward_charrU   )r!   r   iter_endcontentargsMALONEDEBIANCVEwsbrakpunctdotdot_crsearch_items	start_strend_list
url_prefixiterretmatch_start	match_endmatch_suffix	match_tmptextr1   s                            r#   r   zChangelogViewer.on_insert_text   s   
 /*Beem T	E)F2I>BIOV,BIOV,b4i#ov.b4i#ov.R$Y_f-R$Y_f-"t)c/62dS&1"t)c/62dS&1"t)c/62dS&1dS&1"t)c/62R$Y_c*!
( 2> &	!-Y*,,##%G4D ))s22?? +.(i(~~/%NN,	 --/(11)<8+! "..0(11)<8+!!//1 ) 0I $ !<#8#8#CCk9c: C &	!r$   c           	      l   |j                   dk7  r|j                   dk7  ry	 | j                  j                         \  }}|j                         |j                         k7  ry| j                  t        j                  j                  t        |j                        t        |j                              \  }}	 | j                  ||      }|j                         }|D ]  }
t        |
d      s|j                   dk(  rt!        |
j"                          y|j                   dk(  sF| j%                  |
j"                         | j&                  j)                  dddd|j                   |j*                          y y# t        $ r Y w xY w# t        $ r( | j                  ||      \  }	}|j                         }Y w xY w)zcallback for mouse click events      Fr1   NT)buttonr   get_selection_boundsrb   
ValueErrorwindow_to_buffer_coordsr   TextWindowTypeWIDGETintxyget_iter_at_locationrK   AttributeErrorhasattrr   r1   r6   r*   popuptime)r!   	text_vieweventrQ   rR   r   r   ry   rS   	over_textrT   s              r#   r   z"ChangelogViewer.button_press_event   su    <<1!2	;;;;=LUC !S^^%55 --%%s577|S\
A	#,,Q2D==?D  
	 CsE"<<1$SWW%<<1$,,SWW5IIOOdD$ejj  
	 '  		  	# $ 9 9!Q ?Y==?D	#s#   E2 5"F 2	E?>E?.F32F3c                 >   |j                  t        j                  j                  t	        |j
                        t	        |j                              \  }}| j                  ||       | j                  t        j                  j                        j                          y)zxcallback for the mouse movement event, that calls the
        check_hovering method with the mouse postition coordiantesF)r   r   r   r   r   r   r   check_hovering
get_windowTEXTget_pointer)r!   r   r   r   r   s        r#   r   z#ChangelogViewer.motion_notify_event   sq     00%%s577|S\
1 	Aq!**//0<<>r$   c                     |j                  t        j                  j                        }|j	                         \  }}}}|j                  t        j                  j                  ||      \  }}	| j                  ||	       y)zcallback if the widgets gets visible (e.g. moves to the foreground)
        that calls the check_hovering method with the mouse position
        coordinatesF)r   r   r   r   r   r   r   r   )
r!   r   r   windowscreenwxwymodbxbys
             r#   r   z'ChangelogViewer.visibility_notify_event   ss     %%c&8&8&=&=> & 2 2 4R44%%r2
R 	B#r$   c                    d}	 | j                  ||      }|j                         }|D ]  }t        |d      sd} n || j                  k7  s| j
                  rd| _        || _        | j                  rn| j                  t        j                  j                        j                  t        j                  j                  t        j                  j                               y| j                  t        j                  j                        j                  t        j                  j                  t        j                  j                                yy# t        $ r) | j                  ||      \  }}|j                         }Y Zw xY w)zOCheck if the mouse is above a tagged link and if yes show
        a hand cursorFr1   TN)r   rK   r   r   r   r   r   r   r   r   
set_cursorr   Cursornew
CursorTypeHAND2LEFT_PTR)r!   r   r   	_hoveringry   rS   r   rT   s           r#   r   zChangelogViewer.check_hovering  s+    		#,,Q2D==?D  	CsE" 		 %DJ%DM}} 2 2 7 78CCJJNN3>>#7#78  2 2 7 78CCJJNN3>>#:#:; *4  	# $ 9 9!Q ?Y==?D	#s   "E .F F)N)__name__
__module____qualname__r   r6   r-   rU   r   r   r   r   r    r$   r#   r
   r
   )   s2    ,6</M!^& P
r$   r
   __main__
versiontag)weightz

Version 6-14-0ubuntu1.9.04:

  * New upstream version. LP: #382918.
    Release notes at http://java.sun.com/javase/6/webnotes/ReleaseNotes.html.

)girequire_versiongi.repositoryr   r   r   r   r   r.   DistUpgrade.ReleaseNotesViewerr   TextViewr
   r   Windowwcv
get_bufferchangesrM   WeightBOLDr    r/   r0   mainr   r$   r#   <module>r      s   : 
   5%     !    3Bcll BJ z

A		BmmoG|ELL,=,=>		 EE"IJJLCHHJ% r$   