# JV website generator
# (c) 2008, Johan Tuitman
# Licentie: GPL
#
# data structuur voor JV website
import os

class pageData:
    def __init__(self, name):
        self.url = ""
        self.process = True
        self.subProcess = True
        self.newWin = False
        self.inclCopy = []
        self.inclProc = []
        self.fullName = name
        self.pics = {}

    def setUrl(self,url):
        self.url = url

    def getUrl(self):
        return self.url

    def setProcess(self,process):
        self.process = process

    def getProcess(self):
        return self.process

    def setSubProcess(self,subProcess):
        self.subProcess = subProcess

    def getSubProcess(self):
        return self.subProcess
    
    def resetInclCopy(self):
        self.inclCopy = []

    def addInclCopy(self,item):
        self.inclCopy.append(item)

    def getInclCopy(self):
        return self.inclCopy

    def resetInclProc(self):
        self.inclProc = []

    def addInclProc(self,item):
        self.inclProc.append(item)

    def getInclProc(self):
        return self.inclProc

    def setInclProc(self,items):
        self.inclProc=items

    def setFullName(self, name):
        self.fullName = name

    def getFullName(self):
        return self.fullName

    def setNewWin(self,newWin):
        self.newWin = newWin

    def getNewWin(self):
        return self.newWin

    def addPic(self,pic):
        self.pics[pic] = str(pic)

    def setPicName(self,pic,name):
        self.pics[pic] = name

    def delPic(self,pic):
        del self.pics[pic]

    def getPics(self):
        return self.pics

    def getDirName(self,):
        url = self.getUrl()
        if url.find('://') < 0:
            return os.path.dirname(url)
        else:
            return self.getFullName()


class WSData:
    def __init__(self):
        self.menus = []
        self.page = {}
        self.subMenus = {}
        self.basePath = ""
        self.pics = {}
        self.indexPage = pageData('Home')
        self.ftp = ftpData()
        self.workDir = ""
        self.picDir = ""

    def addMenu(self,item):
        self.page[item] = pageData(item)
        self.subMenus[item] = WSData()

    def getMenus(self):
        return self.menus

    def addSubMenu(self,item,sitem):
        mitem = self.getMenuItem(item)
        self.subMenus[mitem].addMenu(sitem)

    def getSubMenus(self,item):
        mitem = self.getMenuItem(item)
        return self.subMenus[mitem].getMenus()

    def getPage(self,item):
        mitem = self.getMenuItem(item)
        return self.page[mitem]

    def getSubPage(self,item,sitem):
        mitem = self.getMenuItem(item)
        return self.subMenus[mitem].getPage(sitem)

    def setMenus(self,items):
        self.menus = items

    def setSubMenus(self,items,sitem):
        mitem = self.getMenuItem(item)
        self.subMenus[mitem].setMenus(sitem)

    def delMenu(self,item):
        mitem = self.getMenuItem(item)
        del self.page[item]

    def delSubMenu(self,item,sitem):
        mitem, smitem = self.getSubMenuItem(item,sitem)
        self.subMenus[mitem].delMenu(smitem)

    def setBasePath(self,path):
        self.basePath = path

    def getBasePath(self):
        return self.basePath

    def getIndexPage(self):
        return self.indexPage

    def getMenuItem(self,item):
        if not str(item).isdigit():
            return item
        else:
            return self.menus[item]

    def getSubMenuItem(self,item,items):
        mitem = self.getMenuItem(item)
        if not str(items).isdigit():
            return mitem, items
        else:
            return mitem, self.subMenus[mitem].getMenus()[items]

    def getSub(self,item):
        mitem = self.getMenuItem(item)
        return self.subMenus[mitem]

    def getFTP(self):
        return self.ftp

    def getWorkDir(self):
        return self.workDir

    def setWorkDir(self,workDir):
        self.workDir = workDir

    def getPicDir(self):
        return self.picDir

    def setPicDir(self,picDir):
        self.picDir = picDir

class ftpData:
    def __init__(self):
        self.site = ""
        self.directory = ""
        self.user = ""
        self.passwd = ""

    def setSite(self,site):
        self.site=site
        
    def getSite(self):
        return self.site

    def setDirectory(self,directory):
        self.directory = directory

    def getDirectory(self):
        return self.directory

    def setUser(self,user):
        self.user = user

    def getUser(self):
        return self.user

    def setPasswd(self,passwd):
        self.passwd = passwd

    def getPasswd(self):
        return self.passwd

class subMData:
    def __init__(self,page,menu,smenu):
        self.page = page
        self.menu = menu
        self.smenu = smenu

    def getPage(self):
        return self.page

    def getMenu(self):
        return self.menu

    def getSMenu(self):
        return self.smenu