Connection adding implemented
authorStas Shtin <antisvin@gmail.com>
Thu, 8 Apr 2010 14:44:00 +0000 (18:44 +0400)
committerStas Shtin <antisvin@gmail.com>
Thu, 8 Apr 2010 14:44:00 +0000 (18:44 +0400)
src/ipypbx/controllers.py
src/ipypbx/main.py
src/ipypbx/state.py
src/ipypbx/ui.py
ui/layout.ui

index f4cbd26..b233cfc 100644 (file)
@@ -1,3 +1,20 @@
+# 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 ipypbx import models, state
 
 
@@ -12,17 +29,25 @@ class BaseHandler(object):
 
     def __init__(self, parent):
         self.parent = parent
+        self.initState()
+
+    def initState(self):
+        return NotImplemented
 
 
 class ConnectionsHandler(BaseHandler):
     """
     Connections handler.
     """
+    def initState(self):
+        self.connections = list(state.store.query(models.Connection))
+        self.currentConnection = None        
+        
     def select(self, index):
         """
         Select another connection as current.
         """
-        state.currentConnection = state.connections[index]
+        self.currentConnection = state.connections[index]
 
     def clone(self):
         """
@@ -33,9 +58,9 @@ class ConnectionsHandler(BaseHandler):
 
     def add(self):
         """
-        Add a new connection.
+        Add new connection.
         """
-        state.currentConnection = None
+        self.currentConnection = None
         self.parent.ui.connectionName.setText('')
         self.parent.ui.connectionLocalIpAddress.setText('')
         self.parent.ui.connectionLocalPort.setText('')
@@ -43,13 +68,21 @@ class ConnectionsHandler(BaseHandler):
         self.parent.ui.connectionFreeswitchPort.setText('')
 
     def save(self):
+        """
+        Save new or existing connection.
+        """
+        name = unicode(self.parent.ui.connectionName.text())
         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 = 
+            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
+            self.parent.ui.connectionList.addItem(name)
index c38d394..197e921 100644 (file)
@@ -26,16 +26,11 @@ class MainWindow(QtGui.QMainWindow):
     """
     def __init__(self):
         QtGui.QMainWindow.__init__(self)
-        
         locale = QtCore.QLocale.system().name()
-        print "Locale is", locale
-        
         translator = QtCore.QTranslator()
     
         if translator.load("ipypbx_%s" % locale.toLower(), "ipypbx/locale"):
             app.installTranslator(translator)
-        else:
-            print "Translation not found"
 
         self.ui = ui.Ui_MainWindow()
         self.ui.setupUi(self)
index 6ae8319..d60fe6e 100644 (file)
@@ -31,12 +31,9 @@ if not os.path.exists(PREFIX):
 store = Store(os.path.join(PREFIX, 'ipypbx.db'))
 
 # Program state data.
-connections = list(store.query(models.Connection))
 sipProfiles = []
 domains = []
 gateways = []
 endpoints = []
 extensions = []
 
-
-currentConnection = None
index e3dd085..7e7f80c 100644 (file)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file '../ui/layout.ui'
 #
-# Created: Wed Apr  7 23:01:27 2010
+# Created: Thu Apr  8 18:41:19 2010
 #      by: PyQt4 UI code generator 4.7.2
 #
 # WARNING! All changes made in this file will be lost!
@@ -26,9 +26,6 @@ class Ui_MainWindow(object):
         self.layoutWidget.setObjectName("layoutWidget")
         self.gridLayout = QtGui.QGridLayout(self.layoutWidget)
         self.gridLayout.setObjectName("gridLayout")
-        self.connectionList = QtGui.QListView(self.layoutWidget)
-        self.connectionList.setObjectName("connectionList")
-        self.gridLayout.addWidget(self.connectionList, 0, 0, 1, 1)
         self.formLayout_7 = QtGui.QFormLayout()
         self.formLayout_7.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
         self.formLayout_7.setObjectName("formLayout_7")
@@ -47,7 +44,6 @@ class Ui_MainWindow(object):
         self.label_11.setObjectName("label_11")
         self.formLayout_7.setWidget(2, QtGui.QFormLayout.LabelRole, self.label_11)
         self.connectionLocalPort = QtGui.QLineEdit(self.layoutWidget)
-        self.connectionLocalPort.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
         self.connectionLocalPort.setObjectName("connectionLocalPort")
         self.formLayout_7.setWidget(2, QtGui.QFormLayout.FieldRole, self.connectionLocalPort)
         self.label_13 = QtGui.QLabel(self.layoutWidget)
@@ -72,6 +68,9 @@ class Ui_MainWindow(object):
         self.connectionSave = QtGui.QPushButton(self.layoutWidget)
         self.connectionSave.setObjectName("connectionSave")
         self.gridLayout.addWidget(self.connectionSave, 1, 1, 1, 1)
+        self.connectionList = QtGui.QListWidget(self.layoutWidget)
+        self.connectionList.setObjectName("connectionList")
+        self.gridLayout.addWidget(self.connectionList, 0, 0, 1, 1)
         self.tabWidget.addTab(self.connectionsTab, "")
         self.sipProfilesTab = QtGui.QWidget()
         self.sipProfilesTab.setMaximumSize(QtCore.QSize(796, 16777215))
index e43edb2..537cfa8 100644 (file)
@@ -46,9 +46,6 @@
        </rect>
       </property>
       <layout class="QGridLayout" name="gridLayout">
-       <item row="0" column="0">
-        <widget class="QListView" name="connectionList"/>
-       </item>
        <item row="0" column="1">
         <layout class="QFormLayout" name="formLayout_7">
          <property name="fieldGrowthPolicy">
           </widget>
          </item>
          <item row="2" column="1">
-          <widget class="QLineEdit" name="connectionLocalPort">
-           <property name="inputMethodHints">
-            <set>Qt::ImhDigitsOnly</set>
-           </property>
-          </widget>
+          <widget class="QLineEdit" name="connectionLocalPort"/>
          </item>
          <item row="4" column="0">
           <widget class="QLabel" name="label_13">
          </property>
         </widget>
        </item>
+       <item row="0" column="0">
+        <widget class="QListWidget" name="connectionList"/>
+       </item>
       </layout>
      </widget>
     </widget>