#!/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 ,
 )
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
 if iiI1111IIi1 :
  iII1II11iI1 = get_hive_translated_string ( ooOOooO0 , "/profiles/introduction" , "" )
  if iII1II11iI1 :
   iII1II11iI1 = iII1II11iI1 . replace ( "\\n" , "\n" )
   OOO . set_intro ( iII1II11iI1 )
   if 88 - 88: I1I * Ooo0Ooo + i1iiIII111 . i1iiIII111 % Oo * oOo0O00
 if O0000OooOoo00 :
  if 65 - 65: Ooo0Ooo * ooo000 + oOo0O00
  if 71 - 71: Ooo0Ooo / ooo000
  if 87 - 87: iI / oOo0O00 % ooo0O0oO00 - oOo0O00 . I1I + Ooo0Ooo
  OO0o0O0o0 = OOO . run ( only_intro = True )
  if OO0o0O0o0 is None :
   print ( "%s: User aborted introduction display" % sys . argv [ 0 ] , file = sys . stderr )
   sys . exit ( 1 )
   if 11 - 11: iI % i1i1i1111I + i1
   if 87 - 87: I1I / Iii1i / Ii
  sys . exit ( 0 )
  if 32 - 32: i1i1i1111I % Ooo0Ooo - o00o0OO00O * I1I
 if len ( iiIII ) == 0 :
  if 92 - 92: IIiIIiIi11I1 - i1 - Iii1i / Ooo0Ooo . I1Ii1I1 / iIiii1i
  if 60 - 60: ooo0O0oO00
  iiI1111II = "%s: Error: no available ThinLinc profiles: " % sys . argv [ 0 ]
  if 79 - 79: Ooo0Ooo % iI1iII1I1I1i % IIiIIiIi11I1 / ooOOO - ooOOO / iIiii1i
  oOo0Oo = find_matching_profiles ( ooOOooO0 )
  O0ooooO = get_wayland_session_desktop_files ( )
  if 89 - 89: I1I * i1i1i1111I
  O0OOooO = ""
  oOOoOOOO000 = ""
  IIIIi = ""
  O0O0oOo00oO0 = "https://www.cendio.com/resources/docs/tag/profiles.html"
  if 73 - 73: i1i1i1111I . Ooo0Ooo * iI1iII1I1I1i / Ii / ooo000 + i1iiIII111
  if not oOo0Oo :
   if 28 - 28: i1iiIII111 + ooOOO - ooOOO - i1i1i1111I
   if not O0ooooO :
    iiI1111II += ( "no desktop environments are installed" )
    if 61 - 61: ooo0O0oO00
    O0OOooO = iI111iiIi11i ( "No desktop environments installed" )
    oOOoOOOO000 = iI111iiIi11i (
 "There are no installed desktop environments — contact "
 "your system administrator!\n\n"
 "<b>Recommended solution</b>\n"
 "Install a desktop environment, for example GNOME, "
 "KDE, XFCE or MATE. Preconfigured ThinLinc profiles are "
 "available for the most common desktops. Note that an "
 "X11-type desktop environment is required."
 )
    O0O0oOo00oO0 += "#no-desktop-environments-installed"
   else :
    iiI1111II += (
 "only Wayland desktop environments are installed"
 )
    if 7 - 7: i1i1i1111I / Ii * Iii1i
    O0OOooO = iI111iiIi11i ( "No X11 desktop environments installed" )
    oOOoOOOO000 = iI111iiIi11i (
 "Only Wayland-type desktops are installed on this system "
 "— ThinLinc requires an X11-type desktop environment. "
 "Contact your system administrator!\n\n"
 "<b>Recommended solution</b>\n"
 "Install the X11 version of a desktop environment. "
 "Preconfigured ThinLinc profiles are available for the "
 "most common desktops."
 )
    O0O0oOo00oO0 += "#no-x11-desktop-environments-installed"
    if 32 - 32: iI . OooOoo
  else :
   i1i1iI1II = { profile for iIi1 in oOo0Oo . values ( ) for profile in iIi1 }
   if 4 - 4: ooo000 % I1I - i1i1i1111I
   if 76 - 76: i1 * oOo0O00 . iI * o00o0OO00O . IiIIii11Ii . ooo0O0oO00
   if 55 - 55: i1i1i1111I + i1iiIII111 % Ooo0Ooo . Oo - IiIIii11Ii - iI1iII1I1I1i
   if not i1i1iI1II :
    iiI1111II += (
 "missing configured profiles for installed desktop "
 "environments:\n  "
 )
    iiI1111II += '\n  ' . join ( sorted ( oOo0Oo ) )
    if 91 - 91: I1Ii1I1 - iIiii1i
    O0OOooO = iI111iiIi11i ( "Missing ThinLinc profile configuration" )
    oOOoOOOO000 = iI111iiIi11i (
 "There are no configured profiles matching currently "
 "installed desktop environments — contact your system "
 "administrator!\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"
 "There are %d installed X11 desktop environment(s), with "
 "session file(s) located at:"
 ) % len ( oOo0Oo )
    if 84 - 84: ooo0O0oO00 % iI1iII1I1I1i - Ooo0Ooo
    IIIIi = '\n' . join ( sorted ( oOo0Oo ) )
    O0O0oOo00oO0 += "#missing-thinlinc-profile-configuration"
    if 94 - 94: i1iiIII111 + i1i1i1111I / iI1iII1I1I1i + iI1iII1I1I1i / o00o0OO00O
   else :
    iiI1111II += (
 "configured profiles mapping to installed desktop "
 "environments are unavailable:\n  "
 )
    OO = [ ]
    for ooOOOO00O , iIi1 in oOo0Oo . items ( ) :
     if iIi1 :
      OO . append ( '%s : %s' % ( ooOOOO00O , ', ' . join ( iIi1 ) ) )
    iiI1111II += '\n  ' . join ( OO )
    if 72 - 72: iIiii1i
    O0OOooO = iI111iiIi11i ( "No available ThinLinc profiles" )
    oOOoOOOO000 = iI111iiIi11i (
 "There are no available profiles for this user — contact "
 "your system administrator!\n\n"
 "<b>Recommended solution</b>\n"
 "Verify that the correct ThinLinc profiles are "
 "activated. There are profiles matching currently "
 "installed desktop environments, but none are available "
 "for this user."
 )
    O0O0oOo00oO0 += "#no-available-thinlinc-profiles"
    if 25 - 25: i1
  Oo0O00OOoo = iI111iiIi11i ( "See %s for more information about the error." ) % O0O0oOo00oO0
  Oo0O00OOoo = tlgtk . linkify_text (
 Oo0O00OOoo , [ iI111iiIi11i ( "ThinLinc administrator's guide" ) ]
 )
  if 38 - 38: i1 - oOo0O00
  O0OO00OO0O = ( { 'text' : oOOoOOOO000 , 'justify' : tlgtk . Gtk . Justification . CENTER } ,
 { 'text' : IIIIi , 'justify' : tlgtk . Gtk . Justification . LEFT ,
 'scroll' : True } ,
 { 'text' : Oo0O00OOoo , 'justify' : tlgtk . Gtk . Justification . CENTER } )
  OOO . set_error ( O0OO00OO0O , O0OOooO )
  OOO . run ( )
  print ( iiI1111II , file = sys . stderr )
  sys . exit ( 1 )
  if 35 - 35: i1 + I1I . i1iiIII111
 ii1II = ooOOooO0 . get_string ( "/profiles/default" )
 for oOoOo in iiIII :
  OOO . add_entry ( oOoOo [ "tag" ] , oOoOo [ "name" ] ,
 oOoOo [ "description" ] , oOoOo [ "icon" ] ,
 oOoOo [ "screenshot" ] ,
 default = ( oOoOo [ 'tag' ] == ii1II ) )
  if 39 - 39: ooo0O0oO00
 OO0o0O0o0 = OOO . run ( )
 if 17 - 17: Ii . oOo0O00 % OooOoo
 if OO0o0O0o0 is None :
  print ( "%s: User aborted profile selection" % sys . argv [ 0 ] , file = sys . stderr )
  sys . exit ( 1 )
  if 82 - 82: Iii1i . oOo0O00 % IIiIIiIi11I1 - iI1iII1I1I1i
 print ( OO0o0O0o0 )
 sys . exit ( 0 )
 if 44 - 44: ooOOO . IIiIIiIi11I1
if __name__ == "__main__" :
 oOooo0OOO ( )
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
