#!/usr/bin/perl
# This script configures ktouch (version 1.0)
use strict;
use warnings;

# We use postconfig() helper subroutine so we have to include
# its definition
require '/usr/lib/localization-config/common/postconfig.pl';
require '/usr/lib/localization-config/common/log.pl';

# If no locale is given as argument, quit
my $lang = $ARGV[0] or log_die("$0: No language given");

# The config filename and relevant section 
my $filename = '/etc/kde2/ktouchrc';

# The associative array with the locale/keyboard pairs
# ktouch version 1.0 support one of: de en fr it la no pt
my %lang_map = (
                #entries sorted alphabetically
#               'ca_ES@euro'  => { 'Keyboard/Language' => 'ca' },
#               'da_DK'       => { 'Keyboard/Language' => 'dk' },
                'de_BE@euro'  => { 'Keyboard/Language' => 'de' },
                'de_DE@euro'  => { 'Keyboard/Language' => 'de' },
#               'el_GR.UTF-8' => { 'Keyboard/Language' => 'el' },
                'en_AU'       => { 'Keyboard/Language' => 'en' },
                'en_CA'       => { 'Keyboard/Language' => 'en' },
                'en_IE@euro'  => { 'Keyboard/Language' => 'en' },
                'en_US'       => { 'Keyboard/Language' => 'en' },
#               'es_ES@euro'  => { 'Keyboard/Language' => 'es' },
                'es_MX'       => { 'Keyboard/Language' => 'la' },
#               'fi_FI@euro'  => { 'Keyboard/Language' => 'fi' },
                'fr_BE@euro'  => { 'Keyboard/Language' => 'fr' },
                'fr_CA'       => { 'Keyboard/Language' => 'us' },
                'fr_FR@euro'  => { 'Keyboard/Language' => 'fr' },
                'it_IT@euro'  => { 'Keyboard/Language' => 'it' },
                'ja_JP'       => { 'Keyboard/Language' => 'en' },
#               'lv_LV'       => { 'Keyboard/Language' => 'lv' },
                'nb_NO'       => { 'Keyboard/Language' => 'no' }, # Same as no_NO
                'nds_DE'      => { 'Keyboard/Language' => 'de' },                
                'nl_BE@euro'  => { 'Keyboard/Language' => 'fr' },
                'nl_NL@euro'  => { 'Keyboard/Language' => 'en' },
                'nn_NO'       => { 'Keyboard/Language' => 'no' },
                'no_NO'       => { 'Keyboard/Language' => 'no' }, # Same as nb_NO
                'pl_PL'       => { 'Keyboard/Language' => 'pl' },
                'pt_BR'       => { 'Keyboard/Language' => 'pt-br' },
                'se_NO'       => { 'Keyboard/Language' => 'no' }, # Should use saami
#                'sv_SE'      => { 'Keyboard/Language' => 'se' },
                'tr_TR'       => { 'Keyboard/Language' => 'tr' },
                );

# Print the supported locale entries.
if ("supported" eq $lang) {
    for $lang (sort keys %lang_map) {
        print "$lang\n";
    }
    exit 0;
}

# Call postconfig() with the appropriate locale/keyboard pair
if(defined(my $conf = $lang_map{$lang})) {
    postconfig('true', $filename, $conf);
} else {
    log_msg("$0: No support for language $lang");
}
