Connections can be added and saved. Removed focus signal from UI.
authorStas Shtin <antisvin@gmail.com>
Thu, 8 Apr 2010 16:08:14 +0000 (20:08 +0400)
committerStas Shtin <antisvin@gmail.com>
Thu, 8 Apr 2010 16:08:14 +0000 (20:08 +0400)
src/ipypbx/controllers.py
src/ipypbx/ui.py
ui/layout.ui

index b233cfc..b0a3fb2 100644 (file)
@@ -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()
index 7e7f80c..e1c854f 100644 (file)
@@ -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):
index 537cfa8..af8b532 100644 (file)
   </widget>
  </widget>
  <resources/>
- <connections>
-  <connection>
-   <sender>connectionAdd</sender>
-   <signal>clicked()</signal>
-   <receiver>connectionName</receiver>
-   <slot>setFocus()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>204</x>
-     <y>377</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>671</x>
-     <y>55</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>sipProfileAdd</sender>
-   <signal>clicked()</signal>
-   <receiver>sipProfileName</receiver>
-   <slot>setFocus()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>204</x>
-     <y>377</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>695</x>
-     <y>55</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>domainAdd</sender>
-   <signal>clicked()</signal>
-   <receiver>domainHostName</receiver>
-   <slot>setFocus()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>204</x>
-     <y>377</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>641</x>
-     <y>55</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>gatewayAdd</sender>
-   <signal>clicked()</signal>
-   <receiver>gatewayName</receiver>
-   <slot>setFocus()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>204</x>
-     <y>377</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>657</x>
-     <y>55</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>endpointAdd</sender>
-   <signal>clicked()</signal>
-   <receiver>endpointUseId</receiver>
-   <slot>setFocus()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>204</x>
-     <y>377</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>641</x>
-     <y>55</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>extensionAdd</sender>
-   <signal>clicked()</signal>
-   <receiver>extensionDestinationMatch</receiver>
-   <slot>setFocus()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>204</x>
-     <y>377</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>659</x>
-     <y>55</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <connections/>
 </ui>