# You should have received a copy of the GNU General Public License
# along with IPyPBX. If not, see <http://www.gnu.org/licenses/>.
-from ipypbx import models, state
+#from ipypbx import models
+from PyQt4 import QtCore
class BaseHandler(object):
return NotImplemented
-class ConnectionsHandler(BaseHandler):
+class ConnectionController(QtCore.QObject):
"""
Connections handler.
"""
- def initState(self):
- self.connections = list(state.store.query(models.Connection))
- self.currentConnection = None
-
- for connection in self.connections:
- self.parent.ui.connectionList.addItem(connection.name)
+# def initState(self):
+# self.connections = []
+# #self.connections = list(state.store.query(models.Connection))
+# self.currentConnection = None
+
+# for connection in self.connections:
+# self.parent.ui.connectionList.addItem(connection.name)
+
+# if self.connections:
+# print self.parent.ui.connectionList.currentRow()
+# self.parent.ui.connectionList.setCurrentRow(0)
+# QtCore.QObject.emit(
+# self.parent.ui.connectionList, QtCore.SIGNAL('currentRowChanged(int)'), 0)
- def select(self, index):
+ def select(self, row):
"""
Select another connection as current.
"""
- self.currentConnection = state.connections[index]
+ self.currentConnection = self.connections[row]
+
+ # Fill in form based on selection.
+ self.parent.ui.connectionName.setText(self.currentConnection.name)
+ self.parent.ui.connectionLocalIpAddress.setText(
+ self.currentConnection.local_ip_address)
+ self.parent.ui.connectionLocalPort.setText(
+ unicode(self.currentConnection.local_port))
+ self.parent.ui.connectionFreeswitchIpAddress.setText(
+ self.currentConnection.freeswitch_ip_address)
+ self.parent.ui.connectionFreeswitchPort.setText(
+ unicode(self.currentConnection.freeswitch_port))
def clone(self):
"""
"""
Add new connection.
"""
+ print '!'
+ print self.parent
self.currentConnection = None
name_template = 'New connection [{0:02}]'
if not connection_exists:
break
- self.parent.ui.connectionName.setText(name)
+ self.parent.ui.connectionName.setText('New connection')
self.parent.ui.connectionName.setFocus()
self.parent.ui.connectionName.selectAll()
self.parent.ui.connectionLocalIpAddress.clear()
# Add to connection list if we've created it.
if self.currentConnection is None:
- self.currentConnection = models.Connection(store=state.store)
+ #self.currentConnection = models.Connection(store=state.store)
self.connections.append(self.currentConnection)
self.parent.ui.connectionList.addItem(name)