From: Stas Shtin Date: Thu, 8 Apr 2010 16:08:14 +0000 (+0400) Subject: Connections can be added and saved. Removed focus signal from UI. X-Git-Url: http://git.maemo.org/git/?p=ipypbx;a=commitdiff_plain;h=4f4b7b93dffc15f6f4b32aed0c7c8d4d580c73f7 Connections can be added and saved. Removed focus signal from UI. --- diff --git a/src/ipypbx/controllers.py b/src/ipypbx/controllers.py index b233cfc..b0a3fb2 100644 --- a/src/ipypbx/controllers.py +++ b/src/ipypbx/controllers.py @@ -41,7 +41,10 @@ class ConnectionsHandler(BaseHandler): """ def initState(self): self.connections = list(state.store.query(models.Connection)) - self.currentConnection = None + self.currentConnection = None + + for connection in self.connections: + self.parent.ui.connectionList.addItem(connection.name) def select(self, index): """ @@ -61,28 +64,47 @@ class ConnectionsHandler(BaseHandler): Add new connection. """ self.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('') + + name_template = 'New connection [{0:02}]' + for i in xrange(1, 100): + name = name_template.format(i) + connection_exists = False + for connection in self.connections: + if connection.name == name: + connection_exists = True + break + + if not connection_exists: + break + + self.parent.ui.connectionName.setText(name) + self.parent.ui.connectionName.setFocus() + self.parent.ui.connectionName.selectAll() + self.parent.ui.connectionLocalIpAddress.clear() + self.parent.ui.connectionLocalPort.clear() + self.parent.ui.connectionFreeswitchIpAddress.clear() + self.parent.ui.connectionFreeswitchPort.clear() def save(self): """ Save new or existing connection. """ name = unicode(self.parent.ui.connectionName.text()) - connection = models.Connection( - name=name, - local_ip_address=unicode( - self.parent.ui.connectionLocalIpAddress.text()), - local_port=int( - self.parent.ui.connectionLocalPort.text()), - freeswitch_ip_address=unicode( - self.parent.ui.connectionFreeswitchIpAddress.text()), - freeswitch_port=int( - self.parent.ui.connectionFreeswitchPort.text())) - if not self.currentConnection: - self.connections.append(connection) - self.currentConnection = connection + + # Add to connection list if we've created it. + if self.currentConnection is None: + self.currentConnection = models.Connection(store=state.store) + self.connections.append(self.currentConnection) self.parent.ui.connectionList.addItem(name) + + self.currentConnection.name = name + self.currentConnection.local_ip_address = unicode( + self.parent.ui.connectionLocalIpAddress.text()) + self.currentConnection.local_port = int( + self.parent.ui.connectionLocalPort.text()) + self.currentConnection.freeswitch_ip_address = unicode( + self.parent.ui.connectionFreeswitchIpAddress.text()) + self.currentConnection.freeswitch_port = int( + self.parent.ui.connectionFreeswitchPort.text()) + + self.currentConnection.checkpoint() diff --git a/src/ipypbx/ui.py b/src/ipypbx/ui.py index 7e7f80c..e1c854f 100644 --- a/src/ipypbx/ui.py +++ b/src/ipypbx/ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file '../ui/layout.ui' # -# Created: Thu Apr 8 18:41:19 2010 +# Created: Thu Apr 8 20:06:26 2010 # by: PyQt4 UI code generator 4.7.2 # # WARNING! All changes made in this file will be lost! @@ -362,12 +362,6 @@ class Ui_MainWindow(object): self.retranslateUi(MainWindow) self.tabWidget.setCurrentIndex(0) - QtCore.QObject.connect(self.connectionAdd, QtCore.SIGNAL("clicked()"), self.connectionName.setFocus) - QtCore.QObject.connect(self.sipProfileAdd, QtCore.SIGNAL("clicked()"), self.sipProfileName.setFocus) - QtCore.QObject.connect(self.domainAdd, QtCore.SIGNAL("clicked()"), self.domainHostName.setFocus) - QtCore.QObject.connect(self.gatewayAdd, QtCore.SIGNAL("clicked()"), self.gatewayName.setFocus) - QtCore.QObject.connect(self.endpointAdd, QtCore.SIGNAL("clicked()"), self.endpointUseId.setFocus) - QtCore.QObject.connect(self.extensionAdd, QtCore.SIGNAL("clicked()"), self.extensionDestinationMatch.setFocus) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): diff --git a/ui/layout.ui b/ui/layout.ui index 537cfa8..af8b532 100644 --- a/ui/layout.ui +++ b/ui/layout.ui @@ -677,102 +677,5 @@ - - - connectionAdd - clicked() - connectionName - setFocus() - - - 204 - 377 - - - 671 - 55 - - - - - sipProfileAdd - clicked() - sipProfileName - setFocus() - - - 204 - 377 - - - 695 - 55 - - - - - domainAdd - clicked() - domainHostName - setFocus() - - - 204 - 377 - - - 641 - 55 - - - - - gatewayAdd - clicked() - gatewayName - setFocus() - - - 204 - 377 - - - 657 - 55 - - - - - endpointAdd - clicked() - endpointUseId - setFocus() - - - 204 - 377 - - - 641 - 55 - - - - - extensionAdd - clicked() - extensionDestinationMatch - setFocus() - - - 204 - 377 - - - 659 - 55 - - - - +