# Path: log.py
# class __NullLogger:
#     def debug(self, msg=""):    pass
#     def warning(self, msg=""):  pass
#     def info(self, msg=""):     pass
#     def error(self, msg=""):    pass
#     def fatal(self, msg=""):    pass
# 
# Path: net/socktypes.py
# TCP_SERVER_BASE_TYPE = 0x00
# TCP_CLIENT_BASE_TYPE = 0x10
# UDP_SERVER_BASE_TYPE = 0x20
# UDP_CLIENT_BASE_TYPE = 0x30
# TCP_SERVER        = TCP_SERVER_BASE_TYPE | 0x01
# TCP_CLIENT_REMOTE = TCP_SERVER_BASE_TYPE | 0x02
# TCP_CLIENT_LOCAL  = TCP_CLIENT_BASE_TYPE | 0x10
# UDP_SERVER        = UDP_SERVER_BASE_TYPE | 0x00 # it's just like a sever
# UDP_CLIENT_REMOTE = UDP_SERVER_BASE_TYPE | 0x01
# UDP_CLIENT_LOCAL  = UDP_CLIENT_BASE_TYPE | 0x01


from log import logger
from ui.AppIcons import *
from SockTreeItem import SockTreeItem
from net import socktypes
from PyQt4.QtGui import (
    QTreeWidget,
    QIcon )
import config
#-*- coding: utf-8 -*-


class SockTreeWidget(QTreeWidget):
    
    def __init__(self, parent=None):
        QTreeWidget.__init__(self, parent)
        self.sockItemDict = {}
    
    def init(self):
        tcpServerEntry = SockTreeItem(socktypes.TCP_SERVER, config.TCP_SERVER_ENTRY_TEXT, config.TCP_SERVER_ROOT_ID)
        tcpClientEntry = SockTreeItem(socktypes.TCP_CLIENT_LOCAL, config.TCP_CLIENT_ENTRY_TEXT, config.TCP_CLIENT_ROOT_ID)
        udpServerEntry = SockTreeItem(socktypes.UDP_SERVER, config.UDP_SERVER_ENTRY_TEXT, config.UDP_SERVER_ROOT_ID)
        udpClientEntry = SockTreeItem(socktypes.UDP_CLIENT_LOCAL, config.UDP_CLIENT_ENTRY_TEXT, config.UDP_CLIENT_ROOT_ID)
        self.addTopLevelItem (tcpServerEntry)
        self.addTopLevelItem (tcpClientEntry)
        self.addTopLevelItem (udpServerEntry)
        self.addTopLevelItem (udpClientEntry)
        self.setCurrentItem(tcpServerEntry)
    
    def getBaseItemBySocketType(self, sockType):
        n = self.topLevelItemCount()
        if n < 1:

# Path: log.py
# class __NullLogger:
#     def debug(self, msg=""):    pass
#     def warning(self, msg=""):  pass
#     def info(self, msg=""):     pass
#     def error(self, msg=""):    pass
#     def fatal(self, msg=""):    pass
# 
# Path: net/socktypes.py
# TCP_SERVER_BASE_TYPE = 0x00
# TCP_CLIENT_BASE_TYPE = 0x10
# UDP_SERVER_BASE_TYPE = 0x20
# UDP_CLIENT_BASE_TYPE = 0x30
# TCP_SERVER        = TCP_SERVER_BASE_TYPE | 0x01
# TCP_CLIENT_REMOTE = TCP_SERVER_BASE_TYPE | 0x02
# TCP_CLIENT_LOCAL  = TCP_CLIENT_BASE_TYPE | 0x10
# UDP_SERVER        = UDP_SERVER_BASE_TYPE | 0x00 # it's just like a sever
# UDP_CLIENT_REMOTE = UDP_SERVER_BASE_TYPE | 0x01
# UDP_CLIENT_LOCAL  = UDP_CLIENT_BASE_TYPE | 0x01


# Path: view/SockTreeWidget.py
from log import logger
from ui.AppIcons import *
from SockTreeItem import SockTreeItem
from net import socktypes
from PyQt4.QtGui import (
    QTreeWidget,
    QIcon )
import config

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


class SockTreeWidget(QTreeWidget):
    
    def __init__(self, parent=None):
        QTreeWidget.__init__(self, parent)
        self.sockItemDict = {}
    
    def init(self):
        tcpServerEntry = SockTreeItem(socktypes.TCP_SERVER, config.TCP_SERVER_ENTRY_TEXT, config.TCP_SERVER_ROOT_ID)
        tcpClientEntry = SockTreeItem(socktypes.TCP_CLIENT_LOCAL, config.TCP_CLIENT_ENTRY_TEXT, config.TCP_CLIENT_ROOT_ID)
        udpServerEntry = SockTreeItem(socktypes.UDP_SERVER, config.UDP_SERVER_ENTRY_TEXT, config.UDP_SERVER_ROOT_ID)
        udpClientEntry = SockTreeItem(socktypes.UDP_CLIENT_LOCAL, config.UDP_CLIENT_ENTRY_TEXT, config.UDP_CLIENT_ROOT_ID)
        self.addTopLevelItem (tcpServerEntry)
        self.addTopLevelItem (tcpClientEntry)
        self.addTopLevelItem (udpServerEntry)
        self.addTopLevelItem (udpClientEntry)
        self.setCurrentItem(tcpServerEntry)
    
    def getBaseItemBySocketType(self, sockType):
        n = self.topLevelItemCount()
        if n < 1:

            logger.error("top level item count is 0!!")