
    Vh$                     z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZ  G d de
      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona
  
module: xfconf
author:
  - "Joseph Benden (@jbenden)"
  - "Alexei Znamensky (@russoz)"
short_description: Edit XFCE4 Configurations
description:
  - This module allows for the manipulation of Xfce 4 Configuration with the help of C(xfconf-query).
seealso:
  - name: xfconf-query(1) man page
    description: Manual page of the C(xfconf-query) tool at the XFCE documentation site.
    link: 'https://docs.xfce.org/xfce/xfconf/xfconf-query'

  - name: xfconf - Configuration Storage System
    description: XFCE documentation for the Xfconf configuration system.
    link: 'https://docs.xfce.org/xfce/xfconf/start'

extends_documentation_fragment:
  - community.general.attributes

attributes:
  check_mode:
    support: full
  diff_mode:
    support: full

options:
  channel:
    description:
      - A Xfconf preference channel is a top-level tree key, inside of the Xfconf repository that corresponds to the location
        for which all application properties/keys are stored. See man xfconf-query(1).
    required: true
    type: str
  property:
    description:
      - A Xfce preference key is an element in the Xfconf repository that corresponds to an application preference. See man
        xfconf-query(1).
    required: true
    type: str
  value:
    description:
      - Preference properties typically have simple values such as strings, integers, or lists of strings and integers. See
        man xfconf-query(1).
    type: list
    elements: raw
  value_type:
    description:
      - The type of value being set.
      - When providing more than one O(value_type), the length of the list must be equal to the length of O(value).
      - If only one O(value_type) is provided, but O(value) contains more than on element, that O(value_type) is applied to
        all elements of O(value).
      - If the O(property) being set is an array and it can possibly have only one element in the array, then O(force_array=true)
        must be used to ensure that C(xfconf-query) interprets the value as an array rather than a scalar.
      - Support for V(uchar), V(char), V(uint64), and V(int64) has been added in community.general 4.8.0.
    type: list
    elements: str
    choices: [string, int, double, bool, uint, uchar, char, uint64, int64, float]
  state:
    type: str
    description:
      - The action to take upon the property/value.
      - The state V(get) has been removed in community.general 5.0.0. Please use the module M(community.general.xfconf_info)
        instead.
    choices: [present, absent]
    default: "present"
  force_array:
    description:
      - Force array even if only one element.
    type: bool
    default: false
    aliases: ['array']
    version_added: 1.0.0
a  
- name: Change the DPI to "192"
  xfconf:
    channel: "xsettings"
    property: "/Xft/DPI"
    value_type: "int"
    value: "192"

- name: Set workspace names (4)
  xfconf:
    channel: xfwm4
    property: /general/workspace_names
    value_type: string
    value: ['Main', 'Work1', 'Work2', 'Tmp']

- name: Set workspace names (1)
  xfconf:
    channel: xfwm4
    property: /general/workspace_names
    value_type: string
    value: ['Main']
    force_array: true
ar  
channel:
  description: The channel specified in the module parameters.
  returned: success
  type: str
  sample: "xsettings"
property:
  description: The property specified in the module parameters.
  returned: success
  type: str
  sample: "/Xft/DPI"
value_type:
  description:
    - The type of the value that was changed (V(none) for O(state=reset)). Either a single string value or a list of strings
      for array types.
    - This is a string or a list of strings.
  returned: success
  type: any
  sample: '"int" or ["str", "str", "str"]'
value:
  description:
    - The value of the preference key after executing the module. Either a single string value or a list of strings for array
      types.
    - This is a string or a list of strings.
  returned: success
  type: any
  sample: "'192' or ['orange', 'yellow', 'violet']"
previous_value:
  description:
    - The value of the preference key before executing the module. Either a single string value or a list of strings for array
      types.
    - This is a string or a list of strings.
  returned: success
  type: any
  sample: '"96" or ["red", "blue", "green"]'
cmd:
  description:
    - A list with the resulting C(xfconf-query) command executed by the module.
  returned: success
  type: list
  elements: str
  version_added: 5.4.0
  sample:
    - /usr/bin/xfconf-query
    - --channel
    - xfce4-panel
    - --property
    - /plugins/plugin-19/timezone
    - --create
    - --type
    - string
    - --set
    - Pacific/Auckland
version:
  description:
    - The version of the C(xfconf-query) command.
  returned: success
  type: str
  sample: 4.18.1
  version_added: 10.2.0
)StateModuleHelper)xfconf_runnerget_xfconf_versionc                       e Zd ZdZdZdZ e e eddd       edd       edd       ed	dd
       ed	d       edddg            ddddgfgdgd      ZdZdZ	d Z
d Zd Zd Zd Zy)XFConfProperty)value)propertychannelr   str)presentabsentr   )typechoicesdefaultT)r   requiredlist)
stringintdoublebooluintucharcharuint64int64float)r   elementsr   raw)r   r    r   Farray)r   r   aliases)stater   r   
value_typer   force_arrayr$   r   r%   )r   r%   )argument_specrequired_ifrequired_togethersupports_check_modec                    t        | j                        | _        t        | j                        | j                  _        dj                  | j                  j                  | j                  j                        | _	        | j                  j                  d| j                                | j                  j                  d| j                  j                         | j                  j                  d| j                  j                         y )Nz/Property "{0}" does not exist on channel "{1}".previous_valuer   r   )initial_value)r   modulerunnerr   varsversionformatr   r   does_notset_getr%   set_metar,   )selfs    l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/xfconf.py__init_module__zXFConfProperty.__init_module__   s    #DKK0.t{{;		IPPQUQZQZQcQceienenevevw		&		4		fdii223		7$))2J2JK    c                 ,   |j                         | j                  k(  ry |st        |      r!| j                  dj	                  ||             |j                         }d|v r3|j                  d      }|j                  d       |j                  d       |S )Nz,xfconf-query failed with error (rc={0}): {1}zValue is an array with
r   )rstripr3   lendo_raiser2   splitpop)r7   rcouterrresults        r8   process_command_outputz%XFConfProperty.process_command_output   sx    ::<4==(SMMHOOPRTWXY#v-\\$'FJJqMJJqMr:   c                     | j                  d| j                        5 }|j                         cd d d        S # 1 sw Y   y xY w)Nzchannel property)output_process)r/   rF   runr7   ctxs     r8   r5   zXFConfProperty._get   s:    [[+D<W<W[X 	\_779	 	 	s	   8Ac                    | j                  dd      5 }|j                  d       |j                  | j                  _        |j
                  | j                  _        |j                  | j                  _        | j                  j                  d|j                  d       d d d        d | j                  _
        y # 1 sw Y   xY w)Nzchannel property resetTcheck_mode_skip)resetrun_info   	verbosity)r/   rI   results_outr0   stdoutresults_errstderrcmdr4   rP   r   rJ   s     r8   state_absentzXFConfProperty.state_absent   s    [[14[H 	ACGG$G"DII"DIIGGDIIMIIMM*cllaM@	A 			A 	As   BB::Cc                    | j                   j                  D cg c]  }t        |       c}| j                   _        | j                   j                  }t	        | j                   j                        }t	        |      }|dk(  r||z  }n||k7  r| j                  d       t        | j                   j                        xs+ t        | j                   j                  t              xs |dkD  | j                   _        | j                  dd      5 }|j                  d| j                   j                  | j                   j                  |f       |j                  | j                   _        |j                   | j                   _        |j$                  | j                   _        | j                   j'                  d|j(                  d	       d d d        | j                   j                  s=| j                   j                  d
   | j                   _        |d
   | j                   _        y || j                   _        y c c}w # 1 sw Y   sxY w)N   z?Number of elements in "value" and "value_type" must be the samez4channel property create force_array values_and_typesTrM   )creater&   values_and_typesrP   rQ   rR   r   )r0   r   r   r%   r>   r?   r   r&   
isinstancer,   r   is_arrayr/   rI   rT   rU   rV   rW   rX   r4   rP   r   )r7   vr%   
values_len	types_lenrK   s         r8   state_presentzXFConfProperty.state_present   s    ,099??;a3q6;		YY))
)

O	>#j0J*$MM[\ &&' tyy//6N 			
 [[Oae[f 	AjmGG4TYY-?-?SWS\S\SbSbdnRoGp"DII"DIIGGDIIMIIMM*cllaM@	A yy!!"iiooa0DIIO']DIIN'DIIN= <&	A 	As   H1B8H66H?N)__name__
__module____qualname__change_paramsdiff_paramsoutput_paramsdictr.   use_old_vardictdefault_stater9   rF   r5   rY   rc    r:   r8   r
   r
      s    MK4ME+@)Ted3ut4%$|~FU3&%'K
 y7L*ABC23 F OML!(r:   r
   c                  ,    t         j                          y )N)r
   executerm   r:   r8   mainrp     s    r:   __main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNHansible_collections.community.general.plugins.module_utils.module_helperr   Aansible_collections.community.general.plugins.module_utils.xfconfr   r   r
   rp   rd   rm   r:   r8   <module>ry      s]    A @HT0<
| g oZ(& Z(z zF r:   