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

class InfoScreen
	def initialize(extlayers, button, nwscreen, scanner=nil, checkscreen=false)
		@nwscreen = nwscreen
		@layers = Array.new
		@checkscreen = checkscreen
		fixed = Gtk::Fixed.new
		
		# Kachel Nutzungsbedingungen
		icon_legal = Gtk::EventBox.new.add  Gtk::Image.new("legal.png")
		text_legal = TileHelpers.create_label("<b>Nutzungsbedingungen anzeigen</b>\n\nKlicken Sie hier, um die Nutzungsbedingungen der Notfall-DVD 4.0 erneut anzuzeigen.", 250)
		icon_legal.signal_connect("button-release-event") { |x,y|
			if y.button == 1 
				extlayers.each { |k,v|v.hide_all }
				extlayers["legal2"].show_all
			end
		}
		
		# Kachel Updates
		icon_update = Gtk::EventBox.new.add  Gtk::Image.new("updater.png")
		text_update = TileHelpers.create_label("<b>Update suchen</b>\n\nKlicken Sie hier, um nach Aktualisierungen für die Notfall-DVD 4.0 zu suchen. Updates bringen Verbesserungen und beseitigen mögliche Fehler.", 250)
		icon_update.signal_connect("button-release-event") { |x,y|
			if nwscreen.test_connection == false
				nwscreen.nextscreen = "infobox"
				nwscreen.fill_wlan_combo 
				extlayers.each { |k,v|v.hide_all }
				extlayers["networks"].show_all
			end
			system("/etc/lesslinux/updater/update_wrapper.sh &")
		}
		# Kachel Mattias Schlenker
		icon_mattias = Gtk::EventBox.new.add  Gtk::Image.new("lesslinux.png")
		text_mattias = TileHelpers.create_label("<b>Technische Umsetzung: Mattias Schlenker</b>\n\nDie COMPUTER BILD Notfall-DVD 4.0 basiert auf LessLinux, einem vielseitigen und robusten Linux-System für den Live-Einsatz von CD, USB-Stick oder PXE-Boot, das von Mattias Schlenker entwickelt und betreut wird.", 380)
		icon_mattias.signal_connect("button-release-event") { |x,y|
			if y.button == 1 
				TileHelpers.open_browser("http://www.mattiasschlenker.de/") 
			end
		}
		
		# Kachel Jan Sass
		icon_jansass = Gtk::EventBox.new.add  Gtk::Image.new("jansass.png")
		text_jansass = TileHelpers.create_label("<b>Grafiken und Design: jansass GmbH</b>\n\n- 15 Jahre und über 1.000 Projekte\n- Werbung in Zeitung, Radio, OoH\n  und Online\n- Für Handel und Dienstleister", 250)
		icon_jansass.signal_connect("button-release-event") { |x,y|
			if y.button == 1 
				TileHelpers.open_browser("http://www.jansass.com/") 
			end
		}

		# Kachel Avira
		scanicon = "avira.png"
		scanicon = "clamav.png" unless scanner == "scancl"
		scantext = "<b>Virenscanner: Avira Operations GmbH &amp; Co. KG</b>\n\nDie Notfall-DVD nutzt den Virenscanner \"scancl\" der Avira Operations GmbH &amp; Co. KG für die Suche nach Schadsoftware."
		scantext = "<b>Virenscanner: ClamAV</b>\n\nDie Notfall-DVD nutzt den freien Virenscanner \"ClamAV\" des gleichnamigen Opensource-Projektes für die Suche nach Schadsoftware." unless scanner == "scancl"
		icon_avira = Gtk::EventBox.new.add  Gtk::Image.new(scanicon)
		text_avira = TileHelpers.create_label(scantext,  250) 
		icon_avira.signal_connect("button-release-event") { |x,y|
			# if y.button == 3
			#	TileHelpers.open_browser("http://www.avira.com/") 
			# end
		}
		
		# Kachel Jan Mattias
		icon_jsms = Gtk::EventBox.new.add  Gtk::Image.new("janmattias.png")
		text_jsms = TileHelpers.create_label("<b>Umsetzung</b>\n\nInformationen zur Gestaltung und technischen Umsetzung der Notfall-DVD 4.0 und den beteiligten Programmierern und Grafikern.",  250) 
		icon_jsms.signal_connect("button-release-event") { |x,y|
			if y.button == 1 
				extlayers.each { |k,v|v.hide_all }
				extlayers["infojanmattias"].show_all
			end
		}
		
		
		text4 = Gtk::Label.new
		text4.width_request = 250
		text4.wrap = true
		text4.set_markup("<span color='white'>Klicken Sie hier, um abzubrechen und zum Startbildschirm zurückzukehren.</span>")
		back = Gtk::EventBox.new.add Gtk::Image.new("cancel.png")
		
		fixed.put(back, 852, 332)
		fixed.put(text4, 605, 338)
		fixed.put(icon_legal, 0, 0)
		fixed.put(text_legal, 130, 0)
		fixed.put(icon_update, 380, 0)
		fixed.put(text_update, 510, 0)
		# fixed.put(icon_mattias, 380, 0)
		# fixed.put(text_mattias, 510, 0)
		# fixed.put(icon_jansass, 0, 0)
		# fixed.put(text_jansass, 130, 0)
		fixed.put(icon_avira, 0, 130)
		fixed.put(text_avira, 130, 130)
		fixed.put(icon_jsms, 380, 130)
		fixed.put(text_jsms, 510, 130)
		
		
		extlayers["infobox"] = fixed
		@layers[0] = fixed
		
		legallayer = create_legal_screen(extlayers)
		extlayers["legal"] = legallayer
		@layers[1] = legallayer
		
		otherlegallayer = create_other_legal_screen(extlayers)
		extlayers["legal2"] = otherlegallayer
		@layers[2] = otherlegallayer
		
		jsmslayer = create_jsms_screen(extlayers)
		extlayers["infojanmattias"] = jsmslayer
		@layers[3] = jsmslayer
		
		button.signal_connect('button-release-event') { |x, y|
			if y.button == 1 
				extlayers.each { |k,v|v.hide_all }
				extlayers["infobox"].show_all
			end
		}
		back.signal_connect('button-release-event') { |x, y|
			if y.button == 1 
				extlayers.each { |k,v|v.hide_all }
				extlayers["start"].show_all
			end
		}
	
	end
	
	def create_jsms_screen(extlayers)
		fixed = Gtk::Fixed.new
		TileHelpers.place_back(fixed, extlayers)
		# Kachel Mattias Schlenker
		icon_mattias = Gtk::EventBox.new.add  Gtk::Image.new("lesslinux.png")
		text_mattias = TileHelpers.create_label("<b>Technische Umsetzung: Mattias Schlenker</b>\n\nDie COMPUTER BILD Notfall-DVD 4.0 basiert auf LessLinux, einem vielseitigen und robusten Linux-System für den Live-Einsatz von CD, USB-Stick oder PXE-Boot, das von Mattias Schlenker entwickelt und betreut wird. Sie erreichen Mattias Schlenker per Email an <b>ms@mattiasschlenker.de</b>.", 380)
		icon_mattias.signal_connect("button-release-event") { |x,y|
			if y.button > 1 
				TileHelpers.open_browser("http://www.mattiasschlenker.de/") 
			end
		}
		
		# Kachel Jan Sass
		icon_jansass = Gtk::EventBox.new.add  Gtk::Image.new("jansass.png")
		text_jansass = TileHelpers.create_label("<b>Grafiken und Design: jansass GmbH</b>\n\n- 15 Jahre und über 1.000 Projekte\n- Werbung in Zeitung, Radio, OoH und Online\n- Für Handel und Dienstleister\n\nSie erreichen Jan Sass per Email an <b>info@jansass.com</b>", 380)
		icon_jansass.signal_connect("button-release-event") { |x,y|
			if y.button > 1
				TileHelpers.open_browser("http://www.jansass.com/") 
			end
		}
		
		fixed.put(icon_mattias, 0, 0)
		fixed.put(text_mattias, 130, 0)
		fixed.put(icon_jansass, 0, 130)
		fixed.put(text_jansass, 130, 130)
		
		
		return fixed
	end
		
		
	
	def create_legal_screen(extlayers)
		fixed = Gtk::Fixed.new
		text4 = Gtk::Label.new
		text4.width_request = 250
		text4.wrap = true
		text4.set_markup("<span color='white'>Nutzungsbedingungen ablehnen und Computer ausschalten.</span>")
		back = Gtk::EventBox.new.add Gtk::Image.new("cancel.png")
		text5 = Gtk::Label.new
		text5.width_request = 250
		text5.wrap = true
		text5.set_markup("<span color='white'>Nutzungsbedingungen akzeptieren und weiter zum Assistenten.</span>")
		forw  = Gtk::EventBox.new.add Gtk::Image.new("forward.png")
		
		disctext = "Ooops nicht gefunden!"
		disctext = File.new("haftung.txt").read if File.exist?("haftung.txt")
		
		disclabel = Gtk::Label.new
		disclabel.set_markup("<span color='white'>Nutzungs- und Haftungsbedingungen</span>")
		fat_font = Pango::FontDescription.new("Sans Bold 14")
		disclabel.modify_font(fat_font)
		textview = Gtk::TextView.new
		textview.buffer.text = disctext
		textview.set_wrap_mode(Gtk::TextTag::WRAP_WORD)
		scrolled_win = Gtk::ScrolledWindow.new
		scrolled_win.border_width = 5
		scrolled_win.add(textview)
		scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS)
		textview.modify_bg(Gtk::STATE_NORMAL, Gdk::Color.parse('#005163') )
		
		# scrolled_win.add(textview)
		scrolled_win.set_size_request(580, 330)
		
		forw.signal_connect('button-release-event') { |x, y|
			if y.button == 1 
				system("touch /var/run/lesslinux/license_accepted") 
				extlayers.each { |k,v|v.hide_all }
				if @checkscreen == false
					extlayers["start"].show_all 
				else
					extlayers["checkscreen"].show_all 
				end
			end
		}
		back.signal_connect('button-release-event') { |x, y|
			if y.button == 1 
				system("/usr/bin/shutdown-wrapper.sh") 
			end
		}
		fixed.put(disclabel, 0, 3)
		fixed.put(scrolled_win, 0, 40)
		fixed.put(forw, 853, 282)
		fixed.put(text5, 605, 288)
		fixed.put(back, 852, 332)
		fixed.put(text4, 605, 338)
		return fixed 
	end
	
	def create_other_legal_screen(extlayers)
		fixed = Gtk::Fixed.new
		text4 = Gtk::Label.new
		text4.width_request = 250
		text4.wrap = true
		text4.set_markup("<span color='white'>Nutzungsbedingungen ablehnen und Computer ausschalten.</span>")
		back = Gtk::EventBox.new.add Gtk::Image.new("cancel.png")
		text5 = Gtk::Label.new
		text5.width_request = 250
		text5.wrap = true
		text5.set_markup("<span color='white'>Nutzungsbedingungen akzeptieren und weiter zum Assistenten.</span>")
		forw  = Gtk::EventBox.new.add Gtk::Image.new("forward.png")
		
		disctext = "Ooops nicht gefunden!"
		disctext = File.new("haftung.txt").read if File.exist?("haftung.txt")
		
		disclabel = Gtk::Label.new
		disclabel.set_markup("<span color='white'>Nutzungs- und Haftungsbedingungen</span>")
		fat_font = Pango::FontDescription.new("Sans Bold 14")
		disclabel.modify_font(fat_font)
		textview = Gtk::TextView.new
		textview.buffer.text = disctext
		textview.set_wrap_mode(Gtk::TextTag::WRAP_WORD)
		scrolled_win = Gtk::ScrolledWindow.new
		scrolled_win.border_width = 5
		scrolled_win.add(textview)
		scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS)
		textview.modify_bg(Gtk::STATE_NORMAL, Gdk::Color.parse('#005163') )
		
		# scrolled_win.add(textview)
		scrolled_win.set_size_request(580, 330)
		
		forw.signal_connect('button-release-event') { |x, y|
			if y.button == 1 
				system("touch /var/run/lesslinux/license_accepted") 
				extlayers.each { |k,v|v.hide_all }
				extlayers["start"].show_all
			end
		}
		back.signal_connect('button-release-event') { |x, y|
			if y.button == 1 
				system("/usr/bin/shutdown-wrapper.sh") 
			end
		}
		fixed.put(disclabel, 0, 3)
		fixed.put(scrolled_win, 0, 40)
		#fixed.put(forw, 853, 282)
		#fixed.put(text5, 605, 288)
		#fixed.put(back, 852, 332)
		#fixed.put(text4, 605, 338)
		TileHelpers.place_back(fixed, extlayers)
		return fixed 
	end	
	
	
	attr_reader :layers

end