ó
ÍÿŠTc           @   s¡   d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z d  d l m Z m	 Z	 m
 Z
 e  j d ƒ Z d „  Z d „  Z d „  Z d	 e j f d
 „  ƒ  YZ d S(   iÿÿÿÿN(   t   gettext(   t   GObjectt   Gtk(   t   CANONICAL_MANAGEDt   LOCAL_MANAGEDt   NOT_MANAGEDsT   ^(([a-zA-Z][a-zA-Z0-9\-]*)?[a-zA-Z0-9][\.]?)*(([A-Za-z][A-Za-z0-9\-]*)?[A-Za-z0-9])$c         C   s
   |  j  ƒ  S(   s/   
    Do some minimal host name sanitation.
    (   t   strip(   t	   host_name(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   sanitise_host_name   s    c         C   s   t  j |  ƒ d k	 S(   sh   
    Check that the provided host name complies with L{HOST_NAME_REGEXP} and is
    therefor valid.
    N(   t   HOST_NAME_REGEXPt   matcht   None(   R   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   is_valid_host_name   s    c         C   s.   y |  j  d ƒ t SWn t k
 r) t SXd S(   sT   
    Test that the provided string contains only characters from the ASCII set.
    t   asciiN(   t   decodet   Truet   UnicodeDecodeErrort   False(   t   text(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   is_ascii   s
    t   ClientSettingsDialogc           B   sa  e  Z d  Z d Z d Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d  „  Z# d! „  Z$ d" „  Z% RS(#   s°   
    L{ClientSettingsDialog} is a subclass of Gtk.Dialog that loads the UI
    components from the associated Glade XML file and wires everything up to
    the controller.
    s   landscape-client-settings.gladei    i   c         C   s‘   t  t |  ƒ j d t d ƒ d t j j ƒ |  j d ƒ |  j t	 ƒ t	 |  _
 t ƒ  |  _ g  |  _ | |  _ |  j ƒ  |  j ƒ  |  j j ƒ  d  S(   Nt   titles   Landscape Servicet   flagss   preferences-management-service(   t   superR   t   __init__t   _R   t   DialogFlagst   MODALt   set_default_icon_namet   set_resizableR   t   _initialisedt   sett   _validation_errorst   _errored_entriest
   controllert   setup_uit	   load_datat   revert(   t   selfR"   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyR   5   s    			

c         C   s-   | j  t j j t j ƒ |  j j | ƒ d S(   sb   
        Show a warning icon on a L{Gtk.Entry} to indicate some associated
        error.
        N(   t   set_icon_from_stockR   t   EntryIconPositiont   PRIMARYt   STOCK_DIALOG_WARNINGR!   t   append(   R&   t   entry(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   indicate_error_on_entryD   s    c         C   s   t  |  j j ƒ  ƒ } t | ƒ } t | ƒ } | rM | rM |  j j | ƒ t S|  j |  j ƒ | sy |  j j	 |  j
 ƒ n  | s• |  j j	 |  j ƒ n  t Sd  S(   N(   R   t   local_landscape_host_entryt   get_textR   R   t   set_textR   R-   R    t   addt   INVALID_HOST_NAMEt   UNICODE_IN_ENTRYR   (   R&   R   t   ascii_okt   host_name_ok(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt%   check_local_landscape_host_name_entryM   s    c         C   s>   t  | j ƒ  ƒ r t S|  j | ƒ |  j j |  j ƒ t Sd S(   sN   
        Check that the text content of a L{Gtk.Entry} is acceptable.
        N(   R   R/   R   R-   R    R1   R3   R   (   R&   R,   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   check_entry]   s
    c         C   sÔ   t  ƒ  |  _ |  j j ƒ  r+ |  j d  ƒ n  |  j j |  j j	 ƒ  ƒ } |  j j
 | d ƒ \ } | t k rn t S| t k r¨ |  j |  j ƒ } |  j |  j ƒ } | o§ | S|  j ƒ  } |  j |  j ƒ } | oÏ | Sd  S(   Ni    (   R   R    t   _info_bar_containert   get_visiblet   dismiss_infobarR   t	   liststoret   get_itert   use_type_comboboxt
   get_activet   getR   R   R   R7   t   hosted_account_name_entryt   hosted_password_entryR6   t   local_password_entry(   R&   t   active_itert   management_typet   account_name_okt   password_okR5   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   validity_checkh   s    	
c         C   s
   t  d ƒ S(   NR   (   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   NO_SERVICE_TEXTz   s    c         C   s
   t  d ƒ S(   Ns   Landscape - hosted by Canonical(   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   HOSTED_SERVICE_TEXT~   s    c         C   s
   t  d ƒ S(   Ns   Landscape - dedicated server(   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   LOCAL_SERVICE_TEXT‚   s    c         C   s
   t  d ƒ S(   Nt   Register(   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   REGISTER_BUTTON_TEXT†   s    c         C   s
   t  d ƒ S(   Nt   Disable(   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   DISABLE_BUTTON_TEXTŠ   s    c         C   s
   t  d ƒ S(   Ns   Invalid host name.(   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   INVALID_HOST_NAME_MESSAGEŽ   s    c         C   s
   t  d ƒ S(   Ns"   Only ASCII characters are allowed.(   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   UNICODE_IN_ENTRY_MESSAGE’   s    c         C   s‚   |  j  j ƒ  } x; |  j  j | d ƒ d |  j j k rL |  j  j | ƒ } q W|  j  j | ƒ } | j ƒ  \ } |  j j	 | ƒ d S(   s_  
        Load the persisted L{management_type} from the controller and set the
        combobox appropriately.

        Note that Gtk makes us jump through some hoops by having it's own model
        level to deal with here.  The conversion between paths and iters makes
        more sense if you understand that treeviews use the same model.
        i    N(
   R;   t   get_iter_firstR?   R"   RD   t	   iter_nextt   get_patht   get_indicesR=   t
   set_active(   R&   t	   list_itert   patht   index(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt&   _set_use_type_combobox_from_controller–   s    	c         C   s0   |  j  j |  j j ƒ |  j j |  j j ƒ d  S(   N(   R@   R0   R"   t   hosted_account_nameRA   t   hosted_password(   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt"   _set_hosted_values_from_controller§   s    	c         C   s0   |  j  j |  j j ƒ |  j j |  j j ƒ d  S(   N(   R.   R0   R"   t   local_landscape_hostRB   t   local_password(   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt!   _set_local_values_from_controller¬   s    	c         C   sA   t  |  _ |  j j ƒ  |  j ƒ  |  j ƒ  |  j ƒ  t |  _ d  S(   N(   R   R   R"   t   loadR\   R_   RY   R   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyR$   ±   s    	


c         C   sš   t  j t j t j t j ƒ } d |  _ | j t |  j	 |  j
 j d ƒ g ƒ | j t |  j |  j
 j d ƒ g ƒ | j t |  j |  j
 j d ƒ g ƒ | S(   s  
        Construct the correct L{Gtk.ListStore} to drive the L{Gtk.ComboBox} for
        use-type.  This a table of:

           * Management type (key)
           * Text to display in the combobox
           * L{Gtk.Frame} to load when this item is selected.
        s   no-service-frames   hosted-service-frames   local-service-frameN(   R   t	   ListStoreR   t   TYPE_PYOBJECTt   TYPE_STRINGR   t   active_widgetR+   R   RH   t   _buildert
   get_objectR   RI   R   RJ   (   R&   R;   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   make_liststore¹   s    		c         C   s`   |  j  j d ƒ |  _ |  j j d |  j d ƒ |  j  j d ƒ |  _ |  j j d |  j d ƒ d  S(   Ns   hosted-account-name-entryt   changedRZ   s   hosted-password-entryR[   (   Re   Rf   R@   t   connectt   on_changed_eventRA   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   link_hosted_service_widgetsÎ   s    				c         C   s`   |  j  j d ƒ |  _ |  j j d |  j d ƒ |  j  j d ƒ |  _ |  j j d |  j d ƒ d  S(   Ns   local-landscape-host-entryRh   R]   s   local-password-entryR^   (   Re   Rf   R.   Ri   Rj   RB   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   link_local_service_widgetsÙ   s    				c         C   st   |  j  j d ƒ |  _ |  j j d |  j ƒ |  j j | ƒ t j ƒ  } |  j j | t	 ƒ |  j j
 | d d ƒ d  S(   Ns   use-type-comboboxRh   R   i   (   Re   Rf   R=   Ri   t   on_combo_changedt	   set_modelR   t   CellRendererTextt
   pack_startR   t   add_attribute(   R&   R;   t   cell(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   link_use_type_comboboxä   s    c         C   s   |  j  t j j ƒ d  S(   N(   t   responseR   t   ResponseTypet   CANCEL(   R&   t   widget(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   cancel_responseì   s    c         C   sœ   |  j  ƒ  r" |  j t j j ƒ nv g  } |  j |  j k rM | j |  j ƒ n  |  j	 |  j k rr | j |  j
 ƒ n  |  j j d j | ƒ ƒ |  j j ƒ  d  S(   Ns   
(   RG   Rt   R   Ru   t   OKR3   R    R+   RP   R2   RO   t   info_messageR0   t   joinR8   t   show(   R&   Rw   t
   error_text(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   register_responseï   s    c         C   sf   |  j  j ƒ  \ } | j ƒ  \ } | j ƒ  \ } } | t k rR | j |  j ƒ n | j |  j ƒ d  S(   N(   t   register_buttont   get_childrenR   R0   RN   RL   (   R&   RD   t	   alignmentt   hboxt   imaget   label(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   set_button_textû   s    c         C   s	  t  j d t  j ƒ |  _ |  j j |  j t t d ƒ |  j j d |  j ƒ |  j j	 ƒ  t  j d t  j
 ƒ |  _ |  j j |  j t t d ƒ |  j j	 ƒ  |  j j d |  j ƒ t  j d t  j ƒ |  _ |  j j |  j t t d ƒ |  j j	 ƒ  |  j j d |  j ƒ d  S(   Nt   stocki    t   clicked(   R   t   Buttont   STOCK_REVERT_TO_SAVEDt   revert_buttont   action_areaRp   R   Ri   R%   R|   t   STOCK_CANCELt   cancel_buttonRx   t   STOCK_OKR   R~   (   R&   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   setup_buttons  s    c         C   sD   |  j  j ƒ  x' |  j D] } | j t j j d  ƒ q Wg  |  _ d  S(   N(   R8   t   hideR!   R'   R   R(   R)   R   (   R&   Rw   R,   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyR:     s    c         C   sÈ  |  j  j d ƒ } |  j  j d ƒ } | j t ƒ | j t ƒ t j ƒ  |  _ |  j j d ƒ t j ƒ  } | j	 | ƒ | j
 ƒ  t j ƒ  } | j	 | ƒ | j
 ƒ  |  j j | d t d t d d ƒ|  j j | d t d t d d ƒ| j ƒ  } t j ƒ  } t j ƒ  |  _ |  j j d d ƒ |  j j
 ƒ  | j |  j d t d t d d	 ƒt j d
 ƒ } | j d |  j ƒ | j
 ƒ  | j | d t d t d d ƒ| j
 ƒ  | j | d t d t d d ƒd  S(   Ns   labels-sizegroups   entries-sizegroupi   t   expandt   fillt   paddingi    g      à?i   t   DismissR‡   (   Re   Rf   t   set_ignore_hiddenR   R   t   HBoxR8   t   set_spacingt   InfoBart
   add_widgetR|   t   LabelRp   t   get_content_areaRz   t   set_alignmentR   Rˆ   Ri   R:   (   R&   t   labels_size_groupt   entries_size_groupt   info_bart   empty_labelt   content_areaR‚   t	   ok_button(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   setup_info_bar  s8    

"

c         C   s*  t  j ƒ  |  _ |  j j d ƒ |  j j t j j t j j t	 ƒ d |  j
 ƒ ƒ |  j ƒ  } | j d ƒ |  j d ƒ |  j ƒ  |  j j d ƒ |  _ |  j j ƒ  | j |  j d t d t d d ƒ|  j j |  j d t d t d d ƒ|  j ƒ  |  _ |  j |  j ƒ |  j ƒ  |  j ƒ  |  j ƒ  d  S(	   Ns   landscape-clientt   uii   s   toplevel-vboxR‘   R’   R“   i    (   R   t   BuilderRe   t   set_translation_domaint   add_from_filet   osRW   R{   t   dirnamet   __file__t
   GLADE_FILER›   R—   t   set_border_widthR£   Rf   t   _vboxt   unparentRp   R   R8   R   Rg   R;   Rs   Rk   Rl   R   (   R&   R¡   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyR#   6  s(    		


c         C   sÆ   |  j  j | j ƒ  ƒ } |  j d  k	 r= |  j j |  j ƒ n  |  j  j | d ƒ \ } |  j | ƒ |  j	 r‡ | |  j
 _ |  j
 j ƒ  n  |  j  j | d ƒ \ |  _ |  j j ƒ  |  j j |  j ƒ d  S(   Ni    i   (   R;   R<   R>   Rd   R   R­   t   removeR?   R…   R   R"   RD   t   modifyR®   R1   (   R&   t   comboboxRV   RD   (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyRm   L  s    	c         C   s*   t  |  j | | j ƒ  ƒ |  j j ƒ  d  S(   N(   t   setattrR"   R/   R°   (   R&   Rw   t	   attribute(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyRj   Y  s    c         G   s   |  j  ƒ  d  S(   N(   t   destroy(   R&   t   args(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   quit]  s    c         C   s(   |  j  j ƒ  |  j ƒ  |  j  j ƒ  d  S(   N(   R"   R%   R$   (   R&   t   button(    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyR%   `  s    
(&   t   __name__t
   __module__t   __doc__R«   R2   R3   R   R-   R6   R7   RG   t   propertyRH   RI   RJ   RL   RN   RO   RP   RY   R\   R_   R$   Rg   Rk   Rl   Rs   Rx   R~   R…   R   R:   R£   R#   Rm   Rj   R¶   R%   (    (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyR   *   sF   																									(   t   reR¨   R    R   t   gi.repositoryR   R   t   landscape.ui.constantsR   R   R   t   compileR	   R   R   R   t   DialogR   (    (    (    sC   /usr/lib/python2.7/dist-packages/landscape/ui/view/configuration.pyt   <module>   s   			