#!/opt/thinlinc/libexec/python3
# -*- mode: python; coding: utf-8 -*-
#
# Copyright 2008-2020 Cendio AB.
# For more information, see http://www.cendio.com
if 82 - 82: Iii1i
import sys
import os
import locale
import gettext
if 87 - 87: Ii % i1i1i1111I . Oo / OooOoo * I1Ii1I1 - I1I
from thinlinc import hiveconf
if 81 - 81: i1 + ooOOO / oOo0O00 * i1iiIII111 * IiIIii11Ii
from thinlinc import prefix
from thinlinc import tlgtk
from thinlinc . profiles import (
 get_profiles ,
 get_hive_translated_string ,
 get_wayland_session_desktop_files ,
 find_matching_profiles ,
 get_preference ,
 remove_preference ,
 decode_preference ,
 )
from thinlinc . profiles . chooser import ProfileChooser
if 84 - 84: ooo000 - Ooo0Ooo + iI1iII1I1I1i . IIiIIiIi11I1
iI111iiIi11i = None
if 77 - 77: iIiii1i - ooo0O0oO00 . o00o0OO00O
def Ooo ( ) :
 global iI111iiIi11i
 if iI111iiIi11i is None :
  I1 = os . path . join ( prefix . get_tl_prefix ( ) , "share" , "locale" )
  ii = gettext . translation ( "tl-misc" , I1 , fallback = True )
  iI111iiIi11i = ii . gettext
  if 91 - 91: iI . iIiii1i . ooOOO / IIiIIiIi11I1 * ooo0O0oO00 / OooOoo
def oOooo0OOO ( ) :
 locale . setlocale ( locale . LC_ALL , "" )
 if 53 - 53: Ii * Oo * ooo000 . i1iiIII111
 Ooo ( )
 if 14 - 14: I1I / ooo0O0oO00
 ooOOooO0 = hiveconf . open_hive ( os . path . join ( prefix . get_tl_prefix ( ) ,
 "etc" , "thinlinc.hconf" ) )
 if 13 - 13: ooo0O0oO00
 iiIII = get_profiles ( ooOOooO0 , run_testcmd = True )
 if 28 - 28: I1Ii1I1 . Iii1i - ooOOO - iI1iII1I1I1i
 O0000OooOoo00 = False
 if 70 - 70: i1iiIII111
 if "TLCOMMAND" in os . environ :
  if 8 - 8: o00o0OO00O
  if 62 - 62: I1Ii1I1 % iIiii1i . I1Ii1I1 . iI . i1i1i1111I
  if not os . getenv ( "TLCOMMAND" ) . strip ( ) :
   print ( "%s: Ignoring existing but empty TLCOMMAND." % ( sys . argv [ 0 ] ) , file = sys . stderr )
  else :
   O0000OooOoo00 = True
   if 87 - 87: Oo - o00o0OO00O
 iiI1111IIi1 = ooOOooO0 . get_bool ( "/profiles/show_intro" , True )
 if 92 - 92: ooOOO / OooOoo - oOo0O00
 if 59 - 59: Iii1i . iI - o00o0OO00O
 if 13 - 13: ooo0O0oO00
 if O0000OooOoo00 and not iiI1111IIi1 :
  sys . exit ( 0 )
  if 28 - 28: OooOoo + i1i1i1111I + IiIIii11Ii / I1Ii1I1 + iI1iII1I1I1i
  if 70 - 70: iI + iIiii1i * ooo0O0oO00 . Oo + ooOOO / Oo
  if 14 - 14: OooOoo % oOo0O00 + I1I % i1iiIII111 * ooOOO / iIiii1i
 if len ( iiIII ) == 1 and not iiI1111IIi1 :
  print ( iiIII [ 0 ] [ "tag" ] )
  sys . exit ( 0 )
  if 63 - 63: i1i1i1111I . Ooo0Ooo * ooOOO
 ii1Ii1I = tlgtk . init ( )
 if 71 - 71: ooo0O0oO00 - Oo . OooOoo . Ii % o00o0OO00O + ooo0O0oO00
 if 19 - 19: Ii / IiIIii11Ii + IiIIii11Ii . I1I
 if 88 - 88: Oo * IiIIii11Ii
 if 100 - 100: iI - OooOoo * I1Ii1I1 / Ooo0Ooo / Iii1i
 if not ii1Ii1I :
  print ( "%s: Warning: Unable initialize GTK+" % sys . argv [ 0 ] , file = sys . stderr )
  if iiI1111IIi1 :
   print ( "%s: Warning: Can't show introduction text" % sys . argv [ 0 ] , file = sys . stderr )
   if 23 - 23: Ooo0Ooo + i1 * I1Ii1I1 + Oo * Ii - IIiIIiIi11I1
  if O0000OooOoo00 :
   sys . exit ( 0 )
  elif len ( iiIII ) > 0 :
   print ( "%s: Warning: Using first available profile as fallback" % sys . argv [ 0 ] , file = sys . stderr )
   print ( iiIII [ 0 ] [ "tag" ] )
   sys . exit ( 0 )
  else :
   print ( "%s: Error: No available ThinLinc profiles. Exiting..." % sys . argv [ 0 ] , file = sys . stderr )
   sys . exit ( 1 )
   if 29 - 29: IiIIii11Ii - oOo0O00
   if 30 - 30: I1I . ooo000
 OOO = ProfileChooser ( )
 if 83 - 83: ooo0O0oO00 - Iii1i + ooOOO . o00o0OO00O / ooOOO
 iII1II11iI1 = get_hive_translated_string ( ooOOooO0 , "/profiles/greeting" )
 if iII1II11iI1 :
  OOO . set_greeting ( iII1II11iI1 )
  if 25 - 25: Ooo0Ooo . iIiii1i . ooo0O0oO00
 Ii1I1I1i = get_hive_translated_string ( ooOOooO0 , "/profiles/introduction" , "" )
 if iiI1111IIi1 and Ii1I1I1i :
  Ii1I1I1i = Ii1I1I1i . replace ( "\\n" , "\n" )
  if 93 - 93: oOo0O00 % Ooo0Ooo * i1iiIII111
  OooO0O00o0 = ooOOooO0 . get_bool ( "/profiles/force_intro" , False )
  OOO . hide_intro_checkbox ( OooO0O00o0 )
  if 73 - 73: ooo0O0oO00 - oOo0O00 . oOo0O00
  I11IIII1i1I = None
  try :
   I11IIII1i1I = get_preference ( 'PROFILE_CHOOSER' , 'DISABLED_INTRO' )
  except Exception as i1111I :
   print ( "%s: Warning: unable to read disabled intro preference: %s" % ( sys . argv [ 0 ] , i1111I ) , file = sys . stderr )
   if 12 - 12: oOo0O00 * i1
  if I11IIII1i1I :
   I11IIII1i1I = decode_preference ( I11IIII1i1I )
   if OooO0O00o0 or I11IIII1i1I != Ii1I1I1i :
    if 26 - 26: Ii . i1
    try :
     remove_preference ( 'PROFILE_CHOOSER' , 'DISABLED_INTRO' )
    except Exception as i1111I :
     print ( "%s: Warning: unable to remove disabled intro preference: %s" % ( sys . argv [ 0 ] , i1111I ) , file = sys . stderr )
     if 61 - 61: iI1iII1I1I1i . o00o0OO00O - ooo000 / ooo000 - i1
     if 19 - 19: Iii1i * Ooo0Ooo . I1Ii1I1 / iIiii1i * Ii - ooo0O0oO00
  if OooO0O00o0 or I11IIII1i1I != Ii1I1I1i :
   OOO . set_intro ( Ii1I1I1i )
   if 32 - 32: iI1iII1I1I1i
 if O0000OooOoo00 :
  if 18 - 18: iIiii1i * iI % iI1iII1I1I1i + iI
  if 93 - 93: ooo0O0oO00 - I1Ii1I1 - IIiIIiIi11I1 * ooOOO - i1
  if 82 - 82: IIiIIiIi11I1 % i1 * ooOOO
  oOoOOO0ooooO0 = OOO . run ( only_intro = True )
  if oOoOOO0ooooO0 is None :
   print ( "%s: User aborted introduction display" % sys . argv [ 0 ] , file = sys . stderr )
   sys . exit ( 1 )
   if 20 - 20: i1i1i1111I / Ooo0Ooo - ooo0O0oO00 + Ooo0Ooo - I1I . Ooo0Ooo
   if 50 - 50: Iii1i * ooo000 % Iii1i - oOo0O00 + ooo000
  sys . exit ( 0 )
  if 54 - 54: ooo0O0oO00 * i1 % i1 - Ooo0Ooo + IIiIIiIi11I1
 if len ( iiIII ) == 0 :
  if 4 - 4: ooo000 + I1Ii1I1 * OooOoo - iI
  if 69 - 69: ooo000
  iIiIiiIIIiII = "%s: Error: no available ThinLinc profiles: " % sys . argv [ 0 ]
  if 44 - 44: Ooo0Ooo + i1i1i1111I + Iii1i - ooo0O0oO00
  I1i1i = find_matching_profiles ( ooOOooO0 )
  ii1ii = get_wayland_session_desktop_files ( )
  if 17 - 17: Oo * I1I % ooOOO - IiIIii11Ii
  iIi1 = ""
  I1II1ii111i = iI111iiIi11i ( "ThinLinc could not start a desktop session — contact "
 "your system administrator!" )
  I1i1iI1I1Ii1 = ""
  oOoOO0O0 = ""
  I111 = "https://www.cendio.com/resources/docs/tag/profiles.html"
  if 35 - 35: IIiIIiIi11I1 % Ooo0Ooo - o00o0OO00O * i1iiIII111 + i1
  if not I1i1i :
   if 12 - 12: i1 - o00o0OO00O - iI
   if not ii1ii :
    iIiIiiIIIiII += ( "no desktop environments are installed" )
    iIi1 = iI111iiIi11i ( "No desktop environments installed" )
    I1i1iI1I1Ii1 = iI111iiIi11i (
 "<b>Problem</b>\n"
 "There are no desktop environments installed on this "
 "system.\n\n"
 "<b>Recommended solution</b>\n"
 "Install a desktop environment, for example GNOME, KDE, "
 "XFCE or MATE. Note that an X11-type desktop environment "
 "is required. Also note that preconfigured ThinLinc "
 "profiles are available for the most common desktops."
 )
    I111 += "#no-desktop-environments-installed"
   else :
    iIiIiiIIIiII += (
 "only Wayland desktop environments are installed"
 )
    iIi1 = iI111iiIi11i ( "No X11 desktop environments installed" )
    I1i1iI1I1Ii1 = iI111iiIi11i (
 "<b>Problem</b>\n"
 "Only Wayland-type desktops are installed on this system "
 "— ThinLinc requires an X11-type desktop environment.\n\n"
 "<b>Recommended solution</b>\n"
 "Install the X11 version of a desktop environment. "
 "Note that preconfigured ThinLinc profiles are available "
 "for the most common desktops."
 )
    I111 += "#no-x11-desktop-environments-installed"
    if 86 - 86: Iii1i + i1iiIII111 - IIiIIiIi11I1 / I1I
  else :
   OO00O0o = { profile for i1II1 in I1i1i . values ( ) for profile in i1II1 }
   if 98 - 98: IIiIIiIi11I1 * IIiIIiIi11I1
   if 58 - 58: i1i1i1111I
   if 38 - 38: i1 - oOo0O00
   if not OO00O0o :
    iIiIiiIIIiII += (
 "missing configured profiles for installed desktop "
 "environments:\n  "
 )
    iIiIiiIIIiII += '\n  ' . join ( sorted ( I1i1i ) )
    iIi1 = iI111iiIi11i ( "Missing ThinLinc profile configuration" )
    I1i1iI1I1Ii1 = iI111iiIi11i (
 "<b>Problem</b>\n"
 "There are no configured ThinLinc profiles matching "
 "currently installed desktop environments.\n\n"
 "<b>Recommended solutions</b>\n"
 "→ Install a different desktop environment, like GNOME, "
 "KDE, XFCE or MATE.\n"
 "→ If no profile exists for the wanted desktop, create a "
 "new ThinLinc profile.\n\n"
 "Note that there are %d installed X11 desktop "
 "environment(s), with session file(s) located at:"
 ) % len ( I1i1i )
    if 85 - 85: IIiIIiIi11I1 + iIiii1i % Ooo0Ooo + ooo0O0oO00 * i1iiIII111
    oOoOO0O0 = '\n' . join ( sorted ( I1i1i ) )
    I111 += "#missing-thinlinc-profile-configuration"
    if 46 - 46: ooOOO - ooOOO + Oo / I1I * Oo + ooo0O0oO00
   else :
    iIiIiiIIIiII += (
 "configured profiles mapping to installed desktop "
 "environments are unavailable:\n  "
 )
    i1II1oOoOo = [ ]
    for o0oOoo0O0o0Oo , i1II1 in I1i1i . items ( ) :
     if i1II1 :
      i1II1oOoOo . append ( '%s : %s' % ( o0oOoo0O0o0Oo , ', ' . join ( i1II1 ) ) )
    iIiIiiIIIiII += '\n  ' . join ( i1II1oOoOo )
    iIi1 = iI111iiIi11i ( "No available ThinLinc profiles" )
    I1i1iI1I1Ii1 = iI111iiIi11i (
 "<b>Problem</b>\n"
 "There are no available ThinLinc profiles for this user.\n\n"
 "<b>Recommended solution</b>\n"
 "Verify that the correct ThinLinc profiles are activated. "
 "Note that there are profiles matching currently installed "
 "desktop environments, but none are available for this user."
 )
    I111 += "#no-available-thinlinc-profiles"
    if 2 - 2: IIiIIiIi11I1 + iI1iII1I1I1i - I1Ii1I1 + ooOOO . IIiIIiIi11I1
  iIi111ii = iI111iiIi11i ( "See %s for more information about the error." ) % I111
  iIi111ii = tlgtk . linkify_text (
 iIi111ii , [ iI111iiIi11i ( "ThinLinc administrator's guide" ) ]
 )
  if 20 - 20: i1i1i1111I + Oo / Ooo0Ooo % iI % iI
  III1II11i = ( { 'text' : I1II1ii111i } ,
 { 'text' : I1i1iI1I1Ii1 ,
 'justify' : tlgtk . Gtk . Justification . LEFT ,
 'xalign' : 0 ,
 'expander' : True } ,
 { 'text' : oOoOO0O0 ,
 'scroll' : True ,
 'expander' : True } ,
 { 'text' : iIi111ii ,
 'justify' : tlgtk . Gtk . Justification . LEFT ,
 'xalign' : 0 ,
 'expander' : True } ,
 )
  OOO . set_error ( III1II11i , iIi1 )
  OOO . run ( )
  print ( iIiIiiIIIiII , file = sys . stderr )
  sys . exit ( 1 )
  if 79 - 79: I1I . I1I * i1i1i1111I + i1 / ooo0O0oO00 / i1i1i1111I
 iI11IIii = ooOOooO0 . get_string ( "/profiles/default" )
 for OOo0oO000oOo0 in iiIII :
  OOO . add_entry ( OOo0oO000oOo0 [ "tag" ] , OOo0oO000oOo0 [ "name" ] ,
 OOo0oO000oOo0 [ "description" ] , OOo0oO000oOo0 [ "icon" ] ,
 OOo0oO000oOo0 [ "screenshot" ] ,
 default = ( OOo0oO000oOo0 [ 'tag' ] == iI11IIii ) )
  if 29 - 29: ooOOO / i1i1i1111I / I1Ii1I1 . iI + o00o0OO00O * oOo0O00
 oOoOOO0ooooO0 = OOO . run ( )
 if 57 - 57: iI1iII1I1I1i
 if oOoOOO0ooooO0 is None :
  print ( "%s: User aborted profile selection" % sys . argv [ 0 ] , file = sys . stderr )
  sys . exit ( 1 )
  if 89 - 89: ooo000 * iIiii1i + ooo0O0oO00
 print ( oOoOOO0ooooO0 )
 sys . exit ( 0 )
 if 64 - 64: iI . Ooo0Ooo . i1iiIII111 * iI
if __name__ == "__main__" :
 oOooo0OOO ( )
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
