#!/usr/bin/ruby
# encoding: utf-8

require 'gtk2'
# require 'vte'
require "rexml/document"
require 'optparse'
# require 'LicenseScreen' 
require 'MfsTranslator'
require "fileutils"

# Constants for positions:

OK_X = 654
OK_Y = 496
CANCEL_X = 518
CANCEL_Y = 496
SETTINGS_X = 382
SETTINGS_Y = 496

lang = ENV['LANGUAGE'][0..1]
lang = ENV['LANG'][0..1] if lang.nil?
lang = "en" if lang.nil?
# @tl = MfsTranslator.new(lang, "forensicgui.xml") 

window = Gtk::Window.new
window.set_size_request(800, 550)
window.border_width = 0
window.window_position = Gtk::Window::POS_CENTER_ALWAYS

window.deletable = false
window.decorated = false
window.allow_grow = false
window.allow_shrink = false
window.title = "CyberShield"

fixed = Gtk::Fixed.new

# Layers are stored in a Hash:

layers = Hash.new

# Back button 

backico = Gtk::EventBox.new
img = "back_" + lang + ".png"
if File.exists? img
	backico.add Gtk::Image.new(img)
else
	backico.add Gtk::Image.new("back_en.png")
end
backico.signal_connect("button_release_event") {
	layers.each { |k,v| v.hide_all }
	backico.hide_all 
	layers["start"].show_all 
}

# First layer for starting page

bgimg = Gtk::Image.new("background.png")
startfixed = Gtk::Fixed.new
layers["start"] = startfixed 
startfixed.put(bgimg, 0, 0)
wwwico = Gtk::EventBox.new
img = "tile_www_" + lang + ".png"
if File.exists? img
	wwwico.add Gtk::Image.new(img)
else
	wwwico.add Gtk::Image.new("tile_www_en.png")
end
startfixed.put(wwwico, 52, 120 )
wwwico.signal_connect("button_release_event") {
	layers.each { |k,v| v.hide_all }
	layers["www"].show_all 
	backico.show_all 
}
bankico = Gtk::EventBox.new
img = "tile_bank_" + lang + ".png"
if File.exists? img
	bankico.add Gtk::Image.new(img)
else
	bankico.add Gtk::Image.new("tile_bank_en.png")
end
#startfixed.put(bankico, 288, 120 )
#bankico.signal_connect("button_release_event") {
#	layers.each { |k,v| v.hide_all }
#	layers["bank"].show_all
#	backico.show_all 
#}
vpnico = Gtk::EventBox.new
img = "tile_vpn_" + lang + ".png"
if File.exists? img
	vpnico.add Gtk::Image.new(img)
else
	vpnico.add Gtk::Image.new("tile_vpn_en.png")
end
#startfixed.put(vpnico, 524, 120 )
#vpnico.signal_connect("button_release_event") {
#	system("ruby /usr/bin/vpn-assistant.rb &") 
#}
mailico = Gtk::EventBox.new
img = "tile_mail_" + lang + ".png"
if File.exists? img
	mailico.add Gtk::Image.new(img)
else
	mailico.add Gtk::Image.new("tile_mail_en.png")
end
startfixed.put(mailico, 53, 305 )
mailico.signal_connect("button_release_event") {
	system("thunderbird &") 
}
offico = Gtk::EventBox.new
img = "tile_office_" + lang + ".png"
if File.exists? img
	offico.add Gtk::Image.new(img)
else
	offico.add Gtk::Image.new("tile_office_en.png")
end
startfixed.put(offico, 288, 305 )
offico.signal_connect("button_release_event") {
	layers.each { |k,v| v.hide_all }
	layers["office"].show_all
	backico.show_all 
}
passico = Gtk::EventBox.new
img = "tile_passwd_" + lang + ".png"
if File.exists? img
	passico.add Gtk::Image.new(img)
else
	passico.add Gtk::Image.new("tile_passwd_en.png")
end
# startfixed.put(passico, 524, 305 )
startfixed.put(passico, 288, 120 )
passico.signal_connect("button_release_event") {
	system("keepassxc &") 
}
fixed.put(startfixed,0,0)

# Second layer WWW

wwwimg = Gtk::Image.new("bg_www.png")
wwwfixed = Gtk::Fixed.new
layers["www"] = wwwfixed 
wwwfixed.put(wwwimg, 0, 0)
wwwvpnico = Gtk::EventBox.new
img = "tile_www_vpn_" + lang + ".png"
if File.exists? img
	wwwvpnico.add Gtk::Image.new(img)
else
	wwwvpnico.add Gtk::Image.new("tile_www_vpn_en.png")
end
#wwwfixed.put(wwwvpnico, 288, 120 )
#wwwvpnico.signal_connect("button_release_event") {
#	system("ruby /usr/bin/vpn-assistant.rb &") 
#}
wwwtorico = Gtk::EventBox.new
img = "tile_www_tor_" + lang + ".png"
if File.exists? img
	wwwtorico.add Gtk::Image.new(img)
else
	wwwtorico.add Gtk::Image.new("tile_www_tor_en.png")
end
wwwfixed.put(wwwtorico, 524, 120 )
wwwtorico.signal_connect("button_release_event") {
	system("tor-browser &") 
}
wwwwwwico = Gtk::EventBox.new
img = "tile_www_www_" + lang + ".png"
if File.exists? img
	wwwwwwico.add Gtk::Image.new(img)
else
	wwwwwwico.add Gtk::Image.new("tile_www_www_en.png")
end
#wwwfixed.put(wwwwwwico, 288, 305 )
wwwfixed.put(wwwwwwico, 288, 120 )
wwwwwwico.signal_connect("button_release_event") {
	system("firefox &") 
}
fixed.put(wwwfixed,0,0)

# Third layer bank

bankimg = Gtk::Image.new("bg_bank.png")
bankfixed = Gtk::Fixed.new
layers["bank"] = bankfixed 
bankfixed.put(bankimg, 0, 0)
bankwwwico = Gtk::EventBox.new
img = "tile_bank_www_" + lang + ".png"
if File.exists? img
	bankwwwico.add Gtk::Image.new(img)
else
	bankwwwico.add Gtk::Image.new("tile_bank_www_en.png")
end
bankfixed.put(bankwwwico, 288, 120 )
bankwwwico.signal_connect("button_release_event") {
	system("firefox &") 
}
bankappico = Gtk::EventBox.new
img = "tile_bank_app_" + lang + ".png"
if File.exists? img
	bankappico.add Gtk::Image.new(img)
else
	bankappico.add Gtk::Image.new("tile_bank_app_en.png")
end
bankfixed.put(bankappico, 524, 120 )
bankappico.signal_connect("button_release_event") {
	system("/opt/bin/gnucash_wrapper &") 
}
fixed.put(bankfixed,0,0)

# Fourth layer office

officeimg = Gtk::Image.new("bg_office.png")
officefixed = Gtk::Fixed.new
layers["office"] = officefixed 
officefixed.put(officeimg, 0, 0)
officewordico = Gtk::EventBox.new
img = "tile_office_writer_" + lang + ".png"
if File.exists? img
	officewordico.add Gtk::Image.new(img)
else
	officewordico.add Gtk::Image.new("tile_office_writer_en.png")
end
officefixed.put(officewordico, 288, 120 )
officewordico.signal_connect("button_release_event") {
	system("libreoffice --writer &") 
}
officesheetico = Gtk::EventBox.new
img = "tile_office_spread_" + lang + ".png"
if File.exists? img
	officesheetico.add Gtk::Image.new(img)
else
	officesheetico.add Gtk::Image.new("tile_office_spread_en.png")
end
officefixed.put(officesheetico, 524, 120 )
officesheetico.signal_connect("button_release_event") {
	system("libreoffice --calc &") 
}
officepresentico = Gtk::EventBox.new
img = "tile_office_present_" + lang + ".png"
if File.exists? img
	officepresentico.add Gtk::Image.new(img)
else
	officepresentico.add Gtk::Image.new("tile_office_present_en.png")
end
officefixed.put(officepresentico, 288, 305 )
officepresentico.signal_connect("button_release_event") {
	system("libreoffice --impress &") 
}
officedeskico = Gtk::EventBox.new
img = "tile_office_desk_" + lang + ".png"
if File.exists? img
	officedeskico.add Gtk::Image.new(img)
else
	officedeskico.add Gtk::Image.new("tile_office_desk_en.png")
end
officefixed.put(officedeskico, 524, 305 )
officedeskico.signal_connect("button_release_event") {
	system("libreoffice &") 
}
fixed.put(officefixed,0,0)

# Fifth layer: LicenseScreen
# licensescreen = LicenseScreen.new(layers, fixed, [])

# Back button
fixed.put(backico , 682 , 499 )

closeico = Gtk::EventBox.new
closeico.add Gtk::Image.new("close.png")
fixed.put(closeico, 762, 19 ) # 19
closeico.signal_connect("button_release_event") {
	exit 0 
}
minico = Gtk::EventBox.new
minico.add Gtk::Image.new("minimize.png")
fixed.put(minico, 730, 19 ) # 19
minico.signal_connect("button_release_event") {
	window.iconify
}

window.add fixed
window.signal_connect('destroy') { Gtk.main_quit }
window.show_all 

layers.each { |k,v| v.hide_all }
backico.hide_all 
# layers["license"].show_all 
layers["start"].show_all 

Gtk.main
