+# 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
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):
"""
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('')
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)
"""
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)
store = Store(os.path.join(PREFIX, 'ipypbx.db'))
# Program state data.
-connections = list(store.query(models.Connection))
sipProfiles = []
domains = []
gateways = []
endpoints = []
extensions = []
-
-currentConnection = None
# 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!
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")
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)
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))
</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>