#coding=utf-8
from PyQt4.QtGui import QWidget
from view.setting.usbset import Ui_Form
from common.logrecord import LogRecord
from model.setting.usbset import UsbSet
from PyQt4.QtCore import SIGNAL
# from model.setting.base.infohintdialog import InfoHintDialog
from common.infohintdialog import InfoHintDialog
 
class UsbSetT(QWidget,Ui_Form):
    def __init__(self):
        super(UsbSetT,self).__init__()
        self.setupUi(self)
        self.usbSet=UsbSet()
        
        self.refreshWidget()
        self.connect(self.checkBoxUsbSet, SIGNAL("clicked()"),self.on_checkBox_UsbSet_clicked)
        self.checkBoxUsbSet.setEnabled(False)
                     
    def on_checkBox_UsbSet_clicked(self):
        LogRecord.instance().recordLog(u"当按钮被点击")
        #允许透传已接入usb设备
        if(self.checkBoxUsbSet.isChecked()):
            #选择允许透传已接入设备
            content = "autousb"
            LogRecord.instance().recordLog(u"设置文件")
            res = self.usbSet.setUsb(content)
            if (0 == res):
                InfoHintDialog(u"已成功设置为允许自动透传已接入USB设备").exec_()
            else:
                InfoHintDialog(u"设置失败").exec_()
        else:
            #取消自动透传
            content = "forbusb"
            res = self.usbSet.setUsb(content)
            if (0 == res):
                InfoHintDialog(u"已取消自动透传已接入USB设备").exec_()
            else:
                InfoHintDialog(u"设置失败").exec_()
        return
        
        
    def refreshWidget(self):#初始化设置
        LogRecord.instance().recordLog(u"初始化设置")
        usbset = self.usbSet.getUsbSet()
        if("forbusb" == usbset):
            self.checkBoxUsbSet.setChecked(False)
        elif("autousb" == usbset):
            self.checkBoxUsbSet.setChecked(True)
        else:
            #将其设置为默认的禁止
            policy = "forbusb"
            self.usbSet.setUsb(policy)
            self.checkBoxUsbSet.setChecked(False)
            
            
            