# -*- coding: utf-8 -*-  

from PyQt4.QtCore import QObject

from base.configFileParser import ConfigFileParser


class StoreInfoParser(QObject):
    _instance = 0 
    def __init__(self):
        super(StoreInfoParser,self).__init__()
        
        
        
    @classmethod 
    def instance(cls):
        if (cls._instance == 0):
            cls._instance = StoreInfoParser()
            
        return cls._instance
    
    #平台配置
    def getAutoConNetwork(self):
        parser = ConfigFileParser()
        if parser.has_section("autoconnetwork"):
            if parser.has_option("autoconnetwork", "autoconnetwork"):
                return parser.getValue("autoconnetwork", "autoconnetwork")
        return ""
    def setAutoConNetwork(self, autoconnetwork):
        parser = ConfigFileParser()
        if parser.has_section("autoconnetwork"):
            if parser.has_option("autoconnetwork", "autoconnetwork"):
                parser.changeSectionValue("autoconnetwork", "autoconnetwork", autoconnetwork)
            else:
                parser.addOption("autoconnetwork", "autoconnetwork", autoconnetwork)
        else:
            parser.addSection("autoconnetwork", "autoconnetwork", autoconnetwork)
            
            
    def getNetworkSwitch(self):
        parser = ConfigFileParser()
        if parser.has_section("networkswitch"):
            if parser.has_option("networkswitch", "networkswitch"):
                return parser.getValue("networkswitch", "networkswitch")
        return []
    def setNetworkSwitch(self, networkswitch):
        parser = ConfigFileParser()
        if parser.has_section("networkswitch"):
            if parser.has_option("networkswitch", "networkswitch"):
                parser.changeSectionValue("networkswitch", "networkswitch", networkswitch)
            else:
                parser.addOption("networkswitch", "networkswitch", networkswitch)
        else:
            parser.addSection("networkswitch", "networkswitch", networkswitch)
            
            
    def getCurrenCenter(self):
        parser = ConfigFileParser()
        if parser.has_section("currentcenter"):
            if parser.has_option("currentcenter", "currentcenter"):
                return parser.getValue("currentcenter", "currentcenter")
        return ""
    def setCurrenCenter(self, currentcenter):
        parser = ConfigFileParser()
        if parser.has_section("currentcenter"):
            if parser.has_option("currentcenter", "currentcenter"):
                parser.changeSectionValue("currentcenter", "currentcenter", currentcenter)
            else:
                parser.addOption("currentcenter", "currentcenter", currentcenter)
        else:
            parser.addSection("currentcenter", "currentcenter", currentcenter)
            
            
    #有限网络配置        
    def getLocalNetworkList(self):
        parser = ConfigFileParser()
        if parser.has_section("localnetworklist"):
            if parser.has_option("localnetworklist", "localnetworklist"):
                return parser.getValue("localnetworklist", "localnetworklist")
        return []
    def setLocalNetworkList(self, localnetworklist):
        parser = ConfigFileParser()
        if parser.has_section("localnetworklist"):
            if parser.has_option("localnetworklist", "localnetworklist"):
                parser.changeSectionValue("localnetworklist", "localnetworklist", localnetworklist)
            else:
                parser.addOption("localnetworklist", "localnetworklist", localnetworklist)
        else:
            parser.addSection("localnetworklist", "localnetworklist", localnetworklist)
            
    def getCurrentLocalNetwork(self):
        parser = ConfigFileParser()
        if parser.has_section("currentlocalnetwork"):
            if parser.has_option("currentlocalnetwork", "currentlocalnetwork"):
                return parser.getValue("currentlocalnetwork", "currentlocalnetwork")
        return ""
    def setCurrentLocalNetwork(self, currentlocalnetwork):
        parser = ConfigFileParser()
        if parser.has_section("currentlocalnetwork"):
            if parser.has_option("currentlocalnetwork", "currentlocalnetwork"):
                parser.changeSectionValue("currentlocalnetwork", "currentlocalnetwork", currentlocalnetwork)
            else:
                parser.addOption("currentlocalnetwork", "currentlocalnetwork", currentlocalnetwork)
        else:
            parser.addSection("currentlocalnetwork", "currentlocalnetwork", currentlocalnetwork)
            
    #无线网络配置
    def getWirelessNetwork(self):
        parser = ConfigFileParser()
        if parser.has_section("wirelessnetwork"):
            if parser.has_option("wirelessnetwork", "wirelessnetwork"):
                return parser.getValue("wirelessnetwork", "wirelessnetwork")
        return ""
    def setWirelessNetwork(self, wirelessnetwork):
        parser = ConfigFileParser()
        if parser.has_section("wirelessnetwork"):
            if parser.has_option("wirelessnetwork", "wirelessnetwork"):
                parser.changeSectionValue("wirelessnetwork", "wirelessnetwork", wirelessnetwork)
            else:
                parser.addOption("wirelessnetwork", "wirelessnetwork", wirelessnetwork)
        else:
            parser.addSection("wirelessnetwork", "wirelessnetwork", wirelessnetwork)
    #自动登录配置
    def getLoginSet(self):
        parser = ConfigFileParser()
        if parser.has_section("loginset"):
            if parser.has_option("loginset", "loginset"):
                return parser.getValue("loginset", "loginset")
        return ""
    
    def removeLoginSet(self):
        parser = ConfigFileParser()
        if parser.has_section("loginset"):
            parser.remove_section("loginset")
        
    def setLoginSet(self, loginset):
        parser = ConfigFileParser()
        if parser.has_section("loginset"):
            if parser.has_option("loginset", "loginset"):
                parser.changeSectionValue("loginset", "loginset", loginset)
            else:
                parser.addOption("loginset", "loginset", loginset)
        else:
            parser.addSection("loginset", "loginset", loginset)
    def getUser(self):
        parser = ConfigFileParser()
        if parser.has_section("user"):
            if parser.has_option("user", "user"):
                return parser.getValue("user", "user")
        return ""
    
    def setUser(self, user):
        parser = ConfigFileParser()
        if parser.has_section("user"):
            if parser.has_option("user", "user"):
                parser.changeSectionValue("user", "user", user)
            else:
                parser.addOption("user", "user", user)
        else:
            parser.addSection("user", "user", user)
            
    def getDefaultVM(self):
        parser = ConfigFileParser()
        if parser.has_section("defaultvm"):
            if parser.has_option("defaultvm", "defaultvm"):
                return parser.getValue("defaultvm", "defaultvm")
        return ""
    def setdefaultvm(self, defaultvm):
        parser = ConfigFileParser()
        if parser.has_section("defaultvm"):
            if parser.has_option("defaultvm", "defaultvm"):
                parser.changeSectionValue("defaultvm", "defaultvm", defaultvm)
            else:
                parser.addOption("defaultvm", "defaultvm", defaultvm)
        else:
            parser.addSection("defaultvm", "defaultvm", defaultvm)
            
    def getOldDefaultVM(self):
        parser = ConfigFileParser()
        if parser.has_section("defaultvm"):
            if parser.has_option("defaultvm", "olddefaultvm"):
                return parser.getValue("defaultvm", "olddefaultvm")
        return ""
    def setolddefaultvm(self, defaultvm):
        parser = ConfigFileParser()
        if parser.has_section("defaultvm"):
            if parser.has_option("defaultvm", "olddefaultvm"):
                parser.changeSectionValue("defaultvm", "olddefaultvm", defaultvm)
            else:
                parser.addOption("defaultvm", "olddefaultvm", defaultvm)
        else:
            parser.addSection("defaultvm", "olddefaultvm", defaultvm)
            
    def getLocalMonitor(self):
        parser = ConfigFileParser()
        if parser.has_section("localmonitor"):
            if parser.has_option("localmonitor", "localmonitor"):
                return parser.getValue("localmonitor", "localmonitor")
        return []
    def setLocalMonitor(self,localmonitor):
        parser = ConfigFileParser()
        if parser.has_section("localmonitor"):
            if parser.has_option("localmonitor", "localmonitor"):
                parser.changeSectionValue("localmonitor", "localmonitor", localmonitor)
            else:
                parser.addOption("localmonitor", "localmonitor", localmonitor)
        else:
            parser.addSection("localmonitor", "localmonitor", localmonitor)           
    #系统属性配置
    def getScreenSaver(self):#屏保
        parser = ConfigFileParser()
        if parser.has_section("screensaver"):
            if parser.has_option("screensaver", "screensaver"):
                return parser.getValue("screensaver", "screensaver")
        return ""
    def setScreenSaver(self, screensaver):
        parser = ConfigFileParser()
        if parser.has_section("screensaver"):
            if parser.has_option("screensaver", "screensaver"):
                parser.changeSectionValue("screensaver", "screensaver", screensaver)
            else:
                parser.addOption("screensaver", "screensaver", screensaver)
        else:
            parser.addSection("screensaver", "screensaver", screensaver)   
            
    def getAutoAdjust(self):#分辨率自适应
        parser = ConfigFileParser()
        if parser.has_section("autoadjust"):
            if parser.has_option("autoadjust", "autoadjust"):
                return parser.getValue("autoadjust", "autoadjust")
        return ""
    def setAutoAdjust(self, autoadjust):
        parser = ConfigFileParser()
        if parser.has_section("autoadjust"):
            if parser.has_option("autoadjust", "autoadjust"):
                parser.changeSectionValue("autoadjust", "autoadjust", autoadjust)
            else:
                parser.addOption("autoadjust", "autoadjust", autoadjust)
        else:
            parser.addSection("autoadjust", "autoadjust", autoadjust)  
            
    def getMultiMonitor(self):#多平设置
        parser = ConfigFileParser()
        if parser.has_section("multimonitor"):
            if parser.has_option("multimonitor", "multimonitor"):
                return parser.getValue("multimonitor", "multimonitor")
        return ""
    def setMultiMonitor(self, multimonitor):
        parser = ConfigFileParser()
        if parser.has_section("multimonitor"):
            if parser.has_option("multimonitor", "multimonitor"):
                parser.changeSectionValue("multimonitor", "multimonitor", multimonitor)
            else:
                parser.addOption("multimonitor", "multimonitor", multimonitor)
        else:
            parser.addSection("multimonitor", "multimonitor", multimonitor)  
            
    def getUpdates(self):#升级设置
        parser = ConfigFileParser()
        if parser.has_section("updates"):
            if parser.has_option("updates", "updates"):
                return parser.getValue("updates", "updates")
        return ""
    def setUpdates(self, updates):
        parser = ConfigFileParser()
        if parser.has_section("updates"):
            if parser.has_option("updates", "updates"):
                parser.changeSectionValue("updates", "updates", updates)
            else:
                parser.addOption("updates", "updates", updates)
        else:
            parser.addSection("updates", "updates", updates)  
            
    def getScreen(self):#屏幕分辨率设置
        parser = ConfigFileParser()
        if parser.has_section("screen"):
            if parser.has_option("screen", "screen"):
                return parser.getValue("screen", "screen")
        return ""
    def setScreen(self, screen):
        parser = ConfigFileParser()
        if parser.has_section("screen"):
            if parser.has_option("screen", "screen"):
                parser.changeSectionValue("screen", "screen", screen)
            else:
                parser.addOption("screen", "screen", screen)
        else:
            parser.addSection("screen", "screen", screen) 
             
    def getUsbSet(self):#usb自动透传
        parser = ConfigFileParser()
        if parser.has_section("usbset"):
            if parser.has_option("usbset", "usbset"):
                return parser.getValue("usbset", "usbset")
        return ""
    def setUsbSet(self, usbset):
        parser = ConfigFileParser()
        if parser.has_section("usbset"):
            if parser.has_option("usbset", "usbset"):
                parser.changeSectionValue("usbset", "usbset", usbset)
            else:
                parser.addOption("usbset", "usbset", usbset)
        else:
            parser.addSection("usbset", "usbset", usbset)  
                
    #终端配置            
    def setTerminalName(self, terminalname):
        #保存终端名称到配置文件
        parser = ConfigFileParser()
        if parser.has_section("terminalname"):
            if parser.has_option("terminalname", "terminalname"):
                parser.changeSectionValue("terminalname", "terminalname", terminalname)
            else:
                parser.addOption("terminalname", "terminalname", terminalname)
        else:
            parser.addSection("terminalname", "terminalname", terminalname)
    def getTerminalName(self):
        parser = ConfigFileParser()
        if parser.has_section("terminalname"):
            if parser.has_option("terminalname", "terminalname"):
                return parser.getValue("terminalname", "terminalname")
        return ""
    def setTerminalType(self, terminaltype):
        parser = ConfigFileParser()
        if parser.has_section("terminaltype"):
            if parser.has_option("terminaltype", "type"):
                parser.changeSectionValue("terminaltype", "type", terminaltype)
            else:
                parser.addOption("terminaltype", "type", terminaltype)
        else:
            parser.addSection("terminaltype", "type", terminaltype)
    def getTerminalType(self):
        parser = ConfigFileParser()
        if parser.has_section("terminaltype"):
            if parser.has_option("terminaltype", "type"):
                return parser.getValue("terminaltype", "type")
        return ""
    
    def setTerminalId(self,terminalid):
        parser = ConfigFileParser()
        if parser.has_section("terminalid"):
            if parser.has_option("terminalid", "terminalid"):
                parser.changeSectionValue("terminalid", "terminalid", terminalid)
            else:
                parser.addOption("terminalid", "terminalid", terminalid)
        else:
            parser.addSection("terminalid", "terminalid", terminalid)
            
    def getTerminalId(self):
        parser = ConfigFileParser()
        if parser.has_section("terminalid"):
            if parser.has_option("terminalid", "terminalid"):
                return parser.getValue("terminalid", "terminalid")
        return []
    
    def setTerminalStatus(self,terminalstatus):
        parser = ConfigFileParser()
        if parser.has_section("terminalstatus"):
            if parser.has_option("terminalstatus", "terminalstatus"):
                parser.changeSectionValue("terminalstatus", "terminalstatus", terminalstatus)
            else:
                parser.addOption("terminalstatus", "terminalstatus", terminalstatus)
        else:
            parser.addSection("terminalstatus", "terminalstatus", terminalstatus)
            
    def getTerminalStatus(self):
        parser = ConfigFileParser()
        if parser.has_section("terminalstatus"):
            if parser.has_option("terminalstatus", "terminalstatus"):
                return parser.getValue("terminalstatus", "terminalstatus")
        return ""
    
    def isDynamicIP(self):
        parser = ConfigFileParser()
        if parser.has_section('dhcp'):
            return parser.getValue('dhcp', 'status') == 'on'
        return False
    
    def setDynamicIP(self):
        parser = ConfigFileParser()
        if parser.has_section('dhcp'):
            if parser.has_option('dhcp', 'status'):
                parser.changeSectionValue('dhcp', 'status', 'on')
            else:
                parser.addSection('dhcp', 'status', 'on')
        else:
            parser.addSection('dhcp', 'status', 'on')
            
            
    def getAutoVmScreenState(self):
        parser = ConfigFileParser()
        if parser.has_section("autoScreenState"):
            if parser.has_option("autoScreenState", "autoScreenState"):
                return parser.getValue("autoScreenState", "autoScreenState")
        return ""

    def setAutoVmScreenState(self,autoScreenState):
        parser = ConfigFileParser()
        if parser.has_section("autoScreenState"):
            if parser.has_option("autoScreenState", "autoScreenState"):
                parser.changeSectionValue("autoScreenState", "autoScreenState", autoScreenState)
            else:
                parser.addOption("autoScreenState", "autoScreenState", autoScreenState)
        else:
            parser.addSection("autoScreenState", "autoScreenState", autoScreenState)
            
    def getLocalDiskInfo(self):#本地个人盘信息
        parser = ConfigFileParser()
        if parser.has_section("getLocalDiskInfo"):
            if parser.has_option("getLocalDiskInfo", "getLocalDiskInfo"):
                return parser.getValue("getLocalDiskInfo", "getLocalDiskInfo")
        return ""
    
    def setLocalDiskInfo(self, getLocalDiskInfo):
        parser = ConfigFileParser()
        if parser.has_section("getLocalDiskInfo"):
            if parser.has_option("getLocalDiskInfo", "getLocalDiskInfo"):
                parser.changeSectionValue("getLocalDiskInfo", "getLocalDiskInfo", getLocalDiskInfo)
            else:
                parser.addOption("getLocalDiskInfo", "getLocalDiskInfo", getLocalDiskInfo)
        else:
            parser.addSection("getLocalDiskInfo", "getLocalDiskInfo", getLocalDiskInfo) 
            
    # add by p_bc for cache -top
    def get_vmcache_download_info(self):
        parser = ConfigFileParser()
        if parser.has_section("cache_info"):
            if parser.has_option("cache_info", "cache_info"):
                return parser.getValue("cache_info", "cache_info")
        return ""
    
    def set_vmcache_download_info(self, cache_info):
        parser = ConfigFileParser()
        if parser.has_section("cache_info"):
            if parser.has_option("cache_info", "cache_info"):
                parser.changeSectionValue("cache_info", "cache_info", cache_info)
            else:
                parser.addOption("cache_info", "cache_info", cache_info)
        else:
            parser.addSection("cache_info", "cache_info", cache_info) 
            
    # add by p_bc for cache -end
    