#!/usr/bin/python
# -*- coding: utf-8 -*-

import gtk, htmlcode, FileChooserEntry, os.path, themelist, paneliconlist, caticonlist

class default(gtk.Table):
	""" Propriétés du FramaKiosk """
	def __init__(self, config, callback):
		self.callback = callback
		self.config = config
		gtk.Table.__init__(self)
		
		self.set_row_spacings(5)
		self.set_col_spacings(5)
		
		label = gtk.Label("<b>FramaKioskTune</b>")
		label.set_alignment(0.5, 0.5)
		label.set_use_markup(True)
		self.attach(label, 0, 1, 0, 1, gtk.EXPAND|gtk.FILL, 0)
		
class index(gtk.Table):
	""" Propriétés du FramaKiosk """
	def __init__(self, config, callback):
		self.callback = callback
		self.config = config
		gtk.Table.__init__(self)
		
		self.set_row_spacings(5)
		self.set_col_spacings(5)
		
		self.titlelabel = gtk.Label("<b>Titre : </b>")
		self.titlelabel.set_alignment(0.0, 0.5)
		self.titlelabel.set_use_markup(True)
		self.attach(self.titlelabel, 0, 1, 0, 1, gtk.FILL, 0)
		
		self.title = gtk.Entry()
		self.attach(self.title, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0)
		
		self.themelabel = gtk.Label("<b>Thème : </b>")
		self.themelabel.set_alignment(0.0, 0.5)
		self.themelabel.set_use_markup(True)
		self.attach(self.themelabel, 0, 1, 1, 2, gtk.FILL, 0)
		
		self.theme = themelist.themelist(self.config)
		self.attach(self.theme, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, 0)
		
		self.attach(gtk.VBox(), 0, 2, 2, 3, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
		
		save = gtk.Button(stock=gtk.STOCK_APPLY)
		save.connect("clicked", self.save)
		self.attach(save, 0, 2, 3, 4, gtk.EXPAND, 0)
		
	def open(self, element):
		self.element = element
		self.title.set_text(element.get("title"))
		self.theme.update(element.get("theme"))
		
	def save(self, widget=None):
		self.element.set("title", self.title.get_text())
		self.element.set("theme", self.theme.get_theme())
		self.callback()

class cat(gtk.Table):
	""" Propriétés d'une catégorie """
	def __init__(self, config, callback):
		self.callback = callback
		self.config = config
		gtk.Table.__init__(self)
		
		self.set_row_spacings(5)
		self.set_col_spacings(5)
		
		self.titlelabel = gtk.Label("<b>Nom : </b>")
		self.titlelabel.set_alignment(0.0, 0.5)
		self.titlelabel.set_use_markup(True)
		self.attach(self.titlelabel, 0, 1, 0, 1, gtk.FILL, 0)
		
		self.title = gtk.Entry()
		self.attach(self.title, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0)
		
		self.filelabel = gtk.Label("<b>Fichier : </b>")
		self.filelabel.set_alignment(0.0, 0.5)
		self.filelabel.set_use_markup(True)
		self.attach(self.filelabel, 0, 1, 1, 2, gtk.FILL, 0)
		
		self.file = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner la page")
		self.attach(self.file, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, 0)
		
		self.iconlabel = gtk.Label("<b>Icône : </b>")
		self.iconlabel.set_alignment(0.0, 0.5)
		self.iconlabel.set_use_markup(True)
		self.attach(self.iconlabel, 0, 1, 2, 3, gtk.FILL, 0)
		
		# 0.4.5 : les icones des panels sont gérées au travers des CSS + JS
		self.icon = caticonlist.caticonlist(self.config)
		self.attach(self.icon, 1, 2, 2, 3, gtk.EXPAND|gtk.FILL, 0)
		
		self.attach(gtk.VBox(), 0, 2, 3, 4, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
		
		save = gtk.Button(stock=gtk.STOCK_APPLY)
		save.connect("clicked", self.save)
		self.attach(save, 0, 2, 4, 5, gtk.EXPAND, 0)
		
	def open(self, element):
		self.element = element
		self.title.set_text(element.get("name"))
		self.file.set_filename(element.get("page"))
		self.icon.update(element.get("icon"))
		
	def save(self, widget=None):
		self.element.set("name", self.title.get_text())
		self.element.set("file", self.file.get_filename())
		self.element.set("icon", self.icon.get_cat())
		self.callback()
		
class subpage(gtk.Table):
	""" Propriétés d'une catégorie """
	def __init__(self, config, callback):
		self.callback = callback
		self.config = config
		gtk.Table.__init__(self)
		
		self.set_row_spacings(5)
		self.set_col_spacings(5)
		
		self.titlelabel = gtk.Label("<b>Nom : </b>")
		self.titlelabel.set_alignment(0.0, 0.5)
		self.titlelabel.set_use_markup(True)
		self.attach(self.titlelabel, 0, 1, 0, 1, gtk.FILL, 0)
		
		self.title = gtk.Entry()
		self.attach(self.title, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0)
		
		self.filelabel = gtk.Label("<b>Fichier : </b>")
		self.filelabel.set_alignment(0.0, 0.5)
		self.filelabel.set_use_markup(True)
		self.attach(self.filelabel, 0, 1, 1, 2, gtk.FILL, 0)
		
		self.file = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner le lanceur")
		self.attach(self.file, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, 0)
		
		self.contentlabel = gtk.Label("<b>Contenu : </b>")
		self.contentlabel.set_alignment(0.0, 0.5)
		self.contentlabel.set_use_markup(True)
		self.attach(self.contentlabel, 0, 2, 2, 3, gtk.FILL, 0)
		
		self.content = htmlcode.HtmlCode()
		self.attach(self.content, 0, 2, 3, 4, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
		
		save = gtk.Button(stock=gtk.STOCK_APPLY)
		save.connect("clicked", self.save)
		self.attach(save, 0, 2, 4, 5, gtk.EXPAND, 0)
		
	def open(self, element):
		self.element = element
		self.title.set_text(element.get("name"))
		self.file.set_filename(element.get("page"))
		try:
			self.content.set_text(element.get("content"))
		except:
			pass
		
	def save(self, widget=None):
		self.element.set("name", self.title.get_text())
		self.element.set("page", self.file.get_filename())
		self.element.set("content", self.content.get_text())
		self.callback()

class separator(gtk.Table):
	""" Propriétés d'une catégorie """
	def __init__(self, config, callback):
		self.callback = callback
		self.config = config
		gtk.Table.__init__(self)
		
		self.set_row_spacings(5)
		self.set_col_spacings(5)
		
		self.titlelabel = gtk.Label("<b>Nom : </b>")
		self.titlelabel.set_alignment(0.0, 0.5)
		self.titlelabel.set_use_markup(True)
		self.attach(self.titlelabel, 0, 1, 0, 1, gtk.FILL, 0)
		
		self.title = gtk.Entry()
		self.attach(self.title, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0)
		
		self.attach(gtk.VBox(), 0, 2, 1, 2, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
		
		save = gtk.Button(stock=gtk.STOCK_APPLY)
		save.connect("clicked", self.save)
		self.attach(save, 0, 2, 2, 3, gtk.EXPAND, 0)
		
	def open(self, element):
		self.element = element
		self.title.set_text(element.get("name"))
		
	def save(self, widget=None):
		self.element.set("name", self.title.get_text())
		self.callback()

class app(gtk.Table):
	""" Propriétés d'une catégorie """
	def __init__(self, config, callback):
		self.callback = callback
		self.config = config
		gtk.Table.__init__(self)
		
		self.set_row_spacings(5)
		self.set_col_spacings(5)
		
		self.iconlabel = gtk.Label("<b>Icône : </b>")
		self.iconlabel.set_alignment(0.0, 0.5)
		self.iconlabel.set_use_markup(True)
		self.attach(self.iconlabel, 0, 1, 0, 1, gtk.FILL, 0)
		
		self.icon = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner l'icône")
		self.attach(self.icon, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0)
		
		self.titlelabel = gtk.Label("<b>Titre : </b>")
		self.titlelabel.set_alignment(0.0, 0.5)
		self.titlelabel.set_use_markup(True)
		self.attach(self.titlelabel, 0, 1, 1, 2, gtk.FILL, 0)
		
		self.title = gtk.Entry()
		self.attach(self.title, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, 0)
		
		self.desclabel = gtk.Label("<b>Description : </b>")
		self.desclabel.set_alignment(0.0, 0.5)
		self.desclabel.set_use_markup(True)
		self.attach(self.desclabel, 0, 1, 2, 3, gtk.FILL, 0)
		
		self.desc = gtk.Entry()
		self.attach(self.desc, 1, 2, 2, 3, gtk.EXPAND|gtk.FILL, 0)
		
		self.filelabel = gtk.Label("<b>Fichier : </b>")
		self.filelabel.set_alignment(0.0, 0.5)
		self.filelabel.set_use_markup(True)
		self.attach(self.filelabel, 0, 1, 3, 4, gtk.FILL, 0)
		
		self.file = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner la page")
		self.attach(self.file, 1, 2, 3, 4, gtk.EXPAND|gtk.FILL, 0)
		
		self.exelabel = gtk.Label("<b>Exécutable : </b>")
		self.exelabel.set_alignment(0.0, 0.5)
		self.exelabel.set_use_markup(True)
		self.attach(self.exelabel, 0, 1, 4, 5, gtk.FILL, 0)
		
		self.exe = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner l'exécutable", True)
		self.attach(self.exe, 1, 2, 4, 5, gtk.EXPAND|gtk.FILL, 0)
		
		self.dirlabel = gtk.Label("<b>Dossier : </b>")
		self.dirlabel.set_alignment(0.0, 0.5)
		self.dirlabel.set_use_markup(True)
		self.attach(self.dirlabel, 0, 1, 5, 6, gtk.FILL, 0)
		
		self.dir = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner le dossier d'exécution", True, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
		self.attach(self.dir, 1, 2, 5, 6, gtk.EXPAND|gtk.FILL, 0)
		
		self.paramlabel = gtk.Label("<b>Paramètres : </b>")
		self.paramlabel.set_alignment(0.0, 0.5)
		self.paramlabel.set_use_markup(True)
		self.attach(self.paramlabel, 0, 1, 6, 7, gtk.FILL, 0)
		
		self.param = gtk.Entry()
		self.attach(self.param, 1, 2, 6, 7, gtk.EXPAND|gtk.FILL, 0)
		
		self.attach(gtk.VBox(), 0, 2, 7, 8, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
		
		save = gtk.Button(stock=gtk.STOCK_APPLY)
		save.connect("clicked", self.save)
		self.attach(save, 0, 2, 8, 9, gtk.EXPAND, 0)
		
	def open(self, element):
		self.element = element
		self.title.set_text(element.get("name"))
		self.file.set_filename(element.get("page"))
		self.desc.set_text(element.get("desc"))
		self.icon.set_filename(element.get("icon"))
		self.exe.set_filename(element.get("exe"))
		self.dir.set_filename(element.get("dir"))
		self.param.set_text(element.get("param"))
		
	def save(self, widget=None):
		self.element.set("name", self.title.get_text())
		self.element.set("page", self.file.get_filename())
		self.element.set("desc", self.desc.get_text())
		self.element.set("icon", self.icon.get_filename())
		self.element.set("exe", self.exe.get_filename())
		self.element.set("dir", self.dir.get_filename())
		self.element.set("param", self.param.get_text())
		self.callback()

class panel_icon(gtk.Table):
	""" Propriétés d'une catégorie """
	def __init__(self, config, callback):
		self.callback = callback
		self.config = config
		gtk.Table.__init__(self)
		
		self.set_row_spacings(5)
		self.set_col_spacings(5)
		
		self.iconlabel = gtk.Label("<b>Icône : </b>")
		self.iconlabel.set_alignment(0.0, 0.5)
		self.iconlabel.set_use_markup(True)
		self.attach(self.iconlabel, 0, 1, 0, 1, gtk.FILL, 0)
		
		# 0.4.5 : les icones des panels sont gérées au travers des CSS + JS
		self.icon = paneliconlist.paneliconlist(self.config)
		self.attach(self.icon, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0)
		
		self.desclabel = gtk.Label("<b>Description : </b>")
		self.desclabel.set_alignment(0.0, 0.5)
		self.desclabel.set_use_markup(True)
		self.attach(self.desclabel, 0, 1, 1, 2, gtk.FILL, 0)
		
		self.desc = gtk.Entry()
		self.attach(self.desc, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, 0)
		
		self.filelabel = gtk.Label("<b>Fichier : </b>")
		self.filelabel.set_alignment(0.0, 0.5)
		self.filelabel.set_use_markup(True)
		self.attach(self.filelabel, 0, 1, 2, 3, gtk.FILL, 0)
		
		self.file = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner le lanceur")
		self.attach(self.file, 1, 2, 2, 3, gtk.EXPAND|gtk.FILL, 0)
		
		self.exelabel = gtk.Label("<b>Exécutable : </b>")
		self.exelabel.set_alignment(0.0, 0.5)
		self.exelabel.set_use_markup(True)
		self.attach(self.exelabel, 0, 1, 3, 4, gtk.FILL, 0)
		
		self.exe = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner l'exécutable", True)
		self.attach(self.exe, 1, 2, 3, 4, gtk.EXPAND|gtk.FILL, 0)
		
		self.dirlabel = gtk.Label("<b>Dossier : </b>")
		self.dirlabel.set_alignment(0.0, 0.5)
		self.dirlabel.set_use_markup(True)
		self.attach(self.dirlabel, 0, 1, 4, 5, gtk.FILL, 0)
		
		self.dir = FileChooserEntry.FileChooserEntry(self.config, "Sélectionner le dossier d'exécution", True, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
		self.attach(self.dir, 1, 2, 4, 5, gtk.EXPAND|gtk.FILL, 0)
		
		self.paramlabel = gtk.Label("<b>Paramètres : </b>")
		self.paramlabel.set_alignment(0.0, 0.5)
		self.paramlabel.set_use_markup(True)
		self.attach(self.paramlabel, 0, 1, 5, 6, gtk.FILL, 0)
		
		self.param = gtk.Entry()
		self.attach(self.param, 1, 2, 5, 6, gtk.EXPAND|gtk.FILL, 0)
		
		self.attach(gtk.VBox(), 0, 2, 6, 7, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
		
		save = gtk.Button(stock=gtk.STOCK_APPLY)
		save.connect("clicked", self.save)
		self.attach(save, 0, 2, 7, 8, gtk.EXPAND, 0)
		
	def open(self, element):
		self.element = element
		self.icon.update(element.get("icon"))
		self.desc.set_text(element.get("name"))
		self.file.set_filename(element.get("page"))
		self.exe.set_filename(element.get("exe"))
		self.dir.set_filename(element.get("dir"))
		self.param.set_text(element.get("param"))
		
	def save(self, widget=None):
		self.element.set("name", self.desc.get_text())
		self.element.set("page", self.file.get_filename())
		self.element.set("icon", self.icon.get_icon())
		self.element.set("exe", self.exe.get_filename())
		self.element.set("dir", self.dir.get_filename())
		self.element.set("param", self.param.get_text())
		self.callback()
