# Path: PyChat/server/startserver.py
# def listen(host, port):
# def listenFtp(host, port):
# 
# Path: PyChat/client/error.py



import gtk
from helper import helperFunc as hf
from PyChat.server import startserver
from PyChat.client.error import __servfail__
        self.check = self.builder.get_object('checkbutton')

    def connect(self, button):
        """
        Handles when connect button is clicked
        """
        entry = self.entry
        buf = entry.get_buffer()
        host = buf.get_text()
        if not host or not hf.validate_host(host):
            entry.grab_focus()
            return
        spin = self.spinbutton
        buf_spin = spin.get_buffer()
        port = buf_spin.get_text()
        if not port:
            spin.grab_focus()
            return
        port = int(port)
        
        obj = self.parent.get_clientobj()
        result, factory = True, None
        if self.check.get_active():
            result, lisport, factory = startserver.listen(host, port)

        if result: # if everything goes well
            if factory: # also starts a server
                obj.set_factory(lisport, factory)
            self.parent.connect(host, port, obj) # try to connect
        else: # incase server couldnt get started

# Path: PyChat/server/startserver.py
# def listen(host, port):
# def listenFtp(host, port):
# 
# Path: PyChat/client/error.py



# Path: PyChat/client/gui/connectBoxClass.py
import gtk
from helper import helperFunc as hf
from PyChat.server import startserver
from PyChat.client.error import __servfail__

        self.check = self.builder.get_object('checkbutton')

    def connect(self, button):
        """
        Handles when connect button is clicked
        """
        entry = self.entry
        buf = entry.get_buffer()
        host = buf.get_text()
        if not host or not hf.validate_host(host):
            entry.grab_focus()
            return
        spin = self.spinbutton
        buf_spin = spin.get_buffer()
        port = buf_spin.get_text()
        if not port:
            spin.grab_focus()
            return
        port = int(port)
        
        obj = self.parent.get_clientobj()
        result, factory = True, None
        if self.check.get_active():
            result, lisport, factory = startserver.listen(host, port)

        if result: # if everything goes well
            if factory: # also starts a server
                obj.set_factory(lisport, factory)
            self.parent.connect(host, port, obj) # try to connect
        else: # incase server couldnt get started

            obj.updateView('server', __servfail__)