#!/usr/bin/kaptain

# This version of the Kaptain OmegaT Launcher: 2015-01-19

start "OmegaT Launcher" -> omticon top bottom ;
  top :tabbed  -> locs mem connect services appearance about ;
  bottom :horizontal -> button_bar ;

omticon -> @icon("images/OmegaT.png") ;

### Locations tab

locs :framed :vertical "Locations" -> javaloc jarfileloc optloc ;


# Location of the Java runtime environment

javaloc "Java runtime environment" -> java_list |! java_pick ;
java_list :horizontal "System-wide Java installation" ->  @combow ("/usr/bin/java", `ls /usr/lib/jvm/*/jre/bin/java`) javaloc_help ;
java_pick :horizontal "Custom Java installation" -> @infile("java")="/opt/omegat/jre/bin/java" ;
javaloc_help :dialog "Help" -> javaloc_m javaloc_hc ;
javaloc_m :horizontal ->  javaloc_t ;
javaloc_t "The current default assumes that you have used the linux-install.sh\n
installation script and are using a local version of the JRE\n
(i.e. you have installed OmegaT with JRE).\n
If you want to use a system-wide version of Java, you can either select \n
\"System-wide Java installation\" (possibly choosing one of the versions \n
from drop-down menu), or replace \"/opt/omegat/jre/bin/java\" with \"java\"\n
(provided Java is in your execution path). If you are using a system-wide \n
version of Java that is NOT in your execution path,\n
replace \"/opt/omegat/jre/bin/java\" with the full path\n
of your java executable (in quotes) or browse and select it." -> @ ;
javaloc_hc :horizontal -> @close="Close";


# Location of the OmegaT.jar file (OmegaT version)
# To make a particular OmegaT.jar file the default, replace =""
# with ="<full path of OmegaT.jar file>"

jarfileloc :vertical "Location of OmegaT.jar" -> jarlist | ! jarpick ;
jarlist :horizontal "System-wide OmegaT installation" -> @combow(`find -L /opt/omegat -name "OmegaT.*jar"`) jarfileloc_help ;
jarpick :horizontal "Custom OmegaT installation"-> @infile("OmegaT.jar")="/opt/omegat/OmegaT-default/OmegaT.jar" @action(jvrs)="Ver.";
jarfileloc_help :dialog "Help" -> jarfileloc_m jarfileloc_hc ;
jarfileloc_m :horizontal ->  jarfileloc_t ;
jarfileloc_t "Location of the OmegaT program. This launcher defaults to the version\n
installed with \"linux-install.sh\". You may use the drop-down menu \n
to select one of OmegaT versions installed in /opt/omegat. You may also \n
choose another version by browsing to and selecting the respective OmegaT.jar" -> @ ;
jarfileloc_hc :horizontal -> @close="Close" ;

jvrs -> "cd `dirname " jarfileloc "` ; \
echo \"#!/usr/bin/kaptain\" > /tmp/otver.kaptn ;\
echo \"start \'\"Version\"\' -> ver button \;\" >> /tmp/otver.kaptn ;\
echo \"button :horizontal -> @close=\'\"Close\"\';\" >> /tmp/otver.kaptn ;\
echo \"ver \'\"$(grep -o -m1 \"OmegaT\\s*[\.0-9]*[0-9 a-z]*\" \.\/changes.txt)\"\' -> @ ;\" >> /tmp/otver.kaptn ;\
kaptain /tmp/otver.kaptn && rm /tmp/otver.kaptn" ;


# Optional file locations

optloc "Optional locations" -> configloc projectloc ;

# Specify non-default configuration files

configloc :horizontal "Directory containing non-default configuration files" -> @directory configloc_help ;
configloc_help :dialog "Help" -> configloc_m configloc_hc ;
configloc_m :horizontal ->  configloc_t ;
configloc_t "Use a different set of configuration files to those in your \nsystem. Useful for example if you wish to use a colleague's \nsegmentation rules rather than your own." -> @ ;
configloc_hc :horizontal -> @close="Close" ;

# Open a specific project at launch

projectloc :horizontal "Open specified project immediately" -> @combow("", `IFS=$(echo "\n\b") && for i in $(find $HOME -name "omegat.project" -type f); do echo "\"$(dirname $i)\""; done`) projectloc_help ;
projectloc_help :dialog "Help" -> projectloc_m projectloc_hc ;
projectloc_m :horizontal ->  projectloc_t ;
projectloc_t "Open a specific project immediately after launching OmegaT. \nUsualy superfluous in GUI mode." -> @ ;
projectloc_hc :horizontal -> @close="Close" ;

### Memory tab

mem :framed "Memory" -> memory ;

memory "Assign memory limit for OmegaT" -> defm | halfg | oneg | twog | memory_help ;
defm "Default" -> "" ;
halfg "512 MB" -> " -Xmx512M" ;
oneg "1 GB" -> " -Xmx1024M" ;
twog "2 GB" -> " -Xmx2048M" ;
memory_help :dialog "Help" -> memory_m memory_hc ;
memory_m :horizontal ->  memory_t ;
memory_t "Determine how much RAM OmegaT is allowed to make use of. \nToo low a value will make large projects slow or impossible to open; too high a value \nwill prevent OmegaT from launching." -> @ ;
memory_hc :horizontal -> @close="Close" ;


### Connectivity tab

connect :framed "Connectivity" -> proxy team ;

proxy "Proxy settings" -> proxyhost proxyport ;

# Enter proxy host IP address

proxyhost "IP address of your proxy server, if your system uses a proxy" -> @string ;

# Proxy Server Port Number

proxyport "Port number used by your system to access the proxy server" -> @string ;

# Team connectivity

team :vertical "Team connectivity for Team projects" -> !ton | toff | thelp ;
ton "Sync with the server" -> " " ;
toff "Disable sync" -> " --no-team" ;

thelp :dialog "Help" -> team_m team_hc ;
team_m :horizontal -> team_t ;
team_t "With this option it is possible to temporarily disable synchronization\nwith the server for Team projects. To re-enable synchronization OmegaT\nneeds to be restarted with the appropriate option." -> @ ;
team_hc :horizontal -> @close="Close" ;

### Services tab

services :framed "Online Services" -> gt ms mymem taas yand ;

# Google Translate API key

gt "Google Translate API key" -> @password="" gt_help ;

gt_help :dialog "Help" -> gt_m gt_hc ;
gt_m :horizontal ->  gt_t ;
gt_t "To use Google Translate within OmegaT, you must order \na password from Google and enter it here." -> @ ;
gt_hc :horizontal -> @close="Close";


# Microsoft Translator API key

ms "Microsoft Translator settings" -> msi msk ms_help ;
msi "Microsoft Translator API Client ID" -> @password="" ;
msk "Microsoft Translator API Secret Key" -> @password="" ;


ms_help :dialog "Help" -> ms_m ms_hc ;
ms_m :horizontal ->  ms_t ;
ms_t "To use Microsoft Translator within OmegaT, you must order \na client ID and a secret key from Microsoft Azure Marketplace \n(see https://datamarket.azure.com/dataset/bing/microsofttranslator) \nand enter them here." -> @ ;
ms_hc :horizontal -> @close="Close";

# MyMemory MT email address

mymem "MyMemory Machine Translation" -> mymem_em mymem_help ;
mymem_em "Valid email address" -> @string="" ;

mymem_help :dialog "Help" -> mymem_m mymem_hc ;
mymem_m :horizontal -> mymem_t ;
mymem_t "Provide your email address to be able to make \n1000 requests to MyMemory server a day \ninstead of 100" -> @ ;
mymem_hc :horizontal -> @close="Close" ;

# TaaS key

taas "TaaS user key" -> taas_k taas_help ;
taas_k "User key for TaaS" -> @password="" ;

taas_help :dialog "Help" -> taas_m taas_hc ;
taas_m :horizontal -> taas_t ;
taas_t "Enter API key to access your private collection from TaaS (terminology as a service) website" -> @ ;
taas_hc :horizontal -> @close="Close" ;

# Yandex Translate

yand "Yandex Translate API key" -> yand_k yand_help ;
yand_k "Yandex Translate API key" -> @password="" ;

yand_help :dialog "Help" -> yand_m yand_hc ;
yand_m :horizontal -> yand_t ;
yand_t "Enter your Yandex Translate API key. It can be requested at\nhttps://api.yandex.com/key/form.xml?service=trnsl" -> @ ;
yand_hc :horizontal -> @close="Close" ;


### Appearance settings tab

appearance :framed "GUI Settings" -> langs fontaa laf ;

# Selection of the user interface language
# Add language codes (that OmegaT has) or delete them.
# The first one on the list becomes the default

langs "Languages" -> UI ;

UI -> UIlang country languages_help ;

UIlang "User interface language (nn)" -> @combow("en", "ar", "be", "ca", "cs", "cy", "da", "de", "el", "eo", "es", "eu", "fr", "gl", "hu", "id", "it", "ja", "nl", "pl", "pt", "ru", "sh", "sk", "sl", "sq", "sv", "tr", "uk", "zh") ;

# Selection of the user country

country "User country (NN)" -> @string(2) ;

languages_help :dialog "Help" -> languages_m languages_hc ;
languages_m :horizontal ->  languages_t ;
languages_t "Select the language of OmegaT's user interface. If no language \nis specified or a language is not available, OmegaT defaults first to the operating \nsystem language, then to English. Different country variants for the same language are not \nused at present." -> @ ;
languages_hc :horizontal -> @close="Close" ;


# Font anti-aliasing settings

fontaa :double "Anti-aliasing settings" -> on | false | defaultaa | off | gasp | lcd_hrgb | lcd_hbgr | lcd_vrgb | lcd_vbgr | aa_help ;
on "Anti-aliasing on" -> "on " ;
false "Anti-aliasing false" -> "false " ;
defaultaa "Anti-aliasing default" -> "default " ;
off "Anti-aliasing off" -> "off " ;
gasp "Use font's built-in hinting instructions" -> "gasp " ;
lcd_hrgb "LCD monitor setting HRGB" -> "lcd_hrgb " ;
lcd_hbgr "LCD monitor setting HBGR" -> "lcd_hbgr " ;
lcd_vrgb "LCD monitor setting VRGB" -> "lcd_vrgb " ;
lcd_vbgr "LCD monitor setting VBGR" -> "lcd_vbgr " ;

aa_help :dialog "Help" -> aa_m aa_hc ;
aa_m :horizontal ->  aa_t ;
aa_t "Fonts in Java on Linux can be very unattractive unless the optimum settings are selected. \nThe optimum settings depend upon the font type and size, your hardware, and the anti-aliasing \nsettings. The best anti-aliasing settings may differ according to the selected font \nand size and are best found by trial and error. It is worth taking time to experiment \nwith these." -> @ ;
aa_hc :horizontal -> @close="Close";

# Look and feel settings

laf "Look and Feel" -> deflaf | gtk | motif | laf_help ;
deflaf "Default" -> " " ;
gtk "GTK" -> " -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel ";
motif "Motif" -> " -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel " ;
laf_help :dialog "Help" -> laf_m laf_hc ;
laf_m :horizontal ->  laf_t ;
laf_t "Modern Linux distributions attempt to create \na uniform look and feel, and you may notice little or no difference with these settings." -> @ ;
laf_hc :horizontal -> @close="Close" ;


### About tab

about :framed "About" -> general_t ;
general_t "About the Kaptain OmegaT Launcher" -> @text (<<LONGTEXT
Certain functions and settings of OmegaT are activated or configured at
runtime, i.e. when OmegaT is launched, by means of command-line options.
The Kaptain OmegaT Launcher is intended to make the use of these functions and
settings easier for GNU/Linux users by providing a user-friendly user interface.
Information on Kaptain and its syntax can be found at
http://kaptain.sourceforge.net

The Kaptain OmegaT Launcher is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your option)
any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.
The text of the GNU General Public License is provided within OmegaT itself,
with which this script is intended to be supplied.
LONGTEXT
) ;


### Button bar

button_bar :horizontal -> launch_button close_button ;
launch_button -> @exec(omt)="Launch" ;
close_button -> @close="Cancel" ;


### Launch command

omt -> javaloc " -jar " memory " -Duser.language=" UIlang " -Duser.country=" country " -Dgoogle.api.key=" gt " -Dmicrosoft.api.client_secret=" msk " -Dmicrosoft.api.client_id=" msi " -Dmymemory.api.email=" mymem " -Dtaas.user.key=" taas " -Dyandex.api.key=" yand " -Dhttp.proxyHost=" proxyhost " -Dhttp.proxyPort=" proxyport " -Dawt.useSystemAAFontSettings=" fontaa laf " " jarfileloc " " projectloc " --config-dir=" configloc team;
