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

from PyQt4.QtCore import QObject
from configfileparser import ConfigFileParser


class StoreInfoParser(QObject):
    _instance = 0 
    def __init__(self):
        super(StoreInfoParser,self).__init__()
        self.parser = ConfigFileParser()

        
    @classmethod 
    def instance(cls):
        if (cls._instance == 0):
            cls._instance = StoreInfoParser()
            
        return cls._instance
        
    def changeConfigFile(self, section, option, value):
        parser = ConfigFileParser()
        if parser.has_section(section):
            if parser.has_option(section, option):
                parser.changeSectionValue(section, option, value)
            else:
                parser.addOption(section, option, value)
        else:
            parser.addSection(section, option, value)

    def getConfigFileInfo(self, section, option):
        parser = ConfigFileParser()
        if parser.has_section(section):
            if parser.has_option(section, option):
                return parser.getValue(section, option)
            
        return None
    
    def deleteSection(self, section):
        if self.parser.has_section(section):
            self.parser.remove_section(section)

#     def getCloudsServerIP(self):
#         return self.getConfigFileInfo("cloudsServerAddress", "ip")
#         
#     
#     
#     def setServerAddress(self, serverIp):
#         #保存服务器地址到配置文件
#         self.changeConfigFile("cloudsServerAddress", "ip", serverIp)

            
    def getScreenSaver(self):
        """
        获得屏保的开启状态
        """
        return self.getConfigFileInfo("Screensaver", "status")
        
    
    def setScreenSaver(self, screensaver):
        """
        设置屏保的状态
        """
        self.changeConfigFile("Screensaver", "status", screensaver)


    def getScreen(self):#屏幕分辨率设置
        return self.getConfigFileInfo("Resolution", "value")
    
      
    def setScreen(self, screen):
        self.changeConfigFile("Resolution", "value", screen)
       
    def getCenterList(self):
        return self.getConfigFileInfo("CenterList", "clist")
       
       
    def setCenterList(self, networkswitch):
        self.changeConfigFile("CenterList", "clist", networkswitch)
       
    def setLoginUserName(self, name):
        self.changeConfigFile("LoginUser", "name", name)
            
    def getLoginUserName(self):
        return self.getConfigFileInfo("LoginUser", "name")
    
    def setLoginCenterName(self, centerName):
        self.changeConfigFile("CenterName", "name", centerName)
        
    def getLoginCenterName(self):
        return self.getConfigFileInfo("CenterName", "name")
    
    def setAutoLoginInfo(self, autoLogininfo):
        self.changeConfigFile("AutoLogin", "info", autoLogininfo)
    
    def getAutoLoginInfo(self):
        return self.getConfigFileInfo("AutoLogin", "info")
       
       
    def deleteAutoLoginInfo(self):
        self.deleteSection("AutoLogin")
        
    def deleteLoginUserName(self):
        self.deleteSection("LoginUser")
        
        
    def getUsbIsAutoConnect(self):
        return self.getConfigFileInfo("UsbAutoConnect", "value")
    
    def setUsbAutoConnectState(self, value):
        self.changeConfigFile("UsbAutoConnect", "value", value)
        
    def getMultiConnectState(self):#多平设置
        return self.getConfigFileInfo("MultiMonitor", "status")
    
    def setMultiConnectState(self, statue):
        self.changeConfigFile("MultiMonitor", "status", statue)
        
    def setAutoVmScreenState(self, autoScreenState):
        self.changeConfigFile("AutoScreenState", "screenState", autoScreenState)
        
    def getAutoVmScreenState(self):
        return self.getConfigFileInfo("AutoScreenState", "screenState")

            
    def getCurrenCenter(self):
        return self.getConfigFileInfo("CurrentCenter", "address")

    def setCurrenCenter(self, currentcenter):
        self.changeConfigFile("CurrentCenter", "address", currentcenter)
            
            
    #有限网络配置        
    def getLocalNetworkList(self):
        v = self.getConfigFileInfo("LocalNetworkList", "netList")
        if v == None:
            return ""
        return v
        
    def setLocalNetworkList(self, localnetworklist):
        self.changeConfigFile("LocalNetworkList", "netList", localnetworklist)
        
            
    def getCurrentLocalNetwork(self):
        return self.getConfigFileInfo("CurrentUseLocalNetwork", "network")

    def setCurrentLocalNetwork(self, currentlocalnetwork):
        self.changeConfigFile("CurrentUseLocalNetwork", "network", currentlocalnetwork)
            
    def getAutoAdjust(self):#分辨率自适应
        return self.getConfigFileInfo("Autoadjust", "autodata")

    
    def setAutoAdjust(self, autoadjust):
        self.changeConfigFile("Autoadjust", "autodata", autoadjust)

            
    def getMultiMonitor(self):#多平设置
        return self.getConfigFileInfo("Multimonitor", "monitor")
    
    def setMultiMonitor(self, multimonitor):
        self.changeConfigFile("Multimonitor", "monitor", multimonitor)
            
             
    def getUsbSet(self):#usb自动透传
        return self.getConfigFileInfo("Usbset", "usbset")

    def setUsbSet(self, usbset):
        self.changeConfigFile("Usbset", "usbset", usbset)  
    
    def setTerminalId(self,terminalid):
        self.changeConfigFile("Terminalid", "id", terminalid)
            
    def getTerminalId(self):
        return self.getConfigFileInfo("Terminalid", "id")
    
