Added initial code for controllers and network stuff
authorStas Shtin <antisvin@gmail.com>
Wed, 7 Apr 2010 18:36:52 +0000 (22:36 +0400)
committerStas Shtin <antisvin@gmail.com>
Wed, 7 Apr 2010 18:36:52 +0000 (22:36 +0400)
src/ipypbx/controllers.py [new file with mode: 0644]
src/ipypbx/network.py [new file with mode: 0644]

diff --git a/src/ipypbx/controllers.py b/src/ipypbx/controllers.py
new file mode 100644 (file)
index 0000000..f4cbd26
--- /dev/null
@@ -0,0 +1,55 @@
+from ipypbx import models, state
+
+
+class BaseHandler(object):
+    """
+    Base class for various entity handlers.
+
+    Doesn't do anything useful on its own.
+    """
+    items = None
+    current_items = None
+
+    def __init__(self, parent):
+        self.parent = parent
+
+
+class ConnectionsHandler(BaseHandler):
+    """
+    Connections handler.
+    """
+    def select(self, index):
+        """
+        Select another connection as current.
+        """
+        state.currentConnection = state.connections[index]
+
+    def clone(self):
+        """
+        TODO: Clone an existing connection.
+
+        This creates a new connection with bound data copied from another one.
+        """
+
+    def add(self):
+        """
+        Add a new connection.
+        """
+        state.currentConnection = None
+        self.parent.ui.connectionName.setText('')
+        self.parent.ui.connectionLocalIpAddress.setText('')
+        self.parent.ui.connectionLocalPort.setText('')
+        self.parent.ui.connectionFreeswitchIpAddress.setText('')
+        self.parent.ui.connectionFreeswitchPort.setText('')
+
+    def save(self):
+        connection = models.Connection(
+            name=self.parent.ui.connectionName.getText(),
+            local_ip_address=self.parent.ui.connectionLocalIpAddress.\
+                getText(),
+            local_port=self.parent.ui.connectionLocalPort.getText(),
+            freeswitch_ip_address=self.parent.ui.\
+                connectionFreeswitchIpAddress.getText(),
+            freeswitch_port=self.parent.ui.connectionFreeswitchPort.getText()
+            )
+    #state.currentConnection = 
diff --git a/src/ipypbx/network.py b/src/ipypbx/network.py
new file mode 100644 (file)
index 0000000..1e526b6
--- /dev/null
@@ -0,0 +1,35 @@
+# Copyright (c) Stas Shtin, 2010
+
+# This file is part of IPyPBX.
+
+# IPyPBX is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# IPyPBX is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with IPyPBX.  If not, see <http://www.gnu.org/licenses/>.
+
+
+from PyQt import QtNetwork
+
+
+class FreeswitchConfigServer(QTcpServer):
+    """
+    This is a server that gets instantiated for every connection.
+    """
+    def __init__(self, host, port, parent=None):
+        super(FreeswitchConfig, self).__init__(self, parent)
+
+        self.newConnection.connect(self, handleClientConnection)
+        self.listen(host, port)
+
+    def handleClientConnection(self):
+        if self.hasPendingConnections():
+            connectionClient = self.nextClientConnection()
+            connectionClient.readyRead.connect(self.receiveData)