#!/bin/bash
PATH=$PATH:/usr/local/lib/inx
. inx_essentials
maybe_switch

f-tools ()
{
EXPORTED=
unbold ; clear ; echo
fig-col
figlet -k -t "  Tools                                                                      "
unbold
echo -e "  Here you can make adjustments and choices..."
head-col
echo -e "\n  Configuration                                                             \n"
info-col
echo "  0: Software Install/Remove.           (sudo aptitude)                           "
echo "  1: Adjust the System Time.            (sudo dpkg-reconfigure tzdata)            "
echo "  2: Choose Your Default Editor.        (sudo update-alternatives --config editor)"
echo "  3: Adjust Sound                       (alsamixer)                               "
echo "  4: Keyboard and Console Configuration (sudo dpkg-reconfigure console-setup)     "
head-col
echo -e "\n  Information                                                               \n"
info-col                                                                      
echo "  5: About INX application choice (email, editors, browsers)                      "
echo "  6: Why you should use GNU Screen                                                "
echo "  7: Extra: Dynamic Virtual Terminal Manager (dvtm)                               "
echo "  8: Introduction to Linux (in the graphical browser - recommended)               "
echo "  9: Hints and Rants                                                              "
echo
fig-col
echo "  a: Credits, Licence, Starter, Advanced"
echo "  b: Back to INX 101         "
echo "  c: Change your default colour theme"
echo "  d: INX Direct Menu         "
echo "  f: Flip colours            "
echo "  m: INX main menu           "
echo "  s: INX and Bash Shortcuts  "
echo "  t: Toggle clock on | off   "
echo "  w: Net and Web menu, Connections."
echo "  x: Give me a command prompt"


f-ttynum
read -s -n 1 TOOLS
choice
}

choice ()
{
case $TOOLS in
    
    0)
    sudo aptitude
    f-tools
    ;;
    1)
    time_settings
    f-tools
    ;;
    2)
    unbold ; clear ; bold ; yellow 
    echo -e "\nHere you can choose your preferred default editor."
    echo -e "It will be used with the mutt mail client, office and so on.\n"
    echo -e "Hint: Don't choose '/bin/ed' unless you are a masochist :)\n"
    white ; printf "  "
    sudo update-alternatives --config editor
    f-tools
    ;;
    3)
    alsamixer
    f-tools
    ;;
    4)
    unbold ; clear ; bold ; yellow
    echo -e "\n\n  Here you can configure your keyboard and console settings."
    echo -e "  For example, choose your country's keyboard mapping.\n"
    echo -e "  Type \"1\" for \"yes\" to continue. Any other key returns to the Tools menu."
    read -s -n 1 CONSOLE
    if  [ "$CONSOLE" != "1" ] ; then
        f-tools
    fi	
    white ; printf "  "
    sudo dpkg-reconfigure console-setup
    f-tools
    ;;
    5)
    alternatives ()
    {
    unbold ; clear ; bold
    fig-col
    figlet -k -t "  Alternatives"
    echo -e "\v"
    head-col
    echo -e "  Some snippets of information about...\n"
    info-col
    echo "  1: INX Email Alternatives"
    echo "  2: INX Editor Alternatives"
    echo "  3: INX Browser Alternatives"
    echo
    head-col
    echo "  Any other key to return to the tools menu."
    
    read -s -n 1 ALTERNATIVES
    case $ALTERNATIVES in
        1)
        unbold ; clear ; bold
        fig-col
        echo -e "\n  INX Email"
        echo
        head-col
        echo "  Three ways to use email in INX:"
        echo
        echo "  IMAPS with Mutt"
        info-col
        echo
        echo "  Most ISPs now support the IMAPS protocol. You can set up"
        echo "  the Mutt email client to use this with the secure version (IMAPS)."
        echo "  Be sure to check to see if your ISP uses a different server for this."
        head-col
        echo
        echo "  Gmail with Mutt"
        info-col
        echo
        echo "  If you have a Gmail account, this way is quicker to set up."
        echo "  There are fewer questions to answer ;-)"
        echo
        head-col
        echo "  For the terminally impatient Gmail user:"
        info-col
        echo
        echo "  There's a quick-and-dirty entry in the mail menu to use elinks."
        echo "  It works, but using Mutt is much nicer!"
        echo
        echo "  Read the introduction on the email menu..."
        head-col
        echo -e "\n  e: Take me to the email menu.\n"
        fig-col
        echo -e "  Any other key to return to the tools menu.\n"
    
        read -s -n 1 MAIL
    	case $MAIL in
	        e)
	        exec mailinx
	        ;;
	        *)
	        alternatives
	        ;;
	    esac
        ;;
        2)
        unbold ; clear ; bold
        fig-col
        echo -e "\n  Editors"
        echo
        head-col
        echo -e "  Jed  "
        info-col
        cat << EOJED
  Jed is the default editor in INX, for these reasons:
  
  * You can explore menus with your mouse, which helps to learn the key bindings.
  * It is fairly intuitive compared to vi, which is the "standard" nix editor.
  * It has pretty colours ;-)
  
  Also included is the tiny "zile" editor. Jed and zile both emulate Emacs.
  
  Recommended: If you want to learn Jed (or indeed Emacs), run the zile editor 
  and try the tutorial. The zile tutorial helps with all three.
  
EOJED
 
        head-col
        echo -e "  Vim  "
        info-col
    cat << EOVIM
  Vi or Vim will be on any GNU/Linux or Unix installation. 
  Knowing your way around vi is always useful.
  
  * Vim has a tutorial - just type "vimtutor" at the command line prompt.
  * Vi/Vim is a "modal" editor - this means it has a "command" mode and an "input" mode.
    You switch by hitting the <escape> key. This is explained in "vimtutor".
  * Vi/vim is very powerful - whenever you see the word "powerful" associated 
    with a *nix app, expect a long apprenticeship ;-) 

EOVIM
        head-col
        echo -e "  MCEdit"
        info-col
        echo -e "  MCEdit is part of the mc (Midnight Commander) package. It is quite intuitive.\n"
        head-col
        echo -e "  Nano"
        info-col
        echo -e "  Nano you have already met briefly, if you have followed the tutorials."
        echo -e "  It is a simple but useful editor."
        head-col
        echo -e "\n  v: Vimtutor"
        echo -e "  z: Zile tutorial. ( type Ctrl+h then  t in Zile for the tutorial)\n"
        fig-col
        echo -e "  Any other key to return to the Tools menu."
        
        read -s -n 1
        case $REPLY in
            v)
	        vimtutor
	        f-tools
	        ;;
	        z)
	        zile
	        f-tools
	        ;;
	        *)
	        alternatives
	        ;;
        esac       
        ;;
        3)
        unbold ; clear ; bold
        fig-col
        echo -e "\n  Browsers \n"
        info-col
        echo "  You have a choice of graphical and non-graphical browsers."
        echo "  Most people will, through habit, prefer the graphical browser."
        echo "  This is O.K. - but be aware that the command-line browser elinks"
        echo "  is really a better choice in INX, most of the time."
        echo
        echo "  Elinks integrates much better with the other applications -"
        echo "  for example, it starts the MOC music player for Shoutcast and"
        echo "  Magnatunes URLs, and it will start the Playinx script to play"
        echo "  Internet videos, provided that the link does not use plugins"
        echo "  javascript or other tricks."
        echo
        echo "  Obviously, the graphical browser (xlinks2) is preferable for "
        echo "  viewing pictures and so on, although elinks will also do this"
        echo "  with the fbi program. Elinks will also show most pdf files "
        echo "  using the fbgs program."
        echo
        fig-col
        echo "  Hit any key to return to the tools menu."
        read -s -n 1
        alternatives
        ;;
        *)
        f-tools
        ;;
    esac
    }
    alternatives
    ;;
    6)
    unbold ; clear ; bold
    fig-col
    echo -e "\n  GNU Screen - Why Bother?\n"
    head-col
    echo -e "  You really should.\n"
    info-col
    echo "  GNU Screen multiplies the usefulness of INX. It enables additional"
    echo "  workspaces, and allows you to organise your applications as desired."
    echo
    echo "  In INX, it is easier to use than it would be with only a default configuration."
    echo "  Your home directory contains custom settings in \"hidden\" files that make Screen"
    echo "  show the various \"tabs\" or workspaces available. You can also see the date"
    echo "  and time at a glance."
    echo
    echo "  The GNU Screen menu has several pre-configured \"sessions\" that you can use."
    echo "  These are examples of what you can do. In any session, though, you can remove"
    echo "  or replace applications each in their own \"tab\"."
    echo
    echo "  Following the screen \"tour\" introduction from that menu will get you started."
    
    head-col
    echo -e "\n  s: Take me to the GNU Screen menu.\n"
    fig-col
    echo "  Hit any other key to return to the tools menu."
    read -s -n 1
    case $REPLY in
        s)
        exec screeninx
        ;;
        *)
        f-tools
        ;;
    esac
    ;;
    7)
    dvtm_info ()
    {
    unbold ; clear ; bold
    fig-col
    figlet -k -t "  dvtm"
    head-col
    echo -e "  Another way to split and organise your screen...\n"
    info-col
    cat << EODVTM
  The "dvtm" "Dynamic Virtual Terminal Manager" is included in INX.
  
  You can use it either in a tty (virtual terminal) or in GNU Screen.
  It acts as a "tiling terminal manager" that splits the screen into
  separate terminals, each of which can be used independently.
  
  The "modifier" key combination (Mod) is "CTRL+g". There are several
  possible ways to manipulate the splits, and so on. If you start 
  dvtm from here, you will see the manual that will help you
  to get started with using it. The main thing to read in the manual
  is the section "Keyboard Commands" that gives the "Mod" key strokes.
  
  You can then create new terminals, and have the manual as a "cheat sheet" 
  visible to guide you. 
  
  As a first action, try: ctrl+g c
  To move back and forth between terminals: ctrl+g [1...n] is probably the 
  easiest way to start (For example, ctrl+g 2 , ctrl+g 1 and so on).
  
  The dvtm man page is not too scary ;)
  
EODVTM

fig-col
echo "  1: Show me the dvtm manual in dvtm itself. (recommended)"
echo "  2: Show me the dvtm manual. (man dvtm)"
echo "  3: Just run dvtm for me."
echo
head-col
echo "  Any other key to return to the tools menu..."
info-col

    read -s -n 1 DVTMINFO
    case $DVTMINFO in
        1)
        dvtm "man dvtm"
        dvtm_info      
        ;;
        2)
        man dvtm
        dvtm_info
        ;;
        3)
        dvtm
        dvtm_info
        ;;
        *)
        f-tools
        ;;
    esac
    }
    dvtm_info
    ;;
    8)
    links2-watch /usr/share/example-content/intro-linux/index.html
    f-tools
    ;;
    9)
    exec hints
    ;;
    a)
    exec first-screen tools # 'first-screen' can take arguments $1=what-to-execute-in-case-'*'
    ;;
    b)
    exec first-screen tools inx101 # $2=which-function-to-call in 'first-screen' (=inx101 here)
    ;;
    c)
    export EXPORTED=theme
    exec theme
    ;;
    d)
    exec direct tools
    ;;
    f)
    switch
    f-tools
    ;;
    m)
    exec menu
    ;;
    x)
    clear
    f-prompt
    ;;
    s)
    clear
    less $HOME/shortcuts
    f-tools
    ;;
    t)
    time-toggle
    f-tools
    ;;
    w)
    exec netinx
    ;;
    *)
    f-tools
    ;;
    
esac
    
}

time_settings ()
{
clear
yellow ; bold
echo -e "\nYour date and time are set to $(date)"
echo -e "Do you want to change that? (y/n)\n"
read -s -n 1 CHANGE
if [ $CHANGE = y -o $CHANGE = Y ] ; then
	sudo dpkg-reconfigure tzdata
fi
clear
yellow ; bold
echo -e "\nWould you like a clock in the top right corner of your screens? [y]"
white
read -s -n 1 VCSTIME
    case $VCSTIME in
    n)
    if pidof vcstime > /dev/null 2>&1 ; then
        sudo killall vcstime  		     # user doesn't want a clock now
    fi
    f-tools
    ;;
    *)
    if pidof vcstime > /dev/null 2>&1 ; then
        sudo killall vcstime  	             # Refresh vcstime clock to reflect setting
        sudo -b vcstime > /dev/null 2>&1
    else
        sudo -b vcstime > /dev/null 2>&1 
    fi
    f-tools
    ;;
esac
}

TOOLS=$1
if [ -n $1 ] ; then
   choice
else
   f-tools
   choice
fi   

